use of javax.swing.event.InternalFrameAdapter 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.InternalFrameAdapter 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.InternalFrameAdapter 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.");
}
}
}
});
}
use of javax.swing.event.InternalFrameAdapter in project tetrad by cmu-phil.
the class DagEditor 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()));
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, DagEditor.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, 8);
}
getWorkbench().setGraph(graph1);
}
});
}
});
return graph;
}
use of javax.swing.event.InternalFrameAdapter in project tetrad by cmu-phil.
the class CalculatorAction method actionPerformed.
/**
* Launches the calculator editoir.
*/
public void actionPerformed(ActionEvent e) {
final CalculatorEditor editor = new CalculatorEditor();
Parameters params = wrapper.getParams();
if (params instanceof HasCalculatorParams) {
params = ((HasCalculatorParams) params).getCalculatorParams();
}
editor.setParams(params);
editor.setParentModels(new Object[] { wrapper });
editor.setup();
EditorWindow editorWindow = new EditorWindow(editor, editor.getName(), "Save", true, dataEditor);
DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
editorWindow.pack();
editorWindow.setVisible(true);
editorWindow.addInternalFrameListener(new InternalFrameAdapter() {
public void internalFrameClosed(InternalFrameEvent e) {
EditorWindow window = (EditorWindow) e.getSource();
if (window.isCanceled()) {
return;
}
if (editor.finalizeEdit()) {
List<String> equations = new ArrayList<>();
String _displayEquations = Preferences.userRoot().get("calculator_equations", "");
String[] displayEquations = _displayEquations.split("///");
for (String equation : displayEquations) {
if (equation.contains("$")) {
for (Node node : editor.getDataSet().getVariables()) {
equations.add(equation.replace("$", node.getName()));
}
} else {
equations.add(equation);
}
}
String[] eqs = equations.toArray(new String[0]);
try {
Transformation.transform(editor.getDataSet(), eqs);
} catch (ParseException e1) {
throw new IllegalStateException("Parse error while applying equations to dataset.");
}
}
}
});
}
Aggregations