use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class RoundedProgressBar method paintComponent.
@Override
public void paintComponent(Graphics g) {
insets = super.getInsets(insets);
final Graphics2D g2d = (Graphics2D) g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
final float x = insets.left;
final float y = insets.top;
final float w = getEffectiveWidth() - insets.right - insets.left;
final float h = HEIGHT;
bkRect.setRoundRect(x, y, w, h, CORNER_RADIUS, CORNER_RADIUS);
g2d.setColor(bgColor);
g2d.fill(bkRect);
if (indet) {
final float nw = (INDET_BAR_WIDTH * 2.0 > w) ? (w * 0.2f) : INDET_BAR_WIDTH;
final float nx = (float) (x + (w - nw) * indetPositionFunc(indetPosition));
fgRect.setRoundRect(nx, y, nw, h, CORNER_RADIUS, CORNER_RADIUS);
g2d.setColor(fgColor);
} else {
fgRect.setRoundRect(x, y, w * progress, h, CORNER_RADIUS, CORNER_RADIUS);
g2d.setColor(fgColor);
}
g2d.fill(fgRect);
bkRect.setRoundRect(x, y, w - 1, h - 1, CORNER_RADIUS, CORNER_RADIUS);
g2d.setStroke(new BasicStroke(1.0f));
g2d.setColor(borderColor);
g2d.draw(bkRect);
g2d.dispose();
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class GraphGraphics method clear.
/**
* Clears image area with background paint specified and sets an appropriate
* transformation of coordinate systems. See the class description for a
* definition of the two coordinate systems: the node coordinate system and
* the image coordinate system.
* <p>
* The background paint is not blended with colors that may already be on
* the underlying image; if a translucent color is used in the background
* paint, the underlying image itself becomes translucent.
* <p>
* It is mandatory to call this method before making the first rendering
* call.
*
* @param bgPaint
* paint to use when clearing the image before painting a new
* frame; translucency is honored, provided that the underlying
* image supports it.
* @param xCenter
* the X component of the translation transform for the frame
* about to be rendered; a node whose center is at the X
* coordinate xCenter will be rendered exactly in the middle of
* the image going across; increasing X values (in the node
* coordinate system) result in movement towards the right on the
* image.
* @param yCenter
* the Y component of the translation transform for the frame
* about to be rendered; a node whose center is at the Y
* coordinate yCenter will be rendered exactly in the middle of
* the image going top to bottom; increasing Y values (in the
* node coordinate system) result in movement towards the bottom
* on the image.
* @param scaleFactor
* the scaling that is to take place when rendering; a distance
* of 1 in node coordinates translates to a distance of
* scaleFactor in the image coordinate system (usually one unit
* in the image coordinate system equates to one pixel width).
* @exception IllegalArgumentException
* if scaleFactor is not positive.
*/
public final void clear(final Paint bgPaint, final double xCenter, final double yCenter, final double scaleFactor) {
if (m_debug) {
checkDispatchThread();
if (!(scaleFactor > 0.0d)) {
throw new IllegalArgumentException("scaleFactor is not positive");
}
}
if (m_gMinimal != null) {
m_gMinimal.dispose();
m_gMinimal = null;
}
if (m_g2d != null) {
m_g2d.dispose();
}
m_g2d = (Graphics2D) image.getGraphics();
if (m_clear) {
final Composite origComposite = m_g2d.getComposite();
m_g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
m_g2d.setPaint(bgPaint);
m_g2d.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
m_g2d.setComposite(origComposite);
}
// For detailed view, render high quality image as much as possible.
// Antialiasing is ON
m_g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Rendering quality is HIGH.
m_g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
// High quality alpha blending is ON.
m_g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
// High quality color rendering is ON.
m_g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
m_g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
m_g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
// Text antialiasing is ON.
m_g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
m_g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
m_g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
m_g2d.setStroke(new BasicStroke(0.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10.0f));
setTransform(xCenter, yCenter, scaleFactor);
m_g2d.transform(m_currXform);
m_currNativeXform.setTransform(m_g2d.getTransform());
m_cleared = true;
}
use of java.awt.BasicStroke in project org.csstudio.display.builder by kasemir.
the class HorizontalNumericAxis method paint.
/**
* {@inheritDoc}
*/
@Override
public void paint(final Graphics2D gc, final Rectangle plot_bounds) {
if (!isVisible())
return;
final Rectangle region = getBounds();
final Stroke old_width = gc.getStroke();
final Color old_fg = gc.getColor();
final Color foreground = GraphicsUtils.convert(getColor());
gc.setColor(foreground);
gc.setFont(scale_font);
super.paint(gc);
// Axis and Tick marks
gc.drawLine(region.x, region.y, region.x + region.width - 1, region.y);
computeTicks(gc);
// Major tick marks
Rectangle avoid = null;
for (MajorTick<Double> tick : ticks.getMajorTicks()) {
final int x = getScreenCoord(tick.getValue());
gc.setStroke(TICK_STROKE);
gc.drawLine(x, region.y, x, region.y + TICK_LENGTH - 1);
// Grid line
if (show_grid) {
// Dashed line
gc.setColor(grid_color);
gc.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 1, new float[] { 5 }, 0));
gc.drawLine(x, plot_bounds.y, x, plot_bounds.y + plot_bounds.height - 1);
gc.setColor(foreground);
}
gc.setStroke(old_width);
// Tick Label
avoid = drawTickLabel(gc, x, tick.getLabel(), false, avoid);
}
// Minor tick marks
for (MinorTick<Double> tick : ticks.getMinorTicks()) {
final int x = getScreenCoord(tick.getValue());
gc.drawLine(x, region.y, x, region.y + TICK_LENGTH - 1);
}
// Label: centered at bottom of region
gc.setFont(label_font);
final Rectangle metrics = GraphicsUtils.measureText(gc, getName());
gc.drawString(getName(), region.x + (region.width - metrics.width) / 2, region.y + metrics.y + region.height - metrics.height);
gc.setColor(old_fg);
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class DNodeViewTest method testSetBorder.
@Test
public void testSetBorder() {
final BasicStroke stroke = new BasicStroke(10f);
dnv1.setBorder(stroke);
// FIXME
// assertEquals(stroke, ((DGraphView)dnv1.getGraphView()).m_nodeDetails.);
// assertEquals(Float.valueOf(10f), Float.valueOf(stroke.getLineWidth()));
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class GraphGraphicsTest method drawCurrentFull.
private long drawCurrentFull(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);
currentGraphGraphics.drawNodeFull((byte) (i % (int) GraphGraphics.s_last_shape), x, y, (x + (rand.nextFloat() * nodeSizeFactor)), (y + (rand.nextFloat() * nodeSizeFactor)), Color.blue, 1.0f + (i % 10), null, 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++) {
ArrowShape arrow = ARROWS[i % 7];
currentGraphGraphics.drawEdgeFull(arrow, rand.nextFloat() * (20f), Color.red, arrow, rand.nextFloat() * (20f), Color.orange, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), currentGraphGraphics.m_noAnchors, rand.nextFloat() * (rand.nextBoolean() ? size : -size), rand.nextFloat() * (rand.nextBoolean() ? size : -size), 1f, edgeStroke, Color.green);
}
end = System.nanoTime();
long duration = (end - begin) + nodeDur;
// } catch (IOException ioe) { ioe.printStackTrace(); }
return duration;
}
Aggregations