List of usage examples for javax.swing ListSelectionModel setSelectionInterval
void setSelectionInterval(int index0, int index1);
From source file:com.peterbochs.PeterBochsDebugger.java
private void breakpointTableMouseClicked(MouseEvent evt) { if (SwingUtilities.isRightMouseButton(evt)) { // select Point p = evt.getPoint(); int rowNumber = breakpointTable.rowAtPoint(p); int columnNumber = breakpointTable.columnAtPoint(p); ListSelectionModel model = breakpointTable.getSelectionModel(); model.setSelectionInterval(rowNumber, rowNumber); breakpointTable.getColumnModel().getSelectionModel().setSelectionInterval(columnNumber, columnNumber); // end select getJBreakpointPopupMenu().show(evt.getComponent(), evt.getX(), evt.getY()); }//from w w w . j a v a 2s. c o m }
From source file:com.peterbochs.PeterBochsDebugger.java
private void jSearchMemoryTableMouseClicked(MouseEvent evt) { if (SwingUtilities.isRightMouseButton(evt)) { // select Point p = evt.getPoint(); int rowNumber = jSearchMemoryTable.rowAtPoint(p); int columnNumber = jSearchMemoryTable.columnAtPoint(p); ListSelectionModel model = jSearchMemoryTable.getSelectionModel(); model.setSelectionInterval(rowNumber, rowNumber); jSearchMemoryTable.getColumnModel().getSelectionModel().setSelectionInterval(columnNumber, columnNumber);/* ww w .ja v a 2s . c o m*/ // end select getJSearchMemoryTablePopupMenu().show(evt.getComponent(), evt.getX(), evt.getY()); } }
From source file:op.care.nursingprocess.DlgNursingProcess.java
private void tblPlanungMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblPlanungMousePressed if (!SwingUtilities.isRightMouseButton(evt)) { return;//from w w w .j ava 2s . c om } Point p = evt.getPoint(); ListSelectionModel lsm = tblPlanung.getSelectionModel(); int row = tblPlanung.rowAtPoint(p); if (lsm.isSelectionEmpty() || (lsm.getMinSelectionIndex() == lsm.getMaxSelectionIndex())) { lsm.setSelectionInterval(row, row); } menu = new JPopupMenu(); /*** * _ _ ____ ____ _ _ * (_) |_ ___ _ __ ___ | _ \ ___ _ __ _ _ _ __ | _ \ ___| | ___| |_ ___ * | | __/ _ \ '_ ` _ \| |_) / _ \| '_ \| | | | '_ \| | | |/ _ \ |/ _ \ __/ _ \ * | | || __/ | | | | | __/ (_) | |_) | |_| | |_) | |_| | __/ | __/ || __/ * |_|\__\___|_| |_| |_|_| \___/| .__/ \__,_| .__/|____/ \___|_|\___|\__\___| * |_| |_| */ JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.commands.delete"), SYSConst.icon22delete); itemPopupDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { for (int row : tblPlanung.getSelectedRows()) { listInterventionSchedule2Remove .add(((TMPlan) tblPlanung.getModel()).getInterventionSchedule(row)); nursingProcess.getInterventionSchedule() .remove(((TMPlan) tblPlanung.getModel()).getInterventionSchedule(row)); } ((TMPlan) tblPlanung.getModel()).fireTableDataChanged(); } }); menu.add(itemPopupDelete); /*** * _ _ ____ ____ _ _ _ * (_) |_ ___ _ __ ___ | _ \ ___ _ __ _ _ _ __/ ___| ___| |__ ___ __| |_ _| | ___ * | | __/ _ \ '_ ` _ \| |_) / _ \| '_ \| | | | '_ \___ \ / __| '_ \ / _ \/ _` | | | | |/ _ \ * | | || __/ | | | | | __/ (_) | |_) | |_| | |_) |__) | (__| | | | __/ (_| | |_| | | __/ * |_|\__\___|_| |_| |_|_| \___/| .__/ \__,_| .__/____/ \___|_| |_|\___|\__,_|\__,_|_|\___| * |_| |_| */ final JMenuItem itemPopupSchedule = new JMenuItem(SYSTools.xx("misc.commands.editsheduling"), SYSConst.icon22clock); itemPopupSchedule.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { final JidePopup popup = new JidePopup(); /** * This routine uses the <b>first</b> element of the selection as the template for editing * the schedule. After the edit it clones this "template", removes the original * InterventionSchedules (copying the apropriate Intervention of every single * Schedule first) and finally creates new schedules and adds them to * the CareProcess in question. */ int row = tblPlanung.getSelectedRows()[0]; InterventionSchedule firstInterventionScheduleWillBeTemplate = ((TMPlan) tblPlanung.getModel()) .getInterventionSchedule(row); JPanel dlg = new PnlSchedule(firstInterventionScheduleWillBeTemplate, new Closure() { @Override public void execute(Object o) { if (o != null) { InterventionSchedule template = (InterventionSchedule) o; ArrayList<InterventionSchedule> listInterventionSchedule2Add = new ArrayList(); for (int row : tblPlanung.getSelectedRows()) { InterventionSchedule oldTermin = ((TMPlan) tblPlanung.getModel()) .getInterventionSchedule(row); InterventionSchedule newTermin = template.clone(); newTermin.setIntervention(oldTermin.getIntervention()); listInterventionSchedule2Remove.add(oldTermin); listInterventionSchedule2Add.add(newTermin); } nursingProcess.getInterventionSchedule().removeAll(listInterventionSchedule2Remove); nursingProcess.getInterventionSchedule().addAll(listInterventionSchedule2Add); popup.hidePopup(); Collections.sort(nursingProcess.getInterventionSchedule()); ((TMPlan) tblPlanung.getModel()).fireTableDataChanged(); } } }); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.getContentPane().add(dlg); popup.setOwner(jspPlanung); popup.removeExcludedComponent(jspPlanung); popup.setDefaultFocusComponent(dlg); GUITools.showPopup(popup, SwingConstants.SOUTH_WEST); } }); menu.add(itemPopupSchedule); menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY()); }
From source file:op.care.prescription.DlgRegular.java
private void tblDosisMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblDosisMousePressed if (!SwingUtilities.isRightMouseButton(evt)) { return;/*from w ww . j a va 2 s .c o m*/ } final TMDose tm = (TMDose) tblDosis.getModel(); if (tm.getRowCount() == 0) { return; } Point p = evt.getPoint(); Point p2 = evt.getPoint(); // Convert a coordinate relative to a component's bounds to screen coordinates SwingUtilities.convertPointToScreen(p2, tblDosis); // final Point screenposition = p2; final int row = tblDosis.rowAtPoint(p); ListSelectionModel lsm = tblDosis.getSelectionModel(); lsm.setSelectionInterval(row, row); // Meneintrge SYSTools.unregisterListeners(menu); menu = new JPopupMenu(); //----------------------------------------- JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.msg.delete"), SYSConst.icon22delete); itemPopupDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PrescriptionSchedule schedule = prescription.getPrescriptionSchedule().get(row); prescription.getPrescriptionSchedule().remove(schedule); schedules2delete.add(schedule); reloadTable(); } }); menu.add(itemPopupDelete); menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY()); }
From source file:op.care.sysfiles.PnlFiles.java
private void tblFilesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFilesMousePressed Point p = evt.getPoint();/* w ww .j a v a2s . co m*/ ListSelectionModel lsm = tblFiles.getSelectionModel(); Point p2 = evt.getPoint(); SwingUtilities.convertPointToScreen(p2, tblFiles); final Point screenposition = p2; boolean singleRowSelected = lsm.getMaxSelectionIndex() == lsm.getMinSelectionIndex(); final int row = tblFiles.rowAtPoint(p); final int col = tblFiles.columnAtPoint(p); if (singleRowSelected) { lsm.setSelectionInterval(row, row); } final TMSYSFiles tm = (TMSYSFiles) tblFiles.getModel(); final SYSFiles sysfile = tm.getRow(tblFiles.convertRowIndexToModel(row)); if (SwingUtilities.isRightMouseButton(evt)) { SYSTools.unregisterListeners(menu); menu = new JPopupMenu(); // SELECT JMenuItem itemPopupShow = new JMenuItem(SYSTools.xx("misc.commands.show"), SYSConst.icon22magnify1); itemPopupShow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN); } }); menu.add(itemPopupShow); if (col == TMSYSFiles.COL_DESCRIPTION && OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { final JMenuItem itemPopupEdit = new JMenuItem(SYSTools.xx("misc.commands.edit"), SYSConst.icon22edit3); itemPopupEdit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { final JidePopup popup = new JidePopup(); popup.setMovable(false); popup.getContentPane() .setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); final JComponent editor = new JTextArea(sysfile.getBeschreibung(), 10, 40); ((JTextArea) editor).setLineWrap(true); ((JTextArea) editor).setWrapStyleWord(true); ((JTextArea) editor).setEditable(true); popup.getContentPane().add(new JScrollPane(editor)); final JButton saveButton = new JButton(SYSConst.icon22apply); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); popup.hidePopup(); SYSFiles mySysfile = em.merge(sysfile); mySysfile.setBeschreibung(((JTextArea) editor).getText().trim()); em.getTransaction().commit(); tm.setSYSFile(tblFiles.convertRowIndexToModel(row), mySysfile); } catch (Exception e) { em.getTransaction().rollback(); OPDE.fatal(e); } finally { em.close(); } } }); saveButton.setHorizontalAlignment(SwingConstants.RIGHT); JPanel pnl = new JPanel(new BorderLayout(10, 10)); JScrollPane pnlEditor = new JScrollPane(editor); pnl.add(pnlEditor, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS)); buttonPanel.add(saveButton); pnl.setBorder(new EmptyBorder(10, 10, 10, 10)); pnl.add(buttonPanel, BorderLayout.SOUTH); popup.setOwner(tblFiles); popup.removeExcludedComponent(tblFiles); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(editor); popup.showPopup(screenposition.x, screenposition.y); } }); menu.add(itemPopupEdit); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) { JMenuItem itemPopupDelete = new JMenuItem(SYSTools.xx("misc.commands.delete"), SYSConst.icon22delete); itemPopupDelete.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { new DlgYesNo( SYSTools.xx("misc.questions.delete1") + "<br/><b>" + sysfile.getFilename() + "</b><br/>" + SYSTools.xx("misc.questions.delete2"), new ImageIcon(getClass().getResource("/artwork/48x48/bw/trashcan_empty.png")), new Closure() { @Override public void execute(Object o) { if (o.equals(JOptionPane.YES_OPTION)) { SYSFilesTools.deleteFile(sysfile); reloadTable(); } } }); } }); menu.add(itemPopupDelete); itemPopupDelete.setEnabled(singleRowSelected); } menu.show(evt.getComponent(), (int) p.getX(), (int) p.getY()); } else if (evt.getClickCount() == 2) { SYSFilesTools.handleFile(sysfile, Desktop.Action.OPEN); } }
From source file:org.pmedv.blackboard.components.PartView.java
private void handlePopupTrigger(MouseEvent e) { if (e.isPopupTrigger() && model.getParts().size() >= 1) { Point p = e.getPoint();/*from w w w .ja v a2s . c o m*/ // get the row index that contains that coordinate int rowNumber = partPanel.getPartTable().rowAtPoint(p); // Get the ListSelectionModel of the JTable ListSelectionModel model = partPanel.getPartTable().getSelectionModel(); // set the selected interval of rows. Using the "rowNumber" // variable for the beginning and end selects only that one row. model.setSelectionInterval(rowNumber, rowNumber); tablePopupMenu.show(e.getComponent(), e.getX(), e.getY()); } }
From source file:org.pmedv.blackboard.dialogs.PartDialog.java
private void handlePopupTrigger(MouseEvent e) { if (e.isPopupTrigger() && model.getParts().size() >= 1) { Point p = e.getPoint();/*from ww w . j ava 2 s . c o m*/ // get the row index that contains that coordinate int rowNumber = partPanel.getPartTable().rowAtPoint(p); // Get the ListSelectionModel of the JTable ListSelectionModel model = partPanel.getPartTable().getSelectionModel(); // set the selected interval of rows. Using the "rowNumber" // variable for the beginning and end selects only that one row. model.setSelectionInterval(rowNumber, rowNumber); tablePopupMenu.show(e.getComponent(), e.getX(), e.getY()); } }
From source file:org.tinymediamanager.ui.movies.MoviePanel.java
/** * Create the panel./*from ww w .j a v a 2 s. c o m*/ */ public MoviePanel() { super(); // load movielist LOGGER.debug("loading MovieList"); movieList = MovieList.getInstance(); sortedMovies = new SortedList<>(GlazedListsSwing.swingThreadProxyList(movieList.getMovies()), new MovieComparator()); sortedMovies.setMode(SortedList.AVOID_MOVING_ELEMENTS); // build menu menu = new JMenu(BUNDLE.getString("tmm.movies")); //$NON-NLS-1$ JFrame mainFrame = MainWindow.getFrame(); JMenuBar menuBar = mainFrame.getJMenuBar(); menuBar.add(menu); setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("850px:grow"), FormFactory.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("500px:grow"), })); splitPaneHorizontal = new JSplitPane(); splitPaneHorizontal.setContinuousLayout(true); add(splitPaneHorizontal, "2, 2, fill, fill"); JPanel panelMovieList = new JPanel(); splitPaneHorizontal.setLeftComponent(panelMovieList); panelMovieList.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] { RowSpec.decode("26px"), FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("fill:max(200px;default):grow"), FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); JToolBar toolBar = new JToolBar(); toolBar.setRollover(true); toolBar.setFloatable(false); toolBar.setOpaque(false); panelMovieList.add(toolBar, "2, 1, left, fill"); // udpate datasource // toolBar.add(actionUpdateDataSources); final JSplitButton buttonUpdateDatasource = new JSplitButton(IconManager.REFRESH); // temp fix for size of the button buttonUpdateDatasource.setText(" "); buttonUpdateDatasource.setHorizontalAlignment(JButton.LEFT); // buttonScrape.setMargin(new Insets(2, 2, 2, 24)); buttonUpdateDatasource.setSplitWidth(18); buttonUpdateDatasource.setToolTipText(BUNDLE.getString("update.datasource")); //$NON-NLS-1$ buttonUpdateDatasource.addSplitButtonActionListener(new SplitButtonActionListener() { public void buttonClicked(ActionEvent e) { actionUpdateDataSources.actionPerformed(e); } public void splitButtonClicked(ActionEvent e) { // build the popupmenu on the fly buttonUpdateDatasource.getPopupMenu().removeAll(); JMenuItem item = new JMenuItem(actionUpdateDataSources2); buttonUpdateDatasource.getPopupMenu().add(item); buttonUpdateDatasource.getPopupMenu().addSeparator(); for (String ds : MovieModuleManager.MOVIE_SETTINGS.getMovieDataSource()) { buttonUpdateDatasource.getPopupMenu() .add(new JMenuItem(new MovieUpdateSingleDatasourceAction(ds))); } buttonUpdateDatasource.getPopupMenu().pack(); } }); JPopupMenu popup = new JPopupMenu("popup"); buttonUpdateDatasource.setPopupMenu(popup); toolBar.add(buttonUpdateDatasource); JSplitButton buttonScrape = new JSplitButton(IconManager.SEARCH); // temp fix for size of the button buttonScrape.setText(" "); buttonScrape.setHorizontalAlignment(JButton.LEFT); // buttonScrape.setMargin(new Insets(2, 2, 2, 24)); buttonScrape.setSplitWidth(18); buttonScrape.setToolTipText(BUNDLE.getString("movie.scrape.selected")); //$NON-NLS-1$ // register for listener buttonScrape.addSplitButtonActionListener(new SplitButtonActionListener() { public void buttonClicked(ActionEvent e) { actionScrape.actionPerformed(e); } public void splitButtonClicked(ActionEvent e) { } }); popup = new JPopupMenu("popup"); JMenuItem item = new JMenuItem(actionScrape2); popup.add(item); item = new JMenuItem(actionScrapeUnscraped); popup.add(item); item = new JMenuItem(actionScrapeSelected); popup.add(item); buttonScrape.setPopupMenu(popup); toolBar.add(buttonScrape); toolBar.add(actionEditMovie); btnRen = new JButton("REN"); btnRen.setAction(actionRename); toolBar.add(btnRen); btnMediaInformation = new JButton("MI"); btnMediaInformation.setAction(actionMediaInformation); toolBar.add(btnMediaInformation); JButton btnCreateOflline = new JButton(); btnCreateOflline.setAction(new MovieCreateOfflineAction(false)); toolBar.add(btnCreateOflline); textField = EnhancedTextField.createSearchTextField(); panelMovieList.add(textField, "3, 1, right, bottom"); textField.setColumns(13); // table = new JTable(); // build JTable MatcherEditor<Movie> textMatcherEditor = new TextComponentMatcherEditor<>(textField, new MovieFilterator()); MovieMatcherEditor movieMatcherEditor = new MovieMatcherEditor(); FilterList<Movie> extendedFilteredMovies = new FilterList<>(sortedMovies, movieMatcherEditor); textFilteredMovies = new FilterList<>(extendedFilteredMovies, textMatcherEditor); movieSelectionModel = new MovieSelectionModel(sortedMovies, textFilteredMovies, movieMatcherEditor); movieTableModel = new DefaultEventTableModel<>(GlazedListsSwing.swingThreadProxyList(textFilteredMovies), new MovieTableFormat()); table = new ZebraJTable(movieTableModel); movieTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent arg0) { lblMovieCountFiltered.setText(String.valueOf(movieTableModel.getRowCount())); // select first movie if nothing is selected ListSelectionModel selectionModel = table.getSelectionModel(); if (selectionModel.isSelectionEmpty() && movieTableModel.getRowCount() > 0) { selectionModel.setSelectionInterval(0, 0); } if (selectionModel.isSelectionEmpty() && movieTableModel.getRowCount() == 0) { movieSelectionModel.setSelectedMovie(null); } } }); // install and save the comparator on the Table movieSelectionModel.setTableComparatorChooser( TableComparatorChooser.install(table, sortedMovies, TableComparatorChooser.SINGLE_COLUMN)); // table = new MyTable(); table.setNewFontSize((float) ((int) Math.round(getFont().getSize() * 0.916))); // scrollPane.setViewportView(table); // JScrollPane scrollPane = new JScrollPane(table); JScrollPane scrollPane = ZebraJTable.createStripedJScrollPane(table); panelMovieList.add(scrollPane, "2, 3, 4, 1, fill, fill"); { final JToggleButton filterButton = new JToggleButton(IconManager.FILTER); filterButton.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$ panelMovieList.add(filterButton, "5, 1, right, bottom"); // add a propertychangelistener which reacts on setting a filter movieSelectionModel.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if ("filterChanged".equals(evt.getPropertyName())) { if (Boolean.TRUE.equals(evt.getNewValue())) { filterButton.setIcon(IconManager.FILTER_ACTIVE); filterButton.setToolTipText(BUNDLE.getString("movieextendedsearch.options.active")); //$NON-NLS-1$ } else { filterButton.setIcon(IconManager.FILTER); filterButton.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$ } } } }); panelExtendedSearch = new MovieExtendedSearchPanel(movieSelectionModel); panelExtendedSearch.setVisible(false); // panelMovieList.add(panelExtendedSearch, "2, 5, 2, 1, fill, fill"); filterButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (panelExtendedSearch.isVisible() == true) { panelExtendedSearch.setVisible(false); } else { panelExtendedSearch.setVisible(true); } } }); } JPanel panelStatus = new JPanel(); panelMovieList.add(panelStatus, "2, 6, 2, 1"); panelStatus.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("1px"), ColumnSpec.decode("146px:grow"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), }, new RowSpec[] { RowSpec.decode("fill:default:grow"), })); panelMovieCount = new JPanel(); panelStatus.add(panelMovieCount, "3, 1, left, fill"); lblMovieCount = new JLabel(BUNDLE.getString("tmm.movies") + ":"); //$NON-NLS-1$ panelMovieCount.add(lblMovieCount); lblMovieCountFiltered = new JLabel(""); panelMovieCount.add(lblMovieCountFiltered); lblMovieCountOf = new JLabel(BUNDLE.getString("tmm.of")); //$NON-NLS-1$ panelMovieCount.add(lblMovieCountOf); lblMovieCountTotal = new JLabel(""); panelMovieCount.add(lblMovieCountTotal); JLayeredPane layeredPaneRight = new JLayeredPane(); layeredPaneRight.setLayout( new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default"), ColumnSpec.decode("default:grow") }, new RowSpec[] { RowSpec.decode("default"), RowSpec.decode("default:grow") })); panelRight = new MovieInformationPanel(movieSelectionModel); layeredPaneRight.add(panelRight, "1, 1, 2, 2, fill, fill"); layeredPaneRight.setLayer(panelRight, 0); // glass pane layeredPaneRight.add(panelExtendedSearch, "1, 1, fill, fill"); layeredPaneRight.setLayer(panelExtendedSearch, 1); splitPaneHorizontal.setRightComponent(layeredPaneRight); splitPaneHorizontal.setContinuousLayout(true); // beansbinding init initDataBindings(); addComponentListener(new ComponentAdapter() { @Override public void componentHidden(ComponentEvent e) { menu.setVisible(false); super.componentHidden(e); } @Override public void componentShown(ComponentEvent e) { menu.setVisible(true); super.componentHidden(e); } }); // further initializations init(); // filter if (MovieModuleManager.MOVIE_SETTINGS.isStoreUiFilters()) { movieList.searchDuplicates(); movieSelectionModel.filterMovies(MovieModuleManager.MOVIE_SETTINGS.getUiFilters()); } }
From source file:org.tinymediamanager.ui.movies.MoviePanel.java
/** * further initializations./*from w w w. j a va2 s.com*/ */ private void init() { // build menu buildMenu(); // moviename column table.getColumnModel().getColumn(0).setCellRenderer(new BorderCellRenderer()); table.getColumnModel().getColumn(0).setIdentifier("title"); //$NON-NLS-1$ // year column int width = table.getFontMetrics(table.getFont()).stringWidth(" 2000"); int titleWidth = table.getFontMetrics(table.getFont()).stringWidth(BUNDLE.getString("metatag.year")); //$NON-NLS-1$ if (titleWidth > width) { width = titleWidth; } table.getTableHeader().getColumnModel().getColumn(1).setPreferredWidth(width); table.getTableHeader().getColumnModel().getColumn(1).setMinWidth(width); table.getTableHeader().getColumnModel().getColumn(1).setMaxWidth((int) (width * 1.5)); table.getTableHeader().getColumnModel().getColumn(1).setIdentifier("year"); //$NON-NLS-1$ // rating column width = table.getFontMetrics(table.getFont()).stringWidth(" 10.0"); titleWidth = table.getFontMetrics(table.getFont()).stringWidth(BUNDLE.getString("metatag.rating")); //$NON-NLS-1$ if (titleWidth > width) { width = titleWidth; } table.getTableHeader().getColumnModel().getColumn(2).setPreferredWidth((int) (width * 1.2)); table.getTableHeader().getColumnModel().getColumn(2).setMinWidth((int) (width * 1.2)); table.getTableHeader().getColumnModel().getColumn(2).setMaxWidth((int) (width * 1.5)); table.getTableHeader().getColumnModel().getColumn(2).setIdentifier("rating"); //$NON-NLS-1$ // date added column width = table.getFontMetrics(table.getFont()).stringWidth("01. Jan. 2000"); titleWidth = table.getFontMetrics(table.getFont()).stringWidth(BUNDLE.getString("metatag.dateadded")); //$NON-NLS-1$ if (titleWidth > width) { width = titleWidth; } table.getTableHeader().getColumnModel().getColumn(3).setPreferredWidth((int) (width * 1.2)); table.getTableHeader().getColumnModel().getColumn(3).setMinWidth((int) (width * 1.2)); table.getTableHeader().getColumnModel().getColumn(3).setMaxWidth((int) (width * 1.2)); table.getTableHeader().getColumnModel().getColumn(3).setIdentifier("dateadded"); //$NON-NLS-1$ // NFO column table.getTableHeader().getColumnModel().getColumn(4) .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.nfo"))); //$NON-NLS-1$ table.getTableHeader().getColumnModel().getColumn(4).setMaxWidth(20); table.getColumnModel().getColumn(4).setHeaderValue(IconManager.INFO); table.getTableHeader().getColumnModel().getColumn(4).setIdentifier("nfo"); //$NON-NLS-1$ // Meta data column table.getTableHeader().getColumnModel().getColumn(5) .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.metadata"))); //$NON-NLS-1$ table.getTableHeader().getColumnModel().getColumn(5).setMaxWidth(20); table.getColumnModel().getColumn(5).setHeaderValue(IconManager.SEARCH); table.getTableHeader().getColumnModel().getColumn(5).setIdentifier("metadata"); //$NON-NLS-1$ // Images column table.getTableHeader().getColumnModel().getColumn(6) .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.images"))); //$NON-NLS-1$ table.getTableHeader().getColumnModel().getColumn(6).setMaxWidth(20); table.getColumnModel().getColumn(6).setHeaderValue(IconManager.IMAGE); table.getTableHeader().getColumnModel().getColumn(6).setIdentifier("images"); //$NON-NLS-1$ // trailer column table.getTableHeader().getColumnModel().getColumn(7) .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.trailer"))); //$NON-NLS-1$ table.getTableHeader().getColumnModel().getColumn(7).setMaxWidth(20); table.getColumnModel().getColumn(7).setHeaderValue(IconManager.CLAPBOARD); table.getTableHeader().getColumnModel().getColumn(7).setIdentifier("trailer"); //$NON-NLS-1$ // subtitles column table.getTableHeader().getColumnModel().getColumn(8) .setHeaderRenderer(new IconRenderer(BUNDLE.getString("tmm.subtitles"))); //$NON-NLS-1$ table.getTableHeader().getColumnModel().getColumn(8).setMaxWidth(20); table.getColumnModel().getColumn(8).setHeaderValue(IconManager.SUBTITLE); table.getTableHeader().getColumnModel().getColumn(8).setIdentifier("subtitle"); //$NON-NLS-1$ // watched column table.getTableHeader().getColumnModel().getColumn(9) .setHeaderRenderer(new IconRenderer(BUNDLE.getString("metatag.watched"))); //$NON-NLS-1$ table.getTableHeader().getColumnModel().getColumn(9).setMaxWidth(20); table.getColumnModel().getColumn(9).setHeaderValue(IconManager.PLAY_SMALL); table.getTableHeader().getColumnModel().getColumn(9).setIdentifier("watched"); //$NON-NLS-1$ table.setSelectionModel(movieSelectionModel.getSelectionModel()); // selecting first movie at startup if (movieList.getMovies() != null && movieList.getMovies().size() > 0) { ListSelectionModel selectionModel = table.getSelectionModel(); if (selectionModel.isSelectionEmpty()) { selectionModel.setSelectionInterval(0, 0); } } // hide columns if needed if (!MovieModuleManager.MOVIE_SETTINGS.isYearColumnVisible()) { table.hideColumn("year"); //$NON-NLS-1$ } if (!MovieModuleManager.MOVIE_SETTINGS.isRatingColumnVisible()) { table.hideColumn("rating"); //$NON-NLS-1$ } if (!MovieModuleManager.MOVIE_SETTINGS.isDateAddedColumnVisible()) { table.hideColumn("dateadded"); //$NON-NLS-1$ } if (!MovieModuleManager.MOVIE_SETTINGS.isNfoColumnVisible()) { table.hideColumn("nfo"); //$NON-NLS-1$ } if (!MovieModuleManager.MOVIE_SETTINGS.isMetadataColumnVisible()) { table.hideColumn("metadata"); //$NON-NLS-1$ } if (!MovieModuleManager.MOVIE_SETTINGS.isImageColumnVisible()) { table.hideColumn("images"); //$NON-NLS-1$ } if (!MovieModuleManager.MOVIE_SETTINGS.isTrailerColumnVisible()) { table.hideColumn("trailer"); //$NON-NLS-1$ } if (!MovieModuleManager.MOVIE_SETTINGS.isSubtitleColumnVisible()) { table.hideColumn("subtitle"); //$NON-NLS-1$ } if (!MovieModuleManager.MOVIE_SETTINGS.isWatchedColumnVisible()) { table.hideColumn("watched"); //$NON-NLS-1$ } // and add a propertychangelistener to the columnhider PropertyChangeListener settingsPropertyChangeListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getSource() instanceof MovieSettings) { if ("yearColumnVisible".equals(evt.getPropertyName())) { setColumnVisibility("year", (Boolean) evt.getNewValue()); //$NON-NLS-1$ } if ("ratingColumnVisible".equals(evt.getPropertyName())) { setColumnVisibility("rating", (Boolean) evt.getNewValue()); //$NON-NLS-1$ } if ("nfoColumnVisible".equals(evt.getPropertyName())) { setColumnVisibility("nfo", (Boolean) evt.getNewValue()); } if ("metadataColumnVisible".equals(evt.getPropertyName())) { setColumnVisibility("metadata", (Boolean) evt.getNewValue()); } if ("dateAddedColumnVisible".equals(evt.getPropertyName())) { setColumnVisibility("dateadded", (Boolean) evt.getNewValue()); } if ("imageColumnVisible".equals(evt.getPropertyName())) { setColumnVisibility("images", (Boolean) evt.getNewValue()); //$NON-NLS-1$ } if ("trailerColumnVisible".equals(evt.getPropertyName())) { setColumnVisibility("trailer", (Boolean) evt.getNewValue()); //$NON-NLS-1$ } if ("subtitleColumnVisible".equals(evt.getPropertyName())) { setColumnVisibility("subtitle", (Boolean) evt.getNewValue()); //$NON-NLS-1$ } if ("watchedColumnVisible".equals(evt.getPropertyName())) { setColumnVisibility("watched", (Boolean) evt.getNewValue()); //$NON-NLS-1$ } } } private void setColumnVisibility(Object identifier, Boolean visible) { if (visible) { table.showColumn(identifier); } else { table.hideColumn(identifier); } } }; MovieModuleManager.MOVIE_SETTINGS.addPropertyChangeListener(settingsPropertyChangeListener); // initialize filteredCount lblMovieCountFiltered.setText(String.valueOf(movieTableModel.getRowCount())); addKeyListener(); }
From source file:org.tinymediamanager.ui.movies.MoviePanel.java
private void addKeyListener() { table.addKeyListener(new KeyListener() { private long lastKeypress = 0; private String searchTerm = ""; @Override/*from www . j ava 2 s. co m*/ public void keyTyped(KeyEvent arg0) { long now = System.currentTimeMillis(); if (now - lastKeypress > 500) { searchTerm = ""; } lastKeypress = now; if (arg0.getKeyChar() != KeyEvent.CHAR_UNDEFINED) { searchTerm += arg0.getKeyChar(); } if (StringUtils.isNotBlank(searchTerm)) { TableModel model = table.getModel(); for (int i = 0; i < model.getRowCount(); i++) { if (model.getValueAt(i, 0) instanceof Movie) { String title = ((Movie) model.getValueAt(i, 0)).getTitleSortable() .toLowerCase(Locale.ROOT); if (title.startsWith(searchTerm)) { ListSelectionModel selectionModel = table.getSelectionModel(); selectionModel.setSelectionInterval(i, i); table.scrollRectToVisible(new Rectangle(table.getCellRect(i, 0, true))); break; } } } } } @Override public void keyReleased(KeyEvent arg0) { } @Override public void keyPressed(KeyEvent arg0) { } }); }