Search in sources :

Example 16 with InternalFrameAdapter

use of javax.swing.event.InternalFrameAdapter in project tetrad by cmu-phil.

the class GeneralizedSemPmListEditor method beginNodeEdit.

private void beginNodeEdit(final Node node, JComponent centering, final JLabel label) {
    if (launchedEditors.keySet().contains(node)) {
        launchedEditors.get(node).moveToFront();
        return;
    }
    final GeneralizedExpressionEditor paramEditor = new GeneralizedExpressionEditor(semPm, node);
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());
    panel.add(paramEditor, BorderLayout.CENTER);
    panel.setBorder(new EmptyBorder(5, 5, 5, 5));
    final EditorWindow editorWindow = new EditorWindow(panel, "Edit Expression", "OK", true, centering);
    DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
    editorWindow.pack();
    editorWindow.setVisible(true);
    launchedEditors.put(node, editorWindow);
    editorWindow.addInternalFrameListener(new InternalFrameAdapter() {

        public void internalFrameClosing(InternalFrameEvent internalFrameEvent) {
            if (!editorWindow.isCanceled()) {
                String expressionString = paramEditor.getExpressionString();
                try {
                    semPm.setNodeExpression(node, expressionString);
                    if (node.getNodeType() == NodeType.ERROR) {
                        label.setText(node + " = " + semPm().getNodeExpressionString(node));
                    } else {
                        label.setText(node + " ~ " + semPm().getNodeExpressionString(node));
                    }
                } catch (ParseException e) {
                    // This is an expression that's been vetted by the expression editor.
                    launchedEditors.remove(node);
                    e.printStackTrace();
                    throw new RuntimeException("The expression editor returned an unparseable string: " + expressionString, e);
                }
                paramsEditor.refreshLabels();
                firePropertyChange("modelChanged", null, null);
            }
            launchedEditors.remove(node);
        }
    });
// GeneralizedExpressionEditor paramEditor = new GeneralizedExpressionEditor(semPm, node);
// 
// int ret = JOptionPane.showOptionDialog(centering, paramEditor,
// "Edit Expression", JOptionPane.OK_CANCEL_OPTION,
// JOptionPane.PLAIN_MESSAGE, null, null, null);
// 
// if (ret == JOptionPane.OK_OPTION) {
// String expressionString = paramEditor.getExpressionString();
// try {
// semPm.setNodeExpression(node, expressionString);
// 
// if (node.getNodeType() == NodeType.ERROR) {
// label.setText(node + " = " + semPm().getNodeExpressionString(node));
// }
// else {
// label.setText(node + " ~ " + semPm().getNodeExpressionString(node));
// }
// 
// paramsEditor.freshenDisplay();
// } catch (ParseException e) {
// // This is an expression that's been vetted by the expression editor.
// e.printStackTrace();
// throw new RuntimeException("The expression editor returned an unparseable string: " + expressionString, e);
// }
// 
// firePropertyChange("modelChanged", null, null);
// }
}
Also used : InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) InternalFrameEvent(javax.swing.event.InternalFrameEvent) ParseException(java.text.ParseException) EmptyBorder(javax.swing.border.EmptyBorder)

Example 17 with InternalFrameAdapter

use of javax.swing.event.InternalFrameAdapter in project tetrad by cmu-phil.

the class SessionEditorNode method launchEditorVisit.

private void launchEditorVisit() {
    try {
        // If there is already an editor open, don't launch another one.
        if (spawnedEditor() != null) {
            return;
        }
        boolean created = createModel(false);
        if (!created) {
            return;
        }
        final SessionNode sessionNode = getSessionNode();
        boolean cloned = sessionNode.useClonedModel();
        SessionModel model = sessionNode.getModel();
        Class<?> modelClass = model.getClass();
        SessionNodeModelConfig modelConfig = this.config.getModelConfig(modelClass);
        Object[] arguments = new Object[] { model };
        JPanel editor = modelConfig.getEditorInstance(arguments);
        addEditorListener(editor);
        ModificationRegistery.registerEditor(sessionNode, editor);
        String descrip = modelConfig.getName();
        editor.setName(getName() + " (" + descrip + ")");
        EditorWindow editorWindow = new EditorWindow(editor, editor.getName(), "Done", cloned, this);
        editorWindow.addInternalFrameListener(new InternalFrameAdapter() {

            @Override
            public void internalFrameClosing(InternalFrameEvent e) {
                if (getChildren().iterator().hasNext()) {
                    finishedEditingDialog();
                }
                ModificationRegistery.unregisterSessionNode(sessionNode);
                setSpawnedEditor(null);
                EditorWindow window = (EditorWindow) e.getSource();
                if (window.isCanceled()) {
                    sessionNode.restoreOriginalModel();
                }
                sessionNode.forgetSavedModel();
            }
        });
        DesktopController.getInstance().addEditorWindow(editorWindow, JLayeredPane.PALETTE_LAYER);
        editorWindow.pack();
        editorWindow.setVisible(true);
        spawnedEditor = editorWindow;
        if (sessionWrapper != null) {
            sessionWrapper.setSessionChanged(true);
        }
    // for (SessionNode child : getChildren()) {
    // 
    // // only break edges to children.
    // if (edge.getNode2() == getModelNode()) {
    // SessionNodeWrapper otherWrapper =
    // (SessionNodeWrapper) edge.getNode1();
    // SessionNode other = otherWrapper.getSessionNode();
    // if (getChildren().contains(other)) {
    // sessionWrapper.removeEdge(edge);
    // }
    // } else {
    // SessionNodeWrapper otherWrapper =
    // (SessionNodeWrapper) edge.getNode2();
    // SessionNode other = otherWrapper.getSessionNode();
    // if (getChildren().contains(other)) {
    // sessionWrapper.removeEdge(edge);
    // }
    // }
    // }
    // Class[] consistentModelClasses = child.getConsistentModelClasses(false);
    // if (consistentModelClasses.length == 0) {
    // child.removeParent(sessionNode);
    // SessionEditorWorkbench sessionWorkbench = getSessionWorkbench();
    // SessionWrapper sessionWrapper = sessionWorkbench.getSessionWrapper();
    // Node node1 = sessionWrapper.getNode(sessionNode.getDisplayName());
    // Node node2 = sessionWrapper.getNode(child.getDisplayName());
    // Edge edge = sessionWrapper.getEdge(node1, node2);
    // sessionWrapper.removeEdge(edge);
    // }
    } catch (CouldNotCreateModelException e) {
        SessionUtils.showPermissibleParentsDialog(e.getModelClass(), SessionEditorNode.this, true, true);
        e.printStackTrace();
    } catch (ClassCastException e) {
        e.printStackTrace();
    } catch (Exception e) {
        Throwable cause = e;
        while (cause.getCause() != null) {
            cause = cause.getCause();
        }
        Component centeringComp = SessionEditorNode.this;
        String s = cause.getMessage();
        if (!"".equals(s)) {
            JOptionPane.showMessageDialog(centeringComp, s, null, JOptionPane.WARNING_MESSAGE);
        }
        e.printStackTrace();
    }
}
Also used : JPanel(javax.swing.JPanel) SessionNode(edu.cmu.tetrad.session.SessionNode) InternalFrameEvent(javax.swing.event.InternalFrameEvent) CouldNotCreateModelException(edu.cmu.tetrad.session.CouldNotCreateModelException) EditorWindow(edu.cmu.tetradapp.editor.EditorWindow) CouldNotCreateModelException(edu.cmu.tetrad.session.CouldNotCreateModelException) UnlistedSessionModel(edu.cmu.tetradapp.model.UnlistedSessionModel) SessionModel(edu.cmu.tetrad.session.SessionModel) InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 18 with InternalFrameAdapter

use of javax.swing.event.InternalFrameAdapter in project opt4j by felixreimann.

the class Viewport method createInternalFrame.

/**
 * Creates a widget as a {@link JInternalFrame}.
 *
 * @param widget
 *            the widget
 * @return the constructed JInternalFrame
 */
protected JInternalFrame createInternalFrame(final Widget widget) {
    final JPanel panel = widget.getPanel();
    final String frameTitle;
    final Icon frameIcon;
    boolean resizable = true;
    boolean closable = true;
    boolean maximizable = true;
    boolean iconifiable = true;
    WidgetParameters parameters = widget.getClass().getAnnotation(WidgetParameters.class);
    if (parameters != null) {
        frameTitle = parameters.title();
        if (!parameters.icon().equals("")) {
            frameIcon = Icons.getIcon(parameters.icon());
        } else {
            frameIcon = null;
        }
        resizable = parameters.resizable();
        closable = parameters.closable();
        maximizable = parameters.maximizable();
        iconifiable = parameters.iconifiable();
    } else {
        frameTitle = null;
        frameIcon = null;
    }
    final JInternalFrame inFrame = new JInternalFrame(frameTitle, resizable, closable, maximizable, iconifiable);
    widget.init(this);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            inFrame.addInternalFrameListener(new InternalFrameAdapter() {

                @Override
                public void internalFrameClosed(InternalFrameEvent arg0) {
                    widgets.remove(widget);
                }
            });
            inFrame.setFrameIcon(frameIcon);
            inFrame.getContentPane().setLayout(new BorderLayout());
            inFrame.getContentPane().add(panel, BorderLayout.CENTER);
            int windows = desktop.getAllFrames().length;
            windows = windows % 6;
            inFrame.setLocation(OFFSET * windows, OFFSET * windows);
        }
    });
    widgets.put(widget, inFrame);
    return inFrame;
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) InternalFrameEvent(javax.swing.event.InternalFrameEvent) Icon(javax.swing.Icon) JInternalFrame(javax.swing.JInternalFrame)

Aggregations

InternalFrameAdapter (javax.swing.event.InternalFrameAdapter)18 InternalFrameEvent (javax.swing.event.InternalFrameEvent)18 EmptyBorder (javax.swing.border.EmptyBorder)7 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 ParseException (java.text.ParseException)4 javax.swing (javax.swing)3 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)3 KettleException (org.pentaho.di.core.exception.KettleException)3 Point (java.awt.Point)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 JPanel (javax.swing.JPanel)2 ChangeEvent (javax.swing.event.ChangeEvent)2 ChangeListener (javax.swing.event.ChangeListener)2 Node (edu.cmu.tetrad.graph.Node)1 CouldNotCreateModelException (edu.cmu.tetrad.session.CouldNotCreateModelException)1 SessionModel (edu.cmu.tetrad.session.SessionModel)1 SessionNode (edu.cmu.tetrad.session.SessionNode)1 Parameters (edu.cmu.tetrad.util.Parameters)1