Example usage for javax.swing JCheckBox addActionListener

List of usage examples for javax.swing JCheckBox addActionListener

Introduction

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

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:org.kuali.test.ui.components.panels.FileTestPanel.java

@Override
protected void initComponents() {
    super.initComponents();

    List<String> labels = new ArrayList<String>();
    labels.add("File Directory");
    labels.add("File Name Pattern");

    for (int i = 0; i < Constants.FILE_CHECK_CONDITIONS.length; ++i) {
        labels.add("");
    }//from   w  w  w .j  a  va  2  s.  c  o  m

    labels.add("Contains Text");

    JPanel p = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    p.add(fileDirectory = new JTextField(30));
    JButton b = new FileSearchButton();
    b.addActionListener(this);
    p.add(b);

    List<JComponent> components = new ArrayList<JComponent>();

    components.add(p);
    components.add(fileNamePattern = new JTextField(20));

    fileComparisons = new ArrayList<JCheckBox>();
    ;
    for (int i = 0; i < Constants.FILE_CHECK_CONDITIONS.length; ++i) {
        JCheckBox cb = new JCheckBox(Constants.FILE_CHECK_CONDITIONS[i]);
        cb.addActionListener(this);
        components.add(cb);
        fileComparisons.add(cb);
    }

    components.add(containingText = new JTextField(40));

    p = new JPanel(new BorderLayout(3, 3));
    p.add(UIUtils.buildEntryPanel(labels.toArray(new String[labels.size()]),
            components.toArray(new JComponent[components.size()])), BorderLayout.NORTH);
    add(p, BorderLayout.CENTER);
}

From source file:org.languagetool.gui.ConfigurationDialog.java

private JPanel getSpecialRuleValuePanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints cons = new GridBagConstraints();
    cons.gridx = 0;/*from   w  w  w  . ja  va2  s.  com*/
    cons.gridy = 0;
    cons.weightx = 0.0f;
    cons.anchor = GridBagConstraints.WEST;

    List<JCheckBox> ruleCheckboxes = new ArrayList<JCheckBox>();
    List<JLabel> ruleLabels = new ArrayList<JLabel>();
    List<JTextField> ruleValueFields = new ArrayList<JTextField>();

    for (int i = 0; i < configurableRules.size(); i++) {
        Rule rule = configurableRules.get(i);
        JCheckBox ruleCheckbox = new JCheckBox(rule.getDescription());
        ruleCheckboxes.add(ruleCheckbox);
        ruleCheckbox.setSelected(getEnabledState(rule));
        cons.insets = new Insets(3, 0, 0, 0);
        panel.add(ruleCheckbox, cons);

        cons.insets = new Insets(0, 24, 0, 0);
        cons.gridy++;
        JLabel ruleLabel = new JLabel(rule.getConfigureText());
        ruleLabels.add(ruleLabel);
        ruleLabel.setEnabled(ruleCheckbox.isSelected());
        panel.add(ruleLabel, cons);

        cons.gridx++;
        int value = config.getConfigurableValue(rule.getId());
        if (config.getConfigurableValue(rule.getId()) < 0) {
            value = rule.getDefaultValue();
        }
        JTextField ruleValueField = new JTextField(Integer.toString(value), 2);
        ruleValueFields.add(ruleValueField);
        ruleValueField.setEnabled(ruleCheckbox.isSelected());
        ruleValueField.setMinimumSize(new Dimension(35, 25)); // without this the box is just a few pixels small, but why?
        panel.add(ruleValueField, cons);

        ruleCheckbox.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@SuppressWarnings("unused") ActionEvent e) {
                ruleValueField.setEnabled(ruleCheckbox.isSelected());
                ruleLabel.setEnabled(ruleCheckbox.isSelected());
                if (ruleCheckbox.isSelected()) {
                    config.getEnabledRuleIds().add(rule.getId());
                    config.getDisabledRuleIds().remove(rule.getId());
                } else {
                    config.getEnabledRuleIds().remove(rule.getId());
                    config.getDisabledRuleIds().add(rule.getId());
                }
            }
        });

        ruleValueField.getDocument().addDocumentListener(new DocumentListener() {
            @Override
            public void insertUpdate(DocumentEvent e) {
                changedUpdate(e);
            }

            @Override
            public void removeUpdate(DocumentEvent e) {
                changedUpdate(e);
            }

            @Override
            public void changedUpdate(DocumentEvent e) {
                try {
                    int num = Integer.parseInt(ruleValueField.getText());
                    if (num < rule.getMinConfigurableValue()) {
                        num = rule.getMinConfigurableValue();
                        ruleValueField.setForeground(Color.RED);
                    } else if (num > rule.getMaxConfigurableValue()) {
                        num = rule.getMaxConfigurableValue();
                        ruleValueField.setForeground(Color.RED);
                    } else {
                        ruleValueField.setForeground(null);
                    }
                    config.setConfigurableValue(rule.getId(), num);
                } catch (Exception ex) {
                    ruleValueField.setForeground(Color.RED);
                }
            }
        });

        cons.gridx = 0;
        cons.gridy++;

    }
    return panel;
}

From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java

/**
 * Setup General (Control Center) Tab//from   w w  w.j a v  a2  s .c  o  m
 * 
 * @return JPanel for Control Center
 */
private JPanel setupGeneral() {

    JPanel generalPanel = new JPanel();
    generalPanel.setLayout(new BorderLayout());

    /* -- Stats Panel -- */
    JPanel statsPanel = new JPanel();
    generalPanel.add(statsPanel, BorderLayout.NORTH);

    statsPanel.setLayout(new GridLayout(0, 2, 10, 10));

    JPanel eastPanel = new JPanel();
    statsPanel.add(eastPanel, BorderLayout.EAST);
    eastPanel.setLayout(new BorderLayout());

    JPanel westPanel = new JPanel();
    statsPanel.add(westPanel, BorderLayout.WEST);
    westPanel.setLayout(new BorderLayout());

    // Grid Information Panel
    JPanel gridInfoPanel = new JPanel();
    eastPanel.add(gridInfoPanel, BorderLayout.NORTH);

    gridInfoPanel.setBorder(BorderFactory.createTitledBorder("Grid Information"));
    gridInfoPanel.setLayout(new GridLayout(0, 2, 10, 10));

    JLabel nodeIdLabel = new JLabel("Node ID :");
    gridInfoPanel.add(nodeIdLabel);
    JLabel nodeId = new JLabel("#nodeid#");
    gridInfoPanel.add(nodeId);
    addUIElement("general.stats.nodeid", nodeId); // Add to components map

    JLabel nodeIpLabel = new JLabel("Node IP :");
    gridInfoPanel.add(nodeIpLabel);
    JLabel nodeIp = new JLabel("#nodeip#");
    gridInfoPanel.add(nodeIp);
    addUIElement("general.stats.nodeip", nodeIp); // Add to components map

    JLabel clusterIdLabel = new JLabel("Cluster ID :");
    gridInfoPanel.add(clusterIdLabel);
    JLabel clusterId = new JLabel("#clusterid#");
    gridInfoPanel.add(clusterId);
    addUIElement("general.stats.clusterid", clusterId); // Add to components map

    JLabel clusterServiceLabel = new JLabel("Cluster Service :");
    gridInfoPanel.add(clusterServiceLabel);
    JLabel clusterService = new JLabel("#clusterservice#");
    gridInfoPanel.add(clusterService);
    addUIElement("general.stats.clusterservice", clusterService); // Add to components map

    // Node Status Panel 
    JPanel nodeStatusPanel = new JPanel();
    eastPanel.add(nodeStatusPanel, BorderLayout.SOUTH);

    nodeStatusPanel.setBorder(BorderFactory.createTitledBorder("GridNode Status"));
    nodeStatusPanel.setLayout(new GridLayout(0, 2, 10, 10));

    JLabel statusLabel = new JLabel("Status :");
    nodeStatusPanel.add(statusLabel);
    JLabel status = new JLabel("#status#");
    nodeStatusPanel.add(status);
    addUIElement("general.stats.status", status); // Add to components map

    JLabel uptimeLabel = new JLabel("Node Up Time :");
    nodeStatusPanel.add(uptimeLabel);
    JLabel uptime = new JLabel("#uptime#");
    nodeStatusPanel.add(uptime);
    addUIElement("general.stats.uptime", uptime); // Add to components map

    JLabel execTimeLabel = new JLabel("Execution Time :");
    nodeStatusPanel.add(execTimeLabel);
    JLabel execTime = new JLabel("#exectime#");
    nodeStatusPanel.add(execTime);
    addUIElement("general.stats.exectime", execTime); // Add to components map

    // Execution Statistics Panel
    JPanel execStatsPanel = new JPanel();
    westPanel.add(execStatsPanel, BorderLayout.NORTH);

    execStatsPanel.setLayout(new GridLayout(0, 2, 10, 10));
    execStatsPanel.setBorder(BorderFactory.createTitledBorder("Execution Statistics"));

    JLabel totalJobsLabel = new JLabel("Total Jobs :");
    execStatsPanel.add(totalJobsLabel);
    JLabel totalJobs = new JLabel("0");
    execStatsPanel.add(totalJobs);
    addUIElement("general.stats.totaljobs", totalJobs); // Add to components map

    JLabel totalTasksLabel = new JLabel("Total Tasks :");
    execStatsPanel.add(totalTasksLabel);
    JLabel totalTasks = new JLabel("0");
    execStatsPanel.add(totalTasks);
    addUIElement("general.stats.totaltasks", totalTasks); // Add to components map

    JLabel totalBansLabel = new JLabel("Banments :");
    execStatsPanel.add(totalBansLabel);
    JLabel totalBans = new JLabel("0");
    execStatsPanel.add(totalBans);
    addUIElement("general.stats.totalbans", totalBans); // Add to components map

    // Execution Active Job Panel
    JPanel activeJobPanel = new JPanel();
    westPanel.add(activeJobPanel, BorderLayout.SOUTH);

    activeJobPanel.setLayout(new GridLayout(0, 2, 10, 10));
    activeJobPanel.setBorder(BorderFactory.createTitledBorder("Active Job"));

    JLabel jobNameLabel = new JLabel("GridJob Name :");
    activeJobPanel.add(jobNameLabel);
    JLabel jobName = new JLabel("#jobname#");
    activeJobPanel.add(jobName);
    addUIElement("general.stats.jobname", jobName); // Add to components map

    JLabel durationLabel = new JLabel("Duration :");
    activeJobPanel.add(durationLabel);
    JLabel duration = new JLabel("#duration#");
    activeJobPanel.add(duration);
    addUIElement("general.stats.duration", duration); // Add to components map

    JLabel tasksLabel = new JLabel("Tasks Executed :");
    activeJobPanel.add(tasksLabel);
    JLabel tasks = new JLabel("#xyz#");
    activeJobPanel.add(tasks);
    addUIElement("general.stats.tasks", tasks); // Add to components map

    JLabel failuresLabel = new JLabel("Failures :");
    activeJobPanel.add(failuresLabel);
    JLabel failures = new JLabel("#failures#");
    activeJobPanel.add(failures);
    addUIElement("general.stats.failures", failures); // Add to components map

    /* -- Log Panel -- */
    JPanel logPanel = new JPanel();
    generalPanel.add(logPanel, BorderLayout.CENTER);

    logPanel.setLayout(new BorderLayout());
    logPanel.setBorder(BorderFactory.createTitledBorder("Log Output"));
    JTextPane logTextPane = new JTextPane();
    logTextPane.setEditable(false);
    logTextPane.setBackground(Color.BLACK);
    logTextPane.setForeground(Color.WHITE);

    logPanel.add(new JScrollPane(logTextPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
    addUIElement("general.log", logTextPane); // Add to component map

    JPanel logOptionsPanel = new JPanel();
    logPanel.add(logOptionsPanel, BorderLayout.SOUTH);
    logOptionsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

    final JCheckBox logScrollCheckbox = new JCheckBox("Auto-Scroll Log");
    logScrollCheckbox.setSelected(true);
    logScrollCheckbox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JTextPaneAppender.setAutoScroll(logScrollCheckbox.isSelected());
        }

    });
    logOptionsPanel.add(logScrollCheckbox);

    // Enable Logging
    JTextPaneAppender.setTextPane(logTextPane);

    /* -- Buttons Panel -- */
    JPanel buttonsPanel = new JPanel();
    generalPanel.add(buttonsPanel, BorderLayout.SOUTH);

    buttonsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

    // Shutdown Button
    JButton shutdownButton = new JButton("Shutdown");
    buttonsPanel.add(shutdownButton);
    shutdownButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            doShutdownNode();
        }

    });

    // Start Up time Thread
    Thread t = new Thread(new Runnable() {
        public void run() {

            long start = System.currentTimeMillis();

            while (true) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    log.warn("Interrupted Exception in Up Time Thread", e);
                }

                final String uptime = TimeUtils.timeDifference(start);

                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                        JLabel upTime = getUIElement("general.stats.uptime");
                        upTime.setText(uptime);
                    }

                });
            }

        }
    });
    t.setDaemon(true);
    t.start();

    // Auto-Discovery Thread
    Thread autoDiscovery = new Thread(new Runnable() {
        public void run() {

            while (true) {
                try {

                    // Attempt every 30 seconds
                    Thread.sleep(30000);

                } catch (InterruptedException e) {
                    log.warn("Interrupted Exception in Up Time Thread", e);
                }

                if (autodiscover && (!Grid.isNode())) {
                    // 30 Second Intervals
                    doDiscover(true);
                }

            }
        }
    });
    autoDiscovery.setDaemon(true);
    autoDiscovery.start();

    return generalPanel;
}

From source file:org.nuclos.client.dbtransfer.DBTransferImport.java

private PanelWizardStep newStep1(final MainFrameTab ifrm) {
    final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate();
    final PanelWizardStep step = new PanelWizardStep(
            localeDelegate.getMessage("dbtransfer.import.step1.1", "Konfigurationsdatei"),
            localeDelegate.getMessage("dbtransfer.import.step1.2",
                    "Bitte w\u00e4hlen Sie eine Konfigurationsdatei aus."));

    final JLabel lbFile = new JLabel(localeDelegate.getMessage("dbtransfer.import.step1.3", "Datei"));

    utils.initJPanel(step,//from  w w  w  . j a  v  a  2 s . c om
            new double[] { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
                    TableLayout.FILL },
            new double[] { 20, TableLayout.PREFERRED, lbFile.getPreferredSize().height, TableLayout.FILL });

    final JButton btnBrowse = new JButton("...");
    //final JProgressBar progressBar = new JProgressBar(0, 230);
    final JCheckBox chbxImportAsNuclon = new JCheckBox(
            localeDelegate.getMessage("configuration.transfer.import.as.nuclon", "Import als Nuclon"));
    chbxImportAsNuclon.setEnabled(false);
    final JEditorPane editWarnings = new JEditorPane();
    editWarnings.setContentType("text/html");
    editWarnings.setEditable(false);
    editWarnings.setBackground(Color.WHITE);

    final JScrollPane scrollWarn = new JScrollPane(editWarnings);
    scrollWarn.setPreferredSize(new Dimension(680, 250));
    scrollWarn.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    scrollWarn.getVerticalScrollBar().setUnitIncrement(20);
    scrollWarn.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollWarn.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    final JScrollPane scrollPrev = new JScrollPane(jpnPreviewContent);
    scrollPrev.setPreferredSize(new Dimension(680, 250));
    scrollPrev.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
    scrollPrev.getVerticalScrollBar().setUnitIncrement(20);
    scrollPrev.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPrev.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    final JPanel jpnPreview = new JPanel(new BorderLayout());
    jpnPreview.add(jpnPreviewHeader, BorderLayout.NORTH);
    jpnPreview.add(scrollPrev, BorderLayout.CENTER);
    jpnPreview.add(jpnPreviewFooter, BorderLayout.SOUTH);
    jpnPreview.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    jpnPreview.setBackground(Color.WHITE);
    jpnPreviewHeader.setBackground(Color.WHITE);
    jpnPreviewContent.setBackground(Color.WHITE);
    jpnPreviewFooter.setBackground(Color.WHITE);

    final JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab(localeDelegate.getMessage("configuration.transfer.prepare.warnings.tab", "Warnungen"),
            scrollWarn);
    final String sDefaultPreparePreviewTabText = localeDelegate
            .getMessage("configuration.transfer.prepare.preview.tab", "Vorschau der Schema Aenderungen");
    tabbedPane.addTab(sDefaultPreparePreviewTabText, jpnPreview);

    final JLabel lbNewUser = new JLabel();

    step.add(lbFile, "0,0");
    step.add(tfTransferFile, "1,0");
    step.add(btnBrowse, "2,0");
    step.add(chbxImportAsNuclon, "1,1");//step.add(progressBar, "1,1");
    step.add(lbNewUser, "0,2,3,2");
    step.add(tabbedPane, "0,3,3,3");

    tfTransferFile.setEditable(false);

    final ActionListener prepareImportAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            ifrm.lockLayerWithProgress(Transfer.TOPIC_CORRELATIONID_PREPARE);

            Thread t = new Thread() {
                @Override
                public void run() {
                    step.setComplete(false);
                    boolean blnTransferWithWarnings = false;
                    //progressBar.setValue(0);
                    //progressBar.setVisible(true);
                    try {
                        String fileName = tfTransferFile.getText();
                        if (StringUtils.isNullOrEmpty(fileName)) {
                            return;
                        }
                        File f = new File(fileName);
                        long size = f.length();

                        final InputStream fin = new BufferedInputStream(new FileInputStream(f));
                        final byte[] transferFile;
                        try {
                            transferFile = utils.getBytes(fin, (int) size);
                        } finally {
                            fin.close();
                        }

                        resetStep2();
                        importTransferObject = getTransferFacadeRemote().prepareTransfer(isNuclon,
                                transferFile);
                        chbxImportAsNuclon.setEnabled(importTransferObject.getTransferOptions()
                                .containsKey(TransferOption.IS_NUCLON_IMPORT_ALLOWED));

                        step.setComplete(!importTransferObject.result.hasCriticals());

                        if (!importTransferObject.result.hasCriticals()
                                && !importTransferObject.result.hasWarnings()) {
                            editWarnings.setText(localeDelegate.getMessage(
                                    "configuration.transfer.prepare.no.warnings", "Keine Warnungen"));
                        } else {
                            editWarnings.setText("<html><body><font color=\"#800000\">"
                                    + importTransferObject.result.getCriticals() + "</font>"
                                    + (importTransferObject.result.hasCriticals() ? "<br />" : "")
                                    + importTransferObject.result.getWarnings() + "</body></html>");
                        }

                        int iPreviewSize = importTransferObject.getPreviewParts().size();
                        blnTransferWithWarnings = setupPreviewPanel(importTransferObject.getPreviewParts());
                        tabbedPane.setTitleAt(1, sDefaultPreparePreviewTabText
                                + (iPreviewSize == 0 ? "" : " (" + iPreviewSize + ")"));
                        lbNewUser.setText(
                                "Neue Benutzer" + ": " + (importTransferObject.getNewUserCount() == 0 ? "keine"
                                        : importTransferObject.getNewUserCount()));
                    } catch (Exception e) {
                        //                              progressBar.setVisible(false);
                        Errors.getInstance().showExceptionDialog(ifrm, e);
                    } finally {
                        btnBrowse.setEnabled(true);
                        //                              progressBar.setVisible(false);
                        ifrm.unlockLayer();
                    }
                    if (blnTransferWithWarnings) {
                        JOptionPane.showMessageDialog(jpnPreviewContent, localeDelegate.getMessage(
                                "dbtransfer.import.step1.19",
                                "Nicht alle Statements knnen durchgefhrt werden!\nBitte kontrollieren Sie die mit rot markierten Eintrge!",
                                "Warning", JOptionPane.WARNING_MESSAGE));
                    }
                }

            };

            t.start();
        }
    };
    final ActionListener browseAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            final JFileChooser filechooser = utils.getFileChooser(
                    localeDelegate.getMessage("configuration.transfer.file.nuclet", "Nuclet-Dateien"),
                    ".nuclet");
            final int iBtn = filechooser.showOpenDialog(ifrm);

            if (iBtn == JFileChooser.APPROVE_OPTION) {

                final File file = filechooser.getSelectedFile();
                if (file != null) {
                    tfTransferFile.setText("");
                    btnBrowse.setEnabled(false);
                    //progressBar.setVisible(true);

                    String fileName = file.getPath();
                    if (StringUtils.isNullOrEmpty(fileName)) {
                        return;
                    }

                    tfTransferFile.setText(fileName);

                    prepareImportAction.actionPerformed(new ActionEvent(this, 0, "prepare"));
                }
            }
        }
    };
    final ActionListener importAsNuclonAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            isNuclon = chbxImportAsNuclon.isSelected();
            prepareImportAction.actionPerformed(new ActionEvent(this, 0, "prepare"));
        }
    };
    btnBrowse.addActionListener(browseAction);
    chbxImportAsNuclon.addActionListener(importAsNuclonAction);

    //      progressBar.setVisible(false);

    return step;
}

From source file:org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent.java

public void addViews() {
    this.setLayout(new GridBagLayout());
    final GridBagConstraints c = new DefaultGridBagConstraints();

    // Numero du commande
    c.gridx = 0;/*from  w w w  . ja  va 2 s .c om*/
    c.weightx = 0;
    this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c);

    this.numeroUniqueCommande = new JUniqueTextField(16);
    c.gridx++;
    c.weightx = 1;
    c.fill = GridBagConstraints.NONE;
    DefaultGridBagConstraints.lockMinimumSize(numeroUniqueCommande);
    this.add(this.numeroUniqueCommande, c);

    // Date
    JLabel labelDate = new JLabel(getLabelFor("DATE"));
    labelDate.setHorizontalAlignment(SwingConstants.RIGHT);
    c.gridx = 2;
    c.weightx = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(labelDate, c);

    JDate dateCommande = new JDate(true);
    c.gridx++;
    c.fill = GridBagConstraints.NONE;
    this.add(dateCommande, c);

    // Fournisseur
    c.gridx = 0;
    c.gridy++;
    c.weightx = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(new JLabel(getLabelFor("ID_FOURNISSEUR"), SwingConstants.RIGHT), c);

    c.gridx = GridBagConstraints.RELATIVE;
    c.gridwidth = 1;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    this.add(this.fourn, c);

    if (!getTable().getFieldsName().contains("LIVRER")) {
        // Commande en cours
        JCheckBox boxEnCours = new JCheckBox(getLabelFor("EN_COURS"));
        c.gridx = 2;
        c.weightx = 0;
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridwidth = GridBagConstraints.REMAINDER;
        this.add(boxEnCours, c);
        c.gridwidth = 1;
        this.addRequiredSQLObject(boxEnCours, "EN_COURS");
    }

    // Fournisseur
    if (getTable().contains("ID_CONTACT_FOURNISSEUR")) {
        c.gridx = 0;
        c.gridy++;
        c.weightx = 0;
        c.fill = GridBagConstraints.HORIZONTAL;
        this.add(new JLabel(getLabelFor("ID_CONTACT_FOURNISSEUR"), SwingConstants.RIGHT), c);

        c.gridx = GridBagConstraints.RELATIVE;
        c.gridwidth = 1;
        c.weightx = 1;
        c.weighty = 0;
        c.fill = GridBagConstraints.HORIZONTAL;
        final ElementComboBox boxContactFournisseur = new ElementComboBox();
        final SQLElement contactElement = Configuration.getInstance().getDirectory()
                .getElement("CONTACT_FOURNISSEUR");
        boxContactFournisseur.init(contactElement, contactElement.getComboRequest(true));
        this.add(boxContactFournisseur, c);
        this.addView(boxContactFournisseur, "ID_CONTACT_FOURNISSEUR", REQ);

        fourn.addValueListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent arg0) {
                // TODO Raccord de mthode auto-gnr
                if (fourn.getSelectedRow() != null) {
                    boxContactFournisseur.getRequest()
                            .setWhere(new Where(contactElement.getTable().getField("ID_FOURNISSEUR"), "=",
                                    fourn.getSelectedRow().getID()));
                } else {
                    boxContactFournisseur.getRequest().setWhere(null);
                }
            }
        });
    }
    // Adresse de livraison
    if (getTable().getFieldsName().contains("ID_ADRESSE")) {
        if (getTable().getFieldsName().contains("LIVRAISON_F")) {
            c.gridx = 0;
            c.gridy++;
            c.weightx = 0;
            c.fill = GridBagConstraints.HORIZONTAL;
            this.add(new JLabel(getLabelFor("ID_ADRESSE")), c);
            c.gridx++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            // c.gridy++;
            this.addView("ID_ADRESSE");
            final DefaultElementSQLObject comp = (DefaultElementSQLObject) this.getView("ID_ADRESSE").getComp();

            if (getTable().getFieldsName().contains("LIVRAISON_F")) {
                final JCheckBox boxLivr = new JCheckBox("Livr par le fournisseur");
                this.add(boxLivr, c);
                this.addSQLObject(boxLivr, "LIVRAISON_F");
                boxLivr.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        if (boxLivr.isSelected() && !comp.isCreated()) {
                            comp.setCreated(true);
                            if (CommandeSQLComponent.this.getTable().contains("ID_AFFAIRE")) {

                                SQLRowValues rowVals = getLivraisonAdr(
                                        ((ElementComboBox) CommandeSQLComponent.this.getView("ID_AFFAIRE")
                                                .getComp()).getSelectedRow());

                                comp.setValue(rowVals);
                            }

                        } else {
                            if (!boxLivr.isSelected()) {
                                comp.setCreated(false);
                            }
                        }
                    }
                });
            }

            c.gridy++;
            this.add(comp, c);
            this.add(this.getView("ID_ADRESSE").getComp(), c);
        } else {

            c.gridy++;
            c.gridx = 0;
            this.add(new JLabel("Livraison"), c);
            c.gridx++;
            c.gridwidth = GridBagConstraints.REMAINDER;
            this.add(boxLivrClient, c);
            c.gridwidth = 1;

            final GridBagConstraints cAdr = new DefaultGridBagConstraints();

            panelAdrSpec.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), cAdr);
            final ElementComboBox boxClient = new ElementComboBox(true);
            cAdr.weightx = 1;
            cAdr.gridx++;
            panelAdrSpec.add(boxClient, cAdr);
            this.addView(boxClient, "ID_CLIENT");

            cAdr.gridy++;
            cAdr.weightx = 0;
            cAdr.gridx = 0;
            panelAdrSpec.add(new JLabel("Adresse", SwingConstants.RIGHT), cAdr);
            final SQLRequestComboBox boxAdr = new SQLRequestComboBox(true);
            boxAdr.uiInit(Configuration.getInstance().getDirectory().getElement(getTable().getTable("ADRESSE"))
                    .getComboRequest(true));
            boxClient.addModelListener("wantedID", new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    if (boxClient.getSelectedRow() != null && !boxClient.getSelectedRow().isUndefined()) {
                        Where w = new Where(boxAdr.getRequest().getPrimaryTable().getField("ID_CLIENT"), "=",
                                boxClient.getSelectedRow().getID());
                        w = w.or(new Where(boxAdr.getRequest().getPrimaryTable().getKey(), "=",
                                boxClient.getSelectedRow().getInt("ID_ADRESSE")));
                        w = w.or(new Where(boxAdr.getRequest().getPrimaryTable().getKey(), "=",
                                boxClient.getSelectedRow().getInt("ID_ADRESSE_F")));
                        w = w.or(new Where(boxAdr.getRequest().getPrimaryTable().getKey(), "=",
                                boxClient.getSelectedRow().getInt("ID_ADRESSE_L")));
                        boxAdr.getRequest().setWhere(w);
                    } else {
                        boxAdr.getRequest().setWhere(null);
                    }
                }
            });
            cAdr.weightx = 1;
            cAdr.gridx++;
            panelAdrSpec.add(boxAdr, cAdr);

            cAdr.gridx = 0;
            cAdr.gridy++;
            cAdr.weightx = 0;
            if (getMode() == Mode.MODIFICATION) {
                panelAdrSpec.add(new JLabel(getLabelFor("ID_ADRESSE")), cAdr);
            }
            cAdr.gridx++;
            cAdr.gridwidth = GridBagConstraints.REMAINDER;
            this.addView("ID_ADRESSE");
            compAdr = (DefaultElementSQLObject) this.getView("ID_ADRESSE").getComp();

            cAdr.gridy++;
            if (getMode() == Mode.MODIFICATION) {
                panelAdrSpec.add(compAdr, cAdr);
            }
            boxAdr.addValueListener(new PropertyChangeListener() {

                @Override
                public void propertyChange(PropertyChangeEvent evt) {
                    SQLRow row = boxAdr.getSelectedRow();
                    if (row != null && !row.isUndefined()) {
                        compAdr.setCreated(true);
                        SQLRowValues asRowValues = new SQLRowValues(row.asRowValues());
                        compAdr.setValue(asRowValues);
                    }
                }
            });

            c.gridy++;
            c.gridx = 0;
            c.gridwidth = GridBagConstraints.REMAINDER;
            c.weightx = 1;
            this.add(panelAdrSpec, c);
            c.gridwidth = 1;
            c.weightx = 0;

            boxLivrClient.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    panelAdrSpec.setVisible(boxLivrClient.isSelected());

                    if (!boxLivrClient.isSelected()) {
                        boxClient.setValue((Integer) null);
                        boxAdr.setValue((Integer) null);
                        compAdr.setCreated(false);
                    }
                }
            });
            panelAdrSpec.setVisible(false);
        }
    }
    c.gridwidth = 1;

    // Champ Module
    c.gridx = 0;
    c.gridy++;
    c.gridwidth = GridBagConstraints.REMAINDER;
    final JPanel addP = ComptaSQLConfElement.createAdditionalPanel();
    this.setAdditionalFieldsPanel(new FormLayouter(addP, 2));
    this.add(addP, c);

    c.gridy++;
    c.gridwidth = 1;

    final ElementComboBox boxDevise = new ElementComboBox();
    if (DefaultNXProps.getInstance().getBooleanValue(AbstractVenteArticleItemTable.ARTICLE_SHOW_DEVISE,
            false)) {
        // Devise
        c.gridx = 0;
        c.gridy++;
        c.weightx = 0;
        c.fill = GridBagConstraints.HORIZONTAL;
        this.add(new JLabel(getLabelFor("ID_DEVISE"), SwingConstants.RIGHT), c);

        c.gridx = GridBagConstraints.RELATIVE;
        c.gridwidth = 1;
        c.weightx = 1;
        c.weighty = 0;
        c.fill = GridBagConstraints.NONE;
        this.add(boxDevise, c);
        this.addView(boxDevise, "ID_DEVISE");
    }

    // Reference
    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 1;
    c.weightx = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.EAST;
    this.add(new JLabel(getLabelFor("NOM"), SwingConstants.RIGHT), c);

    final JTextField textNom = new JTextField();
    c.gridx++;
    c.weightx = 1;
    this.add(textNom, c);

    String field;
    field = "ID_COMMERCIAL";
    // Commercial
    c.weightx = 0;
    c.gridx++;
    this.add(new JLabel(getLabelFor(field), SwingConstants.RIGHT), c);

    ElementComboBox commSel = new ElementComboBox(false, 25);
    c.gridx = GridBagConstraints.RELATIVE;
    c.gridwidth = 1;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.WEST;
    this.add(commSel, c);
    addRequiredSQLObject(commSel, field);

    // Table d'lment
    c.fill = GridBagConstraints.BOTH;
    c.gridy++;
    c.gridx = 0;
    c.weightx = 0;
    c.weighty = 1;
    c.gridwidth = 4;
    this.add(this.table, c);
    if (DefaultNXProps.getInstance().getBooleanValue(AbstractVenteArticleItemTable.ARTICLE_SHOW_DEVISE,
            false)) {

        boxDevise.addValueListener(new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                table.setDevise(boxDevise.getSelectedRow());

            }
        });
    }

    this.fourn.addValueListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            table.setFournisseur(fourn.getSelectedRow());
        }
    });
    // Bottom
    c.gridy++;
    c.weighty = 0;
    this.add(getBottomPanel(), c);

    c.gridx = 0;
    c.gridy++;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;

    JPanel panelOO = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panelOO.add(this.checkImpression, c);
    panelOO.add(this.checkVisu, c);
    c.gridwidth = GridBagConstraints.REMAINDER;
    this.add(panelOO, c);

    addRequiredSQLObject(this.fourn, "ID_FOURNISSEUR");
    addSQLObject(textNom, "NOM");
    addRequiredSQLObject(dateCommande, "DATE");
    // addRequiredSQLObject(radioEtat, "ID_ETAT_DEVIS");
    addRequiredSQLObject(this.numeroUniqueCommande, "NUMERO");
    addSQLObject(this.infos, "INFOS");

    this.numeroUniqueCommande.setText(NumerotationAutoSQLElement.getNextNumero(CommandeSQLElement.class));

    // radioEtat.setValue(EtatDevisSQLElement.EN_ATTENTE);
    // this.numeroUniqueDevis.addLabelWarningMouseListener(new MouseAdapter() {
    // public void mousePressed(MouseEvent e) {
    //
    // if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
    // numeroUniqueDevis.setText(NumerotationAutoSQLElement.getNextNumeroDevis());
    // }
    // }
    // });

    DefaultGridBagConstraints.lockMinimumSize(this.fourn);
    DefaultGridBagConstraints.lockMinimumSize(commSel);
}

From source file:org.pentaho.reporting.designer.extensions.pentaho.drilldown.swing.SwingRemoteDrillDownController.java

/**
 * Initialize component of the controller.
 *///  w  w w  .j a v  a 2 s. c  o m
public void init() {

    // Listeners
    modelWrapperUpdateHandler = new ModelWrapperUpdateHandler();
    pathWrapperUpdateHandler = new PathWrapperUpdateHandler();
    modelWrapper.addPropertyChangeListener(modelWrapperUpdateHandler);
    pentahoPathWrapper.addPropertyChangeListener(pathWrapperUpdateHandler);

    // Report extensions
    initExtensionsMap(pentahoPathWrapper);

    // Server URL check box
    final JCheckBox includeServerUrl = drillDownUi
            .getComponent(SwingRemoteDrillDownUi.ComponentLookup.SERVER_URL_CHECKBOX);
    includeServerUrl.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            pentahoPathWrapper.setUseRemoteServer(includeServerUrl.isSelected());
        }
    });

    // Server URL field
    JTextField serverUrlField = drillDownUi
            .getComponent(SwingRemoteDrillDownUi.ComponentLookup.SERVER_URL_FIELD);
    serverUrlField.getDocument().addDocumentListener(new DocumentBindingListener() {
        @Override
        protected void setData(String data) {
            pentahoPathWrapper.setLocalPath(data);
        }
    });

    // Login button
    JButton loginButton = drillDownUi.getComponent(SwingRemoteDrillDownUi.ComponentLookup.LOGIN_BUTTON);
    loginButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final LoginTask loginTask = new LoginTask(reportDesignerContext,
                    drillDownUi.getEditorPanel().getParent(), new LoginCompleteTask(null));
            SwingUtilities.invokeLater(loginTask);
        }
    });

    // Path field
    JTextField pathField = drillDownUi.getComponent(SwingRemoteDrillDownUi.ComponentLookup.PATH_FIELD);
    serverUrlField.getDocument().addDocumentListener(new DocumentBindingListener() {
        @Override
        protected void setData(String data) {
            pentahoPathWrapper.setServerPath(data);
        }
    });

    // Browse button
    JButton browseButton = drillDownUi.getComponent(SwingRemoteDrillDownUi.ComponentLookup.BROWSE_BUTTON);
    browseButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            final ReportDocumentContext activeContext = reportDesignerContext.getActiveContext();
            if (pentahoPathWrapper.getLoginData() == null) {
                final String path = modelWrapper.getDrillDownPath();
                if (path != null) {
                    final AuthenticationStore authStore = activeContext.getAuthenticationStore();
                    final String username = authStore.getUsername(path);
                    final String password = authStore.getPassword(path);
                    final int timeout = authStore.getIntOption(path, "timeout", 0);
                    pentahoPathWrapper.setLoginData(new AuthenticationData(path, username, password, timeout));
                }
            }

            final LoginTask loginTask = new LoginTask(reportDesignerContext,
                    drillDownUi.getEditorPanel().getParent(),
                    new LoginCompleteTask(new SelectDrillTargetTask(pentahoPathWrapper,
                            drillDownUi.getEditorPanel().getParent(), new RefreshParameterTask(),
                            activeContext)),
                    pentahoPathWrapper.getLoginData());
            SwingUtilities.invokeLater(loginTask);
        }
    });

    // Parameter Table
    DrillDownParameterTable table = drillDownUi
            .getComponent(SwingRemoteDrillDownUi.ComponentLookup.PARAMETER_TABLE);
    table.addDrillDownParameterRefreshListener(new UpdateParametersHandler());
    table.addPropertyChangeListener(DrillDownParameterTable.DRILL_DOWN_PARAMETER_PROPERTY,
            new TableModelBinding());
    PentahoParameterRefreshHandler parameterRefreshHandler = new PentahoParameterRefreshHandler(
            pentahoPathWrapper, reportDesignerContext, drillDownUi.getEditorPanel());
    table.addDrillDownParameterRefreshListener(parameterRefreshHandler);
    parameterRefreshHandler.setParameterTable(table);

    pentahoPathWrapper.addPropertyChangeListener(PentahoPathModel.LOCAL_PATH_PROPERTY,
            new CheckEmptyPathHandler(table));

    SwingUtilities.invokeLater(new RefreshParameterTask());

    // restore any parameters that might have been lost while initializing the UI.
    modelWrapper.setDrillDownParameter(modelWrapper.getDrillDownParameter());

    pentahoPathWrapper.setLocalPathFromParameter(modelWrapper.getDrillDownParameter());
    if (StringUtils.isEmpty(modelWrapper.getDrillDownPath())) {
        pentahoPathWrapper.setUseRemoteServer(false);
        final ReportDocumentContext reportRenderContext = reportDesignerContext.getActiveContext();
        if (reportRenderContext != null) {
            final Object o = reportRenderContext.getProperties().get("pentaho-login-url");
            if (o != null) {
                pentahoPathWrapper.setServerPath(String.valueOf(o));
            } else {
                pentahoPathWrapper.setServerPath(null);
            }
        } else {
            pentahoPathWrapper.setServerPath(null);
        }
    } else {
        pentahoPathWrapper.setUseRemoteServer(true);
        pentahoPathWrapper.setServerPath(modelWrapper.getDrillDownPath());
    }

}

From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java

private TableCellEditor getCellEditor(final SwingTreeCol col) {
    return new DefaultCellEditor(new JComboBox()) {

        JComponent control;/* w ww  .j a va2s .  c  o  m*/

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected,
                final int row, final int column) {
            Component comp;
            ColumnType colType = col.getColumnType();
            if (colType == ColumnType.DYNAMIC) {
                colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column));
            }

            final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column);
            switch (colType) {
            case CHECKBOX:
                final JCheckBox checkbox = new JCheckBox();
                final JTable tbl = table;
                checkbox.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent event) {
                        SwingTree.this.table.setValueAt(checkbox.isSelected(), row, column);
                        tbl.getCellEditor().stopCellEditing();
                    }
                });

                control = checkbox;
                if (value instanceof String) {
                    checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$
                } else if (value instanceof Boolean) {
                    checkbox.setSelected((Boolean) value);
                } else if (value == null) {
                    checkbox.setSelected(false);
                }
                if (isSelected) {
                    checkbox.setBackground(Color.LIGHT_GRAY);
                }
                comp = checkbox;
                checkbox.setEnabled(!cell.isDisabled());
                break;
            case EDITABLECOMBOBOX:
            case COMBOBOX:
                Vector val = (value != null && value instanceof Vector) ? (Vector) value : new Vector();
                final JComboBox comboBox = new JComboBox(val);

                if (isSelected) {
                    comboBox.setBackground(Color.LIGHT_GRAY);
                }

                if (colType == ColumnType.EDITABLECOMBOBOX) {

                    comboBox.setEditable(true);
                    final JTextComponent textComp = (JTextComponent) comboBox.getEditor().getEditorComponent();

                    textComp.addKeyListener(new KeyListener() {
                        private String oldValue = ""; //$NON-NLS-1$

                        public void keyPressed(KeyEvent e) {
                            oldValue = textComp.getText();
                        }

                        public void keyReleased(KeyEvent e) {
                            if (oldValue != null && !oldValue.equals(textComp.getText())) {
                                SwingTree.this.table.setValueAt(textComp.getText(), row, column);

                                oldValue = textComp.getText();
                            } else if (oldValue == null) {
                                // AWT error where sometimes the keyReleased is fired before keyPressed.
                                oldValue = textComp.getText();
                            } else {
                                logger.debug("Special key pressed, ignoring"); //$NON-NLS-1$
                            }
                        }

                        public void keyTyped(KeyEvent e) {
                        }
                    });

                    comboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent event) {
                            // if(textComp.hasFocus() == false && comboBox.hasFocus()){
                            SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$
                                    + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$

                            SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column);
                            // }
                        }
                    });
                } else {
                    comboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent event) {

                            SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$
                                    + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$

                            SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column);
                        }
                    });
                }

                control = comboBox;
                comboBox.setEnabled(!cell.isDisabled());
                comp = comboBox;
                break;
            case LABEL:
                JLabel lbl = new JLabel(cell.getLabel());
                comp = lbl;
                control = lbl;
                break;
            case CUSTOM:
                return new CustomCellEditorWrapper(cell, customEditors.get(col.getType()));
            default:
                final JTextField label = new JTextField((String) value);

                label.getDocument().addDocumentListener(new DocumentListener() {

                    public void changedUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                    public void insertUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                    public void removeUpdate(DocumentEvent arg0) {
                        SwingTree.this.table.setValueAt(label.getText(), row, column);
                    }

                });
                if (isSelected) {
                    label.setOpaque(true);
                    // label.setBackground(Color.LIGHT_GRAY);
                }

                control = label;
                comp = label;
                label.setEnabled(!cell.isDisabled());
                label.setDisabledTextColor(Color.DARK_GRAY);
                break;
            }

            return comp;
        }

        @Override
        public Object getCellEditorValue() {
            if (control instanceof JCheckBox) {
                return ((JCheckBox) control).isSelected();
            } else if (control instanceof JComboBox) {
                JComboBox box = (JComboBox) control;
                if (box.isEditable()) {
                    return ((JTextComponent) box.getEditor().getEditorComponent()).getText();
                } else {
                    return box.getSelectedIndex();
                }
            } else if (control instanceof JTextField) {
                return ((JTextField) control).getText();
            } else {
                return ((JLabel) control).getText();
            }
        }

    };

}

From source file:org.tellervo.desktop.prefs.Prefs.java

private static boolean cantSave(Exception e) {
    JPanel message = new JPanel(new BorderLayout(0, 8)); // (hgap,vgap)
    message.add(new JLabel(I18n.getText("error.prefs_cant_save")), BorderLayout.NORTH);

    // -- dialog with optionpane (warning?)
    JOptionPane optionPane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE);
    JDialog dialog = optionPane.createDialog(null /* ? */, I18n.getText("error.prefs_cant_save_title"));

    // -- buttons: cancel, try again.
    optionPane.setOptions(new String[] { I18n.getText("question.try_again"), I18n.getText("general.cancel") });

    // -- disclosure triangle with scrollable text area: click for
    // details... (stacktrace)
    JComponent stackTrace = new JScrollPane(new JTextArea(BugReport.getStackTrace(e), 10, 60));
    JDisclosureTriangle v = new JDisclosureTriangle(I18n.getText("bug.click_for_details"), stackTrace, false);
    message.add(v, BorderLayout.CENTER);

    // -- checkbox: don't warn me again
    JCheckBox dontWarnCheckbox = new JCheckBox(I18n.getText("bug.dont_warn_again"), false);
    dontWarnCheckbox.addActionListener(new AbstractAction() {
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            dontWarn = !dontWarn;//from w  ww. j  av a2 s  . c om
        }
    });

    // FIXME: consolidate |message| panel construction with Layout methods
    message.add(dontWarnCheckbox, BorderLayout.SOUTH);

    // show dialog
    dialog.pack();
    dialog.setResizable(false);
    dialog.setVisible(true);

    // return true if "try again" is clicked
    return optionPane.getValue().equals(I18n.getText("try_again"));
}

From source file:org.tinymediamanager.ui.panels.MediaScraperConfigurationPanel.java

private JPanel createConfigPanel() {
    JPanel panel = new JPanel();
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 0 };
    gridBagLayout.rowHeights = new int[] { 0 };
    gridBagLayout.columnWeights = new double[] { Double.MIN_VALUE };
    gridBagLayout.rowWeights = new double[] { Double.MIN_VALUE };
    panel.setLayout(gridBagLayout);/*from w w  w.j a va 2 s .c  o m*/

    GridBagConstraints constraints = new GridBagConstraints();
    constraints.gridy = 0;

    // build up the panel for being displayed in the popup
    MediaProviderConfig config = mediaProvider.getProviderInfo().getConfig();
    for (Entry<String, MediaProviderConfigObject> entry : config.getConfigObjects().entrySet()) {
        if (!entry.getValue().isVisible()) {
            continue;
        }

        constraints.anchor = GridBagConstraints.LINE_START;
        constraints.ipadx = 20;

        // label
        JLabel label = new JLabel(entry.getValue().getKeyDescription());
        constraints.gridx = 0;
        panel.add(label, constraints);

        JComponent comp;
        switch (entry.getValue().getType()) {
        case BOOL:
            // display as checkbox
            JCheckBox checkbox = new JCheckBox();
            checkbox.setSelected(entry.getValue().getValueAsBool());
            checkbox.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dirty = true;
                }
            });
            comp = checkbox;
            break;

        case SELECT:
        case SELECT_INDEX:
            // display as combobox
            JComboBox<String> combobox = new JComboBox<>(
                    entry.getValue().getPossibleValues().toArray(new String[0]));
            combobox.setSelectedItem(entry.getValue().getValueAsString());
            combobox.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    dirty = true;
                }
            });
            comp = combobox;
            break;

        default:
            // display as text
            JTextField tf;
            if (entry.getValue().isEncrypt()) {
                tf = new JPasswordField(config.getValue(entry.getKey()));
            } else {
                tf = new JTextField(config.getValue(entry.getKey()));
            }

            tf.setPreferredSize(new Dimension(100, 24));
            tf.getDocument().addDocumentListener(new DocumentListener() {
                @Override
                public void removeUpdate(DocumentEvent e) {
                    dirty = true;
                }

                @Override
                public void insertUpdate(DocumentEvent e) {
                    dirty = true;
                }

                @Override
                public void changedUpdate(DocumentEvent e) {
                    dirty = true;
                }
            });
            comp = tf;
            break;
        }

        comp.putClientProperty(entry.getKey(), entry.getKey());
        constraints.ipadx = 0;
        constraints.gridx = 1;
        panel.add(comp, constraints);

        // add a hint if a long text has been found
        try {
            String desc = BUNDLE.getString(
                    "scraper." + mediaProvider.getProviderInfo().getId() + "." + entry.getKey() + ".desc"); //$NON-NLS-1$
            if (StringUtils.isNotBlank(desc)) {
                JLabel lblHint = new JLabel(IconManager.HINT);
                lblHint.setToolTipText(desc);
                constraints.gridx = 2;
                panel.add(lblHint, constraints);
            }
        } catch (Exception ignored) {
        }
        constraints.gridy++;
    }
    return panel;
}

From source file:org.ut.biolab.medsavant.client.query.view.NumberSearchConditionEditorView.java

@Override
public void loadViewFromSearchConditionParameters(String encoding) throws ConditionRestorationException {

    double[] selectedValues;
    if (encoding == null) {
        selectedValues = null;/*from w ww.ja  v a2  s . c  o  m*/
    } else {
        selectedValues = NumericConditionEncoder.unencodeConditions(encoding);
    }

    final double[] extremeValues = generator.getExtremeNumericValues();
    this.removeAll();

    if (extremeValues == null || (extremeValues[0] == 0 && extremeValues[1] == 0)) {
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
        p.add(Box.createHorizontalGlue());
        p.add(new JLabel("<html>All values are blank for this condition.</html>"));
        p.add(Box.createHorizontalGlue());
        this.add(p);
        return;
    }

    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    JPanel p = ViewUtil.getClearPanel();
    ViewUtil.applyVerticalBoxLayout(p);

    JPanel labelPanel = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(labelPanel);
    labelPanel.add(Box.createHorizontalGlue());
    labelPanel.add(new JLabel("Filtering variants where " + item.getName() + ": "));
    labelPanel.add(Box.createHorizontalGlue());
    ButtonGroup group = new ButtonGroup();
    //JRadioButton isButton = new JRadioButton("is within the following range:");
    //JRadioButton nullButton = new JRadioButton("is missing");
    //group.add(isButton);
    //group.add(nullButton);

    final JCheckBox nullButton = new JCheckBox("include missing values");

    JPanel bp = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(bp);
    p.add(labelPanel);
    p.add(bp);
    add(p);
    final DecimalRangeSlider slider = new DecimalRangeSlider();

    slider.setMajorTickSpacing(5);
    slider.setMinorTickSpacing(1);

    final JTextField fromBox = new JTextField();
    final JTextField toBox = new JTextField();

    nullButton.setSelected(NumericConditionEncoder.encodesNull(encoding));

    nullButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                    ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                    extremeValues[1], nullButton.isSelected());
        }
    });

    fromBox.setMaximumSize(new Dimension(10000, 24));
    toBox.setMaximumSize(new Dimension(10000, 24));
    fromBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setPreferredSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    toBox.setMinimumSize(new Dimension(FROM_TO_WIDTH, 24));
    fromBox.setHorizontalAlignment(JTextField.RIGHT);
    toBox.setHorizontalAlignment(JTextField.RIGHT);

    final JLabel fromLabel = new JLabel();
    final JLabel toLabel = new JLabel();

    ViewUtil.makeMini(fromLabel);
    ViewUtil.makeMini(toLabel);

    JPanel fromToContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(fromToContainer);
    fromToContainer.add(Box.createHorizontalGlue());
    fromToContainer.add(fromBox);
    fromToContainer.add(new JLabel(" - "));
    fromToContainer.add(toBox);
    fromToContainer.add(Box.createHorizontalGlue());

    JPanel minMaxContainer = ViewUtil.getClearPanel();
    minMaxContainer.setLayout(new BoxLayout(minMaxContainer, BoxLayout.X_AXIS));

    JPanel sliderContainer = ViewUtil.getClearPanel();
    sliderContainer.setLayout(new BoxLayout(sliderContainer, BoxLayout.Y_AXIS));
    sliderContainer.add(slider);

    JPanel nullValueContainer = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(nullValueContainer);
    nullValueContainer.add(Box.createHorizontalGlue());
    nullValueContainer.add(nullButton);
    nullButton.setBackground(nullValueContainer.getBackground()); //fixes a windows issue.
    nullValueContainer.add(Box.createHorizontalGlue());

    JPanel labelContainer = ViewUtil.getClearPanel();
    labelContainer.setLayout(new BoxLayout(labelContainer, BoxLayout.X_AXIS));
    labelContainer.add(fromLabel);
    labelContainer.add(Box.createHorizontalGlue());
    labelContainer.add(toLabel);
    sliderContainer.add(labelContainer);
    minMaxContainer.add(Box.createHorizontalGlue());
    minMaxContainer.add(sliderContainer);
    minMaxContainer.add(Box.createHorizontalGlue());

    add(fromToContainer);
    add(minMaxContainer);
    add(nullValueContainer);
    add(Box.createVerticalBox());

    slider.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (slider.isEnabled()) {
                fromBox.setText(ViewUtil.numToString(slider.getLow()));
                toBox.setText(ViewUtil.numToString(slider.getHigh()));
                encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                        ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                        extremeValues[1], nullButton.isSelected());
            }
        }
    });

    final KeyListener keyListener = new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            int key = e.getKeyCode();
            if (key == KeyEvent.VK_ENTER) {
                Range selectedRage = new Range(getNumber(fromBox.getText()), getNumber(toBox.getText()));
                setSelectedValues(slider, fromBox, toBox, selectedRage);
            }
        }

        private double getNumber(String s) {
            try {
                return Double.parseDouble(s.replaceAll(",", ""));
            } catch (NumberFormatException ignored) {
                return 0;
            }
        }
    };

    CaretListener caretListener = new CaretListener() {
        @Override
        public void caretUpdate(CaretEvent ce) {
            if (!isAdjustingSlider) {
                try {
                    encodeValue(ViewUtil.parseDoubleFromFormattedString(fromBox.getText()),
                            ViewUtil.parseDoubleFromFormattedString(toBox.getText()), extremeValues[0],
                            extremeValues[1], nullButton.isSelected());
                } catch (Exception e) {
                }
            }
        }
    };

    fromBox.addKeyListener(keyListener);

    toBox.addKeyListener(keyListener);

    fromBox.addCaretListener(caretListener);

    toBox.addCaretListener(caretListener);

    slider.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            isAdjustingSlider = true;
            fromBox.setText(ViewUtil.numToString(slider.getLow()));
            toBox.setText(ViewUtil.numToString(slider.getHigh()));
            isAdjustingSlider = false;
        }
    });

    JPanel bottomContainer = new JPanel();

    bottomContainer.setLayout(new BoxLayout(bottomContainer, BoxLayout.X_AXIS));

    bottomContainer.add(Box.createHorizontalGlue());

    add(bottomContainer);

    setExtremeValues(slider, fromLabel, toLabel, fromBox, toBox, 0,
            new Range(extremeValues[0], extremeValues[1]));

    if (encoding != null) {
        double[] d = NumericConditionEncoder.unencodeConditions(encoding);
        setSelectedValues(slider, fromBox, toBox, new Range(d[0], d[1]));
    }
}