Search in sources :

Example 76 with JComponent

use of javax.swing.JComponent in project bndtools by bndtools.

the class GitCredentialsProvider method updateCredentialItems.

private static void updateCredentialItems(JComponent[] components) {
    for (JComponent component : components) {
        CredentialItem item = (CredentialItem) component.getClientProperty(CRED_ITEM);
        if (item == null) {
            continue;
        }
        if (item instanceof CredentialItem.Username) {
            JTextField field = (JTextField) component;
            ((CredentialItem.Username) item).setValue(field.getText());
            continue;
        }
        if (item instanceof CredentialItem.Password) {
            JPasswordField field = (JPasswordField) component;
            ((CredentialItem.Password) item).setValue(field.getPassword());
            continue;
        }
        if (item instanceof CredentialItem.StringType) {
            if (item.isValueSecure()) {
                JPasswordField field = (JPasswordField) component;
                ((CredentialItem.StringType) item).setValue(new String(field.getPassword()));
                continue;
            }
            JTextField field = (JTextField) component;
            ((CredentialItem.Username) item).setValue(field.getText());
            continue;
        }
        if (item instanceof CredentialItem.YesNoType) {
            JCheckBox field = (JCheckBox) component;
            ((CredentialItem.YesNoType) item).setValue(field.isSelected());
            continue;
        }
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) JPasswordField(javax.swing.JPasswordField) JComponent(javax.swing.JComponent) CredentialItem(org.eclipse.jgit.transport.CredentialItem) UnsupportedCredentialItem(org.eclipse.jgit.errors.UnsupportedCredentialItem) JTextField(javax.swing.JTextField)

Example 77 with JComponent

use of javax.swing.JComponent in project bndtools by bndtools.

the class GitCredentialsProvider method get.

@Override
public boolean get(URIish uri, CredentialItem... items) throws UnsupportedCredentialItem {
    Mapping mapping = repo.findMapping(uri.toString());
    if (mapping != null) {
        for (CredentialItem item : items) {
            if (item instanceof CredentialItem.Username) {
                ((CredentialItem.Username) item).setValue(mapping.user);
                continue;
            }
            if (item instanceof CredentialItem.Password) {
                ((CredentialItem.Password) item).setValue(mapping.pass);
                continue;
            }
            // Usually Passphrase
            if (item instanceof CredentialItem.StringType && item.isValueSecure()) {
                ((CredentialItem.StringType) item).setValue(new String(mapping.pass));
                continue;
            }
        }
        return true;
    }
    if (isInteractive()) {
        JComponent[] inputs = getSwingUI(items);
        int result = JOptionPane.showConfirmDialog(null, inputs, "Enter credentials for " + repo.getName(), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (result != JOptionPane.OK_OPTION) {
            return false;
        }
        updateCredentialItems(inputs);
        return true;
    }
    return false;
}
Also used : JComponent(javax.swing.JComponent) CredentialItem(org.eclipse.jgit.transport.CredentialItem) UnsupportedCredentialItem(org.eclipse.jgit.errors.UnsupportedCredentialItem) Mapping(bndtools.bndplugins.repo.git.GitOBRRepo.Mapping)

Example 78 with JComponent

use of javax.swing.JComponent in project bndtools by bndtools.

the class GitCredentialsProvider method getSwingUI.

private static JComponent[] getSwingUI(CredentialItem... items) {
    List<JComponent> components = new ArrayList<JComponent>();
    for (CredentialItem item : items) {
        if (item instanceof CredentialItem.Username) {
            components.add(new JLabel(item.getPromptText()));
            JTextField field = new JTextField();
            field.putClientProperty(CRED_ITEM, item);
            components.add(field);
            continue;
        }
        if (item instanceof CredentialItem.Password) {
            components.add(new JLabel(item.getPromptText()));
            JTextField field = new JPasswordField();
            field.putClientProperty(CRED_ITEM, item);
            components.add(field);
            continue;
        }
        if (item instanceof CredentialItem.StringType) {
            components.add(new JLabel(item.getPromptText()));
            JTextField field;
            if (item.isValueSecure()) {
                field = new JPasswordField();
            } else {
                field = new JTextField();
            }
            field.putClientProperty(CRED_ITEM, item);
            components.add(field);
            continue;
        }
        if (item instanceof CredentialItem.InformationalMessage) {
            components.add(new JLabel(item.getPromptText()));
            continue;
        }
        if (item instanceof CredentialItem.YesNoType) {
            JCheckBox field = new JCheckBox(item.getPromptText(), ((CredentialItem.YesNoType) item).getValue());
            field.putClientProperty(CRED_ITEM, item);
            components.add(field);
            continue;
        }
    }
    return components.toArray(new JComponent[0]);
}
Also used : ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) CredentialItem(org.eclipse.jgit.transport.CredentialItem) UnsupportedCredentialItem(org.eclipse.jgit.errors.UnsupportedCredentialItem) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) JPasswordField(javax.swing.JPasswordField)

Example 79 with JComponent

use of javax.swing.JComponent in project JMRI by JMRI.

the class PaneProgPane method newVariable.

/**
     * Add the representation of a single variable. The variable is defined by a
     * JDOM variable Element from the XML file.
     *
     * @param var         element containing variable
     * @param col         column to insert label into
     * @param g           panel layout manager
     * @param cs          constraints on layout manager
     * @param showStdName show the name following the rules for the
     * <em>nameFmt</em> element
     */
public void newVariable(Element var, JComponent col, GridBagLayout g, GridBagConstraints cs, boolean showStdName) {
    // get the name
    String name = var.getAttribute("item").getValue();
    // if it doesn't exist, do nothing
    int i = _varModel.findVarIndex(name);
    if (i < 0) {
        log.trace("Variable \"{}\" not found, omitted", name);
        return;
    }
    //        Leave here for now. Need to track pre-existing corner-case issue
    //        log.info("Entry item="+name+";cs.gridx="+cs.gridx+";cs.gridy="+cs.gridy+";cs.anchor="+cs.anchor+";cs.ipadx="+cs.ipadx);
    // check label orientation
    Attribute attr;
    // this default is also set in the DTD
    String layout = "left";
    if ((attr = var.getAttribute("layout")) != null && attr.getValue() != null) {
        layout = attr.getValue();
    }
    // load label if specified, else use name
    String label = name;
    if (!showStdName) {
        // get name attribute from variable, as that's the mfg name
        label = _varModel.getLabel(i);
    }
    String temp = LocaleSelector.getAttribute(var, "label");
    if (temp != null) {
        label = temp;
    }
    // get representation; store into the list to be programmed
    JComponent rep = getRepresentation(name, var);
    varList.add(i);
    // create the paired label
    JLabel l = new WatchingLabel(label, rep);
    int spaceWidth = getFontMetrics(l.getFont()).stringWidth(" ");
    // assemble v from label, rep
    switch(layout) {
        case "left":
            cs.anchor = GridBagConstraints.EAST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            cs.gridx++;
            cs.anchor = GridBagConstraints.WEST;
            g.setConstraints(rep, cs);
            col.add(rep);
            break;
        //        log.info("Exit item="+name+";cs.gridx="+cs.gridx+";cs.gridy="+cs.gridy+";cs.anchor="+cs.anchor+";cs.ipadx="+cs.ipadx);
        case "right":
            cs.anchor = GridBagConstraints.EAST;
            g.setConstraints(rep, cs);
            col.add(rep);
            cs.gridx++;
            cs.anchor = GridBagConstraints.WEST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            break;
        case "below":
            // variable in center of upper line
            cs.anchor = GridBagConstraints.CENTER;
            g.setConstraints(rep, cs);
            col.add(rep);
            // label aligned like others
            cs.gridy++;
            cs.anchor = GridBagConstraints.WEST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            break;
        case "above":
            // label aligned like others
            cs.anchor = GridBagConstraints.WEST;
            cs.ipadx = spaceWidth;
            g.setConstraints(l, cs);
            col.add(l);
            cs.ipadx = 0;
            // variable in center of lower line
            cs.gridy++;
            cs.anchor = GridBagConstraints.CENTER;
            g.setConstraints(rep, cs);
            col.add(rep);
            break;
        default:
            log.error("layout internally inconsistent: " + layout);
    }
}
Also used : Attribute(org.jdom2.Attribute) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel)

Example 80 with JComponent

use of javax.swing.JComponent in project jdk8u_jdk by JetBrains.

the class Test4682386 method testSwingProperties.

/**
     * Should be exectuted with $JAVA_HOME/lib/dt.jar in the classpath
     * so that there will be a lot more bound properties.
     * <p/>
     * This test isn't really appropriate for automated testing.
     */
private static void testSwingProperties() {
    long start = System.currentTimeMillis();
    for (Class type : TYPES) {
        try {
            Object bean = Beans.instantiate(type.getClassLoader(), type.getName());
            JComponent comp = (JComponent) bean;
            for (int k = 0; k < NUM_LISTENERS; k++) {
                comp.addPropertyChangeListener(new PropertyListener());
            }
            for (PropertyDescriptor pd : getPropertyDescriptors(type)) {
                if (pd.isBound()) {
                    if (DEBUG) {
                        System.out.println("Bound property found: " + pd.getName());
                    }
                    Method read = pd.getReadMethod();
                    Method write = pd.getWriteMethod();
                    try {
                        write.invoke(bean, getValue(pd.getPropertyType(), read.invoke(bean)));
                    } catch (Exception ex) {
                        // do nothing - just move on.
                        if (DEBUG) {
                            System.out.println("Reflective method invocation Exception for " + type + " : " + ex.getMessage());
                        }
                    }
                }
            }
        } catch (Exception ex) {
            // do nothing - just move on.
            if (DEBUG) {
                System.out.println("Exception for " + type.getName() + " : " + ex.getMessage());
            }
        }
    }
    System.out.println("Exec time (ms): " + (System.currentTimeMillis() - start));
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) JComponent(javax.swing.JComponent) Method(java.lang.reflect.Method) IntrospectionException(java.beans.IntrospectionException)

Aggregations

JComponent (javax.swing.JComponent)225 Component (java.awt.Component)44 JPanel (javax.swing.JPanel)37 JLabel (javax.swing.JLabel)34 JButton (javax.swing.JButton)28 BorderLayout (java.awt.BorderLayout)27 Dimension (java.awt.Dimension)23 Insets (java.awt.Insets)20 ActionEvent (java.awt.event.ActionEvent)16 ArrayList (java.util.ArrayList)16 ActionListener (java.awt.event.ActionListener)15 Color (java.awt.Color)13 GridBagConstraints (java.awt.GridBagConstraints)13 Point (java.awt.Point)13 GridBagLayout (java.awt.GridBagLayout)12 JScrollPane (javax.swing.JScrollPane)12 JTextField (javax.swing.JTextField)12 JFrame (javax.swing.JFrame)11 Container (java.awt.Container)8 FlowLayout (java.awt.FlowLayout)8