List of usage examples for java.awt BasicStroke BasicStroke
public BasicStroke(float width)
From source file:no.met.jtimeseries.marinogram.MarinogramTemperaturePlot.java
private XYPlot createPlot(TimeZone timezone, boolean plotAirTemp, boolean plotWaterTemp, boolean plotDewpointTemp) throws ParseException { Date startTime = null;// www . j a v a 2 s .c o m NumberPhenomenon aTemperature = null; NumberPhenomenon wTemperature = null; NumberPhenomenon dTemperature = null; // default setting ChartPlotter plotter = new ChartPlotter(); plotter.setHeight(this.getHeight()); plotter.setWidth(this.getWidth()); plotter.setPlotDefaultProperties("", ""); double minValue = 100; double maxValue = -100; int plotIndex = 0; if (plotAirTemp) { aTemperature = getLocationForecastDataModel().getPhenomenen(PhenomenonName.AirTemperature.toString(), NumberPhenomenon.class); minValue = aTemperature.getMinValue() < minValue ? aTemperature.getMinValue() : minValue; maxValue = aTemperature.getMaxValue() > maxValue ? aTemperature.getMaxValue() : maxValue; startTime = aTemperature.getTime().get(0); plotTemperature(plotter, aTemperature, new BasicStroke(2.0f), Color.RED, messages.getString("label.air"), true); plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true); plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(1, true); plotIndex++; } if (plotWaterTemp) { wTemperature = getOceanForecastDataModel().getPhenomenen(PhenomenonName.seaTemperature.toString(), NumberPhenomenon.class); // only plot water temperature if it is availbe for this location if (wTemperature != null) { minValue = wTemperature.getMinValue() < minValue ? wTemperature.getMinValue() : minValue; maxValue = wTemperature.getMaxValue() > maxValue ? wTemperature.getMaxValue() : maxValue; startTime = wTemperature.getTime().get(0); BasicStroke dottedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, new float[] { 2.0f, 6.0f }, 0.0f); plotTemperature(plotter, wTemperature, dottedStroke, Color.RED, messages.getString("label.water"), true); plotter.getPlot().getRenderer(plotIndex++).setSeriesVisibleInLegend(0, true); } } if (plotDewpointTemp) { dTemperature = getLocationForecastDataModel() .getPhenomenen(PhenomenonName.dewPointTemperature.toString(), NumberPhenomenon.class); minValue = dTemperature.getMinValue() < minValue ? dTemperature.getMinValue() : minValue; maxValue = dTemperature.getMaxValue() > maxValue ? dTemperature.getMaxValue() : maxValue; startTime = dTemperature.getTime().get(0); plotTemperature(plotter, dTemperature, new BasicStroke(2.0f), Color.ORANGE, messages.getString("label.dewpoint"), false); plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true); } double tick = (maxValue - minValue) / 3.5; tick = Math.ceil(tick); double lowBound = Math.floor(minValue / (tick)) * (tick); lowBound = lowBound - tick / 2; double upperBound = lowBound + tick * 7; // set range axis NumberAxis numberAxis = new NumberAxis(); numberAxis.setLabelPaint(Color.RED); numberAxis.setTickLabelPaint(Color.RED); numberAxis.setLabel(messages.getString("parameter.temperature") + " (\u00B0 C)"); numberAxis.setTickUnit(new NumberTickUnit(tick)); numberAxis.setLowerBound(lowBound); numberAxis.setUpperBound(upperBound); //Set left axis and right axis plotter.getPlot().setRangeAxis(0, numberAxis); plotter.getPlot().setRangeAxis(1, numberAxis); //Set the third axis and hide the third axis if (plotAirTemp && plotWaterTemp && plotDewpointTemp) { NumberAxis numberAxis2 = new NumberAxis(); numberAxis2.setTickUnit(new NumberTickUnit(tick)); numberAxis2.setLowerBound(lowBound); numberAxis2.setUpperBound(upperBound); plotter.getPlot().setRangeAxis(2, numberAxis2); plotter.getPlot().getRangeAxis(2).setVisible(false); } //Show legend at the top right position of the plot LegendTitle lt = new LegendTitle(plotter.getPlot()); lt.setItemFont(new Font("Dialog", Font.PLAIN, 9)); lt.setBackgroundPaint(new Color(255, 255, 255, 100)); lt.setFrame(new BlockBorder(Color.white)); lt.setPosition(RectangleEdge.TOP); XYTitleAnnotation ta = new XYTitleAnnotation(0.99, 0.95, lt, RectangleAnchor.TOP_RIGHT); plotter.getPlot().addAnnotation(ta); // set domain range after (must) plot all the data plotter.addHourBasedDomainGridLines(); // add markers plotter.addDomainMarkers(getShortTermTime(startTime), timezone, locale); Date minDate = getShortTermTime(startTime).get(0); Date maxDate = getShortTermTime(startTime).get(getShortTermTime(startTime).size() - 1); plotter.setDomainRange(minDate, maxDate); plotter.setDomainDateFormat(timezone, "HH"); plotter.getPlot().setOutlineVisible(true); // invisible the domain i.e, x axis plotter.getPlot().getDomainAxis().setTickLabelsVisible(false); return plotter.getPlot(); }
From source file:ala.soils2sat.DrawingUtils.java
public static Rectangle drawString(Graphics g, Font font, String text, int x, int y, int width, int height, int align, boolean wrap) { g.setFont(font);/*from ww w. ja v a 2 s .c o m*/ FontMetrics fm = g.getFontMetrics(font); setPreferredAliasingMode(g); Rectangle ret = new Rectangle(0, 0, 0, 0); if (text == null) { return ret; } String[] alines = text.split("\\n"); ArrayList<String> lines = new ArrayList<String>(); for (String s : alines) { if (wrap && fm.stringWidth(s) > width) { // need to split this up into multiple lines... List<String> splitLines = wrapString(s, fm, width); lines.addAll(splitLines); } else { lines.add(s); } } int numlines = lines.size(); while (fm.getHeight() * numlines > height) { numlines--; } if (numlines > 0) { int maxwidth = 0; int minxoffset = y + width; int totalheight = (numlines * fm.getHeight()); int linestart = ((height / 2) - (totalheight / 2)); if (!wrap) { ret.y = y + linestart; } else { ret.y = y; linestart = 0; } for (int idx = 0; idx < numlines; ++idx) { String line = lines.get(idx); int stringWidth = fm.stringWidth(line); // the width of the label depends on the font : // if the width of the label is larger than the item if (stringWidth > 0 && width < stringWidth) { // We have to truncate the label line = clipString(null, fm, line, width); stringWidth = fm.stringWidth(line); } int xoffset = 0; int yoffset = linestart + fm.getHeight() - fm.getDescent(); if (align == TEXT_ALIGN_RIGHT) { xoffset = (width - stringWidth); } else if (align == TEXT_ALIGN_CENTER) { xoffset = (int) Math.round((double) (width - stringWidth) / (double) 2); } if (xoffset < minxoffset) { minxoffset = xoffset; } g.drawString(line, x + xoffset, y + yoffset); if (stringWidth > maxwidth) { maxwidth = stringWidth; } linestart += fm.getHeight(); } ret.width = maxwidth; ret.height = totalheight; ret.x = x + minxoffset; // Debug only... if (DEBUG) { Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(1)); g.setColor(Color.blue); g.drawRect(ret.x, ret.y, ret.width, ret.height); g.setColor(Color.green); g.drawRect(x, y, width, height); } return ret; } return ret; }
From source file:storybook.ui.chart.jfreechart.ChartUtil.java
public static Marker getDateIntervalMarker(Date paramDate1, Date paramDate2, String paramString) { double d1 = paramDate1.getTime(); double d2 = paramDate2.getTime(); BasicStroke localBasicStroke = new BasicStroke(0.3F); IntervalMarker localIntervalMarker = new IntervalMarker(d1, d2, Color.pink, localBasicStroke, Color.black, localBasicStroke, 0.5F);/*from www . j a v a 2 s .c o m*/ localIntervalMarker.setLabel(paramString); localIntervalMarker.setLabelAnchor(RectangleAnchor.BOTTOM); localIntervalMarker.setLabelTextAnchor(TextAnchor.BOTTOM_CENTER); return localIntervalMarker; }
From source file:net.sf.mzmine.modules.peaklistmethods.peakpicking.adap3decompositionV2.EICPlot.java
public EICPlot(List<List<NavigableMap<Double, Double>>> clusters, List<Double> colors, List<List<String>> info, List<NavigableMap<Double, Double>> modelPeaks) { super(null, true); setBackground(Color.white);//ww w . j a va 2 s.c o m setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); NumberAxis xAxis = new NumberAxis("Retention Time"); xAxis.setAutoRangeIncludesZero(false); xAxis.setUpperMargin(0); xAxis.setLowerMargin(0); NumberAxis yAxis = new NumberAxis("Intensity"); yAxis.setAutoRangeIncludesZero(false); yAxis.setUpperMargin(0); yAxis.setLowerMargin(0); xyDataset = new XYSeriesCollection(); colorDataset = new ArrayList<>(); toolTips = new ArrayList<>(); widths = new ArrayList<>(); int seriesID = 0; for (int i = 0; i < clusters.size(); ++i) { List<NavigableMap<Double, Double>> cluster = clusters.get(i); double color = colors.get(i); for (int j = 0; j < cluster.size(); ++j) { XYSeries series = new XYSeries(seriesID++); for (Entry<Double, Double> e : cluster.get(j).entrySet()) series.add(e.getKey(), e.getValue()); xyDataset.addSeries(series); colorDataset.add(color); toolTips.add(info.get(i).get(j)); } } XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() { @Override public Paint getItemPaint(int row, int col) { String type = xyDataset.getSeries(row).getDescription(); Paint color; if (type.equals(PeakType.MODEL.name())) color = COLORS[row % COLORS.length]; else color = new Color(0, 0, 0, 50); return color; } @Override public Stroke getSeriesStroke(int series) { XYSeries s = xyDataset.getSeries(series); String type = s.getDescription(); float width; if (type.equals((PeakType.MODEL.name()))) width = 2.0f; else width = 1.0f; return new BasicStroke(width); } }; renderer.setDefaultShapesVisible(false); renderer.setDefaultToolTipGenerator(new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset dataset, int series, int item) { try { return toolTips.get(series); } catch (NullPointerException | IndexOutOfBoundsException e) { return ""; } } }); XYPlot plot = new XYPlot(xyDataset, xAxis, yAxis, renderer); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); JFreeChart chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 12), plot, false); chart.setBackgroundPaint(Color.white); super.setChart(chart); }
From source file:org.jenkinsci.plugins.autozoil.graph.AutozoilGraph.java
/** * Creates a Autozoil trend graph/* ww w. j av a2 s . c o m*/ * * @return the JFreeChart graph object */ protected JFreeChart createGraph() { final JFreeChart chart = ChartFactory.createLineChart(null, // chart title null, // unused yLabel, // range axis label categoryDataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... final LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.RIGHT); chart.setBackgroundPaint(Color.white); final CategoryPlot plot = chart.getCategoryPlot(); // plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0)); plot.setBackgroundPaint(Color.WHITE); plot.setOutlinePaint(null); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.black); CategoryAxis domainAxis = new ShiftedCategoryAxis(null); plot.setDomainAxis(domainAxis); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); domainAxis.setLowerMargin(0.0); domainAxis.setUpperMargin(0.0); domainAxis.setCategoryMargin(0.0); final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerBound(0); rangeAxis.setAutoRange(true); final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseStroke(new BasicStroke(2.0f)); ColorPalette.apply(renderer); // crop extra space around the graph plot.setInsets(new RectangleInsets(5.0, 0, 0, 5.0)); return chart; }
From source file:ch.zhaw.simulation.diagram.charteditor.DefaultNumberAxisEditor.java
/** * Standard constructor: builds a property panel for the specified axis. * /*from w w w . ja v a 2 s . c o m*/ * @param axis * the axis, which should be changed. */ public DefaultNumberAxisEditor(NumberAxis axis) { super(axis); this.autoRange = axis.isAutoRange(); this.minimumValue = axis.getLowerBound(); this.maximumValue = axis.getUpperBound(); this.gridPaintSample = new PaintSample(Color.blue); this.gridStrokeSample = new StrokeSample(new BasicStroke(1.0f)); this.availableStrokeSamples = new StrokeSample[3]; this.availableStrokeSamples[0] = new StrokeSample(new BasicStroke(1.0f)); this.availableStrokeSamples[1] = new StrokeSample(new BasicStroke(2.0f)); this.availableStrokeSamples[2] = new StrokeSample(new BasicStroke(3.0f)); JTabbedPane other = getOtherTabs(); JPanel range = new JPanel(new LCBLayout(3)); range.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); range.add(new JPanel()); this.autoRangeCheckBox = new JCheckBox(localizationResources.getString("Auto-adjust_range"), this.autoRange); this.autoRangeCheckBox.setActionCommand("AutoRangeOnOff"); this.autoRangeCheckBox.addActionListener(this); range.add(this.autoRangeCheckBox); range.add(new JPanel()); range.add(new JLabel(localizationResources.getString("Minimum_range_value"))); this.minimumRangeValue = new JTextField(Double.toString(this.minimumValue)); this.minimumRangeValue.setEnabled(!this.autoRange); this.minimumRangeValue.setActionCommand("MinimumRange"); this.minimumRangeValue.addActionListener(this); this.minimumRangeValue.addFocusListener(this); range.add(this.minimumRangeValue); range.add(new JPanel()); range.add(new JLabel(localizationResources.getString("Maximum_range_value"))); this.maximumRangeValue = new JTextField(Double.toString(this.maximumValue)); this.maximumRangeValue.setEnabled(!this.autoRange); this.maximumRangeValue.setActionCommand("MaximumRange"); this.maximumRangeValue.addActionListener(this); this.maximumRangeValue.addFocusListener(this); range.add(this.maximumRangeValue); range.add(new JPanel()); other.add(localizationResources.getString("Range"), range); }
From source file:com.hmsinc.epicenter.webapp.remoting.ForecastingService.java
@Secured("ROLE_USER") @Transactional(readOnly = true)/* w w w . jav a2 s . c om*/ @RemoteMethod public String getSeasonalTrendChart(final AnalysisParametersDTO paramsDTO) { final AnalysisParameters params = convertParameters(paramsDTO); // 60 day window final DateTime windowStart = params.getEndDate().minusDays(59); // Set the start date back 1 year + 60 days params.setStartDate(windowStart.minusYears(1).minusDays(59)); final TimeSeriesChart chart = new TimeSeriesChart(); final TimeSeries ts = queryService.queryForTimeSeries(params, paramsDTO.getAlgorithmName(), null); if (ts != null) { final TimeSeries forecast = waveletSeasonalTrendForecaster.process(ts.after(windowStart), ts.before(windowStart.minusDays(1)), null); final TimeSeries known = forecast.before(params.getEndDate()); final TimeSeries predicted = forecast.after(params.getEndDate().plusDays(1)); chart.addBand("70% Confidence Prediction", predicted, ResultType.LOWER_BOUND_70, ResultType.UPPER_BOUND_70, new Color(0x0072bf), new Color(0x0072bf)); chart.addBand("80% Confidence Prediction", predicted, ResultType.LOWER_BOUND_80, ResultType.UPPER_BOUND_80, new Color(0x0099ff), new Color(0x0099ff)); chart.addBand("90% Confidence Prediction", predicted, ResultType.LOWER_BOUND_90, ResultType.UPPER_BOUND_90, new Color(0x3fb2ff), new Color(0x3fb2ff)); chart.addBand("95% Confidence Prediction", predicted, ResultType.LOWER_BOUND_95, ResultType.UPPER_BOUND_95, new Color(0xbfe5ff), new Color(0xbfe5ff)); chart.add("Actual Value", known, ChartColor.VALUE.getColor(), LineStyle.DOTTED); chart.add("Actual Trend", known, ResultType.TREND, ChartColor.VALUE.getColor(), LineStyle.THICK); final DateTime knownFirst = known.first().getTime(); final DateTime predictedFirst = predicted.first().getTime(); final Marker marker = new IntervalMarker( new Day(knownFirst.getDayOfMonth(), knownFirst.getMonthOfYear(), knownFirst.getYear()) .getFirstMillisecond(), new Day(predictedFirst.getDayOfMonth(), predictedFirst.getMonthOfYear(), predictedFirst.getYear()).getFirstMillisecond(), Color.LIGHT_GRAY, new BasicStroke(2.0f), null, null, 1.0f); marker.setAlpha(0.3f); chart.getMarkers().add(marker); chart.setYLabel(params.getDataRepresentation().getDisplayName()); chart.setAlwaysScaleFromZero(false); } return chartService.getChartURL(chart); }
From source file:org.optaplanner.benchmark.impl.statistic.memoryuse.MemoryUseProblemStatistic.java
@Override public void writeGraphFiles(BenchmarkReport benchmarkReport) { Locale locale = benchmarkReport.getLocale(); NumberAxis xAxis = new NumberAxis("Time spent"); xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale)); NumberAxis yAxis = new NumberAxis("Memory"); yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale)); XYPlot plot = new XYPlot(null, xAxis, yAxis, null); plot.setOrientation(PlotOrientation.VERTICAL); int seriesIndex = 0; for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) { XYSeries usedSeries = new XYSeries( singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " used"); // TODO enable max memory, but in the same color as used memory, but with a dotted line instead // XYSeries maxSeries = new XYSeries( // singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " max"); XYItemRenderer renderer = new XYLineAndShapeRenderer(); if (singleBenchmarkResult.isSuccess()) { MemoryUseSingleStatistic singleStatistic = (MemoryUseSingleStatistic) singleBenchmarkResult .getSingleStatistic(problemStatisticType); for (MemoryUseStatisticPoint point : singleStatistic.getPointList()) { long timeMillisSpent = point.getTimeMillisSpent(); MemoryUseMeasurement memoryUseMeasurement = point.getMemoryUseMeasurement(); usedSeries.add(timeMillisSpent, memoryUseMeasurement.getUsedMemory()); // maxSeries.add(timeMillisSpent, memoryUseMeasurement.getMaxMemory()); }//w w w .ja va 2 s . c o m } XYSeriesCollection seriesCollection = new XYSeriesCollection(); seriesCollection.addSeries(usedSeries); // seriesCollection.addSeries(maxSeries); plot.setDataset(seriesIndex, seriesCollection); if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) { // Make the favorite more obvious renderer.setSeriesStroke(0, new BasicStroke(2.0f)); // renderer.setSeriesStroke(1, new BasicStroke(2.0f)); } plot.setRenderer(seriesIndex, renderer); seriesIndex++; } JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " memory use statistic", JFreeChart.DEFAULT_TITLE_FONT, plot, true); graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "MemoryUseStatistic"); }
From source file:sim.util.media.chart.HistogramSeriesAttributes.java
public void rebuildGraphicsDefinitions() { XYBarRenderer renderer = (XYBarRenderer) (((XYPlot) getPlot()).getRenderer()); if (thickness == 0.0) renderer.setDrawBarOutline(false); else {//from w w w .j ava2 s . co m renderer.setSeriesOutlineStroke(getSeriesIndex(), new BasicStroke(thickness)); renderer.setDrawBarOutline(true); } renderer.setSeriesPaint(getSeriesIndex(), reviseColor(fillColor, fillOpacity)); renderer.setSeriesOutlinePaint(getSeriesIndex(), reviseColor(strokeColor, lineOpacity)); repaint(); }
From source file:net.sf.jasperreports.customizers.marker.AbstractMarkerCustomizer.java
protected BasicStroke getStroke(Float strokeWidth) { BasicStroke basicStroke = new BasicStroke(strokeWidth); StrokeStyleEnum strokeStyle = StrokeStyleEnum.getByName(getProperty(PROPERTY_STROKE_STYLE)); if (strokeStyle != null) { switch (strokeStyle) { case SOLID: { //do nothing; already created stroke is good break; }//www . j a va 2 s . c o m case DOTTED: { basicStroke = new BasicStroke(basicStroke.getLineWidth(), basicStroke.getEndCap(), basicStroke.getLineJoin(), basicStroke.getMiterLimit(), new float[] { 1.0f, 1.0f }, basicStroke.getDashPhase()); break; } case DASHED: { basicStroke = new BasicStroke(basicStroke.getLineWidth(), basicStroke.getEndCap(), basicStroke.getLineJoin(), basicStroke.getMiterLimit(), new float[] { 10.0f, 10.0f }, basicStroke.getDashPhase()); break; } } } return basicStroke; }