List of usage examples for java.awt Color lightGray
Color lightGray
To view the source code for java.awt Color lightGray.
Click Source Link
From source file:ui.Graph.java
/** * Creates a chart.// ww w . ja v a 2s . c o m * * @param dataset * the data for the chart. * * @return a chart. */ private JFreeChart createChart(ArrayList<Setpoint> setpoints, ArrayList<Setpoint> traj) { trajectory = traj; XYSeries posSeries = new XYSeries("Position"); XYSeries trajSeries = new XYSeries("Trajectory"); XYSeries velSeries = new XYSeries("Velocity"); for (int i = 0; i < setpoints.size(); i++) { Setpoint p = setpoints.get(i); posSeries.add(p.time, p.position); velSeries.add(p.time, p.velocity); } for (int i = 0; i < trajectory.size(); i++) { Setpoint p = trajectory.get(i); trajSeries.add(p.time, p.position); } XYSeriesCollection posDataset = new XYSeriesCollection(); XYSeriesCollection trajDataset = new XYSeriesCollection(); XYSeriesCollection velDataset = new XYSeriesCollection(); posDataset.addSeries(posSeries); velDataset.addSeries(velSeries); trajDataset.addSeries(trajSeries); // create the chart... final JFreeChart chart = ChartFactory.createScatterPlot("System output", // chart title "X", // x axis label "Y", // y axis label posDataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... chart.setBackgroundPaint(Color.white); // final StandardLegend legend = (StandardLegend) chart.getLegend(); // legend.setDisplaySeriesShapes(true); // get a reference to the plot for further customisation... final XYPlot plot = chart.getXYPlot(); plot.setDataset(0, posDataset); plot.setDataset(1, trajDataset); plot.setDataset(2, velDataset); plot.setBackgroundPaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); XYLineAndShapeRenderer posRenderer = new XYLineAndShapeRenderer(); // renderer.setSeriesShape(0, new Ellipse2D.Float(1.0f, 1.0f, 1.0f, // 1.0f)); posRenderer.setSeriesPaint(0, Color.BLUE); posRenderer.setSeriesLinesVisible(0, true); posRenderer.setSeriesShapesVisible(0, false); XYStepRenderer trajRenderer = new XYStepRenderer(); trajRenderer.setSeriesPaint(1, Color.RED); trajRenderer.setSeriesStroke(1, new BasicStroke(10)); trajRenderer.setSeriesLinesVisible(1, true); trajRenderer.setSeriesShapesVisible(1, false); XYLineAndShapeRenderer velRenderer = new XYLineAndShapeRenderer(); velRenderer.setSeriesPaint(0, Color.MAGENTA); velRenderer.setSeriesLinesVisible(0, true); velRenderer.setSeriesShapesVisible(0, false); // renderer.setSeriesStroke(1, new BasicStroke(0.01f)); plot.setRenderer(0, posRenderer); plot.setRenderer(1, trajRenderer); plot.setRenderer(2, velRenderer); for (Setpoint s : trajectory) { Marker marker = new ValueMarker(s.time); marker.setPaint(Color.DARK_GRAY); marker.setLabel(Float.toString((float) s.position)); marker.setLabelAnchor(RectangleAnchor.TOP_LEFT); marker.setLabelTextAnchor(TextAnchor.TOP_RIGHT); plot.addDomainMarker(marker); } XYTextAnnotation p = new XYTextAnnotation("kP = " + gains.kP, plot.getDomainAxis().getUpperBound() * 0.125, plot.getRangeAxis().getUpperBound() * .75); p.setFont(new Font("Dialog", Font.PLAIN, 12)); plot.addAnnotation(p); XYTextAnnotation i = new XYTextAnnotation("kI = " + gains.kI, plot.getDomainAxis().getUpperBound() * 0.125, plot.getRangeAxis().getUpperBound() * .7); i.setFont(new Font("Dialog", Font.PLAIN, 12)); plot.addAnnotation(i); XYTextAnnotation d = new XYTextAnnotation("kD = " + gains.kD, plot.getDomainAxis().getUpperBound() * 0.125, plot.getRangeAxis().getUpperBound() * .65); d.setFont(new Font("Dialog", Font.PLAIN, 12)); plot.addAnnotation(d); // change the auto tick unit selection to integer units only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setAutoRange(true); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:net.sf.mzmine.chartbasics.chartthemes.ChartThemeFactory.java
public static EStandardChartTheme createBlackNWhiteTheme() { EStandardChartTheme theme = new EStandardChartTheme(THEME.BNW_PRINT, "BnW"); // Fonts//from w ww.j a v a 2 s .c o m theme.setExtraLargeFont(new Font("Arial", Font.BOLD, 16)); theme.setLargeFont(new Font("Arial", Font.BOLD, 11)); theme.setRegularFont(new Font("Arial", Font.PLAIN, 11)); theme.setSmallFont(new Font("Arial", Font.PLAIN, 11)); // Paints theme.setTitlePaint(Color.black); theme.setSubtitlePaint(Color.black); theme.setLegendItemPaint(Color.black); theme.setPlotOutlinePaint(Color.black); theme.setBaselinePaint(Color.black); theme.setCrosshairPaint(Color.black); theme.setLabelLinkPaint(Color.black); theme.setTickLabelPaint(Color.black); theme.setAxisLabelPaint(Color.black); theme.setShadowPaint(Color.black); theme.setItemLabelPaint(Color.black); theme.setLegendBackgroundPaint(Color.white); theme.setChartBackgroundPaint(Color.white); theme.setPlotBackgroundPaint(Color.white); // paint sequence: add black Paint[] colors = new Paint[] { Color.BLACK, new Color(0xFF, 0x55, 0x55), new Color(0x55, 0x55, 0xFF), new Color(0x55, 0xFF, 0x55), new Color(0xFF, 0xFF, 0x55), new Color(0xFF, 0x55, 0xFF), new Color(0x55, 0xFF, 0xFF), Color.pink, Color.gray, ChartColor.DARK_RED, ChartColor.DARK_BLUE, ChartColor.DARK_GREEN, ChartColor.DARK_YELLOW, ChartColor.DARK_MAGENTA, ChartColor.DARK_CYAN, Color.darkGray, ChartColor.LIGHT_RED, ChartColor.LIGHT_BLUE, ChartColor.LIGHT_GREEN, ChartColor.LIGHT_YELLOW, ChartColor.LIGHT_MAGENTA, ChartColor.LIGHT_CYAN, Color.lightGray, ChartColor.VERY_DARK_RED, ChartColor.VERY_DARK_BLUE, ChartColor.VERY_DARK_GREEN, ChartColor.VERY_DARK_YELLOW, ChartColor.VERY_DARK_MAGENTA, ChartColor.VERY_DARK_CYAN, ChartColor.VERY_LIGHT_RED, ChartColor.VERY_LIGHT_BLUE, ChartColor.VERY_LIGHT_GREEN, ChartColor.VERY_LIGHT_YELLOW, ChartColor.VERY_LIGHT_MAGENTA, ChartColor.VERY_LIGHT_CYAN }; theme.setDrawingSupplier( new DefaultDrawingSupplier(colors, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); theme.setErrorIndicatorPaint(Color.black); theme.setGridBandPaint(new Color(255, 255, 255, 20)); theme.setGridBandAlternatePaint(new Color(255, 255, 255, 40)); // axis Color transp = new Color(0, 0, 0, 200); theme.setRangeGridlinePaint(transp); theme.setDomainGridlinePaint(transp); theme.setAxisLinePaint(Color.black); // axis offset theme.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); return theme; }
From source file:br.upe.ecomp.dosa.controller.chart.FileBoxplotChartManager.java
private JFreeChart createChart(String title, String xLabel, String yLabel, BoxAndWhiskerCategoryDataset dataset, boolean logarithmicYAxis) { final CategoryAxis xAxis = new CategoryAxis("Sample"); final NumberAxis yAxis; if (logarithmicYAxis) { yAxis = new LogarithmicAxis("Fitness (Log10)"); ((LogarithmicAxis) yAxis).setExpTickLabelsFlag(true); } else {//from w w w.ja v a 2 s . com yAxis = new NumberAxis("Fitness"); } yAxis.setAutoRangeIncludesZero(false); yAxis.setAutoRange(true); final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer(); renderer.setFillBox(true); renderer.setBaseCreateEntities(true); // renderer.setArtifactPaint(Color.green); renderer.setBaseOutlinePaint(Color.blue); renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator()); final JFreeChart chart = ChartFactory.createBoxAndWhiskerChart(title, xAxis.getLabel(), yAxis.getLabel(), dataset, true); final CategoryPlot plot = chart.getCategoryPlot();// new CategoryPlot(dataset, xAxis, yAxis, // renderer); plot.setBackgroundPaint(Color.white); // chart.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.lightGray); plot.setRenderer(renderer); plot.setRangeAxis(yAxis); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); return chart; }
From source file:org.jfree.chart.demo.TimeSeriesDemo12.java
/** * Creates a chart./*from w w w. j av a2 s .c o m*/ * * @param dataset a dataset. * * @return A chart. */ private JFreeChart createChart(final XYDataset dataset) { final JFreeChart chart = ChartFactory.createTimeSeriesChart("Sample Chart", "Date", "Value", dataset, true, true, false); chart.setBackgroundPaint(Color.white); // final StandardLegend sl = (StandardLegend) chart.getLegend(); // sl.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); //plot.setOutlinePaint(null); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(false); final XYItemRenderer renderer = plot.getRenderer(); if (renderer instanceof StandardXYItemRenderer) { final StandardXYItemRenderer rr = (StandardXYItemRenderer) renderer; rr.setPlotShapes(true); rr.setShapesFilled(true); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); renderer.setSeriesStroke(1, new BasicStroke(2.0f)); } final DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("hh:mma")); return chart; }
From source file:j2se.jfreechart.barchart.BarChartDemo1.java
/** * Creates a sample chart./*from w w w . j a v a 2 s . c o m*/ * * @param dataset the dataset. * * @return The chart. */ private static JFreeChart createChart(CategoryDataset dataset) { // create the chart... JFreeChart chart = ChartFactory.createBarChart("Bar Chart Demo", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips? false // URLs? ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); // OPTIONAL CUSTOMISATION COMPLETED. return chart; }
From source file:org.madsonic.controller.StatusChartController.java
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String type = request.getParameter("type"); int index = Integer.parseInt(request.getParameter("index")); List<TransferStatus> statuses = Collections.emptyList(); if ("stream".equals(type)) { statuses = statusService.getAllStreamStatuses(); } else if ("download".equals(type)) { statuses = statusService.getAllDownloadStatuses(); } else if ("upload".equals(type)) { statuses = statusService.getAllUploadStatuses(); }/* w ww. ja v a 2 s. c o m*/ if (index < 0 || index >= statuses.size()) { return null; } TransferStatus status = statuses.get(index); TimeSeries series = new TimeSeries("Kbps", Millisecond.class); TransferStatus.SampleHistory history = status.getHistory(); long to = System.currentTimeMillis(); long from = to - status.getHistoryLengthMillis(); Range range = new DateRange(from, to); if (!history.isEmpty()) { TransferStatus.Sample previous = history.get(0); for (int i = 1; i < history.size(); i++) { TransferStatus.Sample sample = history.get(i); long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp(); long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered()); double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0); series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps); previous = sample; } } // Compute moving average. series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000); // Find min and max values. double min = 100; double max = 250; for (Object obj : series.getItems()) { TimeSeriesDataItem item = (TimeSeriesDataItem) obj; double value = item.getValue().doubleValue(); if (item.getPeriod().getFirstMillisecond() > from) { min = Math.min(min, value); max = Math.max(max, value); } } // Add 10% to max value. max *= 1.1D; // Subtract 10% from min value. min *= 0.9D; TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white); plot.setBackgroundPaint(background); XYItemRenderer renderer = plot.getRendererForDataset(dataset); renderer.setSeriesPaint(0, Color.gray.darker()); renderer.setSeriesStroke(0, new BasicStroke(2f)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setRange(range); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(new Range(min, max)); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT); return null; }
From source file:net.sourceforge.subsonic.controller.StatusChartController.java
public synchronized ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String type = request.getParameter("type"); int index = Integer.parseInt(request.getParameter("index")); List<TransferStatus> statuses = Collections.emptyList(); if ("stream".equals(type)) { statuses = statusService.getAllStreamStatuses(); } else if ("download".equals(type)) { statuses = statusService.getAllDownloadStatuses(); } else if ("upload".equals(type)) { statuses = statusService.getAllUploadStatuses(); }/*from w ww . j av a2s . c o m*/ if (index < 0 || index >= statuses.size()) { return null; } TransferStatus status = statuses.get(index); TimeSeries series = new TimeSeries("Kbps", Millisecond.class); TransferStatus.SampleHistory history = status.getHistory(); long to = System.currentTimeMillis(); long from = to - status.getHistoryLengthMillis(); Range range = new DateRange(from, to); if (!history.isEmpty()) { TransferStatus.Sample previous = history.get(0); for (int i = 1; i < history.size(); i++) { TransferStatus.Sample sample = history.get(i); long elapsedTimeMilis = sample.getTimestamp() - previous.getTimestamp(); long bytesStreamed = Math.max(0L, sample.getBytesTransfered() - previous.getBytesTransfered()); double kbps = (8.0 * bytesStreamed / 1024.0) / (elapsedTimeMilis / 1000.0); series.addOrUpdate(new Millisecond(new Date(sample.getTimestamp())), kbps); previous = sample; } } // Compute moving average. series = MovingAverage.createMovingAverage(series, "Kbps", 20000, 5000); // Find min and max values. double min = 100; double max = 250; for (Object obj : series.getItems()) { TimeSeriesDataItem item = (TimeSeriesDataItem) obj; double value = item.getValue().doubleValue(); if (item.getPeriod().getFirstMillisecond() > from) { min = Math.min(min, value); max = Math.max(max, value); } } // Add 10% to max value. max *= 1.1D; // Subtract 10% from min value. min *= 0.9D; TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart chart = ChartFactory.createTimeSeriesChart(null, null, null, dataset, false, false, false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_RIGHT); Paint background = new GradientPaint(0, 0, Color.lightGray, 0, IMAGE_HEIGHT, Color.white); plot.setBackgroundPaint(background); XYItemRenderer renderer = plot.getRendererForDataset(dataset); renderer.setSeriesPaint(0, Color.blue.darker()); renderer.setSeriesStroke(0, new BasicStroke(2f)); // Set theme-specific colors. Color bgColor = getBackground(request); Color fgColor = getForeground(request); chart.setBackgroundPaint(bgColor); ValueAxis domainAxis = plot.getDomainAxis(); domainAxis.setRange(range); domainAxis.setTickLabelPaint(fgColor); domainAxis.setTickMarkPaint(fgColor); domainAxis.setAxisLinePaint(fgColor); ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setRange(new Range(min, max)); rangeAxis.setTickLabelPaint(fgColor); rangeAxis.setTickMarkPaint(fgColor); rangeAxis.setAxisLinePaint(fgColor); ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, IMAGE_WIDTH, IMAGE_HEIGHT); return null; }
From source file:com.google.code.facebook.graph.sna.applet.DrawnIconVertexDemo.java
public DrawnIconVertexDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<Integer, Number>(); Integer[] v = createVertices(10); createEdges(v);// w w w . java2 s.c o m vv = new VisualizationViewer<Integer, Number>(new FRLayout<Integer, Number>(graph)); vv.getRenderContext().setVertexLabelTransformer(new Transformer<Integer, String>() { public String transform(Integer v) { return "Vertex " + v; } }); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); vv.getRenderContext().setVertexIconTransformer(new Transformer<Integer, Icon>() { /* * Implements the Icon interface to draw an Icon with background color and * a text label */ public Icon transform(final Integer v) { return new Icon() { public int getIconHeight() { return 20; } public int getIconWidth() { return 20; } public void paintIcon(Component c, Graphics g, int x, int y) { if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.yellow); } else { g.setColor(Color.red); } g.fillOval(x, y, 20, 20); if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.black); } else { g.setColor(Color.white); } g.drawString("" + v, x + 6, y + 15); } }; } }); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.white, Color.yellow)); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.lightGray)); vv.setBackground(Color.white); // add my listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Integer>()); // create a frome to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox()); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:edu.uci.ics.jung.samples.DrawnIconVertexDemo.java
@SuppressWarnings("unchecked") public DrawnIconVertexDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<Integer, Number>(); Integer[] v = createVertices(10); createEdges(v);// w ww . j ava 2 s . c om vv = new VisualizationViewer<Integer, Number>(new FRLayout<Integer, Number>(graph)); vv.getRenderContext().setVertexLabelTransformer(new Transformer<Integer, String>() { public String transform(Integer v) { return "Vertex " + v; } }); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); vv.getRenderContext().setVertexIconTransformer(new Transformer<Integer, Icon>() { /* * Implements the Icon interface to draw an Icon with background color and * a text label */ public Icon transform(final Integer v) { return new Icon() { public int getIconHeight() { return 20; } public int getIconWidth() { return 20; } public void paintIcon(Component c, Graphics g, int x, int y) { if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.yellow); } else { g.setColor(Color.red); } g.fillOval(x, y, 20, 20); if (vv.getPickedVertexState().isPicked(v)) { g.setColor(Color.black); } else { g.setColor(Color.white); } g.drawString("" + v, x + 6, y + 15); } }; } }); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<Integer>(vv.getPickedVertexState(), Color.white, Color.yellow)); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.lightGray)); vv.setBackground(Color.white); // add my listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Integer>()); // create a frome to hold the graph final JFrame frame = new JFrame(); Container content = frame.getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final ModalGraphMouse gm = new DefaultModalGraphMouse<Integer, Number>(); vv.setGraphMouse(gm); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel controls = new JPanel(); controls.add(plus); controls.add(minus); controls.add(((DefaultModalGraphMouse<Integer, Number>) gm).getModeComboBox()); content.add(controls, BorderLayout.SOUTH); frame.pack(); frame.setVisible(true); }
From source file:openqcm.ChartDynamicData.java
public ChartDynamicData() { // add primary axis frequency TimeSeries seriesFrequency = new TimeSeries("Frequency (Hz)"); datasetFrequency = new TimeSeriesCollection(seriesFrequency); rangeAxisF = new NumberAxis("Frequency (Hz)"); XYItemRenderer renderer = new StandardXYItemRenderer(); renderer.setSeriesPaint(0, new Color(0, 142, 192)); rangeAxisF.setAutoRangeIncludesZero(false); rangeAxisF.setAutoRange(true);//w ww. jav a 2 s . co m rangeAxisF.setAutoRangeMinimumSize(50); plot.setDataset(0, datasetFrequency); plot.setRangeAxis(0, rangeAxisF); plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT); plot.setRenderer(0, renderer); plot.mapDatasetToRangeAxis(0, 0); // add secondary axis temperature TimeSeries seriesTemperature = new TimeSeries("Temperature (C)"); datasetTemperature = new TimeSeriesCollection(seriesTemperature); plot.setDataset(1, datasetTemperature); NumberAxis rangeAxisT = new NumberAxis("Temperature (C)"); rangeAxisT.setAutoRangeIncludesZero(false); rangeAxisT.setAutoRange(true); rangeAxisT.setAutoRangeMinimumSize(5); plot.setRangeAxis(1, rangeAxisT); plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT); // custom renderer for dinamically changing temperaure rendererT.setSeriesPaint(0, new Color(255, 128, 0)); plot.setRenderer(1, rendererT); plot.mapDatasetToRangeAxis(1, 1); plotComb.add(plot); plotComb.setBackgroundPaint(Color.white); plotComb.setDomainGridlinePaint(Color.white); plotComb.setRangeGridlinePaint(Color.white); // enable panning for both axis plotComb.setRangePannable(true); plotComb.setDomainPannable(true); // set time axis properties // format time axis as hh:mm:ss SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); DateAxis axis = (DateAxis) plotComb.getDomainAxis(); axis.setDateFormatOverride(format); // default auto range domainAxis.setAutoRange(true); // init the JFreeChart JFreeChart chart = new JFreeChart(plotComb); chart.setBorderPaint(Color.lightGray); chart.setBorderVisible(true); chart.setBackgroundPaint(Color.white); // set legend properties LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.TOP); legend.setItemFont(new Font("Dialog", Font.PLAIN, 9)); // constructor for org.jfree.chart.ChartPanel // ChartPanel(JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips) ChartPanel chartPanel = new ChartPanel(chart, false, true, true, true, true); // enable mouse wheel support for the chart panel chartPanel.setMouseWheelEnabled(true); this.setLayout(new BorderLayout()); // add real time chart to the frame this.add(chartPanel); this.validate(); }