Example usage for java.awt Font BOLD

List of usage examples for java.awt Font BOLD

Introduction

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

Prototype

int BOLD

To view the source code for java.awt Font BOLD.

Click Source Link

Document

The bold style constant.

Usage

From source file:FileLister.java

/**
 * Constructor: create the GUI, and list the initial directory.
 *//*from  w  w w .  j  av  a 2 s . com*/
public FileLister(String directory, FilenameFilter filter) {
    super("File Lister"); // Create the window
    this.filter = filter; // Save the filter, if any

    // Destroy the window when the user requests it
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            dispose();
        }
    });

    list = new List(12, false); // Set up the list
    list.setFont(new Font("MonoSpaced", Font.PLAIN, 14));
    list.addActionListener(this);
    list.addItemListener(this);

    details = new TextField(); // Set up the details area
    details.setFont(new Font("MonoSpaced", Font.PLAIN, 12));
    details.setEditable(false);

    buttons = new Panel(); // Set up the button box
    buttons.setLayout(new FlowLayout(FlowLayout.RIGHT, 15, 5));
    buttons.setFont(new Font("SansSerif", Font.BOLD, 14));

    up = new Button("Up a Directory"); // Set up the two buttons
    close = new Button("Close");
    up.addActionListener(this);
    close.addActionListener(this);

    buttons.add(up); // Add buttons to button box
    buttons.add(close);

    this.add(list, "Center"); // Add stuff to the window
    this.add(details, "North");
    this.add(buttons, "South");
    this.setSize(500, 350);

    listDirectory(directory); // And now list initial directory.
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.TimeChartRenderer.java

public void createChart() {
    XYDataset dataset = (XYDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createTimeSeriesChart(this.datasetStrategy.getTitle(), // title
            this.datasetStrategy.getXAxisLabel(), // x-axis label
            this.datasetStrategy.getYAxisLabel(), // y-axis label
            dataset, // data
            true, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );//from   ww w. j  a va  2  s  .c o m

    // report.setBackgroundPaint( Color.lightGray );
    XYPlot plot = report.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
    XYItemRenderer xyitemrenderer = plot.getRenderer();
    if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) xyitemrenderer;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);

        renderer.setBaseShapesVisible(true);
        renderer.setDrawOutlines(true);
        renderer.setBaseItemLabelGenerator(
                ((AbstractTimeChartStrategy) this.datasetStrategy).getLabelGenerator());
        renderer.setBaseItemLabelFont(new Font("SansSerif", Font.BOLD, 10));
        renderer.setBaseItemLabelsVisible(true);
        renderer.setBasePositiveItemLabelPosition(
                new ItemLabelPosition(ItemLabelAnchor.OUTSIDE10, TextAnchor.BASELINE_RIGHT));
    }

    Paint[] paints = this.datasetStrategy.getPaintColor();
    for (int i = 0; i < dataset.getSeriesCount() && i < paints.length; i++) {
        xyitemrenderer.setSeriesPaint(i, paints[i]);
        xyitemrenderer.setSeriesStroke(i, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    }
    plot.setRangeAxis(((AbstractTimeChartStrategy) this.datasetStrategy).getRangeAxis());
    DashDateAxis axisDate = new DashDateAxis();
    axisDate.setDateFormatOverride(
            ((AbstractTimeChartStrategy) this.datasetStrategy).getTimePeriod().getDateFormat());
    axisDate.setLabel(this.datasetStrategy.getXAxisLabel());
    axisDate.setTickUnit(getTickUnit(((AbstractTimeChartStrategy) this.datasetStrategy).getTimePeriod()));
    axisDate.setUpperMargin(0.0D);
    axisDate.setDateTickLabelAngle(-0.6);

    if (((AbstractTimeChartStrategy) this.datasetStrategy).getStartDate() != null
            && ((AbstractTimeChartStrategy) this.datasetStrategy).getEndDate() != null) {
        axisDate.setRangeWithMargins(
                new DateRange(((AbstractTimeChartStrategy) this.datasetStrategy).getStartDate(),
                        ((AbstractTimeChartStrategy) this.datasetStrategy).getEndDate()));

    }
    plot.setDomainAxis(axisDate);

    Date[] dates = DateUtils.getAllDates(((AbstractTimeChartStrategy) this.datasetStrategy).getStartDate(),
            ((AbstractTimeChartStrategy) this.datasetStrategy).getEndDate(),
            ((AbstractTimeChartStrategy) this.datasetStrategy).getTimePeriod());
    int width = (dates.length * ChartUtils.STANDARD_TIME_ENTRY_WIDTH)
            + ChartUtils.STANDARD_TIME_ADDITIONAL_WIDTH;
    if (width > ChartUtils.MINIMUM_WIDTH) {
        this.setWidth(width);
    } else {
        this.setWidth(ChartUtils.MINIMUM_WIDTH);
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.ImportDataFileInfo.java

/**
 *  shows modified (truncated) data after import
 *//* ww w  .  j  a  v a  2  s  . c o  m*/
protected void showModifiedData() {
    if (importer.getTruncations().size() > 0) {
        JPanel mainPane = new JPanel(new BorderLayout());
        JLabel msg = createLabel(getResourceString("WB_TRUNCATIONS"));
        msg.setFont(msg.getFont().deriveFont(Font.BOLD));
        mainPane.add(msg, BorderLayout.NORTH);

        String[] heads = new String[3];
        String[][] vals = new String[importer.getTruncations().size()][3];
        heads[0] = getResourceString("WB_ROW");
        heads[1] = getResourceString("WB_COLUMN");
        heads[2] = getResourceString("WB_TRUNCATED");

        int row = 0;
        for (DataImportTruncation trunc : importer.getTruncations()) {
            vals[row][0] = String.valueOf(trunc.getRow());
            vals[row][1] = trunc.getColHeader();
            if (vals[row][1].equals("")) {
                vals[row][1] = String.valueOf(trunc.getCol() + 1);
            }
            vals[row++][2] = trunc.getExcluded();
        }

        JTable mods = new JTable(vals, heads);
        mods.setDefaultRenderer(String.class, new BiColorTableCellRenderer(false));

        mainPane.add(UIHelper.createScrollPane(mods), BorderLayout.CENTER);

        CustomFrame cwin = new CustomFrame(getResourceString(MODIFIED_IMPORT_DATA), CustomFrame.OKHELP,
                mainPane);
        cwin.setHelpContext("WorkbenchImportData"); //help context could be more specific
        cwin.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        UIHelper.centerAndShow(cwin);
    }
    if (importer.getMessages().size() > 0) {
        JPanel mainPane = new JPanel(new BorderLayout());
        JTextArea msgs = new JTextArea();
        msgs.setRows(importer.getMessages().size());
        for (String msg : importer.getMessages()) {
            msgs.append(msg);
            msgs.append("\n");
        }
        mainPane.add(msgs, BorderLayout.CENTER);
        CustomFrame cwin = new CustomFrame(getResourceString(MODIFIED_IMPORT_DATA), CustomFrame.OKHELP,
                mainPane);
        cwin.setHelpContext("WorkbenchImportData"); //help context could be more specific
        cwin.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        UIHelper.centerAndShow(cwin);
    }
}

From source file:com.game.ui.views.CharachterEditorPanel.java

public void doGui() {
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    JLabel noteLbl = new JLabel("Pls select a value to choose an enemy or you can create a new "
            + "Enemy entity below. Once selected an Enemy character, its' details will be available below");
    noteLbl.setAlignmentX(0);// w w  w.j  a  v a 2s  . c  o m
    //        noteLbl.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(noteLbl);
    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (GameCharacter character : GameBean.enemyDetails) {
        System.out.println(character.getName());
        model.addElement(character.getName());
    }
    comboBox = new JComboBox(model);
    comboBox.setSelectedIndex(-1);
    comboBox.setMaximumSize(new Dimension(100, 30));
    comboBox.setAlignmentX(0);
    comboBox.setActionCommand("dropDown");
    comboBox.addActionListener(this);
    add(Box.createVerticalStrut(10));
    add(comboBox);
    add(Box.createVerticalStrut(10));
    JPanel panel1 = new JPanel();
    panel1.setAlignmentX(0);
    panel1.setBorder(LineBorder.createGrayLineBorder());
    panel1.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(5, 5, 5, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 2;
    JLabel enemyDtlLbl = new JLabel("Enemy Character Details : ");
    enemyDtlLbl.setFont(new Font("Times New Roman", Font.BOLD, 15));
    panel1.add(enemyDtlLbl, c);
    c.gridwidth = 1;
    c.gridy = 1;
    JLabel nameLbl = new JLabel("Name : ");
    panel1.add(nameLbl, c);
    c.gridx = 1;
    JTextField name = new JTextField("");
    name.setColumns(20);
    panel1.add(name, c);
    c.gridx = 0;
    c.gridy = 2;
    JLabel imageLbl = new JLabel("Image Path : ");
    panel1.add(imageLbl, c);
    c.gridx = 1;
    JTextField image = new JTextField("");
    image.setColumns(20);
    panel1.add(image, c);
    c.gridx = 0;
    c.gridy = 3;
    JLabel healthLbl = new JLabel("Health Pts : ");
    panel1.add(healthLbl, c);
    c.gridx = 1;
    JTextField health = new JTextField("");
    health.setColumns(20);
    panel1.add(health, c);
    c.gridx = 0;
    c.gridy = 4;
    JLabel attackPtsLbl = new JLabel("Attack Points : ");
    panel1.add(attackPtsLbl, c);
    c.gridx = 1;
    JTextField attackPts = new JTextField("");
    attackPts.setColumns(20);
    panel1.add(attackPts, c);
    c.gridx = 0;
    c.gridy = 5;
    JLabel armoursPtsLbl = new JLabel("Armour Points : ");
    panel1.add(armoursPtsLbl, c);
    c.gridx = 1;
    JTextField armourPts = new JTextField("");
    armourPts.setColumns(20);
    panel1.add(armourPts, c);
    c.gridx = 0;
    c.gridy = 6;
    JLabel attackRngeLbl = new JLabel("Attack Range : ");
    panel1.add(attackRngeLbl, c);
    c.gridx = 1;
    JTextField attackRnge = new JTextField("");
    attackRnge.setColumns(20);
    panel1.add(attackRnge, c);
    c.gridx = 0;
    c.gridy = 7;
    JLabel movementLbl = new JLabel("Movement : ");
    panel1.add(movementLbl, c);
    c.gridx = 1;
    JTextField movement = new JTextField("");
    movement.setColumns(20);
    panel1.add(movement, c);
    c.gridx = 0;
    c.gridy = 8;
    c.gridwidth = 2;
    JButton submit = new JButton("Save");
    submit.addActionListener(this);
    submit.setActionCommand("button");
    panel1.add(submit, c);
    add(panel1);
    c.gridx = 0;
    c.gridy = 9;
    JLabel validationMess = new JLabel("Pls enter all the fields or pls choose a character from the drop down");
    validationMess.setForeground(Color.red);
    validationMess.setVisible(false);
    add(validationMess, c);
    add(Box.createVerticalGlue());
}

From source file:netplot.DialPlotPanel.java

public void addPlot() throws NetPlotException {
    chart.setTitle(plotTitle);/*from   ww  w.  j av a  2  s.  c  o  m*/

    DialTextAnnotation annotation = new DialTextAnnotation(plotName);
    annotation.setFont(new Font("Dialog", Font.BOLD, 14));
    if (plotCount == 0) {
        DialValueIndicator dvi = new DialValueIndicator(0);
        dvi.setFont(new Font("Dialog", Font.PLAIN, 10));
        annotation.setRadius(0.7);
        annotation.setPaint(DialPlotPanel.Plot0Color);
        dvi.setRadius(0.60);
        dvi.setAngle(-103.0);
        dvi.setOutlinePaint(DialPlotPanel.Plot0Color);

        StandardDialScale scale = new StandardDialScale(minScaleValue, maxScaleValue, -120, -300,
                yAxisTickCount, yAxisTickCount / 2 - 1);
        scale.setTickRadius(0.88);
        scale.setTickLabelOffset(0.15);
        scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 14));
        plot.addScale(0, scale);
        plot.mapDatasetToScale(0, 0);

        DialPointer.Pointer p = new DialPointer.Pointer(0);
        p.setFillPaint(DialPlotPanel.Plot0Color);
        plot.addPointer(p);

        plot.addLayer(annotation);
        plot.addLayer(dvi);

    } else if (plotCount == 1) {
        annotation.setRadius(0.8);
        annotation.setPaint(DialPlotPanel.Plot1Color);
        DialValueIndicator dvi = new DialValueIndicator(1);
        dvi.setFont(new Font("Dialog", Font.PLAIN, 10));
        dvi.setRadius(0.60);
        dvi.setAngle(-77.0);
        dvi.setOutlinePaint(DialPlotPanel.Plot1Color);

        StandardDialScale scale2 = new StandardDialScale(minScaleValue, maxScaleValue, -120, -300,
                yAxisTickCount, yAxisTickCount / 2 - 1);
        scale2.setTickRadius(0.50);
        scale2.setTickLabelOffset(0.15);
        scale2.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
        scale2.setMajorTickPaint(DialPlotPanel.Plot1Color);
        plot.addScale(1, scale2);
        plot.mapDatasetToScale(1, 1);

        DialPointer.Pointer p = new DialPointer.Pointer(1);
        p.setFillPaint(DialPlotPanel.Plot1Color);
        p.setRadius(0.55);
        plot.addPointer(p);

        plot.addLayer(annotation);
        plot.addLayer(dvi);

    } else {
        throw new NetPlotException(
                "DialPlotPanel.addPlot(). Only two plots available on this plot, this is the third.");
    }

    plotCount++;
}

From source file:it.alus.GPSreceiver.instruments.Altimeter.java

public Altimeter(float groundAltitudeFt) {
    super(null);/*w  w  w . ja va2s.  c  om*/
    altitude = 0;
    if (groundAltitudeFt < 0)
        groundAltitude = 0;
    else
        groundAltitude = groundAltitudeFt;
    hoursDataset = new DefaultValueDataset(0.0);
    minutesDataset = new DefaultValueDataset(0.0);
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);
    Image background = Toolkit.getDefaultToolkit().getImage(getClass().getResource("altimeter.png"));
    plot.setDataset(0, hoursDataset);
    plot.setDataset(1, minutesDataset);
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setBackgroundPaint(Color.lightGray);
    dialFrame.setForegroundPaint(Color.gray);
    DialTextAnnotation annotation = new DialTextAnnotation("Feet");
    annotation.setFont(new Font("Arial", 1, 14));
    annotation.setRadius(0.4D);
    annotation.setPaint(Color.lightGray);
    plot.addLayer(annotation);
    DialValueIndicator valueindicator = new DialValueIndicator(0);
    NumberFormat formatter = new DecimalFormat("#");
    plot.addLayer(valueindicator);
    plot.setDialFrame(dialFrame);
    StandardDialScale scale = new StandardDialScale(0, 10, 90, -360, 1, 10);
    scale.setMajorTickPaint(Color.white);
    scale.setMinorTickPaint(Color.lightGray);
    scale.setFirstTickLabelVisible(false);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.15);
    scale.setTickLabelFormatter(formatter);
    scale.setTickLabelFont(new Font("Arial", Font.BOLD, 24));
    scale.setTickLabelPaint(Color.white);
    plot.addScale(3, scale);
    plot.setBackground(new DialBackground(Color.black));
    StandardDialScale hourScale = new StandardDialScale(0, 10000, 90, -360, 1000, 10);
    hourScale.setVisible(false);
    hourScale.setTickRadius(0.88);
    hourScale.setTickLabelOffset(0.15);
    plot.addScale(0, hourScale);
    StandardDialScale minScale = new StandardDialScale(0, 1000, 90, -360, 0, 0);
    minScale.setVisible(false);
    minScale.setMajorTickIncrement(5.0);
    minScale.setTickRadius(0.68);
    plot.addScale(1, minScale);
    Pointer hourNeedle = new Pointer(0);
    hourNeedle.setRadius(0.55);
    hourNeedle.setFillPaint(Color.lightGray);
    plot.addLayer(hourNeedle);
    plot.mapDatasetToScale(1, 1);
    Pointer minNeedle = new Pointer(1);
    minNeedle.setFillPaint(Color.white);
    plot.addLayer(minNeedle);
    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    cap.setFillPaint(Color.lightGray);
    plot.setCap(cap);
    jChart = new JFreeChart(plot);
    jChart.setBackgroundImage(background);
    super.setChart(jChart);
    super.setPreferredSize(new Dimension(400, 400));
}

From source file:edu.harvard.i2b2.analysis.ui.WaitPanel.java

public void init(int width, int height) {
    if (width <= 0 || height <= 0) {
        width = 273;//from  w  ww.j  a  v  a  2 s .  c  om
        height = 144;
    }

    setBackground(java.awt.Color.WHITE);
    java.awt.Image img = this.getToolkit().getImage(WaitPanel.class.getResource("waiting.gif"));
    comp = new GIFComponent(img);
    add(comp);
    comp.setBounds(width, height, 110, 110);
    comp.go();

    Font currentFont = comp.getFont();
    Font thisFont = new Font(currentFont.getName(), Font.BOLD, 16);

    topLabel = new javax.swing.JLabel();
    add(topLabel);
    topLabel.setBounds(width - 100, height - 70, 250, 40);
    topLabel.setText("Working on visualization .......");
    topLabel.setFont(thisFont);

    topLabel1 = new javax.swing.JLabel();
    add(topLabel1);
    topLabel1.setBounds(width - 100, height - 50, 400, 40);
    topLabel1.setText("Click on \"create model for Timeline\" tab to abort");
    topLabel1.setFont(thisFont);

    elapsedTimeLabel = new javax.swing.JLabel();
    add(elapsedTimeLabel);
    elapsedTimeLabel.setBounds(width - 50, height + 120, 260, 40);
    elapsedTimeLabel.setText("Elapsed Time  =   00 : 00");
    elapsedTimeLabel.setFont(thisFont);

    /*
     * minuteLabel = new javax.swing.JLabel(); add(minuteLabel);
     * minuteLabel.setBounds(width+75, height+120, 25, 40);
     * minuteLabel.setText("00"); minuteLabel.setFont(thisFont);
     * 
     * seperateLabel = new javax.swing.JLabel(); add(seperateLabel);
     * seperateLabel.setText(":"); seperateLabel.setBounds(width+100,
     * height+120, 10, 40); seperateLabel.setFont(thisFont);
     * 
     * secondLabel = new javax.swing.JLabel(); add(secondLabel);
     * secondLabel.setBounds(width+112, height+120, 25, 40);
     * secondLabel.setText("00"); secondLabel.setFont(thisFont);
     */
    estimateTimeLabel = new javax.swing.JLabel();
    add(estimateTimeLabel);
    estimateTimeLabel.setBounds(width - 50, height + 140, 250, 40);
    estimateTimeLabel.setText("Estimated Time = " + this.estimatedTimeStr);
    estimateTimeLabel.setFont(thisFont);

    new Thread(this).start();
}

From source file:edu.harvard.i2b2.patientMapping.ui.WaitPanel.java

public void init(int width, int height) {
    if (width <= 0 || height <= 0) {
        width = 273;/* w ww.  j a  va2s .c om*/
        height = 144;
    }

    setBackground(java.awt.Color.WHITE);
    java.awt.Image img = this.getToolkit().getImage(WaitPanel.class.getResource("waiting.gif"));
    comp = new GIFComponent(img);
    add(comp);
    comp.setBounds(width, height, 110, 110);
    comp.go();

    Font currentFont = comp.getFont();
    Font thisFont = new Font(currentFont.getName(), Font.BOLD, 16);

    topLabel = new javax.swing.JLabel();
    add(topLabel);
    topLabel.setBounds(width - 100, height - 70, 250, 40);
    topLabel.setText("Loading patient set .......");
    topLabel.setFont(thisFont);

    topLabel1 = new javax.swing.JLabel();
    add(topLabel1);
    topLabel1.setBounds(width - 100, height - 50, 400, 40);
    topLabel1.setText("Click on the \"Cancel\" button below to abort");
    topLabel1.setFont(thisFont);

    elapsedTimeLabel = new javax.swing.JLabel();
    add(elapsedTimeLabel);
    elapsedTimeLabel.setBounds(width - 50, height + 120, 260, 40);
    elapsedTimeLabel.setText("Elapsed Time  =   00 : 00");
    elapsedTimeLabel.setFont(thisFont);

    /*
     * minuteLabel = new javax.swing.JLabel(); add(minuteLabel);
     * minuteLabel.setBounds(width+75, height+120, 25, 40);
     * minuteLabel.setText("00"); minuteLabel.setFont(thisFont);
     * 
     * seperateLabel = new javax.swing.JLabel(); add(seperateLabel);
     * seperateLabel.setText(":"); seperateLabel.setBounds(width+100,
     * height+120, 10, 40); seperateLabel.setFont(thisFont);
     * 
     * secondLabel = new javax.swing.JLabel(); add(secondLabel);
     * secondLabel.setBounds(width+112, height+120, 25, 40);
     * secondLabel.setText("00"); secondLabel.setFont(thisFont);
     */
    estimateTimeLabel = new javax.swing.JLabel();
    //add(estimateTimeLabel);
    estimateTimeLabel.setBounds(width - 50, height + 140, 250, 40);
    estimateTimeLabel.setText("Estimated Time = " + this.estimatedTimeStr);
    estimateTimeLabel.setFont(thisFont);

    new Thread(this).start();
}

From source file:Chart.java

 public void paintComponent(Graphics g)
{
   Graphics2D g2 = (Graphics2D) g;

   // compute the minimum and maximum values
   if (values == null) return;
   double minValue = 0;
   double maxValue = 0;
   for (double v : values)
   {//from   www  .j  a  v a  2 s.  c  o  m
      if (minValue > v) minValue = v;
      if (maxValue < v) maxValue = v;
   }
   if (maxValue == minValue) return;

   int panelWidth = getWidth();
   int panelHeight = getHeight();

   Font titleFont = new Font("SansSerif", Font.BOLD, 20);
   Font labelFont = new Font("SansSerif", Font.PLAIN, 10);

   // compute the extent of the title
   FontRenderContext context = g2.getFontRenderContext();
   Rectangle2D titleBounds = titleFont.getStringBounds(title, context);
   double titleWidth = titleBounds.getWidth();
   double top = titleBounds.getHeight();

   // draw the title
   double y = -titleBounds.getY(); // ascent
   double x = (panelWidth - titleWidth) / 2;
   g2.setFont(titleFont);
   g2.drawString(title, (float) x, (float) y);

   // compute the extent of the bar labels
   LineMetrics labelMetrics = labelFont.getLineMetrics("", context);
   double bottom = labelMetrics.getHeight();

   y = panelHeight - labelMetrics.getDescent();
   g2.setFont(labelFont);

   // get the scale factor and width for the bars
   double scale = (panelHeight - top - bottom) / (maxValue - minValue);
   int barWidth = panelWidth / values.length;

   // draw the bars
   for (int i = 0; i < values.length; i++)
   {
      // get the coordinates of the bar rectangle
      double x1 = i * barWidth + 1;
      double y1 = top;
      double height = values[i] * scale;
      if (values[i] >= 0) y1 += (maxValue - values[i]) * scale;
      else
      {
         y1 += maxValue * scale;
         height = -height;
      }

      // fill the bar and draw the bar outline
      Rectangle2D rect = new Rectangle2D.Double(x1, y1, barWidth - 2, height);
      g2.setPaint(Color.RED);
      g2.fill(rect);
      g2.setPaint(Color.BLACK);
      g2.draw(rect);

      // draw the centered label below the bar
      Rectangle2D labelBounds = labelFont.getStringBounds(names[i], context);

      double labelWidth = labelBounds.getWidth();
      x = x1 + (barWidth - labelWidth) / 2;
      g2.drawString(names[i], (float) x, (float) y);
   }
}

From source file:no.uio.medicine.virsurveillance.charts.BoxAndWhiskerChart_AWT.java

/**
 * Creates a new demo./*  w  w  w  . j a  va 2 s  . c  o m*/
 *
 * @param applicationTitle
 * @param chartTitle
 * @param xTitle
 * @param yTitle
 * @param dataPoints
 * @param categories
 * @param seriesTitles
 */
public BoxAndWhiskerChart_AWT(String applicationTitle, String chartTitle, String xTitle, String yTitle,
        ArrayList<ArrayList<ArrayList<Float>>> dataPoints, ArrayList<ArrayList<String>> categories,
        ArrayList<String> seriesTitles) {

    super(applicationTitle);

    this.dataPoints = dataPoints;
    this.categories = categories;
    this.seriesTitles = seriesTitles;

    this.chartTitle = chartTitle;
    this.xAxisTitle = xTitle;
    this.yAxisTitle = yTitle;
    this.Title = applicationTitle;

    BoxAndWhiskerCategoryDataset dataset = (BoxAndWhiskerCategoryDataset) createDataset(this.dataPoints,
            this.categories, this.seriesTitles);

    final CategoryAxis xAxis = new CategoryAxis(this.xAxisTitle);
    final NumberAxis yAxis = new NumberAxis(this.yAxisTitle);
    yAxis.setAutoRangeIncludesZero(false);
    this.renderer = new BoxAndWhiskerRenderer();
    this.renderer.setFillBox(false);
    renderer.setToolTipGenerator(new BoxAndWhiskerToolTipGenerator());
    this.plot = new CategoryPlot(dataset, xAxis, yAxis, this.renderer);

    final JFreeChart chart = new JFreeChart(this.chartTitle, new Font("SansSerif", Font.BOLD, 14), this.plot,
            true);
    chart.setBackgroundPaint(Color.white);
    this.chartPanel = new ChartPanel(chart);
    this.chartPanel.setBackground(Color.white);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(800, 500));
    setContentPane(this.chartPanel);

    this.setDefaultCloseOperation(HIDE_ON_CLOSE);
}