List of usage examples for java.beans PropertyChangeListener PropertyChangeListener
PropertyChangeListener
From source file:org.formic.wizard.step.gui.FeatureListStep.java
/** * {@inheritDoc}//w w w .jav a2 s .c o m * @see org.formic.wizard.step.GuiStep#init() */ public Component init() { featureInfo = new JEditorPane("text/html", StringUtils.EMPTY); featureInfo.setEditable(false); featureInfo.addHyperlinkListener(new HyperlinkListener()); Feature[] features = provider.getFeatures(); JTable table = new JTable(features.length, 1) { private static final long serialVersionUID = 1L; public Class getColumnClass(int column) { return getValueAt(0, column).getClass(); } public boolean isCellEditable(int row, int column) { return false; } }; table.setBackground(new javax.swing.JList().getBackground()); GuiForm form = createForm(); for (int ii = 0; ii < features.length; ii++) { final Feature feature = (Feature) features[ii]; final JCheckBox box = new JCheckBox(); String name = getName() + '.' + feature.getKey(); form.bind(name, box); box.putClientProperty("feature", feature); featureMap.put(feature.getKey(), box); if (feature.getInfo() == null) { feature.setInfo(Installer.getString(getName() + "." + feature.getKey() + ".html")); } feature.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (Feature.ENABLED_PROPERTY.equals(event.getPropertyName())) { if (box.isSelected() != feature.isEnabled()) { box.setSelected(feature.isEnabled()); } } } }); box.setText(Installer.getString(name)); box.setBackground(table.getBackground()); if (!feature.isAvailable()) { box.setSelected(false); box.setEnabled(false); } table.setValueAt(box, ii, 0); } FeatureListMouseListener mouseListener = new FeatureListMouseListener(); for (int ii = 0; ii < features.length; ii++) { Feature feature = (Feature) features[ii]; if (feature.isEnabled() && feature.isAvailable()) { JCheckBox box = (JCheckBox) featureMap.get(feature.getKey()); box.setSelected(true); mouseListener.processDependencies(feature); mouseListener.processExclusives(feature); } } table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.setDefaultRenderer(JCheckBox.class, new ComponentTableCellRenderer()); table.addKeyListener(new FeatureListKeyListener()); table.addMouseListener(mouseListener); table.getSelectionModel().addListSelectionListener(new FeatureListSelectionListener(table)); table.setRowSelectionInterval(0, 0); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JPanel container = new JPanel(new BorderLayout()); container.add(table, BorderLayout.CENTER); panel.add(new JScrollPane(container), BorderLayout.CENTER); JScrollPane infoScroll = new JScrollPane(featureInfo); infoScroll.setMinimumSize(new Dimension(0, 50)); infoScroll.setMaximumSize(new Dimension(0, 50)); infoScroll.setPreferredSize(new Dimension(0, 50)); panel.add(infoScroll, BorderLayout.SOUTH); return panel; }
From source file:com.vmware.vfabric.ide.eclipse.tcserver.internal.ui.ExtendedTcStaticResourcesEditorSection.java
protected void addConfigurationChangeListener() { listener = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (TcServer.PROPERTY_ENHANCED_REDEPLOY.equals(event.getPropertyName())) { updateEnablement();/*from w w w . j a va2 s . c om*/ } else if (TcServer.PROPERTY_AGENT_REDEPLOY.equals(event.getPropertyName())) { updateEnablement(); } else if (TcServer.PROPERTY_STATIC_FILENAMES.equals(event.getPropertyName())) { filenamesTableViewer.setInput(server); } else if (TcServer.PROPERTY_AGENT_OPTIONS.equals(event.getPropertyName())) { if (!updating) { updating = true; agentOptionsText.setText(serverWorkingCopy.getAgentOptions()); agentOptionsText.setSelection(agentOptionsText.getText().length()); updating = false; } } } }; serverWorkingCopy.getServerWorkingCopy().addPropertyChangeListener(listener); }
From source file:ui.panel.UIAccessKeySelect.java
public void runaccessKeySelect() { getAccessKeyData();/*w w w .ja v a 2s . c o m*/ Panel p = new Panel(); Button b = new Button(); Label l = new Label(); setLayout(new BorderLayout()); JPanel pnlInstruction = p.createPanel(Layouts.flow); JLabel lblInstruction = l.createLabel("Access Keys"); pnlInstruction.setBackground(CustomColor.LightBlue.returnColor()); lblInstruction.setForeground(Color.white); lblInstruction.setFont(new Font("San Serif", Font.PLAIN, 18)); pnlInstruction.add(lblInstruction); JPanel pnlBucketList = p.createPanel(Layouts.border); listBucket.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scrollBucket = new JScrollPane(listBucket); Component[] BucketListComponents = { scrollBucket }; pnlBucketList.add(scrollBucket, BorderLayout.CENTER); JPanel pnlButtons = p.createPanel(Layouts.flow); JButton btnBack = b.createButton("Back"); JButton btnSelectElements = b.createButton("Next"); JButton btnAdd = b.createButton("Generate Access Key"); JButton btnRefresh = b.createButton("Refresh"); pnlButtons.add(btnBack); pnlButtons.add(btnAdd); pnlButtons.add(btnRefresh); pnlButtons.add(btnSelectElements); add(pnlInstruction, BorderLayout.NORTH); add(pnlBucketList, BorderLayout.CENTER); add(pnlButtons, BorderLayout.SOUTH); btnBack.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.showPanel("license"); } }); btnRefresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getAccessKeyData(); } }); btnAdd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Data.mainFrame.uiGenerateKey = new UIGenerateKey(); Data.mainFrame.addPanel(Data.mainFrame.uiGenerateKey, "generateKey"); Data.mainFrame.pack(); Data.mainFrame.showPanel("generateKey"); } }); btnSelectElements.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingWorker<Void, Void> mySwingWorker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { int selected = listBucket.getSelectedRow(); if (selected != -1) { Data.accessKey = (String) listBucket.getModel().getValueAt(selected, 0); Data.mainFrame.qrGenerator = new JavaQR(); Data.mainFrame.pack(); Data.mainFrame.addPanel(Data.mainFrame.qrGenerator, "generateQR"); Data.mainFrame.showPanel("generateQR"); } else { JOptionPane.showMessageDialog(Data.mainFrame, "Please Select Access Key", "Error", JOptionPane.ERROR_MESSAGE); } return null; } }; Window win = SwingUtilities.getWindowAncestor((AbstractButton) e.getSource()); final JDialog dialog = new JDialog(win, "Loading", ModalityType.APPLICATION_MODAL); mySwingWorker.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("state")) { if (evt.getNewValue() == SwingWorker.StateValue.DONE) { dialog.dispose(); } } } }); mySwingWorker.execute(); JProgressBar progressBar = new JProgressBar(); progressBar.setIndeterminate(true); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Generating QR Code......."), BorderLayout.PAGE_START); dialog.add(panel); dialog.pack(); dialog.setBounds(50, 50, 300, 100); dialog.setLocationRelativeTo(Data.mainFrame); dialog.setVisible(true); } }); }
From source file:EditorPaneExample6.java
public EditorPaneExample6() { super("JEditorPane Example 6"); pane = new JEditorPane(); pane.setEditable(false); // Start read-only getContentPane().add(new JScrollPane(pane), "Center"); // Build the panel of controls JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridwidth = 1;/* w w w .ja va 2 s . c o m*/ c.gridheight = 1; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; JLabel urlLabel = new JLabel("File name: ", JLabel.RIGHT); panel.add(urlLabel, c); JLabel loadingLabel = new JLabel("State: ", JLabel.RIGHT); c.gridy = 1; panel.add(loadingLabel, c); JLabel typeLabel = new JLabel("Type: ", JLabel.RIGHT); c.gridy = 2; panel.add(typeLabel, c); c.gridx = 1; c.gridy = 0; c.gridwidth = 1; c.weightx = 1.0; c.fill = GridBagConstraints.HORIZONTAL; textField = new JTextField(32); panel.add(textField, c); loadingState = new JLabel(spaces, JLabel.LEFT); loadingState.setForeground(Color.black); c.gridy = 1; c.gridwidth = 2; panel.add(loadingState, c); loadedType = new JLabel(spaces, JLabel.LEFT); loadedType.setForeground(Color.black); c.gridy = 2; panel.add(loadedType, c); // Add a "Save" button saveButton = new JButton("Save"); saveButton.setEnabled(false); c.gridwidth = 1; c.gridx = 2; c.gridy = 0; c.weightx = 0.0; panel.add(saveButton, c); getContentPane().add(panel, "South"); // Change page based on text field textField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String fileName = textField.getText().trim(); file = new File(fileName); absolutePath = file.getAbsolutePath(); String url = "file:///" + absolutePath; try { // Check if the new page and the old // page are the same. URL newURL = new URL(url); URL loadedURL = pane.getPage(); if (loadedURL != null && loadedURL.sameFile(newURL)) { return; } // Try to display the page textField.setEnabled(false); // Disable input textField.paintImmediately(0, 0, textField.getSize().width, textField.getSize().height); saveButton.setEnabled(false); saveButton.paintImmediately(0, 0, saveButton.getSize().width, saveButton.getSize().height); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // Busy cursor loadingState.setText("Loading..."); loadingState.paintImmediately(0, 0, loadingState.getSize().width, loadingState.getSize().height); loadedType.setText(""); loadedType.paintImmediately(0, 0, loadedType.getSize().width, loadedType.getSize().height); pane.setEditable(false); pane.setPage(url); loadedType.setText(pane.getContentType()); } catch (Exception e) { JOptionPane.showMessageDialog(pane, new String[] { "Unable to open file", url }, "File Open Error", JOptionPane.ERROR_MESSAGE); loadingState.setText("Failed"); textField.setEnabled(true); setCursor(Cursor.getDefaultCursor()); } } }); // Listen for page load to complete pane.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (evt.getPropertyName().equals("page")) { loadingState.setText("Page loaded."); textField.setEnabled(true); // Allow entry of new file name textField.requestFocus(); setCursor(Cursor.getDefaultCursor()); // Allow editing and saving if appropriate pane.setEditable(file.canWrite()); saveButton.setEnabled(file.canWrite()); } } }); // Save button saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { try { String type = pane.getContentType(); OutputStream os = new BufferedOutputStream(new FileOutputStream(file + ".save")); pane.setEditable(false); textField.setEnabled(false); saveButton.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); Document doc = pane.getDocument(); int length = doc.getLength(); if (type.endsWith("/rtf")) { // Saving RTF - use the OutputStream try { pane.getEditorKit().write(os, doc, 0, length); os.close(); } catch (BadLocationException ex) { } } else { // Not RTF - use a Writer. Writer w = new OutputStreamWriter(os); pane.write(w); w.close(); } } catch (IOException e) { JOptionPane.showMessageDialog(pane, new String[] { "Unable to save file", file.getAbsolutePath(), }, "File Save Error", JOptionPane.ERROR_MESSAGE); } pane.setEditable(file.canWrite()); textField.setEnabled(true); saveButton.setEnabled(file.canWrite()); setCursor(Cursor.getDefaultCursor()); } }); }
From source file:org.pentaho.reporting.libraries.designtime.swing.date.DateCellEditor.java
private void init() { if (dateChooserPanel == null) { dateChooserPanel = new DateChooserPanel(Calendar.getInstance(), true); dateChooserPanel.addPropertyChangeListener(DateChooserPanel.PROPERTY_DATE, new InternalDateUpdateHandler()); dateField.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { Date newValue = (Date) evt.getNewValue(); newValue = newValue == null ? null : DateConverter.convertToDateType(newValue, dateType); dateChooserPanel.setDate(newValue, false); dateChooserPanel.setDateSelected(true); }/*from ww w.j av a 2s . co m*/ }); dateField.addFocusListener(new FocusAdapter() { public void focusGained(final FocusEvent e) { dateChooserPanel.setDateSelected(false); } }); if (dateField.getFormatterFactory() == null) { setDateFormat(createDateFormat(DEFAULT_FORMAT, Locale.getDefault(), TimeZone.getDefault())); } } }
From source file:org.objectstyle.cayenne.modeler.pref.ComponentGeometry.java
/** * Binds this preference object to synchronize its state with a given component * property./* w w w .ja va 2s .c o m*/ */ public void bindIntProperty(final Component component, final String property, int defaultValue) { updateIntProperty(component, property, defaultValue); component.addPropertyChangeListener(property, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { Object value = e.getNewValue(); setProperty(property, value != null ? value.toString() : null); } }); }
From source file:com.anrisoftware.mongoose.environment.EnvironmentImpl.java
private void setupLocaleHooks(LocaleHooks localeHooks) { localeHooks.addPropertyChangeListener(DISPLAY_LOCALE_PROPERTY, new PropertyChangeListener() { @Override//from www .j a va2s. c om public void propertyChange(PropertyChangeEvent evt) { setLocale((Locale) evt.getNewValue()); } }); localeHooks.hookDefaultLocale(); }
From source file:org.tinymediamanager.core.movie.MovieList.java
/** * Instantiates a new movie list.//from w ww. j a v a 2 s . c o m */ private MovieList() { // create all lists tagsObservable = ObservableCollections.observableList(new CopyOnWriteArrayList<String>()); videoCodecsObservable = ObservableCollections.observableList(new CopyOnWriteArrayList<String>()); audioCodecsObservable = ObservableCollections.observableList(new CopyOnWriteArrayList<String>()); certificationsObservable = ObservableCollections.observableList(new CopyOnWriteArrayList<Certification>()); // the tag listener: its used to always have a full list of all tags used in tmm tagListener = new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { // listen to changes of tags if ("tag".equals(evt.getPropertyName())) { Movie movie = (Movie) evt.getSource(); updateTags(movie); } if (MEDIA_FILES.equals(evt.getPropertyName()) || MEDIA_INFORMATION.equals(evt.getPropertyName())) { Movie movie = (Movie) evt.getSource(); updateMediaInformationLists(movie); } if (CERTIFICATION.equals(evt.getPropertyName())) { Movie movie = (Movie) evt.getSource(); updateCertifications(movie); } } }; movieSettings = MovieModuleManager.MOVIE_SETTINGS; }
From source file:FileChooserTest.java
/** * Constructs an ImagePreviewer./* w ww . j a v a2s . co m*/ * @param chooser the file chooser whose property changes trigger an image change in this * previewer */ public ImagePreviewer(JFileChooser chooser) { setPreferredSize(new Dimension(100, 100)); setBorder(BorderFactory.createEtchedBorder()); chooser.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getPropertyName() == JFileChooser.SELECTED_FILE_CHANGED_PROPERTY) { // the user has selected a new file File f = (File) event.getNewValue(); if (f == null) { setIcon(null); return; } // read the image into an icon ImageIcon icon = new ImageIcon(f.getPath()); // if the icon is too large to fit, scale it if (icon.getIconWidth() > getWidth()) icon = new ImageIcon( icon.getImage().getScaledInstance(getWidth(), -1, Image.SCALE_DEFAULT)); setIcon(icon); } } }); }
From source file:com.mightypocket.ashot.Mediator.java
private void installListeners() { demon.addTaskListener(new Adapter<Void, ImageEx>() { @Override/* w w w . j a v a2 s.c om*/ public void process(TaskEvent<List<ImageEx>> event) { List<ImageEx> value = event.getValue(); if (!value.isEmpty()) { final ImageEx img = value.get(0); updateImageProcessor(img); final Image imgp = imageProcessor.process(img.getValue()); showImage(imgp); if (isRecording() && !(p.getBoolean(PREF_SAVE_SKIP_DUPLICATES, true) && img.isDuplicate())) { imageSaver.saveImage((saveOriginal) ? img.getValue() : imgp); } lastImage = img; } else { showImage(generateDummyImage()); } } }); addPropertyChangeListener(PROP_CONNECTED_DEVICE, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { final JRadioButtonMenuItem disconnected = devices.get((String) evt.getOldValue()); final JRadioButtonMenuItem connected = devices.get((String) evt.getNewValue()); if (disconnected != null) { disconnected.setSelected(false); } if (connected != null) { connected.setSelected(true); } else { devicesGroup.clearSelection(); } } }); addPropertyChangeListener(PROP_FULL_SCREEN, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { logger.debug("Full screen: {}", evt.getNewValue()); boolean fs = (Boolean) evt.getNewValue(); presenter = fs ? fullScreenFrame.getPresenter() : mainPanel.getPresenter(); } }); }