List of usage examples for javax.swing.event ListSelectionEvent getValueIsAdjusting
public boolean getValueIsAdjusting()
From source file:org.tinymediamanager.ui.moviesets.dialogs.MovieSetChooserDialog.java
/** * Instantiates a new movie set chooser panel. * /* w w w. j ava 2 s. c o m*/ * @param movieSet * the movie set */ public MovieSetChooserDialog(MovieSet movieSet, boolean inQueue) { super(BUNDLE.getString("movieset.search"), "movieSetChooser"); //$NON-NLS-1$ setBounds(5, 5, 865, 578); movieSetToScrape = movieSet; getContentPane().setLayout(new BorderLayout(0, 0)); JPanel panelHeader = new JPanel(); getContentPane().add(panelHeader, BorderLayout.NORTH); panelHeader.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("114px:grow"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("100px"), ColumnSpec.decode("2dlu"), }, new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("25px"), FormFactory.RELATED_GAP_ROWSPEC, })); { tfMovieSetName = new JTextField(); panelHeader.add(tfMovieSetName, "2, 2, fill, fill"); tfMovieSetName.setColumns(10); } { JButton btnSearch = new JButton(""); btnSearch.setAction(actionSearch); panelHeader.add(btnSearch, "4, 2, fill, top"); } { JSplitPane splitPane = new JSplitPane(); splitPane.setContinuousLayout(true); splitPane.setResizeWeight(0.5); getContentPane().add(splitPane, BorderLayout.CENTER); { JPanel panelResults = new JPanel(); panelResults.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("300px:grow"), }, new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("fill:403px:grow"), })); JScrollPane panelSearchResults = new JScrollPane(); panelResults.add(panelSearchResults, "2, 2, fill, fill"); splitPane.setLeftComponent(panelResults); { tableMovieSets = new JTable(); panelSearchResults.setViewportView(tableMovieSets); tableMovieSets.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tableMovieSets.setBorder(new LineBorder(new Color(0, 0, 0))); ListSelectionModel rowSM = tableMovieSets.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (!lsm.isSelectionEmpty()) { int selectedRow = lsm.getMinSelectionIndex(); selectedRow = tableMovieSets.convertRowIndexToModel(selectedRow); try { MovieSetChooserModel model = movieSetsFound.get(selectedRow); if (model != MovieSetChooserModel.emptyResult && !model.isScraped()) { ScrapeTask task = new ScrapeTask(model); task.execute(); } } catch (Exception ex) { LOGGER.warn(ex.getMessage()); } } } }); } } { JPanel panelSearchDetail = new JPanel(); splitPane.setRightComponent(panelSearchDetail); panelSearchDetail.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("left:150px"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(300px;default):grow"), FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("250px"), FormFactory.PARAGRAPH_GAP_ROWSPEC, RowSpec.decode("top:default:grow"), FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC })); { lblMovieSetName = new JTextArea(""); lblMovieSetName.setLineWrap(true); lblMovieSetName.setOpaque(false); lblMovieSetName.setWrapStyleWord(true); TmmFontHelper.changeFont(lblMovieSetName, 1.166, Font.BOLD); panelSearchDetail.add(lblMovieSetName, "2, 1, 3, 1, fill, top"); } { lblMovieSetPoster = new ImageLabel(); lblMovieSetPoster.setAlternativeText(BUNDLE.getString("image.notfound.poster")); //$NON-NLS-1$ panelSearchDetail.add(lblMovieSetPoster, "2, 3, fill, fill"); } { JPanel panel = new JPanel(); panelSearchDetail.add(panel, "4, 3, fill, fill"); panel.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); } { JScrollPane scrollPane = new JScrollPane(); panelSearchDetail.add(scrollPane, "2, 5, 3, 1, fill, fill"); { tableMovies = new JTable(); scrollPane.setViewportView(tableMovies); } } { cbAssignMovies = new JCheckBox(BUNDLE.getString("movieset.movie.assign")); //$NON-NLS-1$ cbAssignMovies.setSelected(true); panelSearchDetail.add(cbAssignMovies, "2, 7, 3, 1"); } } } { JPanel bottomPane = new JPanel(); getContentPane().add(bottomPane, BorderLayout.SOUTH); { bottomPane.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("2dlu"), ColumnSpec.decode("185px"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("18px:grow"), FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, ColumnSpec.decode("2dlu"), }, new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.LINE_GAP_ROWSPEC })); { progressBar = new JProgressBar(); bottomPane.add(progressBar, "2, 2, fill, center"); } { lblProgressAction = new JLabel(""); bottomPane.add(lblProgressAction, "4, 2, fill, center"); } { JPanel buttonPane = new JPanel(); bottomPane.add(buttonPane, "6, 2, fill, fill"); EqualsLayout layout = new EqualsLayout(5); buttonPane.setBorder(new EmptyBorder(4, 4, 4, 4)); layout.setMinWidth(100); buttonPane.setLayout(layout); btnOk = new JButton(BUNDLE.getString("Button.ok")); //$NON-NLS-1$ btnOk.setActionCommand("Save"); btnOk.setToolTipText(BUNDLE.getString("Button.ok")); //$NON-NLS-1$ btnOk.setIcon(IconManager.APPLY); btnOk.addActionListener(this); buttonPane.add(btnOk); JButton btnCancel = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$ btnCancel.setActionCommand("Cancel"); btnCancel.setToolTipText(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$ btnCancel.setIcon(IconManager.CANCEL); btnCancel.addActionListener(this); buttonPane.add(btnCancel); if (inQueue) { JButton btnAbort = new JButton(BUNDLE.getString("Button.abortqueue")); //$NON-NLS-1$ btnAbort.setActionCommand("Abort"); btnAbort.setToolTipText(BUNDLE.getString("Button.abortqueue")); //$NON-NLS-1$ btnAbort.setIcon(IconManager.PROCESS_STOP); btnAbort.addActionListener(this); buttonPane.add(btnAbort, "6, 1, fill, top"); } } } } initDataBindings(); // adjust table columns tableMovies.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tableMovies.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); tableMovieSets.getColumnModel().getColumn(0).setHeaderValue(BUNDLE.getString("chooser.searchresult")); tfMovieSetName.setText(movieSet.getTitle()); searchMovie(); }
From source file:org.tinymediamanager.ui.tvshows.dialogs.TvShowEpisodeChooserDialog.java
public TvShowEpisodeChooserDialog(TvShowEpisode ep, MediaScraper mediaScraper) { super(BUNDLE.getString("tvshowepisode.choose"), "episodeChooser"); //$NON-NLS-1$ setBounds(5, 5, 600, 400);/*w w w . jav a 2 s .c o m*/ this.episode = ep; this.mediaScraper = mediaScraper; this.metadata = new MediaEpisode(mediaScraper.getId()); episodeEventList = new ObservableElementList<>( GlazedLists.threadSafeList(new BasicEventList<TvShowEpisodeChooserModel>()), GlazedLists.beanConnector(TvShowEpisodeChooserModel.class)); sortedEpisodes = new SortedList<>(GlazedListsSwing.swingThreadProxyList(episodeEventList), new EpisodeComparator()); getContentPane().setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("590px:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("200dlu:grow"), FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("fill:37px"), FormSpecs.RELATED_GAP_ROWSPEC, })); { JSplitPane splitPane = new JSplitPane(); getContentPane().add(splitPane, "2, 2, fill, fill"); JPanel panelLeft = new JPanel(); panelLeft.setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("150dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("default:grow"), FormSpecs.RELATED_GAP_ROWSPEC, })); textField = EnhancedTextField.createSearchTextField(); panelLeft.add(textField, "2, 2, fill, default"); textField.setColumns(10); JScrollPane scrollPane = new JScrollPane(); scrollPane.setMinimumSize(new Dimension(200, 23)); panelLeft.add(scrollPane, "2, 4, fill, fill"); splitPane.setLeftComponent(panelLeft); MatcherEditor<TvShowEpisodeChooserModel> textMatcherEditor = new TextComponentMatcherEditor<>(textField, new TvShowEpisodeChooserModelFilterator()); FilterList<TvShowEpisodeChooserModel> textFilteredEpisodes = new FilterList<>(sortedEpisodes, textMatcherEditor); AdvancedTableModel<TvShowEpisodeChooserModel> episodeTableModel = GlazedListsSwing .eventTableModelWithThreadProxyList(textFilteredEpisodes, new EpisodeTableFormat()); DefaultEventSelectionModel<TvShowEpisodeChooserModel> selectionModel = new DefaultEventSelectionModel<>( textFilteredEpisodes); selectedEpisodes = selectionModel.getSelected(); selectionModel.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } // display first selected episode if (!selectedEpisodes.isEmpty()) { TvShowEpisodeChooserModel episode = selectedEpisodes.get(0); taPlot.setText(episode.getOverview()); } else { taPlot.setText(""); } taPlot.setCaretPosition(0); } }); table = new JTable(episodeTableModel); table.setSelectionModel(selectionModel); scrollPane.setViewportView(table); JPanel panelRight = new JPanel(); panelRight.setLayout(new FormLayout( new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("150dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("default:grow"), FormSpecs.RELATED_GAP_ROWSPEC, })); JScrollPane scrollPane_1 = new JScrollPane(); panelRight.add(scrollPane_1, "2, 2, fill, fill"); splitPane.setRightComponent(panelRight); taPlot = new JTextArea(); taPlot.setEditable(false); taPlot.setWrapStyleWord(true); taPlot.setLineWrap(true); scrollPane_1.setViewportView(taPlot); splitPane.setDividerLocation(300); } JPanel bottomPanel = new JPanel(); getContentPane().add(bottomPanel, "2, 4, fill, top"); bottomPanel.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.LABEL_COMPONENT_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("25px"), FormFactory.RELATED_GAP_ROWSPEC, })); JPanel buttonPane = new JPanel(); bottomPanel.add(buttonPane, "5, 2, fill, fill"); EqualsLayout layout = new EqualsLayout(5); layout.setMinWidth(100); buttonPane.setLayout(layout); final JButton okButton = new JButton(BUNDLE.getString("Button.ok")); //$NON-NLS-1$ okButton.setToolTipText(BUNDLE.getString("tvshow.change")); okButton.setIcon(IconManager.APPLY); buttonPane.add(okButton); okButton.setActionCommand("OK"); okButton.addActionListener(this); JButton cancelButton = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$ cancelButton.setToolTipText(BUNDLE.getString("edit.discard")); cancelButton.setIcon(IconManager.CANCEL); buttonPane.add(cancelButton); cancelButton.setActionCommand("Cancel"); cancelButton.addActionListener(this); // column widths table.getColumnModel().getColumn(0).setMaxWidth(50); table.getColumnModel().getColumn(1).setMaxWidth(50); SearchTask task = new SearchTask(); task.execute(); MouseListener mouseListener = new MouseListener() { @Override public void mouseReleased(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2 && !e.isConsumed() && e.getButton() == MouseEvent.BUTTON1) { actionPerformed(new ActionEvent(okButton, ActionEvent.ACTION_PERFORMED, "OK")); } } }; table.addMouseListener(mouseListener); }
From source file:org.ut.biolab.medsavant.client.filter.TabularFilterView.java
protected final void initContentPanel() { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); if (availableValues == null) { JTextArea label = new JTextArea( "There are too many unique values to generate this list. You will not be able to filter on this column. "); label.setOpaque(false);//from w w w . j av a 2 s . co m label.setLineWrap(true); label.setWrapStyleWord(true); gbc.weightx = 1.0; gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(3, 3, 3, 3); add(label, gbc); this.showViewCard(); return; } applyButton = new JButton("Apply"); applyButton.setEnabled(false); AbstractListModel model = new SimpleListModel(); field = new QuickListFilterField(model); field.setHintText("Type here to filter options"); // the width of the field has to be less than the width // provided to the filter, otherwise, it will push the grid wider // and components will be inaccessible field.setPreferredSize(new Dimension(FIELD_WIDTH, 22)); filterableList = new FilterableCheckBoxList(field.getDisplayListModel()) { @Override public int getNextMatch(String prefix, int startIndex, Position.Bias bias) { return -1; } @Override public boolean isCheckBoxEnabled(int index) { return true; } }; filterableList.getCheckBoxListSelectionModel() .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); if (model.getSize() > 0) { filterableList.setPrototypeCellValue(model.getElementAt(0)); // Makes it much faster to determine the view's preferred size. } SearchableUtils.installSearchable(filterableList); filterableList.getCheckBoxListSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { applyButton.setEnabled(true); } } }); setAllSelected(true); applyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applyFilter(); } }); JScrollPane jsp = new JScrollPane(filterableList) { @Override public Dimension getPreferredSize() { Dimension result = super.getPreferredSize(); result = new Dimension(Math.min(result.width, TabularFilterView.this.getWidth() - 20), result.height); return result; } }; selectAll = ViewUtil.createHyperLinkButton("Select All"); selectAll.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setAllSelected(true); applyButton.setEnabled(true); } }); JButton selectNone = ViewUtil.createHyperLinkButton("Select None"); selectNone.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setAllSelected(false); applyButton.setEnabled(true); } }); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(3, 15, 3, 15); add(field, gbc); gbc.weighty = 1.0; gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(3, 3, 3, 3); add(jsp, gbc); gbc.gridwidth = 1; gbc.weightx = 0.0; gbc.weighty = 0.0; gbc.fill = GridBagConstraints.NONE; add(selectAll, gbc); add(selectNone, gbc); gbc.weightx = 1.0; gbc.anchor = GridBagConstraints.EAST; add(applyButton, gbc); this.showViewCard(); }
From source file:org.ut.biolab.medsavant.client.view.component.SearchableTablePanel.java
/** * The given action will be executed when the selection changes AND a * scrolling key (pg-up, pg-down, arrow keys, num lock arrow keys) is not * being held down. This method should be used as a scroll-safe alternative * to registering a selection listener.// w w w .j a va 2 s. c o m * * This makes it safe for the user to scroll through the scroll panel * without repeating the action unnecessarily. The action executes in a new * thread. */ public void scrollSafeSelectAction(final Runnable onSelectTask) { final KeyTimer keyTimer = new KeyTimer(KEY_PRESS_TIMER_INTERVAL, new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { keydown = false; waitlong = false; //printTime("Starting Worker"); resetSelectionChangedWorker(onSelectTask); } }); keyTimer.setRepeats(false); getTable().addKeyListener(new KeyAdapter() { private long lastDelta = -1; private long lastTime = System.currentTimeMillis(); private int deltaSame = 0; private boolean first = true; @Override public void keyPressed(KeyEvent ke) { super.keyPressed(ke); if (!ArrayUtils.contains(SCROLLING_KEYS, ke.getKeyCode())) { //System.out.println("Detected key press that wasn't a scrolling key! (keycode=" + ke.getKeyCode() + ")"); return; } long currentTime = System.currentTimeMillis(); long delta = currentTime - lastTime; if (Math.abs(delta - lastDelta) < KEY_PRESS_INTERVAL_EPSILON) { deltaSame++; } else { deltaSame = 0; } if (deltaSame > KEY_PRESS_TIMER_INTERVAL_AUTOADJUST_RUNS) { //If this is the first time we've detected an interval, or if the detected interval //is getting close to the current (padded) interval, then change the current interval to //the detected one + padding. if (first || (delta - KEY_PRESS_TIMER_INTERVAL) > (KEY_PRESS_TIMER_INTERVAL_AUTOADJUST_PADDING / 2.0f)) { KEY_PRESS_TIMER_INTERVAL = (int) delta + KEY_PRESS_TIMER_INTERVAL_AUTOADJUST_PADDING; LOG.info("Detected " + deltaSame + " keypresses with delta ~" + delta + ", setting new repeat-interval to " + KEY_PRESS_TIMER_INTERVAL); first = false; } deltaSame = 0; } lastDelta = delta; lastTime = currentTime; keydown = true; stopSelectionChangedWorker(); if (keyTimer.isRunning()) { keyTimer.stop("keyPressed stop"); if (waitlong) { waitlong = false; keyTimer.setInitialDelay(KEY_PRESS_TIMER_INTERVAL_LONG); } else { keyTimer.setInitialDelay(KEY_PRESS_TIMER_INTERVAL); } keyTimer.restart("keyPressed restart"); } else { waitlong = false; keyTimer.setInitialDelay(KEY_PRESS_TIMER_INTERVAL_LONG); keyTimer.start("keyTimer start"); } } //In Linux, holding a keydown fires pairs of keyPressed and keyReleased events //continually, so we cannot rely on 'keyReleased'. /*@Override public void keyReleased(KeyEvent ke) { super.keyReleased(ke); //To change body of generated methods, choose Tools | Templates. keydown = false; }*/ }); getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } if (keydown == false) { if (!keyTimer.isRunning()) { waitlong = true; // printTime("valueChanged, setting waitlong=true: "); keyTimer.setInitialDelay(KEY_PRESS_TIMER_INTERVAL); keyTimer.start("valueChanged start"); } } } }); }
From source file:org.ut.biolab.medsavant.client.view.dialog.FamilySelector.java
private void initUI() { JPanel p = new JPanel(); ViewUtil.applyVerticalBoxLayout(p);/* www . j a v a 2 s .c om*/ 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 . j av a 2s . co m*/ 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:org.ut.biolab.medsavant.client.view.list.ListView.java
private void updateShowCard() { showCard.removeAll();//from w w w . java 2 s .c o m showCard.setLayout(new BorderLayout()); String[] columnNames = detailedModel.getColumnNames(); Class[] columnClasses = detailedModel.getColumnClasses(); int[] columnVisibility = detailedModel.getHiddenColumns(); int firstVisibleColumn = 0; while (columnVisibility.length > 0 && firstVisibleColumn == columnVisibility[firstVisibleColumn]) { firstVisibleColumn++; } Set<NiceListItem> selectedItems; if (list != null) { selectedItems = new HashSet<NiceListItem>(list.getSelectedItems()); } else { selectedItems = new HashSet<NiceListItem>(); // empty set, for simplicity of not having to null check later on } list = new NiceList(); if (listColorScheme != null) { list.setColorScheme(listColorScheme); } list.startTransaction(); List<Integer> selectedIndicies = new ArrayList<Integer>(); int counter = 0; for (Object[] row : data) { NiceListItem nli = new NiceListItem(row[firstVisibleColumn].toString(), row); list.addItem(nli); if (selectedItems.contains(nli)) { selectedIndicies.add(counter); } counter++; } /* int[] selectedIndiciesArray = new int[selectedIndicies.size()]; System.out.println("Reselecting " + selectedIndicies.size() + " items"); for (int i = 0; i < selectedIndicies.size();i++) { System.out.println("Reselecting " + list.getItem(selectedIndicies.get(i)).toString() + " at index " + selectedIndicies.get(i)); selectedIndiciesArray[i] = selectedIndicies.get(i); }*/ list.endTransaction(); wp.setBackground(list.getColorScheme().getBackgroundColor()); if (detailedView != null) { list.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { List<Object[]> selectedItems = getSelectedRows(); if (selectedItems.size() == 1) { detailedView.setSelectedItem(selectedItems.get(0)); } else { detailedView.setMultipleSelections(selectedItems); } } } }); list.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu popup = detailedView.createPopup(); if (popup != null) { popup.show(e.getComponent(), e.getX(), e.getY()); } } } }); } if (selectedIndicies.isEmpty()) { list.selectItemAtIndex(0); } else { list.selectItemsAtIndicies(selectedIndicies); } JScrollPane jsp = ViewUtil.getClearBorderlessScrollPane(list); jsp.setHorizontalScrollBar(null); JPanel topPanel = new JPanel(); topPanel.setLayout(new MigLayout("wrap, fillx")); topPanel.add(ViewUtil.getEmphasizedLabel(pageName.toUpperCase())); topPanel.setBackground(list.getColorScheme().getBackgroundColor()); if (searchBarEnabled) { topPanel.add(list.getSearchBar(), "growx 1.0"); } showCard.add(topPanel, BorderLayout.NORTH); showCard.add(jsp, BorderLayout.CENTER); showCard.add(controlBar.getComponent(), BorderLayout.SOUTH); }
From source file:org.ut.biolab.medsavant.client.view.list.MasterView.java
private void updateShowCard() { showCard.removeAll();/*w w w .ja va2 s. c o m*/ showCard.setLayout(new BorderLayout()); showCard.setBackground(ViewUtil.getTertiaryMenuColor()); showCard.setBorder(ViewUtil.getBigBorder()); String[] columnNames = detailedModel.getColumnNames(); Class[] columnClasses = detailedModel.getColumnClasses(); int[] columnVisibility = detailedModel.getHiddenColumns(); stp = new ListViewTablePanel(data, columnNames, columnClasses, columnVisibility) { @Override public void forceRefreshData() { refreshList(); } }; selectionGrabber = new RowSelectionGrabber(stp.getTable(), data); if (detailedView != null) { stp.getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { List<Object[]> selectedItems = selectionGrabber.getSelectedItems(); if (selectedItems.size() == 1) { detailedView.setSelectedItem(selectedItems.get(0)); } else { detailedView.setMultipleSelections(selectedItems); } } } }); stp.getTable().addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu popup = detailedView.createPopup(); if (popup != null) { popup.show(e.getComponent(), e.getX(), e.getY()); } } } }); } stp.getTable().getSelectionModel().setSelectionInterval(0, 0); showCard.add(stp, BorderLayout.CENTER); showCard.add(buttonPanel, BorderLayout.SOUTH); }
From source file:org.yccheok.jstock.gui.IndicatorPanel.java
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList1ValueChanged // When the user release the mouse button and completes the selection, // getValueIsAdjusting() becomes false if (evt.getValueIsAdjusting()) { return;//from w w w .ja v a2s . c o m } final String projectName = (String) this.jList1.getSelectedValue(); if (projectName == null) { this.listSelectionEx = null; return; } final IndicatorDefaultDrawing indicatorDefaultDrawing = this.alertIndicatorProjectManager .getIndicatorDefaultDrawing(projectName); boolean userCancel = false; if (indicatorDefaultDrawing != null) { if (this.promptToSaveSignificantEdits(this.listSelectionEx)) { this.setDrawing(indicatorDefaultDrawing); } else { userCancel = true; } } else { if (this.promptToSaveSignificantEdits(this.listSelectionEx)) { final String output = MessageFormat.format( MessagesBundle.getString("question_message_corrupted_file_remove_template"), projectName); if (JOptionPane.showConfirmDialog(this, output, MessagesBundle.getString("question_title_corrupted_file_remove"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { // Do not prompt "Are you sure you want to delete..." dialog box. Delete(false); } else { this.setDrawing(this.createDrawing()); } } else { userCancel = true; } } if (!userCancel) { // Ensure jList1 and jList2 are mutually exclusive. // This must be done before we assign value to this.listSelectionEx, // as list selection listener of jList2 will overwrite this.listSelectionEx. // Also, clearSelection code cannot be placed before any code which depend // on the correctness of this.listSelectionEx. // Ensure jList1 and jList2 are mutually exclusive. // // When cancel is pressed, promptToSaveSignificantEdits has helped us // to determine correct selection. We need not to perform or clear selection // explicitly. this.jList2.clearSelection(); // Whenever cancel happen, we need to make this.listSelectionEx remains // unchanged. this.listSelectionEx = ListSelectionEx.newInstance(this.jList1, projectName); } }
From source file:org.yccheok.jstock.gui.IndicatorPanel.java
private void jList2ValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jList2ValueChanged // When the user release the mouse button and completes the selection, // getValueIsAdjusting() becomes false if (evt.getValueIsAdjusting()) { return;// w ww . j a va 2s .c o m } String projectName = (String) this.jList2.getSelectedValue(); if (projectName == null) { this.listSelectionEx = null; return; } IndicatorDefaultDrawing indicatorDefaultDrawing = this.moduleIndicatorProjectManager .getIndicatorDefaultDrawing(projectName); boolean userCancel = false; if (indicatorDefaultDrawing != null) { if (this.promptToSaveSignificantEdits(this.listSelectionEx)) { this.setDrawing(indicatorDefaultDrawing); } else { userCancel = true; } } else { if (this.promptToSaveSignificantEdits(this.listSelectionEx)) { final String output = MessageFormat.format( MessagesBundle.getString("question_message_corrupted_file_remove_template"), projectName); if (JOptionPane.showConfirmDialog(this, output, MessagesBundle.getString("question_title_corrupted_file_remove"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { // Do not prompt "Are you sure you want to delete..." dialog box. Delete(false); } else { this.setDrawing(this.createDrawing()); } } else { userCancel = true; } } if (!userCancel) { // Ensure jList1 and jList2 are mutually exclusive. // This must be done before we assign value to this.listSelectionEx, // as list selection listener of jList1 will overwrite this.listSelectionEx. // Also, clearSelection code cannot be placed before any code which depend // on the correctness of this.listSelectionEx. // Ensure jList1 and jList2 are mutually exclusive. // // When cancel is pressed, promptToSaveSignificantEdits has helped us // to determine correct selection. We need not to perform or clear selection // explicitly. this.jList1.clearSelection(); // Whenever cancel happen, we need to make this.listSelectionEx remains // unchanged. this.listSelectionEx = ListSelectionEx.newInstance(this.jList2, projectName); } }