Example usage for javax.swing JButton setEnabled

List of usage examples for javax.swing JButton setEnabled

Introduction

In this page you can find the example usage for javax.swing JButton setEnabled.

Prototype

public void setEnabled(boolean b) 

Source Link

Document

Enables (or disables) the button.

Usage

From source file:main.UIController.java

/******** FROM GREGORIAN **********/

public void updateDayComboGregorian() {
    UI window = this.getUi();

    JTextField year = window.getYear();
    JComboBox month = window.getMonth();
    JComboBox day = window.getDay();
    JButton convert = window.getToImladris();
    JTextPane result = window.getResImladris();
    String value = year.getText();
    if (!value.isEmpty()) {
        try {//from ww  w  .  jav a 2 s .  c o m
            int yearNum = Integer.parseInt(value);
            if (yearNum > 0 && yearNum <= GregorianInfo.MAX_SUPPORTED_YEAR) {
                int monthNum = month.getSelectedIndex() + 1;
                int daySel = 0;
                if (day.isEnabled()) {
                    daySel = day.getSelectedIndex() + 1;
                }
                ArrayList<Integer> days = GregorianInfo.getInstance().getDaysArray(yearNum, monthNum);
                day.setModel(new DefaultComboBoxModel(days.toArray()));
                if (daySel > 0 && daySel <= days.size()) {
                    day.setSelectedIndex(daySel - 1);
                }
                day.setEnabled(true);
                convert.setEnabled(true);
                result.setText("");
            } else {
                day.setEnabled(false);
                convert.setEnabled(false);
                day.setModel(new DefaultComboBoxModel());
                result.setText("");
            }
        } catch (NumberFormatException e) {
            day.setEnabled(false);
            convert.setEnabled(false);
            day.setModel(new DefaultComboBoxModel());
            result.setText("");
        }
    } else {
        day.setEnabled(false);
        convert.setEnabled(false);
        day.setModel(new DefaultComboBoxModel());
        result.setText("");
    }
}

From source file:net.pms.newgui.NetworkTab.java

public JComponent build() {
    FormLayout layout = new FormLayout("left:pref, 2dlu, p, 2dlu , p, 2dlu, p, 2dlu, pref:grow",
            "p, 0dlu, p, 0dlu, p, 3dlu, p, 3dlu, p, 3dlu,p, 3dlu, p, 15dlu, p, 3dlu,p, 3dlu, p,  3dlu, p, 3dlu, p, 3dlu, p,3dlu, p, 3dlu, p, 15dlu, p,3dlu, p, 3dlu, p, 15dlu, p, 3dlu, p");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.DLU4_BORDER);
    builder.setOpaque(true);/*  ww  w .  j  a  v a2 s  .  c  o m*/

    CellConstraints cc = new CellConstraints();

    smcheckBox = new JCheckBox(Messages.getString("NetworkTab.3"));
    smcheckBox.setContentAreaFilled(false);
    smcheckBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            PMS.getConfiguration().setMinimized((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    if (PMS.getConfiguration().isMinimized()) {
        smcheckBox.setSelected(true);
    }

    JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), cc.xyw(1, 1, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    builder.addLabel(Messages.getString("NetworkTab.0"), cc.xy(1, 7));
    final KeyedComboBoxModel kcbm = new KeyedComboBoxModel(
            new Object[] { "bg", "ca", "zhs", "zht", "cz", "da", "nl", "en", "fi", "fr", "de", "el", "is", "it",
                    "ja", "no", "pl", "pt", "br", "ro", "ru", "sl", "es", "sv" },
            new Object[] { "Bulgarian", "Catalan", "Chinese (Simplified)", "Chinese (Traditional)", "Czech",
                    "Danish", "Dutch", "English", "Finnish", "French", "German", "Greek", "Icelandic",
                    "Italian", "Japanese", "Norwegian", "Polish", "Portuguese", "Portuguese (Brazilian)",
                    "Romanian", "Russian", "Slovenian", "Spanish", "Swedish" });
    langs = new JComboBox(kcbm);
    langs.setEditable(false);
    //langs.setSelectedIndex(0);
    String defaultLang = null;
    if (configuration.getLanguage() != null && configuration.getLanguage().length() > 0) {
        defaultLang = configuration.getLanguage();
    } else {
        defaultLang = Locale.getDefault().getLanguage();
    }
    if (defaultLang == null) {
        defaultLang = "en";
    }
    kcbm.setSelectedKey(defaultLang);
    if (langs.getSelectedIndex() == -1) {
        langs.setSelectedIndex(0);
    }

    langs.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setLanguage((String) kcbm.getSelectedKey());

            }
        }
    });
    builder.add(langs, cc.xyw(3, 7, 7));

    builder.add(smcheckBox, cc.xyw(1, 9, 9));

    JButton service = new JButton(Messages.getString("NetworkTab.4"));
    service.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (PMS.get().installWin32Service()) {
                JOptionPane.showMessageDialog(
                        (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())),
                        Messages.getString("NetworkTab.11") + Messages.getString("NetworkTab.12"),
                        "Information", JOptionPane.INFORMATION_MESSAGE);

            } else {
                JOptionPane.showMessageDialog(
                        (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())),
                        Messages.getString("NetworkTab.14"), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    builder.add(service, cc.xy(1, 11));
    if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) {
        service.setEnabled(false);
    }

    host = new JTextField(PMS.getConfiguration().getServerHostname());
    host.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setHostname(host.getText());
            PMS.get().getFrame().setReloadable(true);
        }
    });
    // host.setEnabled( StringUtils.isBlank(configuration.getNetworkInterface())) ;
    port = new JTextField(configuration.getServerPort() != 5001 ? "" + configuration.getServerPort() : "");
    port.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            try {
                String p = port.getText();
                if (StringUtils.isEmpty(p)) {
                    p = "5001";
                }
                int ab = Integer.parseInt(p);
                configuration.setServerPort(ab);
                PMS.get().getFrame().setReloadable(true);
            } catch (NumberFormatException nfe) {
            }

        }
    });

    cmp = builder.addSeparator(Messages.getString("NetworkTab.22"), cc.xyw(1, 21, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    ArrayList<String> names = new ArrayList<String>();
    names.add("");
    ArrayList<String> interfaces = new ArrayList<String>();
    interfaces.add("");
    Enumeration<NetworkInterface> enm;
    try {
        enm = NetworkInterface.getNetworkInterfaces();
        while (enm.hasMoreElements()) {
            NetworkInterface ni = enm.nextElement();
            // check for interface has at least one ip address.
            if (ni.getInetAddresses().hasMoreElements()) {
                names.add(ni.getName());
                String displayName = ni.getDisplayName();
                if (displayName == null) {
                    displayName = ni.getName();
                }
                interfaces.add(displayName.trim());
            }
        }
    } catch (SocketException e1) {
        logger.error(null, e1);
    }

    final KeyedComboBoxModel networkInterfaces = new KeyedComboBoxModel(names.toArray(), interfaces.toArray());
    networkinterfacesCBX = new JComboBox(networkInterfaces);
    networkInterfaces.setSelectedKey(configuration.getNetworkInterface());
    networkinterfacesCBX.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setNetworkInterface((String) networkInterfaces.getSelectedKey());
                //host.setEnabled( StringUtils.isBlank(configuration.getNetworkInterface())) ;
                PMS.get().getFrame().setReloadable(true);
            }
        }
    });

    ip_filter = new JTextField(PMS.getConfiguration().getIpFilter());
    ip_filter.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setIpFilter(ip_filter.getText());
            PMS.get().getFrame().setReloadable(true);
        }
    });

    builder.addLabel(Messages.getString("NetworkTab.20"), cc.xy(1, 23));
    builder.add(networkinterfacesCBX, cc.xyw(3, 23, 7));
    builder.addLabel(Messages.getString("NetworkTab.23"), cc.xy(1, 25));
    builder.add(host, cc.xyw(3, 25, 7));
    builder.addLabel(Messages.getString("NetworkTab.24"), cc.xy(1, 27));
    builder.add(port, cc.xyw(3, 27, 7));
    builder.addLabel(Messages.getString("NetworkTab.30"), cc.xy(1, 29));
    builder.add(ip_filter, cc.xyw(3, 29, 7));

    cmp = builder.addSeparator(Messages.getString("NetworkTab.31"), cc.xyw(1, 31, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    newHTTPEngine = new JCheckBox(Messages.getString("NetworkTab.32"));
    newHTTPEngine.setSelected(PMS.getConfiguration().isHTTPEngineV2());
    newHTTPEngine.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            PMS.getConfiguration().setHTTPEngineV2((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(newHTTPEngine, cc.xyw(1, 33, 9));

    preventSleep = new JCheckBox(Messages.getString("NetworkTab.33"));
    preventSleep.setSelected(PMS.getConfiguration().isPreventsSleep());
    preventSleep.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            PMS.getConfiguration().setPreventsSleep((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(preventSleep, cc.xyw(1, 35, 9));

    cmp = builder.addSeparator(Messages.getString("NetworkTab.34"), cc.xyw(1, 37, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    JPanel panel = builder.getPanel();
    JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    return scrollPane;
}

From source file:net.minelord.gui.panes.IRCPane.java

public IRCPane() {
    super();/* ww w. j  a va  2  s  .  co m*/
    this.setBorder(new EmptyBorder(5, 5, 5, 5));
    this.setLayout(null);
    nickSelectPane = new JPanel();
    nickSelectPane.setLayout(null);
    nickSelectPane.setBounds(325, 70, 200, 200);
    TitledBorder title = BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Pick a nick");
    title.setTitleJustification(TitledBorder.RIGHT);
    nickSelectPane.setBorder(title);
    nickSelect = new JTextField();
    final JButton done = new JButton("Done");
    nickSelect.addKeyListener(new KeyListener() {
        @Override
        public void keyTyped(KeyEvent arg0) {
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
            String nick = nickSelect.getText();
            boolean success = true;
            if (nick.length() > 0) {
                if (nick.substring(0, 1).matches("[0-9]") || nick.charAt(0) == '-' || nick.contains(" "))
                    success = false;
            } else
                success = false;
            if (success)
                IRCPane.nick = nick;
            done.setEnabled(success);
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == 10)
                done.doClick();
        }
    });
    nickSelect.setBounds(50, 65, 100, 30);
    done.setBounds(50, 125, 100, 30);
    done.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            remove(nickSelectPane);
            repaint();
            startClient(nickSelect.getText());
        }
    });

    done.setEnabled(false);
    nickSelectPane.add(nickSelect);
    nickSelectPane.add(done);
    add(nickSelectPane);
    addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent paramFocusEvent) {
        }

        @Override
        public void focusGained(FocusEvent paramFocusEvent) {
            if (nickSelectPane.getParent() != null)
                nickSelect.requestFocus();
            if (input != null && input.getParent() != null)
                input.requestFocus();
        }
    });
    instance = this;
}

From source file:edu.ku.brc.specify.prefs.FormattingPrefsPanel.java

/**
 * Create the UI for the panel// w  w w  .  ja v a  2s.c o m
 */
protected void createUI() {
    createForm("Preferences", "Formatting"); //$NON-NLS-1$ //$NON-NLS-2$

    UIValidator.setIgnoreAllValidation(this, true);

    JLabel fontNamesLabel = form.getLabelFor("fontNames"); //$NON-NLS-1$
    ValComboBox fontNamesVCB = form.getCompById("fontNames"); //$NON-NLS-1$

    JLabel fontSizesLabel = form.getLabelFor("fontSizes"); //$NON-NLS-1$
    ValComboBox fontSizesVCB = form.getCompById("fontSizes"); //$NON-NLS-1$

    JLabel controlSizesLabel = form.getLabelFor("controlSizes"); //$NON-NLS-1$
    ValComboBox controlSizesVCB = form.getCompById("controlSizes"); //$NON-NLS-1$

    formTypesCBX = form.getCompById("formtype"); //$NON-NLS-1$

    fontNames = fontNamesVCB.getComboBox();
    fontSizes = fontSizesVCB.getComboBox();
    controlSizes = controlSizesVCB.getComboBox();

    testField = form.getCompById("fontTest"); //$NON-NLS-1$
    if (testField != null) {
        testField.setText(UIRegistry.getResourceString("FormattingPrefsPanel.THIS_TEST")); //$NON-NLS-1$
    }
    if (UIHelper.isMacOS_10_5_X()) {
        fontNamesLabel.setVisible(false);
        fontNamesVCB.setVisible(false);
        fontSizesLabel.setVisible(false);
        fontSizesVCB.setVisible(false);
        testField.setVisible(false);

        int inx = -1;
        int i = 0;
        Vector<String> controlSizeTitles = new Vector<String>();
        for (UIHelper.CONTROLSIZE cs : UIHelper.CONTROLSIZE.values()) {
            String titleStr = getResourceString(cs.toString());
            controlSizeTitles.add(titleStr);
            controlSizesHash.put(titleStr, cs);
            controlSizes.addItem(titleStr);
            if (cs == UIHelper.getControlSize()) {
                inx = i;
            }
            i++;
        }
        controlSizes.setSelectedIndex(inx);

        Font baseFont = UIRegistry.getBaseFont();
        if (baseFont != null) {
            fontNames.addItem(baseFont.getFamily());
            fontSizes.addItem(Integer.toString(baseFont.getSize()));
            fontNames.setSelectedIndex(0);
            fontSizes.setSelectedIndex(0);
        }

    } else {
        controlSizesLabel.setVisible(false);
        controlSizesVCB.setVisible(false);

        Hashtable<String, Boolean> namesUsed = new Hashtable<String, Boolean>();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        for (Font font : ge.getAllFonts()) {
            if (namesUsed.get(font.getFamily()) == null) {
                fontNames.addItem(font.getFamily());
                namesUsed.put(font.getFamily(), true); //$NON-NLS-1$
            }
        }
        for (int i = BASE_FONT_SIZE; i < 22; i++) {
            fontSizes.addItem(Integer.toString(i));
        }

        Font baseFont = UIRegistry.getBaseFont();
        if (baseFont != null) {
            fontNames.setSelectedItem(baseFont.getFamily());
            fontSizes.setSelectedItem(Integer.toString(baseFont.getSize()));

            if (testField != null) {
                ActionListener al = new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        testField.setFont(new Font((String) fontNames.getSelectedItem(), Font.PLAIN,
                                fontSizes.getSelectedIndex() + BASE_FONT_SIZE));
                        form.getUIComponent().validate();
                        clearFontSettings = false;
                    }
                };
                fontNames.addActionListener(al);
                fontSizes.addActionListener(al);
            }
        }
    }

    //-----------------------------------
    // Do DisciplineType Icons
    //-----------------------------------

    String iconName = AppPreferences.getRemote().get(getDisciplineImageName(), "CollectionObject"); //$NON-NLS-1$ //$NON-NLS-2$

    List<Pair<String, ImageIcon>> list = IconManager.getListByType("disciplines", IconManager.IconSize.Std16); //$NON-NLS-1$
    Collections.sort(list, new Comparator<Pair<String, ImageIcon>>() {
        public int compare(Pair<String, ImageIcon> o1, Pair<String, ImageIcon> o2) {
            String s1 = UIRegistry.getResourceString(o1.first);
            String s2 = UIRegistry.getResourceString(o2.first);
            return s1.compareTo(s2);
        }
    });

    disciplineCBX = (ValComboBox) form.getCompById("disciplineIconCBX"); //$NON-NLS-1$

    final JLabel dispLabel = form.getCompById("disciplineIcon"); //$NON-NLS-1$
    JComboBox comboBox = disciplineCBX.getComboBox();
    comboBox.setRenderer(new DefaultListCellRenderer() {
        @SuppressWarnings("unchecked") //$NON-NLS-1$
        public Component getListCellRendererComponent(JList listArg, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) value;
            JLabel label = (JLabel) super.getListCellRendererComponent(listArg, value, index, isSelected,
                    cellHasFocus);
            if (item != null) {
                label.setIcon(item.second);
                label.setText(UIRegistry.getResourceString(item.first));
            }
            return label;
        }
    });

    int inx = 0;
    Pair<String, ImageIcon> colObj = new Pair<String, ImageIcon>("colobj_backstop", //$NON-NLS-1$
            IconManager.getIcon("colobj_backstop", IconManager.IconSize.Std16)); //$NON-NLS-1$
    comboBox.addItem(colObj);

    int cnt = 1;
    for (Pair<String, ImageIcon> item : list) {
        if (item.first.equals(iconName)) {
            inx = cnt;
        }
        comboBox.addItem(item);
        cnt++;
    }

    comboBox.addActionListener(new ActionListener() {
        @SuppressWarnings("unchecked") //$NON-NLS-1$
        public void actionPerformed(ActionEvent e) {
            JComboBox cbx = (JComboBox) e.getSource();
            Pair<String, ImageIcon> item = (Pair<String, ImageIcon>) cbx.getSelectedItem();
            if (item != null) {
                dispLabel.setIcon(IconManager.getIcon(item.first));
                form.getUIComponent().validate();
            }
        }
    });

    comboBox.setSelectedIndex(inx);

    //-----------------------------------
    // Date Field
    //-----------------------------------
    dateFieldCBX = form.getCompById("scrdateformat"); //$NON-NLS-1$
    fillDateFormat();

    //-----------------------------------
    // FormType
    //-----------------------------------
    fillFormTypes();

    //-----------------------------------
    // Do App Icon
    //-----------------------------------

    final JButton getIconBtn = form.getCompById("GetIconImage"); //$NON-NLS-1$
    final JButton clearIconBtn = form.getCompById("ClearIconImage"); //$NON-NLS-1$
    final JLabel appLabel = form.getCompById("appIcon"); //$NON-NLS-1$
    final JButton resetDefFontBtn = form.getCompById("ResetDefFontBtn"); //$NON-NLS-1$

    String imgEncoded = AppPreferences.getRemote().get(iconImagePrefName, ""); //$NON-NLS-1$
    ImageIcon innerAppImgIcon = null;
    if (StringUtils.isNotEmpty(imgEncoded)) {
        innerAppImgIcon = GraphicsUtils.uudecodeImage("", imgEncoded); //$NON-NLS-1$
        if (innerAppImgIcon != null && innerAppImgIcon.getIconWidth() != 32
                || innerAppImgIcon.getIconHeight() != 32) {
            innerAppImgIcon = null;
            clearIconBtn.setEnabled(false);
        } else {
            clearIconBtn.setEnabled(true);
        }
    }

    if (innerAppImgIcon == null) {
        innerAppImgIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$
        clearIconBtn.setEnabled(false);
    } else {
        clearIconBtn.setEnabled(true);
    }
    appLabel.setIcon(innerAppImgIcon);

    getIconBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            chooseToolbarIcon(appLabel, clearIconBtn);
        }
    });

    clearIconBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ImageIcon appIcon = IconManager.getIcon("AppIcon");
            IconEntry entry = IconManager.getIconEntryByName(INNER_APPICON_NAME);
            entry.setIcon(appIcon);
            if (entry.getIcons().get(IconManager.IconSize.Std32) != null) {
                entry.getIcons().get(IconManager.IconSize.Std32).setImageIcon(appIcon);
            }

            appLabel.setIcon(IconManager.getIcon("AppIcon")); //$NON-NLS-1$
            clearIconBtn.setEnabled(false);
            AppPreferences.getRemote().remove(iconImagePrefName);
            form.getValidator().dataChanged(null, null, null);
        }
    });

    resetDefFontBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Font sysDefFont = UIRegistry.getDefaultFont();
            ComboBoxModel model = fontNames.getModel();
            for (int i = 0; i < model.getSize(); i++) {
                //System.out.println("["+model.getElementAt(i).toString()+"]["+sysDefFont.getFamily()+"]");
                if (model.getElementAt(i).toString().equals(sysDefFont.getFamily())) {
                    fontNames.setSelectedIndex(i);
                    clearFontSettings = true;
                    break;
                }
            }

            if (clearFontSettings) {
                fontSizes.setSelectedIndex(sysDefFont.getSize() - BASE_FONT_SIZE);
                clearFontSettings = true; // needs to be redone 
            }

            form.getValidator().dataChanged(null, null, null);
        }
    });

    //-----------------------------------
    // Do Banner Icon Size
    //-----------------------------------

    String fmtStr = "%d x %d pixels";//getResourceString("BNR_ICON_SIZE");
    bnrIconSizeCBX = form.getCompById("bnrIconSizeCBX"); //$NON-NLS-1$

    int size = AppPreferences.getLocalPrefs().getInt(BNR_ICON_SIZE, 20);
    inx = 0;
    cnt = 0;
    for (int pixelSize : pixelSizes) {
        ((DefaultComboBoxModel) bnrIconSizeCBX.getModel())
                .addElement(String.format(fmtStr, pixelSize, pixelSize));
        if (pixelSize == size) {
            inx = cnt;
        }
        cnt++;
    }

    bnrIconSizeCBX.getComboBox().addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            form.getUIComponent().validate();
        }
    });

    bnrIconSizeCBX.getComboBox().setSelectedIndex(inx);

    UIValidator.setIgnoreAllValidation(this, false);
    fontNamesVCB.setChanged(false);
    fontSizesVCB.setChanged(false);

    form.getValidator().validateForm();
}

From source file:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java

/**
 * @return/* w w w .  j a v a 2 s  .  com*/
 */
private void createColObjSearch() {
    if (searchType != SearchType.FromRecordSet) {
        searchForAllAttachments();
        gridPanel.setItemList(rowsVector);
        JScrollPane sb = new JScrollPane(gridPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        add(sb, BorderLayout.CENTER);
        return;
    }

    CellConstraints cc = new CellConstraints();

    String rowDef = searchType != SearchType.FromRecordSet ? "f:p:g" : "p,4px,f:p:g";
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,2px,p", rowDef));

    int y = 1;
    coVBP = new ViewBasedDisplayPanel(null, "COImageSearch", CollectionObject.class.getName(), true,
            MultiView.NO_SCROLLBARS | MultiView.IS_SINGLE_OBJ | MultiView.IS_EDITTING);
    pb.add(coVBP, cc.xyw(1, y, 3));
    y += 2;

    pb.add(gridPanel, cc.xyw(1, y, 3));

    coVBP.setData(dataMap);

    FormViewObj fvo = coVBP.getMultiView().getCurrentViewAsFormViewObj();
    JButton searchBtn = fvo.getCompById("2");
    JTextField textField = fvo.getCompById("1");
    y += 2;

    //fvo.setAlwaysGetDataFromUI(true);

    if (searchBtn != null) {
        final JButton searchBtnFinal = searchBtn;
        final JTextField textFieldFinal = textField;

        searchBtn.setEnabled(false);
        searchBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                //searchForColObjImagesForTable();
                gridPanel.setItemList(rowsVector);
                //invalidate();
                //revalidate();
            }
        });

        textField.getDocument().addDocumentListener(new DocumentAdaptor() {
            @Override
            protected void changed(DocumentEvent e) {
                searchBtnFinal.setEnabled(textFieldFinal.getText().length() > 0);
            }
        });
        textField.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER && textFieldFinal.getText().length() > 0) {
                    //searchForColObjImagesForTable();
                }
            }

        });
    }
    JScrollPane sb = new JScrollPane(pb.getPanel(), JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    add(sb, BorderLayout.CENTER);
}

From source file:ca.canucksoftware.ipkpackager.IpkPackagerView.java

private void disableNewFolderButton(Container c) {
    int len = c.getComponentCount();
    for (int i = 0; i < len; i++) {
        Component comp = c.getComponent(i);
        if (comp instanceof JButton) {
            JButton b = (JButton) comp;
            Icon icon = b.getIcon();
            if (icon != null && (icon == UIManager.getIcon("FileChooser.newFolderIcon")
                    || icon == UIManager.getIcon("FileChooser.upFolderIcon")))
                b.setEnabled(false);
        } else if (comp instanceof Container) {
            disableNewFolderButton((Container) comp);
        }//from  w w w.  j ava  2 s. com
    }
}

From source file:com._17od.upm.gui.AccountDialog.java

public AccountDialog(AccountInformation account, JFrame parentWindow, boolean readOnly,
        ArrayList existingAccounts) {
    super(parentWindow, true);

    boolean addingAccount = false;

    //Request focus on Account JDialog when mouse clicked
    this.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 1) {
                requestFocus();/*from ww  w .j  a  v a2  s .  c  o  m*/

            }
        }
    });

    // Set the title based on weather we've been opened in readonly mode and
    // weather the
    // Account passed in is empty or not
    String title = null;
    if (readOnly) {
        title = Translator.translate("viewAccount");
    } else if (!readOnly && account.getAccountName().trim().equals("")) {
        title = Translator.translate("addAccount");
        addingAccount = true;
    } else {
        title = Translator.translate("editAccount");
    }
    setTitle(title);

    this.pAccount = account;
    this.existingAccounts = existingAccounts;
    this.parentWindow = parentWindow;

    getContentPane().setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    Container container = getContentPane();

    // The AccountName Row
    JLabel accountLabel = new JLabel(Translator.translate("account"));
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(accountLabel, c);

    // This panel will hold the Account field and the copy and paste
    // buttons.
    JPanel accountPanel = new JPanel(new GridBagLayout());

    accountName = new JTextField(new String(pAccount.getAccountName()), 20);
    if (readOnly) {
        accountName.setEditable(false);
    }
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    accountPanel.add(accountName, c);
    accountName.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            accountName.selectAll();
        }
    });

    JButton acctCopyButton = new JButton();
    acctCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    acctCopyButton.setToolTipText("Copy");
    acctCopyButton.setEnabled(true);
    acctCopyButton.setMargin(new Insets(0, 0, 0, 0));
    acctCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextField(accountName);
        }
    });
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    accountPanel.add(acctCopyButton, c);

    JButton acctPasteButton = new JButton();
    acctPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    acctPasteButton.setToolTipText("Paste");
    acctPasteButton.setEnabled(!readOnly);
    acctPasteButton.setMargin(new Insets(0, 0, 0, 0));
    acctPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextField(accountName);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    accountPanel.add(acctPasteButton, c);

    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(accountPanel, c);

    // Userid Row
    JLabel useridLabel = new JLabel(Translator.translate("userid"));
    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(useridLabel, c);

    // This panel will hold the User ID field and the copy and paste
    // buttons.
    JPanel idPanel = new JPanel(new GridBagLayout());

    userId = new JTextField(new String(pAccount.getUserId()), 20);
    if (readOnly) {
        userId.setEditable(false);
    }
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    idPanel.add(userId, c);
    userId.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            userId.selectAll();
        }
    });

    JButton idCopyButton = new JButton();
    idCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    idCopyButton.setToolTipText("Copy");
    idCopyButton.setEnabled(true);
    idCopyButton.setMargin(new Insets(0, 0, 0, 0));
    idCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextField(userId);
        }
    });
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    idPanel.add(idCopyButton, c);

    JButton idPasteButton = new JButton();
    idPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    idPasteButton.setToolTipText("Paste");
    idPasteButton.setEnabled(!readOnly);
    idPasteButton.setMargin(new Insets(0, 0, 0, 0));
    idPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextField(userId);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    idPanel.add(idPasteButton, c);

    c.gridx = 1;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(idPanel, c);

    // Password Row
    JLabel passwordLabel = new JLabel(Translator.translate("password"));
    c.gridx = 0;
    c.gridy = 2;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(15, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(passwordLabel, c);

    // This panel will hold the password, generate password button, copy and
    // paste buttons, and hide password checkbox
    JPanel passwordPanel = new JPanel(new GridBagLayout());

    password = new JPasswordField(new String(pAccount.getPassword()), 20);
    // allow CTRL-C on the password field
    password.putClientProperty("JPasswordField.cutCopyAllowed", Boolean.TRUE);
    password.setEditable(!readOnly);
    password.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            password.selectAll();
        }
    });
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(password, c);

    JButton generateRandomPasswordButton = new JButton(Translator.translate("generate"));
    if (readOnly) {
        generateRandomPasswordButton.setEnabled(false);
    }
    generateRandomPasswordButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionevent) {
            // Get the user's preference about including or not Escape
            // Characters to generated passwords
            Boolean includeEscapeChars = new Boolean(
                    Preferences.get(Preferences.ApplicationOptions.INCLUDE_ESCAPE_CHARACTERS, "true"));
            int pwLength = Preferences.getInt(Preferences.ApplicationOptions.ACCOUNT_PASSWORD_LENGTH, 8);
            String Password;

            if ((includeEscapeChars.booleanValue()) && (pwLength > 3)) {
                // Verify that the generated password satisfies the criteria
                // for strong passwords(including Escape Characters)
                do {
                    Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue());
                } while (!(CheckPassStrong(Password, includeEscapeChars.booleanValue())));

            } else if (!(includeEscapeChars.booleanValue()) && (pwLength > 2)) {
                // Verify that the generated password satisfies the criteria
                // for strong passwords(excluding Escape Characters)
                do {
                    Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue());
                } while (!(CheckPassStrong(Password, includeEscapeChars.booleanValue())));

            } else {
                // Else a weak password of 3 or less chars will be produced
                Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue());
            }
            password.setText(Password);
        }
    });
    if (addingAccount) {
        generateRandomPasswordButton.doClick();
    }
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(generateRandomPasswordButton, c);

    JButton pwCopyButton = new JButton();
    pwCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    pwCopyButton.setToolTipText("Copy");
    pwCopyButton.setEnabled(true);
    pwCopyButton.setMargin(new Insets(0, 0, 0, 0));
    pwCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextField(password);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(pwCopyButton, c);

    JButton pwPasteButton = new JButton();
    pwPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    pwPasteButton.setToolTipText("Paste");
    pwPasteButton.setEnabled(!readOnly);
    pwPasteButton.setMargin(new Insets(0, 0, 0, 0));
    pwPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextField(password);
        }
    });
    c.gridx = 3;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(pwPasteButton, c);

    JCheckBox hidePasswordCheckbox = new JCheckBox(Translator.translate("hide"), true);
    defaultEchoChar = password.getEchoChar();
    hidePasswordCheckbox.setMargin(new Insets(5, 0, 5, 0));
    hidePasswordCheckbox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                password.setEchoChar(defaultEchoChar);
            } else {
                password.setEchoChar((char) 0);
            }
        }
    });

    Boolean hideAccountPassword = new Boolean(
            Preferences.get(Preferences.ApplicationOptions.ACCOUNT_HIDE_PASSWORD, "true"));
    hidePasswordCheckbox.setSelected(hideAccountPassword.booleanValue());

    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    passwordPanel.add(hidePasswordCheckbox, c);

    c.gridx = 1;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(passwordPanel, c);

    // URL Row
    JLabel urlLabel = new JLabel(Translator.translate("url"));
    c.gridx = 0;
    c.gridy = 3;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(urlLabel, c);

    // This panel will hold the URL field and the copy and paste buttons.
    JPanel urlPanel = new JPanel(new GridBagLayout());

    url = new JTextField(new String(pAccount.getUrl()), 20);
    if (readOnly) {
        url.setEditable(false);
    }
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    urlPanel.add(url, c);
    url.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            url.selectAll();
        }
    });

    final JButton urlLaunchButton = new JButton();
    urlLaunchButton.setIcon(Util.loadImage("launch-url-sm.png"));
    urlLaunchButton.setToolTipText("Launch URL");
    urlLaunchButton.setEnabled(true);
    urlLaunchButton.setMargin(new Insets(0, 0, 0, 0));
    urlLaunchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            String urlText = url.getText();

            // Check if the selected url is null or emty and inform the user
            // via JoptioPane message
            if ((urlText == null) || (urlText.length() == 0)) {
                JOptionPane.showMessageDialog(urlLaunchButton.getParent(),
                        Translator.translate("EmptyUrlJoptionpaneMsg"),
                        Translator.translate("UrlErrorJoptionpaneTitle"), JOptionPane.WARNING_MESSAGE);
                // Check if the selected url is a valid formated url(via
                // urlIsValid() method) and inform the user via JoptioPane
                // message
            } else if (!(urlIsValid(urlText))) {
                JOptionPane.showMessageDialog(urlLaunchButton.getParent(),
                        Translator.translate("InvalidUrlJoptionpaneMsg"),
                        Translator.translate("UrlErrorJoptionpaneTitle"), JOptionPane.WARNING_MESSAGE);
                // Call the method LaunchSelectedURL() using the selected
                // url as input
            } else {
                LaunchSelectedURL(urlText);
            }
        }
    });
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    urlPanel.add(urlLaunchButton, c);

    JButton urlCopyButton = new JButton();
    urlCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    urlCopyButton.setToolTipText("Copy");
    urlCopyButton.setEnabled(true);
    urlCopyButton.setMargin(new Insets(0, 0, 0, 0));
    urlCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextField(url);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    urlPanel.add(urlCopyButton, c);

    JButton urlPasteButton = new JButton();
    urlPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    urlPasteButton.setToolTipText("Paste");
    urlPasteButton.setEnabled(!readOnly);
    urlPasteButton.setMargin(new Insets(0, 0, 0, 0));
    urlPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextField(url);
        }
    });
    c.gridx = 3;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    urlPanel.add(urlPasteButton, c);

    c.gridx = 1;
    c.gridy = 3;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(urlPanel, c);

    // Notes Row
    JLabel notesLabel = new JLabel(Translator.translate("notes"));
    c.gridx = 0;
    c.gridy = 4;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    container.add(notesLabel, c);

    // This panel will hold the Notes text area and the copy and paste
    // buttons.
    JPanel notesPanel = new JPanel(new GridBagLayout());

    notes = new JTextArea(new String(pAccount.getNotes()), 10, 20);
    if (readOnly) {
        notes.setEditable(false);
    }
    notes.setLineWrap(true); // Enable line wrapping.
    notes.setWrapStyleWord(true); // Line wrap at whitespace.
    JScrollPane notesScrollPane = new JScrollPane(notes);
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.BOTH;
    notesPanel.add(notesScrollPane, c);

    JButton notesCopyButton = new JButton();
    notesCopyButton.setIcon(Util.loadImage("copy-icon.png"));
    notesCopyButton.setToolTipText("Copy");
    notesCopyButton.setEnabled(true);
    notesCopyButton.setMargin(new Insets(0, 0, 0, 0));
    notesCopyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            copyTextArea(notes);
        }
    });
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    notesPanel.add(notesCopyButton, c);

    JButton notesPasteButton = new JButton();
    notesPasteButton.setIcon(Util.loadImage("paste-icon.png"));
    notesPasteButton.setToolTipText("Paste");
    notesPasteButton.setEnabled(!readOnly);
    notesPasteButton.setMargin(new Insets(0, 0, 0, 0));
    notesPasteButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            pasteToTextArea(notes);
        }
    });
    c.gridx = 2;
    c.gridy = 0;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(0, 0, 0, 5);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    notesPanel.add(notesPasteButton, c);

    c.gridx = 1;
    c.gridy = 4;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(10, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(notesPanel, c);

    // Seperator Row
    JSeparator sep = new JSeparator();
    c.gridx = 0;
    c.gridy = 5;
    c.anchor = GridBagConstraints.PAGE_END;
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.HORIZONTAL;
    container.add(sep, c);

    // Button Row
    JPanel buttonPanel = new JPanel();
    JButton okButton = new JButton(Translator.translate("ok"));
    // Link Enter key to okButton
    getRootPane().setDefaultButton(okButton);
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            okButtonAction();
        }
    });
    buttonPanel.add(okButton);
    if (!readOnly) {
        JButton cancelButton = new JButton(Translator.translate("cancel"));
        cancelButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                closeButtonAction();
            }
        });
        buttonPanel.add(cancelButton);
    }
    c.gridx = 0;
    c.gridy = 6;
    c.anchor = GridBagConstraints.PAGE_END;
    c.insets = new Insets(5, 0, 5, 0);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.NONE;
    container.add(buttonPanel, c);
}

From source file:com.mirth.connect.connectors.http.HttpSender.java

/** Clears the selection in the table and sets the tasks appropriately */
public void deselectRows(MirthTable table, JButton button) {
    table.clearSelection();//  w  w w. j av a  2  s. c o  m
    button.setEnabled(false);
}

From source file:captureplugin.drivers.defaultdriver.AdditionalParams.java

/**
 * Create List-Panel/*w  ww.  ja  va2s  . co m*/
 * @return List-Panel
 */
private Component createListPanel() {
    JPanel panel = new JPanel(new BorderLayout(0, 2));
    panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));

    panel.add(new JLabel(mLocalizer.msg("command", "Command")), BorderLayout.NORTH);

    mList = new JList(mListModel);
    panel.add(new JScrollPane(mList), BorderLayout.CENTER);

    JPanel buttons = new JPanel(new FlowLayout(FlowLayout.LEFT));

    JButton add = new JButton(TVBrowserIcons.newIcon(TVBrowserIcons.SIZE_SMALL));
    add.setToolTipText(Localizer.getLocalization(Localizer.I18N_ADD));
    add.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            addPressed();
        }

    });

    buttons.add(add);

    JButton remove = new JButton(TVBrowserIcons.delete(TVBrowserIcons.SIZE_SMALL));
    remove.setToolTipText(Localizer.getLocalization(Localizer.I18N_DELETE));

    remove.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            removePressed();
        }

    });

    buttons.add(remove);

    final JButton up = new JButton(TVBrowserIcons.up(TVBrowserIcons.SIZE_SMALL));
    up.setToolTipText(Localizer.getLocalization(Localizer.I18N_UP));
    buttons.add(up);

    up.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            upPressed();
        }

    });

    final JButton down = new JButton(TVBrowserIcons.down(TVBrowserIcons.SIZE_SMALL));
    down.setToolTipText(Localizer.getLocalization(Localizer.I18N_DOWN));
    buttons.add(down);

    down.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            downPressed();
        }

    });

    mStartStop = new JButton(mStartIcon);
    mStartStop.setToolTipText(mLocalizer.msg("startstop", "Activate or Deactivate Parameter"));

    mStartStop.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            startStopPressed();
        }
    });

    buttons.add(mStartStop);

    panel.add(buttons, BorderLayout.SOUTH);

    mList.addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            selectionChanged();
            if (mList.getSelectedIndex() == 0) {
                up.setEnabled(false);
                down.setEnabled(true);
            } else if (mList.getSelectedIndex() == mListModel.getSize() - 1) {
                up.setEnabled(true);
                down.setEnabled(false);
            } else {
                up.setEnabled(true);
                down.setEnabled(true);
            }
        }

    });

    selectionChanged();
    return panel;
}

From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java

/**
  * /*from   w ww  . j a v  a 2  s  .com*/
  */
protected void buildSpreadsheet() {

    this.setShowGrid(true);

    int numRows = model.getRowCount();

    scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    final SpreadSheet ss = this;
    JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll",
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    ss.selectAll();
                }
            });
    cornerBtn.setEnabled(true);
    scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn);

    // Allows row and collumn selections to exit at the same time
    setCellSelectionEnabled(true);

    setRowSelectionAllowed(true);
    setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    addMouseListener(new MouseAdapter() {
        /* (non-Javadoc)
         * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
         */
        @SuppressWarnings("synthetic-access")
        @Override
        public void mouseReleased(MouseEvent e) {
            // XXX For Java 5 Bug
            prevRowSelInx = getSelectedRow();
            prevColSelInx = getSelectedColumn();

            if (e.getClickCount() == 2) {
                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                ss.editCellAt(rowIndexStart, colIndexStart);
                if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) {
                    ss.getEditorComponent().requestFocus();

                    final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent();
                    String txt = txtComp.getText();
                    FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont());
                    int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1;
                    int prevWidth = 0;
                    for (int i = 0; i < txt.length(); i++) {

                        int width = fm.stringWidth(txt.substring(0, i));
                        int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5);
                        //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf);
                        //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i);
                        if (x < width) {
                            // Clearing the selection is needed for Window for some reason
                            final int inx = i + (x <= basePlusHalf ? -1 : 0);
                            SwingUtilities.invokeLater(new Runnable() {
                                @SuppressWarnings("synthetic-access")
                                public void run() {
                                    txtComp.setSelectionStart(0);
                                    txtComp.setSelectionEnd(0);
                                    txtComp.setCaretPosition(inx > 0 ? inx : 0);
                                }
                            });
                            break;
                        }
                        prevWidth = width;
                    }
                }
            }
        }
    });

    // Create a row-header to display row numbers.
    // This row-header is made of labels whose Borders,
    // Foregrounds, Backgrounds, and Fonts must be
    // the one used for the table column headers.
    // Also ensure that the row-header labels and the table
    // rows have the same height.

    //i have no idea WHY this has to be called.  i rearranged
    //the table and find replace panel, 
    // i started getting an array index out of
    //bounds on the column header ON MAC ONLY.  
    //tried firing this off, first and it fixed the problem.//meg
    this.getModel().fireTableStructureChanged();

    /*
     * Create the Row Header Panel
     */
    rowHeaderPanel = new JPanel((LayoutManager) null);

    if (getColumnModel().getColumnCount() > 0) {
        TableColumn column = getColumnModel().getColumn(0);
        TableCellRenderer renderer = getTableHeader().getDefaultRenderer();
        if (renderer == null) {
            renderer = column.getHeaderRenderer();
        }

        Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false,
                false, -1, 0);
        cellFont = cellRenderComp.getFont();

    } else {
        cellFont = (new JLabel()).getFont();
    }

    // Calculate Row Height
    cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder");
    Insets insets = cellBorder.getBorderInsets(tableHeader);
    FontMetrics metrics = getFontMetrics(cellFont);

    rowHeight = insets.bottom + metrics.getHeight() + insets.top;
    rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left;

    Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows);
    rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used.

    rhCellMouseAdapter = new RHCellMouseAdapter(this);

    // Adding the row header labels
    for (int ii = 0; ii < numRows; ii++) {
        addRow(ii, ii + 1, false);
    }

    JViewport viewPort = new JViewport();
    dim.height = rowHeight * numRows;
    viewPort.setViewSize(dim);
    viewPort.setView(rowHeaderPanel);
    scrollPane.setRowHeader(viewPort);

    // Experimental from the web, but I think it does the trick.
    addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent e) {
            if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown()
                    && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB
                    && e.getKeyCode() != KeyEvent.VK_ENTER) {
                log.error("Grabbed the event as input");

                int rowIndexStart = getSelectedRow();
                int colIndexStart = getSelectedColumn();

                if (rowIndexStart == -1 || colIndexStart == -1)
                    return;

                ss.editCellAt(rowIndexStart, colIndexStart);
                Component c = ss.getEditorComponent();
                if (c instanceof JTextComponent)
                    ((JTextComponent) c).setText("");
            }
        }
    });

    resizeAndRepaint();

    // Taken from a JavaWorld Example (But it works)
    KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(),
            false);
    KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false);

    Action ssAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SpreadSheet.this.actionPerformed(e);
        }
    };

    getInputMap().put(cut, "Cut");
    getActionMap().put("Cut", ssAction);

    getInputMap().put(copy, "Copy");
    getActionMap().put("Copy", ssAction);

    getInputMap().put(paste, "Paste");
    getActionMap().put("Paste", ssAction);

    ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this);
    ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this);

    setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED);
}