Example usage for javax.swing JLabel setForeground

List of usage examples for javax.swing JLabel setForeground

Introduction

In this page you can find the example usage for javax.swing JLabel setForeground.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The foreground color of the component.")
public void setForeground(Color fg) 

Source Link

Document

Sets the foreground color of this component.

Usage

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Lays out the screen fields./*from   w w w  . j a v  a  2s  .  c  om*/
 * 
 * @param screen The screen to handle.
 * @return See above.
 */
private JPanel layoutScreenContent(ScreenData screen) {
    JPanel content = new JPanel();
    content.setBackground(UIUtilities.BACKGROUND_COLOR);
    content.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    content.setLayout(new GridBagLayout());
    JLabel l = new JLabel();
    Font font = l.getFont();
    int size = font.getSize() - 2;

    Map<JLabel, JComponent> components = new LinkedHashMap<JLabel, JComponent>();

    l = UIUtilities.setTextFont("Protocol Identifier:", Font.BOLD, size);
    JLabel value = UIUtilities.createComponent(null);
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    String v = screen.getProtocolIdentifier();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);

    l = UIUtilities.setTextFont("Protocol Description:", Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setFont(font.deriveFont(font.getStyle(), size));
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    v = screen.getProtocolDescription();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);

    l = UIUtilities.setTextFont("ReagentSet Identifier:", Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setFont(font.deriveFont(font.getStyle(), size));
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    v = screen.getReagentSetIdentifier();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);

    l = UIUtilities.setTextFont("ReagentSet Description:", Font.BOLD, size);
    value = UIUtilities.createComponent(null);
    value.setForeground(UIUtilities.DEFAULT_FONT_COLOR);
    value.setFont(font.deriveFont(font.getStyle(), size));
    v = screen.getReagentSetDescripion();
    if (v == null || v.length() == 0)
        v = NO_SET_TEXT;
    value.setText(v);
    components.put(l, value);

    layoutComponents(content, components);
    return content;
}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.PropertiesUI.java

/**
 * Returns the pixels size as a string.//from w w w .j a  v  a2s.c om
 * 
 * @param details The map to convert.
 * @param component The component displaying the information.
 * @return See above.
 */
private String formatPixelsSize(Map details, JLabel component) {
    String x = (String) details.get(EditorUtil.PIXEL_SIZE_X);
    String y = (String) details.get(EditorUtil.PIXEL_SIZE_Y);
    String z = (String) details.get(EditorUtil.PIXEL_SIZE_Z);
    Double dx = null, dy = null, dz = null;
    boolean number = true;
    NumberFormat nf = NumberFormat.getInstance();
    String units = null;
    UnitsObject o;
    try {
        dx = Double.parseDouble(x);
        o = EditorUtil.transformSize(dx);
        units = o.getUnits();
        dx = o.getValue();
    } catch (Exception e) {
        number = false;
    }
    try {
        dy = Double.parseDouble(y);
        o = EditorUtil.transformSize(dy);
        if (units == null)
            units = o.getUnits();
        dy = o.getValue();
    } catch (Exception e) {
        number = false;
    }
    try {
        dz = Double.parseDouble(z);
        o = EditorUtil.transformSize(dz);
        if (units == null)
            units = o.getUnits();
        dz = o.getValue();
    } catch (Exception e) {
        number = false;
    }

    String label = "Pixels Size (";
    String value = "";
    String tooltip = "<html><body>";
    if (dx != null && dx.doubleValue() > 0) {
        value += nf.format(dx);
        tooltip += "X: " + x + "<br>";
        label += "X";
    }
    if (dy != null && dy.doubleValue() > 0) {
        if (value.length() == 0)
            value += nf.format(dy);
        else
            value += "x" + nf.format(dy);
        ;
        tooltip += "Y: " + y + "<br>";
        label += "Y";
    }
    if (dz != null && dz.doubleValue() > 0) {
        if (value.length() == 0)
            value += nf.format(dz);
        else
            value += "x" + nf.format(dz);
        tooltip += "Z: " + z + "<br>";
        label += "Z";
    }
    label += ") ";
    if (!number) {
        component.setForeground(AnnotationUI.WARNING);
        component.setToolTipText("Values stored in the file...");
    } else {
        component.setToolTipText(tooltip);
    }
    if (value.length() == 0)
        return null;
    component.setText(value);
    if (units == null)
        units = UnitsObject.MICRONS;
    label += units;
    return label;
}

From source file:org.openmicroscopy.shoola.agents.util.EditorUtil.java

/**
 * Formats the label for a required field.
 * //www. ja v a  2  s. com
 * @param value The value to display.
 * @param required Pass <code>true</code> if the field is required,
 *                 <code>false</code> otherwise.
 * @return See above
 */
public static JComponent getLabel(String value, boolean required) {
    if (required) {
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        JLabel l = UIUtilities.setTextFont(value);
        p.add(l);
        l = UIUtilities.setTextFont(MANDATORY_SYMBOL);
        l.setForeground(UIUtilities.REQUIRED_FIELDS_COLOR);
        p.add(l);
        return p;
    }
    return UIUtilities.setTextFont(value);
}

From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java

/**
 * Builds the component displaying the parameters.
 *
 * @return See above.//from  w ww.j  a va2  s .c  o  m
 */
private JPanel buildBody() {
    JPanel p = new JPanel();
    p.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    double[] columns = { TableLayout.PREFERRED, 5, TableLayout.FILL };
    TableLayout layout = new TableLayout();
    layout.setColumn(columns);
    p.setLayout(layout);
    int row = 0;
    JComponent area = buildDescriptionPane();
    JComponent authorsPane = buildScriptDetails();
    if (area != null) {
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(area, "0," + row + ", 2, " + row);
        row++;
    }

    if (authorsPane != null) {
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(authorsPane, "0," + row + ", 2, " + row);
        row++;
    }
    layout.insertRow(row, 5);

    row++;
    Entry<String, ScriptComponent> entry;
    Iterator<Entry<String, ScriptComponent>> i = components.entrySet().iterator();
    ScriptComponent comp;
    int required = 0;
    while (i.hasNext()) {
        entry = i.next();
        comp = entry.getValue();
        layout.insertRow(row, TableLayout.PREFERRED);
        comp.buildUI();
        if (comp.isRequired())
            required++;
        p.add(comp, "0," + row + ", 2, " + row);
        row++;
        layout.insertRow(row, 2);
        row++;
    }
    if (required > 0) {
        JLabel label = new JLabel(TEXT_END);
        Font font = label.getFont();
        label.setFont(font.deriveFont(font.getStyle(), font.getSize() - 2));
        label.setForeground(UIUtilities.REQUIRED_FIELDS_COLOR);
        layout.insertRow(row, TableLayout.PREFERRED);
        p.add(UIUtilities.buildComponentPanel(label), "0," + row + ",2, " + row);
    }

    JPanel controls = new JPanel();
    controls.setLayout(new BorderLayout(0, 0));
    controls.add(new JScrollPane(p), BorderLayout.CENTER);
    controls.add(buildControlPanel(), BorderLayout.SOUTH);
    return controls;
}

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

/**
 * Returns the tool bar.//from ww  w.  j  a v a2s  . c  om
 * 
 * @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.pentaho.ui.xul.swing.tags.SwingDialog.java

private void createDialog() {

    if (getParent() instanceof XulDialog) {
        Object parentObj = ((SwingDialog) getParent()).getDialog();
        dialog = new JDialog((Dialog) parentObj);
        centerComp = (Component) parentObj;
    } else if (getParent() instanceof XulWindow) {

        Object parentObj = getParent().getManagedObject();
        dialog = new JDialog((Frame) parentObj);
        centerComp = (Component) parentObj;
    } else {// w  w  w  .  j a v a2s  .c  om

        Document doc = getDocument();
        Element rootElement = doc.getRootElement();
        XulWindow window = null;
        if (rootElement != this) { // dialog is root, no JFrame Parent
            window = (XulWindow) rootElement;
        }

        if (window != null) {
            frame = (JFrame) window.getManagedObject();
            dialog = new JDialog(frame);
            centerComp = frame;
        } else {

            final Object context = domContainer.getOuterContext();
            if (context instanceof JFrame) {
                frame = (JFrame) context;
                centerComp = (Component) context;
                dialog = new JDialog(frame);
            } else if (context instanceof JDialog) {
                dialog = new JDialog((JDialog) context);
                centerComp = (Component) context;
            } else if (context instanceof JComponent) {
                dialog = new JDialog();
                centerComp = (Component) context;
            } else {
                dialog = new JDialog();
            }
        }
    }

    dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    dialog.setResizable(getResizable());
    dialog.setLayout(new BorderLayout());

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setOpaque(true);
    int pad = (this.getPadding() > -1) ? getPadding() : 3;
    mainPanel.setBorder(BorderFactory.createEmptyBorder(pad, pad, pad, pad));

    dialog.setTitle(title);
    dialog.setModal(isModal());
    dialog.add(mainPanel, BorderLayout.CENTER);
    mainPanel.add(container, BorderLayout.CENTER);
    container.setOpaque(false);

    if (this.header != null) {

        JPanel headerPanel = new JPanel(new BorderLayout());
        headerPanel.setBackground(Color.decode("#5F86C0"));
        headerPanel.setOpaque(true);
        JPanel headerPanelInner = new JPanel(new BorderLayout());
        headerPanelInner.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
        headerPanelInner.setOpaque(false);

        headerPanel.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.decode("#8FB1E5"),
                Color.decode("#446CA9")));

        JLabel title = new JLabel(this.header.getTitle());

        title.setForeground(Color.white);
        headerPanelInner.add(title, BorderLayout.WEST);

        JLabel desc = new JLabel(this.header.getDescription());
        desc.setForeground(Color.white);
        headerPanelInner.add(desc, BorderLayout.EAST);

        headerPanel.add(headerPanelInner, BorderLayout.CENTER);

        mainPanel.add(headerPanel, BorderLayout.NORTH);
    }

    populateButtonPanel();
    mainPanel.add(buttonPanel, BorderLayout.SOUTH);
    dialog.setSize(new Dimension(getWidth(), getHeight()));
    dialog.setPreferredSize(new Dimension(getWidth(), getHeight()));
    dialog.setMinimumSize(new Dimension(getWidth(), getHeight()));

    if (this.getBgcolor() != null) {
        mainPanel.setBackground(Color.decode(this.getBgcolor()));
    }

}

From source file:org.piraso.ui.base.PreferencePanel.java

private void initPreferenceComponentsHorizontalChildLayout() {
    handlers = new ArrayList<ParentChildHandler>();
    CellConstraints c = new CellConstraints();

    int size = CollectionUtils.size(provider.getPreferences());

    int l = 0, r = 2;
    chkPreferences = new JCheckBox[size];
    preferenceKeys = new PreferenceProperty[size];

    JLabel lblHeader = new JLabel(provider.getName());
    Font of = lblHeader.getFont();
    lblHeader.setFont(of.deriveFont(Font.BOLD));

    pnlPreferences.add(lblHeader, c.xyw(2, r, 5));
    r += 2;/*  ww  w.j  a va 2s .  c  o m*/

    JButton parentToggle = null;
    JPanel childrenPanel = null;
    ParentChildHandler parentChildHandler = null;

    Iterator<? extends PreferenceProperty> itrp = provider.getPreferences().iterator();
    for (int j = 0; j < provider.getPreferences().size(); j++, l++) {
        PreferenceProperty prop = itrp.next();

        preferenceKeys[l] = prop;
        chkPreferences[l] = new JCheckBox();
        chkPreferences[l].setText(provider.getMessage(prop.getName()));
        chkPreferences[l].setSelected(prop.isDefaultValue());

        if (prop.isChild()) {
            if (childrenPanel == null) {
                childrenPanel = new JPanel();
                childrenPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1));
                childrenPanel.setOpaque(false);
                childrenPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 1));
                childrenPanel.setVisible(false);

                if (parentChildHandler != null) {
                    parentChildHandler.setChildrenPanel(childrenPanel);
                }

                pnlPreferences.add(childrenPanel, c.xy(6, r));

                r += 2;
            }

            if (parentChildHandler != null) {
                parentChildHandler.addPreference(chkPreferences[l]);
            }

            childrenPanel.add(chkPreferences[l]);
            parentToggle = null;
        } else {
            if (parentToggle != null) {
                parentChildHandler.hide();
            }

            JPanel parentPanel = new JPanel();
            parentPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 1, 1));
            parentPanel.setOpaque(false);

            parentToggle = new JButton(expandImage);

            JLabel previewLabel = new JLabel();
            previewLabel.setForeground(new Color(0, 128, 0));
            previewLabel.setFont(previewLabel.getFont().deriveFont(Font.ITALIC));

            parentChildHandler = new ParentChildHandler(parentToggle, previewLabel);
            parentChildHandler.addPreference(chkPreferences[l]);
            handlers.add(parentChildHandler);

            parentToggle.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));

            parentPanel.add(parentToggle);
            parentPanel.add(chkPreferences[l]);
            parentPanel.add(previewLabel);

            pnlPreferences.add(parentPanel, c.xyw(4, r, 3));

            childrenPanel = null;
            r += 2;
        }

        chkPreferences[l].addActionListener(new CheckBoxClickHandler(l, parentChildHandler));
    }
}

From source file:org.porphyry.view.Opener.java

protected void display(String s, Color c, String side) {
    JLabel l = new JLabel(s);
    l.setForeground(c);
    this.display(l, side);
}

From source file:org.processmining.analysis.decisionmining.DecisionAttribute.java

/**
 * Builds a panel containing a checkbox to include or exclude this
 * attribute, and a combobox in order to chose an attribute type.
 *///from  ww  w  . j av  a 2 s  .  c o m
private void buildAttributePanel() {
    myPanel = new JPanel();
    myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.LINE_AXIS));
    JLabel myNameLabel = new JLabel("Attribute name: ");
    myNameLabel.setForeground(new Color(100, 100, 100));
    myPanel.add(myNameLabel);
    myNameCheckBox = new JCheckBox(getName());
    // per default select everything
    myNameCheckBox.setSelected(true);

    // register check/uncheck action
    myNameCheckBox.addActionListener(new ActionListener() {
        // specify action when the attribute selection scope is changed
        public void actionPerformed(ActionEvent e) {
            JCheckBox cb = (JCheckBox) e.getSource();
            HLAttribute simAtt = getSimulationAttribute();
            if (cb.isSelected() == true) {
                myTypeGuiRepresenation.enable();
                // add attribute to simulation model
                // and to related activities
                createSimulationAttribute();
            } else {
                myTypeGuiRepresenation.disable();
                // remove attribute from simulation model
                // (automatically removes attribute from contained
                // activities)
                hlProcess.removeAttribute(simAtt.getID());
            }
        }
    });

    myPanel.add(myNameCheckBox);
    myPanel.add(Box.createHorizontalGlue());

    createAttributeTypeGui();
    // ArrayList<DecisionAttributeType> attributeTypes = new
    // ArrayList<DecisionAttributeType>();
    // // per default set "nominal"
    // attributeTypes.add(DecisionAttributeType.NOMINAL);
    // attributeTypes.add(DecisionAttributeType.NUMERIC);
    // myTypeGuiRepresenation = new
    // GUIPropertyListWithoutGlue("Attribute type:",
    // "Please determine the type of the attribute", attributeTypes, this);

    myPanel.add(myTypeGuiRepresenation.getPropertyPanel());
}

From source file:org.processmining.analysis.decisionmining.DecisionAttributeForAuLdg.java

/**
 * Builds a panel containing a checkbox to include or exclude this attribute,
 * and a combobox in order to chose an attribute type.
 *///from w ww  .j a  va 2  s  .  co  m
private void buildAttributePanel() {
    myPanel = new JPanel();
    myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.LINE_AXIS));
    JLabel myNameLabel = new JLabel("Attribute name: ");
    myNameLabel.setForeground(new Color(100, 100, 100));
    myPanel.add(myNameLabel);
    myNameCheckBox = new JCheckBox(getName());
    // per default select everything
    myNameCheckBox.setSelected(true);

    // register check/uncheck action
    myNameCheckBox.addActionListener(new ActionListener() {
        // specify action when the attribute selection scope is changed
        public void actionPerformed(ActionEvent e) {
            JCheckBox cb = (JCheckBox) e.getSource();
            HLAttribute simAtt = getSimulationAttribute();
            if (cb.isSelected() == true) {
                myTypeGuiRepresenation.enable();
                // add attribute to simulation model
                // and to related activities
                createSimulationAttribute();
            } else {
                myTypeGuiRepresenation.disable();
                // remove attribute from simulation model
                // (automatically removes attribute from contained activities)
                hlProcess.removeAttribute(simAtt.getID());
            }
        }
    });

    myPanel.add(myNameCheckBox);
    myPanel.add(Box.createHorizontalGlue());

    createAttributeTypeGui();
    // ArrayList<DecisionAttributeType> attributeTypes = new
    // ArrayList<DecisionAttributeType>();
    // // per default set "nominal"
    // attributeTypes.add(DecisionAttributeType.NOMINAL);
    // attributeTypes.add(DecisionAttributeType.NUMERIC);
    // myTypeGuiRepresenation = new
    // GUIPropertyListWithoutGlue("Attribute type:",
    // "Please determine the type of the attribute", attributeTypes, this);

    myPanel.add(myTypeGuiRepresenation.getPropertyPanel());
}