Search in sources :

Example 6 with InternalFrameAdapter

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

the class GraphEditor method createGraphMenu.

private JMenu createGraphMenu() {
    JMenu graph = new JMenu("Graph");
    graph.add(new GraphPropertiesAction(getWorkbench()));
    graph.add(new PathsAction(getWorkbench()));
    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) {
            correlateExogenousVariables();
            getWorkbench().invalidate();
            getWorkbench().repaint();
        }
    });
    uncorrelateExogenous.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            uncorrelationExogenousVariables();
            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, GraphEditor.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);
                }
            });
        }
    });
    graph.addSeparator();
    // JMenuItem meekOrient = new JMenuItem("Meek Orientation");
    // graph.add(meekOrient);
    // meekOrient.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // MeekRules rules = new MeekRules();
    // rules.orientImplied(getGraph());
    // getWorkbench().setGraph(getGraph());
    // firePropertyChange("modelChanged", null, null);
    // }
    // }
    // );
    graph.addSeparator();
    graph.add(new JMenuItem(new SelectBidirectedAction(getWorkbench())));
    graph.add(new JMenuItem(new SelectUndirectedAction(getWorkbench())));
    graph.add(new JMenuItem(new SelectLatentsAction(getWorkbench())));
    // graph.add(action);
    return graph;
}
Also used : ActionEvent(java.awt.event.ActionEvent) InternalFrameEvent(javax.swing.event.InternalFrameEvent) ActionListener(java.awt.event.ActionListener) InternalFrameAdapter(javax.swing.event.InternalFrameAdapter)

Example 7 with InternalFrameAdapter

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

the class EditorWindow method doSetup.

/**
 * Constructs the dialog.
 */
private void doSetup(JPanel editor, boolean cancellable) {
    this.editor = editor;
    addInternalFrameListener(new InternalFrameAdapter() {

        public void InternalFrameClosing(InternalFrameEvent evt) {
            canceled = true;
            closeDialog();
        }
    });
    okButton = null;
    if (buttonName != null) {
        okButton = new JButton(buttonName);
    }
    JButton cancelButton = new JButton("Cancel");
    if (okButton != null) {
        okButton.setPreferredSize(new Dimension(100, 50));
        okButton.addActionListener(new OkListener());
    }
    cancelButton.setPreferredSize(new Dimension(80, 50));
    cancelButton.addActionListener(new CancelListener());
    Box b0 = Box.createVerticalBox();
    Box b = Box.createHorizontalBox();
    b.add(Box.createHorizontalGlue());
    if (okButton != null) {
        b.add(okButton);
    }
    b.add(Box.createHorizontalStrut(5));
    if (cancellable) {
        b.add(cancelButton);
    }
    b.add(Box.createHorizontalGlue());
    b0.add(editor);
    b0.add(b);
    Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
    int width = Math.min(b0.getPreferredSize().width + 50, screensize.width);
    int height = Math.min(b0.getPreferredSize().height + 50, screensize.height - 100);
    if (!(editor instanceof DoNotScroll) && (b0.getPreferredSize().width > width || b0.getPreferredSize().height > height)) {
        JScrollPane scroll = new JScrollPane(b0);
        scroll.setPreferredSize(new Dimension(width, height));
        getContentPane().add(scroll);
    } else {
        getContentPane().add(b0);
    }
    // Set the ok button so that pressing enter activates it.
    // jdramsey 5/5/02
    JRootPane root = SwingUtilities.getRootPane(this);
    if (root != null) {
        root.setDefaultButton(okButton);
    }
    pack();
}
Also used : InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) InternalFrameEvent(javax.swing.event.InternalFrameEvent)

Example 8 with InternalFrameAdapter

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

the class GeneralizedSemImGraphicalEditor method beginNodeEdit.

// ============================================PRIVATE=====================================================//
private void beginNodeEdit(final Node node) {
    if (launchedEditors.keySet().contains(node)) {
        launchedEditors.get(node).moveToFront();
        return;
    }
    final GeneralizedExpressionParameterizer paramEditor = new GeneralizedExpressionParameterizer(semIm, 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, "Parameter Properties", "OK", true, workbench());
    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()) {
                semIm.setSubstitutions(paramEditor.getParameterValues());
                refreshLabels();
                launchedEditors.remove(node);
                firePropertyChange("modelChanged", null, null);
            }
        }
    });
}
Also used : InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) InternalFrameEvent(javax.swing.event.InternalFrameEvent) EmptyBorder(javax.swing.border.EmptyBorder)

Example 9 with InternalFrameAdapter

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

the class GeneralizedSemPmParamsEditor method beginParamEdit.

private void beginParamEdit(final String parameter, final JLabel label, JComponent centering) {
    if (launchedEditors.keySet().contains(parameter)) {
        launchedEditors.get(parameter).moveToFront();
        return;
    }
    final GeneralizedExpressionEditor paramEditor = new GeneralizedExpressionEditor(semPm, parameter);
    final 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(parameter, editorWindow);
    editorWindow.addInternalFrameListener(new InternalFrameAdapter() {

        public void internalFrameClosing(InternalFrameEvent internalFrameEvent) {
            if (!editorWindow.isCanceled()) {
                String expressionString = paramEditor.getExpressionString();
                try {
                    semPm.setParameterExpression(parameter, expressionString);
                    // label.setText(parameter + " ~ " + semPm().getParameterExpressionString(parameter));
                    refreshLabels();
                } catch (ParseException e) {
                    // This is an expression that's been vetted by the expression editor.
                    e.printStackTrace();
                    launchedEditors.remove(parameter);
                    throw new RuntimeException("The expression editor returned an unparseable string: " + expressionString, e);
                } catch (IllegalArgumentException e) {
                    JOptionPane.showMessageDialog(panel, e.getMessage());
                    launchedEditors.remove(parameter);
                }
                firePropertyChange("modelChanged", null, null);
            }
            launchedEditors.remove(parameter);
        }
    });
}
Also used : InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) InternalFrameEvent(javax.swing.event.InternalFrameEvent) ParseException(java.text.ParseException) EmptyBorder(javax.swing.border.EmptyBorder)

Example 10 with InternalFrameAdapter

use of javax.swing.event.InternalFrameAdapter in project mondrian by pentaho.

the class Workbench method newQueryMenuItemActionPerformed.

private void newQueryMenuItemActionPerformed(ActionEvent evt) {
    JMenuItem schemaMenuItem = schemaWindowMap.get(desktopPane.getSelectedFrame());
    final JInternalFrame jf = new JInternalFrame();
    jf.setTitle(getResourceConverter().getString("workbench.new.MDXQuery.title", "MDX Query"));
    QueryPanel qp = new QueryPanel(this);
    jf.getContentPane().add(qp);
    jf.setBounds(0, 0, 500, 480);
    jf.setClosable(true);
    jf.setIconifiable(true);
    jf.setMaximizable(true);
    jf.setResizable(true);
    jf.setVisible(true);
    desktopPane.add(jf);
    jf.show();
    try {
        jf.setSelected(true);
    } catch (Exception ex) {
        // do nothing
        LOGGER.error("newQueryMenuItemActionPerformed.setSelected", ex);
    }
    // add the mdx frame to this set of mdx frames for cascading method
    mdxWindows.add(jf);
    // create mdx menu item
    final javax.swing.JMenuItem queryMenuItem = new javax.swing.JMenuItem();
    queryMenuItem.setText(getResourceConverter().getFormattedString("workbench.new.MDXQuery.menuitem", "{0} MDX", Integer.toString(windowMenuMapIndex)));
    queryMenuItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            try {
                if (jf.isIcon()) {
                    jf.setIcon(false);
                } else {
                    jf.setSelected(true);
                }
            } catch (Exception ex) {
                LOGGER.error("queryMenuItem", ex);
            }
        }
    });
    // disable mdx frame close operation to provide our handler
    // to remove frame object from mdxframeset before closing
    jf.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    jf.addInternalFrameListener(new InternalFrameAdapter() {

        public void internalFrameClosing(InternalFrameEvent e) {
            mdxWindows.remove(jf);
            jf.dispose();
            // follow this by removing file from schemaWindowMap
            windowMenu.remove(queryMenuItem);
            return;
        }
    });
    windowMenu.add(queryMenuItem, -1);
    windowMenu.add(jSeparator3, -1);
    windowMenu.add(cascadeMenuItem, -1);
    windowMenu.add(tileMenuItem, -1);
    windowMenu.add(minimizeMenuItem, -1);
    windowMenu.add(maximizeMenuItem, -1);
    windowMenu.add(closeAllMenuItem, -1);
    qp.setMenuItem(queryMenuItem);
    qp.setSchemaWindowMap(schemaWindowMap);
    qp.setWindowMenuIndex(windowMenuMapIndex++);
    if (schemaMenuItem != null) {
        qp.initConnection(schemaMenuItem.getText());
    } else {
        JOptionPane.showMessageDialog(this, getResourceConverter().getString("workbench.new.MDXQuery.no.selection", "No Mondrian connection. Select a Schema to connect."), getResourceConverter().getString("workbench.new.MDXQuery.no.selection.title", "Alert"), JOptionPane.WARNING_MESSAGE);
    }
}
Also used : javax.swing(javax.swing) InternalFrameAdapter(javax.swing.event.InternalFrameAdapter) InternalFrameEvent(javax.swing.event.InternalFrameEvent) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException)

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