This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func print( | |
_ items: Any..., | |
separator: String = " ", | |
terminator: String = "\n", | |
file: StaticString = #file, | |
function: StaticString = #function, | |
line: UInt = #line, date: Date = Date() | |
) { | |
let components = file.description.components(separatedBy: "/") | |
if let name = components.last { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class ImageUtil { | |
public static BufferedImage pixelate(BufferedImage imageToPixelate, int pixelSize) { | |
BufferedImage pixelateImage = new BufferedImage( | |
imageToPixelate.getWidth(), | |
imageToPixelate.getHeight(), | |
imageToPixelate.getType()); | |
for (int y = 0; y < imageToPixelate.getHeight(); y += pixelSize) { | |
for (int x = 0; x < imageToPixelate.getWidth(); x += pixelSize) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected BufferedImage pixelate(BufferedImage source) { | |
// How big should the pixelations be? | |
final int PIX_SIZE = 16; | |
BufferedImage img = new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_INT_ARGB); | |
Graphics2D g2d = img.createGraphics(); | |
g2d.drawImage(source, 0, 0, this); | |
g2d.dispose(); | |
// Get the raster data (array of pixels) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
import javax.swing.text.AttributeSet; | |
import javax.swing.text.BadLocationException; | |
import javax.swing.text.DocumentFilter; | |
public class RegularExpressionDocumentFilter extends ChainedDocumentFilter { | |
// Useful for every kind of input validation ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.text.AttributeSet; | |
import javax.swing.text.BadLocationException; | |
import javax.swing.text.DocumentFilter; | |
// Original source https://tips4java.wordpress.com/2009/10/18/chaining-document-filters/ | |
public class CaseModificationDocumentFilter extends ChainedDocumentFilter { | |
public enum Case { | |
UPPER, LOWER |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.text.AttributeSet; | |
import javax.swing.text.BadLocationException; | |
import javax.swing.text.DocumentFilter; | |
public class LengthLimitDocumentFilter extends ChainedDocumentFilter { | |
private int maxCharacters; | |
public LengthLimitDocumentFilter(DocumentFilter filter, int maxChars) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.text.AttributeSet; | |
import javax.swing.text.BadLocationException; | |
import javax.swing.text.DocumentFilter; | |
public class NumericDocumentFilter extends ChainedDocumentFilter { | |
private int decimalPrecision = 2; | |
private boolean allowNegative = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.text.AttributeSet; | |
import javax.swing.text.BadLocationException; | |
import javax.swing.text.DocumentFilter; | |
public class CharacterOnlyDocumentFilter extends ChainedDocumentFilter { | |
public CharacterOnlyDocumentFilter(DocumentFilter filter) { | |
super(filter); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Component; | |
import java.awt.KeyboardFocusManager; | |
import java.awt.Toolkit; | |
import javax.swing.LookAndFeel; | |
import javax.swing.UIManager; | |
import javax.swing.text.AbstractDocument; | |
import javax.swing.text.AttributeSet; | |
import javax.swing.text.BadLocationException; | |
import javax.swing.text.Document; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected Point2D pointOnEllipse(double angle, Point2D center, double width, double height) { | |
width = width / 2d; | |
height = height / 2d; | |
angle = Math.toRadians(angle); | |
double t = Math.atan(width * Math.tan(angle) / height); | |
return new Point2D.Double(center.getX() + width * Math.cos(t), center.getY() + height * Math.sin(t)); | |
} |