This file contains 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 static enum Corner { | |
NW(Cursor.NW_RESIZE_CURSOR, 0, 0), | |
SW(Cursor.SW_RESIZE_CURSOR, 0, 1), | |
SE(Cursor.SE_RESIZE_CURSOR, 1, 1), | |
NE(Cursor.NE_RESIZE_CURSOR, 1, 0); | |
// ... | |
} |
This file contains 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
/** Perform an {@link Consumer action} with a disposable {@link Graphics2D graphics context}. */ | |
public static void context(BiConsumer<Throwable,String> handler, | |
Graphics graphics, Consumer<Graphics2D> action) { | |
Graphics2D g = (Graphics2D) graphics.create(); | |
try { | |
action.accept(g); | |
} catch (Throwable t) { | |
handler.accept(t, "Error executing graphics context action"); | |
} finally { | |
g.dispose(); |
This file contains 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
@Override | |
public Point2D apply(Point2D src) { | |
double ox = sw / 2d; | |
double oy = sh / 2d; | |
double u = Point2D.distance(0d, 0d, ox / 2d, oy / 2d); | |
double r = Point2D.distance(ox, oy, src.getX(), src.getY()) / u; | |
double scale = 1d / (r * r); | |
double x = (src.getX() - ox) / u; | |
double y = (src.getY() - oy) / u; |
This file contains 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
AffineTransform getTransform(); | |
default Point2D apply(Point2D src) { | |
return getTransform().transform(src, null); | |
} |
This file contains 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
// Transform unit square to view space | |
double x0 = centre.getX() - (size.getWidth() / 2d / scale); | |
double y0 = centre.getY() - (size.getHeight() / 2d / scale); | |
AffineTransform view = AffineTransform.getScaleInstance(scale, scale); | |
view.translate(-x0, -y0); | |
// Calculate grid position | |
double spacing = config.getMaxGrid() / scale; | |
double mx = centre.getX() - (size.getWidth() / 2d / scale) - (size.getWidth() / 2d); | |
double my = centre.getY() - (size.getHeight() / 2d / scale) - (size.getHeight() / 2d); |
This file contains 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
chooser.setPreviewPanel(new JPanel()); | |
Arrays.asList(chooser.getChooserPanels()).stream() | |
.filter(c -> c.getDisplayName().toLowerCase(Locale.ROOT).contains("swatch")) | |
.findFirst() | |
.ifPresent(c -> { | |
chooser.removeChooserPanel(c); | |
}); |
This file contains 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 static enum Task { ITERATE, PLOT_DENSITY } |
This file contains 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
private Multimap<Task, Future<?>> tasks = Multimaps.synchronizedListMultimap( | |
Multimaps.newListMultimap(Maps.newHashMap(), Lists::newArrayList)); | |
private ConcurrentMap<Future<?>, AtomicBoolean> state = Maps.newConcurrentMap(); |
This file contains 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 Runnable task(AtomicBoolean cancel, Runnable task) { | |
return () -> { | |
while (latch.get()); // Wait until latch released | |
long initial = token.get(); | |
do { | |
task.run(); | |
} while (!cancel.get() && token.get() == initial); | |
}; | |
} |
This file contains 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
// Evaluate the function twice, first for (x,y) position | |
// and then for hue/saturation color space | |
current = points.updateAndGet(0, p -> function.apply(f.apply(p))); | |
old = points.getAndUpdate(1, p -> function.apply(f.apply(p))); |