use of java.awt.BasicStroke in project archi by archimatetool.
the class StrokePointList method strokeList.
static PointList strokeList(PointList list, int offset) {
GeneralPath path = new GeneralPath(Path2D.WIND_NON_ZERO);
Point p = list.getPoint(0);
path.moveTo(p.x, p.y);
for (int i = 1; i < list.size(); i++) path.lineTo((p = list.getPoint(i)).x, p.y);
BasicStroke stroke = new BasicStroke(offset * 2, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f);
Shape stroked = stroke.createStrokedShape(path);
Area area = new Area(stroked);
PathIterator iter = area.getPathIterator(null, 10.0f);
PointList currentSegment = null;
PointList result = null;
int largestSegmentSize = 0;
while (!iter.isDone()) {
if (currentSegment == null)
currentSegment = new PointList(list.size() * 2);
int type = iter.currentSegment(segment);
currentSegment.addPoint(Math.round(segment[0]), Math.round(segment[1]));
iter.next();
if (type == PathIterator.SEG_CLOSE) {
if (currentSegment.size() > largestSegmentSize) {
result = currentSegment;
largestSegmentSize = currentSegment.size();
currentSegment = null;
}
}
}
return result;
}
use of java.awt.BasicStroke in project JSettlers2 by jdmonin.
the class SOCBoardPanel method drawBoard_SC_FTRI_placePort.
/**
* Scenario game option {@link SOCGameOption#K_SC_FTRI _SC_FTRI}: In board mode {@link #SC_FTRI_PLACE_PORT},
* draw the possible coastal edges where the port can be placed, and if the {@link #hilight} cursor is at
* such an edge, draw the port semi-transparently and a solid hilight line at the edge.
* @since 2.0.00
*/
private final void drawBoard_SC_FTRI_placePort(Graphics g) {
drawSeaEdgeLines(g, Color.WHITE, player.getPortMovePotentialLocations(true));
if (hilight == 0)
return;
// Draw the placing port semi-transparently if graphics support it.
// Draw hilight line with some thickness if possible.
int edge = hilight;
if (edge == -1)
edge = 0;
final SOCInventoryItem portItem = game.getPlacingItem();
if (portItem != null) {
// draw the port; similar code to drawPorts_largeBoard
final int landFacing = ((SOCBoardLarge) board).getPortFacingFromEdge(edge);
final int landHexCoord = board.getAdjacentHexToEdge(edge, landFacing);
int px = halfdeltaX * ((landHexCoord & 0xFF) - 1);
int py = halfdeltaY * (landHexCoord >> 8);
// now move 1 hex "backwards" from that hex's upper-left corner
px -= DELTAX_FACING[landFacing];
py -= DELTAY_FACING[landFacing];
final Composite prevComposite;
if (g instanceof Graphics2D) {
prevComposite = ((Graphics2D) g).getComposite();
((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
} else {
prevComposite = null;
}
drawHex(g, px, py, -portItem.itype, landFacing, -1);
if (prevComposite != null)
((Graphics2D) g).setComposite(prevComposite);
}
final Stroke prevStroke;
if (g instanceof Graphics2D) {
prevStroke = ((Graphics2D) g).getStroke();
((Graphics2D) g).setStroke(new BasicStroke(2.5f));
} else {
prevStroke = null;
}
g.setColor(Color.WHITE);
drawSeaEdgeLine(g, edge);
if (prevStroke != null)
((Graphics2D) g).setStroke(prevStroke);
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class ArrowAnnotationImpl method drawArrow.
public void drawArrow(Graphics g, boolean isPrinting) {
if ((source == null || target == null) && !usedForPreviews)
return;
if (!usedForPreviews)
updateBounds();
else
arrowLine = getArrowLine(target, source);
// Draw the line
Graphics2D g2 = (Graphics2D) g;
// Get the stroke
float border = (float) (lineWidth / 2.0);
if (!isPrinting && border < 1.0f)
border = 1.0f;
g2.setPaint(lineColor);
g2.setStroke(new BasicStroke(border, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_ROUND, 10.0f));
Line2D relativeLine = getRelativeLine(arrowLine, 0.0, 0.0, 1.0, border);
if (relativeLine != null) {
// Handle opacity
if (lineColor instanceof Color) {
int alpha = ((Color) lineColor).getAlpha();
float opacity = (float) alpha / (float) 255;
final Composite originalComposite = g2.getComposite();
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity));
g2.draw(relativeLine);
g2.setComposite(originalComposite);
} else {
g2.draw(relativeLine);
}
}
g2.setStroke(new BasicStroke(border));
// Add the head
if (sourceType != ArrowType.NONE) {
if (sourceColor == null)
sourceColor = lineColor;
GraphicsUtilities.drawArrow(g, relativeLine, ArrowEnd.SOURCE, sourceColor, sourceSize * 10.0 * getZoom(), sourceType);
}
if (targetType != ArrowType.NONE) {
if (targetColor == null)
targetColor = lineColor;
GraphicsUtilities.drawArrow(g, relativeLine, ArrowEnd.TARGET, targetColor, targetSize * 10.0 * getZoom(), targetType);
}
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class GroupAnnotationImpl method paint.
@Override
public void paint(Graphics g) {
super.paint(g);
updateBounds();
Graphics2D g2 = (Graphics2D) g;
if (isSelected()) {
g2.setColor(Color.YELLOW);
g2.setStroke(new BasicStroke(2.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f));
g2.drawRect(0, 0, (int) bounds.getWidth(), (int) bounds.getHeight());
}
/*
else {
g2.setColor(Color.BLUE);
g2.setStroke(new BasicStroke(4.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f));
g2.drawRect(-1, -1, (int)bounds.getWidth()+2, (int)bounds.getHeight()+2);
}
*/
}
use of java.awt.BasicStroke in project cytoscape-impl by cytoscape.
the class LineLayer method createChart.
@Override
protected JFreeChart createChart(final CategoryDataset dataset) {
final JFreeChart chart = ChartFactory.createLineChart(// chart title
null, // domain axis label
null, // range axis label
null, // data
dataset, PlotOrientation.VERTICAL, // 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 CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setOutlineVisible(false);
plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
plot.setBackgroundPaint(TRANSPARENT_COLOR);
plot.setBackgroundAlpha(0.0f);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
if (showRangeZeroBaseline) {
plot.setRangeZeroBaselineVisible(true);
plot.setRangeZeroBaselinePaint(axisColor);
plot.setRangeZeroBaselineStroke(new EqualDashStroke(axisWidth));
}
final BasicStroke axisStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final BasicStroke gridLineStroke = new BasicStroke(axisWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.5f, new float[] { 0.5f }, 0.0f);
plot.setRangeGridlineStroke(gridLineStroke);
final CategoryAxis domainAxis = (CategoryAxis) plot.getDomainAxis();
domainAxis.setVisible(showDomainAxis);
domainAxis.setAxisLineStroke(axisStroke);
domainAxis.setAxisLinePaint(axisColor);
domainAxis.setTickMarksVisible(true);
domainAxis.setTickMarkStroke(axisStroke);
domainAxis.setTickMarkPaint(axisColor);
domainAxis.setTickLabelsVisible(true);
domainAxis.setTickLabelFont(domainAxis.getTickLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
domainAxis.setTickLabelPaint(axisColor);
domainAxis.setCategoryLabelPositions(getCategoryLabelPosition());
domainAxis.setCategoryMargin(.1);
domainAxis.setLowerMargin(0.0);
domainAxis.setUpperMargin(0.0);
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setVisible(showRangeAxis);
rangeAxis.setAxisLineStroke(axisStroke);
rangeAxis.setAxisLinePaint(axisColor);
rangeAxis.setTickMarkStroke(axisStroke);
rangeAxis.setTickMarkPaint(axisColor);
rangeAxis.setTickLabelFont(rangeAxis.getLabelFont().deriveFont(axisFontSize).deriveFont(Font.PLAIN));
rangeAxis.setTickLabelPaint(axisColor);
rangeAxis.setLowerMargin(0.0);
rangeAxis.setUpperMargin(0.0);
// Set axis range
if (range != null && range.size() >= 2 && range.get(0) != null && range.get(1) != null) {
rangeAxis.setLowerBound(range.get(0) * 1.1);
rangeAxis.setUpperBound(range.get(1) * 1.1);
}
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseItemLabelGenerator(showItemLabels ? new CustomCategoryItemLabelGenerator(itemLabels) : null);
renderer.setBaseItemLabelsVisible(showItemLabels);
renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(itemFontSize));
renderer.setBaseItemLabelPaint(labelColor);
final BasicStroke seriesStroke = new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
final List<?> keys = dataset.getRowKeys();
if (colors != null && colors.size() >= keys.size()) {
for (int i = 0; i < keys.size(); i++) {
final Color c = colors.get(i);
renderer.setSeriesPaint(i, c);
renderer.setSeriesStroke(i, seriesStroke);
}
}
return chart;
}
Aggregations