Example usage for javax.swing JLabel getLabelFor

List of usage examples for javax.swing JLabel getLabelFor

Introduction

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

Prototype

public Component getLabelFor() 

Source Link

Document

Get the component this is labelling.

Usage

From source file:eu.europa.ec.markt.tlmanager.view.pages.TreeDataPublisher.java

/**
 * This method handles the state of the <code>JLabel</code>'s that are associated to mandatory fields, as well as
 * any 'special' component. It is called via two tracks: Once by the implementation of the
 * <code>BindingListener</code> in <code>BindingManager</code> and once by individual action listeners for each
 * component. These action listeners are installed at the same time of the installation of the binding (cf.
 * BindingManager.setupComponent())./*w  ww  . j a v  a  2 s . c  o  m*/
 *
 * @param component the component
 * @param failure if the label should express a failure
 */
protected void changeMandatoryComponents(Component component, boolean failure) {
    if (mandatoryLabels == null) {
        return;
    }
    for (JLabel label : mandatoryLabels) {
        if (label == null || component == null || label.getLabelFor() == null) {
            continue;
        }
        if (label.getLabelFor().equals(component)) {
            boolean empty = false;
            if (component instanceof JTextField) {
                JTextField tf = (JTextField) component;
                if (tf.getText().isEmpty()) {
                    empty = true;
                }
            } else if (component instanceof JComboBox) {
                JComboBox box = (JComboBox) component;
                if (box.isEditable()) {
                    final String text = ((JTextComponent) box.getEditor().getEditorComponent()).getText();
                    if (StringUtils.isEmpty(text)
                            || StringUtils.equals(text, Util.DEFAULT_NO_SELECTION_ENTRY)) {
                        empty = true;
                    }
                } else {
                    if (box.getSelectedItem().equals(Util.DEFAULT_NO_SELECTION_ENTRY)) {
                        empty = true;
                    }
                }
            } else if (component instanceof JXDatePicker) {
                JXDatePicker picker = (JXDatePicker) component;
                Date date = picker.getDate();
                if (date == null) {
                    empty = true;
                }
            } else if (component instanceof DateTimePicker) {
                DateTimePicker picker = (DateTimePicker) component;
                Date date = picker.getDateTime();
                if (date == null) {
                    empty = true;
                }
            } else if (component instanceof MultivalueButton) {
                MultivalueButton button = (MultivalueButton) component;
                if (button.getMultivaluePanel().getMultivalueModel().isEmpty()) {
                    empty = true;
                }
            } else if (component instanceof CertificateProperty) {
                CertificateProperty certificateProperty = (CertificateProperty) component;
                empty = certificateProperty.isEmpty();
            }

            if (failure || empty) {
                label.setForeground(Configuration.MANDATORY_COLOR);
            } else {
                label.setForeground(Configuration.NORMAL_COLOR);
            }
            break;
        }
    }
}

From source file:ffx.ui.ModelingPanel.java

/**
 * This handles conditional command option input.
 *
 * @param evt ActionEvent//from   w ww.j av a 2  s.co m
 */
private void conditionalCommandEvent(ActionEvent evt) {
    Object source = evt.getSource();
    if (source instanceof JRadioButton) {
        JRadioButton jrb = (JRadioButton) source;
        String selection = jrb.getText().toLowerCase();
        for (JLabel label : conditionals) {
            JTextField jtf = (JTextField) label.getLabelFor();
            String cupon = label.getName().toLowerCase();
            if (cupon.contains(selection) && jrb.isSelected()) {
                label.setEnabled(true);
                jtf.setEnabled(true);
            } else {
                label.setEnabled(false);
                jtf.setEnabled(false);
            }
        }
    } else if (source instanceof JCheckBox) {
        JCheckBox jcb = (JCheckBox) source;
        String selection = jcb.getText().toLowerCase();
        for (JLabel label : conditionals) {
            String cupon = label.getName().toLowerCase();
            JTextField jtf = (JTextField) label.getLabelFor();
            if (cupon.contains(selection) && jcb.isSelected()) {
                label.setEnabled(true);
                jtf.setEnabled(true);
            } else {
                label.setEnabled(false);
                jtf.setEnabled(false);
            }
        }
    }
    statusLabel.setText("  " + createCommandInput());
}

From source file:windows.ValidateEntity.java

public boolean validate(AbstractForm form, String[] fieldsName, String[] excludeField) {
    List<JLabel> lista = new ArrayList<>();
    Field[] fields = ReflectionUtils.getAllFields(form.getClass());
    for (Field field : fields) {
        if (JLabel.class.isAssignableFrom(field.getType())) {
            JLabel l = ReflectionUtils.runGetter(field, form);
            l.setText(null);/*from w  w  w  .j  a va 2s. c o m*/
            l.setVisible(false);
            lista.add(l);
        }
    }
    ValidationContex fieldError = validateGeneral(fieldsName, excludeField);
    if (fieldError == null) {
        return true;
    }
    for (JLabel label : lista) {
        if (label.getLabelFor().getName().equalsIgnoreCase(fieldError.field().getName())) {
            label.setText("<html><p>" + fieldError.message().replace("\n", "<br>") + "</p></html>");
            label.setVisible(true);
        }
    }
    return false;
}