List of usage examples for java.awt BasicStroke BasicStroke
public BasicStroke(float width)
From source file:UserInterface.PublisherRole.ViewUserHabitsJPanel.java
private static JFreeChart createChart(PieDataset dataset) { JFreeChart chart = ChartFactory.createPieChart("User Habits", // chart title dataset, // data false, // no legend true, // tooltips false // no URL generation );/*from w w w . j a va 2 s. c o m*/ // 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 plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE)); plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED)); plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN)); plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW)); 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(" ", 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:org.geotools.renderer.chart.GeometryRenderer.java
public void setStrokeWidth(float width) { setBaseStroke(new BasicStroke(width)); }
From source file:org.jls.toolbox.math.chart.XYLineChart.java
/** * Permet d'largir les lignes du curseur de la courbe. *//*from ww w . j av a 2s . c o m*/ public void setCrossHairBold() { this.plot.setDomainCrosshairStroke(new BasicStroke(1f)); this.plot.setRangeCrosshairStroke(new BasicStroke(1f)); }
From source file:org.cyberoam.iview.charts.MeterChart.java
/** * This method generates JFreeChart instance for Meter chart with dial port and iView customization. * @param reportID//w w w . ja va2 s .com * @param rsw * @param request * @return */ public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) { ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID); JFreeChart chart = null; ReportColumnBean reportColumnBean = null; GraphBean graphBean = null; try { DefaultValueDataset data = null; graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId()); reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(), graphBean.getYColumnId()); String yColumnDBname = reportColumnBean.getDbColumnName(); rsw.first(); double used = Double.parseDouble(rsw.getString(yColumnDBname)); data = new DefaultValueDataset(100 - used); DialPlot plot = new DialPlot(data); chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false); chart.setBackgroundPaint(Color.white); int imgWidth = graphBean.getWidth(); int imgHeight = graphBean.getHeight(); if (request != null && request.getParameter("imgwidth") != null && !"".equalsIgnoreCase(request.getParameter("imgwidth")) && !"null".equalsIgnoreCase(request.getParameter("imgwidth"))) { imgWidth = Integer.parseInt(request.getParameter("imgwidth")); } if (request != null && request.getParameter("imgheight") != null && !"".equalsIgnoreCase(request.getParameter("imgheight")) && !"null".equalsIgnoreCase(request.getParameter("imgheight"))) { imgHeight = Integer.parseInt(request.getParameter("imgheight")); } plot.setView((1 - ((double) imgWidth / (double) imgHeight)) / 2, plot.getViewY(), ((double) imgWidth / (double) imgHeight), plot.getViewHeight()); StandardDialFrame dialFrame = new StandardDialFrame(); dialFrame.setBackgroundPaint(new Color(54, 73, 109)); dialFrame.setRadius(0.8); dialFrame.setStroke(new BasicStroke(0)); plot.setDialFrame(dialFrame); GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(196, 210, 219)); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer( new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); plot.setBackground(db); DialValueIndicator dvi = new DialValueIndicator(0); dvi.setRadius(0.55); dvi.setBackgroundPaint(gp); dvi.setNumberFormat(new DecimalFormat("###")); dvi.setFont(new Font("Vandara", Font.CENTER_BASELINE, 10)); dvi.setOutlinePaint(Color.lightGray); plot.addLayer(dvi); StandardDialScale scale = new StandardDialScale(0, 100, -120, -300, 10, 4); scale.setTickRadius(0.75); scale.setTickLabelOffset(0.15); scale.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 9)); plot.addScale(0, scale); StandardDialRange range = new StandardDialRange(0.0, 50.0, Color.green); range.setInnerRadius(0.35); range.setOuterRadius(0.38); plot.addLayer(range); StandardDialRange range2 = new StandardDialRange(50.0, 75.0, Color.yellow); range2.setInnerRadius(0.35); range2.setOuterRadius(0.38); plot.addLayer(range2); StandardDialRange range3 = new StandardDialRange(75.0, 100.0, Color.red); range3.setInnerRadius(0.35); range3.setOuterRadius(0.38); plot.addLayer(range3); DialPointer needle = new DialPointer.Pointer(); needle.setRadius(0.55); plot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); plot.setCap(cap); } catch (Exception e) { CyberoamLogger.appLog.debug("MeterChart=>Exception : " + e, e); } return chart; }
From source file:org.pentaho.chart.plugin.jfreechart.dial.JFreeDialChartGeneratorIT.java
public void testCapStyle() throws Exception { JFreeChart chart = getJFreeChart("testchart.xml", new Object[][] { { 8D } }); //$NON-NLS-1$ DialPlot plot = (DialPlot) chart.getPlot(); DialCap cap = (DialCap) plot.getCap(); assertEquals(cap.getFillPaint(), new Color(0, 128, 0)); // CSS constant green is 0, 128, 0 assertEquals(cap.getOutlinePaint(), Color.RED); assertEquals(/*from w w w .j a va2 s . c o m*/ String.format("expected: %s but was: %s", 1D, //$NON-NLS-1$ ((BasicStroke) cap.getOutlineStroke()).getLineWidth()), cap.getOutlineStroke(), new BasicStroke(1F)); assertEquals(cap.getRadius(), 0.06D); }
From source file:net.sf.mzmine.modules.visualization.intensityplot.IntensityPlotWindow.java
public IntensityPlotWindow(ParameterSet parameters) { PeakList peakList = parameters.getParameter(IntensityPlotParameters.peakList).getValue() .getMatchingPeakLists()[0];//from ww w . j a va2 s . c o m 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 DoubleParameter)); if ((xAxisValueSource == IntensityPlotParameters.rawDataFilesOption) || isCombo) { chart = ChartFactory.createLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false); 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); // Add the Windows menu JMenuBar menuBar = new JMenuBar(); menuBar.add(new WindowsMenu()); setJMenuBar(menuBar); pack(); // get the window settings parameter ParameterSet paramSet = MZmineCore.getConfiguration().getModuleParameters(IntensityPlotModule.class); WindowSettingsParameter settings = paramSet.getParameter(IntensityPlotParameters.windowSettings); // update the window and listen for changes settings.applySettingsToWindow(this); this.addComponentListener(settings); }
From source file:com.joliciel.jochre.search.highlight.ImageSnippet.java
public BufferedImage getImage() { try {/*from w ww . j a va2 s.c om*/ BufferedImage originalImage = ImageIO.read(imageFile); BufferedImage imageSnippet = new BufferedImage(this.rectangle.getWidth(), this.rectangle.getHeight(), BufferedImage.TYPE_INT_ARGB); originalImage = originalImage.getSubimage(this.rectangle.getLeft(), this.rectangle.getTop(), this.rectangle.getWidth(), this.rectangle.getHeight()); Graphics2D graphics2D = imageSnippet.createGraphics(); graphics2D.drawImage(originalImage, 0, 0, this.rectangle.getWidth(), this.rectangle.getHeight(), null); int extra = 2; for (Rectangle rect : this.highlights) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setPaint(Color.BLACK); graphics2D.drawRect(rect.getLeft() - this.rectangle.getLeft() - extra, rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2), rect.getHeight() + (extra * 2)); graphics2D.setColor(new Color(255, 255, 0, 127)); graphics2D.fillRect(rect.getLeft() - this.rectangle.getLeft() - extra, rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2), rect.getHeight() + (extra * 2)); } return imageSnippet; } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:org.matsim.contrib.socnetsim.usage.analysis.CourtesyHistogramListener.java
static JFreeChart getGraphic(final CourtesyHistogram.DataFrame dataFrame, int iteration, String actType) { final XYSeriesCollection xyData = new XYSeriesCollection(); final XYSeries helloSeries = new XYSeries("hello", false, true); final XYSeries goodbyeSerie = new XYSeries("goodbye", false, true); final XYSeries togetherSerie = new XYSeries("pairs together", false, true); int together = 0; for (int i = 0; i < dataFrame.countsHello.length; i++) { together = together + dataFrame.countsHello[i] - dataFrame.countsGoodbye[i]; double hour = i * dataFrame.binSize / 60.0 / 60.0; helloSeries.add(hour, dataFrame.countsHello[i]); goodbyeSerie.add(hour, dataFrame.countsGoodbye[i]); togetherSerie.add(hour, together); }//from ww w .ja va 2s . c o m xyData.addSeries(helloSeries); xyData.addSeries(goodbyeSerie); xyData.addSeries(togetherSerie); final JFreeChart chart = ChartFactory.createXYStepChart( "Courtesy Statistics," + "actType " + actType + " it." + iteration, "time", "# persons", xyData, PlotOrientation.VERTICAL, true, // legend false, // tooltips false // urls ); XYPlot plot = chart.getXYPlot(); final CategoryAxis axis1 = new CategoryAxis("hour"); axis1.setTickLabelFont(new Font("SansSerif", Font.PLAIN, 7)); plot.setDomainAxis(new NumberAxis("time")); plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f)); plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0f)); plot.setBackgroundPaint(Color.white); plot.setRangeGridlinePaint(Color.gray); plot.setDomainGridlinePaint(Color.gray); return chart; }
From source file:org.ujmp.jfreechart.MatrixChartPanel.java
public synchronized void redraw() { Dataset dataset = null;/*w ww . j a v a2s . c o m*/ dataset = new XYSeriesCollectionWrapper(getMatrix()); // dataset = new CategoryDatasetWrapper(getMatrix()); String title = getMatrix().getLabel(); String xLabel = StringUtil.format(getMatrix().getMatrix().getDimensionLabel(Matrix.ROW)); String yLabel = null; // setChart(ChartFactory.createLineChart(title, xLabel, yLabel, // (CategoryDataset) dataset, PlotOrientation.VERTICAL, true, // true, false)); setChart(ChartFactory.createXYLineChart(title, xLabel, yLabel, (XYDataset) dataset, PlotOrientation.VERTICAL, true, true, false)); XYPlot plot = getChart().getXYPlot(); if (getConfig().isLogScaleDomain()) { try { NumberAxis axis = new LogarithmicAxis(null); plot.setDomainAxis(axis); } catch (Exception e) { NumberAxis axis = new NumberAxis(); plot.setDomainAxis(axis); } } else { NumberAxis axis = new NumberAxis(); plot.setDomainAxis(axis); } if (getConfig().isLogScaleRange()) { try { NumberAxis axis = new LogarithmicAxis(null); plot.setRangeAxis(axis); } catch (Exception e) { NumberAxis axis = new NumberAxis(); plot.setRangeAxis(axis); } } else { NumberAxis axis = new NumberAxis(); plot.setRangeAxis(axis); } getChart().setTitle((String) null); getChart().setBackgroundPaint(Color.WHITE); plot.setDomainGridlinesVisible(false); plot.setRangeGridlinesVisible(false); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setBaseShapesVisible(false); renderer.setDrawSeriesLineAsPath(true); for (int i = 0; i < getMatrix().getColumnCount(); i++) { renderer.setSeriesStroke(i, new BasicStroke(3)); plot.setRenderer(i, renderer); } plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setDomainCrosshairVisible(false); plot.setRangeCrosshairVisible(false); plot.getRangeAxis().setAutoRange(true); plot.getDomainAxis().setAutoRange(true); plot.getDomainAxis().setUpperMargin(0); setMouseZoomable(false); }
From source file:com.google.code.facebook.graph.sna.applet.VertexLabelAsShapeDemo.java
/** * create an instance of a simple graph with basic controls *///from ww w .ja v a 2 s .com public VertexLabelAsShapeDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); layout = new FRLayout<String, Number>(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>( layout, preferredSize); vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize); // this class will provide both label drawing and vertex shapes VertexLabelAsShapeRenderer<String, Number> vlasr = new VertexLabelAsShapeRenderer<String, Number>( vv.getRenderContext()); // customize the render context vv.getRenderContext().setVertexLabelTransformer( // this chains together Transformers so that the html tags // are prepended to the toString method output new ChainedTransformer<String, String>( new Transformer[] { new ToStringLabeller<String>(), new Transformer<String, String>() { public String transform(String input) { return "<html><center>Vertex<p>" + input; } } })); vv.getRenderContext().setVertexShapeTransformer(vlasr); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red)); vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.yellow)); vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f))); // customize the renderer vv.getRenderer() .setVertexRenderer(new GradientVertexRenderer<String, Number>(Color.gray, Color.white, true)); vv.getRenderer().setVertexLabelRenderer(vlasr); vv.setBackground(Color.black); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); final DefaultModalGraphMouse<String, Number> graphMouse = new DefaultModalGraphMouse<String, Number>(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); 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(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); controls.add(modeBox); content.add(controls, BorderLayout.SOUTH); }