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:hermes.renderers.DefaultMessageRenderer.java

/**
 * Show the TextMessage in a JTextArea./*  w  w  w  .j  a va  2s  .c  o  m*/
 * 
 * @param textMessage
 * @return
 * @throws JMSException
 */
protected JComponent handleTextMessage(final TextMessage textMessage) throws JMSException {
    //
    // Show the text in a JTextArea, you can edit the message in place and
    // then drop it onto another queue/topic.

    final String text = textMessage.getText();
    final JTextArea textPane = new JTextArea();

    // final CharBuffer bytes = CharBuffer.wrap(text.subSequence(0,
    // text.length())) ;
    // final JTextArea textPane = new MyTextArea(new PlainDocument(new
    // MappedStringContent(bytes))) ;

    textPane.setEditable(false);
    textPane.setFont(Font.decode("Monospaced-PLAIN-12"));
    textPane.setLineWrap(true);
    textPane.setWrapStyleWord(true);

    textPane.append(text);

    textPane.getDocument().addDocumentListener(new DocumentListener() {
        public void doChange() {
            try {
                textMessage.setText(textPane.getText());
            } catch (JMSException e) {
                JOptionPane.showMessageDialog(textPane, "Unable to update the TextMessage: " + e.getMessage(),
                        "Error modifying message content", JOptionPane.ERROR_MESSAGE);

                try {
                    textPane.setText(textMessage.getText());
                } catch (JMSException e1) {
                    log.error(e1.getMessage(), e1);
                }

                textPane.setEditable(false);
                textPane.getDocument().removeDocumentListener(this);
            }
        }

        @Override
        public void changedUpdate(DocumentEvent arg0) {
            doChange();
        }

        @Override
        public void insertUpdate(DocumentEvent arg0) {
            doChange();
        }

        @Override
        public void removeUpdate(DocumentEvent arg0) {
            doChange();
        }
    });

    textPane.setCaretPosition(0);

    return textPane;
}

From source file:forms.frDados.java

/**
 * Inicializa o grfico de intensidade de sinal dos satlites.
 *//*from w ww  . j  a  v a 2  s . com*/
private void initSatGrafico() {
    dadosGraficoSats.clear();
    plot = ChartFactory.createBarChart("Intensidade do sinal", "PRN", "SNR", dadosGraficoSats,
            PlotOrientation.VERTICAL, false, true, true);

    plot.getTitle().setFont(Font.decode("arial-16"));
    plot.getTitle().setPadding(5, 20, 5, 20);
    plot.setPadding(new RectangleInsets(10, 10, 0, 10));
    //plot.setBackgroundPaint(new Color(255,255,255,0));

    BarRenderer br = (BarRenderer) plot.getCategoryPlot().getRenderer();
    br.setSeriesPaint(0, Color.BLUE);
    br.setMaximumBarWidth(0.05);

    plot.getCategoryPlot().getRangeAxis().setRange(new Range(0, 50), true, true);
    br.setBaseItemLabelsVisible(true);
    br.setSeriesItemLabelFont(0, Font.decode("arial-12"));
    br.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    br.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BASELINE_CENTER));

    SpringLayout lm = new SpringLayout();
    ChartPanel cp = new ChartPanel(plot);
    cp.setBorder(LineBorder.createGrayLineBorder());

    lm.putConstraint(SpringLayout.EAST, pnlSatPlot, 10, SpringLayout.EAST, cp);
    lm.putConstraint(SpringLayout.WEST, cp, 10, SpringLayout.WEST, pnlSatPlot);
    lm.putConstraint(SpringLayout.SOUTH, pnlSatPlot, 10, SpringLayout.SOUTH, cp);
    lm.putConstraint(SpringLayout.NORTH, cp, 10, SpringLayout.NORTH, pnlSatPlot);

    pnlSatPlot.setLayout(lm);
    pnlSatPlot.add(cp);
}

From source file:ShowComponent.java

/**
 * This method loops through the command line arguments looking for class
 * names of components to create and property settings for those components
 * in the form name=value. This method demonstrates reflection and JavaBeans
 * introspection as they can be applied to dynamically created GUIs
 *//*from  w  w  w.j  a v a2  s. c o m*/
public static Vector getComponentsFromArgs(String[] args) {
    Vector components = new Vector(); // List of components to return
    Component component = null; // The current component
    PropertyDescriptor[] properties = null; // Properties of the component
    Object[] methodArgs = new Object[1]; // We'll use this below

    nextarg: // This is a labeled loop
    for (int i = 0; i < args.length; i++) { // Loop through all arguments
        // If the argument does not contain an equal sign, then it is
        // a component class name. Otherwise it is a property setting
        int equalsPos = args[i].indexOf('=');
        if (equalsPos == -1) { // Its the name of a component
            try {
                // Load the named component class
                Class componentClass = Class.forName(args[i]);
                // Instantiate it to create the component instance
                component = (Component) componentClass.newInstance();
                // Use JavaBeans to introspect the component
                // And get the list of properties it supports
                BeanInfo componentBeanInfo = Introspector.getBeanInfo(componentClass);
                properties = componentBeanInfo.getPropertyDescriptors();
            } catch (Exception e) {
                // If any step failed, print an error and exit
                System.out.println("Can't load, instantiate, " + "or introspect: " + args[i]);
                System.exit(1);
            }

            // If we succeeded, store the component in the vector
            components.addElement(component);
        } else { // The arg is a name=value property specification
            String name = args[i].substring(0, equalsPos); // property name
            String value = args[i].substring(equalsPos + 1); // property
            // value

            // If we don't have a component to set this property on, skip!
            if (component == null)
                continue nextarg;

            // Now look through the properties descriptors for this
            // component to find one with the same name.
            for (int p = 0; p < properties.length; p++) {
                if (properties[p].getName().equals(name)) {
                    // Okay, we found a property of the right name.
                    // Now get its type, and the setter method
                    Class type = properties[p].getPropertyType();
                    Method setter = properties[p].getWriteMethod();

                    // Check if property is read-only!
                    if (setter == null) {
                        System.err.println("Property " + name + " is read-only");
                        continue nextarg; // continue with next argument
                    }

                    // Try to convert the property value to the right type
                    // We support a small set of common property types here
                    // Store the converted value in an Object[] so it can
                    // be easily passed when we invoke the property setter
                    try {
                        if (type == String.class) { // no conversion needed
                            methodArgs[0] = value;
                        } else if (type == int.class) { // String to int
                            methodArgs[0] = Integer.valueOf(value);
                        } else if (type == boolean.class) { // to boolean
                            methodArgs[0] = Boolean.valueOf(value);
                        } else if (type == Color.class) { // to Color
                            methodArgs[0] = Color.decode(value);
                        } else if (type == Font.class) { // String to Font
                            methodArgs[0] = Font.decode(value);
                        } else {
                            // If we can't convert, ignore the property
                            System.err
                                    .println("Property " + name + " is of unsupported type " + type.getName());
                            continue nextarg;
                        }
                    } catch (Exception e) {
                        // If conversion failed, continue with the next arg
                        System.err.println("Can't convert  '" + value + "' to type " + type.getName()
                                + " for property " + name);
                        continue nextarg;
                    }

                    // Finally, use reflection to invoke the property
                    // setter method of the component we created, and pass
                    // in the converted property value.
                    try {
                        setter.invoke(component, methodArgs);
                    } catch (Exception e) {
                        System.err.println("Can't set property: " + name);
                    }

                    // Now go on to next command-line arg
                    continue nextarg;
                }
            }

            // If we get here, we didn't find the named property
            System.err.println("Warning: No such property: " + name);
        }
    }

    return components;
}

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

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

    final Plot plot = chart.getPlot();
    final PiePlot pp = (PiePlot) plot;
    final PieDataset pieDS = pp.getDataset();
    pp.setDirection(rotationClockwise ? Rotation.CLOCKWISE : Rotation.ANTICLOCKWISE);
    if ((explodeSegment != null) && (explodePct != null)) {
        configureExplode(pp);/*from  w w w . j av a  2  s .  c  om*/
    }
    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        pp.setToolTipGenerator(new FormulaPieTooltipGenerator(getRuntime(), getTooltipFormula()));
    }
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        pp.setURLGenerator(new FormulaPieURLGenerator(getRuntime(), getUrlFormula()));
    }

    pp.setIgnoreNullValues(ignoreNulls);
    pp.setIgnoreZeroValues(ignoreZeros);
    if (Boolean.FALSE.equals(getItemsLabelVisible())) {
        pp.setLabelGenerator(null);
    } else {
        final ExpressionRuntime runtime = getRuntime();
        final Locale locale = runtime.getResourceBundleFactory().getLocale();

        final FastDecimalFormat fastPercent = new FastDecimalFormat(FastDecimalFormat.TYPE_PERCENT, locale);
        final FastDecimalFormat fastInteger = new FastDecimalFormat(FastDecimalFormat.TYPE_INTEGER, locale);

        final DecimalFormat numFormat = new DecimalFormat(fastInteger.getPattern(),
                new DecimalFormatSymbols(locale));
        numFormat.setRoundingMode(RoundingMode.HALF_UP);

        final DecimalFormat percentFormat = new DecimalFormat(fastPercent.getPattern(),
                new DecimalFormatSymbols(locale));
        percentFormat.setRoundingMode(RoundingMode.HALF_UP);

        final StandardPieSectionLabelGenerator labelGen = new StandardPieSectionLabelGenerator(pieLabelFormat,
                numFormat, percentFormat);
        pp.setLabelGenerator(labelGen);

        final StandardPieSectionLabelGenerator legendGen = new StandardPieSectionLabelGenerator(
                pieLegendLabelFormat, numFormat, percentFormat);
        pp.setLegendLabelGenerator(legendGen);
    }

    if (StringUtils.isEmpty(getLabelFont()) == false) {
        pp.setLabelFont(Font.decode(getLabelFont()));
    }

    if (pieDS != null) {
        final String[] colors = getSeriesColor();
        for (int i = 0; i < colors.length; i++) {
            if (i < pieDS.getItemCount()) {
                pp.setSectionPaint(pieDS.getKey(i), parseColorFromString(colors[i]));
            } else {
                break;
            }
        }
    }

    if (shadowPaint != null) {
        pp.setShadowPaint(shadowPaint);
    }
    if (shadowXOffset != null) {
        pp.setShadowXOffset(shadowXOffset.doubleValue());
    }
    if (shadowYOffset != null) {
        pp.setShadowYOffset(shadowYOffset.doubleValue());
    }
    pp.setCircular(circular);

    if (isShowBorder() == false || isChartSectionOutline() == false) {
        chart.setBorderVisible(false);
        chart.getPlot().setOutlineVisible(false);
    }

}

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

/**
 * @deprecated
 */
public void setBarsTickLabelFont(final String barsTickLabelFont) {
    setRangeTickFont(Font.decode(barsTickLabelFont));
}

From source file:hermes.browser.actions.AbstractFIXBrowserDocumentComponent.java

protected Component createPrettyPrintPanel(FIXMessage m) {
    final JTextArea textArea = new JTextArea();

    textArea.setEditable(false);//from w  w  w. j av a2  s. c  o  m
    textArea.setFont(Font.decode("Monospaced-PLAIN-12"));

    byte[] bytes = null;

    try {
        textArea.setText(FIXUtils.prettyPrint(m));
    } catch (Throwable e) {
        textArea.setText(e.getMessage());

        log.error("exception converting message to byte[]: ", e);
    }

    textArea.setCaretPosition(0);

    return SwingUtils.createJScrollPane(textArea);
}

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

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

    //Create the stroke for the primary (= real) data series...
    final Stroke thick = new BasicStroke(thicknessprimaryseries);

    //...and apply that stroke to the series
    final SpiderWebPlot webPlot = (SpiderWebPlot) chart.getPlot();
    webPlot.setLabelFont(Font.decode(getLabelFont()));

    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        webPlot.setToolTipGenerator(new FormulaCategoryTooltipGenerator(getRuntime(), getTooltipFormula()));
    }// ww  w. j a v  a2  s .  co  m
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        webPlot.setURLGenerator(new FormulaCategoryURLGenerator(getRuntime(), getUrlFormula()));
    }

    final CategoryDataset categoryDataset = webPlot.getDataset();
    final int count = categoryDataset.getRowCount();

    for (int t = 0; t < count; t++) {
        if (categoryDataset.getRowKey(t) instanceof GridCategoryItem) {
            continue;
        }
        webPlot.setSeriesOutlineStroke(t, thick);
    }

    //Set the spiderweb filled (or not)
    webPlot.setWebFilled(radarwebfilled);
    //Set the size of the datapoints on the axis
    webPlot.setHeadPercent(headsize);

    //Set the color of the fake datasets (gridlines) to grey
    for (int t = 0; t < count; t++) {
        if (categoryDataset.getRowKey(t) instanceof GridCategoryItem) {
            webPlot.setSeriesPaint(t, Color.GRAY);
        }
    }

}

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

/**
 * @deprecated
 */
public void setBarsLabelFont(final String barsLabelFont) {
    setRangeTitleFont(Font.decode(barsLabelFont));
}

From source file:hermes.browser.actions.AbstractFIXBrowserDocumentComponent.java

protected Component createHexPanel(FIXMessage m) {
    final JTextArea textArea = new JTextArea();

    textArea.setEditable(false);//  w w  w.j  a va  2 s  .  c om
    textArea.setFont(Font.decode("Monospaced-PLAIN-12"));

    byte[] bytes = null;

    try {
        textArea.setText(DumpUtils.dumpBinary(m.getBytes(), DumpUtils.DUMP_AS_HEX_AND_ALPHA));
    } catch (Throwable e) {
        textArea.setText(e.getMessage());

        log.error("exception converting message to byte[]: ", e);
    }

    textArea.setCaretPosition(0);

    final JScrollPane scrollPane = new JScrollPane();
    scrollPane.setViewportView(textArea);

    return scrollPane;
}

From source file:ffx.ui.KeywordPanel.java

private void initialize() {
    // Load the Keyword Definitions
    loadXML();/*from ww w.j  a va2  s.c o  m*/
    // TextAreas
    flatfileTextArea = new JTextArea();
    flatfileTextArea.setEditable(false);
    flatfileTextArea.setFont(Font.decode("monospaced plain 12"));
    Insets insets = flatfileTextArea.getInsets();
    insets.set(5, 5, 5, 5);
    flatfileTextArea.setMargin(insets);
    // Keyword Edit Panel
    editPanel = new JPanel(flowLayout);
    ClassLoader loader = getClass().getClassLoader();
    ImageIcon icKeyPanel = new ImageIcon(loader.getResource("ffx/ui/icons/page_key.png"));
    noSystemLabel.setIcon(icKeyPanel);
    ImageIcon icon = new ImageIcon(loader.getResource("ffx/ui/icons/information.png"));
    noKeywordLabel.setIcon(icon);
    noKeywordPanel.add(noKeywordLabel);
    editScrollPane = new JScrollPane(editPanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    descriptScrollPane = new JScrollPane(descriptTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    Border eb = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
    descriptScrollPane.setBorder(eb);
    // Add the Keyword Group Panel and Decription Panel to a JSplitPane
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editScrollPane, descriptScrollPane);
    splitPane.setResizeWeight(1.0);
    splitPane.setOneTouchExpandable(true);
    statusLabel.setBorder(eb);
    // Add the main pieces to the overall KeywordPanel (except the ToolBar)
    setLayout(new BorderLayout());
    add(splitPane, BorderLayout.CENTER);
    add(statusLabel, BorderLayout.SOUTH);
    // Init the GridBagContraints
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.anchor = GridBagConstraints.WEST;
    gridBagConstraints.gridheight = 1;
    gridBagConstraints.gridwidth = 1;
    gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
    initToolBar();
    add(toolBar, BorderLayout.NORTH);
    setParamPath();
    loadPrefs();
    loadKeywordGroup();
}