Example usage for javax.swing JInternalFrame setSelected

List of usage examples for javax.swing JInternalFrame setSelected

Introduction

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

Prototype

@BeanProperty(description = "Indicates whether this internal frame is currently the active frame.")
public void setSelected(boolean selected) throws PropertyVetoException 

Source Link

Document

Selects or deselects the internal frame if it's showing.

Usage

From source file:be.fedict.eid.tsl.tool.TslTool.java

private void displayTsl(File tslFile, TrustServiceList trustServiceList) {
    JInternalFrame internalFrame = new TslInternalFrame(tslFile, trustServiceList, this);
    this.desktopPane.add(internalFrame);

    /*//from  w ww.j  a  v a2s  .  co  m
     * Bring new internal frame to top and focus on it.
     */
    this.desktopPane.getDesktopManager().activateFrame(internalFrame);
    try {
        internalFrame.setSelected(true);
    } catch (PropertyVetoException e) {
        LOG.error("veto exception");
    }
}

From source file:be.fedict.eid.tsl.tool.TslTool.java

private void displayTsl(String tslName, TrustServiceList trustServiceList) {
    JInternalFrame internalFrame = new TslInternalFrame(tslName, trustServiceList, this);
    this.desktopPane.add(internalFrame);

    /*/*  w  w  w .j a v a2 s . c o  m*/
     * Bring new internal frame to top and focus on it.
     */
    this.desktopPane.getDesktopManager().activateFrame(internalFrame);
    try {
        internalFrame.setSelected(true);
    } catch (PropertyVetoException e) {
        LOG.error("veto exception");
    }
}

From source file:JavaXWin.java

public void newFrame() {
    JInternalFrame jif = new JInternalFrame("Frame " + m_count, true, true, true, true);
    jif.setBounds(20 * (m_count % 10) + m_tencount * 80, 20 * (m_count % 10), 200, 200);

    JTextArea text = new JTextArea();
    JScrollPane scroller = new JScrollPane();
    scroller.getViewport().add(text);/*from www  .  ja  v a  2 s  . com*/
    try {
        FileReader fileStream = new FileReader("");
        text.read(fileStream, "JavaLinux.txt");
    } catch (Exception e) {
        text.setText("* Could not read JavaLinux.txt *");
    }
    jif.getContentPane().add(scroller);

    m_desktop.add(jif);
    try {
        jif.setSelected(true);
    } catch (PropertyVetoException pve) {
        System.out.println("Could not select " + jif.getTitle());
    }

    m_count++;
    if (m_count % 10 == 0) {
        if (m_tencount < 3)
            m_tencount++;
        else
            m_tencount = 0;
    }
}

From source file:KjellDirdalNotepad.java

public Component add(JInternalFrame frame) {
    JInternalFrame[] array = getAllFrames();
    Point p;/*from  w ww. j a v a 2  s  .co m*/
    int w;
    int h;

    Component retval = super.add(frame);
    checkDesktopSize();
    if (array.length > 0) {
        p = array[0].getLocation();
        p.x = p.x + FRAME_OFFSET;
        p.y = p.y + FRAME_OFFSET;
    } else {
        p = new Point(0, 0);
    }
    frame.setLocation(p.x, p.y);
    if (frame.isResizable()) {
        w = getWidth() - (getWidth() / 3);
        h = getHeight() - (getHeight() / 3);
        if (w < frame.getMinimumSize().getWidth())
            w = (int) frame.getMinimumSize().getWidth();
        if (h < frame.getMinimumSize().getHeight())
            h = (int) frame.getMinimumSize().getHeight();
        frame.setSize(w, h);
    }
    moveToFront(frame);
    frame.setVisible(true);
    try {
        frame.setSelected(true);
    } catch (PropertyVetoException e) {
        frame.toBack();
    }
    return retval;
}

From source file:au.org.ala.delta.editor.DeltaEditor.java

private void buildWindowMenu(JMenu mnuWindow) {
    mnuWindow.removeAll();//from  w w  w . ja  va  2 s  .c  o m

    JMenuItem mnuItCascade = new JMenuItem();
    mnuItCascade.setAction(_actionMap.get("cascadeFrames"));
    mnuWindow.add(mnuItCascade);

    JMenuItem mnuItTile = new JMenuItem();
    mnuItTile.setAction(_actionMap.get("tileFrames"));
    mnuWindow.add(mnuItTile);

    JMenuItem mnuItTileHorz = new JMenuItem();
    mnuItTileHorz.setAction(_actionMap.get("tileFramesHorizontally"));
    mnuWindow.add(mnuItTileHorz);

    JMenuItem mnuItArrangeIcons = new JMenuItem();
    mnuItArrangeIcons.setAction(_actionMap.get("arrangeIcons"));
    mnuWindow.add(mnuItArrangeIcons);

    JMenuItem mnuItCloseAll = new JMenuItem();
    mnuItCloseAll.setAction(_actionMap.get("closeAllFrames"));
    mnuWindow.add(mnuItCloseAll);

    mnuWindow.addSeparator();

    JMenuItem mnuItChooseFont = new JMenuItem();
    mnuItChooseFont.setAction(_actionMap.get("chooseFont"));
    mnuWindow.add(mnuItChooseFont);

    mnuWindow.addSeparator();

    JMenu mnuLF = new JMenu();
    mnuLF.setName("mnuLF");
    mnuLF.setText(_resourceMap.getString("mnuLF.text"));
    mnuWindow.add(mnuLF);

    JMenuItem mnuItMetalLF = new JMenuItem();
    mnuItMetalLF.setAction(_actionMap.get("metalLookAndFeel"));
    mnuLF.add(mnuItMetalLF);

    JMenuItem mnuItWindowsLF = new JMenuItem();
    mnuItWindowsLF.setAction(_actionMap.get("systemLookAndFeel"));
    mnuLF.add(mnuItWindowsLF);

    try {
        // Nimbus L&F was added in update java 6 update 10.
        Class.forName("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel").newInstance();
        JMenuItem mnuItNimbusLF = new JMenuItem();
        mnuItNimbusLF.setAction(_actionMap.get("nimbusLookAndFeel"));
        mnuLF.add(mnuItNimbusLF);
    } catch (Exception e) {
        // The Nimbus L&F is not available, no matter.
    }
    mnuWindow.addSeparator();

    int i = 1;
    for (final JInternalFrame frame : _frames) {
        JMenuItem windowItem = new JCheckBoxMenuItem();
        if (i < 10) {
            windowItem.setText(String.format("%d %s", i, frame.getTitle()));
            windowItem.setMnemonic(KeyEvent.VK_1 + (i - 1));
        } else {
            windowItem.setText(frame.getTitle());
        }
        windowItem.setSelected(frame.isSelected());
        windowItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    frame.setSelected(true);
                } catch (PropertyVetoException e1) {
                }
            }
        });
        mnuWindow.add(windowItem);
        ++i;
    }

}

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  ava2 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 cascadeMenuItemActionPerformed(ActionEvent evt) {
    try {//  w  w  w .  j a v a2 s.c o  m
        int sfi = 1;
        for (JInternalFrame sf : getAllFrames()) {
            if (sf != null && !sf.isIcon()) {
                sf.setMaximum(false);
                sf.setLocation(30 * sfi, 30 * sfi);
                sf.moveToFront();
                sf.setSelected(true);
                sfi++;
            }
        }
    } catch (Exception ex) {
        LOGGER.error("cascadeMenuItemActionPerformed", ex);
        // do nothing
    }
}

From source file:mondrian.gui.Workbench.java

private boolean checkFileOpen(File file) {
    Iterator<JInternalFrame> it = schemaWindowMap.keySet().iterator();
    // keys=schemaframes
    while (it.hasNext()) {
        JInternalFrame elem = it.next();
        File f = ((SchemaExplorer) elem.getContentPane().getComponent(0)).getSchemaFile();
        if (f.equals(file)) {
            try {
                // make the schema file active
                elem.setSelected(true);
                return true;
            } catch (Exception ex) {
                // remove file from map as schema frame does not exist
                schemaWindowMap.remove(elem);
                break;
            }//from   ww w.j  av a  2 s.c om
        }
    }
    return false;
}

From source file:mondrian.gui.Workbench.java

private void closeAllSchemaFrames(boolean exitAfterClose) {
    try {/*from  w ww. j av  a2 s.c  o m*/
        for (JInternalFrame sf : getAllFrames()) {
            if (sf == null) {
                continue;
            }
            if (sf.getContentPane().getComponent(0) instanceof SchemaExplorer) {
                SchemaExplorer se = (SchemaExplorer) sf.getContentPane().getComponent(0);
                sf.setSelected(true);
                int response = confirmFrameClose(sf, se);
                switch (response) {
                case 2:
                    // cancel
                    return;
                case 3:
                    // not dirty
                    sf.setClosed(true);
                    break;
                }
            } else {
                sf.setClosed(true);
            }
        }
        // exit Schema Workbench if no files are open
        if (((schemaWindowMap.keySet().size()) == 0) && exitAfterClose) {
            System.exit(0);
        }
    } catch (Exception ex) {
        LOGGER.error("closeAllSchemaFrames", ex);
    }
}

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  w w .j av  a 2s  .co  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);
    }
}