Example usage for java.awt Font Font

List of usage examples for java.awt Font Font

Introduction

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

Prototype

private Font(String name, int style, float sizePts) 

Source Link

Usage

From source file:org.gbif.portal.web.util.ChartUtils.java

/**
 * Writes out the image using the supplied file name.
 * //  w  w w. j  av a2  s .c o m
 * @param legend
 * @param fileName
 * @return
 */
public static String writePieChartImageToTempFile(Map<String, Double> legend, String fileName) {

    String filePath = System.getProperty(tmpDirSystemProperty) + File.separator + fileName + defaultExtension;
    File fileToCheck = new File(filePath);
    if (fileToCheck.exists()) {
        return fileName + defaultExtension;
    }

    final DefaultPieDataset data = new DefaultPieDataset();
    Set<String> keys = legend.keySet();
    for (String key : keys) {
        logger.info("Adding key : " + key);
        data.setValue(key, legend.get(key));
    }

    // create a pie chart...
    final boolean withLegend = true;
    final JFreeChart chart = ChartFactory.createPieChart(null, data, withLegend, false, false);

    PiePlot piePlot = (PiePlot) chart.getPlot();
    piePlot.setLabelFont(new Font("Arial", Font.PLAIN, 10));
    piePlot.setLabelBackgroundPaint(Color.WHITE);

    LegendTitle lt = chart.getLegend();
    lt.setBackgroundPaint(Color.WHITE);
    lt.setWidth(300);
    lt.setBorder(0, 0, 0, 0);
    lt.setItemFont(new Font("Arial", Font.PLAIN, 11));

    chart.setPadding(new RectangleInsets(0, 0, 0, 0));
    chart.setBorderVisible(false);
    chart.setBackgroundImageAlpha(0);
    chart.setBackgroundPaint(Color.WHITE);
    chart.setBorderPaint(Color.LIGHT_GRAY);

    final BufferedImage image = new BufferedImage(300, 250, BufferedImage.TYPE_INT_RGB);
    KeypointPNGEncoderAdapter adapter = new KeypointPNGEncoderAdapter();
    adapter.setQuality(1);
    try {
        adapter.encode(image);
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
    }
    final Graphics2D g2 = image.createGraphics();
    g2.setFont(new Font("Arial", Font.PLAIN, 11));
    final Rectangle2D chartArea = new Rectangle2D.Double(0, 0, 300, 250);

    // draw
    chart.draw(g2, chartArea, null, null);

    try {
        FileOutputStream fOut = new FileOutputStream(fileToCheck);
        ChartUtilities.writeChartAsPNG(fOut, chart, 300, 250);
        return fileToCheck.getName();
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        return null;
    }
}

From source file:ComboBoxTest.java

public ComboBoxFrame() {
    setTitle("ComboBoxTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add the sample text label

    label = new JLabel("The quick brown fox jumps over the lazy dog.");
    label.setFont(new Font("Serif", Font.PLAIN, DEFAULT_SIZE));
    add(label, BorderLayout.CENTER);

    // make a combo box and add face names

    faceCombo = new JComboBox();
    faceCombo.setEditable(true);/*from w ww.j  a v a  2s. c o m*/
    faceCombo.addItem("Serif");
    faceCombo.addItem("SansSerif");
    faceCombo.addItem("Monospaced");
    faceCombo.addItem("Dialog");
    faceCombo.addItem("DialogInput");

    // the combo box listener changes the label font to the selected face name

    faceCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            label.setFont(new Font((String) faceCombo.getSelectedItem(), Font.PLAIN, DEFAULT_SIZE));
        }
    });

    // add combo box to a panel at the frame's southern border

    JPanel comboPanel = new JPanel();
    comboPanel.add(faceCombo);
    add(comboPanel, BorderLayout.SOUTH);
}

From source file:JSplash.java

private void init() {
    JPanel pnlImage = new JPanel();
    ImageIcon image = new ImageIcon(getClass().getResource("img/logo.jpg"));
    JLabel lblBack = new JLabel(image);
    Border raisedbevel = BorderFactory.createRaisedBevelBorder();
    Border loweredbevel = BorderFactory.createLoweredBevelBorder();

    lblBack.setBounds(0, 0, image.getIconWidth(), image.getIconHeight());
    getLayeredPane().add(lblBack, new Integer(Integer.MIN_VALUE));

    pnlImage.setLayout(null);//from w  w w  . j av a2 s .com
    pnlImage.setOpaque(false);
    pnlImage.setBorder(BorderFactory.createCompoundBorder(raisedbevel, loweredbevel));

    pnlImage.add(this.lblVersion);

    this.lblVersion.setForeground(Color.white);
    this.lblVersion.setFont(new Font("Dialog", Font.PLAIN, 12));
    this.lblVersion.setBounds(15, 69, 120, 20);

    setContentPane(pnlImage);
    setSize(image.getIconWidth(), image.getIconHeight());
}

From source file:hermes.swing.SwingAppender.java

public SwingAppender(String filter) {
    this.filter = filter;

    textArea.setFont(new Font("Courier", Font.PLAIN, 12));
}

From source file:CheckBoxTest.java

public CheckBoxFrame() {
    setTitle("CheckBoxTest");
    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

    // add the sample text label

    label = new JLabel("The quick brown fox jumps over the lazy dog.");
    label.setFont(new Font("Serif", Font.PLAIN, FONTSIZE));
    add(label, BorderLayout.CENTER);

    // this listener sets the font attribute of
    // the label to the check box state

    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            int mode = 0;
            if (bold.isSelected())
                mode += Font.BOLD;
            if (italic.isSelected())
                mode += Font.ITALIC;
            label.setFont(new Font("Serif", mode, FONTSIZE));
        }//  w  w  w.  j av  a 2s  .  c om
    };

    // add the check boxes

    JPanel buttonPanel = new JPanel();

    bold = new JCheckBox("Bold");
    bold.addActionListener(listener);
    buttonPanel.add(bold);

    italic = new JCheckBox("Italic");
    italic.addActionListener(listener);
    buttonPanel.add(italic);

    add(buttonPanel, BorderLayout.SOUTH);
}

From source file:org.jfree.chart.demo.CategoryMarkerDemo1.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart("Category Marker Demo 1", "Category", "Count",
            categorydataset, PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.lightGray);
    categoryplot.setRangeGridlinePaint(Color.white);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot.getRenderer();
    lineandshaperenderer.setSeriesShapesVisible(0, true);
    lineandshaperenderer.setDrawOutlines(true);
    lineandshaperenderer.setUseFillPaint(true);
    lineandshaperenderer.setBaseFillPaint(Color.white);
    CategoryMarker categorymarker = new CategoryMarker("Category 4", Color.blue, new BasicStroke(1.0F));
    categorymarker.setDrawAsLine(true);/* w w  w.  j av  a2 s. c  o  m*/
    categorymarker.setLabel("Marker Label");
    categorymarker.setLabelFont(new Font("Dialog", 0, 11));
    categorymarker.setLabelTextAnchor(TextAnchor.TOP_RIGHT);
    categorymarker.setLabelOffset(new RectangleInsets(2D, 5D, 2D, 5D));
    categoryplot.addDomainMarker(categorymarker, Layer.BACKGROUND);
    return jfreechart;
}

From source file:app.gui.ViewGraphic.java

public ViewGraphic(String title) {
    setSize(600, 400);//from   w w w  . j  a va  2 s  .c o m
    setLocationRelativeTo(this);
    setTitle(title);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent arg0) {
            dispose();
        }
    });
    setLayout(new BorderLayout());

    serieError = new XYSeries(title);

    dataset = new XYSeriesCollection();
    dataset.addSeries(serieError);

    chart = ChartFactory.createXYLineChart(title, Translate.get("GUI_PERIODS"), Translate.get("GUI_ERROR"),
            dataset, PlotOrientation.VERTICAL, true, true, false);
    add(new ChartPanel(chart), BorderLayout.CENTER);

    JPanel south = new JPanel(new MigLayout());

    lblError = new JLabel("");
    lblError.setHorizontalTextPosition(SwingConstants.LEFT);
    lblError.setFont(new Font("ARIAL", Font.BOLD, 26));
    JLabel lblErrorTitle = new JLabel(Translate.get("GUI_ERROR") + ": ");
    lblErrorTitle.setFont(new Font("ARIAL", Font.BOLD, 26));
    south.add(lblErrorTitle);
    south.add(lblError, "wrap");

    add(south, BorderLayout.SOUTH);
    setVisible(true);
}

From source file:WelcomeApplet.java

 public void init()
{
   EventQueue.invokeLater(new Runnable()
      {/*from   ww w  . ja  va  2 s  .  co  m*/
         public void run()
         {
            setLayout(new BorderLayout());

            JLabel label = new JLabel(getParameter("greeting"), SwingConstants.CENTER);
            label.setFont(new Font("Serif", Font.BOLD, 18));
            add(label, BorderLayout.CENTER);

            JPanel panel = new JPanel();

            JButton cayButton = new JButton("Cay Horstmann");
            cayButton.addActionListener(makeAction("http://www.horstmann.com"));
            panel.add(cayButton);

            JButton garyButton = new JButton("Gary Cornell");
            garyButton.addActionListener(makeAction("mailto:gary_cornell@apress.com"));
            panel.add(garyButton);

            add(panel, BorderLayout.SOUTH);
         }
      });
}

From source file:jmbench.plots.MemoryRelativeBarPlot.java

public MemoryRelativeBarPlot(String title) {
    chart = ChartFactory.createBarChart(title, // chart title
            "Operation", // domain axis label
            "Relative Memory", // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );/*from   w  ww . j  a  va  2  s  .c o m*/
    chart.addSubtitle(new TextTitle("(Smaller is Better)", new Font("SansSerif", Font.ITALIC, 12)));

    plot();
}

From source file:ShowOff.java

public ShowOff(String filename, String message, int split) throws IOException, ImageFormatException {

    InputStream in = getClass().getResourceAsStream(filename);
    JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(in);
    mImage = decoder.decodeAsBufferedImage();
    in.close();/*  w ww .  j  a v  a  2s.  co m*/

    mFont = new Font("Serif", Font.PLAIN, 116);

    mMessage = message;
    mSplit = split;

    setSize((int) mImage.getWidth(), (int) mImage.getHeight());
}