List of usage examples for java.beans PropertyChangeListener PropertyChangeListener
PropertyChangeListener
From source file:org.openconcerto.erp.core.humanresources.payroll.element.FichePayeSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private FichePayeModel model; private ElementComboBox comboSelProfil, selSalCombo; private EditFrame edit = null; private ElementComboBox selMois; private int dernMois, dernAnnee; private JTextField textAnnee; JDate dateDu, dateAu;/*www . jav a 2 s .c om*/ private JScrollPane paneTreeLeft; private JPanel pDate; private JButton buttonValider, buttonGenCompta; public void addViews() { this.dernMois = 0; this.dernAnnee = 0; this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); // Tree elt Fiche de Paye On the left c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.gridheight = GridBagConstraints.REMAINDER; final RubriquePayeTree tree = new RubriquePayeTree(); tree.expandRow(0); this.paneTreeLeft = new JScrollPane(tree); // this.add(this.paneTreeLeft, c); // Panel Fiche paye on the right // Salarie JPanel panelRight = new JPanel(); panelRight.setLayout(new GridBagLayout()); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.weighty = 0; c.gridheight = 1; c.gridwidth = 2; this.selSalCombo = new ElementComboBox(); // c.gridx++; panelRight.add(this.selSalCombo, c); // Mois c.gridy++; // c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.weighty = 0; c.gridheight = 1; c.gridwidth = 3; JLabel labelMois = new JLabel("Fiche de paye du mois de"); this.selMois = new ElementComboBox(true, 20); // this.selMois.setEditable(true); // /this.selMois.setEnabled(true); JLabel labelDu = new JLabel("Du"); JLabel labelAu = new JLabel("Au"); this.dateDu = new JDate(); this.dateAu = new JDate(); // JTextField textMois = new JTextField(); JLabel labelAnnee = new JLabel("Anne"); this.textAnnee = new JTextField(); { this.pDate = new JPanel(); this.pDate.setOpaque(false); this.pDate.add(labelMois); this.pDate.add(this.selMois); this.pDate.add(labelAnnee); this.pDate.add(this.textAnnee); this.pDate.add(labelDu); this.pDate.add(this.dateDu); this.pDate.add(labelAu); this.pDate.add(this.dateAu); panelRight.add(this.pDate, c); } c.gridx += 2; c.weightx = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; panelRight.add(new JPanel(), c); // Action Button c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.weighty = 0; JPanel pButtons = new JPanel(); pButtons.setOpaque(false); JButton buttonUp = new JNiceButton(IListFrame.class.getResource("fleche_haut.png")); JButton buttonDown = new JNiceButton(IListFrame.class.getResource("fleche_bas.png")); JButton buttonRemove = new JNiceButton(SQLComponent.class.getResource("delete.png")); { pButtons.add(buttonUp); pButtons.add(buttonDown); pButtons.add(buttonRemove); } panelRight.add(pButtons, c); // Table c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.gridx = 1; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; this.model = new FichePayeModel(1); final JTable table = new JTable(this.model); panelRight.add(new JScrollPane(table), c); FichePayeRenderer rend = new FichePayeRenderer(); table.setDefaultRenderer(String.class, rend); table.setDefaultRenderer(Float.class, rend); // Import profil c.gridx = 1; c.gridy++; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; JLabel labelProfil = new JLabel("Importer depuis un profil prdfini"); panelRight.add(labelProfil, c); c.gridwidth = 1; this.comboSelProfil = new ElementComboBox(); // this.comboSelProfil = new ElementComboBox(); this.comboSelProfil.setListIconVisible(false); c.gridx++; c.gridwidth = 1; // this.comboSelProfil.init(eltProfil.getTable().getField("NOM"), null); panelRight.add(this.comboSelProfil, c); JButton buttonImportProfil = new JButton("Importer"); c.gridx++; panelRight.add(buttonImportProfil, c); // Total Periode JPanel panelTotal = new JPanel(); panelTotal.setBorder(BorderFactory.createTitledBorder("Total priode")); panelTotal.setLayout(new GridBagLayout()); GridBagConstraints cPanel = new DefaultGridBagConstraints(); // Salaire brut JLabel labelBrut = new JLabel(getLabelFor("SAL_BRUT")); panelTotal.add(labelBrut, cPanel); JTextField textSalBrut = new JTextField(10); cPanel.gridx++; cPanel.weightx = 0; panelTotal.add(textSalBrut, cPanel); textSalBrut.setEditable(false); textSalBrut.setEnabled(false); // acompte cPanel.gridx++; JLabel labelAcompte = new JLabel(getLabelFor("ACOMPTE")); panelTotal.add(labelAcompte, cPanel); JTextField textAcompte = new JTextField(10); cPanel.gridx++; panelTotal.add(textAcompte, cPanel); // textAcompte.setEditable(false); // textAcompte.setEnabled(false); // Conges Acquis cPanel.gridx++; JLabel labelCongesAcquis = new JLabel(getLabelFor("CONGES_ACQUIS")); panelTotal.add(labelCongesAcquis, cPanel); JTextField textCongesAcquis = new JTextField(10); cPanel.gridx++; panelTotal.add(textCongesAcquis, cPanel); // cotisation salariale cPanel.gridx = 0; cPanel.gridy++; JLabel labelCotSal = new JLabel(getLabelFor("COT_SAL")); panelTotal.add(labelCotSal, cPanel); JTextField textCotSal = new JTextField(10); cPanel.gridx++; panelTotal.add(textCotSal, cPanel); textCotSal.setEditable(false); textCotSal.setEnabled(false); // cotisation patronale cPanel.gridx++; JLabel labelCotPat = new JLabel(getLabelFor("COT_PAT")); panelTotal.add(labelCotPat, cPanel); JTextField textCotPat = new JTextField(10); cPanel.gridx++; panelTotal.add(textCotPat, cPanel); textCotPat.setEditable(false); textCotPat.setEnabled(false); JLabel labelCSG = new JLabel(getLabelFor("CSG")); cPanel.gridx++; panelTotal.add(labelCSG, cPanel); JTextField textCSG = new JTextField(10); cPanel.gridx++; panelTotal.add(textCSG, cPanel); textCSG.setEditable(false); textCSG.setEnabled(false); // net imposable cPanel.gridx = 0; cPanel.gridy++; JLabel labelNetImp = new JLabel(getLabelFor("NET_IMP")); panelTotal.add(labelNetImp, cPanel); JTextField textNetImp = new JTextField(10); cPanel.gridx++; panelTotal.add(textNetImp, cPanel); textNetImp.setEditable(false); textNetImp.setEnabled(false); cPanel.gridx++; JLabel labelNetAPayer = new JLabel(getLabelFor("NET_A_PAYER")); panelTotal.add(labelNetAPayer, cPanel); JTextField textNetAPayer = new JTextField(10); cPanel.gridx++; panelTotal.add(textNetAPayer, cPanel); textNetAPayer.setEditable(false); textNetAPayer.setEnabled(false); c.gridx = 1; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; panelRight.add(panelTotal, c); // Cumuls c.gridx = 1; c.gridy++; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; this.buttonValider = new JButton("Valider"); // panelRight.add(buttonValider, c); c.gridx++; c.gridwidth = 1; this.buttonGenCompta = new JButton("Generer la comptabilit"); // panelRight.add(buttonGenCompta, c); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; this.add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.paneTreeLeft, panelRight), c); // Listeners this.buttonGenCompta.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int[] i = new int[1]; i[0] = getSelectedID(); SQLRow rowMois = getTable().getBase().getTable("MOIS").getRow(selMois.getSelectedId()); new GenerationMvtFichePaye(i, rowMois.getString("NOM"), textAnnee.getText()); } }); this.buttonValider.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.err.println("Validation de la fiche de paye"); validationFiche(); } }); buttonUp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int newRowSelected = model.upRow(table.getSelectedRow()); if (newRowSelected >= 0) { table.setRowSelectionInterval(newRowSelected, newRowSelected); } } }); buttonDown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int newRowSelected = model.downRow(table.getSelectedRow()); if (newRowSelected >= 0) { table.setRowSelectionInterval(newRowSelected, newRowSelected); } } }); buttonRemove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.removeRow(table.getSelectedRow()); } }); tree.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mE) { TreePath path = tree.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); final Object obj = path.getLastPathComponent(); if (obj == null) { return; } if (mE.getClickCount() == 2 && mE.getButton() == MouseEvent.BUTTON1) { if (obj instanceof VariableRowTreeNode) { model.addRowAt(((VariableRowTreeNode) obj).getRow(), table.getSelectedRow()); } } else { if (mE.getButton() == 3) { if (obj instanceof VariableRowTreeNode) { final SQLRow row = ((VariableRowTreeNode) obj).getRow(); JPopupMenu menuDroit = new JPopupMenu(); menuDroit.add(new AbstractAction("Editer") { public void actionPerformed(ActionEvent e) { if (edit != null) { edit.dispose(); } edit = new EditFrame(Configuration.getInstance().getDirectory() .getElement(row.getTable()), EditFrame.MODIFICATION); edit.selectionId(row.getID(), 0); edit.pack(); edit.setVisible(true); } }); menuDroit.add(new AbstractAction("Nouvelle rubrique") { public void actionPerformed(ActionEvent e) { if (edit != null) { edit.dispose(); } edit = new EditFrame(Configuration.getInstance().getDirectory() .getElement(row.getTable())); edit.pack(); edit.setVisible(true); } }); menuDroit.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y); } } } } }); this.dateDu.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (!dateDu.isEmpty()) { Date d = dateDu.getValue(); if (d != null) { Calendar cal = Calendar.getInstance(); cal.setTime(d); if (selMois.getSelectedId() > 1 && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) { cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, selMois.getSelectedId() - 2); System.err.println("Du " + cal.getTime()); dateDu.setValue(cal.getTime()); } } } } }); this.dateAu.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (!dateAu.isEmpty()) { Date d = dateAu.getValue(); if (d != null) { Calendar cal = Calendar.getInstance(); cal.setTime(d); if (selMois.getSelectedId() > 1 && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) { // TODO checker l'annee // TODO ajouter dans le isValidated du au compris dans le mois // selectionne // Calendar.getInstance().set(Calendar.DAY_OF_MONTH, maxDay); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, selMois.getSelectedId() - 2); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); System.err.println("Au " + cal.getTime()); dateAu.setValue(cal.getTime()); } } } } }); this.addRequiredSQLObject(this.textAnnee, "ANNEE"); this.addRequiredSQLObject(this.selMois, "ID_MOIS"); this.addSQLObject(this.comboSelProfil, "ID_PROFIL_PAYE"); this.addSQLObject(textCongesAcquis, "CONGES_ACQUIS"); this.addSQLObject(textCotPat, "COT_PAT"); this.addSQLObject(textCotSal, "COT_SAL"); this.addSQLObject(textCSG, "CSG"); this.addSQLObject(textNetAPayer, "NET_A_PAYER"); this.addSQLObject(textNetImp, "NET_IMP"); this.addSQLObject(textSalBrut, "SAL_BRUT"); this.addSQLObject(textAcompte, "ACOMPTE"); this.addSQLObject(this.selSalCombo, "ID_SALARIE"); this.addRequiredSQLObject(this.dateDu, "DU"); this.addRequiredSQLObject(this.dateAu, "AU"); this.selSalCombo.setEditable(false); this.selSalCombo.setEnabled(false); this.selSalCombo.setButtonsVisible(false); // this.selSalCombo.setVisible(false); buttonImportProfil.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.loadFromProfil(comboSelProfil.getSelectedId()); } }); } private boolean isDateValid() { String yearS = this.textAnnee.getText().trim(); int annee = (yearS.length() == 0) ? 0 : Integer.parseInt(yearS); int mois = this.selMois.getSelectedId(); // System.err.println("anne " + annee + " dernAnnee " + this.dernAnnee + " mois " + // mois + " dernMois " + this.dernMois); return ((this.dernAnnee == 0) ? true : annee > this.dernAnnee) || ((this.dernMois == 0 || this.dernMois == 13) ? true : mois > this.dernMois); } @Override public synchronized ValidState getValidState() { // FIXME add fireValidChange() return super.getValidState().and(ValidState.createCached(isDateValid(), "Date invalide")); } public int insert(SQLRow order) { int id = super.insert(order); this.model.updateFields(id); return id; } @Override public void update() { super.update(); this.model.updateFields(this.getSelectedID()); } @Override public void select(SQLRowAccessor r) { // System.err.println("SELECT FICHE ID -> " + r.getID()); super.select(r); if (r != null && r.getID() > 1) { this.model.setFicheID(r.getID()); SQLTable tableSal = getTable().getBase().getTable("SALARIE"); SQLRow rowSal = tableSal.getRow(r.getInt("ID_SALARIE")); this.dernMois = rowSal.getInt("DERNIER_MOIS"); this.dernAnnee = rowSal.getInt("DERNIERE_ANNEE"); this.selSalCombo.setVisible(((Boolean) r.getObject("VALIDE")).booleanValue()); this.paneTreeLeft.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue()); this.buttonValider.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue()); setpDateEnabled(!((Boolean) r.getObject("VALIDE")).booleanValue()); } this.selSalCombo.setEditable(false); this.selSalCombo.setEnabled(false); this.selMois.setButtonsVisible(false); this.selSalCombo.setButtonsVisible(false); } private void setpDateEnabled(boolean b) { // System.err.println("Set date enable --> " + b); this.selMois.setEditable(b); // this.selMois.setEnabled(b); this.textAnnee.setEditable(b); this.textAnnee.setEnabled(b); this.dateDu.setEditable(b); this.dateDu.setEnabled(b); this.dateAu.setEditable(b); this.dateAu.setEnabled(b); } private void validationFiche() { this.update(); FichePayeSQLElement.validationFiche(this.getSelectedID()); } protected SQLRowValues createDefaults() { System.err.println("**********Set Defaults on FichePaye.date"); SQLRowValues rowVals = new SQLRowValues(getTable()); Calendar cal = Calendar.getInstance(); rowVals.put("ID_MOIS", cal.get(Calendar.MONTH) + 2); rowVals.put("ANNEE", cal.get(Calendar.YEAR)); cal.set(Calendar.DAY_OF_MONTH, 1); rowVals.put("DU", new java.sql.Date(cal.getTime().getTime())); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); rowVals.put("AU", new java.sql.Date(cal.getTime().getTime())); return rowVals; } }; }
From source file:org.jspresso.hrsample.backend.JspressoModelTest.java
/** * Tests that property cache gets correctly reset when there is no listener * (bug #852) and that the property change events are correctly fired when the * computed property is supposed to change (bug #1025). *///from w ww .j a v a 2s.com @Test public void testComputedPropertyCacheResetAndNotif() { Employee emp = getBackendController().getEntityFactory().createEntityInstance(Employee.class); Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR, 1973); emp.setBirthDate(c.getTime()); assertEquals("Age is not correctly computed.", emp.computeAge(emp.getBirthDate()), emp.getAge()); c.add(Calendar.YEAR, -3); emp.setBirthDate(c.getTime()); assertEquals("Age is not correctly computed after birth date modification.", emp.computeAge(emp.getBirthDate()), emp.getAge()); final StringBuilder buff = new StringBuilder(); emp.addPropertyChangeListener(Employee.AGE, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { buff.append(evt.getNewValue()); } }); c.add(Calendar.YEAR, -5); emp.setBirthDate(c.getTime()); assertEquals("Age is not correctly computedafter 2nd birth date modification.", emp.computeAge(emp.getBirthDate()), emp.getAge()); assertTrue("Age notification failed.", buff.length() > 0); assertEquals("Age notification contains bad value.", emp.computeAge(emp.getBirthDate()).toString(), buff.toString()); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditorControl.java
/** Brings up the folder chooser. */ private void export() { DowngradeChooser chooser = new DowngradeChooser(new RefWindow(), FileChooser.SAVE, "Export", "Select where to export the image as OME-TIFF.", exportFilters); try {//www . j a v a2s .c o m String path = MetadataViewerAgent.getRegistry().getTaskBar() .getLibFileRelative(TransformsParser.SPECIFICATION + ".jar"); chooser.parseData(path); } catch (Exception e) { LogMessage msg = new LogMessage(); msg.print(e); MetadataViewerAgent.getRegistry().getLogger().debug(this, msg); } String s = UIUtilities.removeFileExtension(view.getRefObjectName()); chooser.setSelectedFileFull(s); chooser.setCheckOverride(true); chooser.setApproveButtonText("Export"); IconManager icons = IconManager.getInstance(); chooser.setTitleIcon(icons.getIcon(IconManager.EXPORT_AS_OMETIFF_48)); chooser.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) { File[] files = (File[]) evt.getNewValue(); File folder = files[0]; if (folder == null) folder = UIUtilities.getDefaultFolder(); Object src = evt.getSource(); Target target = null; if (src instanceof DowngradeChooser) { ((FileChooser) src).setVisible(false); ((FileChooser) src).dispose(); target = ((DowngradeChooser) src).getSelectedSchema(); } model.exportImageAsOMETIFF(folder, target); } else if (DowngradeChooser.HELP_DOWNGRADE_PROPERTY.equals(name)) { Registry reg = MetadataViewerAgent.getRegistry(); String url = (String) reg.lookup("HelpDowngrade"); reg.getTaskBar().openURL(url); } } }); chooser.centerDialog(); }
From source file:org.jspresso.framework.application.frontend.action.lov.LovAction.java
/** * Feed context with dialog./*from w w w . ja va2 s. com*/ * * @param erqDescriptor * the erq descriptor * @param queryComponent * the query component * @param lovView * the lov view * @param actionHandler * the action handler * @param context * the context */ protected void feedContextWithDialog(IReferencePropertyDescriptor<IComponent> erqDescriptor, IQueryComponent queryComponent, IView<E> lovView, final IActionHandler actionHandler, final Map<String, Object> context) { getViewConnector(context).setConnectorValue(getViewConnector(context).getConnectorValue()); if (!context.containsKey(ModalDialogAction.DIALOG_ACTIONS)) { List<IDisplayableAction> actions = new ArrayList<>(); actions.add(getOkAction()); if (getCreateAction() != null) { actions.add(getCreateAction()); } actions.add(getFindAction()); actions.add(getCancelAction()); context.put(ModalDialogAction.DIALOG_ACTIONS, actions); } context.put(ModalDialogAction.DIALOG_TITLE, getI18nName(getTranslationProvider(context), getLocale(context)) + " : " + erqDescriptor.getReferencedDescriptor().getI18nName(getTranslationProvider(context), getLocale(context))); context.put(ModalDialogAction.DIALOG_VIEW, lovView); if (lovView instanceof ICompositeView<?>) { context.put(ModalDialogAction.DIALOG_FOCUSED_COMPONENT, ((ICompositeView<E>) lovView).getChildren().get(1).getPeer()); } if (pagingAction != null) { PropertyChangeListener paginationListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getOldValue() != null && evt.getNewValue() != null) { try { context.put(AbstractQbeAction.PAGINATE, null); actionHandler.execute(pagingAction, context); } finally { context.remove(AbstractQbeAction.PAGINATE); } } } }; queryComponent.addPropertyChangeListener(IPageable.PAGE, paginationListener); } }
From source file:org.tinymediamanager.ui.tvshows.TvShowPanel.java
/** * Instantiates a new tv show panel./* w w w .j a v a 2s . c om*/ */ public TvShowPanel() { super(); treeModel = new TvShowTreeModel(tvShowList.getTvShows()); tvShowSeasonSelectionModel = new TvShowSeasonSelectionModel(); tvShowEpisodeSelectionModel = new TvShowEpisodeSelectionModel(); // build menu menu = new JMenu(BUNDLE.getString("tmm.tvshows")); //$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("default:grow"), })); JSplitPane splitPane = new JSplitPane(); splitPane.setContinuousLayout(true); add(splitPane, "2, 2, fill, fill"); JPanel panelTvShowTree = new JPanel(); splitPane.setLeftComponent(panelTvShowTree); panelTvShowTree.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.UNRELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, RowSpec.decode("3px:grow"), FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); textField = EnhancedTextField.createSearchTextField(); panelTvShowTree.add(textField, "4, 1, right, bottom"); textField.setColumns(12); textField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(final DocumentEvent e) { applyFilter(); } @Override public void removeUpdate(final DocumentEvent e) { applyFilter(); } @Override public void changedUpdate(final DocumentEvent e) { applyFilter(); } public void applyFilter() { TvShowTreeModel filteredModel = (TvShowTreeModel) tree.getModel(); if (StringUtils.isNotBlank(textField.getText())) { filteredModel.setFilter(SearchOptions.TEXT, textField.getText()); } else { filteredModel.removeFilter(SearchOptions.TEXT); } filteredModel.filter(tree); } }); final JToggleButton btnFilter = new JToggleButton(IconManager.FILTER); btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$ panelTvShowTree.add(btnFilter, "6, 1, default, bottom"); JScrollPane scrollPane = new JScrollPane(); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); panelTvShowTree.add(scrollPane, "2, 3, 5, 1, fill, fill"); JToolBar toolBar = new JToolBar(); toolBar.setRollover(true); toolBar.setFloatable(false); toolBar.setOpaque(false); panelTvShowTree.add(toolBar, "2, 1"); // 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(); buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateDatasources2)); buttonUpdateDatasource.getPopupMenu().addSeparator(); for (String ds : TvShowModuleManager.SETTINGS.getTvShowDataSource()) { buttonUpdateDatasource.getPopupMenu() .add(new JMenuItem(new TvShowUpdateSingleDatasourceAction(ds))); } buttonUpdateDatasource.getPopupMenu().addSeparator(); buttonUpdateDatasource.getPopupMenu().add(new JMenuItem(actionUpdateTvShow)); 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.setSplitWidth(18); buttonScrape.setToolTipText(BUNDLE.getString("tvshow.scrape.selected")); //$NON-NLS-1$ // register for listener buttonScrape.addSplitButtonActionListener(new SplitButtonActionListener() { @Override public void buttonClicked(ActionEvent e) { actionScrape.actionPerformed(e); } @Override 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); item = new JMenuItem(actionScrapeNewItems); popup.add(item); buttonScrape.setPopupMenu(popup); toolBar.add(buttonScrape); toolBar.add(actionEdit); JButton btnMediaInformation = new JButton(); btnMediaInformation.setAction(actionMediaInformation); toolBar.add(btnMediaInformation); // install drawing of full with tree = new ZebraJTree(treeModel) { private static final long serialVersionUID = 2422163883324014637L; @Override public void paintComponent(Graphics g) { width = this.getWidth(); super.paintComponent(g); } }; tvShowSelectionModel = new TvShowSelectionModel(tree); TreeUI ui = new TreeUI() { @Override protected void paintRow(Graphics g, Rectangle clipBounds, Insets insets, Rectangle bounds, TreePath path, int row, boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { bounds.width = width - bounds.x; super.paintRow(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf); } }; tree.setUI(ui); tree.setRootVisible(false); tree.setShowsRootHandles(true); tree.setCellRenderer(new TvShowTreeCellRenderer()); tree.setRowHeight(0); scrollPane.setViewportView(tree); JPanel panelHeader = new JPanel() { private static final long serialVersionUID = -6914183798172482157L; @Override public void paintComponent(Graphics g) { super.paintComponent(g); JTattooUtilities.fillHorGradient(g, AbstractLookAndFeel.getTheme().getColHeaderColors(), 0, 0, getWidth(), getHeight()); } }; scrollPane.setColumnHeaderView(panelHeader); panelHeader.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px"), ColumnSpec.decode("center:20px") }, new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, })); JLabel lblTvShowsColumn = new JLabel(BUNDLE.getString("metatag.tvshow")); //$NON-NLS-1$ lblTvShowsColumn.setHorizontalAlignment(JLabel.CENTER); panelHeader.add(lblTvShowsColumn, "2, 1"); JLabel lblNfoColumn = new JLabel(""); lblNfoColumn.setHorizontalAlignment(JLabel.CENTER); lblNfoColumn.setIcon(IconManager.INFO); lblNfoColumn.setToolTipText(BUNDLE.getString("metatag.nfo"));//$NON-NLS-1$ panelHeader.add(lblNfoColumn, "4, 1"); JLabel lblImageColumn = new JLabel(""); lblImageColumn.setHorizontalAlignment(JLabel.CENTER); lblImageColumn.setIcon(IconManager.IMAGE); lblImageColumn.setToolTipText(BUNDLE.getString("metatag.images"));//$NON-NLS-1$ panelHeader.add(lblImageColumn, "5, 1"); JLabel lblSubtitleColumn = new JLabel(""); lblSubtitleColumn.setHorizontalAlignment(JLabel.CENTER); lblSubtitleColumn.setIcon(IconManager.SUBTITLE); lblSubtitleColumn.setToolTipText(BUNDLE.getString("metatag.subtitles"));//$NON-NLS-1$ panelHeader.add(lblSubtitleColumn, "6, 1"); JPanel panel = new JPanel(); panelTvShowTree.add(panel, "2, 5, 3, 1, fill, fill"); panel.setLayout(new FormLayout( new ColumnSpec[] { FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, })); JLabel lblTvShowsT = new JLabel(BUNDLE.getString("metatag.tvshows") + ":"); //$NON-NLS-1$ panel.add(lblTvShowsT, "1, 2, fill, fill"); lblTvShows = new JLabel(""); panel.add(lblTvShows, "3, 2"); JLabel labelSlash = new JLabel("/"); panel.add(labelSlash, "5, 2"); JLabel lblEpisodesT = new JLabel(BUNDLE.getString("metatag.episodes") + ":"); //$NON-NLS-1$ panel.add(lblEpisodesT, "7, 2"); lblEpisodes = new JLabel(""); panel.add(lblEpisodes, "9, 2"); 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 JPanel(); layeredPaneRight.add(panelRight, "1, 1, 2, 2, fill, fill"); layeredPaneRight.setLayer(panelRight, 0); // glass pane final TvShowExtendedSearchPanel panelExtendedSearch = new TvShowExtendedSearchPanel(treeModel, tree); panelExtendedSearch.setVisible(false); // panelMovieList.add(panelExtendedSearch, "2, 5, 2, 1, fill, fill"); btnFilter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (panelExtendedSearch.isVisible() == true) { panelExtendedSearch.setVisible(false); } else { panelExtendedSearch.setVisible(true); } } }); // add a propertychangelistener which reacts on setting a filter tree.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if ("filterChanged".equals(evt.getPropertyName())) { if (Boolean.TRUE.equals(evt.getNewValue())) { btnFilter.setIcon(IconManager.FILTER_ACTIVE); btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options.active")); //$NON-NLS-1$ } else { btnFilter.setIcon(IconManager.FILTER); btnFilter.setToolTipText(BUNDLE.getString("movieextendedsearch.options")); //$NON-NLS-1$ } } } }); layeredPaneRight.add(panelExtendedSearch, "1, 1, fill, fill"); layeredPaneRight.setLayer(panelExtendedSearch, 1); splitPane.setRightComponent(layeredPaneRight); panelRight.setLayout(new CardLayout(0, 0)); JPanel panelTvShow = new TvShowInformationPanel(tvShowSelectionModel); panelRight.add(panelTvShow, "tvShow"); JPanel panelTvShowSeason = new TvShowSeasonInformationPanel(tvShowSeasonSelectionModel); panelRight.add(panelTvShowSeason, "tvShowSeason"); JPanel panelTvShowEpisode = new TvShowEpisodeInformationPanel(tvShowEpisodeSelectionModel); panelRight.add(panelTvShowEpisode, "tvShowEpisode"); tree.addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node != null) { // click on a tv show if (node.getUserObject() instanceof TvShow) { TvShow tvShow = (TvShow) node.getUserObject(); tvShowSelectionModel.setSelectedTvShow(tvShow); CardLayout cl = (CardLayout) (panelRight.getLayout()); cl.show(panelRight, "tvShow"); } // click on a season if (node.getUserObject() instanceof TvShowSeason) { TvShowSeason tvShowSeason = (TvShowSeason) node.getUserObject(); tvShowSeasonSelectionModel.setSelectedTvShowSeason(tvShowSeason); CardLayout cl = (CardLayout) (panelRight.getLayout()); cl.show(panelRight, "tvShowSeason"); } // click on an episode if (node.getUserObject() instanceof TvShowEpisode) { TvShowEpisode tvShowEpisode = (TvShowEpisode) node.getUserObject(); tvShowEpisodeSelectionModel.setSelectedTvShowEpisode(tvShowEpisode); CardLayout cl = (CardLayout) (panelRight.getLayout()); cl.show(panelRight, "tvShowEpisode"); } } else { // check if there is at least one tv show in the model TvShowRootTreeNode root = (TvShowRootTreeNode) tree.getModel().getRoot(); if (root.getChildCount() == 0) { // sets an inital show tvShowSelectionModel.setSelectedTvShow(null); } } } }); 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(); initDataBindings(); // selecting first TV show at startup if (tvShowList.getTvShows() != null && tvShowList.getTvShows().size() > 0) { DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) ((DefaultMutableTreeNode) tree.getModel() .getRoot()).getFirstChild(); tree.setSelectionPath(new TreePath(((DefaultMutableTreeNode) firstLeaf.getParent()).getPath())); tree.setSelectionPath(new TreePath(firstLeaf.getPath())); } }
From source file:org.tinymediamanager.ui.movies.dialogs.MovieBatchEditorDialog.java
/** * Instantiates a new movie batch editor. * //from w ww . ja va 2 s . c om * @param movies * the movies */ public MovieBatchEditorDialog(final List<Movie> movies) { super(BUNDLE.getString("movie.edit"), "movieBatchEditor"); //$NON-NLS-1$ setBounds(5, 5, 350, 230); getContentPane().setLayout(new BorderLayout(0, 0)); { JPanel panelContent = new JPanel(); getContentPane().add(panelContent, BorderLayout.CENTER); panelContent.setLayout(new FormLayout(new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC, }, new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.RELATED_GAP_ROWSPEC, })); JLabel lblGenres = new JLabel(BUNDLE.getString("metatag.genre")); //$NON-NLS-1$ panelContent.add(lblGenres, "2, 2, 2, 1, right, default"); // cbGenres = new JComboBox(MediaGenres2.values()); cbGenres = new AutocompleteComboBox(MediaGenres.values()); cbGenres.setEditable(true); panelContent.add(cbGenres, "5, 2, fill, default"); JButton btnAddGenre = new JButton(""); btnAddGenre.setIcon(IconManager.LIST_ADD); btnAddGenre.setMargin(new Insets(2, 2, 2, 2)); btnAddGenre.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); MediaGenres genre = null; Object item = cbGenres.getSelectedItem(); // genre if (item instanceof MediaGenres) { genre = (MediaGenres) item; } // newly created genre? if (item instanceof String) { genre = MediaGenres.getGenre((String) item); } // MediaGenres2 genre = (MediaGenres2) cbGenres.getSelectedItem(); if (genre != null) { for (Movie movie : moviesToEdit) { movie.addGenre(genre); } } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnAddGenre, "7, 2"); JButton btnRemoveGenre = new JButton(""); btnRemoveGenre.setIcon(IconManager.LIST_REMOVE); btnRemoveGenre.setMargin(new Insets(2, 2, 2, 2)); btnRemoveGenre.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); MediaGenres genre = (MediaGenres) cbGenres.getSelectedItem(); for (Movie movie : moviesToEdit) { movie.removeGenre(genre); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnRemoveGenre, "9, 2"); JLabel lblTags = new JLabel(BUNDLE.getString("metatag.tags")); //$NON-NLS-1$ panelContent.add(lblTags, "2, 4, 2, 1, right, default"); cbTags = new AutocompleteComboBox(movieList.getTagsInMovies().toArray()); cbTags.setEditable(true); panelContent.add(cbTags, "5, 4, fill, default"); JButton btnAddTag = new JButton(""); btnAddTag.setIcon(IconManager.LIST_ADD); btnAddTag.setMargin(new Insets(2, 2, 2, 2)); btnAddTag.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); String tag = (String) cbTags.getSelectedItem(); if (StringUtils.isBlank(tag)) { return; } for (Movie movie : moviesToEdit) { movie.addToTags(tag); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnAddTag, "7, 4"); JButton btnRemoveTag = new JButton(""); btnRemoveTag.setIcon(IconManager.LIST_REMOVE); btnRemoveTag.setMargin(new Insets(2, 2, 2, 2)); btnRemoveTag.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); String tag = (String) cbTags.getSelectedItem(); for (Movie movie : moviesToEdit) { movie.removeFromTags(tag); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnRemoveTag, "9, 4"); JLabel lblCertification = new JLabel(BUNDLE.getString("metatag.certification")); //$NON-NLS-1$ panelContent.add(lblCertification, "2, 6, 2, 1, right, default"); final JComboBox cbCertification = new JComboBox(); for (Certification cert : Certification .getCertificationsforCountry(MovieModuleManager.MOVIE_SETTINGS.getCertificationCountry())) { cbCertification.addItem(cert); } panelContent.add(cbCertification, "5, 6, fill, default"); JButton btnCertification = new JButton(""); btnCertification.setMargin(new Insets(2, 2, 2, 2)); btnCertification.setIcon(IconManager.APPLY); btnCertification.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Certification cert = (Certification) cbCertification.getSelectedItem(); for (Movie movie : moviesToEdit) { movie.setCertification(cert); ; } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnCertification, "7, 6"); JLabel lblMovieSet = new JLabel(BUNDLE.getString("metatag.movieset")); //$NON-NLS-1$ panelContent.add(lblMovieSet, "2, 8, 2, 1, right, default"); cbMovieSet = new JComboBox(); panelContent.add(cbMovieSet, "5, 8, fill, default"); JButton btnSetMovieSet = new JButton(""); btnSetMovieSet.setMargin(new Insets(2, 2, 2, 2)); btnSetMovieSet.setIcon(IconManager.APPLY); btnSetMovieSet.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // movie set Object obj = cbMovieSet.getSelectedItem(); for (Movie movie : moviesToEdit) { if (obj instanceof String) { movie.removeFromMovieSet(); } if (obj instanceof MovieSet) { MovieSet movieSet = (MovieSet) obj; if (movie.getMovieSet() != movieSet) { movie.removeFromMovieSet(); movie.setMovieSet(movieSet); movieSet.insertMovie(movie); } } } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnSetMovieSet, "7, 8"); JButton btnNewMovieset = new JButton(""); btnNewMovieset.setMargin(new Insets(2, 2, 2, 2)); btnNewMovieset.setAction(new MovieSetAddAction(false)); panelContent.add(btnNewMovieset, "9, 8"); JLabel lblWatched = new JLabel(BUNDLE.getString("metatag.watched")); //$NON-NLS-1$ panelContent.add(lblWatched, "2, 10, 2, 1, right, default"); chckbxWatched = new JCheckBox(""); panelContent.add(chckbxWatched, "5, 10"); JButton btnWatched = new JButton(""); btnWatched.setMargin(new Insets(2, 2, 2, 2)); btnWatched.setIcon(IconManager.APPLY); btnWatched.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); for (Movie movie : moviesToEdit) { movie.setWatched(chckbxWatched.isSelected()); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnWatched, "7, 10"); JLabel lblVideo3D = new JLabel(BUNDLE.getString("metatag.3d")); //$NON-NLS-1$ panelContent.add(lblVideo3D, "2, 12, 2, 1, right, default"); final JCheckBox chckbxVideo3D = new JCheckBox(""); panelContent.add(chckbxVideo3D, "5, 12"); JButton btnVideo3D = new JButton(""); btnVideo3D.setMargin(new Insets(2, 2, 2, 2)); btnVideo3D.setIcon(IconManager.APPLY); btnVideo3D.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); for (Movie movie : moviesToEdit) { movie.setVideoIn3D(chckbxVideo3D.isSelected()); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnVideo3D, "7, 12"); JLabel lblMediasource = new JLabel(BUNDLE.getString("metatag.source")); //$NON-NLS-1$ panelContent.add(lblMediasource, "2, 14, 2, 1, right, default"); final JComboBox cbMediaSource = new JComboBox(MediaSource.values()); panelContent.add(cbMediaSource, "5, 14, fill, default"); JButton btnMediaSource = new JButton(""); btnMediaSource.setMargin(new Insets(2, 2, 2, 2)); btnMediaSource.setIcon(IconManager.APPLY); btnMediaSource.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; Object obj = cbMediaSource.getSelectedItem(); if (obj instanceof MediaSource) { MediaSource mediaSource = (MediaSource) obj; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); for (Movie movie : moviesToEdit) { movie.setMediaSource(mediaSource); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } } }); panelContent.add(btnMediaSource, "7, 14"); JLabel lblLanguage = new JLabel(BUNDLE.getString("metatag.language")); //$NON-NLS-1$ panelContent.add(lblLanguage, "2, 16, 2, 1, right, default"); tfLanguage = new JTextField(); panelContent.add(tfLanguage, "5, 16, fill, default"); tfLanguage.setColumns(10); JButton btnLanguage = new JButton(""); btnLanguage.setMargin(new Insets(2, 2, 2, 2)); btnLanguage.setIcon(IconManager.APPLY); btnLanguage.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); for (Movie movie : moviesToEdit) { movie.setSpokenLanguages(tfLanguage.getText()); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnLanguage, "7, 16"); { JLabel lblSorttitleT = new JLabel(BUNDLE.getString("metatag.sorttitle")); //$NON-NLS-1$ panelContent.add(lblSorttitleT, "2, 18, right, default"); JButton btnSetSorttitle = new JButton(BUNDLE.getString("edit.setsorttitle")); //$NON-NLS-1$ btnSetSorttitle.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); for (Movie movie : moviesToEdit) { movie.setSortTitle(movie.getTitleSortable()); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); JLabel lblSorttitleInfo = new JLabel(IconManager.HINT); lblSorttitleInfo.setToolTipText(BUNDLE.getString("edit.setsorttitle.desc")); //$NON-NLS-1$ panelContent.add(lblSorttitleInfo, "3, 18"); panelContent.add(btnSetSorttitle, "5, 18"); JButton btnClearSorttitle = new JButton(BUNDLE.getString("edit.clearsorttitle")); //$NON-NLS-1$ btnClearSorttitle.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { changed = true; setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); for (Movie movie : moviesToEdit) { movie.setSortTitle(""); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } }); panelContent.add(btnClearSorttitle, "5, 20"); } } { JPanel panelButtons = new JPanel(); FlowLayout flowLayout = (FlowLayout) panelButtons.getLayout(); flowLayout.setAlignment(FlowLayout.RIGHT); getContentPane().add(panelButtons, BorderLayout.SOUTH); JButton btnClose = new JButton(BUNDLE.getString("Button.close")); //$NON-NLS-1$ btnClose.setIcon(IconManager.APPLY); btnClose.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { // rewrite movies, if anything changed if (changed) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); for (Movie movie : moviesToEdit) { movie.writeNFO(); movie.saveToDb(); } setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } setVisible(false); } }); panelButtons.add(btnClose); // add window listener to write changes (if the window close button "X" is // pressed) addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // rewrite movies, if anything changed if (changed) { for (Movie movie : moviesToEdit) { movie.writeNFO(); movie.saveToDb(); } // if configured - sync with trakt.tv if (MovieModuleManager.MOVIE_SETTINGS.getSyncTrakt()) { TmmTask task = new SyncTraktTvTask(moviesToEdit, null); TmmTaskManager.getInstance().addUnnamedTask(task); } } } }); } { setMovieSets(); moviesToEdit = movies; PropertyChangeListener listener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if ("addedMovieSet".equals(evt.getPropertyName())) { setMovieSets(); } } }; movieList.addPropertyChangeListener(listener); } }
From source file:org.jaffa.flexfields.FlexBean.java
/** * Adds a default PropertyChangeListener to the listener list. */// www . j a v a 2s.co m private void addPropertyChangeListener() { addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { valueChanged(evt.getPropertyName(), evt.getOldValue()); if (log.isDebugEnabled()) log.debug("Field '" + evt.getPropertyName() + "' updated from '" + evt.getOldValue() + "' to '" + evt.getNewValue() + "'"); } }); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditorUI.java
/** * Removes the tags.//from w ww . j a va 2s .c o m * * @param src The mouse clicked location. * @param location The location of the mouse pressed. */ void removeTags(JComponent src, Point location) { if (!generalPane.hasTagsToUnlink()) return; if (model.isGroupLeader() || model.isAdministrator()) { if (tagMenu == null) { tagMenu = new PermissionMenu(PermissionMenu.REMOVE, "Tags"); tagMenu.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String n = evt.getPropertyName(); if (PermissionMenu.SELECTED_LEVEL_PROPERTY.equals(n)) { removeLinks((Integer) evt.getNewValue(), model.getAllTags()); } } }); } tagMenu.show(src, location.x, location.y); return; } SwingUtilities.convertPointToScreen(location, src); MessageBox box = new MessageBox(model.getRefFrame(), "Remove All Your Tags", "Are you sure you want to remove all your Tags?"); Dimension d = box.getPreferredSize(); Point p = new Point(location.x - d.width / 2, location.y); if (box.showMsgBox(p) == MessageBox.YES_OPTION) { List<TagAnnotationData> list = generalPane.removeTags(); if (list.size() > 0) saveData(true); } }
From source file:org.openmicroscopy.shoola.env.ui.ActivityComponent.java
/** * Downloads the passed object is supported. * /*from www .ja v a 2s . co m*/ * @param text The text used if the object is not loaded. * @param object The object to handle. * @param folder Indicates where to download the file or <code>null</code>. */ void download(String text, Object object, File folder) { if (!(object instanceof FileAnnotationData || object instanceof OriginalFile)) return; int index = -1; if (text == null) text = ""; String name = ""; String description = ""; long dataID = -1; OriginalFile of = null; if (object instanceof FileAnnotationData) { FileAnnotationData data = (FileAnnotationData) object; if (data.isLoaded()) { name = data.getFileName(); description = data.getDescription(); of = (OriginalFile) data.getContent(); } else { of = null; dataID = data.getId(); index = DownloadActivityParam.FILE_ANNOTATION; if (text.length() == 0) text = "Annotation"; name = text + "_" + dataID; } } else { of = (OriginalFile) object; if (!of.isLoaded()) { dataID = of.getId().getValue(); index = DownloadActivityParam.ORIGINAL_FILE; if (text.length() == 0) text = "File"; name = text + "_" + dataID; of = null; } } final OriginalFile original = of; final int type = index; final String desc = description; final long id = dataID; if (folder != null) { if (original == null && type == -1) return; DownloadActivityParam activity; IconManager icons = IconManager.getInstance(registry); if (original != null) { activity = new DownloadActivityParam(original, folder, icons.getIcon(IconManager.DOWNLOAD_22)); } else { activity = new DownloadActivityParam(id, type, folder, icons.getIcon(IconManager.DOWNLOAD_22)); } activity.setLegend(desc); activity.setUIRegister(false); viewer.notifyActivity(ctx, activity); return; } JFrame f = registry.getTaskBar().getFrame(); FileChooser chooser = new FileChooser(f, FileChooser.SAVE, "Download", "Select where to download the file.", null, true, true); IconManager icons = IconManager.getInstance(registry); chooser.setTitleIcon(icons.getIcon(IconManager.DOWNLOAD_48)); chooser.setSelectedFileFull(name); chooser.setApproveButtonText("Download"); chooser.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String name = evt.getPropertyName(); if (FileChooser.APPROVE_SELECTION_PROPERTY.equals(name)) { File[] files = (File[]) evt.getNewValue(); File folder = files[0]; if (original == null && type == -1) return; IconManager icons = IconManager.getInstance(registry); DownloadActivityParam activity; if (original != null) { activity = new DownloadActivityParam(original, folder, icons.getIcon(IconManager.DOWNLOAD_22)); } else { activity = new DownloadActivityParam(id, type, folder, icons.getIcon(IconManager.DOWNLOAD_22)); } activity.setLegend(desc); viewer.notifyActivity(ctx, activity); } } }); chooser.centerDialog(); }
From source file:de.bfs.radon.omsimulation.gui.OMPanelData.java
/** * Initialises the interface of the data panel. *//*from w w w . ja v a2 s . com*/ protected void initialize() { setLayout(null); lblExportChartTo = new JLabel("Export chart to ..."); lblExportChartTo.setBounds(436, 479, 144, 14); lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblExportChartTo.setVisible(false); add(lblExportChartTo); btnCsv = new JButton("CSV"); btnCsv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String csv; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("csv")) { csv = ""; } else { csv = ".csv"; } String csvPath = file.getAbsolutePath() + csv; OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem(); double[] selectedValues = selectedRoom.getValues(); File csvFile = new File(csvPath); try { FileWriter logWriter = new FileWriter(csvFile); BufferedWriter csvOutput = new BufferedWriter(logWriter); csvOutput.write("\"ID\";\"" + selectedRoom.getId() + "\""); csvOutput.newLine(); for (int i = 0; i < selectedValues.length; i++) { csvOutput.write("\"" + i + "\";\"" + (int) selectedValues[i] + "\""); csvOutput.newLine(); } JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success", JOptionPane.INFORMATION_MESSAGE); csvOutput.close(); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnCsv.setBounds(590, 475, 70, 23); btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnCsv.setVisible(false); add(btnCsv); btnPdf = new JButton("PDF"); btnPdf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String pdf; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("pdf")) { pdf = ""; } else { pdf = ".pdf"; } String pdfPath = file.getAbsolutePath() + pdf; OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); String title = building.getName(); OMRoom selectedRoom = (OMRoom) comboBoxRooms.getSelectedItem(); JFreeChart chart = OMCharts.createRoomChart(title, selectedRoom, false); int height = (int) PageSize.A4.getWidth(); int width = (int) PageSize.A4.getHeight(); try { OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title); JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnPdf.setBounds(670, 475, 70, 23); btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnPdf.setVisible(false); add(btnPdf); lblSelectProject = new JLabel("Select Project"); lblSelectProject.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectProject.setBounds(10, 65, 132, 14); add(lblSelectProject); lblSelectRoom = new JLabel("Select Room"); lblSelectRoom.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectRoom.setBounds(10, 94, 132, 14); add(lblSelectRoom); panelData = new JPanel(); panelData.setBounds(10, 118, 730, 347); add(panelData); btnRefresh = new JButton("Load"); btnRefresh.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (txtOmbFile.getText() != null && !txtOmbFile.getText().equals("") && !txtOmbFile.getText().equals(" ")) { txtOmbFile.setBackground(Color.WHITE); String ombPath = txtOmbFile.getText(); String omb; String[] tmpFileName = ombPath.split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(ombPath + omb); setOmbFile(ombPath + omb); File ombFile = new File(ombPath + omb); if (ombFile.exists()) { txtOmbFile.setBackground(Color.WHITE); btnRefresh.setEnabled(false); comboBoxProjects.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); btnPdf.setVisible(false); btnCsv.setVisible(false); lblExportChartTo.setVisible(false); progressBar.setVisible(true); progressBar.setStringPainted(true); progressBar.setIndeterminate(true); refreshProjectsTask = new RefreshProjects(); refreshProjectsTask.execute(); } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "OMB-file not found, please check the file path!", "Error", JOptionPane.ERROR_MESSAGE); } } else { txtOmbFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "Please select an OMB-file!", "Warning", JOptionPane.WARNING_MESSAGE); } } }); btnRefresh.setBounds(616, 61, 124, 23); add(btnRefresh); btnMaximize = new JButton("Fullscreen"); btnMaximize.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnMaximize.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (comboBoxRooms.isEnabled()) { if (comboBoxRooms.getSelectedItem() != null) { OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); String title = building.getName(); OMRoom room = (OMRoom) comboBoxRooms.getSelectedItem(); panelRoom = createRoomPanel(title, room, false, false); JFrame chartFrame = new JFrame(); JPanel chartPanel = createRoomPanel(title, room, false, true); chartFrame.getContentPane().add(chartPanel); chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight()); chartFrame.setTitle("OM Simulation Tool: " + title + ", Room " + room.getId()); chartFrame.setResizable(true); chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); chartFrame.setVisible(true); } } } }); btnMaximize.setBounds(10, 475, 124, 23); btnMaximize.setVisible(false); add(btnMaximize); comboBoxProjects = new JComboBox<OMBuilding>(); comboBoxProjects.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); comboBoxProjects.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { boolean b = false; Color c = null; if (comboBoxProjects.isEnabled()) { if (comboBoxProjects.getSelectedItem() != null) { b = true; c = Color.WHITE; OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); comboBoxRooms.removeAllItems(); for (int i = 0; i < building.getRooms().length; i++) { comboBoxRooms.addItem(building.getRooms()[i]); } for (int i = 0; i < building.getCellars().length; i++) { comboBoxRooms.addItem(building.getCellars()[i]); } for (int i = 0; i < building.getMiscs().length; i++) { comboBoxRooms.addItem(building.getMiscs()[i]); } } else { b = false; c = null; } } else { b = false; c = null; } lblSelectRoom.setEnabled(b); panelData.setEnabled(b); btnMaximize.setVisible(b); comboBoxRooms.setEnabled(b); panelData.setBackground(c); } }); comboBoxProjects.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { boolean b = false; Color c = null; if (comboBoxProjects.isEnabled()) { if (comboBoxProjects.getSelectedItem() != null) { b = true; c = Color.WHITE; OMBuilding building = (OMBuilding) comboBoxProjects.getSelectedItem(); comboBoxRooms.removeAllItems(); for (int i = 0; i < building.getRooms().length; i++) { comboBoxRooms.addItem(building.getRooms()[i]); } for (int i = 0; i < building.getCellars().length; i++) { comboBoxRooms.addItem(building.getCellars()[i]); } for (int i = 0; i < building.getMiscs().length; i++) { comboBoxRooms.addItem(building.getMiscs()[i]); } } else { b = false; c = null; } } else { b = false; c = null; } lblSelectRoom.setEnabled(b); panelData.setEnabled(b); btnMaximize.setVisible(b); comboBoxRooms.setEnabled(b); panelData.setBackground(c); } }); comboBoxProjects.setBounds(152, 61, 454, 22); add(comboBoxProjects); comboBoxRooms = new JComboBox<OMRoom>(); comboBoxRooms.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); comboBoxRooms.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (comboBoxRooms.isEnabled()) { if (comboBoxRooms.getSelectedItem() != null) { setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); remove(panelData); comboBoxRooms.setEnabled(false); refreshChartsTask = new RefreshCharts(); refreshChartsTask.execute(); } } } }); comboBoxRooms.setBounds(152, 90, 454, 22); add(comboBoxRooms); progressBar = new JProgressBar(); progressBar.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); progressBar.setBounds(10, 475, 730, 23); progressBar.setVisible(false); add(progressBar); lblSelectRoom.setEnabled(false); panelData.setEnabled(false); comboBoxRooms.setEnabled(false); lblHelp = new JLabel( "Select an OMB-Object file to analyse its data. You can inspect radon concentration for each room."); lblHelp.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblHelp.setForeground(Color.GRAY); lblHelp.setBounds(10, 10, 730, 14); add(lblHelp); txtOmbFile = new JTextField(); txtOmbFile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); txtOmbFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent arg0) { setOmbFile(txtOmbFile.getText()); } }); txtOmbFile.setBounds(152, 33, 454, 20); add(txtOmbFile); txtOmbFile.setColumns(10); btnBrowse = new JButton("Browse"); btnBrowse.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.omb", "omb")); fileDialog.showOpenDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String omb; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("omb")) { omb = ""; } else { omb = ".omb"; } txtOmbFile.setText(file.getAbsolutePath() + omb); setOmbFile(file.getAbsolutePath() + omb); } } }); btnBrowse.setBounds(616, 32, 124, 23); add(btnBrowse); lblSelectOmbfile = new JLabel("Select OMB-File"); lblSelectOmbfile.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblSelectOmbfile.setBounds(10, 36, 132, 14); add(lblSelectOmbfile); }