List of usage examples for java.awt BasicStroke BasicStroke
public BasicStroke(float width)
From source file:org.uncommons.watchmaker.swing.evolutionmonitor.JVMView.java
private JFreeChart createHeapChart(double maxMemory) { TimeSeriesCollection dataSet = new TimeSeriesCollection(); dataSet.addSeries(memoryUsageSeries); dataSet.addSeries(heapSizeSeries);/* w ww.ja v a 2 s. c o m*/ JFreeChart chart = ChartFactory.createXYAreaChart("JVM Heap", "Time", "Megabytes", dataSet, PlotOrientation.VERTICAL, true, // Legend. false, // Tooltips. false); DateAxis timeAxis = new DateAxis("Time"); timeAxis.setLowerMargin(0); timeAxis.setUpperMargin(0); chart.getXYPlot().setDomainAxis(timeAxis); chart.getXYPlot().getRangeAxis().setLowerBound(0); chart.getXYPlot().getRangeAxis().setUpperBound(maxMemory * 1.1); // Add 10% to leave room for marker. // Add a horizontal marker to indicate the heap growth limit. ValueMarker marker = new ValueMarker(maxMemory, Color.BLACK, new BasicStroke(1)); marker.setLabel("Maximum Permitted Heap Size (adjust with -Xmx)"); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); marker.setLabelAnchor(RectangleAnchor.RIGHT); chart.getXYPlot().addRangeMarker(marker); chart.getXYPlot().getRenderer().setSeriesPaint(0, Color.RED); chart.getXYPlot().getRenderer().setSeriesPaint(1, new Color(0, 128, 0, 128)); return chart; }
From source file:playground.artemc.calibration.charts.AddSecondChart.java
public void addChart() { plot.setDataset(1, dataset);//from w w w .j a v a 2 s . c o m plot.mapDatasetToRangeAxis(1, 0); final LineAndShapeRenderer renderer = new LineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.BLACK); renderer.setSeriesStroke(0, new BasicStroke(4.0f)); plot.setRenderer(1, renderer); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); plot.setDomainGridlinesVisible(true); }
From source file:action.ImageAction.java
public JFreeChart getChart() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Ford", 23.3); dataset.setValue("Chevy", 32.4); dataset.setValue("Yugo", 44.2); boolean legend = true; boolean tooltips = false; boolean urls = false; JFreeChart chart = (JFreeChart) ChartFactory.createPieChart("Cars", dataset, legend, tooltips, urls); chart.setBorderPaint(Color.GREEN); chart.setBorderStroke(new BasicStroke(5.0f)); chart.setBorderVisible(true);/*from w ww . j a va 2 s . c om*/ return chart; }
From source file:org.geopublishing.atlasStyler.classification.RasterClassification.java
@Override public BufferedImage createHistogramImage(boolean showMean, boolean showSd, int histogramBins, String label_xachsis) throws InterruptedException, IOException { HistogramDataset hds = new HistogramDataset(); DoubleArrayList valuesAL;/*w w w . j a v a2 s. c om*/ valuesAL = getStatistics().elements(); double[] elements = Arrays.copyOf(valuesAL.elements(), getStatistics().size()); hds.addSeries(1, elements, histogramBins); /** Statically label the Y Axis **/ String label_yachsis = ASUtil.R("QuantitiesClassificationGUI.Histogram.YAxisLabel"); JFreeChart chart = org.jfree.chart.ChartFactory.createHistogram(null, label_xachsis, label_yachsis, hds, PlotOrientation.VERTICAL, false, true, true); /*********************************************************************** * Paint the classes into the JFreeChart */ int countLimits = 0; for (Double cLimit : getClassLimits()) { ValueMarker marker = new ValueMarker(cLimit); XYPlot plot = chart.getXYPlot(); marker.setPaint(Color.orange); marker.setLabel(String.valueOf(countLimits)); marker.setLabelAnchor(RectangleAnchor.TOP_LEFT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(marker); countLimits++; } /*********************************************************************** * Optionally painting SD and MEAN into the histogram */ try { if (showSd) { ValueMarker marker; marker = new ValueMarker(getSD(), Color.green.brighter(), new BasicStroke(1.5f)); XYPlot plot = chart.getXYPlot(); marker.setLabel(ASUtil.R("QuantitiesClassificationGUI.Histogram.SD.ShortLabel")); marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); plot.addDomainMarker(marker); } if (showMean) { ValueMarker marker; marker = new ValueMarker(getMean(), Color.green.darker(), new BasicStroke(1.5f)); XYPlot plot = chart.getXYPlot(); marker.setLabel(ASUtil.R("QuantitiesClassificationGUI.Histogram.Mean.ShortLabel")); marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); plot.addDomainMarker(marker); } } catch (Exception e) { LOGGER.error("Painting SD and MEAN into the histogram", e); } /*********************************************************************** * Render the Chart */ BufferedImage image = chart.createBufferedImage(400, 200); return image; }
From source file:cn.InstFS.wkr.NetworkMining.UIs.TimeSeriesChart2.java
public static JFreeChart createChart(DataItems nor, DataItems abnor, String title, String protocol1, String protocol2) {/* www. j a va2s . c o m*/ // ? XYDataset xydataset1 = TimeSeriesChart1.createNormalDataset(nor, protocol1); JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "", "", xydataset1); XYPlot xyplot = (XYPlot) jfreechart.getPlot(); XYLineAndShapeRenderer xylineandshaperenderer1 = (XYLineAndShapeRenderer) xyplot.getRenderer(); // ??1?1 NumberAxis numberaxis = (NumberAxis) xyplot.getRangeAxis(); numberaxis.setAutoRangeIncludesZero(false); java.awt.geom.Ellipse2D.Double double1 = new java.awt.geom.Ellipse2D.Double(-4D, -4D, 6D, 6D); // ??? // ?? xylineandshaperenderer1.setSeriesLinesVisible(0, true); xylineandshaperenderer1.setBaseShapesVisible(false); xylineandshaperenderer1.setSeriesShape(0, double1); xylineandshaperenderer1.setSeriesPaint(0, Color.blue); xylineandshaperenderer1.setSeriesFillPaint(0, Color.blue); xylineandshaperenderer1.setSeriesOutlinePaint(0, Color.blue); xylineandshaperenderer1.setSeriesStroke(0, new BasicStroke(0.5F)); // ? XYDataset xydataset2 = TimeSeriesChart1.createNormalDataset(abnor, protocol2); /* XYTextAnnotation localXYTextAnnotation = new XYTextAnnotation("aa",10, Double.parseDouble(abnor.getElementAt(10).getData())); xyplot.addAnnotation(localXYTextAnnotation);*/ XYLineAndShapeRenderer xylineandshaperenderer2 = new XYLineAndShapeRenderer(); int datasetcount = xyplot.getDatasetCount(); xyplot.setDataset(datasetcount, xydataset2); xyplot.setRenderer(datasetcount, xylineandshaperenderer2); /* System.out.println("DatasetCount="+xyplot.getDatasetCount()); for(int c=0;c<xyplot.getDatasetCount();c++){ System.out.println("DatasetSeriesCount="+xyplot.getDataset(c).getSeriesCount()); System.out.println("Dataset["+c+"]="+xyplot.getDataset(c).getSeriesKey(0)); }*/ /* // ??? xylineandshaperenderer2.setBaseShapesVisible(false); // ?? xylineandshaperenderer2.setSeriesLinesVisible(0, true); xylineandshaperenderer2.setSeriesShape(0, double1); // xylineandshaperenderer2.setSeriesPaint(0, Color.green); xylineandshaperenderer2.setSeriesFillPaint(0, Color.green); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer2.setUseFillPaint(true); xylineandshaperenderer2 .setBaseItemLabelGenerator(new StandardXYItemLabelGenerator()); xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F)); */ xylineandshaperenderer2.setSeriesLinesVisible(0, true); xylineandshaperenderer2.setBaseShapesVisible(false); xylineandshaperenderer2.setSeriesShape(0, double1); xylineandshaperenderer2.setSeriesPaint(0, Color.GREEN); xylineandshaperenderer2.setSeriesFillPaint(0, Color.GREEN); xylineandshaperenderer2.setSeriesOutlinePaint(0, Color.green); xylineandshaperenderer2.setSeriesStroke(0, new BasicStroke(0.5F)); jfreechart.getLegend().setVisible(true); return jfreechart; }
From source file:net.itransformers.topologyviewer.menu.handlers.graphTools.shortherstPathMenuHandlers.DijkstraWeightedShortestPathMenuHandler.java
@Override public void actionPerformed(ActionEvent e) { final GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent(); final MyVisualizationViewer vv = (MyVisualizationViewer) viewerPanel.getVisualizationViewer(); Collection<String> vertices = viewerPanel.getCurrentGraph().getVertices(); String[] test = vertices.toArray(new String[0]); Arrays.sort(test);/*w w w . j av a 2 s .c o m*/ final String mFrom = (String) JOptionPane.showInputDialog(frame, "Choose A Node", "A Node", JOptionPane.PLAIN_MESSAGE, null, test, test[0]); final String mTo = (String) JOptionPane.showInputDialog(frame, "Choose B Node", "B Node", JOptionPane.PLAIN_MESSAGE, null, test, test[0]); String weightedKey = JOptionPane.showInputDialog(frame, "Enter Weighted Key", "Weighted Key", JOptionPane.QUESTION_MESSAGE); Transformer<String, Double> wtTransformer = new Transformer<String, Double>() { public Double transform(String edgeId) { return null; } }; final Graph<String, String> mGraph = viewerPanel.getCurrentGraph(); DijkstraShortestPath<String, String> alg = new DijkstraShortestPath(mGraph, wtTransformer); final List<String> mPred = alg.getPath(mFrom, mTo); // System.out.println("The shortest unweighted path from" + mFrom +" to " + mTo + " is:"); // System.out.println(mPred.toString()); if (mPred == null) { JOptionPane.showMessageDialog(frame, String.format("Shortest path between %s,%s is not found", mFrom, mTo), "Message", JOptionPane.INFORMATION_MESSAGE); return; } final Layout<String, String> layout = vv.getGraphLayout(); for (final String edge : layout.getGraph().getEdges()) { if (mPred.contains(edge)) { vv.setEdgeStroke(edge, new BasicStroke(4f)); } } }
From source file:de.codesourcery.planning.swing.DateAxis.java
public BoundingBox render(ITimelineCallback callback, boolean layoutOnly) { final Calendar cal = Calendar.getInstance(); cal.setTime(startDate);/*from w w w. ja va 2 s . c om*/ cal.set(Calendar.MILLISECOND, 0); Date currentDate = cal.getTime(); final Date endDate = duration.addTo(startDate); BoundingBox lastLabel = null; final int labelSpacing = 10; final Graphics2D graphics = callback.getGraphics(); final int fontHeight = graphics.getFontMetrics().getHeight(); final double scalingFactor = getXScalingFactor(callback.getBoundingBox()); final BoundingBox box = callback.getBoundingBox(); double x = callback.getBoundingBox().getX(); final int tickToLabelSpacing = 2; final int tickLength = fontHeight; final int axisHeight = fontHeight + tickLength + tickToLabelSpacing; final double xIncrement = Math.floor(tickDuration.toSeconds() * scalingFactor); final Color oldColor = graphics.getColor(); // while (currentDate.compareTo(endDate) <= 0) { final int currentX = (int) Math.floor(x); if (lastLabel == null || lastLabel.getMaxX() < x) { final String labelText = callback.getLabelProvider().getTimelineLabel(currentDate); if (!StringUtils.isBlank(labelText)) { final Rectangle2D stringBounds = callback.getStringBounds(labelText); if (!layoutOnly) { graphics.setColor(Color.BLACK); // draw tick final Stroke oldStroke = graphics.getStroke(); graphics.setStroke(new BasicStroke(2.0f)); graphics.drawLine(currentX, box.getY() + axisHeight, currentX, box.getY() + fontHeight + tickToLabelSpacing); graphics.setStroke(oldStroke); // draw label callback.drawString(Color.BLACK, currentX, box.getY(), labelText); } final BoundingBox labelBox = new BoundingBox(currentX, box.getY(), currentX + (int) stringBounds.getWidth() + labelSpacing, box.getY() + (int) stringBounds.getHeight()); if (lastLabel == null) { lastLabel = labelBox; } else { lastLabel.add(labelBox); } } } else { // draw short tick if (!layoutOnly) { final int halfTickHeight = (int) Math.floor(tickLength / 2.0d); graphics.drawLine(currentX, box.getY() + axisHeight, currentX, box.getY() + axisHeight - halfTickHeight); } } // draw part of axis if (!layoutOnly) { graphics.drawLine((int) x, box.getY() + axisHeight, (int) (x + xIncrement), box.getY() + axisHeight); } x += xIncrement; currentDate = tickDuration.addTo(currentDate); } callback.getGraphics().setColor(oldColor); final BoundingBox result = lastLabel != null ? lastLabel : new BoundingBox(0, 0, 0, 0); result.incHeight(axisHeight); return result; }
From source file:graph_line.java
public void addMarkers(double[] peak) { if (_active > 0) { for (int i = 0; i < peak.length; i++) { Marker m1 = new ValueMarker(peak[i]); m1.setStroke(new BasicStroke((float) .5)); m1.setPaint(Color.GRAY); plot.addDomainMarker(m1);/* w ww .j a v a 2 s . c o m*/ } } }
From source file:de.bund.bfr.jung.JungUtils.java
public static <V, E> Pair<Transformer<E, Stroke>, Transformer<Context<Graph<V, E>, E>, Shape>> newEdgeStrokeArrowTransformers( int thickness, Integer maxThickness, Map<E, Double> thicknessValues) { double denom = getDenominator(thicknessValues); int max = maxThickness != null ? maxThickness : thickness + 10; Transformer<E, Stroke> strokeTransformer = edge -> { Double factor = thicknessValues != null ? thicknessValues.get(edge) : null; double width = factor != null ? thickness + (max - thickness) * factor / denom : thickness; return new BasicStroke((float) width); };//from www . java 2 s . co m Transformer<Context<Graph<V, E>, E>, Shape> arrowTransformer = edge -> { BasicStroke stroke = (BasicStroke) strokeTransformer.transform(edge.element); return ArrowFactory.getNotchedArrow(stroke.getLineWidth() + 8, 2 * stroke.getLineWidth() + 10, 4); }; return new Pair<>(strokeTransformer, arrowTransformer); }
From source file:api3.transform.PlotWave.java
public void plot(double[][] signal, String name, long samplerate) { frame.setTitle(name);/*from ww w . j a va2 s .c o m*/ XYSeries[] soundWave = new XYSeries[signal.length]; for (int j = 0; j < signal.length; ++j) { soundWave[j] = new XYSeries("sygnal" + j); for (int i = 0; i < signal[0].length; ++i) { double index = (samplerate == 0) ? i : 1000.0 * (double) i / (double) samplerate; soundWave[j].add(index, signal[j][i]); } } XYSeriesCollection dataset = new XYSeriesCollection(); for (int j = 0; j < signal.length; ++j) { dataset.addSeries(soundWave[j]); } JFreeChart chart = // (samplerate ==0 )? // ChartFactory.createXYBarChart( // name, // "prbka", // false, // "warto", // new XYBarDataset(dataset,0.0625), // PlotOrientation.VERTICAL, // true,false,false) // : ChartFactory.createXYLineChart(name, "prbka", "warto", dataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = (XYPlot) chart.getPlot(); final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis(); slider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { int value = slider.getValue(); double minimum = domainAxis.getRange().getLowerBound(); double maximum = domainAxis.getRange().getUpperBound(); double delta = (0.1f * (domainAxis.getRange().getLength())); if (value < lastValue) { // left minimum = minimum - delta; maximum = maximum - delta; } else { // right minimum = minimum + delta; maximum = maximum + delta; } DateRange range = new DateRange(minimum, maximum); domainAxis.setRange(range); lastValue = value; if (lastValue == slider.getMinimum() || lastValue == slider.getMaximum()) { slider.setValue(SLIDER_DEFAULT_VALUE); } } }); plot.addRangeMarker(new ValueMarker(0, Color.BLACK, new BasicStroke(1))); ChartPanel chartPanel = new ChartPanel(chart); Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4), BorderFactory.createEtchedBorder()); chartPanel.setBorder(border); chartPanel.addMouseWheelListener(addZoomWheel()); panel.add(chartPanel); JPanel dashboard = new JPanel(new BorderLayout()); dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4)); dashboard.add(slider); panel.add(dashboard, BorderLayout.SOUTH); frame.getContentPane().add((JPanel) panel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }