Example usage for javax.swing SpinnerNumberModel SpinnerNumberModel

List of usage examples for javax.swing SpinnerNumberModel SpinnerNumberModel

Introduction

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

Prototype

public SpinnerNumberModel(double value, double minimum, double maximum, double stepSize) 

Source Link

Document

Constructs a SpinnerNumberModel with the specified value, minimum/maximum bounds, and stepSize.

Usage

From source file:de.atomfrede.tools.evalutation.options.ui.OptionsDialog.java

private JSpinner getCo2Absolute_deltaFiveMinutesMaximumSpinner() {
    if (co2Absolute_deltaFiveMinutesMaximumSpinner == null) {
        co2Absolute_deltaFiveMinutesMaximumSpinner = new JSpinner(new SpinnerNumberModel(
                CO2AbsoluteOnlyEvaluationOptions.co2AbsoluteOnly_getDeltaFiveMinutesMaximum(),
                Integer.MIN_VALUE, Integer.MAX_VALUE, 10));
        co2Absolute_deltaFiveMinutesMaximumSpinner
                .setEnabled(!CO2AbsoluteOnlyEvaluationOptions.isAutoScaleDeltaFiveMinutes());
    }/*from w w w  .  j a va  2s.  c om*/
    return co2Absolute_deltaFiveMinutesMaximumSpinner;
}

From source file:com.dragoniade.deviantart.ui.PreferencesDialog.java

public PreferencesDialog(final DownloaderGUI owner, Properties config) {
    super(owner, "Preferences", true);

    HttpClientParams params = new HttpClientParams();
    params.setVersion(HttpVersion.HTTP_1_1);
    params.setSoTimeout(30000);//from   w  w  w  . j a v a 2 s .c  om
    client = new HttpClient(params);
    setProxy(ProxyCfg.parseConfig(config));

    sample = new Deviation();
    sample.setId(15972367L);
    sample.setTitle("Fella Promo");
    sample.setArtist("devart");
    sample.setImageDownloadUrl(DOWNLOAD_URL);
    sample.setImageFilename(Deviation.extractFilename(DOWNLOAD_URL));
    sample.setCollection(new Collection(1L, "MyCollect"));
    setLayout(new BorderLayout());
    panes = new JTabbedPane(JTabbedPane.TOP);

    JPanel genPanel = new JPanel();
    BoxLayout genLayout = new BoxLayout(genPanel, BoxLayout.Y_AXIS);
    genPanel.setLayout(genLayout);
    panes.add("General", genPanel);

    JLabel userLabel = new JLabel("Username");

    userLabel.setToolTipText("The username the account you want to download the favorites from.");

    userField = new JTextField(config.getProperty(Constants.USERNAME));

    userLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    userField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    userField.setMaximumSize(new Dimension(Integer.MAX_VALUE, userField.getFont().getSize() * 2));

    genPanel.add(userLabel);
    genPanel.add(userField);

    JPanel radioPanel = new JPanel();
    BoxLayout radioLayout = new BoxLayout(radioPanel, BoxLayout.X_AXIS);
    radioPanel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    radioPanel.setBorder(new EmptyBorder(0, 5, 0, 5));

    radioPanel.setLayout(radioLayout);

    JLabel searchLabel = new JLabel("Search for");
    searchLabel
            .setToolTipText("Select what you want to download from that user: it favorites or it galleries.");
    searchLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searchLabel.setBorder(new EmptyBorder(0, 5, 0, 5));

    selectedSearch = SEARCH.lookup(config.getProperty(Constants.SEARCH, SEARCH.getDefault().getId()));
    buttonGroup = new ButtonGroup();

    for (final SEARCH search : SEARCH.values()) {
        JRadioButton radio = new JRadioButton(search.getLabel());
        radio.setAlignmentX(JLabel.LEFT_ALIGNMENT);
        radio.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                selectedSearch = search;
            }
        });

        buttonGroup.add(radio);
        radioPanel.add(radio);
        if (search.equals(selectedSearch)) {
            radio.setSelected(true);
        }
    }

    genPanel.add(radioPanel);

    final JTextField sampleField = new JTextField("");
    sampleField.setEditable(false);

    JLabel locationLabel = new JLabel("Download location");
    locationLabel.setToolTipText("The folder pattern where you want the file to be downloaded in.");

    JLabel legendsLabel = new JLabel(
            "<html><body>Field names: %user%, %artist%, %title%, %id%, %filename%, %collection%, %ext%<br></br>Example:</body></html>");
    legendsLabel.setToolTipText("An example of where a file will be downloaded to.");

    locationString = new StringBuilder();
    locationField = new JTextField(config.getProperty(Constants.LOCATION));
    locationField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationString.setLength(0);
            locationString.append(dest.getAbsolutePath());
            sampleField.setText(locationString.toString());
            if (useSameForMatureBox.isSelected()) {
                locationMatureString.setLength(0);
                locationMatureString.append(sampleField.getText());
                locationMatureField.setText(locationField.getText());
            }
        }

        public void keyTyped(KeyEvent e) {
        }

    });
    locationField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });
    JLabel locationMatureLabel = new JLabel("Mature download location");
    locationMatureLabel.setToolTipText(
            "The folder pattern where you want the file marked as 'Mature' to be downloaded in.");

    locationMatureString = new StringBuilder();
    locationMatureField = new JTextField(config.getProperty(Constants.MATURE));
    locationMatureField.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
            // TODO Auto-generated method stub

        }

        public void keyReleased(KeyEvent e) {
            File dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
                    sample.getImageFilename());
            locationMatureString.setLength(0);
            locationMatureString.append(dest.getAbsolutePath());
            sampleField.setText(locationMatureString.toString());
        }

        public void keyTyped(KeyEvent e) {
        }

    });

    locationMatureField.addMouseListener(new MouseListener() {
        public void mouseReleased(MouseEvent e) {
        }

        public void mousePressed(MouseEvent e) {
        }

        public void mouseExited(MouseEvent e) {
            sampleField.setText(locationString.toString());
        }

        public void mouseEntered(MouseEvent e) {
            sampleField.setText(locationMatureString.toString());
        }

        public void mouseClicked(MouseEvent e) {
        }
    });

    useSameForMatureBox = new JCheckBox("Use same location for mature deviation?");
    useSameForMatureBox.setSelected(locationLabel.getText().equals(locationMatureField.getText()));
    useSameForMatureBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            if (useSameForMatureBox.isSelected()) {
                locationMatureField.setEditable(false);
                locationMatureField.setText(locationField.getText());
                locationMatureString.setLength(0);
                locationMatureString.append(locationString);
            } else {
                locationMatureField.setEditable(true);
            }

        }
    });

    File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    sampleField.setText(dest.getAbsolutePath());
    locationString.append(sampleField.getText());

    dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample,
            sample.getImageFilename());
    locationMatureString.append(dest.getAbsolutePath());

    locationLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationField.setMaximumSize(new Dimension(Integer.MAX_VALUE, locationField.getFont().getSize() * 2));
    locationMatureLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    locationMatureField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    locationMatureField
            .setMaximumSize(new Dimension(Integer.MAX_VALUE, locationMatureField.getFont().getSize() * 2));
    useSameForMatureBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    legendsLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    legendsLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, legendsLabel.getFont().getSize() * 2));
    sampleField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    sampleField.setMaximumSize(new Dimension(Integer.MAX_VALUE, sampleField.getFont().getSize() * 2));

    genPanel.add(locationLabel);
    genPanel.add(locationField);

    genPanel.add(locationMatureLabel);
    genPanel.add(locationMatureField);
    genPanel.add(useSameForMatureBox);

    genPanel.add(legendsLabel);
    genPanel.add(sampleField);
    genPanel.add(Box.createVerticalBox());

    final KeyListener prxChangeListener = new KeyListener() {

        public void keyTyped(KeyEvent e) {
            proxyChangeState = true;
        }

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
        }
    };

    JPanel prxPanel = new JPanel();
    BoxLayout prxLayout = new BoxLayout(prxPanel, BoxLayout.Y_AXIS);
    prxPanel.setLayout(prxLayout);
    panes.add("Proxy", prxPanel);

    JLabel prxHostLabel = new JLabel("Proxy Host");
    prxHostLabel.setToolTipText("The hostname of the proxy server");
    prxHostField = new JTextField(config.getProperty(Constants.PROXY_HOST));
    prxHostLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxHostField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxHostField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxHostField.getFont().getSize() * 2));

    JLabel prxPortLabel = new JLabel("Proxy Port");
    prxPortLabel.setToolTipText("The port of the proxy server (Default 80).");

    prxPortSpinner = new JSpinner();
    prxPortSpinner.setModel(new SpinnerNumberModel(
            Integer.parseInt(config.getProperty(Constants.PROXY_PORT, "80")), 1, 65535, 1));

    prxPortLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPortSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPortSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPortSpinner.getFont().getSize() * 2));

    JLabel prxUserLabel = new JLabel("Proxy username");
    prxUserLabel.setToolTipText("The username used for authentication, if applicable.");
    prxUserField = new JTextField(config.getProperty(Constants.PROXY_USERNAME));
    prxUserLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxUserField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxUserField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxUserField.getFont().getSize() * 2));

    JLabel prxPassLabel = new JLabel("Proxy username");
    prxPassLabel.setToolTipText("The username used for authentication, if applicable.");
    prxPassField = new JPasswordField(config.getProperty(Constants.PROXY_PASSWORD));
    prxPassLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    prxPassField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    prxPassField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPassField.getFont().getSize() * 2));

    prxUseBox = new JCheckBox("Use a proxy?");
    prxUseBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            prxChangeListener.keyTyped(null);

            if (prxUseBox.isSelected()) {
                prxHostField.setEditable(true);
                prxPortSpinner.setEnabled(true);
                prxUserField.setEditable(true);
                prxPassField.setEditable(true);

            } else {
                prxHostField.setEditable(false);
                prxPortSpinner.setEnabled(false);
                prxUserField.setEditable(false);
                prxPassField.setEditable(false);
            }
        }
    });

    prxUseBox.setSelected(!Boolean.parseBoolean(config.getProperty(Constants.PROXY_USE)));
    prxUseBox.doClick();
    proxyChangeState = false;

    prxHostField.addKeyListener(prxChangeListener);
    prxUserField.addKeyListener(prxChangeListener);
    prxPassField.addKeyListener(prxChangeListener);
    prxPortSpinner.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            proxyChangeState = true;
        }
    });
    prxPanel.add(prxUseBox);

    prxPanel.add(prxHostLabel);
    prxPanel.add(prxHostField);

    prxPanel.add(prxPortLabel);
    prxPanel.add(prxPortSpinner);

    prxPanel.add(prxUserLabel);
    prxPanel.add(prxUserField);

    prxPanel.add(prxPassLabel);
    prxPanel.add(prxPassField);
    prxPanel.add(Box.createVerticalBox());

    final JPanel advPanel = new JPanel();
    BoxLayout advLayout = new BoxLayout(advPanel, BoxLayout.Y_AXIS);
    advPanel.setLayout(advLayout);
    panes.add("Advanced", advPanel);
    panes.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            JTabbedPane pane = (JTabbedPane) e.getSource();

            if (proxyChangeState && pane.getSelectedComponent() == advPanel) {
                Properties properties = new Properties();
                properties.setProperty(Constants.PROXY_USERNAME, prxUserField.getText().trim());
                properties.setProperty(Constants.PROXY_PASSWORD, new String(prxPassField.getPassword()).trim());
                properties.setProperty(Constants.PROXY_HOST, prxHostField.getText().trim());
                properties.setProperty(Constants.PROXY_PORT, prxPortSpinner.getValue().toString());
                properties.setProperty(Constants.PROXY_USE, Boolean.toString(prxUseBox.isSelected()));
                ProxyCfg prx = ProxyCfg.parseConfig(properties);
                setProxy(prx);
                revalidateSearcher(null);
            }
        }
    });
    JLabel domainLabel = new JLabel("Deviant Art domain name");
    domainLabel.setToolTipText("The deviantART main domain, should it ever change.");

    domainField = new JTextField(config.getProperty(Constants.DOMAIN));
    domainLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    domainField.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    domainField.setMaximumSize(new Dimension(Integer.MAX_VALUE, domainField.getFont().getSize() * 2));

    advPanel.add(domainLabel);
    advPanel.add(domainField);

    JLabel throttleLabel = new JLabel("Throttle search delay");
    throttleLabel.setToolTipText(
            "Slow down search query by inserting a pause between them. This help prevent abuse when doing a massive download.");

    throttleSpinner = new JSpinner();
    throttleSpinner.setModel(
            new SpinnerNumberModel(Integer.parseInt(config.getProperty(Constants.THROTTLE, "0")), 5, 60, 1));

    throttleLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    throttleSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    throttleSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, throttleSpinner.getFont().getSize() * 2));

    advPanel.add(throttleLabel);
    advPanel.add(throttleSpinner);

    JLabel searcherLabel = new JLabel("Searcher");
    searcherLabel.setToolTipText("Select a searcher that will look for your favorites.");

    searcherBox = new JComboBox();
    searcherBox.setRenderer(new TogglingRenderer());

    final AtomicInteger index = new AtomicInteger(0);
    searcherBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox combo = (JComboBox) e.getSource();
            Object selectedItem = combo.getSelectedItem();
            if (selectedItem instanceof SearchItem) {
                SearchItem item = (SearchItem) selectedItem;
                if (item.isValid) {
                    index.set(combo.getSelectedIndex());
                } else {
                    combo.setSelectedIndex(index.get());
                }
            }
        }
    });

    try {
        for (Class<Search> clazz : SearcherClassCache.getInstance().getClasses()) {

            Search searcher = clazz.newInstance();
            String name = searcher.getName();

            SearchItem item = new SearchItem(name, clazz.getName(), true);
            searcherBox.addItem(item);
        }
        String selectedClazz = config.getProperty(Constants.SEARCHER,
                com.dragoniade.deviantart.deviation.SearchRss.class.getName());
        revalidateSearcher(selectedClazz);
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }

    searcherLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherLabel.setBorder(new EmptyBorder(0, 5, 0, 5));
    searcherBox.setAlignmentX(JLabel.LEFT_ALIGNMENT);
    searcherBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, searcherBox.getFont().getSize() * 2));

    advPanel.add(searcherLabel);
    advPanel.add(searcherBox);

    advPanel.add(Box.createVerticalBox());

    add(panes, BorderLayout.CENTER);

    JButton saveBut = new JButton("Save");

    userField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            if (field.getText().trim().length() == 0) {
                JOptionPane.showMessageDialog(input, "The user musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The location must contains at least a %filename% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    locationMatureField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String content = field.getText().trim();
            if (content.length() == 0) {
                JOptionPane.showMessageDialog(input, "The Mature location musn't be empty.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (!content.contains("%filename%") && !content.contains("%id%")) {
                JOptionPane.showMessageDialog(input,
                        "The Mature location must contains at least a %username% or an %id% field.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }
            return true;
        }
    });

    domainField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            JTextField field = (JTextField) input;
            String domain = field.getText().trim();
            if (domain.length() == 0) {
                JOptionPane.showMessageDialog(input, "You must specify the deviantART main domain.", "Warning",
                        JOptionPane.WARNING_MESSAGE);
                return false;
            }

            if (domain.toLowerCase().startsWith("http://")) {
                JOptionPane.showMessageDialog(input,
                        "You must specify the deviantART main domain, not the full URL (aka www.deviantart.com).",
                        "Warning", JOptionPane.WARNING_MESSAGE);
                return false;
            }

            return true;
        }
    });
    locationField.setVerifyInputWhenFocusTarget(true);

    final JDialog parent = this;
    saveBut.addActionListener(new ActionListener() {

        String errorMsg = "The location is invalid or cannot be written to.";

        public void actionPerformed(ActionEvent e) {

            String username = userField.getText().trim();
            String location = locationField.getText().trim();
            String locationMature = locationMatureField.getText().trim();
            String domain = domainField.getText().trim();
            String throttle = throttleSpinner.getValue().toString();
            String searcher = searcherBox.getSelectedItem().toString();

            String prxUse = Boolean.toString(prxUseBox.isSelected());
            String prxHost = prxHostField.getText().trim();
            String prxPort = prxPortSpinner.getValue().toString();
            String prxUsername = prxUserField.getText().trim();
            String prxPassword = new String(prxPassField.getPassword()).trim();

            if (!testPath(location, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }
            if (!testPath(locationMature, username)) {
                JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE);
            }

            Properties p = new Properties();
            p.setProperty(Constants.USERNAME, username);
            p.setProperty(Constants.LOCATION, location);
            p.setProperty(Constants.MATURE, locationMature);
            p.setProperty(Constants.DOMAIN, domain);
            p.setProperty(Constants.THROTTLE, throttle);
            p.setProperty(Constants.SEARCHER, searcher);
            p.setProperty(Constants.SEARCH, selectedSearch.getId());

            p.setProperty(Constants.PROXY_USE, prxUse);
            p.setProperty(Constants.PROXY_HOST, prxHost);
            p.setProperty(Constants.PROXY_PORT, prxPort);
            p.setProperty(Constants.PROXY_USERNAME, prxUsername);
            p.setProperty(Constants.PROXY_PASSWORD, prxPassword);

            owner.savePreferences(p);
            parent.dispose();
        }
    });

    JButton cancelBut = new JButton("Cancel");
    cancelBut.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            parent.dispose();
        }
    });

    JPanel buttonPanel = new JPanel();
    BoxLayout butLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS);
    buttonPanel.setLayout(butLayout);

    buttonPanel.add(saveBut);
    buttonPanel.add(cancelBut);
    add(buttonPanel, BorderLayout.SOUTH);

    pack();
    setResizable(false);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    this.setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2);
    setVisible(true);
}

From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java

private void appendPopulationSpinner(GridBagLayout gridBagLayout, GridBagConstraints constraints,
        JPanel mainPanel) {/*from w w  w.  j a v a 2  s. c o m*/
    SpinnerModel populationModel = new SpinnerNumberModel(populationInitial, POPULATION_MIN, POPULATION_MAX,
            POPULATION_STEP);
    populationSpinner = new JSpinner(populationModel);
    JLabel populationLabel = new JLabel(populationText);
    populationLabel.setLabelFor(populationSpinner);

    constraints.weightx = LAYOUT_LABEL_WEIGHT;
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    gridBagLayout.setConstraints(populationLabel, constraints);
    mainPanel.add(populationLabel);
    constraints.weightx = LAYOUT_INPUT_WEIGHT;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(populationSpinner, constraints);
    mainPanel.add(populationSpinner);
}

From source file:org.adamkrajcik.gui.MainForm.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.//from   w  ww .j  a  v  a 2s .  c  o  m
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    cellarDialog = new javax.swing.JDialog();
    cellar_nameLabel = new javax.swing.JLabel();
    cellar_nameInput = new javax.swing.JTextField();
    cellar_addressLabel = new javax.swing.JLabel();
    cellar_capacityLabel = new javax.swing.JLabel();
    cellar_addressInput = new javax.swing.JTextField();
    cellar_capacitySpinner = new javax.swing.JSpinner();
    cellar_createButton = new javax.swing.JButton();
    cellar_cancelButton = new javax.swing.JButton();
    cellar_errorLabel = new javax.swing.JLabel();
    wineDialog = new javax.swing.JDialog();
    wine_nameLabel = new javax.swing.JLabel();
    wine_countryLabel = new javax.swing.JLabel();
    wine_vintageLabel = new javax.swing.JLabel();
    wine_quantityLabel = new javax.swing.JLabel();
    wine_typeLabel = new javax.swing.JLabel();
    wine_nameInput = new javax.swing.JTextField();
    wine_countryInput = new javax.swing.JTextField();
    wine_vintageInput = new javax.swing.JSpinner();
    wine_quantityInput = new javax.swing.JSpinner();
    wine_typeInput = new javax.swing.JComboBox();
    wine_createButton = new javax.swing.JButton();
    wine_cancelButton = new javax.swing.JButton();
    wine_errorLabel = new javax.swing.JLabel();
    tabbedPanel = new javax.swing.JTabbedPane();
    winePanel = new javax.swing.JPanel();
    jScrollPane2 = new javax.swing.JScrollPane();
    WineTable = new javax.swing.JTable();
    wineFilterPanel = new javax.swing.JPanel();
    ResetFilterButton = new javax.swing.JButton();
    FilterLabel = new javax.swing.JLabel();
    cellarPanel = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    CellarTable = new javax.swing.JTable();
    menuBar = new javax.swing.JMenuBar();
    wineMenu = new javax.swing.JMenu();
    createWineMenuItem = new javax.swing.JMenuItem();
    deleteWineMenuItem = new javax.swing.JMenuItem();
    putWineToCellarMenuItem = new javax.swing.JMenuItem();
    removeFromCellarMenuItem = new javax.swing.JMenuItem();
    jSeparator1 = new javax.swing.JPopupMenu.Separator();
    loadAllWinesMenuItem = new javax.swing.JMenuItem();
    cellarMenu = new javax.swing.JMenu();
    createCellarMenuItem = new javax.swing.JMenuItem();
    deleteCellarMenuItem = new javax.swing.JMenuItem();
    jSeparator2 = new javax.swing.JPopupMenu.Separator();
    findWinesMenuItem = new javax.swing.JMenuItem();
    loadAllCellarsMenuItem = new javax.swing.JMenuItem();

    java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/adamkrajcik/gui/resources/lang"); // NOI18N
    cellarDialog.setTitle(bundle.getString("newCellar")); // NOI18N
    cellarDialog.setResizable(false);
    cellarDialog.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosed(java.awt.event.WindowEvent evt) {
            cellarDialogWindowClosed(evt);
        }
    });

    cellar_nameLabel.setText(bundle.getString("name")); // NOI18N

    cellar_addressLabel.setText(bundle.getString("address")); // NOI18N

    cellar_capacityLabel.setText(bundle.getString("wineCapacity")); // NOI18N

    cellar_capacitySpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1),
            null, Integer.valueOf(1)));

    cellar_createButton.setText(bundle.getString("create")); // NOI18N
    cellar_createButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            cellar_createButtonActionPerformed(evt);
        }
    });

    cellar_cancelButton.setText(bundle.getString("cancel")); // NOI18N
    cellar_cancelButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            cellar_cancelButtonActionPerformed(evt);
        }
    });

    cellar_errorLabel.setFont(new java.awt.Font("Cantarell", 1, 18)); // NOI18N
    cellar_errorLabel.setForeground(new java.awt.Color(255, 32, 0));
    cellar_errorLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

    javax.swing.GroupLayout cellarDialogLayout = new javax.swing.GroupLayout(cellarDialog.getContentPane());
    cellarDialog.getContentPane().setLayout(cellarDialogLayout);
    cellarDialogLayout.setHorizontalGroup(cellarDialogLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cellarDialogLayout.createSequentialGroup().addGroup(cellarDialogLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(cellarDialogLayout.createSequentialGroup().addGap(36, 36, 36)
                            .addGroup(cellarDialogLayout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(cellar_addressLabel).addComponent(cellar_nameLabel)
                                    .addComponent(cellar_capacityLabel))
                            .addGap(18, 18, 18)
                            .addGroup(cellarDialogLayout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cellar_addressInput).addComponent(cellar_nameInput)
                                    .addComponent(cellar_capacitySpinner, javax.swing.GroupLayout.DEFAULT_SIZE,
                                            150, Short.MAX_VALUE))
                            .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(cellarDialogLayout.createSequentialGroup()
                            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(cellar_createButton)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(cellar_cancelButton))
                    .addGroup(cellarDialogLayout.createSequentialGroup().addContainerGap().addComponent(
                            cellar_errorLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addContainerGap()));
    cellarDialogLayout.setVerticalGroup(cellarDialogLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, cellarDialogLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(cellar_errorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 22,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(cellarDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cellar_nameLabel).addComponent(cellar_nameInput,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(cellarDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cellar_addressLabel).addComponent(cellar_addressInput,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(cellarDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cellar_capacitySpinner, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cellar_capacityLabel))
                    .addGap(18, 18, 18)
                    .addGroup(cellarDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cellar_createButton).addComponent(cellar_cancelButton))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

    wineDialog.setTitle(bundle.getString("newWine")); // NOI18N
    wineDialog.setResizable(false);
    wineDialog.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosed(java.awt.event.WindowEvent evt) {
            wineDialogWindowClosed(evt);
        }
    });

    wine_nameLabel.setText(bundle.getString("name")); // NOI18N

    wine_countryLabel.setText(bundle.getString("country")); // NOI18N

    wine_vintageLabel.setText(bundle.getString("vintage")); // NOI18N

    wine_quantityLabel.setText(bundle.getString("quantity")); // NOI18N

    wine_typeLabel.setText(bundle.getString("wineType")); // NOI18N

    wine_nameInput.setToolTipText("");

    wine_vintageInput.setModel(new SpinnerNumberModel((short) Calendar.getInstance().get(Calendar.YEAR),
            (short) 1700, (short) Calendar.getInstance().get(Calendar.YEAR), (short) 1));

    wine_quantityInput.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(20), Integer.valueOf(1),
            null, Integer.valueOf(1)));

    wine_typeInput.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "RED", "WHITE", "ROSE" }));

    wine_createButton.setText(bundle.getString("create")); // NOI18N

    wine_cancelButton.setText(bundle.getString("cancel")); // NOI18N

    javax.swing.GroupLayout wineDialogLayout = new javax.swing.GroupLayout(wineDialog.getContentPane());
    wineDialog.getContentPane().setLayout(wineDialogLayout);
    wineDialogLayout.setHorizontalGroup(wineDialogLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(wineDialogLayout.createSequentialGroup().addContainerGap().addGroup(wineDialogLayout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(wineDialogLayout
                            .createSequentialGroup()
                            .addGroup(wineDialogLayout
                                    .createParallelGroup(
                                            javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(wine_typeLabel).addComponent(wine_quantityLabel)
                                    .addComponent(wine_vintageLabel).addComponent(wine_countryLabel)
                                    .addComponent(wine_nameLabel))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(wineDialogLayout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, wineDialogLayout
                                            .createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                                            .addComponent(wine_createButton,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE, 80,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                            .addComponent(wine_cancelButton,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE, 80,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addGap(12, 12, 12))
                                    .addGroup(
                                            wineDialogLayout
                                                    .createParallelGroup(
                                                            javax.swing.GroupLayout.Alignment.LEADING, false)
                                                    .addComponent(wine_nameInput)
                                                    .addComponent(wine_countryInput,
                                                            javax.swing.GroupLayout.PREFERRED_SIZE, 300,
                                                            javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(wine_vintageInput)
                                                    .addComponent(wine_quantityInput,
                                                            javax.swing.GroupLayout.PREFERRED_SIZE, 150,
                                                            javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(wine_typeInput, javax.swing.GroupLayout.PREFERRED_SIZE, 150,
                                            javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(wine_errorLabel, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap()));
    wineDialogLayout.setVerticalGroup(wineDialogLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, wineDialogLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(wine_errorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(wineDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(wine_nameLabel).addComponent(wine_nameInput,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(wineDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(wine_countryLabel).addComponent(wine_countryInput,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(wineDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(wine_vintageLabel).addComponent(wine_vintageInput,
                                    javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(wineDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(wine_quantityInput, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(wine_quantityLabel))
                    .addGap(18, 18, 18)
                    .addGroup(wineDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(wine_typeInput, javax.swing.GroupLayout.PREFERRED_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(wine_typeLabel))
                    .addGap(18, 18, 18)
                    .addGroup(wineDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(wine_createButton).addComponent(wine_cancelButton))
                    .addContainerGap(32, Short.MAX_VALUE)));

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("WineCellarsManager");

    tabbedPanel.setName(""); // NOI18N

    WineTable.setModel(wineTableModel);
    jScrollPane2.setViewportView(WineTable);

    wineFilterPanel.setBackground(new java.awt.Color(255, 115, 115));

    ResetFilterButton.setText(bundle.getString("clearFilter")); // NOI18N
    ResetFilterButton.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            ResetFilterButtonActionPerformed(evt);
        }
    });

    FilterLabel.setText("Wines in cellar: name address capacity:");

    javax.swing.GroupLayout wineFilterPanelLayout = new javax.swing.GroupLayout(wineFilterPanel);
    wineFilterPanel.setLayout(wineFilterPanelLayout);
    wineFilterPanelLayout.setHorizontalGroup(wineFilterPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, wineFilterPanelLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(FilterLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 408,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 365, Short.MAX_VALUE)
                    .addComponent(ResetFilterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 107,
                            javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap()));
    wineFilterPanelLayout.setVerticalGroup(
            wineFilterPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                            wineFilterPanelLayout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(ResetFilterButton).addComponent(FilterLabel)));

    javax.swing.GroupLayout winePanelLayout = new javax.swing.GroupLayout(winePanel);
    winePanel.setLayout(winePanelLayout);
    winePanelLayout.setHorizontalGroup(winePanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(winePanelLayout.createSequentialGroup().addContainerGap()
                    .addGroup(winePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(wineFilterPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
                                    javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap()));
    winePanelLayout.setVerticalGroup(winePanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(winePanelLayout.createSequentialGroup().addContainerGap()
                    .addComponent(wineFilterPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
                            javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 437, Short.MAX_VALUE)
                    .addContainerGap()));

    tabbedPanel.addTab(bundle.getString("wines"), winePanel); // NOI18N

    CellarTable.setModel(cellarTableModel);
    CellarTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    jScrollPane1.setViewportView(CellarTable);

    javax.swing.GroupLayout cellarPanelLayout = new javax.swing.GroupLayout(cellarPanel);
    cellarPanel.setLayout(cellarPanelLayout);
    cellarPanelLayout.setHorizontalGroup(cellarPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cellarPanelLayout.createSequentialGroup().addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 904, Short.MAX_VALUE)
                    .addContainerGap()));
    cellarPanelLayout.setVerticalGroup(cellarPanelLayout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cellarPanelLayout.createSequentialGroup().addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
                    .addContainerGap()));

    tabbedPanel.addTab(bundle.getString("cellars"), cellarPanel); // NOI18N

    wineMenu.setText(bundle.getString("wine")); // NOI18N

    createWineMenuItem.setText(bundle.getString("create")); // NOI18N
    createWineMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            createWineMenuItemActionPerformed(evt);
        }
    });
    wineMenu.add(createWineMenuItem);

    deleteWineMenuItem.setText(bundle.getString("delete")); // NOI18N
    deleteWineMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            deleteWineMenuItemActionPerformed(evt);
        }
    });
    wineMenu.add(deleteWineMenuItem);

    putWineToCellarMenuItem.setText(bundle.getString("putToCellar")); // NOI18N
    putWineToCellarMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            putWineToCellarMenuItemActionPerformed(evt);
        }
    });
    wineMenu.add(putWineToCellarMenuItem);

    removeFromCellarMenuItem.setText(bundle.getString("removeFromCellar")); // NOI18N
    removeFromCellarMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            removeFromCellarMenuItemActionPerformed(evt);
        }
    });
    wineMenu.add(removeFromCellarMenuItem);
    wineMenu.add(jSeparator1);

    loadAllWinesMenuItem.setText(bundle.getString("loadWines")); // NOI18N
    loadAllWinesMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            loadAllWinesMenuItemActionPerformed(evt);
        }
    });
    wineMenu.add(loadAllWinesMenuItem);

    menuBar.add(wineMenu);

    cellarMenu.setText(bundle.getString("cellar")); // NOI18N

    createCellarMenuItem.setText(bundle.getString("create")); // NOI18N
    createCellarMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            createCellarMenuItemActionPerformed(evt);
        }
    });
    cellarMenu.add(createCellarMenuItem);

    deleteCellarMenuItem.setText(bundle.getString("delete")); // NOI18N
    deleteCellarMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            deleteCellarMenuItemActionPerformed(evt);
        }
    });
    cellarMenu.add(deleteCellarMenuItem);
    cellarMenu.add(jSeparator2);

    findWinesMenuItem.setText(bundle.getString("findWines")); // NOI18N
    findWinesMenuItem.setToolTipText("");
    findWinesMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            findWinesMenuItemActionPerformed(evt);
        }
    });
    cellarMenu.add(findWinesMenuItem);

    loadAllCellarsMenuItem.setText(bundle.getString("loadCellars")); // NOI18N
    loadAllCellarsMenuItem.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            loadAllCellarsMenuItemActionPerformed(evt);
        }
    });
    cellarMenu.add(loadAllCellarsMenuItem);

    menuBar.add(cellarMenu);

    setJMenuBar(menuBar);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
            layout.createSequentialGroup().addContainerGap().addComponent(tabbedPanel).addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addComponent(tabbedPanel).addContainerGap()));

    tabbedPanel.getAccessibleContext().setAccessibleName("");

    pack();
}

From source file:coreferenceresolver.gui.MarkupGUI.java

private JScrollPane newMarkupPanel(NounPhrase np, ReviewElement reviewElement) {
    //MODEL//from w w w.  ja va  2  s .co m
    Element element = new Element();

    //Newly added
    ScrollablePanel markupPanel = new ScrollablePanel();
    markupPanel.setLayout(new BoxLayout(markupPanel, BoxLayout.X_AXIS));
    markupPanel.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.FIT);

    JTextArea npContentTxtArea = new JTextArea();
    npContentTxtArea.setEditable(false);
    npContentTxtArea.setText(((MarkupNounPhrase) np).content);
    markupPanel.add(npContentTxtArea);

    //REF
    SpinnerModel refSpinnerModel = new SpinnerNumberModel(np.getChainId(), -1, COLORS.length - 1, 1);
    JSpinner refSpinner = new JSpinner(refSpinnerModel);
    refSpinner.setValue(np.getChainId());

    refSpinner.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            np.setChainId((int) refSpinner.getValue());
            try {
                rePaint(reviewElements.get(np.getReviewId()), np);
            } catch (BadLocationException ex) {
                Logger.getLogger(MarkupGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });

    element.refSpinner = refSpinner;

    //TYPE        
    String[] typeValues = { "Object", "Other", "Candidate", "Attribute" };
    SpinnerModel typeSpinnerModel = new SpinnerListModel(typeValues);
    JSpinner typeSpinner = new JSpinner(typeSpinnerModel);
    typeSpinner.setValue(typeValues[np.getType()]);

    element.typeSpinner = typeSpinner;

    //REF + TYPE
    ScrollablePanel spinners = new ScrollablePanel();
    spinners.setLayout(new BoxLayout(spinners, BoxLayout.X_AXIS));
    spinners.setScrollableWidth(ScrollablePanel.ScrollableSizeHint.FIT);
    spinners.add(refSpinner);
    spinners.add(typeSpinner);
    markupPanel.add(spinners);

    reviewElement.addElement(element);

    JScrollPane scrollMarkupPanel = new JScrollPane(markupPanel);

    return scrollMarkupPanel;
}

From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java

private void appendLifespanSpinner(GridBagLayout gridBagLayout, GridBagConstraints constraints,
        JPanel mainPanel) {/*from   w w  w  .  ja  va  2  s. c  o  m*/
    SpinnerModel lifespanModel = new SpinnerNumberModel(lifespanInitial, LIFESPAN_MIN, LIFESPAN_MAX,
            LIFESPAN_STEP);
    lifespanSpinner = new JSpinner(lifespanModel);
    JLabel lifespanLabel = new JLabel(lifespanText);
    lifespanLabel.setLabelFor(lifespanSpinner);

    constraints.weightx = LAYOUT_LABEL_WEIGHT;
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    gridBagLayout.setConstraints(lifespanLabel, constraints);
    mainPanel.add(lifespanLabel);
    constraints.weightx = LAYOUT_INPUT_WEIGHT;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(lifespanSpinner, constraints);
    mainPanel.add(lifespanSpinner);
}

From source file:view.caja.Despacho.java

private void initGUI() {
    try {//from   w ww .  j a  va 2  s. c o  m
        {
            panRoot = new JPanel();
            getContentPane().add(panRoot, BorderLayout.CENTER);
            panRoot.setLayout(null);
            panRoot.setPreferredSize(new java.awt.Dimension(810, 498));
            {
                scrollProds = getTablaProductos();
                panRoot.add(scrollProds);
                scrollProds.setBounds(15, 106, 390, 287);
            }
            {
                lbTitulo = new JLabel();
                panRoot.add(lbTitulo);
                lbTitulo.setText("LISTA DE PRODUCTOS :");
                lbTitulo.setFont(new Font("Helvetica", Font.BOLD, 15));
                lbTitulo.setBounds(15, 76, 243, 16);
            }
            {
                lbTituloCodigo = new JLabel();
                panRoot.add(lbTituloCodigo);
                lbTituloCodigo.setText("Agregando Productos");
                lbTituloCodigo.setFont(new Font("Helvetica", Font.BOLD, 15));
                lbTituloCodigo.setBounds(572, 179, 168, 16);
            }
            {
                btAdd = new JButton();
                panRoot.add(btAdd);
                btAdd.setBounds(529, 220, 57, 45);
                btAdd.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/add.png")));
                btAdd.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        agregarNuevoProductoParaVender();
                    }
                });
            }
            {
                btQuitar = new JButton();
                panRoot.add(btQuitar);
                btQuitar.setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/delete.png")));
                btQuitar.setBounds(529, 270, 57, 48);
                btQuitar.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        quitarFila();
                    }
                });
                btQuitar.setEnabled(false);
            }
            {
                btRemoveAll = new JButton();
                panRoot.add(btRemoveAll);
                btRemoveAll.setBounds(532, 324, 54, 54);
                btRemoveAll
                        .setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/deleteAll.png")));
                btRemoveAll.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        quitarTodo();
                    }
                });
                btRemoveAll.setEnabled(false);
            }
            {
                lbTituloForm = new JLabel();
                panRoot.add(lbTituloForm);
                lbTituloForm.setText("REALIZANDO VENTA");
                lbTituloForm.setBounds(241, 20, 253, 44);
                lbTituloForm.setFont(new Font("Monospaced", Font.BOLD, 25));
            }
            {
                jlblAniadir = new JLabel();
                panRoot.add(jlblAniadir);
                jlblAniadir.setText("Aadir");
                jlblAniadir.setFont(new Font("Helvetica", Font.BOLD, 13));
                jlblAniadir.setBounds(592, 230, 68, 23);
            }
            {
                jlblQuitar = new JLabel();
                panRoot.add(jlblQuitar);
                jlblQuitar.setText("Quitar");
                jlblQuitar.setFont(new Font("Helvetica", Font.BOLD, 13));
                jlblQuitar.setBounds(592, 281, 68, 16);
            }
            {
                jlblQuitarTodos = new JLabel();
                panRoot.add(jlblQuitarTodos);
                jlblQuitarTodos.setText("Quitar Todos");
                jlblQuitarTodos.setFont(new Font("Helvetica", Font.BOLD, 13));
                jlblQuitarTodos.setBounds(592, 338, 88, 16);
            }
            {
                jbtnConfirmar = new JButton();
                panRoot.add(jbtnConfirmar);
                jbtnConfirmar.setText("   Confirmar");
                jbtnConfirmar
                        .setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/acepted3.png")));
                jbtnConfirmar.setBounds(85, 412, 167, 62);
                jbtnConfirmar.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        if (contador != 0 && jtxtCampo.getText() != "" && jtxtnit.getText() != "") {
                            cambio = aCobrar - Double.parseDouble(jspn.getValue().toString());
                            efectuar();
                            JOptionPane.showMessageDialog(null, "Se debe dar el cambio de " + cambio, "Alerta",
                                    2);
                        } else {
                            JOptionPane.showMessageDialog(null, "Existen Campos Obligatorios para la venta",
                                    "Alerta", 2);
                        }

                    }

                    public void efectuar() {
                        FactoryFactura factFactura = new FactoryFactura();
                        int idFactura = 0;
                        int idCliente = comprador.getId_Cliente();
                        int idUsuario = usuario.getIdusuario();
                        Factura fact = new Factura();
                        fact.setNit(comprador.getNit());
                        fact.setTotal(Float.parseFloat(Double.toString(aCobrar)));
                        fact.setCambio(Float.parseFloat(cambio + ""));
                        try {
                            idFactura = factFactura.insertFactura(fact);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        FactoryVenta factVenta = new FactoryVenta();
                        Venta nuevaVenta = new Venta();
                        nuevaVenta.setFechaVenta(factVenta.getFechaHoy());
                        nuevaVenta.setHventa(factVenta.getHora());
                        nuevaVenta.setId_Cliente(idCliente);
                        nuevaVenta.setId_factura(idFactura);
                        nuevaVenta.setId_Usario(idUsuario);
                        try {
                            if (factVenta.insertVenta(nuevaVenta)) {

                            }
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        FactoryDetalleVenta factDVenta = new FactoryDetalleVenta();
                        for (int i = 0; i < tbCarrito.getRowCount(); i++) {
                            int idprod = (Integer) tbCarrito.getValueAt(i, 5);
                            int idventaMax = factVenta.getIdMaximo();
                            int cantidad = (Integer) tbCarrito.getValueAt(i, 4);
                            try {
                                factDVenta.insertDetalleVenta(idprod, idventaMax, cantidad);
                            } catch (Exception e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                        setVisible(false);
                        JOptionPane.showMessageDialog(null, "La Venta se ha realizado exitosamente...",
                                "Felicidades", 1);

                    }
                });

            }
            {
                jbtnCancelar = new JButton();
                panRoot.add(jbtnCancelar);
                jbtnCancelar.setText("     Cancelar");
                jbtnCancelar
                        .setIcon(new ImageIcon(getClass().getClassLoader().getResource("img/cancelShop.png")));
                jbtnCancelar.setBounds(294, 413, 170, 60);
                jbtnCancelar.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent arg0) {
                        System.exit(0);
                    }
                });
            }
            {
                jlblDatosCliente = new JLabel();
                panRoot.add(jlblDatosCliente);
                jlblDatosCliente.setText("Datos de Cliente");
                jlblDatosCliente.setFont(new Font("Helvetica", Font.BOLD, 15));
                jlblDatosCliente.setBounds(580, 64, 126, 16);
            }
            {
                jlblNombre = new JLabel();
                panRoot.add(jlblNombre);
                jlblNombre.setText("Nombre : ");
                jlblNombre.setBounds(545, 138, 69, 18);
            }
            {
                jtxtCampo = new JTextField();
                panRoot.add(jtxtCampo);
                jtxtCampo.setBounds(603, 133, 137, 28);
            }
            {
                jtxtnit = new JTextField();
                panRoot.add(jtxtnit);
                jtxtnit.setBounds(602, 92, 140, 28);
                jtxtnit.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent evt) {
                        String cad = jtxtnit.getText();
                        comprador = clienteABuscar(cl, cad);
                        jtxtCampo.setText(comprador.getNombreCliente());
                        jtxtCampo.setEditable(false);
                    }
                });

                TextAutoCompleter autoCompl = new TextAutoCompleter(jtxtnit);
                for (int i = 0; i < cl.size(); i++) {
                    Cliente c = cl.get(i);
                    autoCompl.addItem(c.getNit());
                }
                autoCompl.setMode(0);

            }

            {
                jlblNit = new JLabel();
                panRoot.add(jlblNit);
                jlblNit.setText("Nit o CI :");
                jlblNit.setBounds(542, 99, 46, 16);
            }
            {
                jlblCantidad = new JLabel();
                panRoot.add(jlblCantidad);
                jlblCantidad.setText("Cantidad :");
                jlblCantidad.setFont(new Font("Helvetica", Font.BOLD, 15));
                jlblCantidad.setBounds(424, 169, 79, 16);
            }
            {
                jlblCantMostrar = new JLabel();
                panRoot.add(jlblCantMostrar);
                jlblCantMostrar.setBounds(435, 183, 68, 58);
                jlblCantMostrar.setText("0");
                jlblCantMostrar.setFont(new Font("Monospaced", Font.BOLD, 35));
            }
            {
                jlblACobrar = new JLabel();
                panRoot.add(jlblACobrar);
                jlblACobrar.setText("A Cobrar :");
                jlblACobrar.setFont(new Font("Helvetica", Font.BOLD, 15));
                jlblACobrar.setBounds(424, 270, 79, 16);
            }
            {
                jlblACobrarMostrar = new JLabel();
                panRoot.add(jlblACobrarMostrar);
                jlblACobrarMostrar.setBounds(430, 292, 68, 58);
                jlblACobrarMostrar.setText("0.0");
                jlblACobrarMostrar.setFont(new Font("Monospaced", Font.BOLD, 29));
            }
            {
                jlblPagado = new JLabel();
                panRoot.add(jlblPagado);
                jlblPagado.setText("Monto con el que se pago Bs :");
                jlblPagado.setBounds(532, 420, 168, 16);
            }
            {
                SpinnerNumberModel jSpinnerCantidadModel = new SpinnerNumberModel(0, 0, 1000, 1);
                jspn = new JSpinner();
                panRoot.add(jspn);
                jspn.setModel(jSpinnerCantidadModel);
                jspn.setBounds(706, 414, 59, 28);
            }
        }
        pack();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.ciphertool.zodiacengine.gui.view.SwingUserInterface.java

private void appendSurvivalRateSpinner(GridBagLayout gridBagLayout, GridBagConstraints constraints,
        JPanel mainPanel) {//from w  w  w . j a va2s  . c om
    SpinnerModel survivalRateModel = new SpinnerNumberModel(survivalInitial, SURVIVAL_MIN, SURVIVAL_MAX,
            SURVIVAL_STEP);
    survivalRateSpinner = new JSpinner(survivalRateModel);
    JLabel survivalRateLabel = new JLabel(survivalRateText);
    survivalRateLabel.setLabelFor(survivalRateSpinner);

    constraints.weightx = LAYOUT_LABEL_WEIGHT;
    constraints.gridwidth = GridBagConstraints.RELATIVE;
    gridBagLayout.setConstraints(survivalRateLabel, constraints);
    mainPanel.add(survivalRateLabel);
    constraints.weightx = LAYOUT_INPUT_WEIGHT;
    constraints.gridwidth = GridBagConstraints.REMAINDER;
    gridBagLayout.setConstraints(survivalRateSpinner, constraints);
    mainPanel.add(survivalRateSpinner);
}

From source file:edu.ku.brc.af.ui.db.DatabaseLoginPanel.java

/**
 * Creates the UI for the login and hooks up any listeners.
 * @param isDlg  whether the parent is a dialog (false mean JFrame)
 * @param iconName the icon that will be shown in the panel
 * @param engageUPPrefs whether it should load and save the username password into the prefs
 * @param helpContext the help context to use.
 *///  ww w .  j  a  v  a  2  s . co m
protected void createUI(final boolean isDlg, final String iconName, final String helpContext) {
    final boolean isNotEmbedded = !DBConnection.getInstance().isEmbedded() && !UIRegistry.isMobile();
    final AppPreferences localPrefs = AppPreferences.getLocalPrefs();

    //Font cachedFont = UIManager.getFont("JLabel.font");
    SkinItem skinItem = SkinsMgr.getSkinItem("LoginPanel");
    if (skinItem != null) {
        skinItem.pushFG("Label.foreground");
    }

    if (isNotEmbedded) {
        SpinnerModel portModel = new SpinnerNumberModel(3306, //initial value
                0, //min
                Integer.MAX_VALUE, //max
                1); //step
        portSpinner = new JSpinner(portModel);
        JSpinner.NumberEditor editor = new JSpinner.NumberEditor(portSpinner, "#");
        portSpinner.setEditor(editor);

        portSpinner.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                DatabaseDriverInfo drvInfo = dbDrivers.get(dbDriverCBX.getSelectedIndex());
                if (drvInfo != null && isNotEmbedded && portSpinner != null) {
                    drvInfo.setPort((Integer) portSpinner.getValue());
                }
            }
        });
        setControlSize(portSpinner);
    }

    // First create the controls and hook up listeners
    dbPickList = new PropertiesPickListAdapter("login.databases"); //$NON-NLS-1$
    svPickList = new PropertiesPickListAdapter("login.servers"); //$NON-NLS-1$

    username = createTextField(15);
    password = createPasswordField(15);

    FocusAdapter focusAdp = new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            super.focusGained(e);

            JTextField tf = (JTextField) e.getSource();
            tf.selectAll();
        }
    };
    username.addFocusListener(focusAdp);
    password.addFocusListener(focusAdp);

    databases = new ValComboBox(dbPickList);
    if (databases.getComboBox() instanceof Java2sAutoComboBox) {
        ((Java2sAutoComboBox) databases.getComboBox()).setCaseSensitive(true);
    }
    servers = new ValComboBox(svPickList);

    dbPickList.setComboBox(databases);
    svPickList.setComboBox(servers);

    setControlSize(password);
    setControlSize(databases);
    setControlSize(servers);

    if (masterUsrPwdProvider != null) {
        editKeyInfoBtn = UIHelper.createI18NButton("CONFIG_MSTR_KEY");
        editKeyInfoBtn.setIcon(IconManager.getIcon("Key", IconManager.IconSize.Std20));
        editKeyInfoBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (masterUsrPwdProvider != null && databases != null) {
                    String itemName = null;
                    if (databases.getComboBox().getSelectedItem() instanceof String) {
                        itemName = (String) databases.getComboBox().getSelectedItem();
                    } else {
                        PickListItemIFace pli = (PickListItemIFace) databases.getComboBox().getSelectedItem();
                        if (pli != null && pli.getValue() != null) {
                            itemName = pli.getValue();
                        }
                    }

                    if (itemName != null) {
                        masterUsrPwdProvider.editMasterInfo(username.getText(), itemName, false);
                    }
                }
            }
        });
    }

    rememberUsernameCBX = createCheckBox(getResourceString("rememberuser")); //$NON-NLS-1$
    rememberUsernameCBX.setEnabled(engageUPPrefs);

    statusBar = new JStatusBar();
    statusBar.setErrorIcon(IconManager.getIcon("Error", IconManager.IconSize.Std16)); //$NON-NLS-1$

    cancelBtn = createButton(getResourceString("CANCEL")); //$NON-NLS-1$
    loginBtn = createButton(getResourceString("Login")); //$NON-NLS-1$
    helpBtn = createButton(getResourceString("HELP")); //$NON-NLS-1$

    forwardImgIcon = IconManager.getIcon("Forward"); //$NON-NLS-1$
    downImgIcon = IconManager.getIcon("Down"); //$NON-NLS-1$
    moreBtn = new JCheckBox(getResourceString("LOGIN_DLG_MORE"), forwardImgIcon); // XXX I18N //$NON-NLS-1$
    setControlSize(moreBtn);

    // Extra
    dbDrivers = DatabaseDriverInfo.getDriversList();
    dbDriverCBX = createComboBox(dbDrivers);

    dbDriverCBX.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateUIControls();

            DatabaseDriverInfo drvInfo = dbDrivers.get(dbDriverCBX.getSelectedIndex());
            if (drvInfo != null && isNotEmbedded && portSpinner != null) {
                Integer defPort = drvInfo.getPortAsInt();
                int portFromPref = localPrefs.getInt(LOGIN_PORT, defPort);

                portSpinner.setValue(portFromPref);
                drvInfo.setPort(portFromPref);
            }
        }
    });

    if (dbDrivers.size() > 0) {
        if (dbDrivers.size() == 1) {
            dbDriverCBX.setSelectedIndex(0);
            dbDriverCBX.setEnabled(false);

        } else {
            String selectedStr = localPrefs.get("login.dbdriver_selected", "MySQL"); //$NON-NLS-1$ //$NON-NLS-2$
            int inx = Collections.binarySearch(dbDrivers,
                    new DatabaseDriverInfo(selectedStr, null, null, false, null));
            dbDriverCBX.setSelectedIndex(inx > -1 ? inx : -1);
        }

    } else {
        JOptionPane.showConfirmDialog(null, getResourceString("NO_DBDRIVERS"), //$NON-NLS-1$
                getResourceString("NO_DBDRIVERS_TITLE"), JOptionPane.CLOSED_OPTION); //$NON-NLS-1$
        System.exit(1);
    }

    addFocusListenerForTextComp(username);
    addFocusListenerForTextComp(password);

    addKeyListenerFor(username, !isDlg);
    addKeyListenerFor(password, !isDlg);

    addKeyListenerFor(databases.getTextField(), !isDlg);
    addKeyListenerFor(servers.getTextField(), !isDlg);

    if (!isDlg) {
        addKeyListenerFor(loginBtn, true);
    }

    rememberUsernameCBX.setSelected(engageUPPrefs ? localPrefs.getBoolean("login.rememberuser", false) : false); //$NON-NLS-1$

    cancelBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (dbListener != null) {
                dbListener.cancelled();
            }
        }
    });

    loginBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doLogin();
        }
    });

    HelpMgr.registerComponent(helpBtn, helpContext); //$NON-NLS-1$

    moreBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (extraPanel.isVisible()) {
                if (dbDriverCBX.getSelectedIndex() != -1) {
                    extraPanel.setVisible(false);
                    moreBtn.setIcon(forwardImgIcon);
                }

            } else {
                extraPanel.setVisible(true);
                moreBtn.setIcon(downImgIcon);
            }
            if (window != null) {
                window.pack();
            }
        }
    });

    // Ask the PropertiesPickListAdapter to set the index from the prefs
    dbPickList.setSelectedIndex();
    svPickList.setSelectedIndex();

    servers.getTextField().addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            updateUIControls();
        }
    });

    databases.getTextField().addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            updateUIControls();
        }
    });

    databases.getTextField().addFocusListener(new FocusAdapter() {
        String server = null;

        private String getServerStr() {
            String serverStr = null;
            Object serverObj = servers.getValue();
            if (serverObj != null) {
                serverStr = serverObj.toString();
            }
            return serverStr;
        }

        @Override
        public void focusGained(FocusEvent e) {
            server = getServerStr();
        }

        @Override
        public void focusLost(FocusEvent e) {
            if (server != null) {
                String newVal = getServerStr();
                if (newVal != null && !newVal.equals(server)) {
                    setUsrPwdControlsFromPrefs();
                }
            }
        }
    });

    setUsrPwdControlsFromPrefs();

    // Layout the form

    PanelBuilder formBuilder = new PanelBuilder(new FormLayout("p,3dlu,p:g", "p,2dlu,p,2dlu,p,2dlu,p,2dlu,p")); //$NON-NLS-1$ //$NON-NLS-2$
    CellConstraints cc = new CellConstraints();
    formBuilder.addSeparator(getResourceString("LOGINLABEL"), cc.xywh(1, 1, 3, 1)); //$NON-NLS-1$

    addLine("username", username, formBuilder, cc, 3); //$NON-NLS-1$
    addLine("password", password, formBuilder, cc, 5); //$NON-NLS-1$
    formBuilder.add(moreBtn, cc.xy(3, 7));

    PanelBuilder extraPanelBlder = new PanelBuilder(new FormLayout("p,3dlu,p:g", //$NON-NLS-1$ 
            UIHelper.createDuplicateJGoodiesDef("p", "2dlu", isNotEmbedded ? 9 : 11))); //$NON-NLS-1$ //$NON-NLS-2$

    extraPanel = extraPanelBlder.getPanel();
    extraPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 4, 2));

    //extraPanelBlder.addSeparator("", cc.xywh(1, 1, 3, 1)); //$NON-NLS-1$
    int y = 1;
    y = addLine(null, rememberUsernameCBX, extraPanelBlder, cc, y);
    y = addLine("databases", databases, extraPanelBlder, cc, y); //$NON-NLS-1$
    y = addLine("servers", servers, extraPanelBlder, cc, y); //$NON-NLS-1$

    y = addLine("driver", dbDriverCBX, extraPanelBlder, cc, y); //$NON-NLS-1$
    if (isNotEmbedded) {
        y = addLine("port", portSpinner, extraPanelBlder, cc, y); //$NON-NLS-1$
    }
    if (editKeyInfoBtn != null) {
        PanelBuilder pb = new PanelBuilder(new FormLayout("p,f:p:g", "p"));
        pb.add(editKeyInfoBtn, cc.xy(1, 1));
        y = addLine(null, pb.getPanel(), extraPanelBlder, cc, y);
        pb.getPanel().setOpaque(false);
    }
    extraPanel.setVisible(false);

    formBuilder.add(extraPanelBlder.getPanel(), cc.xywh(3, 9, 1, 1));

    PanelBuilder outerPanel = new PanelBuilder(new FormLayout("p,3dlu,p:g", "t:p,2dlu,p,2dlu,p"), this); //$NON-NLS-1$ //$NON-NLS-2$
    JLabel icon = StringUtils.isNotEmpty(iconName) ? new JLabel(IconManager.getIcon(iconName)) : null;

    if (icon != null) {
        icon.setBorder(BorderFactory.createEmptyBorder(10, 10, 2, 2));
    }

    formBuilder.getPanel().setBorder(BorderFactory.createEmptyBorder(10, 5, 0, 5));

    if (icon != null) {
        outerPanel.add(icon, cc.xy(1, 1));
    }
    JPanel btnPanel = ButtonBarFactory.buildOKCancelHelpBar(loginBtn, cancelBtn, helpBtn);
    outerPanel.add(formBuilder.getPanel(), cc.xy(3, 1));
    outerPanel.add(btnPanel, cc.xywh(1, 3, 3, 1));
    outerPanel.add(statusBar, cc.xywh(1, 5, 3, 1));

    formBuilder.getPanel().setOpaque(false);
    outerPanel.getPanel().setOpaque(false);
    btnPanel.setOpaque(false);

    updateUIControls();

    if (skinItem != null) {
        skinItem.popFG("Label.foreground");
    }

    if (AppPreferences.getLocalPrefs().getBoolean(expandExtraPanelName, false)) {
        extraPanel.setVisible(true);
        moreBtn.setIcon(downImgIcon);
    }
}

From source file:de.bfs.radon.omsimulation.gui.OMPanelTesting.java

/**
 * Adds event-listeners to the project's combobox.
 *///from   w  w  w.  j av  a2  s  .c  om
protected void addEventListener() {
    comboBoxProjects.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            boolean b = false;
            Color c = null;
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    b = true;
                    c = Color.WHITE;
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    comboBoxRoom1.removeAllItems();
                    comboBoxRoom2.removeAllItems();
                    comboBoxRoom3.removeAllItems();
                    comboBoxRoom4.removeAllItems();
                    comboBoxRoom5.removeAllItems();
                    comboBoxRoom6.removeAllItems();
                    comboBoxRoom7.removeAllItems();
                    for (int i = 0; i < building.getRooms().length; i++) {
                        comboBoxRoom1.addItem(building.getRooms()[i]);
                        comboBoxRoom2.addItem(building.getRooms()[i]);
                        comboBoxRoom3.addItem(building.getRooms()[i]);
                        comboBoxRoom4.addItem(building.getRooms()[i]);
                        comboBoxRoom5.addItem(building.getRooms()[i]);
                        comboBoxRoom6.addItem(building.getRooms()[i]);
                        comboBoxRoom7.addItem(building.getRooms()[i]);
                    }
                    for (int i = 0; i < building.getCellars().length; i++) {
                        comboBoxRoom1.addItem(building.getCellars()[i]);
                        comboBoxRoom2.addItem(building.getCellars()[i]);
                        comboBoxRoom3.addItem(building.getCellars()[i]);
                        comboBoxRoom4.addItem(building.getCellars()[i]);
                        comboBoxRoom5.addItem(building.getCellars()[i]);
                        comboBoxRoom6.addItem(building.getCellars()[i]);
                        comboBoxRoom7.addItem(building.getCellars()[i]);
                    }
                    comboBoxRoom7.setSelectedIndex(comboBoxRoom7.getItemCount() - 1);
                    sliderStartTime.setMaximum(building.getValueCount() - 168);
                    spnrStartTime.setModel(new SpinnerNumberModel(0, 0, building.getValueCount() - 168, 1));
                } else {
                    b = false;
                    c = null;
                }
            } else {
                b = false;
                c = null;
            }
            lblSelectRooms.setEnabled(b);
            lblStartTime.setEnabled(b);
            panelCampaign.setEnabled(b);
            btnMaximize.setVisible(isSimulated);
            btnPdf.setVisible(isSimulated);
            btnCsv.setVisible(isSimulated);
            lblExportChartTo.setVisible(isSimulated);
            sliderStartTime.setEnabled(b);
            spnrStartTime.setEnabled(b);
            comboBoxRoom1.setEnabled(b);
            comboBoxRoom2.setEnabled(b);
            comboBoxRoom3.setEnabled(b);
            comboBoxRoom4.setEnabled(b);
            comboBoxRoom5.setEnabled(b);
            comboBoxRoom6.setEnabled(b);
            comboBoxRoom7.setEnabled(b);
            panelCampaign.setBackground(c);
        }
    });
    comboBoxProjects.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            boolean b = false;
            Color c = null;
            if (comboBoxProjects.isEnabled() || isResult) {
                if (comboBoxProjects.getSelectedItem() != null) {
                    b = true;
                    c = Color.WHITE;
                    OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem();
                    comboBoxRoom1.removeAllItems();
                    comboBoxRoom2.removeAllItems();
                    comboBoxRoom3.removeAllItems();
                    comboBoxRoom4.removeAllItems();
                    comboBoxRoom5.removeAllItems();
                    comboBoxRoom6.removeAllItems();
                    comboBoxRoom7.removeAllItems();
                    for (int i = 0; i < building.getRooms().length; i++) {
                        comboBoxRoom1.addItem(building.getRooms()[i]);
                        comboBoxRoom2.addItem(building.getRooms()[i]);
                        comboBoxRoom3.addItem(building.getRooms()[i]);
                        comboBoxRoom4.addItem(building.getRooms()[i]);
                        comboBoxRoom5.addItem(building.getRooms()[i]);
                        comboBoxRoom6.addItem(building.getRooms()[i]);
                        comboBoxRoom7.addItem(building.getRooms()[i]);
                    }
                    for (int i = 0; i < building.getCellars().length; i++) {
                        comboBoxRoom1.addItem(building.getCellars()[i]);
                        comboBoxRoom2.addItem(building.getCellars()[i]);
                        comboBoxRoom3.addItem(building.getCellars()[i]);
                        comboBoxRoom4.addItem(building.getCellars()[i]);
                        comboBoxRoom5.addItem(building.getCellars()[i]);
                        comboBoxRoom6.addItem(building.getCellars()[i]);
                        comboBoxRoom7.addItem(building.getCellars()[i]);
                    }
                    comboBoxRoom7.setSelectedIndex(comboBoxRoom7.getItemCount() - 1);
                    sliderStartTime.setMaximum(building.getValueCount() - 168);
                    spnrStartTime.setModel(new SpinnerNumberModel(0, 0, building.getValueCount() - 168, 1));
                } else {
                    b = false;
                    c = null;
                }
            } else {
                b = false;
                c = null;
            }
            lblSelectRooms.setEnabled(b);
            lblStartTime.setEnabled(b);
            panelCampaign.setEnabled(b);
            btnMaximize.setVisible(isSimulated);
            btnPdf.setVisible(isSimulated);
            btnCsv.setVisible(isSimulated);
            lblExportChartTo.setVisible(isSimulated);
            sliderStartTime.setEnabled(b);
            spnrStartTime.setEnabled(b);
            comboBoxRoom1.setEnabled(b);
            comboBoxRoom2.setEnabled(b);
            comboBoxRoom3.setEnabled(b);
            comboBoxRoom4.setEnabled(b);
            comboBoxRoom5.setEnabled(b);
            comboBoxRoom6.setEnabled(b);
            comboBoxRoom7.setEnabled(b);
            panelCampaign.setBackground(c);
        }
    });
}