use of java.awt.Stroke in project jdk8u_jdk by JetBrains.
the class WPathGraphics method deviceFrameRect.
/**
* Draw the bounding rectangle using transformed coordinates.
*/
@Override
protected void deviceFrameRect(int x, int y, int width, int height, Color color) {
AffineTransform deviceTransform = getTransform();
/* check if rotated or sheared */
int transformType = deviceTransform.getType();
boolean usePath = ((transformType & (AffineTransform.TYPE_GENERAL_ROTATION | AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0);
if (usePath) {
draw(new Rectangle2D.Float(x, y, width, height));
return;
}
Stroke stroke = getStroke();
if (stroke instanceof BasicStroke) {
BasicStroke lineStroke = (BasicStroke) stroke;
int endCap = lineStroke.getEndCap();
int lineJoin = lineStroke.getLineJoin();
/* check for default style and try to optimize it by
* calling the frameRect native function instead of using paths.
*/
if ((endCap == BasicStroke.CAP_SQUARE) && (lineJoin == BasicStroke.JOIN_MITER) && (lineStroke.getMiterLimit() == 10.0f)) {
float lineWidth = lineStroke.getLineWidth();
Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth);
deviceTransform.deltaTransform(penSize, penSize);
float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y));
/* transform upper left coordinate */
Point2D.Float ul_pos = new Point2D.Float(x, y);
deviceTransform.transform(ul_pos, ul_pos);
/* transform lower right coordinate */
Point2D.Float lr_pos = new Point2D.Float(x + width, y + height);
deviceTransform.transform(lr_pos, lr_pos);
float w = (float) (lr_pos.getX() - ul_pos.getX());
float h = (float) (lr_pos.getY() - ul_pos.getY());
WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();
/* use selectStylePen, if supported */
if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color) == true) {
wPrinterJob.frameRect((float) ul_pos.getX(), (float) ul_pos.getY(), w, h);
} else /* not supported, must be a Win 9x */
{
double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes());
if ((deviceLineWidth / lowerRes) < MAX_THINLINE_INCHES) {
/* use the default pen styles for thin pens. */
wPrinterJob.selectPen(deviceLineWidth, color);
wPrinterJob.frameRect((float) ul_pos.getX(), (float) ul_pos.getY(), w, h);
} else {
draw(new Rectangle2D.Float(x, y, width, height));
}
}
} else {
draw(new Rectangle2D.Float(x, y, width, height));
}
}
}
use of java.awt.Stroke in project jdk8u_jdk by JetBrains.
the class WPathGraphics method deviceDrawLine.
/**
* Draw a line using a pen created using the specified color
* and current stroke properties.
*/
@Override
protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd, Color color) {
Stroke stroke = getStroke();
if (stroke instanceof BasicStroke) {
BasicStroke lineStroke = (BasicStroke) stroke;
if (lineStroke.getDashArray() != null) {
draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd));
return;
}
float lineWidth = lineStroke.getLineWidth();
Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth);
AffineTransform deviceTransform = getTransform();
deviceTransform.deltaTransform(penSize, penSize);
float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y));
Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin);
deviceTransform.transform(begin_pos, begin_pos);
Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd);
deviceTransform.transform(end_pos, end_pos);
int endCap = lineStroke.getEndCap();
int lineJoin = lineStroke.getLineJoin();
/* check if it's a one-pixel line */
if ((end_pos.getX() == begin_pos.getX()) && (end_pos.getY() == begin_pos.getY())) {
/* endCap other than Round will not print!
* due to Windows GDI limitation, force it to CAP_ROUND
*/
endCap = BasicStroke.CAP_ROUND;
}
WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();
/* call native function that creates pen with style */
if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color)) {
wPrinterJob.moveTo((float) begin_pos.getX(), (float) begin_pos.getY());
wPrinterJob.lineTo((float) end_pos.getX(), (float) end_pos.getY());
} else /* selectStylePen is not supported, must be Win 9X */
{
/* let's see if we can use a a default pen
* if it's round end (Windows' default style)
* or it's vertical/horizontal
* or stroke is too thin.
*/
double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes());
if ((endCap == BasicStroke.CAP_ROUND) || (((xBegin == xEnd) || (yBegin == yEnd)) && (deviceLineWidth / lowerRes < MAX_THINLINE_INCHES))) {
wPrinterJob.selectPen(deviceLineWidth, color);
wPrinterJob.moveTo((float) begin_pos.getX(), (float) begin_pos.getY());
wPrinterJob.lineTo((float) end_pos.getX(), (float) end_pos.getY());
} else {
draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd));
}
}
}
}
use of java.awt.Stroke in project jmeter by apache.
the class RespTimeGraphChart method drawSample.
private void drawSample(String _title, String[] _xAxisLabels, String _yAxisTitle, String[] _legendLabels, double[][] _data, int _width, int _height, int _incrScaleYAxis, Color[] _color, Font legendFont, Graphics g) {
// define max scale y axis
double max = maxYAxisScale > 0 ? maxYAxisScale : getTopValue(findMax(_data), BigDecimal.ROUND_UP);
try {
// if the title graph is empty, we can assume some default
if (_title.length() == 0) {
//$NON-NLS-1$
_title = JMeterUtils.getResString("graph_resp_time_title");
}
this.setPreferredSize(new Dimension(_width, _height));
// replace _xAxisTitle to null (don't display x axis title)
DataSeries dataSeries = new DataSeries(_xAxisLabels, null, _yAxisTitle, _title);
// Stroke and shape line settings
Stroke[] strokes = new Stroke[_legendLabels.length];
for (int i = 0; i < _legendLabels.length; i++) {
strokes[i] = new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5f);
}
Shape[] shapes = new Shape[_legendLabels.length];
for (int i = 0; i < _legendLabels.length; i++) {
shapes[i] = pointShape;
}
LineChartProperties lineChartProperties = new LineChartProperties(strokes, shapes);
// Lines colors
Paint[] paints = new Paint[_color.length];
System.arraycopy(_color, 0, paints, 0, _color.length);
// Define chart type (line)
AxisChartDataSet axisChartDataSet = new AxisChartDataSet(_data, _legendLabels, paints, ChartType.LINE, lineChartProperties);
dataSeries.addIAxisPlotDataSet(axisChartDataSet);
ChartProperties chartProperties = new ChartProperties();
LabelAxisProperties xaxis = new LabelAxisProperties();
DataAxisProperties yaxis = new DataAxisProperties();
yaxis.setUseCommas(showGrouping);
if (legendFont != null) {
yaxis.setAxisTitleChartFont(new ChartFont(legendFont, new Color(20)));
yaxis.setScaleChartFont(new ChartFont(legendFont, new Color(20)));
xaxis.setAxisTitleChartFont(new ChartFont(legendFont, new Color(20)));
xaxis.setScaleChartFont(new ChartFont(legendFont, new Color(20)));
}
if (titleFont != null) {
chartProperties.setTitleFont(new ChartFont(titleFont, new Color(0)));
}
// Y Axis ruler
try {
// ~a tic every 50 px
double numInterval = _height / 50d;
double incrYAxis = max / numInterval;
double incrTopValue = _incrScaleYAxis;
if (_incrScaleYAxis == 0) {
incrTopValue = getTopValue(incrYAxis, BigDecimal.ROUND_HALF_UP);
}
if (incrTopValue < 1) {
// Increment cannot be < 1
incrTopValue = 1.0d;
}
yaxis.setUserDefinedScale(0, incrTopValue);
yaxis.setNumItems((int) (max / incrTopValue) + 1);
yaxis.setShowGridLines(1);
} catch (PropertyException e) {
log.warn("Exception while setting Y axis properties.", e);
}
AxisProperties axisProperties = new AxisProperties(xaxis, yaxis);
axisProperties.setXAxisLabelsAreVertical(true);
LegendProperties legendProperties = new LegendProperties();
legendProperties.setBorderStroke(null);
legendProperties.setPlacement(legendPlacement);
legendProperties.setIconBorderPaint(Color.WHITE);
legendProperties.setIconBorderStroke(new BasicStroke(0f, BasicStroke.CAP_SQUARE, BasicStroke.CAP_SQUARE));
// Manage legend placement
legendProperties.setNumColumns(LegendAreaProperties.COLUMNS_FIT_TO_IMAGE);
if (legendPlacement == LegendAreaProperties.RIGHT || legendPlacement == LegendAreaProperties.LEFT) {
legendProperties.setNumColumns(1);
}
if (legendFont != null) {
legendProperties.setFont(legendFont);
}
AxisChart axisChart = new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, _width, _height);
axisChart.setGraphics2D((Graphics2D) g);
axisChart.render();
} catch (ChartDataException | PropertyException e) {
log.warn("Exception while rendering axis chart.", e);
}
}
use of java.awt.Stroke in project jmeter by apache.
the class LineGraph method drawSample.
private void drawSample(String _title, String[] _xAxisLabels, String _xAxisTitle, String _yAxisTitle, double[][] _data, int _width, int _height, Graphics g) {
try {
if (_width == 0) {
_width = 450;
}
if (_height == 0) {
_height = 250;
}
this.setPreferredSize(new Dimension(_width, _height));
DataSeries dataSeries = new DataSeries(_xAxisLabels, _xAxisTitle, _yAxisTitle, _title);
String[] legendLabels = yAxisLabel;
Paint[] paints = this.createPaint(_data.length);
Shape[] shapes = createShapes(_data.length);
Stroke[] lstrokes = createStrokes(_data.length);
LineChartProperties lineChartProperties = new LineChartProperties(lstrokes, shapes);
AxisChartDataSet axisChartDataSet = new AxisChartDataSet(_data, legendLabels, paints, ChartType.LINE, lineChartProperties);
dataSeries.addIAxisPlotDataSet(axisChartDataSet);
ChartProperties chartProperties = new ChartProperties();
AxisProperties axisProperties = new AxisProperties();
// show the grid lines, to turn it off, set it to zero
axisProperties.getYAxisProperties().setShowGridLines(1);
axisProperties.setXAxisLabelsAreVertical(true);
// set the Y Axis to round
DataAxisProperties daxp = (DataAxisProperties) axisProperties.getYAxisProperties();
daxp.setRoundToNearest(1);
LegendProperties legendProperties = new LegendProperties();
AxisChart axisChart = new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, _width, _height);
axisChart.setGraphics2D((Graphics2D) g);
axisChart.render();
} catch (Exception e) {
log.error("Error while rendering axis chart. {}", e.getMessage());
}
}
use of java.awt.Stroke in project JMRI by JMRI.
the class DrawFrame method setDrawParams.
protected void setDrawParams() {
TargetPane targetPane = (TargetPane) _parent.getEditor().getTargetPanel();
Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10f);
targetPane.setSelectRectStroke(stroke);
targetPane.setSelectRectColor(Color.green);
}
Aggregations