List of usage examples for java.awt Color DARK_GRAY
Color DARK_GRAY
To view the source code for java.awt Color DARK_GRAY.
Click Source Link
From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java
/** * Internal implementation to add a list of documents to a presentation; either as a single slide or a series of slides. * @param imageSource the image source to convert images to data. * @param ppt the presentation to add to. * @param sl the slide to add to (can be null if pagination is enabled). * @param anchor bounding rectangle to draw onto, in PowerPoint coordinates. * @param paginate whether to render results as multiple slides if they don't fit on one slide. * @param data the documents to render./*from w ww . j a v a2s .c o m*/ * @param results optional string to render into the top-left corner of the available space. * Will appear on each page if pagination is enabled. * @param sortBy optional string to render into the top-right corner of the available space. * Will appear on each page if pagination is enabled. */ private static void addList(final ImageSource imageSource, final XMLSlideShow ppt, XSLFSlide sl, final Rectangle2D.Double anchor, final boolean paginate, final ListData data, final String results, final String sortBy) { final double // How much space to leave at the left and right edge of the slide xMargin = 20, // How much space to leave at the top yMargin = 5, // Size of the icon iconWidth = 20, iconHeight = 24, // Find's thumbnail height is 97px by 55px, hardcoded in the CSS in .document-thumbnail thumbScale = 0.8, thumbW = 97 * thumbScale, thumbH = 55 * thumbScale, // Margin around the thumbnail thumbMargin = 4., // Space between list items listItemMargin = 5.; final Pattern highlightPattern = Pattern .compile("<HavenSearch-QueryText-Placeholder>(.*?)</HavenSearch-QueryText-Placeholder>"); double yCursor = yMargin + anchor.getMinY(), xCursor = xMargin + anchor.getMinX(); int docsOnPage = 0; final Document[] docs = data.getDocs(); for (int docIdx = 0; docIdx < docs.length; ++docIdx) { final Document doc = docs[docIdx]; if (sl == null) { sl = ppt.createSlide(); yCursor = yMargin + anchor.getMinY(); xCursor = xMargin + anchor.getMinX(); docsOnPage = 0; double yStep = 0; if (StringUtils.isNotBlank(results)) { final XSLFTextBox textBox = sl.createTextBox(); textBox.clearText(); final Rectangle2D.Double textBounds = new Rectangle2D.Double(xCursor, yCursor, Math.max(0, anchor.getMaxX() - xCursor - xMargin), 20); textBox.setAnchor(textBounds); addTextRun(textBox.addNewTextParagraph(), results, 12., Color.LIGHT_GRAY); yStep = textBox.getTextHeight(); } if (StringUtils.isNotBlank(sortBy)) { final XSLFTextBox sortByEl = sl.createTextBox(); sortByEl.clearText(); final XSLFTextParagraph sortByText = sortByEl.addNewTextParagraph(); sortByText.setTextAlign(TextParagraph.TextAlign.RIGHT); addTextRun(sortByText, sortBy, 12., Color.LIGHT_GRAY); sortByEl.setAnchor(new Rectangle2D.Double(xCursor, yCursor, Math.max(0, anchor.getMaxX() - xCursor - xMargin), 20)); yStep = Math.max(sortByEl.getTextHeight(), yStep); } if (yStep > 0) { yCursor += listItemMargin + yStep; } } XSLFAutoShape icon = null; if (data.isDrawIcons()) { icon = sl.createAutoShape(); icon.setShapeType(ShapeType.SNIP_1_RECT); icon.setAnchor(new Rectangle2D.Double(xCursor, yCursor + listItemMargin, iconWidth, iconHeight)); icon.setLineColor(Color.decode("#888888")); icon.setLineWidth(2.0); xCursor += iconWidth; } final XSLFTextBox listEl = sl.createTextBox(); listEl.clearText(); listEl.setAnchor(new Rectangle2D.Double(xCursor, yCursor, Math.max(0, anchor.getMaxX() - xCursor - xMargin), Math.max(0, anchor.getMaxY() - yCursor))); final XSLFTextParagraph titlePara = listEl.addNewTextParagraph(); addTextRun(titlePara, doc.getTitle(), data.getTitleFontSize(), Color.BLACK).setBold(true); if (StringUtils.isNotBlank(doc.getDate())) { final XSLFTextParagraph datePara = listEl.addNewTextParagraph(); datePara.setLeftMargin(5.); addTextRun(datePara, doc.getDate(), data.getDateFontSize(), Color.GRAY).setItalic(true); } if (StringUtils.isNotBlank(doc.getRef())) { addTextRun(listEl.addNewTextParagraph(), doc.getRef(), data.getRefFontSize(), Color.GRAY); } final double thumbnailOffset = listEl.getTextHeight(); final XSLFTextParagraph contentPara = listEl.addNewTextParagraph(); Rectangle2D.Double pictureAnchor = null; XSLFPictureData pictureData = null; if (StringUtils.isNotBlank(doc.getThumbnail())) { try { // Picture reuse is automatic pictureData = addPictureData(imageSource, ppt, doc.getThumbnail()); // We reserve space for the picture, but we don't actually add it yet. // The reason is we may have to remove it later if it doesn't fit; but due to a quirk of OpenOffice, // deleting the picture shape removes the pictureData as well; which is a problem since the // pictureData can be shared between multiple pictures. pictureAnchor = new Rectangle2D.Double(xCursor, yCursor + thumbnailOffset + thumbMargin, thumbW, thumbH); // If there is enough horizontal space, put the text summary to the right of the thumbnail image, // otherwise put it under the thumbnail, if (listEl.getAnchor().getWidth() > 2.5 * thumbW) { contentPara.setLeftMargin(thumbW); } else { contentPara.addLineBreak().setFontSize(thumbH); } } catch (RuntimeException e) { // if there's any errors, we'll just ignore the image } } final String rawSummary = doc.getSummary(); if (StringUtils.isNotBlank(rawSummary)) { // HTML treats newlines and multiple whitespace as a single whitespace. final String summary = rawSummary.replaceAll("\\s+", " "); final Matcher matcher = highlightPattern.matcher(summary); int idx = 0; while (matcher.find()) { final int start = matcher.start(); if (idx < start) { addTextRun(contentPara, summary.substring(idx, start), data.getSummaryFontSize(), Color.DARK_GRAY); } addTextRun(contentPara, matcher.group(1), data.getSummaryFontSize(), Color.DARK_GRAY) .setBold(true); idx = matcher.end(); } if (idx < summary.length()) { addTextRun(contentPara, summary.substring(idx), data.getSummaryFontSize(), Color.DARK_GRAY); } } double elHeight = Math.max(listEl.getTextHeight(), iconHeight); if (pictureAnchor != null) { elHeight = Math.max(elHeight, pictureAnchor.getMaxY() - yCursor); } yCursor += elHeight; xCursor = xMargin + anchor.getMinX(); docsOnPage++; if (yCursor > anchor.getMaxY()) { if (docsOnPage > 1) { // If we drew more than one list element on this page; and we exceeded the available space, // delete the last element's shapes and redraw it on the next page. // We don't have to remove the picture since we never added it. sl.removeShape(listEl); if (icon != null) { sl.removeShape(icon); } --docIdx; } else if (pictureAnchor != null) { // We've confirmed we need the picture, add it. sl.createPicture(pictureData).setAnchor(pictureAnchor); } sl = null; if (!paginate) { break; } } else { yCursor += listItemMargin; if (pictureAnchor != null) { // We've confirmed we need the picture, add it. sl.createPicture(pictureData).setAnchor(pictureAnchor); } } } }
From source file:CGgui.java
private void SaveGrayMinChrt() { //get chart and renderer XYPlot xyplot = (XYPlot) minchart.getPlot(); XYItemRenderer renderer0 = xyplot.getRenderer(0); XYItemRenderer renderer1 = xyplot.getRenderer(1); //set gray//from ww w. j a v a2 s . co m Paint defaultPaint0 = renderer0.getSeriesPaint(0); Paint defaultPaint1 = renderer1.getSeriesPaint(0); renderer0.setSeriesPaint(0, Color.LIGHT_GRAY); renderer1.setSeriesPaint(0, Color.DARK_GRAY); xyplot.setRenderer(0, renderer0); xyplot.setRenderer(1, renderer1); //save SaveMinChrt(); //restore color renderer0.setSeriesPaint(0, defaultPaint0); renderer1.setSeriesPaint(0, defaultPaint1); xyplot.setRenderer(0, renderer0); xyplot.setRenderer(1, renderer1); }
From source file:edu.ku.brc.ui.UIRegistry.java
/** * Writes a string message into the BufferedImage on GlassPane and sets the main component's visibility to false and * shows the GlassPane./* w w w . jav a2 s. c o m*/ * @param msg the message * @param pointSize the Font point size for the message to be writen in */ public static GhostGlassPane writeGlassPaneMsg(final String msg, final int pointSize) { GhostGlassPane glassPane = getGlassPane(); if (glassPane != null) { glassPane.finishDnD(); } glassPane.setMaskingEvents(true); Component mainComp = get(MAINPANE); if (mainComp != null && glassPane != null) { JFrame frame = (JFrame) get(FRAME); frameRect = frame.getBounds(); int y = 0; JMenuBar menuBar = null; Dimension size = mainComp.getSize(); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { menuBar = frame.getJMenuBar(); size.height += menuBar.getSize().height; y += menuBar.getSize().height; } BufferedImage buffer = getGlassPaneBufferedImage(size.width, size.height); Graphics2D g2 = buffer.createGraphics(); if (menuBar != null) { menuBar.paint(g2); } g2.translate(0, y); mainComp.paint(g2); g2.translate(0, -y); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(new Color(255, 255, 255, 128)); g2.fillRect(0, 0, size.width, size.height); g2.setFont(new Font((new JLabel()).getFont().getName(), Font.BOLD, pointSize)); FontMetrics fm = g2.getFontMetrics(); int tw = fm.stringWidth(msg); int th = fm.getHeight(); int tx = (size.width - tw) / 2; int ty = (size.height - th) / 2; int expand = 20; int arc = expand * 2; g2.setColor(Color.WHITE); g2.fillRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc, arc); g2.setColor(Color.DARK_GRAY); g2.drawRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc, arc); g2.setColor(Color.BLACK); g2.drawString(msg, tx, ty); g2.dispose(); glassPane.setImage(buffer); glassPane.setPoint(new Point(0, 0), GhostGlassPane.ImagePaintMode.ABSOLUTE); glassPane.setOffset(new Point(0, 0)); glassPane.setVisible(true); mainComp.setVisible(false); //Using paintImmediately fixes problems with glass pane not showing, such as for workbench saves initialed //during workbench or app shutdown. Don't know if there is a better way to fix it. //glassPane.repaint(); glassPane.paintImmediately(glassPane.getBounds()); showingGlassPane = true; } return glassPane; }
From source file:com.igormaznitsa.mindmap.swing.panel.MindMapPanel.java
private static void drawErrorText(final Graphics2D gfx, final Dimension fullSize, final String error) { final Font font = new Font(Font.DIALOG, Font.BOLD, 24); final FontMetrics metrics = gfx.getFontMetrics(font); final Rectangle2D textBounds = metrics.getStringBounds(error, gfx); gfx.setFont(font);/* w w w . ja v a 2 s . co m*/ gfx.setColor(Color.DARK_GRAY); gfx.fillRect(0, 0, fullSize.width, fullSize.height); final int x = (int) (fullSize.width - textBounds.getWidth()) / 2; final int y = (int) (fullSize.height - textBounds.getHeight()) / 2; gfx.setColor(Color.BLACK); gfx.drawString(error, x + 5, y + 5); gfx.setColor(Color.RED.brighter()); gfx.drawString(error, x, y); }
From source file:com.diversityarrays.kdxplore.curate.TrialDataEditor.java
private void updateRowFilter() { @SuppressWarnings("unchecked") TableRowSorter<CurationTableModel> rowSorter = (TableRowSorter<CurationTableModel>) curationTable .getRowSorter();/*from www . j av a2 s . co m*/ onlyRowsWithScores = onlyRowsWithScoresCheckbox.isSelected(); boolean onlyUneditedBefore = onlyUncurated; onlyUncurated = onlyUneditedCheckbox.isSelected(); @SuppressWarnings("unused") boolean hideInactiveBefore = hideInactive; hideInactive = hideInactivePlots.isSelected(); JLabel label = curationTablePanel.separator.getLabel(); String msg; if (isAnyFilterActive()) { rowSorter.setRowFilter(plotFilter); label.setForeground(Color.RED); msg = PHRASE_SHOWING + curationTable.getRowCount() + " of " + curationTableModel.getRowCount(); } else { rowSorter.setRowFilter(null); label.setForeground(Color.DARK_GRAY); msg = PHRASE_SHOWING_ALL + +curationTable.getRowCount(); } curationTable.setRowSorter(rowSorter); if (onlyUneditedBefore != onlyUncurated) { curationTableModel.setUsingOnlyUnedited(onlyUncurated); } // Allow filter to be applied before updating SwingUtilities.invokeLater(new Runnable() { @Override public void run() { label.setToolTipText(msg); label.setText(msg); } }); }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
private BufferedImage drawText(BufferedImage bi, String outputText, boolean verticalAlign) { Graphics2D g2d = bi.createGraphics(); g2d.setFont(new Font(textFont, Font.BOLD, textFontSize)); FontMetrics fm = g2d.getFontMetrics(); int textWidth = fm.stringWidth(outputText); int imageWidth = bi.getWidth(); int imageHeight = bi.getHeight(); int leftAlignment; int topAlignment; if (textAlignment.equalsIgnoreCase(LEFT)) { leftAlignment = textOffset;//from w w w . j a v a 2s.c o m } else if (textAlignment.equalsIgnoreCase(RIGHT)) { leftAlignment = imageWidth - textWidth - textOffset; } else { leftAlignment = (imageWidth / 2) - (textWidth / 2); } if (verticalAlign) { // Align the text to the top topAlignment = fm.getHeight() - 10; } else { // Align the text to the bottom topAlignment = imageHeight - 10; } // Create the drop shadow if (StringUtils.isNotBlank(textFontShadow)) { g2d.setColor(getColor(textFontShadow, Color.DARK_GRAY)); g2d.drawString(outputText, leftAlignment + 2, topAlignment + 2); } // Create the text itself g2d.setColor(getColor(textFontColor, Color.LIGHT_GRAY)); g2d.drawString(outputText, leftAlignment, topAlignment); g2d.dispose(); return bi; }
From source file:com.pianobakery.complsa.MainGui.java
private void createUIComponents() { this.indexTypeComboBox = new JComboBox(indexType); this.termComboBox = new JComboBox(termweights); //docSearchTitles = new String[]{"%Similarity","Path","Show"}; docSearchResModel = new DocSearchModel(); docSearchResTable = new JTable(docSearchResModel); docSearchResTable.setShowHorizontalLines(false); docSearchResTable.setShowVerticalLines(true); docSearchResTable.setFillsViewportHeight(true); docSearchResTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); docSearchResTable.setShowGrid(false); docSearchResTable.setGridColor(Color.DARK_GRAY); docSearchResTable.setAutoscrolls(true); docSearchResTable.getColumn("%Similarities:").setPreferredWidth(100); docSearchResTable.getColumn("%Similarities:").setWidth(25); docSearchResTable.getColumn("Filename:").setPreferredWidth(600); docSearchResTable.getColumn("Filename:").setWidth(100); docSearchResTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); DefaultTableCellRenderer leftRenderer = new DefaultTableCellRenderer(); leftRenderer.setHorizontalAlignment(JLabel.LEFT); docSearchResTable.getColumnModel().getColumn(0).setCellRenderer(leftRenderer); termSearchTitles = new String[] { "%Similarities:", "Terms:" }; termSearchResModel = new DefaultTableModel(termSearchTitles, 0) { @Override/*w w w .ja va2 s .c om*/ public boolean isCellEditable(int row, int column) { return false; } }; termSearchResTable = new JTable(termSearchResModel); termSearchResTable.setShowVerticalLines(true); termSearchResTable.setShowHorizontalLines(false); termSearchResTable.setFillsViewportHeight(true); termSearchResTable.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); termSearchResTable.setShowGrid(false); termSearchResTable.setGridColor(Color.DARK_GRAY); termSearchResTable.setAutoscrolls(true); termSearchResTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); termSearchResTable.getColumnModel().getColumn(0).setPreferredWidth(80); termSearchResTable.getColumnModel().getColumn(0).setWidth(80); termSearchResTable.getColumnModel().getColumn(0).setCellRenderer(leftRenderer); termSearchResTable.getColumnModel().getColumn(1).setPreferredWidth(120); termSearchResTable.getColumnModel().getColumn(1).setWidth(120); //docSearchResTable.getColumnModel().getColumn(0).setPreferredWidth(50); //docSearchResTable.getColumnModel().getColumn(1).sizeWidthToFit(); }
From source file:net.sf.fspdfs.chartthemes.spring.GenericChartTheme.java
/** * *///from w w w. ja v a 2 s . com protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); dialPlot.setDataset((ValueDataset) getDataset()); StandardDialFrame dialFrame = new StandardDialFrame(); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(jrPlot.getBackcolor()); dialPlot.setBackground(db); Range range = convertRange(jrPlot.getDataRange()); //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270, (range.getUpperBound() - range.getLowerBound()) / 6, 15); 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(jrPlot.getTickColor()); scale.setMinorTickPaint(jrPlot.getTickColor()); 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 > 0) colorStep = 255 / size; for (int i = 0; i < size; i++) { JRMeterInterval interval = (JRMeterInterval) intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0); StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(), intervalRange.getUpperBound(), interval.getBackgroundColor() == null ? color : interval.getBackgroundColor()); 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)) { DialValueIndicator dvi = new DialValueIndicator(0); 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); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor()); dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new DialPointer.Pointer(); 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, isShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }
From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java
/** * *//*from w w w .j ava 2 s. co m*/ protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); dialPlot.setDataset((ValueDataset) getDataset()); StandardDialFrame dialFrame = new StandardDialFrame(); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(jrPlot.getBackcolor()); dialPlot.setBackground(db); Range range = convertRange(jrPlot.getDataRange()); //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270, (range.getUpperBound() - range.getLowerBound()) / 6, 15); scale.setTickRadius(0.9); scale.setTickLabelOffset(0.16); JRBaseFont font = new JRBaseFont(); JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getTickLabelFont(), font); JRFontUtil.copyNonNullOwnProperties(jrPlot.getTickLabelFont(), font); font = new JRBaseFont(getChart(), font); scale.setTickLabelFont(JRFontUtil.getAwtFont(font, getLocale())); scale.setMajorTickStroke(new BasicStroke(1f)); scale.setMinorTickStroke(new BasicStroke(0.3f)); scale.setMajorTickPaint(jrPlot.getTickColor()); scale.setMinorTickPaint(jrPlot.getTickColor()); 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 > 0) colorStep = 255 / size; for (int i = 0; i < size; i++) { JRMeterInterval interval = (JRMeterInterval) intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0); StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(), intervalRange.getUpperBound(), interval.getBackgroundColor() == null ? color : interval.getBackgroundColor()); 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)) { DialValueIndicator dvi = new DialValueIndicator(0); 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 = new JRBaseFont(); JRFontUtil.copyNonNullOwnProperties(getPlotSettings().getDisplayFont(), displayFont); JRFontUtil.copyNonNullOwnProperties(jrPlot.getValueDisplay().getFont(), displayFont); displayFont = new JRBaseFont(getChart(), displayFont); Font themeDisplayFont = JRFontUtil.getAwtFont(displayFont, getLocale()); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor()); dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new DialPointer.Pointer(); 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, isShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }
From source file:net.sf.jasperreports.chartthemes.spring.GenericChartTheme.java
/** * *//* ww w .j a v a2 s . co m*/ protected JFreeChart createDialChart() throws JRException { JRMeterPlot jrPlot = (JRMeterPlot) getPlot(); // get data for diagrams DialPlot dialPlot = new DialPlot(); dialPlot.setDataset((ValueDataset) getDataset()); StandardDialFrame dialFrame = new StandardDialFrame(); dialPlot.setDialFrame(dialFrame); DialBackground db = new DialBackground(jrPlot.getBackcolor()); dialPlot.setBackground(db); Range range = convertRange(jrPlot.getDataRange()); //double bound = Math.max(Math.abs(range.getUpperBound()), Math.abs(range.getLowerBound())); int tickCount = jrPlot.getTickCount() != null && jrPlot.getTickCount() > 1 ? jrPlot.getTickCount() : 7; StandardDialScale scale = new StandardDialScale(range.getLowerBound(), range.getUpperBound(), 225, -270, (range.getUpperBound() - range.getLowerBound()) / (tickCount - 1), 15); 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(jrPlot.getTickColor()); scale.setMinorTickPaint(jrPlot.getTickColor()); scale.setTickLabelsVisible(true); scale.setFirstTickLabelVisible(true); // localizing the default tick label formatter scale.setTickLabelFormatter(new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(getLocale()))); 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 > 0) colorStep = 255 / size; for (int i = 0; i < size; i++) { JRMeterInterval interval = intervals.get(i); Range intervalRange = convertRange(interval.getDataRange()); Color color = new Color(255 - colorStep * i, 0 + colorStep * i, 0); StandardDialRange dialRange = new StandardDialRange(intervalRange.getLowerBound(), intervalRange.getUpperBound(), interval.getBackgroundColor() == null ? color : interval.getBackgroundColor()); 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)) { DialValueIndicator dvi = new DialValueIndicator(0); dvi.setBackgroundPaint(ChartThemesConstants.TRANSPARENT_PAINT); // dvi.setFont(getFontUtil().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); String[] textLines = label.split("\\n"); for (int i = 0; i < textLines.length; i++) { DialTextAnnotation dialAnnotation = new DialTextAnnotation(textLines[i]); dialAnnotation.setFont(themeDisplayFont); dialAnnotation.setPaint(jrPlot.getValueDisplay().getColor()); dialAnnotation.setRadius(Math.sin(Math.PI / 4.0) + i / 10.0); dialAnnotation.setAnchor(TextAnchor.CENTER); dialPlot.addLayer(dialAnnotation); } } DialPointer needle = new DialPointer.Pointer(); 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, isShowLegend()); // Set all the generic options configureChart(jfreeChart, getPlot()); return jfreeChart; }