Example usage for java.awt Font decode

List of usage examples for java.awt Font decode

Introduction

In this page you can find the example usage for java.awt Font decode.

Prototype

public static Font decode(String str) 

Source Link

Document

Returns the Font that the str argument describes.

Usage

From source file:net.semanticmetadata.lire.utils.FileUtils.java

public static void saveImageResultsToPng(String prefix, ImageSearchHits hits, String queryImage,
        IndexReader reader) throws IOException {
    LinkedList<BufferedImage> results = new LinkedList<BufferedImage>();
    int width = 0;
    for (int i = 0; i < hits.length(); i++) {
        // hits.score(i)
        // hits.doc(i).get("descriptorImageIdentifier")
        BufferedImage tmp = ImageIO.read(new FileInputStream(
                reader.document(hits.documentID(i)).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]));
        //            if (tmp.getHeight() > 200) {
        double factor = 200d / ((double) tmp.getHeight());
        tmp = ImageUtils.scaleImage(tmp, (int) (tmp.getWidth() * factor), 200);
        //            }
        width += tmp.getWidth() + 5;/*from  w w w. j a v a  2s  .c o m*/
        results.add(tmp);
    }
    BufferedImage result = new BufferedImage(width, 220, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) result.getGraphics();
    g2.setColor(Color.white);
    g2.setBackground(Color.white);
    g2.clearRect(0, 0, result.getWidth(), result.getHeight());
    g2.setColor(Color.black);
    g2.setFont(Font.decode("\"Arial\", Font.BOLD, 12"));
    int offset = 0;
    int count = 0;
    for (Iterator<BufferedImage> iterator = results.iterator(); iterator.hasNext();) {
        BufferedImage next = iterator.next();
        g2.drawImage(next, offset, 20, null);
        g2.drawString(hits.score(count) + "", offset + 5, 12);
        offset += next.getWidth() + 5;
        count++;
    }
    ImageIO.write(result, "PNG", new File(prefix + "_" + (System.currentTimeMillis() / 1000) + ".png"));
}

From source file:net.semanticmetadata.lire.utils.FileUtils.java

public static void saveImageResultsToPng(String prefix, TopDocs hits, String queryImage, IndexReader ir)
        throws IOException {
    LinkedList<BufferedImage> results = new LinkedList<BufferedImage>();
    int width = 0;
    for (int i = 0; i < Math.min(hits.scoreDocs.length, 10); i++) {
        // hits.score(i)
        // hits.doc(i).get("descriptorImageIdentifier")
        BufferedImage tmp = ImageIO
                .read(new FileInputStream(ir.document(hits.scoreDocs[i].doc).get("descriptorImageIdentifier")));
        if (tmp.getHeight() > 200) {
            double factor = 200d / ((double) tmp.getHeight());
            tmp = ImageUtils.scaleImage(tmp, (int) (tmp.getWidth() * factor), 200);
        }//from   ww w  . j  av  a 2 s.  c o m
        width += tmp.getWidth() + 5;
        results.add(tmp);
    }
    BufferedImage result = new BufferedImage(width, 220, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) result.getGraphics();
    g2.setColor(Color.black);
    g2.clearRect(0, 0, result.getWidth(), result.getHeight());
    g2.setColor(Color.green);
    g2.setFont(Font.decode("\"Arial\", Font.BOLD, 12"));
    int offset = 0;
    int count = 0;
    for (Iterator<BufferedImage> iterator = results.iterator(); iterator.hasNext();) {
        BufferedImage next = iterator.next();
        g2.drawImage(next, offset, 20, null);
        g2.drawString(hits.scoreDocs[count].score + "", offset + 5, 12);
        offset += next.getWidth() + 5;
        count++;
    }
    ImageIO.write(result, "PNG", new File(prefix + "_" + (System.currentTimeMillis() / 1000) + ".png"));
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYAreaLineChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final XYPlot plot = chart.getXYPlot();

    if (isSharedRangeAxis() == false) {
        final ValueAxis linesAxis = plot.getRangeAxis(1);
        if (linesAxis instanceof NumberAxis) {
            final NumberAxis numberAxis = (NumberAxis) linesAxis;
            numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero());
            numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero());

            if (getLinePeriodCount() > 0) {
                if (getLineTicksLabelFormat() != null) {
                    final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(),
                            getResourceBundleFactory().getLocale());
                    numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter));
                } else {
                    numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount()));
                }//  w  w w  .j a  va  2 s .c  o m
            } else {
                if (getLineTicksLabelFormat() != null) {
                    final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(),
                            new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                    numberAxis.setNumberFormatOverride(formatter);
                }
            }
        } else if (linesAxis instanceof DateAxis) {
            final DateAxis numberAxis = (DateAxis) linesAxis;

            if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) {
                if (getLineTicksLabelFormat() != null) {
                    final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(),
                            new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                    numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()),
                            (int) getLinePeriodCount(), formatter));
                } else {
                    numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()),
                            (int) getLinePeriodCount()));
                }
            } else if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setDateFormatOverride(formatter);
            }
        }

        if (linesAxis != null) {
            final Font labelFont = Font.decode(getLabelFont());
            linesAxis.setLabelFont(labelFont);
            linesAxis.setTickLabelFont(labelFont);

            if (getLineTitleFont() != null) {
                linesAxis.setLabelFont(getLineTitleFont());
            }
            if (getLineTickFont() != null) {
                linesAxis.setTickLabelFont(getLineTickFont());
            }
            final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
            if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
                final double lineRangeMinimumVal = lineRangeMinimum == null ? 0 : lineRangeMinimum;
                final double lineRangeMaximumVal = lineRangeMaximum == null ? 0 : lineRangeMaximum;
                if (lineRangeMinimum != null) {
                    linesAxis.setLowerBound(getLineRangeMinimum());
                }
                if (lineRangeMaximum != null) {
                    linesAxis.setUpperBound(getRangeMaximum());
                }
                if (lineRangeMinimumVal == 0 && lineRangeMaximumVal == 1) {
                    linesAxis.setLowerBound(0);
                    linesAxis.setUpperBound(1);
                    linesAxis.setAutoRange(true);
                }
            } else {
                if (lineRangeMinimum != null) {
                    linesAxis.setLowerBound(lineRangeMinimum);
                }
                if (lineRangeMaximum != null) {
                    linesAxis.setUpperBound(lineRangeMaximum);
                }
                linesAxis.setAutoRange(isLineAxisAutoRange());
            }
        }
    }

    final XYLineAndShapeRenderer linesRenderer = (XYLineAndShapeRenderer) plot.getRenderer(1);
    if (linesRenderer != null) {
        //set stroke with line width
        linesRenderer.setStroke(translateLineStyle(getLineWidth(), getLineStyle()));
        //hide shapes on line
        linesRenderer.setShapesVisible(isMarkersVisible());
        linesRenderer.setBaseShapesFilled(isMarkersVisible());

        //set colors for each line
        for (int i = 0; i < lineSeriesColor.size(); i++) {
            final String s = (String) lineSeriesColor.get(i);
            linesRenderer.setSeriesPaint(i, parseColorFromString(s));
        }
    }
}

From source file:org.fhcrc.cpl.viewer.quant.gui.ProteinQuantSummaryFrame.java

License:asdf

/**
 * Initialize the GUI components//w w w .ja v  a2 s  . c o  m
 */
protected void initGUI() {
    //Global stuff
    setSize(fullWidth, fullHeight);

    eventPropertiesTable = new QuantEvent.QuantEventPropertiesTable();
    eventPropertiesTable.setVisible(true);
    JScrollPane eventPropsScrollPane = new JScrollPane();
    eventPropsScrollPane.setViewportView(eventPropertiesTable);
    eventPropsScrollPane.setSize(propertiesWidth, propertiesHeight);
    eventPropertiesDialog = new JDialog(this, "Event Properties");
    eventPropertiesDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    eventPropertiesDialog.setSize(propertiesWidth, propertiesHeight);
    eventPropertiesDialog.setContentPane(eventPropsScrollPane);

    ListenerHelper helper = new ListenerHelper(this);
    setTitle("Protein Summary");
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 1;
    gbc.weightx = 1;

    try {
        (getOwner()).setIconImage(ImageIO.read(WorkbenchFrame.class.getResourceAsStream("icon.gif")));
    } catch (Exception e) {
    }

    try {
        Localizer.renderSwixml("org/fhcrc/cpl/viewer/quant/gui/ProteinQuantSummaryFrame.xml", this);
        assert null != contentPanel;
        setContentPane(contentPanel);
    } catch (Exception x) {
        ApplicationContext.errorMessage("error creating dialog", x);
        throw new RuntimeException(x);
    }

    buttonSelectAllVisible.setEnabled(false);
    helper.addListener(buttonSelectAllVisible, "buttonSelectAllVisible_actionPerformed");
    buttonDeselectAll.setEnabled(false);
    helper.addListener(buttonDeselectAll, "buttonDeselectAll_actionPerformed");

    buildTurkHITsButton.setEnabled(false);
    helper.addListener(buildTurkHITsButton, "buttonBuildTurkHITs_actionPerformed");
    loadSelectedEventsButton.setEnabled(false);
    helper.addListener(loadSelectedEventsButton, "buttonLoadSelected_actionPerformed");
    autoAssessSelectedEventsButton.setEnabled(false);
    helper.addListener(autoAssessSelectedEventsButton, "buttonAutoAssess_actionPerformed");

    showPropertiesButton.setEnabled(false);
    helper.addListener(showPropertiesButton, "buttonShowProperties_actionPerformed");
    showProteinRatiosButton.setEnabled(false);
    helper.addListener(showProteinRatiosButton, "buttonShowProteinRatios_actionPerformed");

    //summary panel
    summaryPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
    summaryPanel.setPreferredSize(new Dimension(fullWidth, summaryPanelHeight));
    summaryPanel.setMinimumSize(new Dimension(200, summaryPanelHeight));
    gbc.fill = GridBagConstraints.NONE;

    gbc.gridwidth = 1;
    summaryPanel.add(buttonSelectAllVisible, gbc);
    summaryPanel.add(buttonDeselectAll, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    summaryPanel.add(showPropertiesButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    summaryPanel.add(showProteinRatiosButton, gbc);

    gbc.gridwidth = 1;

    summaryPanel.add(loadSelectedEventsButton, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    summaryPanel.add(autoAssessSelectedEventsButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    summaryPanel.add(buildTurkHITsButton, gbc);

    gbc.fill = GridBagConstraints.BOTH;

    eventsScrollPane = new JScrollPane();
    eventsScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    eventsScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

    eventsPanel = new JPanel();
    eventsPanel.setLayout(new GridBagLayout());

    eventsTable = new QuantEventsSummaryTable();
    eventsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    eventsTable.getSelectionModel().addListSelectionListener(new EventsTableListSelectionHandler());
    eventsScrollPane.setViewportView(eventsTable);
    eventsScrollPane.setMinimumSize(new Dimension(400, 400));

    gbc.insets = new Insets(0, 0, 0, 0);
    mainPanel.add(eventsScrollPane, gbc);

    logRatioHistogramPanel = new PanelWithLogRatioHistAndFields();
    logRatioHistogramPanel.setBorder(BorderFactory.createTitledBorder("Log Ratios"));
    logRatioHistogramPanel.setPreferredSize(new Dimension(width - 10, 300));
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 100;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    add(logRatioHistogramPanel, gbc);

    //status message
    messageLabel = new JLabel();
    messageLabel.setBackground(Color.WHITE);
    messageLabel.setFont(Font.decode("verdana plain 12"));
    messageLabel.setText(" ");
    statusPanel = new JPanel();
    gbc.weighty = 1;
    statusPanel.setPreferredSize(new Dimension(width - 10, 50));
    statusPanel.add(messageLabel, gbc);
    add(statusPanel, gbc);

    //per-protein event summary table; disembodied
    //todo: move this into its own class? it's getting kind of complicated
    proteinRatiosTable = new JTable();
    proteinRatiosTable.setVisible(true);
    ListSelectionModel proteinTableSelectionModel = proteinRatiosTable.getSelectionModel();
    proteinTableSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    proteinTableSelectionModel.addListSelectionListener(new ProteinTableListSelectionHandler());
    JScrollPane proteinRatiosScrollPane = new JScrollPane();
    proteinRatiosScrollPane.setViewportView(proteinRatiosTable);
    proteinRatiosScrollPane.setPreferredSize(new Dimension(proteinDialogWidth,
            proteinDialogHeight - PROTEINTABLE_HISTPANEL_HEIGHT - PROTEINTABLE_SCATTERPLOTPANEL_HEIGHT - 70));
    proteinRatiosDialog = new JDialog(this, "Protein Ratios");
    proteinRatiosDialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    proteinRatiosDialog.setSize(proteinDialogWidth, proteinDialogHeight);
    JPanel proteinRatiosContentPanel = new JPanel();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.fill = GridBagConstraints.BOTH;
    proteinRatiosContentPanel.add(proteinRatiosScrollPane, gbc);
    proteinRatiosDialog.setContentPane(proteinRatiosContentPanel);
    perProteinLogRatioHistogramPanel = new PanelWithLogRatioHistAndFields();
    perProteinLogRatioHistogramPanel.addRangeUpdateListener(new ProteinTableLogRatioHistogramListener());

    perProteinLogRatioHistogramPanel.setBorder(BorderFactory.createTitledBorder("Log Ratios"));
    perProteinLogRatioHistogramPanel
            .setPreferredSize(new Dimension(proteinDialogWidth - 10, PROTEINTABLE_HISTPANEL_HEIGHT));
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    proteinRatiosDialog.add(perProteinLogRatioHistogramPanel, gbc);

    perProteinPeptideLogRatioPanel = new JPanel();
    perProteinPeptideLogRatioPanel.setBorder(BorderFactory.createTitledBorder("By Peptide"));
    perProteinPeptideLogRatioPanel
            .setPreferredSize(new Dimension(proteinDialogWidth - 10, PROTEINTABLE_SCATTERPLOTPANEL_HEIGHT));
    proteinRatiosDialog.add(perProteinPeptideLogRatioPanel, gbc);
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.BarLineChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final CategoryPlot plot = chart.getCategoryPlot();

    if (isSharedRangeAxis() == false) {
        final ValueAxis linesAxis = plot.getRangeAxis(1);
        if (linesAxis instanceof NumberAxis) {
            final NumberAxis numberAxis = (NumberAxis) linesAxis;
            numberAxis.setAutoRangeIncludesZero(isLineAxisIncludesZero());
            numberAxis.setAutoRangeStickyZero(isLineAxisStickyZero());

            if (getLinePeriodCount() > 0) {
                if (getLineTicksLabelFormat() != null) {
                    final FastDecimalFormat formatter = new FastDecimalFormat(getLineTicksLabelFormat(),
                            getResourceBundleFactory().getLocale());
                    numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount(), formatter));
                } else {
                    numberAxis.setTickUnit(new FastNumberTickUnit(getLinePeriodCount()));
                }/*from  ww  w .j av  a 2  s .c o m*/
            } else {
                if (getLineTicksLabelFormat() != null) {
                    final DecimalFormat formatter = new DecimalFormat(getLineTicksLabelFormat(),
                            new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                    numberAxis.setNumberFormatOverride(formatter);
                }
            }
        } else if (linesAxis instanceof DateAxis) {
            final DateAxis numberAxis = (DateAxis) linesAxis;

            if (getLinePeriodCount() > 0 && getLineTimePeriod() != null) {
                if (getLineTicksLabelFormat() != null) {
                    final SimpleDateFormat formatter = new SimpleDateFormat(getLineTicksLabelFormat(),
                            new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                    numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()),
                            (int) getLinePeriodCount(), formatter));
                } else {
                    numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getLineTimePeriod()),
                            (int) getLinePeriodCount()));
                }
            } else if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setDateFormatOverride(formatter);
            }
        }

        if (linesAxis != null) {
            final Font labelFont = Font.decode(getLabelFont());
            linesAxis.setLabelFont(labelFont);
            linesAxis.setTickLabelFont(labelFont);

            if (getLineTitleFont() != null) {
                linesAxis.setLabelFont(getLineTitleFont());
            }
            if (getLineTickFont() != null) {
                linesAxis.setTickLabelFont(getLineTickFont());
            }
            final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
            if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
                if (getRangeMinimum() != 0) {
                    linesAxis.setLowerBound(getLineRangeMinimum());
                }
                if (getRangeMaximum() != 1) {
                    linesAxis.setUpperBound(getLineRangeMaximum());
                }
                if (getLineRangeMinimum() == 0 && getLineRangeMaximum() == 1) {
                    linesAxis.setLowerBound(0);
                    linesAxis.setUpperBound(1);
                    linesAxis.setAutoRange(true);
                }
            } else {
                linesAxis.setLowerBound(getLineRangeMinimum());
                linesAxis.setUpperBound(getLineRangeMaximum());
                linesAxis.setAutoRange(isLineAxisAutoRange());
            }
        }
    }

    final LineAndShapeRenderer linesRenderer = (LineAndShapeRenderer) plot.getRenderer(1);
    if (linesRenderer != null) {
        //set stroke with line width
        linesRenderer.setStroke(translateLineStyle(lineWidth, lineStyle));
        //hide shapes on line
        linesRenderer.setShapesVisible(isMarkersVisible());
        linesRenderer.setBaseShapesFilled(isMarkersVisible());

        //set colors for each line
        for (int i = 0; i < lineSeriesColor.size(); i++) {
            final String s = (String) lineSeriesColor.get(i);
            linesRenderer.setSeriesPaint(i, parseColorFromString(s));
        }
    }
}

From source file:com.google.gwt.benchmarks.viewer.server.ReportImageServer.java

private void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {

    String uri = request.getRequestURI();
    String requestString = uri.split("test_images/")[1];
    String[] requestParams = requestString.split("/");

    String reportName = URLDecoder.decode(requestParams[0], charset);
    String categoryName = URLDecoder.decode(requestParams[1], charset);
    // String className = URLDecoder.decode(requestParams[2], charset);
    String testName = URLDecoder.decode(requestParams[3], charset);
    String agent = URLDecoder.decode(requestParams[4], charset);

    ReportDatabase db = ReportDatabase.getInstance();
    Report report = db.getReport(reportName);
    List<Category> categories = report.getCategories();
    Category category = getCategoryByName(categories, categoryName);
    List<Benchmark> benchmarks = category.getBenchmarks();
    Benchmark benchmark = getBenchmarkByName(benchmarks, testName);
    List<Result> results = benchmark.getResults();
    Result result = getResultsByAgent(results, agent);

    String title = BrowserInfo.getBrowser(agent);
    JFreeChart chart = createChart(testName, result, title, results);

    chart.getTitle().setFont(Font.decode("Verdana BOLD 12"));
    chart.setAntiAlias(true);//  w  w  w .j  a va2s  . c om
    chart.setBorderVisible(true);
    chart.setBackgroundPaint(new Color(241, 241, 241));

    Plot plot = chart.getPlot();

    plot.setDrawingSupplier(getDrawingSupplier());
    plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 640, 480, new Color(200, 200, 200)));

    if (plot instanceof XYPlot) {
        XYPlot xyplot = (XYPlot) plot;
        Font labelFont = Font.decode("Verdana PLAIN");
        xyplot.getDomainAxis().setLabelFont(labelFont);
        xyplot.getRangeAxis().setLabelFont(labelFont);
        org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
        xyitemrenderer.setStroke(new BasicStroke(4));
        if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
            XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyitemrenderer;
            xylineandshaperenderer.setShapesVisible(true);
            xylineandshaperenderer.setShapesFilled(true);
        }
    }

    // Try to fit all the graphs into a 1024 window, with a min of 240 and a max
    // of 480
    final int graphWidth = Math.max(240, Math.min(480, (1024 - 10 * results.size()) / results.size()));
    BufferedImage img = chart.createBufferedImage(graphWidth, 240);
    byte[] image = EncoderUtil.encode(img, ImageFormat.PNG);

    // The images have unique URLs; might as well set them to never expire.
    response.setHeader("Cache-Control", "max-age=0");
    response.setHeader("Expires", "Fri, 2 Jan 1970 00:00:00 GMT");
    response.setContentType("image/png");
    response.setContentLength(image.length);

    OutputStream output = response.getOutputStream();
    output.write(image);
}

From source file:de.codesourcery.planning.swing.PlanningCanvas.java

/**
 * Subclassing hook, CALLED FROM CONSTRUCTOR !!
 * @return//from w ww  .ja  va  2 s.  co m
 */
protected MyRenderOptions createRenderOptions() {

    //      final String[] fontnames =
    //         GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    //      for (int i = 0; i < fontnames.length; i++) {
    //         System.out.println("Got font: "+fontnames[i] );
    //      }

    final Font font = Font.decode("Serif-BOLD-12");
    Font labelFont;
    if (font != null) {
        labelFont = font;
    } else {
        System.out.println("Unable to use custom font Serif-BOLD-12 , font not found");
        labelFont = getFont().deriveFont(Font.BOLD, 14);
    }
    return new MyRenderOptions(labelFont);
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final CategoryPlot cpl = chart.getCategoryPlot();
    final CategoryItemRenderer renderer = cpl.getRenderer();
    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        renderer.setBaseToolTipGenerator(
                new FormulaCategoryTooltipGenerator(getRuntime(), getTooltipFormula()));
    }/*from  www . j  a v a 2s.  com*/
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        renderer.setBaseItemURLGenerator(new FormulaCategoryURLGenerator(getRuntime(), getUrlFormula()));
    }
    if (this.categoricalLabelFormat != null) {
        final StandardCategoryItemLabelGenerator scilg;
        if (categoricalLabelDecimalFormat != null) {
            final DecimalFormat numFormat = new DecimalFormat(categoricalLabelDecimalFormat,
                    new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale()));
            numFormat.setRoundingMode(RoundingMode.HALF_UP);
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, numFormat);
        } else if (categoricalLabelDateFormat != null) {
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, new SimpleDateFormat(
                    categoricalLabelDateFormat, getRuntime().getResourceBundleFactory().getLocale()));
        } else {
            final DecimalFormat formatter = new DecimalFormat();
            formatter.setDecimalFormatSymbols(
                    new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale()));
            scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, formatter);
        }
        renderer.setBaseItemLabelGenerator(scilg);
    }
    renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible()));
    if (getItemLabelFont() != null) {
        renderer.setBaseItemLabelFont(getItemLabelFont());
    }

    if (categoricalItemLabelRotation != null) {
        final ItemLabelPosition orgPosItemLabelPos = renderer.getBasePositiveItemLabelPosition();
        if (orgPosItemLabelPos == null) {
            final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
            renderer.setBasePositiveItemLabelPosition(pos2);
        } else {
            final ItemLabelPosition pos2 = new ItemLabelPosition(orgPosItemLabelPos.getItemLabelAnchor(),
                    orgPosItemLabelPos.getTextAnchor(), orgPosItemLabelPos.getRotationAnchor(),
                    categoricalItemLabelRotation.doubleValue());
            renderer.setBasePositiveItemLabelPosition(pos2);
        }

        final ItemLabelPosition orgNegItemLabelPos = renderer.getBaseNegativeItemLabelPosition();
        if (orgNegItemLabelPos == null) {
            final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12,
                    TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue());
            renderer.setBaseNegativeItemLabelPosition(pos2);
        } else {
            final ItemLabelPosition neg2 = new ItemLabelPosition(orgNegItemLabelPos.getItemLabelAnchor(),
                    orgNegItemLabelPos.getTextAnchor(), orgNegItemLabelPos.getRotationAnchor(),
                    categoricalItemLabelRotation.doubleValue());
            renderer.setBaseNegativeItemLabelPosition(neg2);
        }
    }

    final Font labelFont = Font.decode(getLabelFont());

    final CategoryAxis categoryAxis = cpl.getDomainAxis();
    categoryAxis.setLabelFont(labelFont);
    categoryAxis.setTickLabelFont(labelFont);
    if (getCategoryTitleFont() != null) {
        categoryAxis.setLabelFont(getCategoryTitleFont());
    }
    if (getCategoryTickFont() != null) {
        categoryAxis.setTickLabelFont(getCategoryTickFont());
    }

    if (maxCategoryLabelWidthRatio != null) {
        categoryAxis.setMaximumCategoryLabelWidthRatio(maxCategoryLabelWidthRatio.floatValue());
    }
    cpl.setDomainGridlinesVisible(showGridlines);
    if (labelRotation != null) {
        double angle = labelRotation.doubleValue();
        CategoryLabelPosition top = createUpRotationCategoryLabelPosition(PlaneDirection.TOP, angle);
        CategoryLabelPosition bottom = createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, angle);
        CategoryLabelPosition left = createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, angle);
        CategoryLabelPosition right = createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT, angle);
        CategoryLabelPositions rotationLabelPositions = new CategoryLabelPositions(top, bottom, left, right);
        categoryAxis.setCategoryLabelPositions(rotationLabelPositions);
    }

    final String[] colors = getSeriesColor();
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, parseColorFromString(colors[i]));
    }

    if (lowerMargin != null) {
        categoryAxis.setLowerMargin(lowerMargin.doubleValue());
    }
    if (upperMargin != null) {
        categoryAxis.setUpperMargin(upperMargin.doubleValue());
    }
    if (categoryMargin != null) {
        categoryAxis.setCategoryMargin(categoryMargin.doubleValue());
    }

    configureRangeAxis(cpl, labelFont);
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.AbstractChartExpression.java

protected void configureChart(final JFreeChart chart) {
    // Misc Properties
    final TextTitle chartTitle = chart.getTitle();
    if (chartTitle != null) {
        final Font titleFont = Font.decode(getTitleFont());
        chartTitle.setFont(titleFont);// w w w  .  ja  v  a  2 s .c  o  m
    }

    if (isAntiAlias() == false) {
        chart.setAntiAlias(false);
    }

    chart.setBorderVisible(isShowBorder());

    final Color backgroundColor = parseColorFromString(getBackgroundColor());
    if (backgroundColor != null) {
        chart.setBackgroundPaint(backgroundColor);
    }

    if (plotBackgroundColor != null) {
        chart.getPlot().setBackgroundPaint(plotBackgroundColor);
    }
    chart.getPlot().setBackgroundAlpha(plotBackgroundAlpha);
    chart.getPlot().setForegroundAlpha(plotForegroundAlpha);
    final Color borderCol = parseColorFromString(getBorderColor());
    if (borderCol != null) {
        chart.setBorderPaint(borderCol);
    }

    //remove legend if showLegend = false
    if (!isShowLegend()) {
        chart.removeLegend();
    } else { //if true format legend
        final LegendTitle chLegend = chart.getLegend();
        if (chLegend != null) {
            final RectangleEdge loc = translateEdge(legendLocation.toLowerCase());
            if (loc != null) {
                chLegend.setPosition(loc);
            }
            if (getLegendFont() != null) {
                chLegend.setItemFont(Font.decode(getLegendFont()));
            }
            if (!isDrawLegendBorder()) {
                chLegend.setBorder(BlockBorder.NONE);
            }
            if (legendBackgroundColor != null) {
                chLegend.setBackgroundPaint(legendBackgroundColor);
            }
            if (legendTextColor != null) {
                chLegend.setItemPaint(legendTextColor);
            }
        }

    }

    final Plot plot = chart.getPlot();
    plot.setNoDataMessageFont(Font.decode(getLabelFont()));

    final String message = getNoDataMessage();
    if (message != null) {
        plot.setNoDataMessage(message);
    }

    plot.setOutlineVisible(isChartSectionOutline());

    if (backgroundImage != null) {
        if (plotImageCache != null) {
            plot.setBackgroundImage(plotImageCache);
        } else {
            final ExpressionRuntime expressionRuntime = getRuntime();
            final ProcessingContext context = expressionRuntime.getProcessingContext();
            final ResourceKey contentBase = context.getContentBase();
            final ResourceManager manager = context.getResourceManager();
            try {
                final ResourceKey key = createKeyFromString(manager, contentBase, backgroundImage);
                final Resource resource = manager.create(key, null, Image.class);
                final Image image = (Image) resource.getResource();
                plot.setBackgroundImage(image);
                plotImageCache = image;
            } catch (Exception e) {
                logger.error("ABSTRACTCHARTEXPRESSION.ERROR_0007_ERROR_RETRIEVING_PLOT_IMAGE", e); //$NON-NLS-1$
                throw new IllegalStateException("Failed to process chart");
            }
        }
    }
}

From source file:org.fhcrc.cpl.viewer.quant.gui.QuantitationReviewer.java

/**
 * Initialize all GUI components and display the UI
 */// w  w w. j  ava2 s  . c  o  m
protected void initGUI() {
    settingsCLM = new ProteinQuantChartsCLM(false);

    setTitle("Qurate");
    try {
        setIconImage(ImageIO.read(WorkbenchFrame.class.getResourceAsStream("icon.gif")));
    } catch (Exception e) {
    }

    try {
        Localizer.renderSwixml("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewer.xml", this);
        assert null != contentPanel;
    } catch (Exception x) {
        ApplicationContext.errorMessage("error creating dialog", x);
        throw new RuntimeException(x);
    }

    //Menu
    openFileAction = new OpenFileAction(this);
    createChartsAction = new CreateChartsAction();
    filterPepXMLAction = new FilterPepXMLAction(this);
    proteinSummaryAction = new ProteinSummaryAction(this);

    try {
        JMenuBar jmenu = (JMenuBar) Localizer.getSwingEngine(this)
                .render("org/fhcrc/cpl/viewer/quant/gui/QuantitationReviewerMenu.xml");
        for (int i = 0; i < jmenu.getMenuCount(); i++)
            jmenu.getMenu(i).getPopupMenu().setLightWeightPopupEnabled(false);
        this.setJMenuBar(jmenu);
    } catch (Exception x) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_LOADING_MENUS"), x);
        throw new RuntimeException(x);
    }

    //Global stuff
    setSize(fullWidth, fullHeight);
    setContentPane(contentPanel);
    ListenerHelper helper = new ListenerHelper(this);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.insets = new Insets(5, 5, 5, 5);
    gbc.weighty = 1;
    gbc.weightx = 1;

    leftPanel.setLayout(new GridBagLayout());
    leftPanel.setBorder(BorderFactory.createLineBorder(Color.gray));

    //Properties panel stuff
    propertiesTable = new QuantEvent.QuantEventPropertiesTable();
    propertiesScrollPane = new JScrollPane();
    propertiesScrollPane.setViewportView(propertiesTable);
    propertiesScrollPane.setMinimumSize(new Dimension(propertiesWidth, propertiesHeight));

    //event summary table; disembodied
    eventSummaryTable = new QuantEventsSummaryTable();
    eventSummaryTable.setVisible(true);
    ListSelectionModel tableSelectionModel = eventSummaryTable.getSelectionModel();
    tableSelectionModel.addListSelectionListener(new EventSummaryTableListSelectionHandler());
    JScrollPane eventSummaryScrollPane = new JScrollPane();
    eventSummaryScrollPane.setViewportView(eventSummaryTable);
    eventSummaryScrollPane.setSize(propertiesWidth, propertiesHeight);
    eventSummaryFrame = new Frame("All Events");
    eventSummaryFrame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent event) {
            eventSummaryFrame.setVisible(false);
        }
    });
    eventSummaryFrame.setSize(950, 450);
    eventSummaryFrame.add(eventSummaryScrollPane);

    //fields related to navigation
    navigationPanel = new JPanel();
    backButton = new JButton("<");
    backButton.setToolTipText("Previous Event");
    backButton.setMaximumSize(new Dimension(50, 30));
    backButton.setEnabled(false);
    forwardButton = new JButton(">");
    forwardButton.setToolTipText("Next Event");
    forwardButton.setMaximumSize(new Dimension(50, 30));
    forwardButton.setEnabled(false);
    showEventSummaryButton = new JButton("Show All");
    showEventSummaryButton.setToolTipText("Show all events in a table");
    showEventSummaryButton.setEnabled(false);

    helper.addListener(backButton, "buttonBack_actionPerformed");
    helper.addListener(forwardButton, "buttonForward_actionPerformed");
    helper.addListener(showEventSummaryButton, "buttonShowEventSummary_actionPerformed");

    gbc.fill = GridBagConstraints.NONE;
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    gbc.anchor = GridBagConstraints.WEST;
    navigationPanel.add(backButton, gbc);
    gbc.gridwidth = GridBagConstraints.RELATIVE;
    navigationPanel.add(forwardButton, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    navigationPanel.add(showEventSummaryButton, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    navigationPanel.setBorder(BorderFactory.createTitledBorder("Event"));
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Fields related to curation of events
    curationPanel = new JPanel();
    curationPanel.setLayout(new GridBagLayout());
    curationPanel.setBorder(BorderFactory.createTitledBorder("Curation"));
    //Quantitation curation
    JPanel quantCurationPanel = new JPanel();
    quantCurationPanel.setLayout(new GridBagLayout());
    quantCurationPanel.setBorder(BorderFactory.createTitledBorder("Quantitation"));
    quantCurationButtonGroup = new ButtonGroup();
    JRadioButton unknownRadioButton = new JRadioButton("?");
    JRadioButton goodRadioButton = new JRadioButton("Good");
    JRadioButton badRadioButton = new JRadioButton("Bad");
    onePeakRatioRadioButton = new JRadioButton("1-Peak");

    unknownRadioButton.setEnabled(false);
    goodRadioButton.setEnabled(false);
    badRadioButton.setEnabled(false);
    onePeakRatioRadioButton.setEnabled(false);

    quantCurationButtonGroup.add(unknownRadioButton);
    quantCurationButtonGroup.add(goodRadioButton);
    quantCurationButtonGroup.add(badRadioButton);
    quantCurationButtonGroup.add(onePeakRatioRadioButton);

    unknownRadioButtonModel = unknownRadioButton.getModel();
    goodRadioButtonModel = goodRadioButton.getModel();
    badRadioButtonModel = badRadioButton.getModel();
    onePeakRadioButtonModel = onePeakRatioRadioButton.getModel();

    helper.addListener(unknownRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(goodRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(badRadioButton, "buttonCuration_actionPerformed");
    helper.addListener(onePeakRadioButtonModel, "buttonCuration_actionPerformed");

    gbc.anchor = GridBagConstraints.WEST;
    quantCurationPanel.add(unknownRadioButton, gbc);
    quantCurationPanel.add(badRadioButton, gbc);
    quantCurationPanel.add(goodRadioButton, gbc);
    quantCurationPanel.add(onePeakRatioRadioButton, gbc);

    gbc.anchor = GridBagConstraints.PAGE_START;
    //ID curation
    JPanel idCurationPanel = new JPanel();
    idCurationPanel.setLayout(new GridBagLayout());
    idCurationPanel.setBorder(BorderFactory.createTitledBorder("ID"));
    idCurationButtonGroup = new ButtonGroup();
    JRadioButton idUnknownRadioButton = new JRadioButton("?");
    JRadioButton idGoodRadioButton = new JRadioButton("Good");
    JRadioButton idBadRadioButton = new JRadioButton("Bad");
    idUnknownRadioButton.setEnabled(false);
    idGoodRadioButton.setEnabled(false);
    idBadRadioButton.setEnabled(false);

    idCurationButtonGroup.add(idUnknownRadioButton);
    idCurationButtonGroup.add(idGoodRadioButton);
    idCurationButtonGroup.add(idBadRadioButton);
    idUnknownRadioButtonModel = idUnknownRadioButton.getModel();
    idGoodRadioButtonModel = idGoodRadioButton.getModel();
    idBadRadioButtonModel = idBadRadioButton.getModel();
    helper.addListener(idUnknownRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idGoodRadioButton, "buttonIDCuration_actionPerformed");
    helper.addListener(idBadRadioButton, "buttonIDCuration_actionPerformed");
    gbc.anchor = GridBagConstraints.WEST;
    idCurationPanel.add(idUnknownRadioButton, gbc);
    idCurationPanel.add(idBadRadioButton, gbc);
    idCurationPanel.add(idGoodRadioButton, gbc);

    gbc.gridwidth = GridBagConstraints.RELATIVE;
    curationPanel.add(quantCurationPanel, gbc);
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    curationPanel.add(idCurationPanel, gbc);

    //curation comment
    commentTextField = new JTextField();
    commentTextField.setToolTipText("Comment on this event");
    //saves after every keypress.  Would be more efficient to save when navigating away or saving to file
    commentTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            if (quantEvents == null)
                return;
            QuantEvent quantEvent = quantEvents.get(displayedEventIndex);
            //save the comment, being careful about tabs and new lines
            quantEvent.setComment(commentTextField.getText().replace("\t", " ").replace("\n", " "));
        }

        public void keyTyped(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });
    curationPanel.add(commentTextField, gbc);

    assessmentPanel = new JPanel();
    assessmentPanel.setLayout(new GridBagLayout());
    assessmentPanel.setBorder(BorderFactory.createTitledBorder("Algorithmic Assessment"));
    assessmentTypeTextField = new JTextField();
    assessmentTypeTextField.setEditable(false);
    assessmentPanel.add(assessmentTypeTextField, gbc);
    assessmentDescTextField = new JTextField();
    assessmentDescTextField.setEditable(false);
    assessmentPanel.add(assessmentDescTextField, gbc);

    //Theoretical peak distribution
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    theoreticalPeaksPanel = new JPanel();
    theoreticalPeaksPanel.setBorder(BorderFactory.createTitledBorder("Theoretical Peaks"));
    theoreticalPeaksPanel.setLayout(new GridBagLayout());
    theoreticalPeaksPanel.setMinimumSize(new Dimension(leftPanelWidth - 10, theoreticalPeaksPanelHeight));
    theoreticalPeaksPanel.setMaximumSize(new Dimension(1200, theoreticalPeaksPanelHeight));
    showTheoreticalPeaks();

    //Add everything to the left panel
    gbc.insets = new Insets(0, 5, 0, 5);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.anchor = GridBagConstraints.PAGE_START;
    leftPanel.addComponentListener(new LeftPanelResizeListener());
    gbc.weighty = 10;
    gbc.fill = GridBagConstraints.VERTICAL;
    leftPanel.add(propertiesScrollPane, gbc);
    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_END;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(assessmentPanel, gbc);
    leftPanel.add(theoreticalPeaksPanel, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    leftPanel.add(curationPanel, gbc);
    leftPanel.add(navigationPanel, gbc);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.PAGE_START;

    //Chart display
    multiChartDisplay = new TabbedMultiChartDisplayPanel();
    multiChartDisplay.setResizeDelayMS(0);

    rightPanel.addComponentListener(new RightPanelResizeListener());
    rightPanel.add(multiChartDisplay, gbc);

    //status message
    messageLabel.setBackground(Color.WHITE);
    messageLabel.setFont(Font.decode("verdana plain 12"));
    messageLabel.setText(" ");

    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    //paranoia.  Sometimes it seems Qurate doesn't exit when you close every window
    addWindowStateListener(new WindowStateListener() {
        public void windowStateChanged(WindowEvent e) {
            if (e.getNewState() == WindowEvent.WINDOW_CLOSED) {
                dispose();
                System.exit(0);
            }
        }
    });

}