List of usage examples for java.awt BasicStroke BasicStroke
public BasicStroke(float width)
From source file:application.BrokersMouseListener.java
@Override public void graphClicked(Object arg0, MouseEvent arg1) { //Reset the selected variable for all the broker ListIterator<Broker> it = state.getBrokersList(); while (it.hasNext()) { it.next().resetSelected();//from w ww . j a va 2 s .com } Broker broker = (Broker) arg0; //SET the selected variable for THE SPECIFIC broker broker.setSelected(); Transformer<Broker, Paint> vertexPaint = new Transformer<Broker, Paint>() { public Paint transform(Broker b) { if (b.selected()) { return Color.GREEN; } return Color.GRAY; } }; //Reset the selected variable for all the link it = state.getBrokersList(); while (it.hasNext()) { Broker b = it.next(); ListIterator<Interface> intit = b.getInterfaces(); while (intit.hasNext()) { Interface ix = intit.next(); ix.getLink().resetSelected(); } } //SET the selected variable for THE SPECIFIC links it = state.getBrokersList(); while (it.hasNext()) { Broker b = it.next(); ListIterator<Interface> intit = b.getInterfaces(); if (b.equals(broker)) { while (intit.hasNext()) { Interface ix = intit.next(); ix.getLink().setSelected(); } } else { while (intit.hasNext()) { Interface ix = intit.next(); ix.getLink().setSelectedBcastFunction(state.getBrokerPosition(broker)); } } } Transformer<Link, Stroke> edgeStrokeTransformer = new Transformer<Link, Stroke>() { public Stroke transform(Link link) { if (link.selected()) { final Stroke edgeStroke = new BasicStroke(2); return edgeStroke; } else { float[] dot = { 1.0f, 3.0f }; final Stroke edgeStroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, dot, 0f); return edgeStroke; } } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); vv.getRenderContext().setEdgeStrokeTransformer(edgeStrokeTransformer); //((FRLayout)layout).initialize(); //((FRLayout)layout).step(); vv.repaint(); }
From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialScale.java
/** * Draws the scale on the dial plot./*from ww w.j a va 2 s.c o m*/ * * @param g2 the graphics target (<code>null</code> not permitted). * @param plot the dial plot (<code>null</code> not permitted). * @param frame the reference frame that is used to construct the * geometry of the plot (<code>null</code> not permitted). * @param view the visible part of the plot (<code>null</code> not * permitted). */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.getTickRadius(), this.getTickRadius()); Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getMajorTickLength(), this.getTickRadius() - this.getMajorTickLength()); Rectangle2D arcRectMinor = arcRect; if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) { arcRectMinor = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getMinorTickLength(), this.getTickRadius() - this.getMinorTickLength()); } Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getTickLabelOffset(), this.getTickRadius() - this.getTickLabelOffset()); boolean firstLabel = true; Arc2D arc = new Arc2D.Double(); Line2D workingLine = new Line2D.Double(); Stroke arcStroke = new BasicStroke(0.75f); for (double v = this.getLowerBound(); v <= this.getUpperBound(); v += this.getMajorTickIncrement()) { arc.setArc(arcRect, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN); g2.setPaint(this.getMajorTickPaint()); g2.setStroke(arcStroke); g2.draw(arc); Point2D pt0 = arc.getEndPoint(); arc.setArc(arcRectMajor, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN); Point2D pt1 = arc.getEndPoint(); g2.setPaint(this.getMajorTickPaint()); g2.setStroke(this.getMajorTickStroke()); workingLine.setLine(pt0, pt1); g2.draw(workingLine); arc.setArc(arcRectForLabels, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN); Point2D pt2 = arc.getEndPoint(); if (this.getTickLabelsVisible()) { if (!firstLabel || this.getFirstTickLabelVisible()) { g2.setFont(this.getTickLabelFont()); TextUtilities.drawAlignedString(this.getTickLabelFormatter().format(v), g2, (float) pt2.getX(), (float) pt2.getY(), TextAnchor.CENTER); } } firstLabel = false; // now do the minor tick marks if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) { double minorTickIncrement = this.getMajorTickIncrement() / (this.getMinorTickCount() + 1); for (int i = 0; i < this.getMinorTickCount(); i++) { double vv = v + ((i + 1) * minorTickIncrement); if (vv >= this.getUpperBound()) { break; } double angle = valueToAngle(vv); arc.setArc(arcRect, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN); pt0 = arc.getEndPoint(); arc.setArc(arcRectMinor, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN); Point2D pt3 = arc.getEndPoint(); g2.setStroke(this.getMinorTickStroke()); g2.setPaint(this.getMinorTickPaint()); workingLine.setLine(pt0, pt3); g2.draw(workingLine); } } } }
From source file:uom.research.thalassemia.util.PieChartCreator.java
/** * Creates a chart./* w ww . ja v a 2 s .com*/ * * @param dataset the dataset. * * @return A chart. */ private JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart(title, // chart title dataset, // data true, // no legend true, // tooltips false // no URL generation ); // set a custom background for the chart chart.setBackgroundPaint( new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY)); // customise the title position and font TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); // use gradients and white borders for the section colours int itemIndex = 0; for (Object col : pieDataset.getKeys()) { plot.setSectionPaint(col.toString(), gradientPaints[itemIndex]); if (itemIndex == pieDataset.getItemCount() - 1) { itemIndex = 0; } itemIndex++; } plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); // customise the section label appearance plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); return chart; }
From source file:eu.udig.tools.jgrass.profile.ProfileView.java
public void addStopLine(double x) { DecimalFormat formatter = new DecimalFormat("0.0"); // add a category marker ValueMarker marker = new ValueMarker(x, Color.red, new BasicStroke(1.0f)); marker.setAlpha(0.6f);//from ww w . j ava2s .co m marker.setLabel(formatter.format(x)); marker.setLabelFont(new Font("Dialog", Font.PLAIN, 8)); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); marker.setLabelOffset(new RectangleInsets(2, 5, 2, 5)); plot.addDomainMarker(marker, Layer.BACKGROUND); markers.add(marker); }
From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialScale.java
/** * Draws the scale on the dial plot.//from w w w . java2 s .c o m * * @param g2 the graphics target (<code>null</code> not permitted). * @param plot the dial plot (<code>null</code> not permitted). * @param frame the reference frame that is used to construct the * geometry of the plot (<code>null</code> not permitted). * @param view the visible part of the plot (<code>null</code> not * permitted). */ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Rectangle2D arcRect = DialPlot.rectangleByRadius(frame, this.getTickRadius(), this.getTickRadius()); Rectangle2D arcRectMajor = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getMajorTickLength(), this.getTickRadius() - this.getMajorTickLength()); Rectangle2D arcRectMinor = arcRect; if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) { arcRectMinor = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getMinorTickLength(), this.getTickRadius() - this.getMinorTickLength()); } Rectangle2D arcRectForLabels = DialPlot.rectangleByRadius(frame, this.getTickRadius() - this.getTickLabelOffset(), this.getTickRadius() - this.getTickLabelOffset()); boolean firstLabel = true; Arc2D arc = new Arc2D.Double(); Line2D workingLine = new Line2D.Double(); Stroke arcStroke = new BasicStroke(0.75f); for (double v = this.getLowerBound(); v <= this.getUpperBound(); v += this.getMajorTickIncrement()) { arc.setArc(arcRect, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN); g2.setPaint(this.getMajorTickPaint()); g2.setStroke(arcStroke); g2.draw(arc); Point2D pt0 = arc.getEndPoint(); arc.setArc(arcRectMajor, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN); Point2D pt1 = arc.getEndPoint(); g2.setPaint(this.getMajorTickPaint()); g2.setStroke(this.getMajorTickStroke()); workingLine.setLine(pt0, pt1); g2.draw(workingLine); arc.setArc(arcRectForLabels, this.getStartAngle(), valueToAngle(v) - this.getStartAngle(), Arc2D.OPEN); Point2D pt2 = arc.getEndPoint(); if (this.getTickLabelsVisible()) { if (!firstLabel || this.getFirstTickLabelVisible()) { g2.setFont(this.getTickLabelFont()); TextUtilities.drawAlignedString(this.getTickLabelFormatter().format(v), g2, (float) pt2.getX(), (float) pt2.getY(), TextAnchor.CENTER); } } firstLabel = false; // now do the minor tick marks if (this.getMinorTickCount() > 0 && this.getMinorTickLength() > 0.0) { double minorTickIncrement = this.getMajorTickIncrement() / (this.getMinorTickCount() + 1); for (int i = 0; i < this.getMinorTickCount(); i++) { double vv = v + ((i + 1) * minorTickIncrement); if (vv >= this.getUpperBound()) { break; } double angle = valueToAngle(vv); arc.setArc(arcRect, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN); pt0 = arc.getEndPoint(); arc.setArc(arcRectMinor, this.getStartAngle(), angle - this.getStartAngle(), Arc2D.OPEN); Point2D pt3 = arc.getEndPoint(); g2.setStroke(this.getMinorTickStroke()); g2.setPaint(this.getMinorTickPaint()); workingLine.setLine(pt0, pt3); g2.draw(workingLine); } } } }
From source file:org.jfree.chart.demo.selection.SelectionDemo2.java
private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension<XYCursor> ext) { JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo2", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainPannable(true);//from ww w. j a v a 2 s. c o m plot.setRangePannable(true); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer(); r.setSeriesFillPaint(0, r.lookupSeriesPaint(0)); r.setSeriesFillPaint(1, r.lookupSeriesPaint(1)); r.setSeriesFillPaint(2, r.lookupSeriesPaint(2)); r.setUseFillPaint(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setTickMarkInsideLength(2.0f); domainAxis.setTickMarkOutsideLength(2.0f); domainAxis.setMinorTickMarksVisible(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setTickMarkInsideLength(2.0f); rangeAxis.setTickMarkOutsideLength(2.0f); rangeAxis.setMinorTickMarksVisible(true); //add selection specific rendering IRSUtilities.setSelectedItemFillPaint(r, ext, Color.white); //register plot as selection change listener ext.addChangeListener(plot); return chart; }
From source file:playground.dgrether.linkanalysis.DgCountPerIterationGraph.java
public JFreeChart createChart() { XYPlot plot = new XYPlot(); ValueAxis xAxis = this.axisBuilder.createValueAxis("Iteration"); xAxis.setRange(this.controllerConfig.getFirstIteration(), this.controllerConfig.getLastIteration() + 2); ValueAxis yAxis = this.axisBuilder.createValueAxis("Trips"); // yAxis.setRange(-0.05, 0.3); // xAxis.setVisible(false); // xAxis.setFixedAutoRange(1.0); plot.setDomainAxis(xAxis);// w w w . ja v a2s.c o m plot.setRangeAxis(yAxis); plot.setDataset(0, this.dataset); DgColorScheme colorScheme = new DgColorScheme(); XYItemRenderer renderer2; renderer2 = new XYLineAndShapeRenderer(true, true); for (int i = 0; i < this.dataset.getSeriesCount(); i++) { renderer2.setSeriesItemLabelsVisible(i, true); renderer2.setSeriesOutlineStroke(i, new BasicStroke(3.0f)); renderer2.setSeriesStroke(i, new BasicStroke(2.0f)); renderer2.setSeriesPaint(i, colorScheme.getColor(i + 1, "a")); } // renderer2.setSeriesItemLabelGenerator(0, this.labelGenerator); // renderer2.setSeriesStroke(1, new BasicStroke(2.0f)); // renderer2.setSeriesOutlineStroke(1, new BasicStroke(3.0f)); // renderer2.setSeriesPaint(1, colorScheme.getColor(2, "a")); plot.setRenderer(0, renderer2); JFreeChart chart = new JFreeChart("", plot); chart.setBackgroundPaint(ChartColor.WHITE); chart.getLegend().setItemFont(this.axisBuilder.getAxisFont()); chart.setTextAntiAlias(true); // chart.removeLegend(); return chart; }
From source file:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotFrame.java
public IntensityPlotFrame(ParameterSet parameters) { PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue()[0]; String title = "Intensity plot [" + peakList + "]"; String xAxisLabel = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue().toString(); String yAxisLabel = parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue().toString(); // create dataset dataset = new IntensityPlotDataset(parameters); // create new JFreeChart logger.finest("Creating new chart instance"); Object xAxisValueSource = parameters.getParameter(IntensityPlotParameters.xAxisValueSource).getValue(); boolean isCombo = (xAxisValueSource instanceof ParameterWrapper) && (((ParameterWrapper) xAxisValueSource).getParameter() instanceof ComboParameter); if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) { chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false);/* w w w .j a v a 2s. c o m*/ CategoryPlot plot = (CategoryPlot) chart.getPlot(); // set renderer StatisticalLineAndShapeRenderer renderer = new StatisticalLineAndShapeRenderer(false, true); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator CategoryToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); } else { chart = ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYErrorRenderer renderer = new XYErrorRenderer(); renderer.setBaseStroke(new BasicStroke(2)); plot.setRenderer(renderer); plot.setBackgroundPaint(Color.white); // set tooltip generator XYToolTipGenerator toolTipGenerator = new IntensityPlotTooltipGenerator(); renderer.setBaseToolTipGenerator(toolTipGenerator); } chart.setBackgroundPaint(Color.white); // create chart JPanel ChartPanel chartPanel = new ChartPanel(chart); add(chartPanel, BorderLayout.CENTER); IntensityPlotToolBar toolBar = new IntensityPlotToolBar(this); add(toolBar, BorderLayout.EAST); // disable maximum size (we don't want scaling) chartPanel.setMaximumDrawWidth(Integer.MAX_VALUE); chartPanel.setMaximumDrawHeight(Integer.MAX_VALUE); // set title properties TextTitle chartTitle = chart.getTitle(); chartTitle.setMargin(5, 0, 0, 0); chartTitle.setFont(titleFont); LegendTitle legend = chart.getLegend(); legend.setItemFont(legendFont); legend.setBorder(0, 0, 0, 0); Plot plot = chart.getPlot(); // set shape provider IntensityPlotDrawingSupplier shapeSupplier = new IntensityPlotDrawingSupplier(); plot.setDrawingSupplier(shapeSupplier); // set y axis properties NumberAxis yAxis; if (plot instanceof CategoryPlot) yAxis = (NumberAxis) ((CategoryPlot) plot).getRangeAxis(); else yAxis = (NumberAxis) ((XYPlot) plot).getRangeAxis(); NumberFormat yAxisFormat = MZmineCore.getConfiguration().getIntensityFormat(); if (parameters.getParameter(IntensityPlotParameters.yAxisValueSource).getValue() == YAxisValueSource.RT) yAxisFormat = MZmineCore.getConfiguration().getRTFormat(); yAxis.setNumberFormatOverride(yAxisFormat); setTitle(title); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setBackground(Color.white); pack(); }
From source file:org.jfree.expdemo.SelectionDemo2.java
private static JFreeChart createChart(XYDataset dataset, DatasetSelectionExtension ext) { JFreeChart chart = ChartFactory.createScatterPlot("SelectionDemo2", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setNoDataMessage("NO DATA"); plot.setDomainPannable(true);//w w w. j a v a 2 s . co m plot.setRangePannable(true); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlineStroke(new BasicStroke(0.0f)); plot.setRangeGridlineStroke(new BasicStroke(0.0f)); plot.setDomainMinorGridlinesVisible(true); plot.setRangeMinorGridlinesVisible(true); XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer(); r.setSeriesFillPaint(0, r.lookupSeriesPaint(0)); r.setSeriesFillPaint(1, r.lookupSeriesPaint(1)); r.setSeriesFillPaint(2, r.lookupSeriesPaint(2)); r.setUseFillPaint(true); NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); domainAxis.setTickMarkInsideLength(2.0f); domainAxis.setTickMarkOutsideLength(2.0f); domainAxis.setMinorTickCount(2); domainAxis.setMinorTickMarksVisible(true); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setTickMarkInsideLength(2.0f); rangeAxis.setTickMarkOutsideLength(2.0f); rangeAxis.setMinorTickCount(2); rangeAxis.setMinorTickMarksVisible(true); //add selection specific rendering IRSUtilities.setSelectedItemFillPaint(r, ext, Color.white); //register plot as selection change listener ext.addSelectionChangeListener(plot); return chart; }
From source file:storybook.ui.chart.jfreechart.ChartUtil.java
public static Marker getDateMarker(Date paramDate, String paramString, boolean paramBoolean) { double d = paramDate.getTime(); ValueMarker localValueMarker = new ValueMarker(d, Color.red, new BasicStroke(0.3F)); localValueMarker.setLabel(paramString); localValueMarker.setLabelFont(new Font("SansSerif", 2, 11)); localValueMarker.setLabelAnchor(RectangleAnchor.BOTTOM); if (paramBoolean) { localValueMarker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } else {/*from ww w . ja v a 2 s .c o m*/ localValueMarker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT); } return localValueMarker; }