List of usage examples for java.awt BasicStroke JOIN_MITER
int JOIN_MITER
To view the source code for java.awt BasicStroke JOIN_MITER.
Click Source Link
From source file:com.planetmayo.debrief.satc_rcp.views.SpatialView.java
private void plotCurrentTopRoutes(List<CompositeRoute> _currentRoutes) { float width = 1.0f; for (CompositeRoute route : _currentRoutes) { Color currentColor = Color.BLACK; for (CoreRoute routePart : route.getLegs()) { Point startP = routePart.getStartPoint(); Point endP = routePart.getEndPoint(); XYSeries series = new XYSeries("" + (_numCycles++), false); series.add(new XYDataItem(startP.getY(), startP.getX())); series.add(new XYDataItem(endP.getY(), endP.getX())); // get the shape _myData.addSeries(series);/*from w w w . j a va 2s . co m*/ // get the series num int num = _myData.getSeriesCount() - 1; _renderer.setSeriesPaint(num, currentColor); _renderer.setSeriesStroke(num, new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, new float[] { 4.f, width }, 0.0f), false); _renderer.setSeriesLinesVisible(num, true); _renderer.setSeriesShapesVisible(num, false); } } }
From source file:lucee.runtime.img.Image.java
public void setDrawingStroke(Struct attr) throws PageException { // empty // w w w.ja v a2 s.c o m if (attr == null || attr.size() == 0) { setDrawingStroke(new BasicStroke()); return; } // width float width = Caster.toFloatValue(attr.get("width", new Float(1F))); if (width < 0) throw new ExpressionException("key [width] should be a none negativ number"); // endcaps String strEndcaps = Caster.toString(attr.get("endcaps", "square")); strEndcaps = strEndcaps.trim().toLowerCase(); int endcaps; if ("square".equals(strEndcaps)) endcaps = BasicStroke.CAP_SQUARE; else if ("butt".equals(strEndcaps)) endcaps = BasicStroke.CAP_BUTT; else if ("round".equals(strEndcaps)) endcaps = BasicStroke.CAP_ROUND; else throw new ExpressionException("key [endcaps] has an invalid value [" + strEndcaps + "], valid values are [square,round,butt]"); // linejoins String strLinejoins = Caster.toString(attr.get("linejoins", "miter")); strLinejoins = strLinejoins.trim().toLowerCase(); int linejoins; if ("bevel".equals(strLinejoins)) linejoins = BasicStroke.JOIN_BEVEL; else if ("miter".equals(strLinejoins)) linejoins = BasicStroke.JOIN_MITER; else if ("round".equals(strLinejoins)) linejoins = BasicStroke.JOIN_ROUND; else throw new ExpressionException("key [linejoins] has an invalid value [" + strLinejoins + "], valid values are [bevel,miter,round]"); // miterlimit float miterlimit = 10.0F; if (linejoins == BasicStroke.JOIN_MITER) { miterlimit = Caster.toFloatValue(attr.get("miterlimit", new Float(10F))); if (miterlimit < 1F) throw new ExpressionException("key [miterlimit] should be greater or equal to 1"); } // dashArray Object oDashArray = attr.get("dashArray", null); float[] dashArray = null; if (oDashArray != null) { dashArray = ArrayUtil.toFloatArray(oDashArray); } // dash_phase float dash_phase = Caster.toFloatValue(attr.get("dash_phase", new Float(0F))); setDrawingStroke(width, endcaps, linejoins, miterlimit, dashArray, dash_phase); }
From source file:weka.classifiers.timeseries.eval.graph.JFreeChartDriver.java
protected JFreeChart getFutureForecastChart(TSForecaster forecaster, List<List<NumericPrediction>> preds, List<String> targetNames, Instances history) { if (forecaster instanceof TSLagUser && history != null) { TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker(); if (lagMaker.getAdjustForTrends() && !lagMaker.isUsingAnArtificialTimeIndex()) { // fill in any missing time stamps only history = new Instances(history); history = weka.classifiers.timeseries.core.Utils.replaceMissing(history, null, lagMaker.getTimeStampField(), true, lagMaker.getPeriodicity(), lagMaker.getSkipEntries()); }/*from w w w. j a v a2 s. co m*/ } // set up a collection of series XYIntervalSeriesCollection xyDataset = new XYIntervalSeriesCollection(); if (history != null) { // add actual historical data values for (String targetName : targetNames) { XYIntervalSeries targetSeries = new XYIntervalSeries(targetName, false, false); xyDataset.addSeries(targetSeries); } } // add predicted series for (String targetName : targetNames) { XYIntervalSeries targetSeries = new XYIntervalSeries(targetName + "-predicted", false, false); xyDataset.addSeries(targetSeries); } ValueAxis timeAxis = null; NumberAxis valueAxis = new NumberAxis(""); valueAxis.setAutoRangeIncludesZero(false); int timeIndex = -1; boolean timeAxisIsDate = false; double artificialTimeStart = 0; double lastRealTimeValue = Utils.missingValue(); if (forecaster instanceof TSLagUser && history != null) { TSLagMaker lagMaker = ((TSLagUser) forecaster).getTSLagMaker(); if (!lagMaker.isUsingAnArtificialTimeIndex() && lagMaker.getAdjustForTrends()) { String timeName = lagMaker.getTimeStampField(); if (history.attribute(timeName).isDate()) { timeAxis = new DateAxis(""); timeAxisIsDate = true; timeIndex = history.attribute(timeName).index(); } } else { try { artificialTimeStart = (history != null) ? 1 : lagMaker.getArtificialTimeStartValue() + 1; } catch (Exception ex) { } } } if (timeAxis == null) { timeAxis = new NumberAxis(""); ((NumberAxis) timeAxis).setAutoRangeIncludesZero(false); } boolean hasConfidenceIntervals = false; // now populate the series if (history != null) { // do the actuals first for (int i = 0; i < history.numInstances(); i++) { Instance current = history.instance(i); for (String targetName : targetNames) { int dataIndex = history.attribute(targetName.trim()).index(); if (dataIndex >= 0) { XYIntervalSeries actualSeries = null; int actualIndex = xyDataset.indexOf(targetName); actualSeries = xyDataset.getSeries(actualIndex); double x = Utils.missingValue(); if (timeAxisIsDate) { x = current.value(timeIndex); if (!Utils.isMissingValue(x)) { lastRealTimeValue = x; } } else { x = artificialTimeStart; } double y = Utils.missingValue(); y = current.value(dataIndex); if (!Utils.isMissingValue(x) && !Utils.isMissingValue(y)) { if (actualSeries != null) { actualSeries.add(x, x, x, y, y, y); } } } } if (!timeAxisIsDate) { artificialTimeStart++; } } } // now do the futures List<String> forecasterTargets = AbstractForecaster.stringToList(forecaster.getFieldsToForecast()); // loop over the steps for (int j = 0; j < preds.size(); j++) { List<NumericPrediction> predsForStepJ = preds.get(j); // advance the real time index (if appropriate) if (timeAxisIsDate) { lastRealTimeValue = ((TSLagUser) forecaster).getTSLagMaker() .advanceSuppliedTimeValue(lastRealTimeValue); } for (String targetName : targetNames) { // look up this requested target in the list that the forecaster // has predicted int predIndex = forecasterTargets.indexOf(targetName.trim()); if (predIndex >= 0) { NumericPrediction predsForTargetAtStepJ = predsForStepJ.get(predIndex); XYIntervalSeries predSeries = null; int datasetIndex = xyDataset.indexOf(targetName + "-predicted"); predSeries = xyDataset.getSeries(datasetIndex); if (predSeries != null) { double y = predsForTargetAtStepJ.predicted(); double x = Utils.missingValue(); double yHigh = y; double yLow = y; double[][] conf = predsForTargetAtStepJ.predictionIntervals(); if (conf.length > 0) { yLow = conf[0][0]; yHigh = conf[0][1]; hasConfidenceIntervals = true; } if (!timeAxisIsDate) { x = artificialTimeStart; } else { x = lastRealTimeValue; } if (!Utils.isMissingValue(x) && !Utils.isMissingValue(y)) { predSeries.add(x, x, x, y, yLow, yHigh); } } } } // advance the artificial time index (if appropriate) if (!timeAxisIsDate) { artificialTimeStart++; } } String title = "Future forecast for: "; for (String s : targetNames) { title += s + ","; } title = title.substring(0, title.lastIndexOf(",")); /* * String algoSpec = forecaster.getAlgorithmName(); title += " (" + algoSpec * + ")"; */ if (forecaster instanceof WekaForecaster && hasConfidenceIntervals) { double confPerc = ((WekaForecaster) forecaster).getConfidenceLevel() * 100.0; title += " [" + Utils.doubleToString(confPerc, 0) + "% conf. intervals]"; } XYErrorRenderer renderer = new XYErrorRenderer(); // renderer.setShapesFilled(true); XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, renderer); // renderer = (XYErrorRenderer)plot.getRenderer(); if (history != null) { for (String targetName : targetNames) { XYIntervalSeries predSeries = null; int predIndex = xyDataset.indexOf(targetName + "-predicted"); predSeries = xyDataset.getSeries(predIndex); XYIntervalSeries actualSeries = null; int actualIndex = xyDataset.indexOf(targetName); actualSeries = xyDataset.getSeries(actualIndex); if (actualSeries != null && predSeries != null) { // match the color of the actual series java.awt.Paint actualPaint = renderer.lookupSeriesPaint(actualIndex); renderer.setSeriesPaint(predIndex, actualPaint); // now set the line style to dashed BasicStroke dashed = new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f }, 0.0f); renderer.setSeriesStroke(predIndex, dashed); } } } renderer.setBaseLinesVisible(true); renderer.setDrawXError(false); renderer.setDrawYError(true); JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true); chart.setBackgroundPaint(java.awt.Color.white); TextTitle chartTitle = chart.getTitle(); String fontName = chartTitle.getFont().getFontName(); java.awt.Font newFont = new java.awt.Font(fontName, java.awt.Font.PLAIN, 12); chartTitle.setFont(newFont); return chart; }
From source file:dbseer.gui.chart.DBSeerChartFactory.java
private static BasicStroke toStroke(int style) { BasicStroke result = null;/*from w w w. j a v a 2s . c o m*/ float lineWidth = 1.5f; float dash[] = { 5.0f }; float dot[] = { lineWidth }; if (style == STYLE_LINE) { result = new BasicStroke(lineWidth); } else if (style == STYLE_DASH) { result = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f); } else if (style == STYLE_DOT) { result = new BasicStroke(lineWidth * 2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 2.0f, dot, 0.0f); } return result; }
From source file:com.planetmayo.debrief.satc_rcp.views.SpatialView.java
private void plotRoutesWithScores(HashMap<LegWithRoutes, ArrayList<ScoredRoute>> legRoutes) { if (legRoutes.size() == 0) return;// w w w . j a v a 2 s . c o m // we need to store the point labels. get ready to store them _scoredRouteLabels.clear(); final DateFormat labelTimeFormat = new SimpleDateFormat("mm:ss"); // work through the legs Iterator<LegWithRoutes> lIter = legRoutes.keySet().iterator(); while (lIter.hasNext()) { final LegWithRoutes thisL = lIter.next(); final ArrayList<ScoredRoute> scoredRoutes = legRoutes.get(thisL); double max = 0, min = Double.MAX_VALUE; for (Iterator<ScoredRoute> iterator = scoredRoutes.iterator(); iterator.hasNext();) { ScoredRoute route = iterator.next(); // Ensure thisScore is between 0-100 double thisScore = route.theScore; thisScore = Math.log(thisScore); if (max < thisScore) { max = thisScore; } if (min > thisScore) { min = thisScore; } } System.out.println(" for leg: " + thisL.getClass().getName() + " min:" + min + " max:" + max); for (Iterator<ScoredRoute> iterator = scoredRoutes.iterator(); iterator.hasNext();) { ScoredRoute route = iterator.next(); Point startP = route.theRoute.getStartPoint(); Point endP = route.theRoute.getEndPoint(); // Ensure thisScore is between 0-100 double thisScore = route.theScore; thisScore = Math.log(thisScore); double thisColorScore = (thisScore - min) / (max - min); // System.out.println("this s:" + (int) thisScore + " was:" // + route.theScore); XYSeries series = new XYSeries("" + (_numCycles++), false); series.add(new XYDataItem(startP.getY(), startP.getX())); series.add(new XYDataItem(endP.getY(), endP.getX())); // get the shape _myData.addSeries(series); // get the series num int num = _myData.getSeriesCount() - 1; _renderer.setSeriesPaint(num, getHeatMapColorFor(thisColorScore)); // make the line width inversely proportional to the score, with a max // width of 2 pixels final float width = (float) (2f - 2 * thisColorScore); // make the top score solid, and worse scores increasingly sparse final float dash[]; if (thisScore == min) { dash = null; } else { float thisWid = (float) (1f + Math.exp(thisScore - min) / 3); float[] tmpDash = { 4, thisWid }; dash = tmpDash; } // and put this line thickness, dashing into a stroke object BasicStroke stroke = new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, dash, 0.0f); _renderer.setSeriesStroke(num, stroke, false); _renderer.setSeriesLinesVisible(num, true); _renderer.setSeriesShapesVisible(num, false); _renderer.setSeriesVisibleInLegend(num, false); // ok, we'll also show the route points XYSeries series2 = new XYSeries("" + (_numCycles++), false); ArrayList<String> theseLabels = new ArrayList<String>(); // loop through the points Iterator<State> stIter = route.rawRoute.getStates().iterator(); while (stIter.hasNext()) { State state = (State) stIter.next(); Point loc = state.getLocation(); XYDataItem newPt = new XYDataItem(loc.getY(), loc.getX()); series2.add(newPt); // and store the label for this point theseLabels.add(labelTimeFormat.format(state.getTime())); } // get the shape _myData.addSeries(series2); // // // get the series num num = _myData.getSeriesCount() - 1; // ok, we now need to put hte series into the right slot _scoredRouteLabels.put(num, theseLabels); if (_settings.isShowRoutePointLabels()) { _renderer.setSeriesItemLabelGenerator(num, new XYItemLabelGenerator() { @Override public String generateLabel(XYDataset arg0, int arg1, int arg2) { String res = null; ArrayList<String> thisList = _scoredRouteLabels.get(arg1); if (thisList != null) { res = thisList.get(arg2); } return res; } }); _renderer.setSeriesItemLabelPaint(num, getHeatMapColorFor(thisColorScore)); } // _renderer.setSeriesPaint(num, getHeatMapColorFor(thisColorScore)); _renderer.setSeriesItemLabelsVisible(num, _settings.isShowRoutePointLabels()); _renderer.setSeriesLinesVisible(num, false); _renderer.setSeriesPaint(num, getHeatMapColorFor(thisColorScore)); _renderer.setSeriesShapesVisible(num, _settings.isShowRoutePoints()); _renderer.setSeriesVisibleInLegend(num, false); } } }
From source file:de.fau.amos.ChartRenderer.java
/** * Creates Chart (JFreeChart object) using TimeSeriesCollection. Used for forecast only. * /* w w w . j a va 2s . c o m*/ * @param collection TimeSeriesCollection that provides basis for chart. * @param time Time where "real" data ends. * @param unit Unit of displayed values (kWh,TNF,kWh/TNF) * @return Returns finished JFreeChart. */ private JFreeChart createForecastChart(final TimeSeriesCollection collection, String time, String unit) { // Modification of X-Axis Label int day = Integer.parseInt(time.substring(8, 10)); int month = Integer.parseInt(time.substring(5, 7)); int year = Integer.parseInt(time.substring(0, 4)); //get Weekday Calendar c = Calendar.getInstance(); c.set(year, month - 1, day, 0, 0); int weekDay = c.get(Calendar.DAY_OF_WEEK); String dayString = new DateFormatSymbols(Locale.US).getWeekdays()[weekDay] + ", " + day + ". "; String monthString = new DateFormatSymbols(Locale.US).getMonths()[month - 1]; String xAxisLabel = "" + dayString + monthString + " " + time.substring(0, 4); //Creation of the lineChart JFreeChart lineChart = ChartFactory.createTimeSeriesChart("Forecast", // title xAxisLabel, // x-axis label // "Energy Consumption "+("1".equals(unit)?"[kWh]":("2".equals(unit)?"[kWh/TNF]":("3".equals(unit)?"[TNF]":""))), // y-axis label ("1".equals(unit) ? "Energy Consumption [kWh]" : ("2".equals(unit) ? "Energy Consumption [kWh/TNF]" : ("3".equals(unit) ? "Produced Pieces [TNF]" : ""))), collection, // data true, // create legend? false, // generate tooltips? false // generate URLs? ); //graphical modifications for LineChart lineChart.setBackgroundPaint(Color.white); XYPlot plot = lineChart.getXYPlot(); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(0, 0, 0, 0)); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer() { private static final long serialVersionUID = 1L; // Stroke soild = new BasicStroke(2.0f); Stroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 10.0f }, 0.0f); @Override public Stroke getItemStroke(int row, int column) { //third series in collection -> forecast collection if (row == 2) { return dashed; //partial dashed->not needed now, maybe later // double x = collection.getXValue(row, column); // // if ( x > 4){ // return dashed; // } else { // return soild; // } } else return super.getItemStroke(row, column); } }; renderer.setBaseShapesVisible(false); renderer.setBaseShapesFilled(true); renderer.setBaseStroke(new BasicStroke(3)); plot.setRenderer(renderer); return lineChart; }
From source file:org.jfree.experimental.swt.SWTGraphics2D.java
/** * Returns the AWT line join corresponding to the specified SWT line join. * * @param swtLineJoin the SWT line join. * * @return The AWT line join./* w ww . j ava 2s . c o m*/ */ private int toAwtLineJoin(int swtLineJoin) { if (swtLineJoin == SWT.JOIN_BEVEL) { return BasicStroke.JOIN_BEVEL; } else if (swtLineJoin == SWT.JOIN_MITER) { return BasicStroke.JOIN_MITER; } else if (swtLineJoin == SWT.JOIN_ROUND) { return BasicStroke.JOIN_ROUND; } else { throw new IllegalArgumentException("SWT LineJoin " + swtLineJoin + " not recognised"); } }
From source file:org.jfree.experimental.swt.SWTGraphics2D.java
/** * Returns the SWT line join corresponding to the specified AWT line join. * * @param awtLineJoin the AWT line join. * * @return The SWT line join./*from w ww . ja v a 2s. c o m*/ */ private int toSwtLineJoin(int awtLineJoin) { if (awtLineJoin == BasicStroke.JOIN_BEVEL) { return SWT.JOIN_BEVEL; } else if (awtLineJoin == BasicStroke.JOIN_MITER) { return SWT.JOIN_MITER; } else if (awtLineJoin == BasicStroke.JOIN_ROUND) { return SWT.JOIN_ROUND; } else { throw new IllegalArgumentException("AWT LineJoin " + awtLineJoin + " not recognised"); } }
From source file:eu.udig.style.advanced.utils.Utilities.java
/** * Convert a sld line join definition to the java awt value. * //from ww w . j a v a2 s .c om * @param sldJoin the sld join string. * @return the awt value. */ public static int sld2awtJoin(String sldJoin) { if (sldJoin.equals(lineJoinNames[1])) { return BasicStroke.JOIN_BEVEL; } else if (sldJoin.equals("") || sldJoin.equals(lineJoinNames[2])) { return BasicStroke.JOIN_MITER; } else if (sldJoin.equals(lineJoinNames[3])) { return BasicStroke.JOIN_ROUND; } else { throw new IllegalArgumentException("unsupported line join"); } }
From source file:jhplot.HChart.java
/** * // w ww . ja v a2 s . c om * @param type * =0 - solid, 1-dashed, 2-dashed-dotted,3 dotted * @param width * width * @return */ private Stroke getStrokes(int type, float width, float dash) { float[][] pattern = { { dash }, { dash, dash }, { dash, dash, dash * 0.3f, dash }, { dash * 0.3f, dash * 2f } }; if (type == 0) return new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f); // solid line if (type == 1) return new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, pattern[1], 0.0f); // dashed // line if (type == 2) return new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, pattern[2], 0.0f); // dash-dotted // line if (type == 3) return new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER, 10.0f, pattern[3], 0.0f); // dotted // line return new BasicStroke(width, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f); }