use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class PieLayer method createChart.
@Override
protected JFreeChart createChart(final PieDataset dataset) {
JFreeChart chart = ChartFactory.createPieChart(// chart title
null, // data
dataset, // include legend
false, // tooltips
false, // urls
false);
chart.setAntiAlias(true);
chart.setBorderVisible(false);
chart.setBackgroundPaint(TRANSPARENT_COLOR);
chart.setBackgroundImageAlpha(0.0f);
chart.setPadding(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
final PiePlot plot = (PiePlot) chart.getPlot();
plot.setCircular(true);
plot.setStartAngle(startAngle);
plot.setDirection(rotation == Rotation.ANTICLOCKWISE ? org.jfree.util.Rotation.ANTICLOCKWISE : org.jfree.util.Rotation.CLOCKWISE);
plot.setOutlineVisible(false);
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setInteriorGap(INTERIOR_GAP);
plot.setBackgroundPaint(TRANSPARENT_COLOR);
plot.setBackgroundAlpha(0.0f);
plot.setShadowPaint(TRANSPARENT_COLOR);
plot.setShadowXOffset(0.0);
plot.setShadowYOffset(0.0);
plot.setLabelGenerator(showItemLabels ? new CustomPieSectionLabelGenerator(labels) : null);
plot.setSimpleLabels(true);
plot.setLabelFont(plot.getLabelFont().deriveFont(itemFontSize));
plot.setLabelBackgroundPaint(TRANSPARENT_COLOR);
plot.setLabelOutlinePaint(TRANSPARENT_COLOR);
plot.setLabelShadowPaint(TRANSPARENT_COLOR);
plot.setLabelPaint(labelColor);
final BasicStroke stroke = new BasicStroke(borderWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final List<?> keys = dataset.getKeys();
for (int i = 0; i < keys.size(); i++) {
final String k = (String) keys.get(i);
final Color c = colors.size() > i ? colors.get(i) : DEFAULT_ITEM_BG_COLOR;
plot.setSectionPaint(k, c);
plot.setSectionOutlinePaint(k, borderWidth > 0 ? borderColor : TRANSPARENT_COLOR);
plot.setSectionOutlineStroke(k, stroke);
}
return chart;
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class ArrowIcon method paintIcon.
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(c.getForeground());
double x1 = x;
double y1 = y + height / 2.0;
double x2 = x1 + width;
double y2 = y1;
// If shape is not defined, treat as no-arrow.
if (value != null) {
final AffineTransform af = new AffineTransform();
g2d.setStroke(new BasicStroke(2.0f));
Shape shape = value;
final double minx = shape.getBounds2D().getMinX();
final double miny = shape.getBounds2D().getMinY();
// Adjust position if it is NOT in first quadrant.
if (minx < 0) {
af.setToTranslation(Math.abs(minx), 0);
shape = af.createTransformedShape(shape);
}
if (miny < 0) {
af.setToTranslation(0, Math.abs(miny));
shape = af.createTransformedShape(shape);
}
final double shapeWidth = shape.getBounds2D().getWidth();
final double shapeHeight = shape.getBounds2D().getHeight() * 2;
final double originalXYRatio = shapeWidth / shapeHeight;
final double xRatio = (width / 3) / shapeWidth;
final double yRatio = height / shapeHeight;
af.setToScale(xRatio * originalXYRatio, yRatio);
shape = af.createTransformedShape(shape);
Rectangle2D bound = shape.getBounds2D();
af.setToTranslation(x2 - bound.getWidth(), y2 - bound.getHeight() / 2);
shape = af.createTransformedShape(shape);
g2d.fill(shape);
x2 = shape.getBounds2D().getCenterX() - 2;
}
g2d.setStroke(EDGE_STROKE);
g2d.draw(new Line2D.Double(x1, y1, x2, y2));
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class ContinuousTrackRenderer method paintComponent.
@Override
protected void paintComponent(Graphics gfx) {
trackHeight = slider.getHeight() - 100;
arrowBarPosition = trackHeight + 50;
// AA on
Graphics2D g = (Graphics2D) gfx;
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
double minValue = tracer.getMin(vp);
double maxValue = tracer.getMax(vp);
int thumb_width = 12;
int track_width = slider.getWidth() - thumb_width;
g.translate(thumb_width / 2, 12);
// get the list of tumbs
List<Thumb<V>> stops = slider.getModel().getSortedThumbs();
int numPoints = stops.size();
// set up the data for the gradient
float[] fractions = new float[numPoints];
final Double[] doubleValues = new Double[numPoints];
int i = 0;
values.clear();
values.add(below);
values.add(above);
for (Thumb<V> thumb : stops) {
doubleValues[i] = thumb.getObject().doubleValue();
fractions[i] = thumb.getPosition();
values.add(thumb.getObject());
i++;
}
for (V val : values) {
if (min >= val.floatValue())
min = val.floatValue();
if (max <= val.floatValue())
max = val.floatValue();
}
// Draw arrow bar
g.setStroke(new BasicStroke(1.0f));
g.setColor(LABEL_COLOR);
g.drawLine(0, arrowBarPosition, track_width, arrowBarPosition);
Polygon arrow = new Polygon();
arrow.addPoint(track_width, arrowBarPosition);
arrow.addPoint(track_width - 20, arrowBarPosition - 8);
arrow.addPoint(track_width - 20, arrowBarPosition);
g.fill(arrow);
g.setColor(DISABLED_LABEL_COLOR);
g.drawLine(0, arrowBarPosition, 15, arrowBarPosition - 30);
g.drawLine(15, arrowBarPosition - 30, 25, arrowBarPosition - 30);
g.setFont(SMALL_FONT);
g.drawString("Min=" + minValue, 28, arrowBarPosition - 25);
g.drawLine(track_width, arrowBarPosition, track_width - 15, arrowBarPosition + 30);
g.drawLine(track_width - 15, arrowBarPosition + 30, track_width - 25, arrowBarPosition + 30);
final String maxStr = "Max=" + maxValue;
int strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), maxStr);
g.drawString(maxStr, track_width - strWidth - 26, arrowBarPosition + 35);
g.setFont(DEF_FONT);
g.setColor(LABEL_COLOR);
strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), title);
g.drawString(title, (track_width / 2) - (strWidth / 2), arrowBarPosition + 35);
/*
* If no points, just draw empty box.
*/
if (numPoints == 0) {
g.setColor(BORDER_COLOR);
g.setStroke(new BasicStroke(1.5f));
g.drawRect(0, 5, track_width, trackHeight);
return;
}
g.setStroke(new BasicStroke(1.0f));
/*
* Fill background
*/
g.setColor(BACKGROUND_COLOR);
g.fillRect(0, 5, track_width, trackHeight);
int newX = 0;
int lastY = 0;
Point2D p1 = new Point2D.Float(0, 5);
Point2D p2 = new Point2D.Float(0, 5);
for (i = 0; i < doubleValues.length; i++) {
newX = (int) (track_width * (fractions[i] / 100));
p2.setLocation(newX, 5);
int newY = (5 + trackHeight) - (int) ((doubleValues[i].floatValue() / max) * trackHeight);
valueArea.reset();
g.setColor(VALUE_AREA_COLOR);
if (i == 0) {
int h = (5 + trackHeight) - (int) ((below.floatValue() / max) * trackHeight);
g.fillRect(0, h, newX, (int) ((below.floatValue() / max) * trackHeight));
g.setColor(TRACK_COLOR);
g.fillRect(-5, h - 5, 10, 10);
belowSquare = new Point(0, h);
} else {
valueArea.addPoint((int) p1.getX(), lastY);
valueArea.addPoint(newX, newY);
valueArea.addPoint(newX, trackHeight + 5);
valueArea.addPoint((int) p1.getX(), trackHeight + 5);
g.fill(valueArea);
}
for (int j = 0; j < stops.size(); j++) {
final V tValue = slider.getModel().getThumbAt(j).getObject();
if (tValue.doubleValue() == doubleValues[i].doubleValue()) {
Point newPoint = new Point(newX, newY);
if (verticesList.containsValue(newPoint) == false)
verticesList.put(j, new Point(newX, newY));
break;
}
}
lastY = newY;
g.setColor(LABEL_COLOR);
g.setStroke(new BasicStroke(1.5f));
g.setFont(SMALL_FONT);
int numberWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), doubleValues[i].toString());
g.setColor(LABEL_COLOR);
if (fractions[i] < 10) {
g.drawLine(newX, newY, newX + 15, newY - 35);
g.drawString(doubleValues[i].toString(), newX + numberWidth, newY - 48);
} else {
g.drawLine(newX, newY, newX - 15, newY + 35);
g.drawString(doubleValues[i].toString(), newX - (numberWidth + 5), newY + 48);
}
g.setColor(LABEL_COLOR);
g.setFont(SMALL_FONT);
Double curPositionValue = ((Double) (((fractions[i] / 100) * tracer.getRange(vp)) + minValue)).doubleValue();
String valueString = String.format("%.4f", curPositionValue);
int flipLimit = 90;
int borderVal = track_width - newX;
if (((i % 2) == 0) && (flipLimit < borderVal)) {
g.drawLine(newX, arrowBarPosition, newX + 20, arrowBarPosition - 15);
g.drawLine(newX + 20, arrowBarPosition - 15, newX + 30, arrowBarPosition - 15);
g.setColor(LABEL_COLOR);
g.drawString(valueString, newX + 33, arrowBarPosition - 11);
} else if (((i % 2) == 1) && (flipLimit < borderVal)) {
g.drawLine(newX, arrowBarPosition, newX + 20, arrowBarPosition + 15);
g.drawLine(newX + 20, arrowBarPosition + 15, newX + 30, arrowBarPosition + 15);
g.setColor(LABEL_COLOR);
g.drawString(valueString, newX + 33, arrowBarPosition + 19);
} else if (((i % 2) == 0) && (flipLimit >= borderVal)) {
g.drawLine(newX, arrowBarPosition, newX - 20, arrowBarPosition - 15);
g.drawLine(newX - 20, arrowBarPosition - 15, newX - 30, arrowBarPosition - 15);
g.setColor(LABEL_COLOR);
g.drawString(valueString, newX - 90, arrowBarPosition - 11);
} else {
g.drawLine(newX, arrowBarPosition, newX - 20, arrowBarPosition + 15);
g.drawLine(newX - 20, arrowBarPosition + 15, newX - 30, arrowBarPosition + 15);
g.setColor(LABEL_COLOR);
g.drawString(valueString, newX - 90, arrowBarPosition + 19);
}
g.setColor(LABEL_COLOR);
g.fillOval(newX - 3, arrowBarPosition - 3, 6, 6);
p1.setLocation(p2);
}
p2.setLocation(track_width, 5);
g.setColor(VALUE_AREA_COLOR);
int h = (5 + trackHeight) - (int) ((above.floatValue() / max) * trackHeight);
g.fillRect((int) p1.getX(), h, track_width - (int) p1.getX(), (int) ((above.floatValue() / max) * trackHeight));
g.setColor(TRACK_COLOR);
g.fillRect(track_width - 5, h - 5, 10, 10);
aboveSquare = new Point(track_width, h);
/*
* Finally, draw border line (rectangle)
*/
g.setColor(BORDER_COLOR);
g.setStroke(new BasicStroke(1.5f));
g.drawRect(0, 5, track_width, trackHeight);
g.setColor(TRACK_COLOR);
g.setStroke(new BasicStroke(1.5f));
for (Integer key : verticesList.keySet()) {
Point p = verticesList.get(key);
if (clickFlag) {
int diffX = Math.abs(p.x - (curPoint.x - 6));
int diffY = Math.abs(p.y - (curPoint.y - 12));
if (((diffX < 6) && (diffY < 6)) || (key == selectedIdx)) {
g.setColor(FOCUS_COLOR);
g.setStroke(new BasicStroke(2.5f));
} else {
g.setColor(TRACK_COLOR);
g.setStroke(new BasicStroke(1.5f));
}
}
g.drawRect(p.x - 5, p.y - 5, 10, 10);
}
/*
* Draw below & above
*/
g.translate(-THUMB_WIDTH / 2, -12);
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class JRangeSlider method paintTrack.
private void paintTrack(final Graphics g, final Color color1, final Color color2, final Color borderColor, int x, int y, int w, int h) {
final Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
final Point p1 = orientation == VERTICAL ? new Point(x, y) : new Point(x, y);
final Point p2 = orientation == VERTICAL ? new Point(x + w, y) : new Point(x, y + h);
final Paint p = new GradientPaint(p1, color1, p2, color2);
final int arc = 4;
// Background
g2.setPaint(p);
g2.fillRoundRect(x, y, w, h, arc, arc);
// Border
g2.setColor(borderColor);
g2.setStroke(new BasicStroke(1));
g2.drawRoundRect(x, y, w, h, arc, arc);
g2.dispose();
}
use of java.awt.BasicStroke in project org.csstudio.display.builder by kasemir.
the class JFXRepresentation method updateBackground.
/**
* Update background, using background color and grid information from model
*/
private void updateBackground() {
final WidgetColor background = model.propBackgroundColor().getValue();
// Setting the "-fx-background:" of the root node propagates
// to all child nodes in the scene graph.
//
// if (isEditMode())
// model_root.setStyle("-fx-background: linear-gradient(from 0px 0px to 10px 10px, reflect, #D2A2A2 48%, #D2A2A2 2%, #D2D2A2 48% #D2D2A2 2%)");
// else
// model_root.setStyle("-fx-background: " + JFXUtil.webRGB(background));
//
// In edit mode, this results in error messages because the linear-gradient doesn't "work" for all nodes:
//
// javafx.scene.CssStyleHelper (calculateValue)
// Caught java.lang.ClassCastException: javafx.scene.paint.LinearGradient cannot be cast to javafx.scene.paint.Color
// while converting value for
// '-fx-background-color' from rule '*.text-input' in stylesheet ..jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
// '-fx-effect' from rule '*.scroll-bar:vertical>*.increment-button>*.increment-arrow' in StyleSheet ... jfxrt.jar!/com/sun/javafx/scene/control/skin/modena/modena.bss
// '-fx-effect' from rule '*.scroll-bar:vertical>*.decrement-button>*.decrement-arrow' in stylesheet ... modena.bss
// '-fx-effect' from rule '*.scroll-bar:horizontal>*.increment-button>*.increment-arrow' in stylesheet ... modena.bss
//
// In the runtime, the background color style is applied to for example the TextEntryRepresentation,
// overriding its jfx_node.setBackground(..) setting.
// Setting just the scroll body background to a plain color or grid image provides basic color control.
// In edit mode, the horiz_bound, vert_bound lines and grid provide sufficient
// visual indication of the display size.
final Color backgroundColor = new Color(background.getRed(), background.getGreen(), background.getBlue());
final boolean gridVisible = isEditMode() ? model.propGridVisible().getValue() : false;
final int gridStepX = model.propGridStepX().getValue(), gridStepY = model.propGridStepY().getValue();
final WidgetColor grid_rgb = model.propGridColor().getValue();
final Color gridColor = new Color(grid_rgb.getRed(), grid_rgb.getGreen(), grid_rgb.getBlue());
final BufferedImage image = new BufferedImage(gridStepX, gridStepY, BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2d = image.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2d.setBackground(backgroundColor);
g2d.clearRect(0, 0, gridStepX, gridStepY);
if (gridVisible) {
g2d.setColor(gridColor);
g2d.setStroke(new BasicStroke(GRID_LINE_WIDTH));
g2d.drawLine(0, 0, gridStepX, 0);
g2d.drawLine(0, 0, 0, gridStepY);
}
final WritableImage wimage = new WritableImage(gridStepX, gridStepY);
SwingFXUtils.toFXImage(image, wimage);
final ImagePattern pattern = new ImagePattern(wimage, 0, 0, gridStepX, gridStepY, false);
widget_parent.setBackground(new Background(new BackgroundFill(pattern, CornerRadii.EMPTY, Insets.EMPTY)));
}
Aggregations