Example usage for javax.swing JComboBox getSelectedItem

List of usage examples for javax.swing JComboBox getSelectedItem

Introduction

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

Prototype

public Object getSelectedItem() 

Source Link

Document

Returns the current selected item.

Usage

From source file:com.floreantpos.bo.ui.explorer.ModifierExplorer.java

private JPanel buildSearchForm() {
    List<MenuModifierGroup> grpName;
    JPanel panel = new JPanel();
    panel.setLayout(new MigLayout("", "[][]30[][]30[]", "[]20[]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    JLabel nameLabel = new JLabel(Messages.getString("ModifierExplorer.3")); //$NON-NLS-1$
    JLabel groupLabel = new JLabel(Messages.getString("ModifierExplorer.4")); //$NON-NLS-1$
    final JTextField nameField = new JTextField(15);
    grpName = MenuModifierGroupDAO.getInstance().findAll();
    final JComboBox cbGroup = new JComboBox();
    cbGroup.addItem(Messages.getString("ModifierExplorer.5")); //$NON-NLS-1$
    for (MenuModifierGroup s : grpName) {
        cbGroup.addItem(s);//from  ww w.  ja  va  2  s  .  com
    }

    JButton searchBttn = new JButton(Messages.getString("ModifierExplorer.6")); //$NON-NLS-1$
    panel.add(nameLabel, "align label"); //$NON-NLS-1$
    panel.add(nameField);
    panel.add(groupLabel);
    panel.add(cbGroup);
    panel.add(searchBttn);

    TitledBorder title;
    Border loweredetched;
    loweredetched = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
    title = BorderFactory.createTitledBorder(loweredetched, Messages.getString("ModifierExplorer.8")); //$NON-NLS-1$
    title.setTitleJustification(TitledBorder.LEFT);
    panel.setBorder(title);
    searchBttn.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            List<MenuModifier> modifierList;
            String txName = nameField.getText();
            Object selectedItem = cbGroup.getSelectedItem();
            if (selectedItem instanceof MenuModifierGroup) {
                modifierList = ModifierDAO.getInstance().findModifier(txName, (MenuModifierGroup) selectedItem);
            } else {
                modifierList = ModifierDAO.getInstance().findModifier(txName, null);
            }

            setModifierList(modifierList);
        }
    });
    return panel;
}

From source file:DateChooserPanel.java

/**
 * Handles action-events from the date panel.
 *
 * @param e information about the event that occurred.
 *///from   w ww . ja v  a2  s  . com
public void actionPerformed(final ActionEvent e) {

    if (e.getActionCommand().equals("monthSelectionChanged")) {
        final JComboBox c = (JComboBox) e.getSource();

        // In most cases, changing the month will not change the selected
        // day.  But if the selected day is 29, 30 or 31 and the newly
        // selected month doesn't have that many days, we revert to the 
        // last day of the newly selected month...
        int dayOfMonth = this.chosenDate.get(Calendar.DAY_OF_MONTH);
        this.chosenDate.set(Calendar.DAY_OF_MONTH, 1);
        this.chosenDate.set(Calendar.MONTH, c.getSelectedIndex());
        int maxDayOfMonth = this.chosenDate.getActualMaximum(Calendar.DAY_OF_MONTH);
        this.chosenDate.set(Calendar.DAY_OF_MONTH, Math.min(dayOfMonth, maxDayOfMonth));
        refreshButtons();
    } else if (e.getActionCommand().equals("yearSelectionChanged")) {
        if (!this.refreshing) {
            final JComboBox c = (JComboBox) e.getSource();
            final Integer y = (Integer) c.getSelectedItem();

            // in most cases, changing the year will not change the 
            // selected day.  But if the selected day is Feb 29, and the
            // newly selected year is not a leap year, we revert to 
            // Feb 28...
            int dayOfMonth = this.chosenDate.get(Calendar.DAY_OF_MONTH);
            this.chosenDate.set(Calendar.DAY_OF_MONTH, 1);
            this.chosenDate.set(Calendar.YEAR, y.intValue());
            int maxDayOfMonth = this.chosenDate.getActualMaximum(Calendar.DAY_OF_MONTH);
            this.chosenDate.set(Calendar.DAY_OF_MONTH, Math.min(dayOfMonth, maxDayOfMonth));
            refreshYearSelector();
            refreshButtons();
        }
    } else if (e.getActionCommand().equals("todayButtonClicked")) {
        setDate(new Date());
    } else if (e.getActionCommand().equals("dateButtonClicked")) {
        final JButton b = (JButton) e.getSource();
        final int i = Integer.parseInt(b.getName());
        final Calendar cal = getFirstVisibleDate();
        cal.add(Calendar.DATE, i);
        setDate(cal.getTime());
    }
}

From source file:edu.ku.brc.specify.config.FeedBackDlg.java

@Override
protected FeedBackSenderItem getFeedBackSenderItem(final Class<?> cls, final Exception exception) {
    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,4px,p,4px,p,4px,p,4px,f:p:g"));

    Vector<String> taskItems = new Vector<String>();
    for (Taskable task : TaskMgr.getInstance().getAllTasks()) {
        taskItems.add(task.getTitle());/*from w  w  w.j  av  a 2s  .  c o  m*/
    }

    String[] OTHERS = { "WEBSITE", "CSTSUP", "INSTL", "DOC", "WHTPR", "HLP" };
    for (String key : OTHERS) {
        taskItems.add(UIRegistry.getResourceString("FeedBackDlg." + key));
    }
    Collections.sort(taskItems);

    final JComboBox taskCBX = createComboBox(taskItems);
    final JTextField subjectTF = createTextField();
    final JTextField issueTF = createTextField();
    final JTextArea commentsTA = createTextArea(15, 60);

    int y = 1;
    pb.add(createI18NLabel("FeedBackDlg.INFO"), cc.xyw(1, y, 4));
    y += 2;

    pb.add(createI18NFormLabel("FeedBackDlg.SUB"), cc.xy(1, y));
    pb.add(subjectTF, cc.xyw(3, y, 2));
    y += 2;

    pb.add(createI18NFormLabel("FeedBackDlg.COMP"), cc.xy(1, y));
    pb.add(taskCBX, cc.xy(3, y));
    y += 2;

    //pb.add(createFormLabel("Question/Issue"), cc.xy(1, y));
    //pb.add(issueTF,                           cc.xyw(3, y, 2)); y += 2;

    pb.add(createI18NFormLabel("FeedBackDlg.COMM"), cc.xy(1, y));
    y += 2;
    pb.add(createScrollPane(commentsTA, true), cc.xyw(1, y, 4));
    y += 2;

    Taskable currTask = SubPaneMgr.getInstance().getCurrentSubPane().getTask();
    taskCBX.setSelectedItem(currTask != null ? currTask : TaskMgr.getDefaultTaskable());

    pb.setDefaultDialogBorder();
    CustomDialog dlg = new CustomDialog((Frame) null, UIRegistry.getResourceString("FeedBackDlg.TITLE"), true,
            pb.getPanel());

    centerAndShow(dlg);

    if (!dlg.isCancelled()) {
        String taskTitle = (String) taskCBX.getSelectedItem();
        if (taskTitle != null) {
            for (Taskable task : TaskMgr.getInstance().getAllTasks()) {
                if (task.getTitle().equals(taskTitle)) {
                    taskTitle = task.getName();
                }
            }
        } else {
            taskTitle = "No Task Name";
        }
        FeedBackSenderItem item = new FeedBackSenderItem(taskTitle, subjectTF.getText(), issueTF.getText(),
                commentsTA.getText(), "", cls != null ? cls.getName() : "");
        return item;
    }
    return null;
}

From source file:com.brainflow.application.toplevel.Brainflow.java

private IImageDataSource specialHandling(IImageDataSource dataSource) {

    if (dataSource.getFileFormat().equals("Analyze7.5")) {
        JPanel panel = new JPanel();
        JLabel messageLabel = new JLabel("Please select correct image orientation from menu: ");
        java.util.List<Anatomy3D> choices = Anatomy3D.getInstanceList();
        JComboBox choiceBox = new JComboBox(choices.toArray());

        //todo hackery alert
        Anatomy anatomy = dataSource.getImageInfo().getAnatomy();
        choiceBox.setSelectedItem(anatomy);

        FormLayout layout = new FormLayout("4dlu, l:p, p:g, 4dlu", "6dlu, p, 10dlu, p, 6dlu");
        CellConstraints cc = new CellConstraints();
        panel.setLayout(layout);/*from w  w w .j  a  v  a2s  .c om*/
        panel.add(messageLabel, cc.xyw(2, 2, 2));
        panel.add(choiceBox, cc.xyw(2, 4, 2));

        JOptionPane.showMessageDialog(brainFrame, panel, "Analyze 7.5 image format ...",
                JOptionPane.WARNING_MESSAGE);
        Anatomy selectedAnatomy = (Anatomy) choiceBox.getSelectedItem();
        if (selectedAnatomy != anatomy) {
            //todo hackery alert
            dataSource.getImageInfo().setAnatomy((Anatomy3D) selectedAnatomy);
            dataSource.releaseData();
        }
    }

    return dataSource;

}

From source file:be.agiv.security.demo.Main.java

private void showPreferences() {
    JTabbedPane tabbedPane = new JTabbedPane();

    GridBagLayout proxyGridBagLayout = new GridBagLayout();
    GridBagConstraints proxyGridBagConstraints = new GridBagConstraints();
    JPanel proxyPanel = new JPanel(proxyGridBagLayout) {

        private static final long serialVersionUID = 1L;

        @Override/*from w w w .  j av a 2s  .  c  o  m*/
        public Insets getInsets() {
            return new Insets(10, 10, 10, 10);
        }
    };
    tabbedPane.addTab("Proxy", proxyPanel);

    JCheckBox proxyEnableCheckBox = new JCheckBox("Enable proxy", this.proxyEnable);
    proxyGridBagConstraints.gridx = 0;
    proxyGridBagConstraints.gridy = 0;
    proxyGridBagConstraints.anchor = GridBagConstraints.WEST;
    proxyGridBagConstraints.ipadx = 5;
    proxyGridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
    proxyGridBagLayout.setConstraints(proxyEnableCheckBox, proxyGridBagConstraints);
    proxyPanel.add(proxyEnableCheckBox);
    proxyGridBagConstraints.gridwidth = 1;

    JLabel proxyHostLabel = new JLabel("Host:");
    proxyGridBagConstraints.gridx = 0;
    proxyGridBagConstraints.gridy++;
    proxyGridBagLayout.setConstraints(proxyHostLabel, proxyGridBagConstraints);
    proxyPanel.add(proxyHostLabel);

    JTextField proxyHostTextField = new JTextField(this.proxyHost, 20);
    proxyGridBagConstraints.gridx++;
    proxyGridBagLayout.setConstraints(proxyHostTextField, proxyGridBagConstraints);
    proxyPanel.add(proxyHostTextField);

    JLabel proxyPortLabel = new JLabel("Port:");
    proxyGridBagConstraints.gridx = 0;
    proxyGridBagConstraints.gridy++;
    proxyGridBagLayout.setConstraints(proxyPortLabel, proxyGridBagConstraints);
    proxyPanel.add(proxyPortLabel);

    JTextField proxyPortTextField = new JTextField(Integer.toString(this.proxyPort), 8);
    proxyGridBagConstraints.gridx++;
    proxyGridBagLayout.setConstraints(proxyPortTextField, proxyGridBagConstraints);
    proxyPanel.add(proxyPortTextField);

    JLabel proxyTypeLabel = new JLabel("Type:");
    proxyGridBagConstraints.gridx = 0;
    proxyGridBagConstraints.gridy++;
    proxyGridBagLayout.setConstraints(proxyTypeLabel, proxyGridBagConstraints);
    proxyPanel.add(proxyTypeLabel);

    JComboBox proxyTypeComboBox = new JComboBox(new Object[] { Proxy.Type.HTTP, Proxy.Type.SOCKS });
    proxyTypeComboBox.setSelectedItem(this.proxyType);
    proxyGridBagConstraints.gridx++;
    proxyGridBagLayout.setConstraints(proxyTypeComboBox, proxyGridBagConstraints);
    proxyPanel.add(proxyTypeComboBox);

    int dialogResult = JOptionPane.showConfirmDialog(this, tabbedPane, "Preferences",
            JOptionPane.OK_CANCEL_OPTION);
    if (dialogResult == JOptionPane.CANCEL_OPTION) {
        return;
    }

    this.statusBar.setStatus("Applying new preferences...");
    this.proxyHost = proxyHostTextField.getText();
    this.proxyPort = Integer.parseInt(proxyPortTextField.getText());
    this.proxyType = (Proxy.Type) proxyTypeComboBox.getSelectedItem();
    this.proxyEnable = proxyEnableCheckBox.isSelected();
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.DataImportDialog.java

public void actionPerformed(ActionEvent e) {
    JComboBox cb = (JComboBox) e.getSource();
    //Object source = e.g
    String str = (String) cb.getSelectedItem();
    log.debug("actionPerformed");
    if (str.equals("\"")) {
        stringQualifierChar = '\"';
        changeQualifier(str);/*  w  w w .j a  va  2s.c  o m*/
    } else if (str.equals("\'")) {
        stringQualifierChar = '\'';
        changeQualifier(str);
    } else if (str.equals("{" + getResourceString("NONE") + "}")) {
        changeQualifier(str);
    } else if (str.equals("US-ASCII") || str.equals("ISO-8859-1") || str.equals("UTF-8")) {
        charset = Charset.forName(str);
    } else if (str.equals(getResourceString("DEFAULT"))) {
        charset = Charset.defaultCharset();
    } else if (str.equals(getResourceString("BACKSLASH"))) {
        escapeMode = CsvReader.ESCAPE_MODE_BACKSLASH;
    } else if (str.equals(getResourceString("DOUBLED"))) {
        escapeMode = CsvReader.ESCAPE_MODE_DOUBLED;
    }
    updateTableDisplay();
}

From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java

public void actionPerformed(ActionEvent event) {
    if (event.getSource() == addButton1) {
        addButtonDependent();//from   ww  w  .  ja va2 s.c o  m
        return;
    } else if (event.getSource() == removeButton1) {
        removeButtonDependent();
        return;
    } else if (event.getSource() == addButton2) {
        addButtonIndependent();
        return;
    } else if (event.getSource() == removeButton2) {
        removeButtonIndependent();
        return;
    }

    if (event.getSource() == stepJButton) {
        stop();
        for (int s = 0; s < num_series; s++) {
            mEMexperiment[s].EM(ws);
        }
    } else if (event.getSource() == runJButton) {
        stop();
        start();
        return;
    } else if (event.getSource() == stopJButton) {
        stop();
    } else if (event.getSource() == segmentJButton) {

        stop();
        if (mixSelected == GL_MIX)
            return;

        XYDataset[] ds1 = new XYDataset[num_series];
        for (int s = 0; s < num_series; s++)
            ds1[s] = mEMexperiment[s].getSegmentedPoints();
        //   resultsTable = mEMexperiment.getResultsTable();
        segment_flag = true;

        if (ds1 != null) {
            setTable(storage_ds);
            //if (redoTable)
            kernels = addKernels();
            chart = createChart(ds1);
            refreshChartPanel();
            setChart();
        }
        return;
    } else if (event.getSource() instanceof JComboBox) {
        JComboBox JCB = (JComboBox) event.getSource();
        String JCB_Value = (String) JCB.getSelectedItem();
        //  System.out.println("JCB_Value = " + JCB_Value);

        if (JCB_Value.indexOf("Together") != -1) {
            // System.out.println("GaussMix");
            modelAllSelected = TOGETHER;
            setEM();
            updateKernels();
        } else if (JCB_Value.indexOf("independently") != -1) {
            // System.out.println("GaussMix");
            modelAllSelected = SEPARATE;
            setEM();
            updateKernels();
        } else if (JCB_Value.equals("GaussMix")) {
            // System.out.println("GaussMix");
            setMixtureSelect(CG_MIX);
            updateKernels();
        } else if (JCB_Value.equals("LineMix")) {
            //  System.out.println("LinearMix");
            setMixtureSelect(GL_MIX);
            updateKernels();
        } else if (JCB_Value.equals("Fast")) {
            // System.out.println("Speed selected: Fast");
            setSpeed("Fast");
        } else if (JCB_Value.equals("Normal")) {
            // System.out.println("Speed selected: Normal");
            setSpeed("Normal");
        } else if (JCB_Value.equals("Slow")) {
            // System.out.println("Speed selected: Slow");
            setSpeed("Slow");
        } else // Number of Kernels
        {
            stop();
            nkSelected = Integer.parseInt(JCB_Value);
            for (int s = 0; s < num_series; s++) {
                mEMexperiment[s].setNumOfKernels(nkSelected);
            }
            updateKernels();
            if (EM_Thread != null)
                start();
        }
    } else if (event.getActionCommand().equals("ClearPts")) {
        resetMappingList();
        for (int s = 0; s < num_series; s++) {
            mEMexperiment[s].getDB().clearPoints();
            mEMexperiment[s].resetSize();
        }
    } else if (event.getActionCommand().equals("RandomPts")) {
        for (int s = 0; s < num_series; s++) {
            mEMexperiment[s].getDB().randomPoints(NUM_RANDOM_PTS);
            mEMexperiment[s].resetSize();
        }
        addRandomPts2Storage();
        //updateKernels();
        // System.out.println("ButtonRandomPts::DB.nPoints()=" + mEMexperiment.getDB().nPoints());
    } else if (event.getActionCommand().equals("InitKernels")) {
        updateKernels();
    } else if (event.getActionCommand().equals("AutoInitKernels")) {
        manualKernel = false;
        isPressingAlt = false;
        for (int s = 0; s < num_series; s++) {
            mEMexperiment[s].setManualKernel(false);
        }
        initControlPanel();
        this.getContentPane().add(toolContainer, BorderLayout.NORTH);
        updateKernels();
    } else if (event.getActionCommand().equals("RemoveLastKernel")) {
        removeLastManualKernel();

    }

    // System.out.println("Action performed : inde="+independentVarLength);
    redoChart(); // redotable
    //  System.out.println("Action performed after redoChart : inde="+independentVarLength);
    return;
}

From source file:Interface.Stats.java

/**
 *
 * @param f /*ww w .  j a  v a  2  s.  c  o  m*/
 */
private Stats(JFrame f) {
    // On initialise les boutons
    JButton valider = new JButton("Valider");
    JButton retour = new JButton("Retour");
    JComboBox combo = new JComboBox();

    // On initialise et remplit la combobox
    combo.setPreferredSize(new Dimension(400, 30));
    combo.addItem("Nombre de patient par service");
    combo.addItem("Salaire moyen des employs");
    combo.addItem("Nombre d'intervention par mdecin");

    // On initialise les JLabels
    JLabel texte = new JLabel("Veuillez selectionner la requete  envoyer");

    // On change le bouton de forme
    valider.setPreferredSize(new Dimension(200, 30));
    valider.setOpaque(false);
    retour.setPreferredSize(new Dimension(200, 30));
    retour.setOpaque(false);

    // On initialise les Jpanels
    p1 = new JPanel();
    p1.setPreferredSize(new Dimension(600, 100));
    p1.add(texte);
    p1.setOpaque(false);

    p2 = new JPanel();
    p2.add(combo);
    p2.setOpaque(false);

    p4 = new JPanel();
    p4.add(retour);
    p4.add(valider);
    p4.setOpaque(false);

    // Gestion des boutons
    retour.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Accueil.getFenetre(f);
        }
    });

    valider.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (combo.getSelectedItem().equals("Nombre de patient par service")) {

                System.out.println(
                        "Nb de patients en REA : " + Connexion.getInstance().nb_malade_services("\"REA\""));
                System.out.println(
                        "Nb de patients en ORL : " + Connexion.getInstance().nb_malade_services("\"ORL\""));
                System.out.println(
                        "Nb de patients en CHG : " + Connexion.getInstance().nb_malade_services("\"CHG\""));

                //      new Camembert(f, Connexion.getInstance().nb_malade_services("\"REA\""), Connexion.getInstance().nb_malade_services("\"ORL\""), Connexion.getInstance().nb_malade_services("\"CHG\""));
                JPanel panel_camemb = Camembert.cCamembert(f,
                        Connexion.getInstance().nb_malade_services("\"REA\""),
                        Connexion.getInstance().nb_malade_services("\"ORL\""),
                        Connexion.getInstance().nb_malade_services("\"CHG\""));
                ;

                f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                f.add(p1);
                f.add(p2);
                f.add(p4);
                f.add(panel_camemb);

                f.setVisible(true);

            } else if (combo.getSelectedItem().equals("Salaire moyen des employs")) {
                JLabel jf_doc, jf_inf, jf_emp;
                JTextField jtf_doc, jtf_inf, jtf_emp;
                JPanel p5, p6, p7;

                // On initialise les JF
                jf_doc = new JLabel("Salaire moyen des docteurs");
                jf_inf = new JLabel("Salaire moyen des infirmiers");
                jf_emp = new JLabel("Salaire moyen de tous les employs");

                // On initialise les JTF
                jtf_doc = new JTextField();
                jtf_doc.setPreferredSize(new Dimension(200, 30));
                jtf_doc.setText(Float.toString(Connexion.getInstance().moyenne_salaired()) + " ");

                jtf_inf = new JTextField();
                jtf_inf.setPreferredSize(new Dimension(200, 30));
                jtf_inf.setText(Float.toString((Connexion.getInstance().moyenne_salairei())) + " ");

                jtf_emp = new JTextField();
                jtf_emp.setPreferredSize(new Dimension(160, 30));
                jtf_emp.setText(Float.toString((Connexion.getInstance().moyenne_salaire())) + " ");

                // On cre les JPanels
                p5 = new JPanel();
                p5.add(jf_doc);
                p5.add(jtf_doc);
                p5.setOpaque(false);

                p6 = new JPanel();
                p6.add(jf_inf);
                p6.add(jtf_inf);
                p6.setOpaque(false);

                p7 = new JPanel();
                p7.add(jf_emp);
                p7.add(jtf_emp);
                p7.setOpaque(false);

                f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                f.add(p1);
                f.add(p2);
                f.add(p4);
                f.add(p5);
                f.add(p6);
                f.add(p7);

                f.setVisible(true);
                f.setSize(new Dimension(600, 600));
            } else if (combo.getSelectedItem().equals("Nombre d'intervention par mdecin")) {
                ArrayList liste = null;
                try {
                    // ICI !!!!!!!!!!
                    liste = Connexion.getInstance().reporting(
                            "SELECT e.nom , COUNT(d.no_docteur) FROM hospitalisation h, docteur d , employe e WHERE (h.no_docteur= d.no_docteur) AND e.no_employe = d.no_docteur  GROUP BY e.nom");
                } catch (SQLException ex) {
                    Logger.getLogger(Stats.class.getName()).log(Level.SEVERE, null, ex);
                }
                if (liste != null) {
                    JPanel panel_camemb = Camembert.cCamembert(f, liste);

                    f.setContentPane(new ImagePanel(new ImageIcon("fond66.jpg").getImage())); // Met l'image en background
                    f.add(p1);
                    f.add(p2);
                    f.add(p4);
                    f.add(panel_camemb);

                    f.setVisible(true);
                }

            }
        }
    });
}

From source file:projects.wdlf47tuc.ProcessAllSwathcal.java

/**
 * Main entry point./*from www  . ja  v  a2  s. c om*/
 * 
 * @param args
 * 
 * @throws IOException 
 * 
 */
public ProcessAllSwathcal() {

    // Path to AllSwathcal.dat file
    File allSwathcal = new File(
            "/home/nrowell/Astronomy/Data/47_Tuc/Kalirai_2012/UVIS/www.stsci.edu/~jkalirai/47Tuc/AllSwathcal.dat");

    // Read file contents into the List
    try (BufferedReader in = new BufferedReader(new FileReader(allSwathcal))) {
        String sourceStr;
        while ((sourceStr = in.readLine()) != null) {
            Source source = Source.parseSource(sourceStr);
            if (source != null) {
                allSources.add(source);
            }
        }
    } catch (IOException e) {
    }

    logger.info("Parsed " + allSources.size() + " Sources from AllSwathcal.dat");

    // Initialise chart
    cmdPanel = new ChartPanel(updateDataAndPlotCmd(allSources));
    cmdPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent e) {
            // Capture mouse click location, transform to graph coordinates and add
            // a point to the polygonal selection box.
            Point2D p = cmdPanel.translateScreenToJava2D(e.getTrigger().getPoint());
            Rectangle2D plotArea = cmdPanel.getScreenDataArea();
            XYPlot plot = (XYPlot) cmdPanel.getChart().getPlot();
            double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge());
            double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge());
            points.add(new double[] { chartX, chartY });
            cmdPanel.setChart(plotCmd());
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent arg0) {
        }
    });

    // Create colour combo boxes
    final JComboBox<Filter> magComboBox = new JComboBox<Filter>(filters);
    final JComboBox<Filter> col1ComboBox = new JComboBox<Filter>(filters);
    final JComboBox<Filter> col2ComboBox = new JComboBox<Filter>(filters);

    // Set initial values
    magComboBox.setSelectedItem(magFilter);
    col1ComboBox.setSelectedItem(col1Filter);
    col2ComboBox.setSelectedItem(col2Filter);

    // Create an action listener for these
    ActionListener al = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            if (evt.getSource() == magComboBox) {
                magFilter = (Filter) magComboBox.getSelectedItem();
            }
            if (evt.getSource() == col1ComboBox) {
                col1Filter = (Filter) col1ComboBox.getSelectedItem();
            }
            if (evt.getSource() == col2ComboBox) {
                col2Filter = (Filter) col2ComboBox.getSelectedItem();
            }
            // Changed colour(s), so reset selection box coordinates
            points.clear();
            cmdPanel.setChart(updateDataAndPlotCmd(allSources));
        }
    };
    magComboBox.addActionListener(al);
    col1ComboBox.addActionListener(al);
    col2ComboBox.addActionListener(al);
    // Add a bit of padding to space things out
    magComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));
    col1ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));
    col2ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Set up statistic sliders
    final JSlider magErrMaxSlider = GuiUtil.buildSlider(magErrorRangeMin, magErrorRangeMax, 3, "%3.3f");
    final JSlider chi2MaxSlider = GuiUtil.buildSlider(chi2RangeMin, chi2RangeMax, 3, "%3.3f");
    final JSlider sharpMinSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f");
    final JSlider sharpMaxSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f");

    // Set intial values
    magErrMaxSlider.setValue(
            (int) Math.rint(100.0 * (magErrMax - magErrorRangeMin) / (magErrorRangeMax - magErrorRangeMin)));
    chi2MaxSlider.setValue((int) Math.rint(100.0 * (chi2Max - chi2RangeMin) / (chi2RangeMax - chi2RangeMin)));
    sharpMinSlider
            .setValue((int) Math.rint(100.0 * (sharpMin - sharpRangeMin) / (sharpRangeMax - sharpRangeMin)));
    sharpMaxSlider
            .setValue((int) Math.rint(100.0 * (sharpMax - sharpRangeMin) / (sharpRangeMax - sharpRangeMin)));

    // Set labels & initial values
    final JLabel magErrMaxLabel = new JLabel(getMagErrMaxLabel());
    final JLabel chi2MaxLabel = new JLabel(getChi2MaxLabel());
    final JLabel sharpMinLabel = new JLabel(getSharpMinLabel());
    final JLabel sharpMaxLabel = new JLabel(getSharpMaxLabel());

    // Create a change listener fot these
    ChangeListener cl = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();

            if (source == magErrMaxSlider) {
                // Compute max mag error from slider position
                double newMagErrMax = magErrorRangeMin
                        + (magErrorRangeMax - magErrorRangeMin) * (source.getValue() / 100.0);
                magErrMax = newMagErrMax;
                magErrMaxLabel.setText(getMagErrMaxLabel());
            }
            if (source == chi2MaxSlider) {
                // Compute Chi2 max from slider position
                double newChi2Max = chi2RangeMin + (chi2RangeMax - chi2RangeMin) * (source.getValue() / 100.0);
                chi2Max = newChi2Max;
                chi2MaxLabel.setText(getChi2MaxLabel());
            }
            if (source == sharpMinSlider) {
                // Compute sharp min from slider position
                double newSharpMin = sharpRangeMin
                        + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0);
                sharpMin = newSharpMin;
                sharpMinLabel.setText(getSharpMinLabel());
            }
            if (source == sharpMaxSlider) {
                // Compute sharp max from slider position
                double newSharpMax = sharpRangeMin
                        + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0);
                sharpMax = newSharpMax;
                sharpMaxLabel.setText(getSharpMaxLabel());
            }
            cmdPanel.setChart(updateDataAndPlotCmd(allSources));
        }
    };
    magErrMaxSlider.addChangeListener(cl);
    chi2MaxSlider.addChangeListener(cl);
    sharpMinSlider.addChangeListener(cl);
    sharpMaxSlider.addChangeListener(cl);
    // Add a bit of padding to space things out
    magErrMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    chi2MaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    sharpMinSlider.setBorder(new EmptyBorder(5, 5, 5, 5));
    sharpMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Text field to store distance modulus
    final JTextField distanceModulusField = new JTextField(Double.toString(mu));
    distanceModulusField.setBorder(new EmptyBorder(5, 5, 5, 5));

    Border compound = BorderFactory.createCompoundBorder(new LineBorder(this.getBackground(), 5),
            BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

    final JButton lfButton = new JButton("Luminosity function for selection");
    lfButton.setBorder(compound);
    lfButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            // Read distance modulus field
            try {
                double mu_new = Double.parseDouble(distanceModulusField.getText());
                mu = mu_new;
            } catch (NullPointerException | NumberFormatException ex) {
                JOptionPane.showMessageDialog(lfButton,
                        "Error parsing the distance modulus: " + ex.getMessage(), "Distance Modulus Error",
                        JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (boxedSources.isEmpty()) {
                JOptionPane.showMessageDialog(lfButton, "No sources are currently selected!", "Selection Error",
                        JOptionPane.ERROR_MESSAGE);
            } else {
                computeAndPlotLuminosityFunction(boxedSources);
            }
        }
    });
    final JButton clearSelectionButton = new JButton("Clear selection");
    clearSelectionButton.setBorder(compound);
    clearSelectionButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            points.clear();
            cmdPanel.setChart(plotCmd());
        }
    });

    JPanel controls = new JPanel(new GridLayout(9, 2));
    controls.setBorder(new EmptyBorder(10, 10, 10, 10));
    controls.add(new JLabel("Magnitude = "));
    controls.add(magComboBox);
    controls.add(new JLabel("Colour 1 = "));
    controls.add(col1ComboBox);
    controls.add(new JLabel("Colour 2 = "));
    controls.add(col2ComboBox);
    controls.add(magErrMaxLabel);
    controls.add(magErrMaxSlider);
    controls.add(chi2MaxLabel);
    controls.add(chi2MaxSlider);
    controls.add(sharpMinLabel);
    controls.add(sharpMinSlider);
    controls.add(sharpMaxLabel);
    controls.add(sharpMaxSlider);
    controls.add(new JLabel("Adopted distance modulus = "));
    controls.add(distanceModulusField);
    controls.add(lfButton);
    controls.add(clearSelectionButton);

    this.setLayout(new BorderLayout());
    this.add(cmdPanel, BorderLayout.CENTER);
    this.add(controls, BorderLayout.SOUTH);

    this.validate();
}

From source file:ffx.ui.ModelingPanel.java

/**
 * {@inheritDoc}//from ww  w  .java 2s. com
 */
@Override
public void actionPerformed(ActionEvent evt) {
    synchronized (this) {
        String actionCommand = evt.getActionCommand();
        // A change to the selected TINKER Command
        switch (actionCommand) {
        case "FFXCommand":
            JComboBox jcb = (JComboBox) toolBar.getComponentAtIndex(2);
            String com = jcb.getSelectedItem().toString();
            if (!com.equals(activeCommand)) {
                activeCommand = com.toLowerCase();
                loadCommand();
            }
            break;
        case "LogSettings":
            // A change to the Log Settings.
            loadLogSettings();
            statusLabel.setText("  " + createCommandInput());
            break;
        case "Launch":
            // Launch the selected Force Field X command.
            runScript();
            break;
        case "NUCLEIC":
        case "PROTEIN":
            // Editor functions for the Protein and Nucleic Acid Builders
            builderCommandEvent(evt);
            break;
        case "Conditional":
            // Some command options are conditional on other input.
            conditionalCommandEvent(evt);
            break;
        case "End":
            // End the currently executing command.
            setEnd();
            break;
        case "Delete":
            // Delete log files.
            deleteLogs();
            break;
        case "Description":
            // Allow command descriptions to be hidden.
            JCheckBoxMenuItem box = (JCheckBoxMenuItem) evt.getSource();
            setDivider(box.isSelected());
            break;
        default:
            logger.log(Level.WARNING, "ModelingPanel ActionCommand not recognized: {0}", evt);
            break;
        }
    }
}