use of java.beans.PropertyChangeListener in project jdk8u_jdk by JetBrains.
the class JOptionPane method createInternalFrame.
/**
* Creates and returns an instance of <code>JInternalFrame</code>.
* The internal frame is created with the specified title,
* and wrapping the <code>JOptionPane</code>.
* The returned <code>JInternalFrame</code> is
* added to the <code>JDesktopPane</code> ancestor of
* <code>parentComponent</code>, or components
* parent if one its ancestors isn't a <code>JDesktopPane</code>,
* or if <code>parentComponent</code>
* doesn't have a parent then a <code>RuntimeException</code> is thrown.
*
* @param parentComponent the parent <code>Component</code> for
* the internal frame
* @param title the <code>String</code> to display in the
* frame's title bar
* @return a <code>JInternalFrame</code> containing a
* <code>JOptionPane</code>
* @exception RuntimeException if <code>parentComponent</code> does
* not have a valid parent
*/
public JInternalFrame createInternalFrame(Component parentComponent, String title) {
Container parent = JOptionPane.getDesktopPaneForComponent(parentComponent);
if (parent == null && (parentComponent == null || (parent = parentComponent.getParent()) == null)) {
throw new RuntimeException("JOptionPane: parentComponent does " + "not have a valid parent");
}
// Option dialogs should be closable only
final JInternalFrame iFrame = new JInternalFrame(title, false, true, false, false);
iFrame.putClientProperty("JInternalFrame.frameType", "optionDialog");
iFrame.putClientProperty("JInternalFrame.messageType", Integer.valueOf(getMessageType()));
iFrame.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosing(InternalFrameEvent e) {
if (getValue() == UNINITIALIZED_VALUE) {
setValue(null);
}
}
});
addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
// (newValue = null in that case). Otherwise, close the dialog.
if (iFrame.isVisible() && event.getSource() == JOptionPane.this && event.getPropertyName().equals(VALUE_PROPERTY)) {
// Use reflection to get Container.stopLWModal().
try {
Method method = AccessController.doPrivileged(new ModalPrivilegedAction(Container.class, "stopLWModal"));
if (method != null) {
method.invoke(iFrame, (Object[]) null);
}
} catch (IllegalAccessException ex) {
} catch (IllegalArgumentException ex) {
} catch (InvocationTargetException ex) {
}
try {
iFrame.setClosed(true);
} catch (java.beans.PropertyVetoException e) {
}
iFrame.setVisible(false);
}
}
});
iFrame.getContentPane().add(this, BorderLayout.CENTER);
if (parent instanceof JDesktopPane) {
parent.add(iFrame, JLayeredPane.MODAL_LAYER);
} else {
parent.add(iFrame, BorderLayout.CENTER);
}
Dimension iFrameSize = iFrame.getPreferredSize();
Dimension rootSize = parent.getSize();
Dimension parentSize = parentComponent.getSize();
iFrame.setBounds((rootSize.width - iFrameSize.width) / 2, (rootSize.height - iFrameSize.height) / 2, iFrameSize.width, iFrameSize.height);
// We want dialog centered relative to its parent component
Point iFrameCoord = SwingUtilities.convertPoint(parentComponent, 0, 0, parent);
int x = (parentSize.width - iFrameSize.width) / 2 + iFrameCoord.x;
int y = (parentSize.height - iFrameSize.height) / 2 + iFrameCoord.y;
// If possible, dialog should be fully visible
int ovrx = x + iFrameSize.width - rootSize.width;
int ovry = y + iFrameSize.height - rootSize.height;
x = Math.max((ovrx > 0 ? x - ovrx : x), 0);
y = Math.max((ovry > 0 ? y - ovry : y), 0);
iFrame.setBounds(x, y, iFrameSize.width, iFrameSize.height);
parent.validate();
try {
iFrame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {
}
return iFrame;
}
use of java.beans.PropertyChangeListener in project jdk8u_jdk by JetBrains.
the class JOptionPane method initDialog.
private void initDialog(final JDialog dialog, int style, Component parentComponent) {
dialog.setComponentOrientation(this.getComponentOrientation());
Container contentPane = dialog.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(this, BorderLayout.CENTER);
dialog.setResizable(false);
if (JDialog.isDefaultLookAndFeelDecorated()) {
boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
if (supportsWindowDecorations) {
dialog.setUndecorated(true);
getRootPane().setWindowDecorationStyle(style);
}
}
dialog.pack();
dialog.setLocationRelativeTo(parentComponent);
final PropertyChangeListener listener = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent event) {
// (newValue = null in that case). Otherwise, close the dialog.
if (dialog.isVisible() && event.getSource() == JOptionPane.this && (event.getPropertyName().equals(VALUE_PROPERTY)) && event.getNewValue() != null && event.getNewValue() != JOptionPane.UNINITIALIZED_VALUE) {
dialog.setVisible(false);
}
}
};
WindowAdapter adapter = new WindowAdapter() {
private boolean gotFocus = false;
public void windowClosing(WindowEvent we) {
setValue(null);
}
public void windowClosed(WindowEvent e) {
removePropertyChangeListener(listener);
dialog.getContentPane().removeAll();
}
public void windowGainedFocus(WindowEvent we) {
// Once window gets focus, set initial focus
if (!gotFocus) {
selectInitialValue();
gotFocus = true;
}
}
};
dialog.addWindowListener(adapter);
dialog.addWindowFocusListener(adapter);
dialog.addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent ce) {
// reset value to ensure closing works properly
setValue(JOptionPane.UNINITIALIZED_VALUE);
}
});
addPropertyChangeListener(listener);
}
use of java.beans.PropertyChangeListener in project jdk8u_jdk by JetBrains.
the class BasicLookAndFeel method installAWTEventListener.
void installAWTEventListener() {
if (invocator == null) {
invocator = new AWTEventHelper();
needsEventHelper = true;
// Add a PropertyChangeListener to our AppContext so we're alerted
// when the AppContext is disposed(), at which time this laf should
// be uninitialize()d.
disposer = new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent prpChg) {
uninitialize();
}
};
AppContext.getAppContext().addPropertyChangeListener(AppContext.GUI_DISPOSED, disposer);
}
}
use of java.beans.PropertyChangeListener in project jdk8u_jdk by JetBrains.
the class EnumEditor method setValue.
public void setValue(Object value) {
if ((value != null) && !this.type.isInstance(value)) {
throw new IllegalArgumentException("Unsupported value: " + value);
}
Object oldValue;
PropertyChangeListener[] listeners;
synchronized (this.listeners) {
oldValue = this.value;
this.value = value;
if ((value == null) ? oldValue == null : value.equals(oldValue)) {
// do not fire event if value is not changed
return;
}
int size = this.listeners.size();
if (size == 0) {
// do not fire event if there are no any listener
return;
}
listeners = this.listeners.toArray(new PropertyChangeListener[size]);
}
PropertyChangeEvent event = new PropertyChangeEvent(this, null, oldValue, value);
for (PropertyChangeListener listener : listeners) {
listener.propertyChange(event);
}
}
use of java.beans.PropertyChangeListener in project intellij-plugins by JetBrains.
the class JstdServerSettingsTab method listenForChanges.
private void listenForChanges() {
myPortField.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
update();
}
});
myBrowserTimeoutSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
update();
}
});
myRunnerModeComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
update();
}
});
}
Aggregations