Search in sources :

Example 81 with Container

use of java.awt.Container in project jdk8u_jdk by JetBrains.

the class JMenu method getPopupMenuOrigin.

/**
     * Computes the origin for the <code>JMenu</code>'s popup menu.
     * This method uses Look and Feel properties named
     * <code>Menu.menuPopupOffsetX</code>,
     * <code>Menu.menuPopupOffsetY</code>,
     * <code>Menu.submenuPopupOffsetX</code>, and
     * <code>Menu.submenuPopupOffsetY</code>
     * to adjust the exact location of popup.
     *
     * @return a <code>Point</code> in the coordinate space of the
     *          menu which should be used as the origin
     *          of the <code>JMenu</code>'s popup menu
     *
     * @since 1.3
     */
protected Point getPopupMenuOrigin() {
    int x;
    int y;
    JPopupMenu pm = getPopupMenu();
    // Figure out the sizes needed to caclulate the menu position
    Dimension s = getSize();
    Dimension pmSize = pm.getSize();
    // the size has not yet been initiated
    if (pmSize.width == 0) {
        pmSize = pm.getPreferredSize();
    }
    Point position = getLocationOnScreen();
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    GraphicsConfiguration gc = getGraphicsConfiguration();
    Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gd = ge.getScreenDevices();
    for (int i = 0; i < gd.length; i++) {
        if (gd[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
            GraphicsConfiguration dgc = gd[i].getDefaultConfiguration();
            if (dgc.getBounds().contains(position)) {
                gc = dgc;
                break;
            }
        }
    }
    if (gc != null) {
        screenBounds = gc.getBounds();
        // take screen insets (e.g. taskbar) into account
        Insets screenInsets = toolkit.getScreenInsets(gc);
        screenBounds.width -= Math.abs(screenInsets.left + screenInsets.right);
        screenBounds.height -= Math.abs(screenInsets.top + screenInsets.bottom);
        position.x -= Math.abs(screenInsets.left);
        position.y -= Math.abs(screenInsets.top);
    }
    Container parent = getParent();
    if (parent instanceof JPopupMenu) {
        // We are a submenu (pull-right)
        int xOffset = UIManager.getInt("Menu.submenuPopupOffsetX");
        int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY");
        if (SwingUtilities.isLeftToRight(this)) {
            // First determine x:
            // Prefer placement to the right
            x = s.width + xOffset;
            if (position.x + x + pmSize.width >= screenBounds.width + screenBounds.x && // popup doesn't fit - place it wherever there's more room
            screenBounds.width - s.width < 2 * (position.x - screenBounds.x)) {
                x = 0 - xOffset - pmSize.width;
            }
        } else {
            // First determine x:
            // Prefer placement to the left
            x = 0 - xOffset - pmSize.width;
            if (position.x + x < screenBounds.x && // popup doesn't fit - place it wherever there's more room
            screenBounds.width - s.width > 2 * (position.x - screenBounds.x)) {
                x = s.width + xOffset;
            }
        }
        // Then the y:
        // Prefer dropping down
        y = yOffset;
        if (position.y + y + pmSize.height >= screenBounds.height + screenBounds.y && // popup doesn't fit - place it wherever there's more room
        screenBounds.height - s.height < 2 * (position.y - screenBounds.y)) {
            y = s.height - yOffset - pmSize.height;
        }
    } else {
        // We are a toplevel menu (pull-down)
        int xOffset = UIManager.getInt("Menu.menuPopupOffsetX");
        int yOffset = UIManager.getInt("Menu.menuPopupOffsetY");
        if (SwingUtilities.isLeftToRight(this)) {
            // First determine the x:
            // Extend to the right
            x = xOffset;
            if (position.x + x + pmSize.width >= screenBounds.width + screenBounds.x && // popup doesn't fit - place it wherever there's more room
            screenBounds.width - s.width < 2 * (position.x - screenBounds.x)) {
                x = s.width - xOffset - pmSize.width;
            }
        } else {
            // First determine the x:
            // Extend to the left
            x = s.width - xOffset - pmSize.width;
            if (position.x + x < screenBounds.x && // popup doesn't fit - place it wherever there's more room
            screenBounds.width - s.width > 2 * (position.x - screenBounds.x)) {
                x = xOffset;
            }
        }
        // Then the y:
        // Prefer dropping down
        y = s.height + yOffset;
        if (position.y + y + pmSize.height >= screenBounds.height + screenBounds.y && // popup doesn't fit - place it wherever there's more room
        screenBounds.height - s.height < 2 * (position.y - screenBounds.y)) {
            // Otherwise drop 'up'
            y = 0 - yOffset - pmSize.height;
        }
    }
    return new Point(x, y);
}
Also used : Container(java.awt.Container) GraphicsDevice(java.awt.GraphicsDevice) Insets(java.awt.Insets) Rectangle(java.awt.Rectangle) Toolkit(java.awt.Toolkit) Dimension(java.awt.Dimension) Point(java.awt.Point) GraphicsEnvironment(java.awt.GraphicsEnvironment) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 82 with Container

use of java.awt.Container in project jdk8u_jdk by JetBrains.

the class CompareTabOrderComparator method getComponentAfter.

public Component getComponentAfter(Container aContainer, Component aComponent) {
    Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor();
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }
        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }
    return null;
}
Also used : Container(java.awt.Container) FocusTraversalPolicy(java.awt.FocusTraversalPolicy)

Example 83 with Container

use of java.awt.Container in project jdk8u_jdk by JetBrains.

the class CompareTabOrderComparator method getFirstComponent.

public Component getFirstComponent(Container aContainer) {
    Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor();
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getFirstComponent(root);
        }
        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getFirstComponent(root);
    }
    return null;
}
Also used : Container(java.awt.Container) FocusTraversalPolicy(java.awt.FocusTraversalPolicy)

Example 84 with Container

use of java.awt.Container in project jdk8u_jdk by JetBrains.

the class JFileChooser method createDialog.

/**
     * Creates and returns a new <code>JDialog</code> wrapping
     * <code>this</code> centered on the <code>parent</code>
     * in the <code>parent</code>'s frame.
     * This method can be overriden to further manipulate the dialog,
     * to disable resizing, set the location, etc. Example:
     * <pre>
     *     class MyFileChooser extends JFileChooser {
     *         protected JDialog createDialog(Component parent) throws HeadlessException {
     *             JDialog dialog = super.createDialog(parent);
     *             dialog.setLocation(300, 200);
     *             dialog.setResizable(false);
     *             return dialog;
     *         }
     *     }
     * </pre>
     *
     * @param   parent  the parent component of the dialog;
     *                  can be <code>null</code>
     * @return a new <code>JDialog</code> containing this instance
     * @exception HeadlessException if GraphicsEnvironment.isHeadless()
     * returns true.
     * @see java.awt.GraphicsEnvironment#isHeadless
     * @since 1.4
     */
protected JDialog createDialog(Component parent) throws HeadlessException {
    FileChooserUI ui = getUI();
    String title = ui.getDialogTitle(this);
    putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, title);
    JDialog dialog;
    Window window = JOptionPane.getWindowForComponent(parent);
    if (window instanceof Frame) {
        dialog = new JDialog((Frame) window, title, true);
    } else {
        dialog = new JDialog((Dialog) window, title, true);
    }
    dialog.setComponentOrientation(this.getComponentOrientation());
    Container contentPane = dialog.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(this, BorderLayout.CENTER);
    if (JDialog.isDefaultLookAndFeelDecorated()) {
        boolean supportsWindowDecorations = UIManager.getLookAndFeel().getSupportsWindowDecorations();
        if (supportsWindowDecorations) {
            dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
        }
    }
    dialog.pack();
    dialog.setLocationRelativeTo(parent);
    return dialog;
}
Also used : Window(java.awt.Window) Frame(java.awt.Frame) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) Dialog(java.awt.Dialog) FileChooserUI(javax.swing.plaf.FileChooserUI)

Example 85 with Container

use of java.awt.Container in project jdk8u_jdk by JetBrains.

the class CompareTabOrderComparator method getLastComponent.

public Component getLastComponent(Container aContainer) {
    Container root = (aContainer.isFocusCycleRoot()) ? aContainer : aContainer.getFocusCycleRootAncestor();
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getLastComponent(root);
        }
        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getLastComponent(root);
    }
    return null;
}
Also used : Container(java.awt.Container) FocusTraversalPolicy(java.awt.FocusTraversalPolicy)

Aggregations

Container (java.awt.Container)250 JPanel (javax.swing.JPanel)70 JLabel (javax.swing.JLabel)65 JButton (javax.swing.JButton)56 JScrollPane (javax.swing.JScrollPane)55 BoxLayout (javax.swing.BoxLayout)50 FlowLayout (java.awt.FlowLayout)49 Component (java.awt.Component)46 BorderLayout (java.awt.BorderLayout)44 Dimension (java.awt.Dimension)39 ActionEvent (java.awt.event.ActionEvent)38 ActionListener (java.awt.event.ActionListener)26 JComponent (javax.swing.JComponent)22 JFrame (javax.swing.JFrame)22 JmriJFrame (jmri.util.JmriJFrame)20 Border (javax.swing.border.Border)18 JTable (javax.swing.JTable)17 JTextArea (javax.swing.JTextArea)17 Frame (java.awt.Frame)16 JTextField (javax.swing.JTextField)16