use of javax.swing.event.InternalFrameEvent in project jdk8u_jdk by JetBrains.
the class JInternalFrame method fireInternalFrameEvent.
// remind: name ok? all one method ok? need to be synchronized?
/**
* Fires an internal frame event.
*
* @param id the type of the event being fired; one of the following:
* <ul>
* <li><code>InternalFrameEvent.INTERNAL_FRAME_OPENED</code>
* <li><code>InternalFrameEvent.INTERNAL_FRAME_CLOSING</code>
* <li><code>InternalFrameEvent.INTERNAL_FRAME_CLOSED</code>
* <li><code>InternalFrameEvent.INTERNAL_FRAME_ICONIFIED</code>
* <li><code>InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED</code>
* <li><code>InternalFrameEvent.INTERNAL_FRAME_ACTIVATED</code>
* <li><code>InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED</code>
* </ul>
* If the event type is not one of the above, nothing happens.
*/
protected void fireInternalFrameEvent(int id) {
Object[] listeners = listenerList.getListenerList();
InternalFrameEvent e = null;
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == InternalFrameListener.class) {
if (e == null) {
e = new InternalFrameEvent(this, id);
// System.out.println("InternalFrameEvent: " + e.paramString());
}
switch(e.getID()) {
case InternalFrameEvent.INTERNAL_FRAME_OPENED:
((InternalFrameListener) listeners[i + 1]).internalFrameOpened(e);
break;
case InternalFrameEvent.INTERNAL_FRAME_CLOSING:
((InternalFrameListener) listeners[i + 1]).internalFrameClosing(e);
break;
case InternalFrameEvent.INTERNAL_FRAME_CLOSED:
((InternalFrameListener) listeners[i + 1]).internalFrameClosed(e);
break;
case InternalFrameEvent.INTERNAL_FRAME_ICONIFIED:
((InternalFrameListener) listeners[i + 1]).internalFrameIconified(e);
break;
case InternalFrameEvent.INTERNAL_FRAME_DEICONIFIED:
((InternalFrameListener) listeners[i + 1]).internalFrameDeiconified(e);
break;
case InternalFrameEvent.INTERNAL_FRAME_ACTIVATED:
((InternalFrameListener) listeners[i + 1]).internalFrameActivated(e);
break;
case InternalFrameEvent.INTERNAL_FRAME_DEACTIVATED:
((InternalFrameListener) listeners[i + 1]).internalFrameDeactivated(e);
break;
default:
break;
}
}
}
/* we could do it off the event, but at the moment, that's not how
I'm implementing it */
// if (id == InternalFrameEvent.INTERNAL_FRAME_CLOSING) {
// doDefaultCloseAction();
// }
}
use of javax.swing.event.InternalFrameEvent 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 javax.swing.event.InternalFrameEvent in project drools by kiegroup.
the class AdventureFrame method handleRequestGive.
// public void receiveMessage(List cmd) {
// Performative p = null;
//
// switch ( p ) {
// case REQUEST :
// //Performatives r = ( Performatives ) p ;
// }
// }
public void handleRequestGive() {
final JOptionPane pane = new JOptionPane("xxx msg");
pane.setWantsInput(true);
pane.setInputValue("");
pane.setOptions(new String[] { "Yes", "No" });
JInternalFrame internalFrame = pane.createInternalFrame(contentPane, "xxx title");
internalFrame.setVisible(true);
pane.show();
internalFrame.addInternalFrameListener(new InternalFrameListener() {
public void internalFrameOpened(InternalFrameEvent e) {
}
public void internalFrameIconified(InternalFrameEvent e) {
}
public void internalFrameDeiconified(InternalFrameEvent e) {
}
public void internalFrameDeactivated(InternalFrameEvent e) {
}
public void internalFrameClosing(InternalFrameEvent e) {
}
public void internalFrameClosed(InternalFrameEvent e) {
System.out.println(pane.getInputValue() + ":" + pane.getValue());
}
public void internalFrameActivated(InternalFrameEvent e) {
}
});
}
use of javax.swing.event.InternalFrameEvent in project tetrad by cmu-phil.
the class SemGraphEditor method createGraphMenu.
private JMenu createGraphMenu() {
JMenu graph = new JMenu("Graph");
graph.add(new GraphPropertiesAction(getWorkbench()));
graph.add(new PathsAction(getWorkbench()));
// graph.add(new DirectedPathsAction(getWorkbench()));
// graph.add(new TreksAction(getWorkbench()));
// graph.add(new AllPathsAction(getWorkbench()));
// graph.add(new NeighborhoodsAction(getWorkbench()));
graph.addSeparator();
errorTerms = new JMenuItem();
if (getSemGraph().isShowErrorTerms()) {
errorTerms.setText("Hide Error Terms");
} else {
errorTerms.setText("Show Error Terms");
}
errorTerms.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuItem menuItem = (JMenuItem) e.getSource();
if ("Hide Error Terms".equals(menuItem.getText())) {
menuItem.setText("Show Error Terms");
getSemGraph().setShowErrorTerms(false);
} else if ("Show Error Terms".equals(menuItem.getText())) {
menuItem.setText("Hide Error Terms");
getSemGraph().setShowErrorTerms(true);
}
}
});
graph.add(errorTerms);
graph.addSeparator();
JMenuItem correlateExogenous = new JMenuItem("Correlate Exogenous Variables");
JMenuItem uncorrelateExogenous = new JMenuItem("Uncorrelate Exogenous Variables");
graph.add(correlateExogenous);
graph.add(uncorrelateExogenous);
graph.addSeparator();
correlateExogenous.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
correlationExogenousVariables();
getWorkbench().invalidate();
getWorkbench().repaint();
}
});
uncorrelateExogenous.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
uncorrelateExogenousVariables();
getWorkbench().invalidate();
getWorkbench().repaint();
}
});
JMenuItem randomGraph = new JMenuItem("Random Graph");
graph.add(randomGraph);
randomGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final GraphParamsEditor editor = new GraphParamsEditor();
editor.setParams(parameters);
EditorWindow editorWindow = new EditorWindow(editor, "Edit Random Graph Parameters", "Done", false, SemGraphEditor.this);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosed(InternalFrameEvent e1) {
EditorWindow window = (EditorWindow) e1.getSource();
if (window.isCanceled()) {
return;
}
RandomUtil.getInstance().setSeed(new Date().getTime());
Graph graph1 = edu.cmu.tetradapp.util.GraphUtils.makeRandomGraph(getGraph(), parameters);
boolean addCycles = parameters.getBoolean("randomAddCycles", false);
if (addCycles) {
int newGraphNumMeasuredNodes = parameters.getInt("newGraphNumMeasuredNodes", 10);
int newGraphNumEdges = parameters.getInt("newGraphNumEdges", 10);
graph1 = GraphUtils.cyclicGraph2(newGraphNumMeasuredNodes, newGraphNumEdges, 6);
}
getWorkbench().setGraph(graph1);
}
});
}
});
graph.addSeparator();
graph.add(new JMenuItem(new SelectBidirectedAction(getWorkbench())));
// graph.add(action);
return graph;
}
use of javax.swing.event.InternalFrameEvent in project tetrad by cmu-phil.
the class CreateTimeSeriesDataAction method actionPerformed.
/**
* Performs the action of loading a session from a file.
*/
public void actionPerformed(ActionEvent e) {
DataModel dataModel = getDataEditor().getSelectedDataModel();
if (!(dataModel instanceof DataSet)) {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Must be a tabular data set.");
return;
}
this.dataSet = (DataSet) dataModel;
SpinnerNumberModel spinnerNumberModel = new SpinnerNumberModel(getNumLags(), 0, 20, 1);
JSpinner jSpinner = new JSpinner(spinnerNumberModel);
jSpinner.setPreferredSize(jSpinner.getPreferredSize());
spinnerNumberModel.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
SpinnerNumberModel model = (SpinnerNumberModel) e.getSource();
setNumLags(model.getNumber().intValue());
}
});
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
Box b = Box.createVerticalBox();
Box b1 = Box.createHorizontalBox();
b1.add(new JLabel("Number of time lags: "));
b1.add(Box.createHorizontalGlue());
b1.add(Box.createHorizontalStrut(15));
b1.add(jSpinner);
b1.setBorder(new EmptyBorder(10, 10, 10, 10));
b.add(b1);
panel.add(b, BorderLayout.CENTER);
EditorWindow editorWindow = new EditorWindow(panel, "Create time series data", "Save", true, dataEditor);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.setVisible(true);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosed(InternalFrameEvent e) {
EditorWindow window = (EditorWindow) e.getSource();
if (!window.isCanceled()) {
if (dataSet.isContinuous()) {
createContinuousTimeSeriesData();
} else if (dataSet.isDiscrete()) {
createDiscreteTimeSeriesData();
} else {
JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), "Data set must be either continuous or discrete.");
}
}
}
});
}
Aggregations