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:org.openmicroscopy.shoola.env.data.util.StatusLabel.java

/** Initializes the components.*/
private void initialize() {
    step = 0;/*from w w  w. j  a va 2  s .  co m*/
    sizeUpload = 0;
    fileSize = "";
    seriesCount = 0;
    readerType = "";
    markedAsCancel = false;
    cancellable = true;
    totalUploadedSize = 0;
    generalLabel = new JLabel(DEFAULT_TEXT);
    Font f = generalLabel.getFont();
    Font derived = f.deriveFont(f.getStyle(), f.getSize() - 2);
    uploadBar = new JProgressBar(0, MAX);
    uploadBar.setFont(derived);
    uploadBar.setStringPainted(true);
    Dimension d = uploadBar.getPreferredSize();
    uploadBar.setPreferredSize(new Dimension(WIDTH, d.height));
    processingBar = new JProgressBar(0, STEPS.size());
    processingBar.setStringPainted(true);
    processingBar.setString(DEFAULT_TEXT);
    processingBar.setFont(derived);
    uploadBar.setVisible(false);
    processingBar.setVisible(false);
}

From source file:org.openmicroscopy.shoola.env.ui.ActivityComponent.java

/**
 * Returns the tool bar./*from   w w  w .java 2s.  c  o  m*/
 * 
 * @return See above.
 */
private JComponent createToolBar() {
    toolBar = new JToolBar();
    toolBar.setOpaque(false);
    toolBar.setFloatable(false);
    toolBar.setBorder(null);
    buttonIndex = 0;
    toolBar.add(exceptionButton);
    toolBar.add(Box.createHorizontalStrut(5));
    buttonIndex = 2;
    toolBar.add(cancelButton);
    JLabel l = new JLabel();
    Font f = l.getFont();
    l.setForeground(UIUtilities.LIGHT_GREY.darker());
    l.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2));
    String s = UIUtilities.formatShortDateTime(null);
    String[] values = s.split(" ");
    if (values.length > 1) {
        String v = values[1];
        if (values.length > 2)
            v += " " + values[2];
        l.setText(v);
        toolBar.add(Box.createHorizontalStrut(5));
        toolBar.add(l);
        toolBar.add(Box.createHorizontalStrut(5));
    }
    return toolBar;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Creates a new label.//  w  w w. java  2s .  c  o m
 * 
 * @param type    The type of component to create. Default type is JLabel.
 * @param color The foreground color if not <code>null</code>.
 * @return See above.
 */
public static JComponent createComponent(Class type, Color color) {
    if (type == null)
        type = JLabel.class;
    JComponent comp = null;
    if (JLabel.class.equals(type))
        comp = new JLabel();
    else if (OMETextField.class.equals(type))
        comp = new OMETextField();
    else if (OMETextArea.class.equals(type))
        comp = new OMETextArea();
    else if (NumericalTextField.class.equals(type)) {
        comp = new NumericalTextField();
        ((NumericalTextField) comp).setHorizontalAlignment(JTextField.LEFT);
        ((NumericalTextField) comp).setNegativeAccepted(true);
        comp.setBorder(null);
    }

    if (comp == null)
        comp = new JLabel();
    comp.setBackground(BACKGROUND_COLOR);
    Font font = comp.getFont();
    comp.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2));
    if (color != null)
        comp.setForeground(color);
    return comp;
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/**
 * Creates a button looking like an hyper-link.
 * /*from  w  w w.  jav a2s .c o m*/
 * @param text The text to display
 * @return See above.
 */
public static JButton createHyperLinkButton(String text) {
    if (text == null || text.trim().length() == 0)
        text = "hyperlink";
    JButton b = new JButton(text);
    Font f = b.getFont();
    b.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2));
    b.setOpaque(false);
    b.setForeground(UIUtilities.HYPERLINK_COLOR);
    unifiedButtonLookAndFeel(b);
    return b;
}

From source file:org.tellervo.desktop.prefs.Prefs.java

/**
 * Code a font into a string/*from   ww  w.  ja v a  2 s  . c o  m*/
 * 
 * @param f
 * @return
 */
public static final String stringifyFont(Font f) {
    StringBuffer sb = new StringBuffer();

    sb.append(f.getFontName());
    sb.append('-');

    int s = sb.length();
    if ((f.getStyle() & Font.BOLD) != 0) {
        sb.append("BOLD");
    }
    if ((f.getStyle() & Font.ITALIC) != 0) {
        sb.append("ITALIC");
    }
    if (sb.length() > s) {
        sb.append('-');
    }

    sb.append(f.getSize());

    return sb.toString();
}

From source file:org.yccheok.jstock.gui.IndicatorPanel.java

private ListCellRenderer getListCellRenderer(final IndicatorProjectManager projectManager) {
    return new DefaultListCellRenderer() {
        @Override//from w w  w . j a va2  s.  c om
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Component component = super.getListCellRendererComponent(list, value, index, isSelected,
                    cellHasFocus);
            if (component != null && value != null) {
                final OperatorIndicator operatorIndicator = projectManager
                        .getOperatorIndicator(value.toString());
                if (operatorIndicator != null
                        && operatorIndicator.getType() != projectManager.getPreferredOperatorIndicatorType()) {
                    final Font oldFont = component.getFont();
                    component.setFont(oldFont.deriveFont(oldFont.getStyle() | Font.ITALIC));
                }
            }
            return component;
        }
    };
}

From source file:org.yccheok.jstock.gui.Utils.java

/**
 * Get a new bold version of specified font, with rest of specified font
 * attributes remained the same.//from w  ww  . j a v a 2 s. c  om
 * 
 * @param font specified font
 * @return a new bold version of specified font
 */
public static Font getBoldFont(Font font) {
    return font.deriveFont(font.getStyle() | Font.BOLD);
}

From source file:processing.app.EditorTab.java

public void applyPreferences() {
    textarea.setCodeFoldingEnabled(PreferencesData.getBoolean("editor.code_folding"));
    scrollPane.setFoldIndicatorEnabled(PreferencesData.getBoolean("editor.code_folding"));
    scrollPane.setLineNumbersEnabled(PreferencesData.getBoolean("editor.linenumbers"));

    // apply the setting for 'use external editor', but only if it changed
    if (external != PreferencesData.getBoolean("editor.external")) {
        external = !external;//w  w w . j  a  v  a2s  .c  o m
        if (external) {
            // disable line highlight and turn off the caret when disabling
            textarea.setBackground(Theme.getColor("editor.external.bgcolor"));
            textarea.setHighlightCurrentLine(false);
            textarea.setEditable(false);
            // Detach from the code, since we are no longer the authoritative source
            // for file contents.
            file.setStorage(null);
            // Reload, in case the file contents already changed.
            reload();
        } else {
            textarea.setBackground(Theme.getColor("editor.bgcolor"));
            textarea.setHighlightCurrentLine(Theme.getBoolean("editor.linehighlight"));
            textarea.setEditable(true);
            file.setStorage(this);
            // Reload once just before disabling external mode, to ensure we have
            // the latest contents.
            reload();
        }
    }
    // apply changes to the font size for the editor
    Font editorFont = scale(PreferencesData.getFont("editor.font"));

    // check whether a theme-defined editor font is available
    Font themeFont = Theme.getFont("editor.font");
    if (themeFont != null) {
        // Apply theme font if the editor font has *not* been changed by the user,
        // This allows themes to specify an editor font which will only be applied
        // if the user hasn't already changed their editor font via preferences.txt
        String defaultFontName = StringUtils.defaultIfEmpty(PreferencesData.getDefault("editor.font"), "")
                .split(",")[0];
        if (defaultFontName.equals(editorFont.getName())) {
            editorFont = new Font(themeFont.getName(), themeFont.getStyle(), editorFont.getSize());
        }
    }

    textarea.setFont(editorFont);
    scrollPane.getGutter().setLineNumberFont(editorFont);
}

From source file:ro.nextreports.engine.exporter.ResultExporter.java

private void buildCellFont(Map<String, Object> format, Font font) {
    format.put(StyleFormatConstants.FONT_FAMILY_KEY, font.getFamily());
    format.put(StyleFormatConstants.FONT_NAME_KEY, font.getName());
    format.put(StyleFormatConstants.FONT_SIZE, new Float(font.getSize()));
    if (Font.PLAIN == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_NORMAL);
    }//from   w ww.  j  a v a  2 s .  co m
    if (Font.BOLD == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_BOLD);
    }
    if (Font.ITALIC == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_ITALIC);
    }
    if ((Font.BOLD | Font.ITALIC) == font.getStyle()) {
        format.put(StyleFormatConstants.FONT_STYLE_KEY, StyleFormatConstants.FONT_STYLE_BOLDITALIC);
    }
}

From source file:savant.export.ExportPlugin.java

private void setupGUI(JPanel panel) {

    panel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    //create padding
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 0;/*from w w  w .j  a v  a 2s .  c o m*/
    gbc.weighty = 0;
    gbc.gridx = 0;
    gbc.gridy = 0;
    JPanel fill1 = new JPanel();
    fill1.setPreferredSize(new Dimension(10, 10));
    panel.add(fill1, gbc);

    //create path chooser
    JLabel htmlLabel = new JLabel(
            "<html>Choose folder to save files.<br>An html index file will be created here.</html>");
    gbc.gridwidth = 2;
    gbc.gridx = 1;
    gbc.gridy = 1;
    panel.add(htmlLabel, gbc);
    pf = new PathField(JFileChooser.OPEN_DIALOG, false, true);
    gbc.gridx = 1;
    gbc.gridy = 2;
    panel.add(pf, gbc);

    //create runExport button
    JButton runButton = new JButton("Run");
    runButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            exportThread = new Thread("Export Plugin") {
                @Override
                public void run() {
                    try {
                        runTool();
                    } catch (InterruptedException ex) {
                        //TODO: deal with exception?
                        LOG.error("Export interrupted.", ex);
                    }
                }
            };
            exportThread.start();

            //create progress dialog
            Object[] options = { "Cancel" };
            progressPanel = new JOptionPane("     Running Export: 1");
            progressPanel.setOptions(options);
            progressDialog = progressPanel.createDialog("Export in progress");
            progressDialog.setVisible(true);
            if (progressPanel.getValue().equals("Cancel")) {
                exportCancelled = true;
            }

        }
    });
    gbc.weightx = 0;
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gbc.gridx = 1;
    gbc.gridy = 3;
    panel.add(runButton, gbc);

    //create output label
    outputLabel = new JLabel();
    Font f = outputLabel.getFont();
    outputLabel.setFont(f.deriveFont(f.getStyle() ^ Font.BOLD));
    gbc.gridx = 2;
    gbc.gridy = 3;
    panel.add(outputLabel, gbc);

    //create padding
    JPanel fill2 = new JPanel();
    fill2.setPreferredSize(new Dimension(10, 10));
    gbc.weightx = 1.0;
    gbc.gridwidth = 1;
    gbc.gridx = 2;
    gbc.gridy = 3;
    panel.add(fill2, gbc);

    JPanel fill3 = new JPanel();
    fill3.setPreferredSize(new Dimension(10, 10));
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.gridwidth = 2;
    gbc.gridx = 0;
    gbc.gridy = 4;
    panel.add(fill3, gbc);
}