use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class GraphGraphicsTest method drawOldFull.
private long drawOldFull(Random rand) {
final float nodeSizeFactor = 50f;
float size = (float) canvasSize;
long begin = System.nanoTime();
for (int i = 0; i < numNodes; i++) {
float x = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
float y = rand.nextFloat() * (rand.nextBoolean() ? size : -size);
oldGraphGraphics.drawNodeFull((byte) (i % (int) OldGraphGraphics.s_last_shape), x, y, (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)), Color.blue, 1.0f + (i % 10), Color.yellow);
}
long end = System.nanoTime();
long nodeDur = end - begin;
BasicStroke edgeStroke = new BasicStroke(1f);
begin = System.nanoTime();
for (int i = 0; i < numEdges; i++) {
oldGraphGraphics.drawEdgeFull((byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.red, (byte) ((i % 7) - 8), rand.nextFloat() * (20f), Color.orange, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), oldGraphGraphics.m_noAnchors, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, Color.green, 0f);
}
end = System.nanoTime();
long duration = (end - begin) + nodeDur;
return duration;
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class OldGraphGraphics method setStroke.
private final void setStroke(final float width, final float dashLength, final int capType, final boolean ignoreCache) {
if ((!ignoreCache) && (width == m_currStrokeWidth) && (dashLength == m_currDash[0]) && (capType == m_currCapType)) {
return;
}
m_currStrokeWidth = width;
m_currDash[0] = dashLength;
m_currDash[1] = dashLength;
m_currCapType = capType;
// lots of new strokes if they constantly change.
if (m_currDash[0] == 0.0f) {
m_g2d.setStroke(new BasicStroke(width, capType, BasicStroke.JOIN_ROUND, 10.0f));
} else {
m_g2d.setStroke(new BasicStroke(width, capType, BasicStroke.JOIN_ROUND, 10.0f, m_currDash, 0.0f));
}
}
use of java.awt.BasicStroke in project AlgorithmsSolutions by Allenskoo856.
the class Draw method setPenRadius.
/**
* Sets the radius of the pen to the given size.
*
* @param r the radius of the pen
* @throws IllegalArgumentException if r is negative
*/
public void setPenRadius(double r) {
if (r < 0)
throw new IllegalArgumentException("pen radius must be positive");
penRadius = r * DEFAULT_SIZE;
BasicStroke stroke = new BasicStroke((float) penRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
// BasicStroke stroke = new BasicStroke((float) penRadius);
offscreen.setStroke(stroke);
}
use of java.awt.BasicStroke in project AlgorithmsSolutions by Allenskoo856.
the class StdDraw method setPenRadius.
/**
* Sets the radius of the pen to the specified size.
* The pen is circular, so that lines have rounded ends, and when you set the
* pen radius and draw a point, you get a circle of the specified radius.
* The pen radius is not affected by coordinate scaling.
*
* @param radius the radius of the pen
* @throws IllegalArgumentException if {@code radius} is negative
*/
public static void setPenRadius(double radius) {
if (!(radius >= 0))
throw new IllegalArgumentException("pen radius must be nonnegative");
penRadius = radius;
float scaledPenRadius = (float) (radius * DEFAULT_SIZE);
BasicStroke stroke = new BasicStroke(scaledPenRadius, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
// BasicStroke stroke = new BasicStroke(scaledPenRadius);
offscreen.setStroke(stroke);
}
use of java.awt.BasicStroke in project imagej1 by imagej.
the class OverlayBrushTool method mousePressed.
public void mousePressed(ImagePlus imp, MouseEvent e) {
ImageCanvas ic = imp.getCanvas();
float x = (float) ic.offScreenXD(e.getX());
float y = (float) ic.offScreenYD(e.getY());
xStart = x;
yStart = y;
oldWidth = width;
int ctrlMask = IJ.isMacintosh() ? InputEvent.META_MASK : InputEvent.CTRL_MASK;
int resizeMask = InputEvent.SHIFT_MASK | ctrlMask;
if ((e.getModifiers() & resizeMask) == resizeMask) {
mode = DO_RESIZE;
return;
} else if ((e.getModifiers() & ctrlMask) != 0) {
// Pick the color from image or overlay
// Limitiation: no sub-pixel accuracy here.
// Don't use awt.robot to pick the color, it is influenced by screen color calibration
int[] rgbValues = imp.flatten().getPixel((int) x, (int) y);
Color color = new Color(rgbValues[0], rgbValues[1], rgbValues[2]);
boolean altKeyDown = (e.getModifiers() & InputEvent.ALT_MASK) != 0;
if (altKeyDown)
Toolbar.setBackgroundColor(color);
else {
Toolbar.setForegroundColor(color);
if (gd != null)
options.setColor(color);
}
mode = IDLE;
return;
}
// prepare drawing
mode = UNCONSTRAINED;
path = new GeneralPath();
path.moveTo(x, y);
newPath = true;
stroke = new BasicStroke(width, BasicStroke.CAP_ROUND, /*CAP_BUTT*/
BasicStroke.JOIN_ROUND);
}
Aggregations