List of usage examples for java.awt Color LIGHT_GRAY
Color LIGHT_GRAY
To view the source code for java.awt Color LIGHT_GRAY.
Click Source Link
From source file:org.oscarehr.web.reports.ocan.NeedRatingOverTimeReportGenerator.java
private JFreeChart generateNeedsOverTimeChart() { CategoryDataset dataset = this.createDataset(); JFreeChart chart = ChartFactory.createStackedBarChart("Needs over Time (Consumer and Staff)", // chart title "Assessments", // x axis label "# of Domain", // y axis label dataset, // data PlotOrientation.VERTICAL, true, // include legend true, // tooltips false // urls );//from w w w. j a v a 2 s.c o m chart.setBackgroundPaint(Color.LIGHT_GRAY); GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer(); KeyToGroupMap map = new KeyToGroupMap("G1"); map.mapKeyToGroup("Consumer (Unknown)", "G1"); map.mapKeyToGroup("Consumer (No Needs)", "G1"); map.mapKeyToGroup("Consumer (Met Needs)", "G1"); map.mapKeyToGroup("Consumer (Unmet Needs)", "G1"); map.mapKeyToGroup("Staff (Unknown)", "G2"); map.mapKeyToGroup("Staff (No Needs)", "G2"); map.mapKeyToGroup("Staff (Met Needs)", "G2"); map.mapKeyToGroup("Staff (Unmet Needs)", "G2"); renderer.setSeriesToGroupMap(map); renderer.setItemMargin(0.1); //renderer.setItemLabelsVisible(true); renderer.setMaximumBarWidth(15); Paint p1 = Color.GREEN; renderer.setSeriesPaint(0, p1); renderer.setSeriesPaint(4, p1); renderer.setSeriesPaint(7, p1); Paint p2 = Color.BLUE; renderer.setSeriesPaint(1, p2); renderer.setSeriesPaint(5, p2); renderer.setSeriesPaint(8, p2); Paint p3 = new Color(255, 255, 153); renderer.setSeriesPaint(2, p3); renderer.setSeriesPaint(6, p3); renderer.setSeriesPaint(9, p3); Paint p4 = Color.ORANGE; renderer.setSeriesPaint(3, p4); renderer.setSeriesPaint(7, p4); renderer.setSeriesPaint(10, p4); SubCategoryAxis domainAxis = new SubCategoryAxis("Assessments"); domainAxis.setCategoryMargin(0.05); domainAxis.addSubCategory("Consumer"); domainAxis.addSubCategory("Staff"); domainAxis.setMinorTickMarkInsideLength(10); domainAxis.setMinorTickMarkInsideLength(10); domainAxis.setMinorTickMarksVisible(true); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDomainAxis(domainAxis); plot.setRenderer(renderer); LegendItemCollection result = new LegendItemCollection(); LegendItem item1 = new LegendItem("Unknown", Color.GREEN); LegendItem item2 = new LegendItem("No Needs", Color.BLUE); LegendItem item3 = new LegendItem("Met Needs", new Color(255, 255, 153)); LegendItem item4 = new LegendItem("Unmet Needs", Color.ORANGE); result.add(item1); result.add(item2); result.add(item3); result.add(item4); plot.setFixedLegendItems(result); plot.setBackgroundPaint(Color.lightGray); plot.setRangeGridlinePaint(Color.black); NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setRange(new Range(0, 24), true, false); rangeAxis.setTickUnit(new NumberTickUnit(4)); plot.getDomainAxis().setCategoryMargin(0.35); renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator()); renderer.setBaseItemLabelsVisible(true); renderer.setBasePositiveItemLabelPosition( new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.BASELINE_LEFT)); return chart; }
From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java
/** * *//*from w w w .j ava 2 s . c om*/ protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); GradientPaint gp = new GradientPaint(new Point(), Color.LIGHT_GRAY, new Point(), Color.BLACK, false); GradientPaint gp2 = new GradientPaint(new Point(), Color.GRAY, new Point(), Color.BLACK); // get data for diagrams DialPlot dialPlot = new DialPlot(); //dialPlot.setView(0.0, 0.0, 1.0, 1.0); if (getDataset() != null) { dialPlot.setDataset((ValueDataset) getDataset()); } StandardDialFrame dialFrame = new StandardDialFrame(); //dialFrame.setRadius(0.60); //dialFrame.setBackgroundPaint(gp2); dialFrame.setForegroundPaint(gp2); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); dialPlot.setBackground(db); StandardDialScale scale = null; int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale); double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale); scale = new StandardDialScale(lowerBound, upperBound, 225, -270, (upperBound - lowerBound) / 6, 15); if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) { scale.setTickLabelFormatter(new DecimalFormat("#,##0")); } else if (dialUnitScale == 1) { scale.setTickLabelFormatter(new DecimalFormat("#,##0.0")); } else if (dialUnitScale <= 0) { scale.setTickLabelFormatter(new DecimalFormat("#,##0.00")); } } else { scale = new StandardDialScale(); } scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); scale.setTickLabelFont(themeTickLabelFont); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.3f)); scale.setMajorTickPaint(Color.WHITE); scale.setMinorTickPaint(Color.WHITE); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); dialPlot.addScale(0, scale); List intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 3) colorStep = 255 / (size - 3); for (int i = 0; i < size; i++) { JRMeterInterval interval = (JRMeterInterval) intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(), dialUnitScale); double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(), dialUnitScale); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound, interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 12f); dialRange.setInnerRadius(0.41); dialRange.setOuterRadius(0.41); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.parseBoolean(displayVisibility)) { ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) dvi.setNumberFormat(new DecimalFormat(pattern)); dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { JRFont displayFont = jrPlot.getValueDisplay().getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); if (dialUnitScale < 0) label = new MessageFormat(label) .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) }); else if (dialUnitScale < 3) label = new MessageFormat(label).format(new Object[] { "1" }); else label = new MessageFormat(label) .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) }); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(Color.WHITE); dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } //DialPointer needle = new DialPointer.Pointer(); Paint paint = new Color(191, 48, 0); DialPointer needle = new ScaledDialPointer(dialUnitScale, paint, paint); needle.setVisible(true); needle.setRadius(0.91); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.DARK_GRAY); cap.setOutlinePaint(Color.GRAY); cap.setOutlineStroke(new BasicStroke(0.5f)); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart((String) evaluateExpression(getChart().getTitleExpression()), null, dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend().booleanValue()); // Set all the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false); return jfreeChart; }
From source file:org.nuclos.client.ui.collect.SubForm.java
private void init() { contentPane.add(toolbar,//from w ww . java 2s . c o m toolbar.getOrientation() == JToolBar.HORIZONTAL ? BorderLayout.NORTH : BorderLayout.WEST); // Configure table scrollPane.getViewport().setBackground(subformtbl.getBackground()); subformtbl.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); subformtbl.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); // subformtbl.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); scrollPane.getViewport().setView(subformtbl); JLabel labCorner = new JLabel(); labCorner.setEnabled(false); labCorner.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 1, Color.GRAY)); labCorner.setBackground(Color.LIGHT_GRAY); scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, labCorner); rowHeader = createTableRowHeader(subformtbl, scrollPane); subformtbl.setRowHeaderTable(rowHeader); // subformtbl.addMouseListener(newToolbarContextMenuListener(subformtbl, subformtbl)); addToolbarMouseListener(subformtbl, subformtbl, subformtbl); // scrollPane.getViewport().addMouseListener(newToolbarContextMenuListener(scrollPane.getViewport(), subformtbl)); addToolbarMouseListener(scrollPane.getViewport(), scrollPane.getViewport(), subformtbl); }
From source file:au.com.gaiaresources.bdrs.controller.test.TestDataCreator.java
private byte[] createImage(int width, int height, String text) throws IOException { if (width < 0) { width = random.nextInt(DEFAULT_MAX_IMAGE_WIDTH - DEFAULT_MIN_IMAGE_WIDTH) + DEFAULT_MIN_IMAGE_WIDTH; }//from w ww .j a v a 2s. c om if (height < 0) { height = random.nextInt(DEFAULT_MAX_IMAGE_HEIGHT - DEFAULT_MIN_IMAGE_HEIGHT) + DEFAULT_MIN_IMAGE_HEIGHT; } BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) img.getGraphics(); g2.setBackground(new Color(220, 220, 220)); Dimension size; float fontSize = g2.getFont().getSize(); // Make the text as large as possible. do { g2.setFont(g2.getFont().deriveFont(fontSize)); FontMetrics metrics = g2.getFontMetrics(g2.getFont()); int hgt = metrics.getHeight(); int adv = metrics.stringWidth(text); size = new Dimension(adv + 2, hgt + 2); fontSize = fontSize + 1f; } while (size.width < Math.round(0.9 * width) && size.height < Math.round(0.9 * height)); g2.setColor(Color.DARK_GRAY); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.drawString(text, (width - size.width) / 2, (height - size.height) / 2); g2.setColor(Color.LIGHT_GRAY); g2.drawRect(0, 0, width - 1, height - 1); ByteArrayOutputStream baos = new ByteArrayOutputStream(width * height); ImageIO.write(img, "png", baos); baos.flush(); byte[] rawBytes = baos.toByteArray(); baos.close(); return rawBytes; }
From source file:org.ala.spatial.web.services.GDMWSController.java
public static void generateChart5(String outputdir, String plotName, String plotData) { try {//ww w . j ava 2 s . c o m CSVReader csv = new CSVReader(new FileReader(plotData)); List<String[]> rawdata = csv.readAll(); double[][] dataCht = new double[2][rawdata.size() - 1]; for (int i = 1; i < rawdata.size(); i++) { String[] row = rawdata.get(i); dataCht[0][i - 1] = Double.parseDouble(row[0]); dataCht[1][i - 1] = Double.parseDouble(row[1]); } DefaultXYDataset dataset = new DefaultXYDataset(); dataset.addSeries("", dataCht); System.out.println("Setting up jChart for " + plotName); //generateChartByType(plotName, plotName, "f("+plotName+")", null, outputdir, "xyline", plotName); JFreeChart jChart = ChartFactory.createXYLineChart(plotName, plotName, "f(" + plotName + ")", dataset, PlotOrientation.VERTICAL, false, false, false); jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); XYPlot plot = (XYPlot) jChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setDomainZeroBaselineVisible(true); plot.setRangeZeroBaselineVisible(true); plot.setDomainGridlinesVisible(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1)); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setAutoRangeIncludesZero(false); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); System.out.println("Writing image...."); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + plotName + ".png"), jChart, 500, 500); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + plotName + "_thumb.png"), jChart, 210, 140); } catch (Exception e) { System.out.println("Unable to generate charts 2 and 3:"); e.printStackTrace(System.out); } }
From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java
@Override protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); GradientPaint gp = new GradientPaint(new Point(), Color.LIGHT_GRAY, new Point(), Color.BLACK, false); GradientPaint gp2 = new GradientPaint(new Point(), Color.GRAY, new Point(), Color.BLACK); // get data for diagrams DialPlot dialPlot = new DialPlot(); //dialPlot.setView(0.0, 0.0, 1.0, 1.0); if (getDataset() != null) { dialPlot.setDataset((ValueDataset) getDataset()); }//w w w.j ava 2 s . c o m StandardDialFrame dialFrame = new StandardDialFrame(); //dialFrame.setRadius(0.60); //dialFrame.setBackgroundPaint(gp2); dialFrame.setForegroundPaint(gp2); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(gp); db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); dialPlot.setBackground(db); StandardDialScale scale = null; int dialUnitScale = 1; Range range = convertRange(jrPlot.getDataRange()); if (range != null) { double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); dialUnitScale = ChartThemesUtilities.getScale(bound); double lowerBound = ChartThemesUtilities.getTruncatedValue(range.getLowerBound(), dialUnitScale); double upperBound = ChartThemesUtilities.getTruncatedValue(range.getUpperBound(), dialUnitScale); int tickCount = jrPlot.getTickCount() != null && jrPlot.getTickCount() > 1 ? jrPlot.getTickCount() : 7; scale = new StandardDialScale(lowerBound, upperBound, 225, -270, (upperBound - lowerBound) / (tickCount - 1), 15); if ((lowerBound == (int) lowerBound && upperBound == (int) upperBound && scale.getMajorTickIncrement() == (int) scale.getMajorTickIncrement()) || dialUnitScale > 1) { scale.setTickLabelFormatter( new DecimalFormat("#,##0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale == 1) { scale.setTickLabelFormatter( new DecimalFormat("#,##0.0", DecimalFormatSymbols.getInstance(getLocale()))); } else if (dialUnitScale <= 0) { scale.setTickLabelFormatter( new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(getLocale()))); } else { // localizing the default tick label formatter scale.setTickLabelFormatter( new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale()))); } } else { scale = new StandardDialScale(); // localizing the default tick label formatter scale.setTickLabelFormatter(new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale()))); } scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); JRFont tickLabelFont = jrPlot.getTickLabelFont(); Integer defaultBaseFontSize = (Integer) getDefaultValue(defaultChartPropertiesMap, ChartThemesConstants.BASEFONT_SIZE); Font themeTickLabelFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_TICK_LABEL_FONT), tickLabelFont, defaultBaseFontSize); scale.setTickLabelFont(themeTickLabelFont); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.3f)); scale.setMajorTickPaint(Color.WHITE); scale.setMinorTickPaint(Color.WHITE); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); dialPlot.addScale(0, scale); List<JRMeterInterval> intervals = jrPlot.getIntervals(); if (intervals != null && intervals.size() > 0) { int size = Math.min(3, intervals.size()); int colorStep = 0; if (size > 3) colorStep = 255 / (size - 3); for (int i = 0; i < size; i++) { JRMeterInterval interval = intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); double intervalLowerBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getLowerBound(), dialUnitScale); double intervalUpperBound = ChartThemesUtilities.getTruncatedValue(intervalRange.getUpperBound(), dialUnitScale); Color color = i < 3 ? (Color) ChartThemesConstants.AEGEAN_INTERVAL_COLORS.get(i) : new Color(255 - colorStep * (i - 3), 0 + colorStep * (i - 3), 0); ScaledDialRange dialRange = new ScaledDialRange(intervalLowerBound, intervalUpperBound, interval.getBackgroundColor() == null ? color : interval.getBackgroundColor(), 12f); dialRange.setInnerRadius(0.41); dialRange.setOuterRadius(0.41); dialPlot.addLayer(dialRange); } } JRValueDisplay display = jrPlot.getValueDisplay(); String displayVisibility = display != null && getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_VALUE_DISPLAY_VISIBLE) : "false"; if (Boolean.parseBoolean(displayVisibility)) { ScaledDialValueIndicator dvi = new ScaledDialValueIndicator(0, dialUnitScale); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(JRFontUtil.getAwtFont(jrFont).deriveFont(10f).deriveFont(Font.BOLD)); dvi.setOutlinePaint(ChartThemesConstants.TRANSPARENT_PAINT); dvi.setPaint(Color.WHITE); String pattern = display.getMask() != null ? display.getMask() : "#,##0.####"; if (pattern != null) dvi.setNumberFormat(new DecimalFormat(pattern, DecimalFormatSymbols.getInstance(getLocale()))); dvi.setRadius(0.15); dvi.setValueAnchor(RectangleAnchor.CENTER); dvi.setTextAnchor(TextAnchor.CENTER); //dvi.setTemplateValue(Double.valueOf(getDialTickValue(dialPlot.getValue(0),dialUnitScale))); dialPlot.addLayer(dvi); } String label = getChart().hasProperties() ? getChart().getPropertiesMap().getProperty(DefaultChartTheme.PROPERTY_DIAL_LABEL) : null; if (label != null) { JRFont displayFont = jrPlot.getValueDisplay().getFont(); Font themeDisplayFont = getFont( (JRFont) getDefaultValue(defaultPlotPropertiesMap, ChartThemesConstants.PLOT_DISPLAY_FONT), displayFont, defaultBaseFontSize); if (dialUnitScale < 0) label = new MessageFormat(label) .format(new Object[] { String.valueOf(Math.pow(10, dialUnitScale)) }); else if (dialUnitScale < 3) label = new MessageFormat(label).format(new Object[] { "1" }); else label = new MessageFormat(label) .format(new Object[] { String.valueOf((int) Math.pow(10, dialUnitScale - 2)) }); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(Color.WHITE); dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } //DialPointer needle = new DialPointer.Pointer(); Paint paint = new Color(191, 48, 0); DialPointer needle = new ScaledDialPointer(dialUnitScale, paint, paint); needle.setVisible(true); needle.setRadius(0.91); dialPlot.addLayer(needle); DialCap cap = new DialCap(); cap.setRadius(0.05); cap.setFillPaint(Color.DARK_GRAY); cap.setOutlinePaint(Color.GRAY); cap.setOutlineStroke(new BasicStroke(0.5f)); dialPlot.setCap(cap); JFreeChart jfreeChart = new JFreeChart(evaluateTextExpression(getChart().getTitleExpression()), null, dialPlot, getChart().getShowLegend() == null ? false : getChart().getShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); jfreeChart.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); jfreeChart.setBorderVisible(false); return jfreeChart; }
From source file:nl.detoren.ijsco.ui.Mainscreen.java
public JPanel createPanelScenarios() { JPanel panel = new JPanel(); panel.setBackground(Color.RED); panel.setLayout(new GridLayout(1, 0)); schemaModel = new SchemaModel(panel, status.schemas); schemaTabel = new JTable(schemaModel) { @Override//from w w w . j ava2s. c o m public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer(renderer, row, column); // Tooltip if (c instanceof JComponent) { SchemaModel model = (SchemaModel) getModel(); ((JComponent) c).setToolTipText(model.getToolTip(row, column).toString()); } // Alternate row color if (!isRowSelected(row)) { c.setBackground(row % 2 == 0 ? Color.WHITE : Color.LIGHT_GRAY); } return c; } }; schemaTabel.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { panel.getParent().getParent().repaint(); } }); JScrollPane scrollpane = new JScrollPane(); scrollpane.setViewportView(schemaTabel); //panel.add(scrollpane, new ExtendedGridConstraints(0, 2)); panel.add(scrollpane); return panel; }
From source file:org.ala.spatial.web.services.GDMWSController.java
public static void generateChartByType(String title, String xLabel, String yLabel, Dataset dataset, String outputdir, String type, String filename) throws IOException { JFreeChart jChart = null;/*from ww w . j ava 2s . c o m*/ if ("line".equalsIgnoreCase(type)) { jChart = ChartFactory.createLineChart(title, xLabel, yLabel, (CategoryDataset) dataset, PlotOrientation.VERTICAL, false, false, false); } else if ("bar".equalsIgnoreCase(type)) { System.out.println("Setting up jChart"); jChart = ChartFactory.createBarChart(title, xLabel, yLabel, (CategoryDataset) dataset, PlotOrientation.VERTICAL, false, false, false); System.out.println("Writing image...."); } else if ("xyline".equalsIgnoreCase(type)) { jChart = ChartFactory.createXYLineChart(title, xLabel, yLabel, (XYDataset) dataset, PlotOrientation.VERTICAL, false, false, false); } if ("xyline".equalsIgnoreCase(type)) { XYPlot plot = (XYPlot) jChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeZeroBaselineVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); domain.setAutoRangeIncludesZero(false); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount()); //System.out.println("dataset.getRowCount(): " + dataset.getRowCount()); } else { CategoryPlot plot = (CategoryPlot) jChart.getPlot(); plot.setBackgroundPaint(Color.WHITE); plot.setRangeZeroBaselineVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1)); CategoryAxis domain = (CategoryAxis) plot.getDomainAxis(); domain.setAxisLineVisible(false); domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); NumberAxis range = (NumberAxis) plot.getRangeAxis(); range.setAutoRangeIncludesZero(false); range.setAxisLineVisible(false); range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); //System.out.println("dataset.getColumnCount(): " + dataset.getColumnCount()); //System.out.println("dataset.getRowCount(): " + dataset.getRowCount()); } jChart.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14)); ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/" + filename + ".png"), jChart, 900, 500); }
From source file:com.diversityarrays.kdxplore.specgroup.SpecimenGroupEditor.java
private JComponent createBottomComponent() { // =========//from ww w. jav a2s . c o m specimenTableModel = new SpecimenTableModel(null); specimenTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { exportSpecimenList.setEnabled(specimenTableModel.getRowCount() > 0); } }); specimenTable = new JTable(specimenTableModel); specimenTable.setAutoCreateRowSorter(true); specimenTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { deleteSpecimenFromList.setEnabled(specimenTable.getSelectedRowCount() > 0); } } }); // specimenTableModel.addTableModelListener(new TableModelListener() { // @Override // public void tableChanged(TableModelEvent e) { // fileDropTarget.setVisible(specimenTableModel.getRowCount() > 0); // } // }); CompoundBorder border = new CompoundBorder(new LineBorder(Color.DARK_GRAY), new EmptyBorder(4, 2, 4, 2)); fileDropTarget.setBorder(border); fileDropTarget.setBackground(Color.LIGHT_GRAY); // fileDropTarget.setVisible(false); deleteSpecimenFromList.setEnabled(false); TitledTablePanel specimenTablePanel = new TitledTablePanel("Specimen", specimenTable, "Download from database,\n Drag/drop Specimens or Drag/drop CSV File above"); // saveAction.setEnabled(false); // downloadSpecimenList.setEnabled(false); exportSpecimenList.setEnabled(false); Box otherBox = Box.createHorizontalBox(); otherBox.add(downloadSpecimensButton); otherBox.add(fileDropTarget); otherBox.add(Box.createHorizontalGlue()); otherBox.add(new JButton(exportSpecimenList)); otherBox.add(Box.createHorizontalGlue()); otherBox.add(new JLabel("(local)")); otherBox.add(new JButton(deleteSpecimenFromList)); JPanel containerPanel2 = new JPanel(new BorderLayout()); containerPanel2.add(otherBox, BorderLayout.NORTH); containerPanel2.add(specimenTablePanel, BorderLayout.CENTER); fileDropTarget.setTransferHandler(flth); // TableTransferHandler tth2 = TableTransferHandler.initialiseForCopySelectAll(specimenTable, true); // ChainingTransferHandler cth = new ChainingTransferHandler(flth, genotypeTransferHandler, tth2); TransferHandler cth = genotypeTransferHandler; // ChainingTH cth = new ChainingTH(genotypeTransferHandler, tth2); specimenTablePanel.scrollPane.setTransferHandler(cth); specimenTablePanel.setTransferHandler(cth); specimenTable.setTransferHandler(cth); specimenTable.setDragEnabled(true); return containerPanel2; }
From source file:msi.gama.outputs.layers.ChartLayerStatement.java
public void updateseries(final IScope scope) throws GamaRuntimeException { // datas=dataswithoutlists; datasfromlists = new ArrayList<ChartData>(); for (int dl = 0; dl < datalists.size(); dl++) { ChartDataList datalist = datalists.get(dl); Object val = datalist.valuelistexp.resolveAgainst(scope).value(scope); if (!(val instanceof GamaList)) { // GuiUtils.debug("chart list with no list..."); return; }// w ww.j a va 2 s. com List<List> values = Cast.asList(scope, val); if (datalist.doreverse) { List tempvalues = Cast.asList(scope, val); values = new ArrayList<List>(); if (tempvalues.get(0) instanceof GamaList) { IList nval = Cast.asList(scope, tempvalues.get(0)); for (int j = 0; j < nval.size(); j++) { List nl = new ArrayList(); nl.add(nval.get(j)); values.add(nl); } } else { // GuiUtils.debug("Reverse series but not list of list..." + tempvalues); return; } if (tempvalues.size() > 1) { for (int i = 1; i < tempvalues.size(); i++) { if (tempvalues.get(i) instanceof GamaList) { IList nval = Cast.asList(scope, tempvalues.get(i)); for (int j = 0; j < nval.size(); j++) { // Cast.asList(scope, values.get(j)).add(nval.get(j)); values.get(j).add(nval.get(j)); } } else { // GuiUtils.debug("Reverse series but not list of list..." + tempvalues); return; } } } // GuiUtils.debug("New Values"+values); } List defaultnames = new ArrayList<String>(); List defaultcolors = new ArrayList<GamaColor>(); for (int i = 0; i < values.size() + 1; i++) { defaultnames.add("data" + i); // defaultcolors.add(GamaColor.array[i]); if (i < 10) { if (i == 0) { defaultcolors.add(Cast.asColor(scope, Color.CYAN)); } if (i == 1) { defaultcolors.add(Cast.asColor(scope, Color.RED)); } if (i == 2) { defaultcolors.add(Cast.asColor(scope, Color.YELLOW)); } if (i == 3) { defaultcolors.add(Cast.asColor(scope, Color.GREEN)); } if (i == 4) { defaultcolors.add(Cast.asColor(scope, Color.BLUE)); } if (i == 5) { defaultcolors.add(Cast.asColor(scope, Color.PINK)); } if (i == 6) { defaultcolors.add(Cast.asColor(scope, Color.MAGENTA)); } if (i == 7) { defaultcolors.add(Cast.asColor(scope, Color.ORANGE)); } if (i == 8) { defaultcolors.add(Cast.asColor(scope, Color.LIGHT_GRAY)); } if (i == 9) { defaultcolors.add(Cast.asColor(scope, Color.DARK_GRAY)); } } if (i >= 10) { if (i < GamaColor.colors.size()) { defaultcolors.add(GamaColor.int_colors.values()[i]); } else { defaultcolors.add(GamaColor.getInt(Random.opRnd(scope, 10000))); } } } if (datalist.colorlistexp != null) { Object valcol = datalist.colorlistexp.resolveAgainst(scope).value(scope); if (valcol instanceof GamaList) { for (int c = 0; c < ((GamaList) valcol).size(); c++) { // if ( type == SERIES_CHART) // defaultcolors.set(c+1, Cast.asColor(scope, ((GamaList)valcol).get(c))); // else defaultcolors.set(c, Cast.asColor(scope, ((GamaList) valcol).get(c))); } } } boolean dynamicseriesnames = false; List<String> seriesnames = new ArrayList(); if (datalist.legendlistexp != null) { Object valc = datalist.legendlistexp.resolveAgainst(scope).value(scope); if (valc instanceof GamaList) { dynamicseriesnames = true; seriesnames = (GamaList) valc; for (int i = 0; i < Math.min(values.size(), seriesnames.size()); i++) { defaultnames.set(i, seriesnames.get(i) + "(" + i + ")"); if (type == SERIES_CHART && ((XYPlot) chart.getPlot()).getDataset(i + 1) != null) { if (((DefaultTableXYDataset) ((XYPlot) chart.getPlot()).getDataset(i + 1)) .getSeriesCount() > 0) { ((DefaultTableXYDataset) ((XYPlot) chart.getPlot()).getDataset(i + 1)).getSeries(0) .setKey(seriesnames.get(i) + "(" + i + ")"); } } } if (values.size() > seriesnames.size()) { for (int i = seriesnames.size(); i < values.size(); i++) { defaultnames.set(i, "(" + i + ")"); } } } else { for (int i = values.size(); i < values.size(); i++) { defaultnames.set(i, "(" + i + ")"); } } } int nbseries = values.size(); // if ( type==SERIES_CHART ) nbseries++; // ChartData first=datas.get(0); if (type == HISTOGRAM_CHART) { ((DefaultCategoryDataset) dataset).clear(); } if (type == PIE_CHART) { ((DefaultPieDataset) dataset).clear(); } if (nbseries > datalist.previoussize) { for (int i = datalist.previoussize; i < nbseries; i++) { AbstractRenderer r; try { r = datalist.renderer.getClass().newInstance(); if (XYLineAndShapeRenderer.class.isAssignableFrom(r.getClass())) { ((XYLineAndShapeRenderer) r).setBaseShapesFilled( ((XYLineAndShapeRenderer) datalist.renderer).getBaseShapesFilled()); ((XYLineAndShapeRenderer) r).setBaseShapesVisible( ((XYLineAndShapeRenderer) datalist.renderer).getBaseShapesVisible()); ((XYLineAndShapeRenderer) r).setSeriesLinesVisible(0, ((XYLineAndShapeRenderer) datalist.renderer).getSeriesLinesVisible(0)); } ChartData newdata; newdata = ChartDataListStatement.newChartData(scope, r, Cast.asString(scope, defaultnames.get(i)), Cast.asColor(scope, defaultcolors.get(i)), values.get(i)); datas.add(newdata); datasfromlists.add(newdata); if (type == SERIES_CHART || type == XY_CHART || type == SCATTER_CHART) { final XYPlot plot = (XYPlot) chart.getPlot(); final String legend = newdata.getName(); // if (dataset==null) // dataset = new XYDataset(); if (type == SERIES_CHART || type == XY_CHART) { dataset = new DefaultTableXYDataset(); final XYSeries serie = new XYSeries(legend, false, false); ((DefaultTableXYDataset) dataset).addSeries(serie); } else { dataset = new XYSeriesCollection(); final XYSeries serie = new XYSeries(legend, false, true); ((XYSeriesCollection) dataset).addSeries(serie); } expressions_index.put(legend, datas.size() - 1); plot.setRenderer(datas.size() - 1, (XYItemRenderer) newdata.getRenderer(), false); final Color c = newdata.getColor(); plot.getRenderer(datas.size() - 1).setSeriesPaint(0, c); // if ((i>0)||(type==XY_CHART)) plot.setDataset(datas.size() - 1, (XYDataset) dataset); history.append(legend); history.append(','); } if (type == HISTOGRAM_CHART) { final CategoryPlot plot = (CategoryPlot) chart.getPlot(); int l = 0; for (final ChartData e : datas) { // String legend = e.getName(); // ((DefaultCategoryDataset) dataset).setValue(0d, new Integer(0), legend/* , legend // */); final String legend = e.getName(); if (!CategoryItemRenderer.class.isInstance(e.getRenderer())) { e.renderer = new BarRenderer(); } plot.setRenderer(l, (CategoryItemRenderer) e.getRenderer(), false); final Color c = e.getColor(); plot.getRenderer(l).setSeriesPaint(0, c); // plot.setDataset(i, (DefaultCategoryDataset) dataset); // } l++; history.append(legend); history.append(','); } if (history.length() > 0) { history.deleteCharAt(history.length() - 1); } history.append(Strings.LN); // plot.setDataset((DefaultCategoryDataset) dataset); } if (type == PIE_CHART) { int l = 0; // dataset = new DefaultPieDataset(); final PiePlot plot = (PiePlot) chart.getPlot(); for (final ChartData e : datas) { final String legend = e.getName(); ((DefaultPieDataset) dataset).insertValue(l++, legend, null); history.append(legend); history.append(','); } if (history.length() > 0) { history.deleteCharAt(history.length() - 1); } history.append(Strings.LN); history.append(Strings.LN); // plot.setDataset((DefaultPieDataset) dataset); l = 0; for (final ChartData e : datas) { plot.setSectionPaint(l++, e.getColor()); } plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})")); if (exploded) { for (final Object c : ((DefaultPieDataset) dataset).getKeys()) { plot.setExplodePercent((Comparable) c, 0.20); } } } } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } datalist.previoussize = nbseries; } boolean dynamiccategorynames = false; List<String> categorynames = new ArrayList<String>(); /* * if (datalist.categlistexp!=null) * { * Object valc=datalist.categlistexp.resolveAgainst(scope).value(scope); * if ((valc instanceof GamaList)) * { * dynamiccategorynames=true; * categorynames=(GamaList)valc; * } * * if (type==HISTOGRAM_CHART) * { * for ( int i=0; i<values.size(); i++ ) { * GamaList x = new GamaList(); * Object obj = values.get(i); * if ( obj instanceof GamaList ) { * x = (GamaList) obj; * // clearvalues=true; * if (dynamiccategorynames) * { * for (int j=0;j<x.length(scope);j++) * if (j<categorynames.size()) * { * ((DefaultCategoryDataset) dataset).setValue(Cast.asFloat(scope, * x.get(j)).doubleValue(),(String)defaultnames.get(i),categorynames.get(j).toString()+"("+j+")"); * } * else * ((DefaultCategoryDataset) dataset).setValue(Cast.asFloat(scope, * x.get(j)).doubleValue(),(String)defaultnames.get(i),"("+j+")"); * } * else * { * for (int j=0;j<x.length(scope);j++) * ((DefaultCategoryDataset) dataset).setValue(Cast.asFloat(scope, * x.get(j)).doubleValue(),(String)defaultnames.get(i), new Integer(j)); * * } * } else { * ((DefaultCategoryDataset) dataset).setValue(Cast.asFloat(scope, obj).doubleValue(), new * Integer(0),(String)defaultnames.get(i)); * } * } * } * } */ if (chart.getLegend() == null) { chart.addLegend(new LegendTitle(chart.getPlot())); } // LegendTitle legend = chart.getLegend(); // GuiUtils.debug("dyncateg:"+defaultnames); // GuiUtils.debug("legend:"+legend); for (int i = 0; i < nbseries; i++) { ChartData first = datas.get(i); if (type == SERIES_CHART) { first = datas.get(i + 1); } first.lastvalue = values.get(i); } } }