List of usage examples for javax.swing.event ListSelectionEvent getSource
public Object getSource()
From source file:org.tinymediamanager.ui.moviesets.dialogs.MovieSetChooserDialog.java
/** * Instantiates a new movie set chooser panel. * // w w w .j a v a 2 s.c om * @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:pcgen.gui2.dialog.ChooserDialog.java
@Override public void valueChanged(ListSelectionEvent e) { if (availTable != null && !e.getValueIsAdjusting()) { if (e.getSource() == availTable.getSelectionModel() && availTable.getSelectedObject() instanceof InfoFacade) { InfoFacade target = (InfoFacade) availTable.getSelectedObject(); InfoFactory factory = chooser.getInfoFactory(); if (factory != null && target != null) { infoPane.setText(factory.getHTMLInfo(target)); }/*from ww w.ja va2 s .c o m*/ } } }
From source file:pcgen.gui2.sources.AdvancedSourceSelectionPanel.java
@Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (e.getSource() == availableTable.getSelectionModel()) { int selectedRow = availableTable.getSelectedRow(); if (selectedRow != -1) { final Object data = availableTable.getModel().getValueAt(selectedRow, 0); if (data != null && data instanceof CampaignFacade) { setSelectedCampaign((CampaignFacade) data); }/*from www. jav a2s .c om*/ } } else if (e.getSource() == selectedTable.getSelectionModel()) { int selectedRow = selectedTable.getSelectedRow(); if (selectedRow != -1) { final Object data = selectedTable.getModel().getValueAt(selectedRow, 0); if (data != null && data instanceof CampaignFacade) { setSelectedCampaign((CampaignFacade) data); } } } } }
From source file:pcgen.gui2.tabs.spells.SpellInfoHandler.java
@Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Object obj;//from ww w . ja v a 2 s . c o m if (e.getSource() == availableTable.getSelectionModel()) { obj = availableTable.getSelectedObject(); } else { obj = selectedTable.getSelectedObject(); } if (obj instanceof SpellNode) { SpellNode node = (SpellNode) obj; String text = character.getInfoFactory().getHTMLInfo(node.getSpell()); currText = text; spellsPane.setText(text); } else if (obj instanceof RootNode) { RootNode node = (RootNode) obj; String text = character.getInfoFactory().getSpellBookInfo(node.getName()); if (!StringUtils.isEmpty(text)) { currText = text; spellsPane.setText(text); } } } }
From source file:pl.otros.logview.gui.message.editor.MessageColorizerBrowser.java
public MessageColorizerBrowser(OtrosApplication otrosApplication) { super(new BorderLayout()); this.container = otrosApplication.getAllPluginables().getMessageColorizers(); this.otrosApplication = otrosApplication; toolBar = new JToolBar(); editor = new MessageColorizerEditor(container, otrosApplication.getStatusObserver()); JLabel noEditable = new JLabel("Selected MessageColorizer is not editable.", SwingConstants.CENTER); JLabel nothingSelected = new JLabel("Nothing selected", SwingConstants.CENTER); listModel = new PluginableElementListModel<MessageColorizer>(container); jList = new JList(listModel); jList.setCellRenderer(new PluginableElementNameListRenderer()); cardLayout = new CardLayout(); contentPanel = new JPanel(cardLayout); contentPanel.add(editor, CARD_LAYOUT_EDITOR); contentPanel.add(noEditable, CARD_LAYOUT_NOT_EDITABLE); contentPanel.add(nothingSelected, CARD_LAYOUT_NO_SELECTED); cardLayout.show(contentPanel, CARD_LAYOUT_NOT_EDITABLE); JSplitPane mainSplitPane = new JSplitPane(SwingConstants.VERTICAL, new JScrollPane(jList), contentPanel); mainSplitPane.setDividerLocation(220); jList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override//from w w w. j ava 2s . c o m public void valueChanged(ListSelectionEvent e) { showSelected(); enableDisableButtonsForSelectedColorizer(); } }); jList.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_DELETE) { ActionEvent actionEvent = new ActionEvent(e.getSource(), ActionEvent.ACTION_PERFORMED, ""); deleteAction.actionPerformed(actionEvent); } } }); JButton createNew = new JButton("Create new", Icons.ADD); createNew.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveAsButton.setEnabled(false); createNew(); } }); saveButton = new JButton("Save and use", Icons.DISK); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { PropertyPatternMessageColorizer mc = editor.createMessageColorizer(); File selectedFile = null; String f = mc.getFile(); if (StringUtils.isNotBlank(f)) { selectedFile = new File(mc.getFile()); } else { int response = chooser.showSaveDialog(MessageColorizerBrowser.this); if (response != JFileChooser.APPROVE_OPTION) { return; } selectedFile = chooser.getSelectedFile(); if (!selectedFile.getName().endsWith(".pattern")) { selectedFile = new File(selectedFile.getParentFile(), selectedFile.getName() + ".pattern"); } } removeMessageColorizerWithNullFile(); applyMessageColorizer(selectedFile); saveMessageColorizer(selectedFile); jList.setSelectedValue(mc, true); } catch (ConfigurationException e1) { String errorMessage = String.format("Can't save message colorizer: %s", e1.getMessage()); LOGGER.severe(errorMessage); MessageColorizerBrowser.this.otrosApplication.getStatusObserver().updateStatus(errorMessage, StatusObserver.LEVEL_ERROR); } } }); saveAsButton = new JButton("Save as", Icons.DISK_PLUS); saveAsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { int response = chooser.showSaveDialog(MessageColorizerBrowser.this); if (response != JFileChooser.APPROVE_OPTION) { return; } File selectedFile = chooser.getSelectedFile(); selectedFile = chooser.getSelectedFile(); if (!selectedFile.getName().endsWith(".pattern")) { selectedFile = new File(selectedFile.getParentFile(), selectedFile.getName() + ".pattern"); } removeMessageColorizerWithNullFile(); applyMessageColorizer(selectedFile); saveMessageColorizer(selectedFile); jList.setSelectedValue(editor.createMessageColorizer(), true); } catch (ConfigurationException e1) { String errorMessage = String.format("Can't save message colorizer: %s", e1.getMessage()); LOGGER.severe(errorMessage); MessageColorizerBrowser.this.otrosApplication.getStatusObserver().updateStatus(errorMessage, StatusObserver.LEVEL_ERROR); } } }); useButton = new JButton("Use without saving"); useButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { removeMessageColorizerWithNullFile(); applyMessageColorizer(File.createTempFile("messageColorizer", "pattern")); } catch (Exception e) { LOGGER.severe("Cannot create message colorizer: " + e.getMessage()); } } }); deleteAction = new DeleteSelected(otrosApplication); deleteButton = new JButton(deleteAction); toolBar.setFloatable(false); toolBar.add(createNew); toolBar.add(saveButton); toolBar.add(saveAsButton); toolBar.add(useButton); toolBar.add(deleteButton); enableDisableButtonsForSelectedColorizer(); initFileChooser(); this.add(mainSplitPane); this.add(toolBar, BorderLayout.SOUTH); }
From source file:xtrememp.PlaylistManager.java
@Override public void valueChanged(ListSelectionEvent e) { if (e.getSource() == playlistTable.getSelectionModel()) { if (playlistTable.getSelectedRowCount() > 0) { remFromPlaylistButton.setEnabled(true); mediaInfoButton.setEnabled(true); }//from ww w. java 2 s. co m ListSelectionModel lsm = playlistTable.getSelectionModel(); if (lsm.getMinSelectionIndex() == 0) { moveUpButton.setEnabled(false); } else { moveUpButton.setEnabled(true); } if (lsm.getMaxSelectionIndex() == (playlistTable.getRowCount() - 1)) { moveDownButton.setEnabled(false); } else { moveDownButton.setEnabled(true); } } }