Example usage for javax.swing JInternalFrame show

List of usage examples for javax.swing JInternalFrame show

Introduction

In this page you can find the example usage for javax.swing JInternalFrame show.

Prototype

@SuppressWarnings("deprecation")
public void show() 

Source Link

Document

If the internal frame is not visible, brings the internal frame to the front, makes it visible, and attempts to select it.

Usage

From source file:InternalFrameTest.java

/**
 * Creates an internal frame on the desktop.
 * @param c the component to display in the internal frame
 * @param t the title of the internal frame.
 *///from  w w  w. j  a v  a  2  s .c  om
public void createInternalFrame(Component c, String t) {
    final JInternalFrame iframe = new JInternalFrame(t, true, // resizable
            true, // closable
            true, // maximizable
            true); // iconifiable

    iframe.add(c, BorderLayout.CENTER);
    desktop.add(iframe);

    iframe.setFrameIcon(new ImageIcon("document.gif"));

    // add listener to confirm frame closing
    iframe.addVetoableChangeListener(new VetoableChangeListener() {
        public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
            String name = event.getPropertyName();
            Object value = event.getNewValue();

            // we only want to check attempts to close a frame
            if (name.equals("closed") && value.equals(true)) {
                // ask user if it is ok to close
                int result = JOptionPane.showInternalConfirmDialog(iframe, "OK to close?", "Select an Option",
                        JOptionPane.YES_NO_OPTION);

                // if the user doesn't agree, veto the close
                if (result != JOptionPane.YES_OPTION)
                    throw new PropertyVetoException("User canceled close", event);
            }
        }
    });

    // position frame
    int width = desktop.getWidth() / 2;
    int height = desktop.getHeight() / 2;
    iframe.reshape(nextFrameX, nextFrameY, width, height);

    iframe.show();

    // select the frame--might be vetoed
    try {
        iframe.setSelected(true);
    } catch (PropertyVetoException e) {
    }

    frameDistance = iframe.getHeight() - iframe.getContentPane().getHeight();

    // compute placement for next frame

    nextFrameX += frameDistance;
    nextFrameY += frameDistance;
    if (nextFrameX + width > desktop.getWidth())
        nextFrameX = 0;
    if (nextFrameY + height > desktop.getHeight())
        nextFrameY = 0;
}

From source file:mondrian.gui.Workbench.java

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);//  w  ww.ja  v  a2s. c o m
    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);
    }
}

From source file:mondrian.gui.Workbench.java

private void aboutMenuItemActionPerformed(ActionEvent evt) {
    try {//  w  w w  .  ja v a2s .  c  om
        JEditorPane jEditorPane = new JEditorPane(
                myClassLoader.getResource(getResourceConverter().getGUIReference("version")).toString());
        jEditorPane.setEditable(false);
        JScrollPane jScrollPane = new JScrollPane(jEditorPane);
        JPanel jPanel = new JPanel();
        jPanel.setLayout(new java.awt.BorderLayout());
        jPanel.add(jScrollPane, java.awt.BorderLayout.CENTER);

        JInternalFrame jf = new JInternalFrame();
        jf.setTitle("About");
        jf.getContentPane().add(jPanel);

        Dimension screenSize = this.getSize();
        int aboutW = 400;
        int aboutH = 300;
        int width = (screenSize.width / 2) - (aboutW / 2);
        int height = (screenSize.height / 2) - (aboutH / 2) - 100;
        jf.setBounds(width, height, aboutW, aboutH);
        jf.setClosable(true);

        desktopPane.add(jf);

        jf.setVisible(true);
        jf.show();
    } catch (Exception ex) {
        LOGGER.error("aboutMenuItemActionPerformed", ex);
    }
}

From source file:mondrian.gui.Workbench.java

private int confirmFrameClose(JInternalFrame schemaFrame, SchemaExplorer se) {
    if (se.isDirty()) {
        JMenuItem schemaMenuItem = schemaWindowMap.get(desktopPane.getSelectedFrame());
        // yes=0; no=1; cancel=2
        int answer = JOptionPane.showConfirmDialog(null,
                getResourceConverter().getFormattedString("workbench.saveSchemaOnClose.alert",
                        "Save changes to {0}?", se.getSchemaFile().toString()),
                getResourceConverter().getString("workbench.saveSchemaOnClose.title", "Schema"),
                JOptionPane.YES_NO_CANCEL_OPTION);
        switch (answer) {
        case 0://w ww.  java  2 s. c o  m
            saveMenuItemActionPerformed(null);
            schemaWindowMap.remove(schemaFrame);
            updateMDXCatalogList();
            schemaFrame.dispose();
            windowMenu.remove(schemaMenuItem);
            break;
        case 1:
            schemaFrame.dispose();
            schemaWindowMap.remove(schemaFrame);
            windowMenu.remove(schemaMenuItem);
            break;
        case 2:
            try {
                schemaFrame.setClosed(false);
                schemaFrame.show();
            } catch (Exception ex) {
                LOGGER.error(ex);
            }
        }
        return answer;
    }
    return 3;
}

From source file:mondrian.gui.Workbench.java

private void openSchemaFrame(File file, boolean newFile) {
    try {/*from  www . j  a va  2 s .  c  o m*/
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

        if (!newFile) {
            // check if file not already open
            if (checkFileOpen(file)) {
                return;
            }
            // check if schema file exists
            if (!file.exists()) {
                JOptionPane.showMessageDialog(this,
                        getResourceConverter().getFormattedString("workbench.open.schema.not.found",
                                "{0} File not found.", file.getAbsolutePath()),
                        getResourceConverter().getString("workbench.open.schema.not.found.title", "Alert"),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }
            // check if file is writable
            if (!file.canWrite()) {
                JOptionPane.showMessageDialog(this,
                        getResourceConverter().getFormattedString("workbench.open.schema.not.writeable",
                                "{0} is not writeable.", file.getAbsolutePath()),
                        getResourceConverter().getString("workbench.open.schema.not.writeable.title", "Alert"),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }
            checkSchemaFile(file);
        }

        final JInternalFrame schemaFrame = new JInternalFrame();
        schemaFrame.setTitle(getResourceConverter().getFormattedString("workbench.open.schema.title",
                "Schema - {0}", file.getName()));

        getNewJdbcMetadata();

        schemaFrame.getContentPane().add(new SchemaExplorer(this, file, jdbcMetaData, newFile, schemaFrame));

        String errorOpening = ((SchemaExplorer) schemaFrame.getContentPane().getComponent(0)).getErrMsg();
        if (errorOpening != null) {
            JOptionPane.showMessageDialog(this,
                    getResourceConverter().getFormattedString("workbench.open.schema.error",
                            "Error opening schema - {0}.", errorOpening),
                    getResourceConverter().getString("workbench.open.schema.error.title", "Error"),
                    JOptionPane.ERROR_MESSAGE);
            schemaFrame.setClosed(true);
            return;
        }

        schemaFrame.setBounds(0, 0, 1000, 650);
        schemaFrame.setClosable(true);
        schemaFrame.setIconifiable(true);
        schemaFrame.setMaximizable(true);
        schemaFrame.setResizable(true);
        schemaFrame.setVisible(true);

        desktopPane.add(schemaFrame, javax.swing.JLayeredPane.DEFAULT_LAYER);
        schemaFrame.show();
        schemaFrame.setMaximum(true);

        displayWarningOnFailedConnection();

        final javax.swing.JMenuItem schemaMenuItem = new javax.swing.JMenuItem();
        schemaMenuItem.setText(windowMenuMapIndex++ + " " + file.getName());
        schemaMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    if (schemaFrame.isIcon()) {
                        schemaFrame.setIcon(false);
                    } else {
                        schemaFrame.setSelected(true);
                    }
                } catch (Exception ex) {
                    LOGGER.error("schemaMenuItem", ex);
                }
            }
        });

        windowMenu.add(schemaMenuItem, 0);
        windowMenu.setEnabled(true);

        windowMenu.add(jSeparator3, -1);
        windowMenu.add(cascadeMenuItem, -1);
        windowMenu.add(tileMenuItem, -1);
        windowMenu.add(minimizeMenuItem, -1);
        windowMenu.add(maximizeMenuItem, -1);
        windowMenu.add(closeAllMenuItem, -1);

        // add the file details in menu map
        schemaWindowMap.put(schemaFrame, schemaMenuItem);
        updateMDXCatalogList();

        schemaFrame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        schemaFrame.addInternalFrameListener(new InternalFrameAdapter() {
            public void internalFrameClosing(InternalFrameEvent e) {
                if (schemaFrame.getContentPane().getComponent(0) instanceof SchemaExplorer) {
                    SchemaExplorer se = (SchemaExplorer) schemaFrame.getContentPane().getComponent(0);
                    int response = confirmFrameClose(schemaFrame, se);
                    if (response == 3) { // not dirty
                        if (se.isNewFile()) {
                            se.getSchemaFile().delete();
                        }
                        // default case for no save and not dirty
                        schemaWindowMap.remove(schemaFrame);
                        updateMDXCatalogList();
                        schemaFrame.dispose();
                        windowMenu.remove(schemaMenuItem);
                    }
                }
            }
        });

        schemaFrame.setFocusable(true);
        schemaFrame.addFocusListener(new FocusAdapter() {
            public void focusGained(FocusEvent e) {
                if (schemaFrame.getContentPane().getComponent(0) instanceof SchemaExplorer) {
                    SchemaExplorer se = (SchemaExplorer) schemaFrame.getContentPane().getComponent(0);
                    // update view menu based on schemaframe who gained
                    // focus
                    viewXmlMenuItem.setSelected(se.isEditModeXML());
                }
            }

            public void focusLost(FocusEvent e) {
                if (schemaFrame.getContentPane().getComponent(0) instanceof SchemaExplorer) {
                    SchemaExplorer se = (SchemaExplorer) schemaFrame.getContentPane().getComponent(0);
                    // update view menu based on
                    viewXmlMenuItem.setSelected(se.isEditModeXML());
                }
            }
        });
        viewXmlMenuItem.setSelected(false);
    } catch (Exception ex) {
        LOGGER.error("openSchemaFrame", ex);
    } finally {
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }
}

From source file:mondrian.gui.Workbench.java

private void newJDBCExplorerMenuItemActionPerformed(ActionEvent evt) {
    try {//from   w ww . j a  v a 2 s.  c  om
        if (jdbcMetaData == null) {
            getNewJdbcMetadata();
        }

        final JInternalFrame jf = new JInternalFrame();

        jf.setTitle(getResourceConverter().getFormattedString("workbench.new.JDBCExplorer.title",
                "JDBC Explorer - {0} {1}", jdbcMetaData.getDatabaseProductName(),
                jdbcMetaData.getJdbcConnectionUrl()));
        getNewJdbcMetadata();

        JdbcExplorer jdbce = new JdbcExplorer(jdbcMetaData, this);

        jf.getContentPane().add(jdbce);
        jf.setBounds(0, 0, 500, 480);
        jf.setClosable(true);
        jf.setIconifiable(true);
        jf.setMaximizable(true);
        jf.setResizable(true);
        jf.setVisible(true);

        // create jdbc menu item
        final javax.swing.JMenuItem jdbcMenuItem = new javax.swing.JMenuItem();
        jdbcMenuItem.setText(getResourceConverter().getFormattedString("workbench.new.JDBCExplorer.menuitem",
                "{0} JDBC Explorer", Integer.toString(windowMenuMapIndex++)));
        jdbcMenuItem.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);
                }
            }
        });

        jf.addInternalFrameListener(new InternalFrameAdapter() {
            public void internalFrameClosing(InternalFrameEvent e) {
                jdbcWindows.remove(jf);
                jf.dispose();
                // follow this by removing file from schemaWindowMap
                windowMenu.remove(jdbcMenuItem);
                return;
            }
        });

        desktopPane.add(jf);
        jf.setVisible(true);
        jf.show();

        try {
            jf.setSelected(true);
        } catch (Exception ex) {
            // do nothing
            LOGGER.error("newJDBCExplorerMenuItemActionPerformed.setSelected", ex);
        }

        jdbcWindows.add(jf);

        windowMenu.add(jdbcMenuItem, -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);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this,
                getResourceConverter().getFormattedString("workbench.new.JDBCExplorer.exception",
                        "Database connection not successful.\n{0}", ex.getLocalizedMessage()),
                getResourceConverter().getString("workbench.new.JDBCExplorer.exception.title",
                        "Database Connection Error"),
                JOptionPane.ERROR_MESSAGE);
        LOGGER.error("newJDBCExplorerMenuItemActionPerformed", ex);
    }
}

From source file:org.docx4all.ui.main.WordMLEditor.java

public void createInternalFrame(FileObject f) {
    if (f == null) {
        return;/*from   www.j a v a2  s .c om*/
    }

    log.info(VFSUtils.getFriendlyName(f.getName().getURI()));

    JInternalFrame iframe = _iframeMap.get(f.getName().getURI());
    if (iframe != null) {
        iframe.setVisible(true);

    } else {
        iframe = new JInternalFrame(f.getName().getBaseName(), true, true, true, true);
        iframe.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        iframe.addInternalFrameListener(_internalFrameListener);
        iframe.addInternalFrameListener(_toolbarStates);
        iframe.addPropertyChangeListener(WindowMenu.getInstance());

        if (iframe.getUI() instanceof BasicInternalFrameUI) {
            BasicInternalFrameUI ui = (BasicInternalFrameUI) iframe.getUI();
            javax.swing.JComponent northPane = ui.getNorthPane();
            if (northPane == null) {
                // Happens on Mac OSX: Google for "osx java getNorthPane"
                // Fix is from it.businesslogic.ireport.gui.JMDIFrame
                javax.swing.plaf.basic.BasicInternalFrameUI aUI = new javax.swing.plaf.basic.BasicInternalFrameUI(
                        iframe);
                iframe.setUI(aUI);

                // Try again
                ui = (BasicInternalFrameUI) iframe.getUI();
                northPane = ((javax.swing.plaf.basic.BasicInternalFrameUI) ui).getNorthPane();
            }
            northPane.addMouseMotionListener(_titleBarMouseListener);
        }

        JEditorPane editorView = createEditorView(f);
        JPanel panel = FxScriptUIHelper.getInstance().createEditorPanel(editorView);

        iframe.getContentPane().add(panel);
        iframe.pack();
        _desktop.add(iframe);

        editorView.requestFocusInWindow();
        editorView.select(0, 0);

        String filePath = f.getName().getURI();
        iframe.putClientProperty(WordMLDocument.FILE_PATH_PROPERTY, filePath);
        _iframeMap.put(filePath, iframe);

        iframe.show();
    }

    try {
        iframe.setSelected(true);
        iframe.setIcon(false);
        iframe.setMaximum(true);
    } catch (PropertyVetoException exc) {
        // do nothing
    }
}