Example usage for java.awt Font getStyle

List of usage examples for java.awt Font getStyle

Introduction

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

Prototype

public int getStyle() 

Source Link

Document

Returns the style of this Font .

Usage

From source file:FontChooser.java

public boolean doesFontMatch(Font font) {
    if (font == null) {
        return false;
    }//  w  ww.  j a  va  2s  .com
    return font.getFamily().equals(_familyName) && font.getSize() == getSize()
            && font.getStyle() == generateStyle();
}

From source file:com.rapidminer.gui.new_plotter.gui.GlobalConfigurationPanel.java

@Override
protected void adaptGUI() {

    // init title textfield
    String title = getPlotConfiguration().getTitleText();
    if (title == null) {
        title = "";
    }//  www .j av  a  2s  .c  o m
    if (!title.equals(titleTextField.getText())) {
        titleTextField.setText(title);
    }

    // init title font button
    Font titleFont = getPlotConfiguration().getTitleFont();
    if (titleFont != null) {
        titleTextField.setFont(new Font(titleFont.getFamily(), titleFont.getStyle(), fontSize));
    }

    plotOrientationChanged(getPlotConfiguration().getOrientation());

    // init plot background color label
    Color backgroundColor = getPlotConfiguration().getPlotBackgroundColor();
    if (backgroundColor == null) {
        backgroundColor = Color.white;
    }
    // plotBackgroundColorChooserButton.setIcon(createColoredRectangleIcon(backgroundColor));

    // init chart background color label
    Color chartBackgroundColor = getPlotConfiguration().getChartBackgroundColor();
    if (chartBackgroundColor == null) {
        chartBackgroundColor = Color.white;
    }
    // frameBackgroundColorChooserButton.setIcon(createColoredRectangleIcon(chartBackgroundColor));

    // init colors schemes comobox
    Map<String, ColorScheme> colorSchemes = getPlotConfiguration().getColorSchemes();
    colorsSchemesComboBoxModel.removeAllElements();
    for (ColorScheme scheme : colorSchemes.values()) {
        colorsSchemesComboBoxModel.addElement(scheme);
    }
    colorsSchemesComboBoxModel.setSelectedItem(getPlotConfiguration().getActiveColorScheme());

}

From source file:com.itemanalysis.jmetrik.gui.JmetrikPreferencesManager.java

public void setFont(Font f) {
    p.put(OUTPUT_FONT, f.getFontName());
    p.putInt(OUTPUT_FONT_STYLE, f.getStyle());
    p.putInt(OUTPUT_FONT_SIZE, f.getSize());
}

From source file:FontChooser.java

public void setCurrentFont(Font font) {
    if (font == null) {
        font = jSample.getFont();/*from w  w  w .  j  ava  2s  .  com*/
    }

    jFont.setText(font.getName());
    jFontActionPerformed(null);

    jStyle.setText(styleToString(font.getStyle()));
    jStyleActionPerformed(null);

    jSize.setText(Integer.toString(font.getSize()));
    jSizeActionPerformed(null);
}

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

private String convertFontToString(final Font font) {
    if (font == null) {
        return null;
    }//from   w  w w.  j a v a  2s.  co m

    final String fontName = font.getFamily();
    final int fontSize = font.getSize();
    final int fontStyle = font.getStyle();
    final String fontStyleText;
    if ((fontStyle & (Font.BOLD | Font.ITALIC)) == (Font.BOLD | Font.ITALIC)) {
        fontStyleText = "BOLDITALIC";
    } else if ((fontStyle & Font.BOLD) == Font.BOLD) {
        fontStyleText = "BOLD";
    } else if ((fontStyle & Font.ITALIC) == Font.ITALIC) {
        fontStyleText = "ITALIC";
    } else {
        fontStyleText = "PLAIN";
    }
    return (fontName + "-" + fontStyleText + "-" + fontSize);
}

From source file:com.tascape.qa.th.android.driver.App.java

/**
 * The method starts a GUI to let an user inspect element tree and take screenshot when the user is interacting
 * with the app-under-test manually. Please make sure to set timeout long enough for manual interaction.
 *
 * @param timeoutMinutes timeout in minutes to fail the manual steps
 *
 * @throws Exception if case of error//from w ww  .  j ava  2 s  .  c om
 */
public void interactManually(int timeoutMinutes) throws Exception {
    LOG.info("Start manual UI interaction");
    long end = System.currentTimeMillis() + timeoutMinutes * 60000L;

    AtomicBoolean visible = new AtomicBoolean(true);
    AtomicBoolean pass = new AtomicBoolean(false);
    String tName = Thread.currentThread().getName() + "m";
    SwingUtilities.invokeLater(() -> {
        JDialog jd = new JDialog((JFrame) null, "Manual Device UI Interaction - " + device.getProductDetail());
        jd.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);

        JPanel jpContent = new JPanel(new BorderLayout());
        jd.setContentPane(jpContent);
        jpContent.setPreferredSize(new Dimension(1088, 828));
        jpContent.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        JPanel jpInfo = new JPanel();
        jpContent.add(jpInfo, BorderLayout.PAGE_START);
        jpInfo.setLayout(new BorderLayout());
        {
            JButton jb = new JButton("PASS");
            jb.setForeground(Color.green.darker());
            jb.setFont(jb.getFont().deriveFont(Font.BOLD));
            jpInfo.add(jb, BorderLayout.LINE_START);
            jb.addActionListener(event -> {
                pass.set(true);
                jd.dispose();
                visible.set(false);
            });
        }
        {
            JButton jb = new JButton("FAIL");
            jb.setForeground(Color.red);
            jb.setFont(jb.getFont().deriveFont(Font.BOLD));
            jpInfo.add(jb, BorderLayout.LINE_END);
            jb.addActionListener(event -> {
                pass.set(false);
                jd.dispose();
                visible.set(false);
            });
        }

        JLabel jlTimeout = new JLabel("xxx seconds left", SwingConstants.CENTER);
        jpInfo.add(jlTimeout, BorderLayout.CENTER);
        jpInfo.add(jlTimeout, BorderLayout.CENTER);
        new SwingWorker<Long, Long>() {
            @Override
            protected Long doInBackground() throws Exception {
                while (System.currentTimeMillis() < end) {
                    Thread.sleep(1000);
                    long left = (end - System.currentTimeMillis()) / 1000;
                    this.publish(left);
                }
                return 0L;
            }

            @Override
            protected void process(List<Long> chunks) {
                Long l = chunks.get(chunks.size() - 1);
                jlTimeout.setText(l + " seconds left");
                if (l < 850) {
                    jlTimeout.setForeground(Color.red);
                }
            }
        }.execute();

        JPanel jpResponse = new JPanel(new BorderLayout());
        JPanel jpProgress = new JPanel(new BorderLayout());
        jpResponse.add(jpProgress, BorderLayout.PAGE_START);

        JTextArea jtaJson = new JTextArea();
        jtaJson.setEditable(false);
        jtaJson.setTabSize(4);
        Font font = jtaJson.getFont();
        jtaJson.setFont(new Font("Courier New", font.getStyle(), font.getSize()));

        JTree jtView = new JTree();

        JTabbedPane jtp = new JTabbedPane();
        jtp.add("tree", new JScrollPane(jtView));
        jtp.add("json", new JScrollPane(jtaJson));

        jpResponse.add(jtp, BorderLayout.CENTER);

        JPanel jpScreen = new JPanel();
        jpScreen.setMinimumSize(new Dimension(200, 200));
        jpScreen.setLayout(new BoxLayout(jpScreen, BoxLayout.PAGE_AXIS));
        JScrollPane jsp1 = new JScrollPane(jpScreen);
        jpResponse.add(jsp1, BorderLayout.LINE_START);

        JPanel jpJs = new JPanel(new BorderLayout());
        JTextArea jtaJs = new JTextArea();
        jpJs.add(new JScrollPane(jtaJs), BorderLayout.CENTER);

        JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jpResponse, jpJs);
        jSplitPane.setResizeWeight(0.88);
        jpContent.add(jSplitPane, BorderLayout.CENTER);

        JPanel jpLog = new JPanel();
        jpLog.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
        jpLog.setLayout(new BoxLayout(jpLog, BoxLayout.LINE_AXIS));

        JCheckBox jcbTap = new JCheckBox("Enable Click", null, false);
        jpLog.add(jcbTap);
        jpLog.add(Box.createHorizontalStrut(8));

        JButton jbLogUi = new JButton("Log Screen");
        jpResponse.add(jpLog, BorderLayout.PAGE_END);
        {
            jpLog.add(jbLogUi);
            jbLogUi.addActionListener((ActionEvent event) -> {
                jtaJson.setText("waiting for screenshot...");
                Thread t = new Thread(tName) {
                    @Override
                    public void run() {
                        LOG.debug("\n\n");
                        try {
                            WindowHierarchy wh = device.loadWindowHierarchy();
                            jtView.setModel(getModel(wh));

                            jtaJson.setText("");
                            jtaJson.append(wh.root.toJson().toString(2));
                            jtaJson.append("\n");

                            File png = device.takeDeviceScreenshot();
                            BufferedImage image = ImageIO.read(png);

                            int w = device.getDisplayWidth();
                            int h = device.getDisplayHeight();

                            BufferedImage resizedImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                            Graphics2D g2 = resizedImg.createGraphics();
                            g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                    RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                            g2.drawImage(image, 0, 0, w, h, null);
                            g2.dispose();

                            JLabel jLabel = new JLabel(new ImageIcon(resizedImg));
                            jpScreen.removeAll();
                            jsp1.setPreferredSize(new Dimension(w + 30, h));
                            jpScreen.add(jLabel);

                            jLabel.addMouseListener(new MouseAdapter() {
                                @Override
                                public void mouseClicked(MouseEvent e) {
                                    LOG.debug("clicked at {},{}", e.getPoint().getX(), e.getPoint().getY());
                                    if (jcbTap.isSelected()) {
                                        device.click(e.getPoint().x, e.getPoint().y);
                                        device.waitForIdle();
                                        jbLogUi.doClick();
                                    }
                                }
                            });
                        } catch (Exception ex) {
                            LOG.error("Cannot log screen", ex);
                            jtaJson.append("Cannot log screen");
                        }
                        jtaJson.append("\n\n\n");
                        LOG.debug("\n\n");

                        jd.setSize(jd.getBounds().width + 1, jd.getBounds().height + 1);
                        jd.setSize(jd.getBounds().width - 1, jd.getBounds().height - 1);
                    }
                };
                t.start();
            });
        }
        jpLog.add(Box.createHorizontalStrut(38));
        {
            JButton jbLogMsg = new JButton("Log Message");
            jpLog.add(jbLogMsg);
            JTextField jtMsg = new JTextField(10);
            jpLog.add(jtMsg);
            jtMsg.addFocusListener(new FocusListener() {
                @Override
                public void focusLost(final FocusEvent pE) {
                }

                @Override
                public void focusGained(final FocusEvent pE) {
                    jtMsg.selectAll();
                }
            });
            jtMsg.addKeyListener(new KeyAdapter() {
                @Override
                public void keyPressed(java.awt.event.KeyEvent e) {
                    if (e.getKeyCode() == java.awt.event.KeyEvent.VK_ENTER) {
                        jbLogMsg.doClick();
                    }
                }
            });
            jbLogMsg.addActionListener(event -> {
                Thread t = new Thread(tName) {
                    @Override
                    public void run() {
                        String msg = jtMsg.getText();
                        if (StringUtils.isNotBlank(msg)) {
                            LOG.info("{}", msg);
                            jtMsg.selectAll();
                        }
                    }
                };
                t.start();
                try {
                    t.join();
                } catch (InterruptedException ex) {
                    LOG.error("Cannot take screenshot", ex);
                }
                jtMsg.requestFocus();
            });
        }
        jpLog.add(Box.createHorizontalStrut(38));
        {
            JButton jbClear = new JButton("Clear");
            jpLog.add(jbClear);
            jbClear.addActionListener(event -> {
                jtaJson.setText("");
            });
        }

        JPanel jpAction = new JPanel();
        jpContent.add(jpAction, BorderLayout.PAGE_END);
        jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS));
        jpJs.add(jpAction, BorderLayout.PAGE_END);

        jd.pack();
        jd.setVisible(true);
        jd.setLocationRelativeTo(null);

        jbLogUi.doClick();
    });

    while (visible.get()) {
        if (System.currentTimeMillis() > end) {
            LOG.error("Manual UI interaction timeout");
            break;
        }
        Thread.sleep(500);
    }

    if (pass.get()) {
        LOG.info("Manual UI Interaction returns PASS");
    } else {
        Assert.fail("Manual UI Interaction returns FAIL");
    }
}

From source file:ca.sqlpower.architect.swingui.TestPlayPen.java

/**
 * Returns a new value that is not equal to oldVal. The
 * returned object will be a new instance compatible with oldVal.  
 * /*from  www  .j av a 2s . c  o m*/
 * @param property The property that should be modified.
 * @param oldVal The existing value of the property to modify.  The returned value
 * will not equal this one at the time this method was first called.
 */
private Object getNewDifferentValue(PropertyDescriptor property, Object oldVal) {
    Object newVal; // don't init here so compiler can warn if the
    // following code doesn't always give it a value
    if (property.getPropertyType() == String.class) {
        newVal = "new " + oldVal;
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        if (oldVal == null) {
            newVal = new Boolean(false);
        } else {
            newVal = new Boolean(!((Boolean) oldVal).booleanValue());
        }
    } else if (property.getPropertyType() == Double.class || property.getPropertyType() == Double.TYPE) {
        if (oldVal == null) {
            newVal = new Double(0);
        } else {
            newVal = new Double(((Double) oldVal).doubleValue() + 1);
        }
    } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) {
        if (oldVal == null) {
            newVal = new Integer(0);
        } else {
            newVal = new Integer(((Integer) oldVal).intValue() + 1);
        }
    } else if (property.getPropertyType() == Color.class) {
        if (oldVal == null) {
            newVal = new Color(0xFAC157);
        } else {
            Color oldColor = (Color) oldVal;
            newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000);
        }
    } else if (property.getPropertyType() == Font.class) {
        if (oldVal == null) {
            newVal = FontManager.getDefaultPhysicalFont();
        } else {
            Font oldFont = (Font) oldVal;
            newVal = new Font(oldFont.getFontName(), oldFont.getSize() + 2, oldFont.getStyle());
        }
    } else if (property.getPropertyType() == Set.class) {
        newVal = new HashSet();
        ((Set) newVal).add("test");
    } else if (property.getPropertyType() == List.class) {
        newVal = new ArrayList();
        ((List) newVal).add("test");
    } else if (property.getPropertyType() == Point.class) {
        newVal = new Point(1, 3);
    } else {
        throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                + property.getPropertyType().getName() + ") in getNewDifferentValue()");
    }

    return newVal;
}

From source file:net.mariottini.swing.JFontChooser.java

/**
 * Sets the currently selected font. The dialog will try to change the listboxes selections
 * according to the font set./*w ww  .j  a  v a  2  s  .c  om*/
 * 
 * @param font
 *          the font to select.
 */
public void setSelectedFont(Font font) {
    fontList.setSelectedValue(font.getFamily(), true);
    styleList.setSelectedIndex(font.getStyle());
    int size = font.getSize();
    int index = Arrays.binarySearch(SIZES, new Integer(size));
    if (index >= 0) {
        sizeList.setSelectedIndex(index);
        sizeList.ensureIndexIsVisible(index);
    } else {
        sizeText.setText(String.valueOf(size));
    }
}

From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java

private void fontSizeIncreaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontSizeIncreaseButtonActionPerformed
    MyTreeNodeRenderer renderer = (MyTreeNodeRenderer) projectTree.getCellRenderer();
    Font oldFont = renderer.getFont();
    Font font = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize() + 1);
    renderer.setFont(font);//  w  w  w  . j a va  2  s  .  c  om
    projectTree.updateUI();
    NbPreferences.forModule(this.getClass()).putInt("font", font.getSize());
}

From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java

private void fontSizeDecreaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fontSizeDecreaseButtonActionPerformed
    MyTreeNodeRenderer renderer = (MyTreeNodeRenderer) projectTree.getCellRenderer();
    Font oldFont = renderer.getFont();
    Font font = new Font(oldFont.getFontName(), oldFont.getStyle(), oldFont.getSize() - 1);
    renderer.setFont(font);//from  www.j a v  a 2s  .  com
    projectTree.updateUI();
    NbPreferences.forModule(this.getClass()).putInt("font", font.getSize());
}