Example usage for java.awt Font ITALIC

List of usage examples for java.awt Font ITALIC

Introduction

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

Prototype

int ITALIC

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

Click Source Link

Document

The italicized style constant.

Usage

From source file:net.sf.dynamicreports.test.jasper.chart.CandlestickChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);//from w  w  w  .  j  ava 2s.c  o  m

    JFreeChart chart = getChart("summary.chart1", 0);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    Assert.assertEquals("renderer", CandlestickRenderer.class, renderer.getClass());
    Assert.assertEquals("show volume", false, ((CandlestickRenderer) renderer).getDrawVolume());
    highLowChartDataTest(chart, 0, new Object[][] { { "serie", date1, 50d, 35d, 40d, 47d, 70d },
            { "serie", date2, 55d, 40d, 50d, 45d, 120d }, { "serie", date3, 48d, 41d, 42d, 47d, 90d } });

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getXYPlot().getDomainAxis();
    Assert.assertEquals("category label", "time", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());

    chart = getChart("summary.chart3", 0);
    axis = chart.getXYPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    //Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());
}

From source file:net.sf.dynamicreports.test.jasper.chart.HighLowChartTest.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/*from w w w  .  ja  v a 2 s. c om*/

    JFreeChart chart = getChart("summary.chart1", 0);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    Assert.assertEquals("renderer", HighLowRenderer.class, renderer.getClass());
    Assert.assertEquals("show open ticks", true, ((HighLowRenderer) renderer).getDrawOpenTicks());
    Assert.assertEquals("show close ticks", true, ((HighLowRenderer) renderer).getDrawCloseTicks());
    highLowChartDataTest(chart, 0, new Object[][] { { "serie", date1, 50d, 35d, 40d, 47d, 70d },
            { "serie", date2, 55d, 40d, 50d, 45d, 120d }, { "serie", date3, 48d, 41d, 42d, 47d, 90d } });

    chart = getChart("summary.chart2", 0);
    Axis axis = chart.getXYPlot().getDomainAxis();
    Assert.assertEquals("category label", "time", axis.getLabel());
    Assert.assertEquals("category label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("category label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());

    chart = getChart("summary.chart3", 0);
    axis = chart.getXYPlot().getRangeAxis();
    Assert.assertEquals("value label", "value", axis.getLabel());
    Assert.assertEquals("value label color", Color.BLUE, axis.getLabelPaint());
    Assert.assertEquals("value label font", new Font("Arial", Font.BOLD, 10), axis.getLabelFont());
    Assert.assertEquals("tick label color", Color.CYAN, axis.getTickLabelPaint());
    Assert.assertEquals("tick label font", new Font("Arial", Font.ITALIC, 10), axis.getTickLabelFont());
    Assert.assertEquals("tick label mask", "10.00", ((NumberAxis) axis).getNumberFormatOverride().format(10));
    //Assert.assertEquals("line color", Color.LIGHT_GRAY, axis.getAxisLinePaint());
    Assert.assertEquals("range min value", 1d, ((ValueAxis) axis).getLowerBound());
    Assert.assertEquals("range max value", 15d, ((ValueAxis) axis).getUpperBound());
    Assert.assertTrue("vertical tick labels", ((ValueAxis) axis).isVerticalTickLabels());
}

From source file:com.mgmtp.perfload.perfalyzer.reportpreparation.PlotCreator.java

public JFreeChart createPlot(final AxisType xAxisType, final AxisType yAxisType,
        final RendererType rendererType, final DisplayData displayData, final DataRange dataRange,
        boolean showMarkers, final NumberDataSet... dataSets) {

    NumberAxis xAxis = createAxis(xAxisType, resourceBundle.getString(displayData.getUnitX()));

    XYPlot plot;/*w  w  w  .  j  a  va 2  s.c  om*/
    if (dataSets.length == 1) {
        NumberAxis yAxis = createAxis(yAxisType, resourceBundle.getString(displayData.getUnitY()));
        plot = new XYPlot(dataSets[0], xAxis, yAxis, rendererType.createRenderer());
    } else {
        CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(xAxis);
        for (int i = 0; i < dataSets.length; ++i) {
            NumberDataSet dataSet = dataSets[i];
            // no range for y-axis!
            NumberAxis yAxis = createAxis(yAxisType,
                    resourceBundle.getString(displayData.getUnitYList().get(i)));
            XYPlot subPlot = new XYPlot(dataSet, null, yAxis, rendererType.createRenderer());
            combinedPlot.add(subPlot);
            formatPlot(subPlot);
        }
        plot = combinedPlot;
    }

    JFreeChart chart = new JFreeChart(plot);
    CHART_THEME.apply(chart);

    formatPlot(plot);

    if (showMarkers) {
        for (Marker marker : markers) {
            IntervalMarker im = new IntervalMarker(marker.getLeftMillis() / 1000L,
                    marker.getRightMillis() / 1000L);
            im.setLabel(marker.getName());
            im.setLabelFont(new Font("Sans Serif", Font.ITALIC | Font.BOLD, 14));
            im.setLabelAnchor(RectangleAnchor.TOP);
            im.setLabelOffset(new RectangleInsets(8d, 0d, 0d, 0d));
            im.setLabelPaint(Color.BLACK);
            im.setAlpha(.2f);
            im.setPaint(Color.WHITE);
            im.setOutlinePaint(Color.BLACK);
            im.setOutlineStroke(new BasicStroke(1.0f));
            plot.addDomainMarker(im, Layer.BACKGROUND);
        }
    }

    LegendTitle legend = chart.getLegend();
    legend.setBackgroundPaint(new Color(229, 229, 229));
    legend.setFrame(
            new LineBorder(new Color(213, 213, 213), new BasicStroke(1.0f), legend.getFrame().getInsets()));

    // only for non-logarithmic axes
    // range must be set after plot is created, otherwise nothing is drawn
    if (dataRange != null && !xAxisType.equals(AxisType.LOGARITHMIC)) {
        xAxis.setRange(dataRange.getLowerSeconds(), dataRange.getUpperSeconds());
    }

    return chart;
}

From source file:edu.ku.brc.ui.skin.SkinItem.java

/**
 * Constructs the font or return null./*from w w w . j a  v a2  s .co  m*/
 * @return return the font or null
 */
public Font getFont() {
    if (font == null && StringUtils.isNotEmpty(fontName) && fontSize > 0) {
        int style = Font.PLAIN;
        if (StringUtils.isNotEmpty(fontStyle)) {
            if (fontStyle.equalsIgnoreCase("plain")) {
                style = Font.PLAIN;

            } else if (fontStyle.equalsIgnoreCase("bold")) {
                style = Font.BOLD;

            } else if (fontStyle.equalsIgnoreCase("italic")) {
                style = Font.ITALIC;

            } else if (fontStyle.equalsIgnoreCase("bolditalic")) {
                style = Font.BOLD | Font.ITALIC;
            }
        }
        font = new Font(fontName, style, fontSize);
    }
    return font;
}

From source file:org.eclipse.om2m.ipu.sample.GUI.java

/**
 * Creates the frame./*from   w  ww.ja v  a 2 s.  com*/
 */
public GUI() {
    setLocationByPlatform(true);
    setResizable(false);
    setTitle("Sample Simulated IPU");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width - 500) / 2, (screenSize.height - 570) / 2, 497, 570);

    contentPanel = new JPanel();
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPanel);
    contentPanel.setLayout(null);

    // Lamp0 Switcher0
    JPanel panel_Lamp0 = new JPanel();
    panel_Lamp0.setBounds(10, 5, 319, 260);
    contentPanel.add(panel_Lamp0);
    panel_Lamp0.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp0.setLayout(null);
    LABEL_LAMP_0.setIcon(iconLampOFF);
    LABEL_LAMP_0.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_0.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_0.setBounds(10, 9, 149, 240);
    panel_Lamp0.add(LABEL_LAMP_0);

    // Lamp0 Switch Button
    JButton button_Lamp0 = new JButton();
    button_Lamp0.setOpaque(false);
    button_Lamp0.setPressedIcon(iconButtonON);
    button_Lamp0.setIcon(iconButtonOFF);
    button_Lamp0.setBounds(187, 44, 122, 155);
    panel_Lamp0.add(button_Lamp0);
    button_Lamp0.setMinimumSize(new Dimension(30, 23));
    button_Lamp0.setMaximumSize(new Dimension(30, 23));
    button_Lamp0.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher0 = new JLabel("Switch LAMP_0");
    labelSwitcher0.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher0.setFocusCycleRoot(true);
    labelSwitcher0.setBorder(null);
    labelSwitcher0.setAutoscrolls(true);
    labelSwitcher0.setBounds(187, 199, 118, 29);
    panel_Lamp0.add(labelSwitcher0);
    // Listener for Lamp0 Switch Button
    button_Lamp0.addActionListener(new java.awt.event.ActionListener() {
        // Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp0 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp0 state
                    Switchs.switchLamp(LAMP_0, !SampleMonitor.LAMPS.get(LAMP_0).getState());
                }
            }.start();
        }
    });

    // Lamp1 Switcher 1
    JPanel panel_Lamp1 = new JPanel();
    panel_Lamp1.setBounds(10, 271, 319, 260);
    contentPanel.add(panel_Lamp1);
    panel_Lamp1.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp1.setLayout(null);

    LABEL_LAMP_1.setIcon(iconLampOFF);
    LABEL_LAMP_1.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_1.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_1.setBounds(10, 9, 154, 240);
    panel_Lamp1.add(LABEL_LAMP_1);

    // Lamp1 Switch Button
    JButton button_Lamp1 = new JButton();
    button_Lamp1.setOpaque(false);
    button_Lamp1.setPressedIcon(iconButtonON);
    button_Lamp1.setIcon(iconButtonOFF);
    button_Lamp1.setBounds(187, 44, 122, 156);
    panel_Lamp1.add(button_Lamp1);
    button_Lamp1.setMinimumSize(new Dimension(30, 23));
    button_Lamp1.setMaximumSize(new Dimension(30, 23));
    button_Lamp1.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher1 = new JLabel("Switch LAMP_1");
    labelSwitcher1.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher1.setFocusCycleRoot(true);
    labelSwitcher1.setBorder(null);
    labelSwitcher1.setAutoscrolls(true);
    labelSwitcher1.setBounds(187, 199, 118, 29);
    panel_Lamp1.add(labelSwitcher1);
    // Listener for Lamp1 Switch Button
    button_Lamp1.addActionListener(new java.awt.event.ActionListener() {
        //Switch Button clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp1 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp1 state
                    Switchs.switchLamp(LAMP_1, !SampleMonitor.LAMPS.get(LAMP_1).getState());
                }
            }.start();
        }
    });

    // Switcher All lamps
    JButton buttonAllLamp = new JButton();
    buttonAllLamp.setOpaque(false);
    buttonAllLamp.setPressedIcon(iconButtonON);
    buttonAllLamp.setIcon(iconButtonOFF);
    buttonAllLamp.setBounds(339, 190, 145, 168);
    contentPanel.add(buttonAllLamp);
    buttonAllLamp.setMinimumSize(new Dimension(30, 23));
    buttonAllLamp.setMaximumSize(new Dimension(30, 23));
    buttonAllLamp.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitchAll = new JLabel("Switch All");
    labelSwitchAll.setAutoscrolls(true);
    labelSwitchAll.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitchAll.setFocusCycleRoot(true);
    labelSwitchAll.setBorder(null);
    labelSwitchAll.setBounds(371, 369, 85, 29);
    contentPanel.add(labelSwitchAll);
    // Listener of Switch all Button
    buttonAllLamp.addActionListener(new java.awt.event.ActionListener() {
        // Switch Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change all lamps states
            new Thread() {
                public void run() {
                    // Send switch all request to create a content with the current State
                    Switchs.switchAll(!(SampleMonitor.LAMPS.get(LAMP_0).getState()
                            && SampleMonitor.LAMPS.get(LAMP_1).getState()));
                }
            }.start();
        }
    });
}

From source file:tvbrowser.ui.filter.dlgs.EditFilterDlg.java

public EditFilterDlg(JFrame parent, FilterList filterList, UserFilter filter) {

    super(parent, true);

    UiUtilities.registerForClosing(this);

    mFilterList = filterList;/*from  www  .  j av a 2 s.  co m*/
    mParent = parent;
    mFilter = filter;

    JPanel contentPane = (JPanel) getContentPane();
    contentPane.setLayout(new BorderLayout(7, 7));
    contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    if (filter == null) {
        setTitle(mLocalizer.msg("titleNew", "Create filter"));
    } else {
        setTitle(mLocalizer.msg("titleEdit", "Edit filter {0}", filter.toString()));
        mFilterName = filter.toString();
    }

    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.Y_AXIS));

    mFilterNameTF = new JTextField(new PlainDocument() {

        public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
            str = str.replaceAll("[\\p{Punct}&&[^_]]", "_");
            super.insertString(offset, str, a);
        }
    }, "", 30);

    mFilterNameTF.getDocument().addDocumentListener(this);
    JPanel panel = new JPanel(new BorderLayout(7, 7));
    panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0));
    panel.add(new JLabel(mLocalizer.msg("filterName", "Filter name:")), BorderLayout.WEST);
    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.add(mFilterNameTF, BorderLayout.WEST);
    panel.add(panel1, BorderLayout.CENTER);
    northPanel.add(panel);

    mFilterRuleTF = new JTextField();
    mFilterRuleTF.getDocument().addDocumentListener(this);
    mFilterRuleTF.addCaretListener(this);
    panel = new JPanel(new BorderLayout(7, 7));
    panel1 = new JPanel(new BorderLayout());
    panel.add(new JLabel(mLocalizer.msg("ruleString", "Filter rule:")), BorderLayout.WEST);
    JLabel exampleLb = new JLabel(
            mLocalizer.msg("ruleExample", "example: component1 or (component2 and not component3)"));
    Font f = exampleLb.getFont();
    exampleLb.setFont(new Font(f.getName(), Font.ITALIC | Font.PLAIN, f.getSize()));
    panel1.add(exampleLb, BorderLayout.WEST);
    panel.add(panel1, BorderLayout.CENTER);
    northPanel.add(panel);
    northPanel.add(mFilterRuleTF);
    mFilterRuleErrorLb = new JLabel();
    mFilterRuleErrorLb.setForeground(Color.red);
    panel = new JPanel(new BorderLayout(7, 7));
    panel.add(mFilterRuleErrorLb, BorderLayout.WEST);
    mColLb = new JLabel("0");
    panel.add(mColLb, BorderLayout.EAST);
    northPanel.add(panel);

    JPanel filterComponentsPanel = new JPanel(new BorderLayout(7, 7));
    filterComponentsPanel.add(DefaultComponentFactory.getInstance().createSeparator(
            mLocalizer.msg("componentsTitle", "Available filter components:")), BorderLayout.NORTH);
    JPanel btnPanel = new JPanel(new BorderLayout());
    panel1 = new JPanel(new GridLayout(0, 1, 0, 7));

    mNewBtn = new JButton(mLocalizer.msg("newButton", "new"));
    mEditBtn = new JButton(Localizer.getLocalization(Localizer.I18N_EDIT));
    mRemoveBtn = new JButton(Localizer.getLocalization(Localizer.I18N_DELETE));

    mNewBtn.addActionListener(this);
    mEditBtn.addActionListener(this);
    mRemoveBtn.addActionListener(this);

    panel1.add(mNewBtn);
    panel1.add(mEditBtn);
    panel1.add(mRemoveBtn);

    btnPanel.add(panel1, BorderLayout.NORTH);

    mComponentTableModel = new FilterTableModel();

    mRuleTableBox = new JTable(mComponentTableModel);
    mRuleTableBox.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            updateBtns();
        }
    });

    mRuleTableBox.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() >= 2) {
                int row = mRuleTableBox.rowAtPoint(e.getPoint());

                if (mRuleTableBox.getSelectedRow() == row && mEditBtn.isEnabled()) {
                    actionPerformed(new ActionEvent(mEditBtn, ActionEvent.ACTION_PERFORMED,
                            mEditBtn.getActionCommand()));
                }
            }
        }
    });

    mRuleTableBox.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    mRuleTableBox.setShowGrid(false);
    mRuleTableBox.setShowVerticalLines(true);
    mRuleTableBox.getColumnModel().getColumn(0).setPreferredWidth(125);
    mRuleTableBox.getColumnModel().getColumn(1).setPreferredWidth(320);
    //    mRuleTableBox.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    // Dispatchs the KeyEvent to the RootPane for Closing the Dialog.
    // Needed for Java 1.4.
    mRuleTableBox.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                mRuleTableBox.getRootPane().dispatchEvent(e);
            }
        }
    });

    JPanel ruleListBoxPanel = new JPanel(new BorderLayout());
    ruleListBoxPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 7, 0));
    ruleListBoxPanel.add(new JScrollPane(mRuleTableBox), BorderLayout.CENTER);

    filterComponentsPanel.add(btnPanel, BorderLayout.EAST);
    filterComponentsPanel.add(ruleListBoxPanel, BorderLayout.CENTER);

    ButtonBarBuilder2 bottomBar = Utilities.createFilterButtonBar();

    mOkBtn = new JButton(Localizer.getLocalization(Localizer.I18N_OK));
    mOkBtn.addActionListener(this);
    getRootPane().setDefaultButton(mOkBtn);

    mCancelBtn = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL));
    mCancelBtn.addActionListener(this);

    bottomBar.addButton(new JButton[] { mOkBtn, mCancelBtn });

    contentPane.add(northPanel, BorderLayout.NORTH);
    contentPane.add(filterComponentsPanel, BorderLayout.CENTER);
    contentPane.add(bottomBar.getPanel(), BorderLayout.SOUTH);

    if (mFilter != null) {
        mFilterNameTF.setText(mFilter.toString());
        mFilterRuleTF.setText(mFilter.getRule());
    }

    FilterComponent[] fc = FilterComponentList.getInstance().getAvailableFilterComponents();

    Arrays.sort(fc, new FilterComponent.NameComparator());

    for (FilterComponent element : fc) {
        mComponentTableModel.addElement(element);
    }

    updateBtns();

    Settings.layoutWindow("editFilterDlg", this, new Dimension(600, 300));
    setVisible(true);
}

From source file:HardcopyWriter.java

/**
 * The constructor for this class has a bunch of arguments: The frame argument
 * is required for all printing in Java. The jobname appears left justified at
 * the top of each printed page. The font size is specified in points, as
 * on-screen font sizes are. The margins are specified in inches (or fractions
 * of inches).//www. j a  v  a2s. c o m
 */
public HardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin,
        double topmargin, double bottommargin) throws HardcopyWriter.PrintCanceledException {
    // Get the PrintJob object with which we'll do all the printing.
    // The call is synchronized on the static printprops object, which
    // means that only one print dialog can be popped up at a time.
    // If the user clicks Cancel in the print dialog, throw an exception.
    Toolkit toolkit = frame.getToolkit(); // get Toolkit from Frame
    synchronized (printprops) {
        job = toolkit.getPrintJob(frame, jobname, printprops);
    }
    if (job == null)
        throw new PrintCanceledException("User cancelled print request");

    pagesize = job.getPageDimension(); // query the page size
    pagedpi = job.getPageResolution(); // query the page resolution

    // Bug Workaround:
    // On windows, getPageDimension() and getPageResolution don't work, so
    // we've got to fake them.
    if (System.getProperty("os.name").regionMatches(true, 0, "windows", 0, 7)) {
        // Use screen dpi, which is what the PrintJob tries to emulate
        pagedpi = toolkit.getScreenResolution();
        // Assume a 8.5" x 11" page size. A4 paper users must change this.
        pagesize = new Dimension((int) (8.5 * pagedpi), 11 * pagedpi);
        // We also have to adjust the fontsize. It is specified in points,
        // (1 point = 1/72 of an inch) but Windows measures it in pixels.
        fontsize = fontsize * pagedpi / 72;
    }

    // Compute coordinates of the upper-left corner of the page.
    // I.e. the coordinates of (leftmargin, topmargin). Also compute
    // the width and height inside of the margins.
    x0 = (int) (leftmargin * pagedpi);
    y0 = (int) (topmargin * pagedpi);
    width = pagesize.width - (int) ((leftmargin + rightmargin) * pagedpi);
    height = pagesize.height - (int) ((topmargin + bottommargin) * pagedpi);

    // Get body font and font size
    font = new Font("Monospaced", Font.PLAIN, fontsize);
    metrics = frame.getFontMetrics(font);
    lineheight = metrics.getHeight();
    lineascent = metrics.getAscent();
    charwidth = metrics.charWidth('0'); // Assumes a monospaced font!

    // Now compute columns and lines will fit inside the margins
    chars_per_line = width / charwidth;
    lines_per_page = height / lineheight;

    // Get header font information
    // And compute baseline of page header: 1/8" above the top margin
    headerfont = new Font("SansSerif", Font.ITALIC, fontsize);
    headermetrics = frame.getFontMetrics(headerfont);
    headery = y0 - (int) (0.125 * pagedpi) - headermetrics.getHeight() + headermetrics.getAscent();

    // Compute the date/time string to display in the page header
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
    df.setTimeZone(TimeZone.getDefault());
    time = df.format(new Date());

    this.jobname = jobname; // save name
    this.fontsize = fontsize; // save font size
}

From source file:TextSamplerDemo.java

public TextSamplerDemo() {
    setLayout(new BorderLayout());

    //Create a regular text field.
    JTextField textField = new JTextField(10);
    textField.setActionCommand(textFieldString);
    textField.addActionListener(this);

    //Create a password field.
    JPasswordField passwordField = new JPasswordField(10);
    passwordField.setActionCommand(passwordFieldString);
    passwordField.addActionListener(this);

    //Create a formatted text field.
    JFormattedTextField ftf = new JFormattedTextField(java.util.Calendar.getInstance().getTime());
    ftf.setActionCommand(textFieldString);
    ftf.addActionListener(this);

    //Create some labels for the fields.
    JLabel textFieldLabel = new JLabel(textFieldString + ": ");
    textFieldLabel.setLabelFor(textField);
    JLabel passwordFieldLabel = new JLabel(passwordFieldString + ": ");
    passwordFieldLabel.setLabelFor(passwordField);
    JLabel ftfLabel = new JLabel(ftfString + ": ");
    ftfLabel.setLabelFor(ftf);/* w w  w  .j ava 2 s  . co m*/

    //Create a label to put messages during an action event.
    actionLabel = new JLabel("Type text and then Enter in a field.");
    actionLabel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));

    //Lay out the text controls and the labels.
    JPanel textControlsPane = new JPanel();
    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    textControlsPane.setLayout(gridbag);

    JLabel[] labels = { textFieldLabel, passwordFieldLabel, ftfLabel };
    JTextField[] textFields = { textField, passwordField, ftf };
    addLabelTextRows(labels, textFields, gridbag, textControlsPane);

    c.gridwidth = GridBagConstraints.REMAINDER; //last
    c.anchor = GridBagConstraints.WEST;
    c.weightx = 1.0;
    textControlsPane.add(actionLabel, c);
    textControlsPane.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Text Fields"), BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Create a text area.
    JTextArea textArea = new JTextArea("This is an editable JTextArea. "
            + "A text area is a \"plain\" text component, " + "which means that although it can display text "
            + "in any font, all of the text is in the same font.");
    textArea.setFont(new Font("Serif", Font.ITALIC, 16));
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    JScrollPane areaScrollPane = new JScrollPane(textArea);
    areaScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    areaScrollPane.setPreferredSize(new Dimension(250, 250));
    areaScrollPane.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Plain Text"),
                    BorderFactory.createEmptyBorder(5, 5, 5, 5)),
            areaScrollPane.getBorder()));

    //Create an editor pane.
    JEditorPane editorPane = createEditorPane();
    JScrollPane editorScrollPane = new JScrollPane(editorPane);
    editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    editorScrollPane.setPreferredSize(new Dimension(250, 145));
    editorScrollPane.setMinimumSize(new Dimension(10, 10));

    //Create a text pane.
    JTextPane textPane = createTextPane();
    JScrollPane paneScrollPane = new JScrollPane(textPane);
    paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    paneScrollPane.setPreferredSize(new Dimension(250, 155));
    paneScrollPane.setMinimumSize(new Dimension(10, 10));

    //Put the editor pane and the text pane in a split pane.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, editorScrollPane, paneScrollPane);
    splitPane.setOneTouchExpandable(true);
    splitPane.setResizeWeight(0.5);
    JPanel rightPane = new JPanel(new GridLayout(1, 0));
    rightPane.add(splitPane);
    rightPane.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("Styled Text"),
            BorderFactory.createEmptyBorder(5, 5, 5, 5)));

    //Put everything together.
    JPanel leftPane = new JPanel(new BorderLayout());
    leftPane.add(textControlsPane, BorderLayout.PAGE_START);
    leftPane.add(areaScrollPane, BorderLayout.CENTER);

    add(leftPane, BorderLayout.LINE_START);
    add(rightPane, BorderLayout.LINE_END);
}

From source file:ExposedFloat.java

public void init() {

    Panel buttonPanel = new PanelWithInsets(0, 0, 0, 0);
    buttonPanel.setLayout(new GridLayout(6, 2, 5, 5));
    buttonPanel.add(maximumButton);//from w ww .  ja v  a 2  s . c o  m
    buttonPanel.add(minimumButton);
    buttonPanel.add(positiveInfinityButton);
    buttonPanel.add(negativeInfinityButton);
    buttonPanel.add(piButton);
    buttonPanel.add(notANumberButton);
    buttonPanel.add(new Button(multByZeroButtonString));
    buttonPanel.add(new Button(changeSignButtonString));
    buttonPanel.add(new Button(doubleButtonString));
    buttonPanel.add(new Button(halveButtonString));
    buttonPanel.add(new RepeaterButton(incrementButtonString));
    buttonPanel.add(new RepeaterButton(decrementButtonString));

    binaryField = new Label("00000000000000000000000000000000");
    signField = new Label("0");
    exponentField = new Label("00000000");
    mantissaField = new Label("000000000000000000000000");
    hexField = new Label("00000000");
    base2Field = new Label("0");
    base10Field = new Label("0");

    Font fieldFont = new Font("TimesRoman", Font.PLAIN, 12);
    binaryField.setFont(fieldFont);
    signField.setFont(fieldFont);
    exponentField.setFont(fieldFont);
    mantissaField.setFont(fieldFont);
    hexField.setFont(fieldFont);
    base2Field.setFont(fieldFont);
    base10Field.setFont(fieldFont);

    Panel numberPanel = new Panel();
    numberPanel.setBackground(Color.white);
    numberPanel.setLayout(new GridLayout(7, 1));
    numberPanel.add(signField);
    numberPanel.add(exponentField);
    numberPanel.add(mantissaField);
    Panel binaryPanel = new Panel();
    binaryPanel.setLayout(new BorderLayout());
    binaryPanel.add("Center", binaryField);
    numberPanel.add(binaryPanel);

    Panel hexPanel = new Panel();
    hexPanel.setLayout(new BorderLayout());
    hexPanel.add("Center", hexField);
    numberPanel.add(hexPanel);
    numberPanel.add(base2Field);
    numberPanel.add(base10Field);

    Panel labelPanel = new Panel();
    labelPanel.setBackground(Color.white);
    labelPanel.setLayout(new GridLayout(7, 1));
    Font labelFont = new Font("Helvetica", Font.ITALIC, 11);
    Label label = new Label(signString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(exponentString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(mantissaString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(binaryString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(hexString, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(base2String, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);
    label = new Label(base10String, Label.CENTER);
    label.setFont(labelFont);
    labelPanel.add(label);

    Panel dataPanel = new Panel();
    dataPanel.setLayout(new BorderLayout());
    dataPanel.add("West", labelPanel);
    dataPanel.add("Center", numberPanel);

    ColoredLabel title = new ColoredLabel(titleString, Label.CENTER, Color.cyan);
    title.setFont(new Font("Helvetica", Font.BOLD, 12));

    setBackground(Color.green);
    setLayout(new BorderLayout(5, 5));
    add("North", title);
    add("West", buttonPanel);
    add("Center", dataPanel);
}

From source file:edu.ucla.stat.SOCR.chart.demo.BarChartDemo7.java

/**
 * Creates a sample chart.//  www.java  2 s . com
 * 
 * @param dataset  the dataset.
 * 
 * @return The chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            !legendPanelOn, // include legend
            true, // tooltips?
            false // URLs?
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    IntervalMarker target = new IntervalMarker(4.5, 7.5);
    target.setLabel("Target Range");
    target.setLabelFont(new Font("SansSerif", Font.ITALIC, 11));
    target.setLabelAnchor(RectangleAnchor.LEFT);
    target.setLabelTextAnchor(TextAnchor.CENTER_LEFT);
    target.setPaint(new Color(222, 222, 255, 128));
    plot.addRangeMarker(target, Layer.BACKGROUND);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);
    renderer.setItemMargin(0.10);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray);
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray);
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray);
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);
    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    renderer.setBaseItemLabelGenerator(new CustomCategoryItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(true);
    ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.INSIDE12, TextAnchor.CENTER_RIGHT,
            TextAnchor.CENTER_RIGHT, -Math.PI / 2.0);
    renderer.setBasePositiveItemLabelPosition(p);

    ItemLabelPosition p2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT,
            TextAnchor.CENTER_LEFT, -Math.PI / 2.0);
    renderer.setPositiveItemLabelPositionFallback(p2);
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
    // OPTIONAL CUSTOMISATION COMPLETED.
    setCategorySummary(dataset);
    return chart;

}