Example usage for javax.swing JButton setEnabled

List of usage examples for javax.swing JButton setEnabled

Introduction

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

Prototype

public void setEnabled(boolean b) 

Source Link

Document

Enables (or disables) the button.

Usage

From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java

private AbstractWizardPage getCreatePage() {
    //setup page//  w  ww.jav a  2  s .  co  m
    final DefaultWizardPage page = new DefaultWizardPage(PAGENAME_CREATE) {
        @Override
        public void setupWizardButtons() {
            fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK);
            fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH);
            fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT);
        }
    };
    page.addText("You are now ready to " + (modify ? "make changes to" : "create") + " this project. ");

    final JLabel progressLabel = new JLabel("");

    page.addComponent(progressLabel);

    final JButton workButton = new JButton((modify ? "Modify Project" : "Create Project"));
    final JButton publishButton = new JButton("Publish Variants");

    final JComponent j = new JLabel(
            "<html><p>You may continue. The import process will continue in the< background and you will be notified upon completion.</p></html>");

    workButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            j.setVisible(true);
            page.fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);

            workButton.setEnabled(false);

            new ProjectWorker<Void>("Modifying project", autoPublish.isSelected(),
                    LoginController.getSessionID(), projectID) {
                @Override
                protected Void runInBackground() throws Exception {
                    LOG.info("Requesting modification from server");
                    modifyProject(true, true, true, this);
                    LOG.info("Modification complete");
                    return null;
                }
            }.execute();

            toFront();
        }
    });

    page.addComponent(ViewUtil.alignRight(workButton));

    page.addComponent(j);
    j.setVisible(false);

    if (modify) {
        page.addComponent(ViewUtil.alignRight(publishButton));
        publishButton.setVisible(false);
    }

    return page;
}

From source file:org.ut.biolab.medsavant.client.region.RegionWizard.java

private AbstractWizardPage getGenesPage() {
    return new DefaultWizardPage(PAGENAME_GENES) {
        private static final int GENE_SELECTION_PANE_WIDTH = 350;
        private JPanel leftSide;
        private GeneSelectionPanel geneManiaResultsPanel;
        private Set<String> geneManiaGeneNames = null;

        {/*from w ww.ja va2 s .  c  o  m*/
            selectedGenesPanel = new GeneSelectionPanel(true, true);
            sourceGenesPanel = new GeneSelectionPanel(true, true);
            geneManiaResultsPanel = new GeneSelectionPanel(true, true) {
                @Override
                protected void dragAndDropAddGenes(Set<Gene> geneSet) {
                    Set<Object> genesToMoveToGeneManiaPanel = new HashSet<Object>(geneManiaGeneNames);
                    genesToMoveToGeneManiaPanel.retainAll(selectedGenesPanel.getSelectedKeys());
                    selectedGenesPanel.copyItems(geneManiaResultsPanel, genesToMoveToGeneManiaPanel);
                    selectedGenesPanel.moveSelectedItems(sourceGenesPanel);
                }

                @Override
                protected void dragAndDropRemoveKeys(Set<Object> keySet) {
                    Set<Object> keys = geneManiaResultsPanel.getSelectedKeys();
                    geneManiaResultsPanel.removeRows(keys);
                    sourceGenesPanel.removeRows(keys);
                }
            };
            geneManiaResultsPanel.setOddRowColor(new Color(242, 249, 245));

            runGeneManiaButton = new JButton("Run GeneMANIA");
            runGeneManiaButton.setEnabled(!DirectorySettings.isGeneManiaInstalled());

            ListSelectionListener selectionListener = new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent lse) {
                    int numSel = sourceGenesPanel.getNumSelected() + selectedGenesPanel.getNumSelected();
                    if (geneManiaGeneNames != null) {
                        numSel += geneManiaResultsPanel.getNumSelected();
                    }
                    if (GenemaniaInfoRetriever.isGeneManiaDownloading()) {
                        runGeneManiaButton.setEnabled(false);
                    } else {
                        runGeneManiaButton.setEnabled(numSel > 0 || !DirectorySettings.isGeneManiaInstalled());
                    }
                }
            };

            sourceGenesPanel.getTable().getSelectionModel().addListSelectionListener(selectionListener);
            selectedGenesPanel.getTable().getSelectionModel().addListSelectionListener(selectionListener);
            selectedGenesPanel.getTable().getModel().addTableModelListener(new TableModelListener() {
                @Override
                public void tableChanged(TableModelEvent tme) {
                    if (selectedGenesPanel.getData().length > 0) {
                        fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);
                    } else {
                        fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT);
                    }
                }
            });

            selectedGenesPanel.setPreferredSize(
                    new Dimension(GENE_SELECTION_PANE_WIDTH, selectedGenesPanel.getPreferredSize().height));

            final JPanel outerLeftSide = new JPanel();
            outerLeftSide.setLayout(new BoxLayout(outerLeftSide, BoxLayout.X_AXIS));

            leftSide = new JPanel();
            leftSide.setLayout(new BoxLayout(leftSide, BoxLayout.Y_AXIS));
            leftSide.add(sourceGenesPanel);
            outerLeftSide.add(leftSide);
            final JPanel bg = new JPanel();
            bg.setLayout(new BoxLayout(bg, BoxLayout.Y_AXIS));

            JButton addButton = new JButton("Add ");
            JButton removeButton = new JButton("? Remove");

            sourceGenesPanel.getTable().addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent me) {
                    if (me.getClickCount() == 2) {
                        sourceGenesPanel.moveSelectedItems(selectedGenesPanel);
                    }
                }
            });

            selectedGenesPanel.getTable().addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent me) {
                    if (me.getClickCount() == 2) {
                        if (geneManiaGeneNames != null) {
                            Set<Object> genesToMoveToGeneManiaPanel = new HashSet<Object>(geneManiaGeneNames);
                            genesToMoveToGeneManiaPanel.retainAll(selectedGenesPanel.getSelectedKeys());
                            selectedGenesPanel.copyItems(geneManiaResultsPanel, genesToMoveToGeneManiaPanel);
                        }
                        selectedGenesPanel.moveSelectedItems(sourceGenesPanel);
                    }
                }
            });

            geneManiaResultsPanel.getTable().addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent me) {
                    if (me.getClickCount() == 2) {
                        Set<Object> keys = geneManiaResultsPanel.getSelectedKeys();
                        geneManiaResultsPanel.moveSelectedItems(selectedGenesPanel);
                        sourceGenesPanel.moveItems(selectedGenesPanel, keys);
                    }
                }
            });

            addButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    if (geneManiaGeneNames != null) {
                        Set<Object> keys = geneManiaResultsPanel.getSelectedKeys();
                        geneManiaResultsPanel.moveSelectedItems(selectedGenesPanel);
                        sourceGenesPanel.moveItems(selectedGenesPanel, keys);
                    } else {
                        sourceGenesPanel.moveSelectedItems(selectedGenesPanel);
                    }
                }
            });

            removeButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    if (geneManiaGeneNames != null) {
                        Set<Object> genesToMoveToGeneManiaPanel = new HashSet<Object>(geneManiaGeneNames);
                        genesToMoveToGeneManiaPanel.retainAll(selectedGenesPanel.getSelectedKeys());
                        selectedGenesPanel.copyItems(geneManiaResultsPanel, genesToMoveToGeneManiaPanel);
                    }
                    selectedGenesPanel.moveSelectedItems(sourceGenesPanel);
                }
            });

            bg.add(Box.createVerticalGlue());
            bg.add(addButton);
            bg.add(removeButton);
            bg.add(Box.createVerticalGlue());
            outerLeftSide.add(bg);

            JPanel rightSide = new JPanel();
            rightSide.setLayout(new BoxLayout(rightSide, BoxLayout.Y_AXIS));
            rightSide.add(selectedGenesPanel);
            rightSide.add(runGeneManiaButton);

            final JSplitPane hsplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, outerLeftSide, rightSide);
            hsplitPane.setResizeWeight(1);
            addComponent(hsplitPane, true);

            if (!DirectorySettings.isGeneManiaInstalled()) {
                runGeneManiaButton.setText("Download GeneMANIA");
                if (GenemaniaInfoRetriever.isGeneManiaDownloading()) {
                    runGeneManiaButton.setEnabled(false);
                    registerDownloadListener();
                }
            }

            runGeneManiaButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {

                    if (!DirectorySettings.isGeneManiaInstalled()) {
                        int response = DialogUtils.askYesNo("Download GeneMANIA?",
                                "GeneMANIA is not yet installed.  Do you want to download and install it now?");
                        try {
                            if (response == DialogUtils.OK) {
                                runGeneManiaButton.setText("Run GeneMANIA");
                                runGeneManiaButton.setEnabled(false);
                                registerDownloadListener();

                                /*
                                 DownloadTask dt = GenemaniaInfoRetriever.getGeneManiaDownloadTask();
                                 dt.addPropertyChangeListener(new PropertyChangeListener() {
                                 @Override
                                 public void propertyChange(PropertyChangeEvent evt) {
                                 if (evt.getPropertyName().equals("downloadState")) {
                                 DownloadTask.DownloadState ds = (DownloadTask.DownloadState) evt.getNewValue();
                                 if (ds == DownloadTask.DownloadState.CANCELLED
                                 || ds == DownloadTask.DownloadState.FINISHED) {
                                        
                                 runGeneManiaButton.setEnabled(
                                 (selectedGenesPanel.getNumSelected() + sourceGenesPanel.getNumSelected()) > 0);
                                 }
                                 }
                                 }
                                 });
                                 */
                                GenemaniaInfoRetriever.getGeneManiaDownloadTask().execute();
                            }
                        } catch (IOException e) {
                            DialogUtils.displayMessage("Error downloading GeneMANIA files");
                            LOG.error(e);
                        }
                    } else {

                        final List<String> selectedGenes = new LinkedList<String>();
                        for (Gene g : selectedGenesPanel.getSelectedGenes()) {
                            selectedGenes.add(g.getName());
                        }
                        for (Gene g : sourceGenesPanel.getSelectedGenes()) {
                            selectedGenes.add(g.getName());
                        }
                        if (geneManiaGeneNames != null) {
                            for (Gene g : geneManiaResultsPanel.getSelectedGenes()) {
                                selectedGenes.add(g.getName());
                            }
                        }
                        final JButton closeGeneManiaButton = new JButton("? Close GeneMANIA results");
                        closeGeneManiaButton.setEnabled(false);
                        final JPanel geneManiaContainingPanel = new JPanel();
                        geneManiaContainingPanel
                                .setLayout(new BoxLayout(geneManiaContainingPanel, BoxLayout.Y_AXIS));

                        final SwingWorker geneManiaWorker = new SwingWorker() {
                            private List<Object[]> results;

                            @Override
                            public void done() {
                                Object[][] newdata = new Object[results.size()][4];
                                results.toArray(newdata);
                                geneManiaResultsPanel.updateData(newdata);
                                geneManiaResultsPanel.updateView();
                                geneManiaContainingPanel.removeAll();
                                geneManiaContainingPanel.add(geneManiaResultsPanel);
                                geneManiaContainingPanel.revalidate();
                                geneManiaContainingPanel.repaint();
                                closeGeneManiaButton.setEnabled(true);
                            }

                            @Override
                            public Object doInBackground() {
                                try {
                                    GenemaniaInfoRetriever genemania = new GenemaniaInfoRetriever();
                                    genemania.setGenes(selectedGenes);
                                    List<String> geneNameList = genemania.getRelatedGeneNamesByScore();
                                    geneManiaGeneNames = new HashSet<String>();
                                    geneManiaGeneNames.addAll(geneNameList);
                                    LOG.debug("Found " + geneNameList.size() + " related genes");

                                    results = new ArrayList<Object[]>(geneNameList.size());

                                    int i = 0;
                                    for (String gene : geneNameList) {
                                        if (isCancelled()) {
                                            return null;
                                        }
                                        Gene g = GeneSetFetcher.getInstance().getGeneDictionary().get(gene);
                                        if (g == null) {
                                            LOG.warn("No gene found for " + gene);
                                        } else if (!selectedGenesPanel.hasKey(g.getName())) {
                                            results.add(new Object[] { g.getName(), g.getChrom(), g.getStart(),
                                                    g.getEnd() });
                                        }
                                    }
                                } catch (IOException e) {
                                    LOG.error(e);
                                } catch (ApplicationException e) {
                                    LOG.error(e);
                                } catch (DataStoreException e) {
                                    LOG.error(e);
                                } catch (NoRelatedGenesInfoException e) {
                                    LOG.error(e);
                                }
                                return null;
                            }
                        };

                        leftSide.removeAll();

                        closeGeneManiaButton.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent ae) {
                                try {
                                    geneManiaWorker.cancel(true);
                                } catch (Exception e) {
                                    //genemania throws exceptions when cancelled
                                }
                                leftSide.removeAll();
                                leftSide.add(sourceGenesPanel);
                                leftSide.validate();
                                leftSide.repaint();
                                geneManiaGeneNames = null;
                            }
                        });

                        JPanel closeButtonPanel = new JPanel();
                        closeButtonPanel.setLayout(new BoxLayout(closeButtonPanel, BoxLayout.X_AXIS));
                        closeButtonPanel.add(closeGeneManiaButton);
                        closeButtonPanel.add(Box.createHorizontalGlue());

                        leftSide.add(closeButtonPanel);

                        geneManiaContainingPanel.add(new WaitPanel("Querying GeneMANIA for related genes"));

                        leftSide.add(geneManiaContainingPanel);
                        leftSide.validate();
                        leftSide.repaint();
                        geneManiaWorker.execute();

                    } //end else
                }//end actionPerformed
            });//end ActionListener
        }

        @Override
        public void setupWizardButtons() {
            fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH);
            fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK);

            if (selectedGenesPanel.getNumSelected() > 0) {
                fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);
            } else {
                fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT);
            }
        }
    };
}

From source file:org.ut.biolab.medsavant.client.variant.VariantWorker.java

/**
 * Initialise functionality shared by all UpdateWorkers and PublicationWorkers.
 *
 * @param activity "Importing", "Publishing", or "Removing"
 * @param wizard the wizard which is providing the user interface
 * @param progressLabel label which indicates progress activity
 * @param progressBar provides quantitative display of progress
 * @param workButton starts the process and cancels it
 *///from w  ww  .j  a v  a2s. co  m
VariantWorker(String activity, WizardDialog wizard, JLabel progressLabel, JProgressBar progressBar,
        JButton workButton) {
    super(activity + "Variants");
    this.activity = activity;
    this.wizard = wizard;
    this.progressLabel = progressLabel;
    this.progressBar = progressBar;
    this.workButton = workButton;

    progressLabel.setText(String.format("%s ...", activity));

    // Convert our start button into a cancel button.
    workButton.setText("Cancel");
    if (workButton.getActionListeners().length > 0) {
        workButton.removeActionListener(workButton.getActionListeners()[0]);
    }
    workButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            VariantWorker.this.progressBar.setIndeterminate(true);
            VariantWorker.this.workButton.setText("Cancelling...");
            VariantWorker.this.workButton.setEnabled(false);
            cancel(true);
        }
    });

    workButton.setEnabled(true);
    wizard.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}

From source file:org.ut.biolab.medsavant.client.view.dialog.FamilySelector.java

private void initUI() {

    JPanel p = new JPanel();
    ViewUtil.applyVerticalBoxLayout(p);/* ww  w  .j  a v a2  s . c  o m*/
    this.add(p);

    topPanel = ViewUtil.getClearPanel();
    middlePanel = ViewUtil.getClearPanel();
    bottomPanel = ViewUtil.getClearPanel();

    p.add(topPanel);
    p.add(middlePanel);
    p.add(bottomPanel);

    // middle
    middlePanel.setLayout(new BorderLayout());

    retriever = new FamilyReceiver();

    stp = new SearchableTablePanel("Individuals", COLUMN_NAMES, COLUMN_CLASSES, HIDDEN_COLUMNS, true, true,
            Integer.MAX_VALUE, false, SearchableTablePanel.TableSelectionType.ROW, Integer.MAX_VALUE,
            retriever);
    stp.setExportButtonVisible(false);

    middlePanel.add(stp, BorderLayout.CENTER);

    // bottom
    ViewUtil.applyVerticalBoxLayout(bottomPanel);

    numselections = ViewUtil.getTitleLabel("0 families selected");

    JPanel text = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(text);

    JButton clearIndividuals = ViewUtil
            .getIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.CLOSE));
    clearIndividuals.setToolTipText("Clear selections");
    clearIndividuals.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            clearSelections();
        }
    });

    text.add(numselections);
    text.add(Box.createHorizontalStrut(5));
    text.add(clearIndividuals);
    bottomPanel.add(ViewUtil.centerHorizontally(text));

    final JButton addAllIndividuals = ViewUtil.getSoftButton("Add All");
    bottomPanel.add(addAllIndividuals);

    final JButton addIndividuals = ViewUtil.getSoftButton("Add Selected");
    bottomPanel.add(addIndividuals);

    final JButton removeIndividuals = ViewUtil.getSoftButton("Remove Selected");
    bottomPanel.add(removeIndividuals);

    final JButton removeAllIndividuals = ViewUtil.getSoftButton("Remove All");
    bottomPanel.add(removeAllIndividuals);

    JPanel buttons = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(buttons);

    buttons.add(addAllIndividuals);
    buttons.add(addIndividuals);
    buttons.add(removeIndividuals);
    buttons.add(removeAllIndividuals);

    JPanel windowControlPanel = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(windowControlPanel);
    windowControlPanel.add(Box.createHorizontalGlue());

    JButton cancel = new JButton("Cancel");
    bottomPanel.add(ViewUtil.centerHorizontally(buttons));

    ok = new JButton("OK");
    bottomPanel.add(ViewUtil.alignRight(ok));
    ok.setEnabled(false);

    windowControlPanel.add(cancel);
    windowControlPanel.add(ok);

    bottomPanel.add(windowControlPanel);

    final JDialog instance = this;

    ok.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            instance.setVisible(false);
            setIndividualsChosen(true);
        }
    });

    cancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            instance.setVisible(false);
            setIndividualsChosen(false || hasMadeSelections);
        }
    });

    addIndividuals.setEnabled(false);
    removeIndividuals.setEnabled(false);

    stp.getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent lse) {
            if (!lse.getValueIsAdjusting()) {

                int rows[] = stp.getTable().getSelectedRows();

                boolean someSelection = rows.length > 0;

                addIndividuals.setEnabled(someSelection);
                removeIndividuals.setEnabled(someSelection);

                if (someSelection) {
                    addIndividuals.setText("Add Selected (" + rows.length + ")");
                    removeIndividuals.setText("Remove Selected (" + rows.length + ")");
                } else {
                    addIndividuals.setText("Add Selected");
                    removeIndividuals.setText("Remove Selected");
                }
            }
        }
    });

    stp.getTable().getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent tme) {
            //addAllIndividuals.setText("Add All (" + stp.getTable().getModel().getRowCount() + ")");
            //removeAllIndividuals.setText("Remove All (" + stp.getTable().getModel().getRowCount() + ")");
        }
    });

    ActionListener addAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            addSelections(false);
        }
    };

    ActionListener addAllAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            addSelections(true);
        }
    };

    ActionListener removeAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            removeSelections(false);
        }
    };

    ActionListener removeAllAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            removeSelections(true);
        }
    };

    addIndividuals.addActionListener(addAction);
    addAllIndividuals.addActionListener(addAllAction);
    removeIndividuals.addActionListener(removeAction);
    removeAllIndividuals.addActionListener(removeAllAction);

    this.pack();
    this.setLocationRelativeTo(MedSavantFrame.getInstance());
}

From source file:org.ut.biolab.medsavant.client.view.dialog.IndividualSelector.java

private void initUI() {

    JPanel p = new JPanel();
    ViewUtil.applyVerticalBoxLayout(p);//from w  w  w .  jav  a2 s.  c om
    this.add(p);

    topPanel = ViewUtil.getClearPanel();
    middlePanel = ViewUtil.getClearPanel();
    bottomPanel = ViewUtil.getClearPanel();

    p.add(topPanel);
    p.add(middlePanel);
    p.add(bottomPanel);

    // Only display the bottom panel for multiple patient selection
    if (onlyOnePatient) {
        bottomPanel.setVisible(false);
    }

    // middle
    middlePanel.setLayout(new BorderLayout());

    individualsRetriever = new IndividualsReceiver();
    individualsSTP = new SearchableTablePanel("Individuals", COLUMN_NAMES, COLUMN_CLASSES, HIDDEN_COLUMNS, true,
            true, Integer.MAX_VALUE, false, SearchableTablePanel.TableSelectionType.ROW, Integer.MAX_VALUE,
            individualsRetriever);
    individualsSTP.setExportButtonVisible(false);

    //If patients or cohorts are edited, update the searchabletable.
    CacheController.getInstance().addListener(new Listener<ModificationType>() {
        @Override
        public void handleEvent(ModificationType event) {
            if (event == ModificationType.PATIENT || event == ModificationType.COHORT) {
                if (!individualsSTP.isUpdating()) {
                    forceRefresh = true;
                    individualsSTP.forceRefreshData();
                }
            }
        }

    });

    middlePanel.add(individualsSTP, BorderLayout.CENTER);

    // bottom
    ViewUtil.applyVerticalBoxLayout(bottomPanel);

    numselections = ViewUtil.getTitleLabel("0 individual(s) selected");

    JPanel text = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(text);

    JButton clearIndividuals = ViewUtil
            .getIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.CLOSE));
    clearIndividuals.setToolTipText("Clear selections");
    clearIndividuals.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            clearSelections();
        }
    });

    text.add(numselections);
    text.add(Box.createHorizontalStrut(5));
    text.add(clearIndividuals);
    bottomPanel.add(ViewUtil.centerHorizontally(text));

    final JButton addAllIndividuals = ViewUtil.getSoftButton("Add All");
    bottomPanel.add(addAllIndividuals);

    final JButton addIndividuals = ViewUtil.getSoftButton("Add Selected");
    bottomPanel.add(addIndividuals);

    final JButton removeIndividuals = ViewUtil.getSoftButton("Remove Selected");
    bottomPanel.add(removeIndividuals);

    final JButton removeAllIndividuals = ViewUtil.getSoftButton("Remove All");
    bottomPanel.add(removeAllIndividuals);

    JPanel buttons = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(buttons);

    buttons.add(addAllIndividuals);
    buttons.add(addIndividuals);
    buttons.add(removeIndividuals);
    buttons.add(removeAllIndividuals);

    JPanel windowControlPanel = ViewUtil.getClearPanel();
    ViewUtil.applyHorizontalBoxLayout(windowControlPanel);
    windowControlPanel.add(Box.createHorizontalGlue());

    JButton cancel = new JButton("Cancel");
    bottomPanel.add(ViewUtil.centerHorizontally(buttons));

    ok = new JButton("OK");
    bottomPanel.add(ViewUtil.alignRight(ok));
    ok.setEnabled(false);

    windowControlPanel.add(cancel);
    windowControlPanel.add(ok);

    bottomPanel.add(windowControlPanel);

    final JDialog instance = this;

    ok.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            instance.setVisible(false);
            setIndividualsChosen(true);
        }
    });

    cancel.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            instance.setVisible(false);
            setIndividualsChosen(false || hasMadeSelections);
        }
    });

    addIndividuals.setEnabled(false);
    removeIndividuals.setEnabled(false);

    individualsSTP.getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent lse) {
            if (!lse.getValueIsAdjusting()) {

                int rows[] = individualsSTP.getTable().getSelectedRows();

                boolean someSelection = rows.length > 0;

                addIndividuals.setEnabled(someSelection);
                removeIndividuals.setEnabled(someSelection);

                if (someSelection) {
                    addIndividuals.setText("Add Selected (" + rows.length + ")");
                    removeIndividuals.setText("Remove Selected (" + rows.length + ")");
                } else {
                    addIndividuals.setText("Add Selected");
                    removeIndividuals.setText("Remove Selected");
                }

                /* Close the dialog if only a single individual is requested. */
                if (onlyOnePatient && rows.length == 1) {
                    selectedRows.clear();
                    selectedHospitalIDs.clear();

                    int realRow = individualsSTP.getActualRowAt(rows[0]);
                    selectedRows.add(realRow);
                    Object[] o = individualsRetriever.getIndividuals().get(realRow);
                    selectedHospitalIDs.add(o[INDEX_OF_HOSPITAL_ID].toString());

                    instance.setVisible(false);
                    setIndividualsChosen(true);

                    individualsSTP.getTable().clearSelection(); // if errors crop up, this line may be causing ListSelectionEvents - can be removed
                }
            }
        }
    });

    individualsSTP.getTable().getModel().addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent tme) {
            //addAllIndividuals.setText("Add All (" + stp.getTable().getModel().getRowCount() + ")");
            //removeAllIndividuals.setText("Remove All (" + stp.getTable().getModel().getRowCount() + ")");
        }
    });

    ActionListener addAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            addSelections(false);
        }
    };

    ActionListener addAllAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            addSelections(true);
        }
    };

    ActionListener removeAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            removeSelections(false);
        }
    };

    ActionListener removeAllAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            removeSelections(true);
        }
    };

    addIndividuals.addActionListener(addAction);
    addAllIndividuals.addActionListener(addAllAction);
    removeIndividuals.addActionListener(removeAction);
    removeAllIndividuals.addActionListener(removeAllAction);

    this.pack();
    this.setLocationRelativeTo(MedSavantFrame.getInstance());
}

From source file:pcgui.SetupParametersPanel.java

/**
 * Create the frame./*from ww w  .  jav a 2 s .co m*/
 * 
 * @param switcher
 * 
 * @param rootFrame
 */

public SetupParametersPanel(final PanelSwitcher switcher, JFrame rootFrame) {
    this.rootFrame = rootFrame;
    setLayout(new BorderLayout());

    JLabel headingLabel = new JLabel("Setup Parameters");
    headingLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
    add(headingLabel, BorderLayout.NORTH);
    JButton saveBtn = new JButton("Save");
    final JButton runModifiedBtn = new JButton("Run");

    runModifiedBtn.setEnabled(false);

    runModifiedBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            runModel();

        }
    });

    saveBtn.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            //creating separate copy of model so that changes in one doesn't effect other
            ArrayList<ArrayList<Object>> mod = new ArrayList<ArrayList<Object>>(model.getData());
            //call save model of modelsaver
            //TODO add visualization list and save to excel using similar method as below
            //TODO add modelname, should contain .xls/.xlsx extension
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_hhmmss");
            outputFile = importedFile.toString().replace(".mos", "") + "_" + sdf.format(new Date())
                    + "_FEORA_solution.xlsx";
            ModelSaver.saveInputModel(mod, outputFile);

            runModifiedBtn.setEnabled(true);

        }
    });

    JLabel label = new JLabel("Enter count of random value runs");
    repeatCount = new JTextField();
    repeatCount.setToolTipText("Enter count for which each combination of step variables is run ");
    repeatCount.setText("1");
    repeatCount.setPreferredSize(new Dimension(100, 20));

    JPanel runConfig = new JPanel();
    runConfig.setLayout(new GridLayout(2, 2));

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.CENTER;

    JPanel configCount = new JPanel(new FlowLayout());
    JPanel configButtons = new JPanel(new FlowLayout());
    configCount.add(label);
    configCount.add(repeatCount);

    JButton btnLoadSavedConfiguration = new JButton("Load Saved Configuration");
    btnLoadSavedConfiguration.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JFileChooser jFileChooser = new JFileChooser();

            File workingDirectory = new File(System.getProperty("user.dir"));

            jFileChooser.setCurrentDirectory(workingDirectory);

            jFileChooser.setFileFilter(new FileFilter() {

                @Override
                public String getDescription() {
                    // TODO Auto-generated method stub
                    return "Excel solution files";
                }

                @Override
                public boolean accept(File f) {
                    // TODO Auto-generated method stub
                    return f.isDirectory() || f.getName().endsWith(".xls") || f.getName().endsWith(".xlsx");

                }
            });
            int returnVal = jFileChooser.showOpenDialog(null);

            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = jFileChooser.getSelectedFile();

                // This is where a real application would open the file.

                if (file.getName().endsWith(".xls") || file.getName().endsWith(".xlsx")) {
                    String fileName = file.getAbsolutePath();
                    List<List<String>> savedConfig = ModelSaver.loadInputConfigFromExcel(fileName);
                    ArrayList<Symbol> symList = new ArrayList<Symbol>();

                    int i = 0;
                    for (List<String> list : savedConfig) {
                        //ignore the header row
                        if (i > 0) {
                            System.out.println("VariableName=" + list.get(0));
                            System.out.println("Datatype=" + list.get(1));
                            System.out.println("Type=" + list.get(2));
                            System.out.println("Value=" + list.get(3));
                            System.out.println("ExternalFile=" + list.get(4));
                            System.out.println("ExcelRange=" + list.get(5));
                            System.out.println("DistributionFunction=" + list.get(6));
                            System.out.println("OutputTracket=" + list.get(7));
                            Symbol sym = new Symbol<>();
                            sym.name = list.get(0);
                            sym.typeString = list.get(1);
                            sym.mode = list.get(2);
                            sym.set(list.get(3));
                            sym.externalFile = list.get(4);
                            sym.excelFileRange = list.get(5);
                            sym.distFunction = list.get(6);
                            sym.trackingEnabled = Boolean.parseBoolean(list.get(7));
                            symList.add(sym);
                        }
                        i++;

                    }
                    initParamList(symList, parser);
                }

            } else {
                //               System.out.println("Open command cancelled by user.");
            }

        }
    });
    configButtons.add(btnLoadSavedConfiguration);

    configButtons.add(saveBtn);
    configButtons.add(runModifiedBtn);
    runConfig.add(configCount);
    runConfig.add(configButtons);
    add(runConfig, BorderLayout.SOUTH);

    setVisible(true);
}

From source file:qic.launcher.Main.java

private void startGUI(TakeDown installer) {
    TextAreaWithBackground textArea = new TextAreaWithBackground();

    JButton launchButton = new JButton("  Launch  ");
    launchButton.setEnabled(false);
    JProgressBar progressBar = new JProgressBar();

    launchButton.addActionListener(e -> {
        runAIC();/*from   w w  w.j a  v a 2  s .  co m*/
        System.exit(0);
    });

    JPanel southPanel = new JPanel();
    southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.X_AXIS));
    southPanel.add(progressBar);
    southPanel.add(launchButton);
    JFrame frame = new JFrame("QIC Search Updater");
    frame.setIconImage(new ImageIcon(getClass().getResource("/q.png")).getImage());
    frame.setLayout(new BorderLayout(5, 5));
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    frame.getContentPane().add(southPanel, BorderLayout.SOUTH);
    frame.setSize(495, 445);
    frame.setLocationRelativeTo(null);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    textArea.setText("Loading path notes...");

    String imgUrl = "http://poeqic.github.io/launcher/images/background.png";
    try {
        Image image = ImageIO.read(new URL(imgUrl));
        if (image != null)
            textArea.setBackgroundImage(image);
    } catch (IOException ex) {
        logger.error("Error while loading background image from: " + imgUrl, ex);
    }

    Worker<String> pathNotesWorker = new Worker<String>(() -> URLConnectionReader.getText(CHANGELOG_URL),
            s -> textArea.setText(s), e -> showErrorAndQuit(e));
    pathNotesWorker.execute();

    Worker<Boolean> updaterWorker = new Worker<Boolean>(() -> {
        progressBar.setIndeterminate(true);
        return installer.installOrUpdate();
    }, b -> {
        progressBar.setIndeterminate(false);
        launchButton.setEnabled(true);
    }, e -> showErrorAndQuit(e));
    updaterWorker.execute();

}

From source file:qic.ui.ManualPanel.java

@SuppressWarnings("serial")
public ManualPanel(Main main) {
    super(new BorderLayout(5, 5));

    table.setDoubleBuffered(true);/*w  ww. j  a va  2s .co m*/

    JTextField searchTf = new JTextField(100);
    JButton runBtn = new JButton("Run");
    runBtn.setPreferredSize(new Dimension(200, 10));
    JLabel invalidTermsLblLbl = new JLabel();
    invalidTermsLblLbl.setFont(invalidTermsLblLbl.getFont().deriveFont(Font.BOLD));
    JLabel invalidTermsLbl = new JLabel();
    invalidTermsLbl.setForeground(Color.RED);
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.X_AXIS));
    JLabel searchLbl = new JLabel(" Search: ");
    searchLbl.setFont(searchLbl.getFont().deriveFont(Font.BOLD));
    northPanel.add(searchLbl);
    northPanel.add(searchTf);
    northPanel.add(invalidTermsLblLbl);
    northPanel.add(invalidTermsLbl);
    northPanel.add(runBtn);
    this.add(northPanel, BorderLayout.NORTH);

    List<String> searchList = Util.loadSearchList(MANUAL_TXT_FILENAME);
    searchList.stream().forEach(searchJListModel::addElement);
    searchJList.setModel(searchJListModel);

    searchJList.addListSelectionListener(e -> {
        if (e.getValueIsAdjusting()) {
            searchTf.setText(trimToEmpty(searchJList.getSelectedValue()));
        }
    });
    searchJList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            if (evt.getClickCount() == 2) {
                int index = searchJList.locationToIndex(evt.getPoint());
                if (index != -1) {
                    String search = trimToEmpty(searchJListModel.getElementAt(index));
                    searchTf.setText(search);
                    runBtn.doClick();
                }
            }
        }
    });

    searchJList.getInputMap().put(KeyStroke.getKeyStroke("DELETE"), "doSomething");
    searchJList.getActionMap().put("doSomething", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int selectedIndex = searchJList.getSelectedIndex();
            if (selectedIndex != -1) {
                searchJListModel.remove(selectedIndex);
            }
        }
    });

    ActionListener runCommand = e -> {
        String tfText = searchTf.getText().trim();
        if (!tfText.isEmpty()) {
            Worker<Command> worker = new Worker<Command>(() -> {
                runBtn.setEnabled(false);
                Command result = null;
                try {
                    result = runQuery(main, tfText);
                } catch (Exception ex) {
                    runBtn.setEnabled(true);
                    SwingUtil.showError(ex);
                }
                return result;
            }, command -> {
                if (command != null) {
                    if (command.invalidSearchTerms.isEmpty()) {
                        addDataToTable(command);
                        saveSearchToList(tfText);
                        invalidTermsLbl.setText("");
                        invalidTermsLblLbl.setText("");
                        if (getBooleanProperty(MANUAL_AUTO_VERIFY, false)) {
                            long sleep = Config.getLongProperty(Config.MANUAL_AUTO_VERIFY_SLEEP, 5000);
                            table.runAutoVerify(sleep);
                        }
                    } else {
                        String invalidTermsStr = command.invalidSearchTerms.stream().collect(joining(", "));
                        invalidTermsLbl.setText(invalidTermsStr + " ");
                        invalidTermsLblLbl.setText(" Invalid: ");
                    }
                }
                runBtn.setEnabled(true);
            });
            worker.execute();
        }
    };

    searchTf.addActionListener(runCommand);
    runBtn.addActionListener(runCommand);

    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(table),
            new JScrollPane(searchJList));

    this.add(splitPane, BorderLayout.CENTER);
}

From source file:rita.ui.component.DialogSelectEnemies.java

private void enablePositionOptions(boolean enable) {
    if (!enable) {
        canSelectPosition = false;/*from  w ww .j  a v  a 2s .c  om*/
        for (Component comp : positionComponents) {
            comp.setEnabled(false);
        }
    } else {
        canSelectPosition = true;
        buttonPos.setEnabled(true);
        for (Component compPanel : panelSelectRobots.getComponents()) {
            JPanel parent = (JPanel) compPanel;
            // para cada panel la primer componente es el check y el segundo
            // es el boton
            JCheckBox check = (JCheckBox) parent.getComponent(0);
            if (check.isSelected()) {
                JButton button = (JButton) parent.getComponent(1);
                button.setEnabled(true);
            }
        }
    }
}

From source file:savant.util.swing.TrackChooser.java

private JButton createAllRight() {
    JButton allRight = new JButton(">>");
    allRight.setToolTipText("Add all to selected");
    if (!this.multiple)
        allRight.setEnabled(false);
    allRight.addActionListener(new ActionListener() {
        @Override/*from w ww.  j  a  v a 2  s  .c  o  m*/
        public void actionPerformed(ActionEvent e) {
            selectAll();
        }
    });
    return allRight;
}