Example usage for javax.swing JFrame getBounds

List of usage examples for javax.swing JFrame getBounds

Introduction

In this page you can find the example usage for javax.swing JFrame getBounds.

Prototype

public Rectangle getBounds() 

Source Link

Document

Gets the bounds of this component in the form of a Rectangle object.

Usage

From source file:levelBuilder.DialogMaker.java

/**
 * Displays key (i.e. legend) to the graph.
 *//*from   w w w.  j ava  2s.c om*/
private static void keyWindow() {
    JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0));

    BufferedImage img1 = null;
    BufferedImage img2 = null;
    BufferedImage img3 = null;
    BufferedImage img4 = null;
    BufferedImage img5 = null;
    try {
        img1 = ImageIO.read(new File(imgDir + "green.png"));
        img2 = ImageIO.read(new File(imgDir + "red.png"));
        img3 = ImageIO.read(new File(imgDir + "blue.png"));
        img4 = ImageIO.read(new File(imgDir + "circle.png"));
        img5 = ImageIO.read(new File(imgDir + "square.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    panel.add(new JLabel("Initial Node", new ImageIcon(img1), SwingConstants.LEFT));
    panel.add(new JLabel("End Node", new ImageIcon(img2), SwingConstants.LEFT));
    panel.add(new JLabel("Intermediate Node", new ImageIcon(img3), SwingConstants.LEFT));
    panel.add(new JLabel("Player Node", new ImageIcon(img4), SwingConstants.LEFT));
    panel.add(new JLabel("NPC Node", new ImageIcon(img5), SwingConstants.LEFT));

    JFrame frame = new JFrame("Key");
    panel.setOpaque(true);
    frame.setContentPane(panel);
    frame.pack();
    frame.setLocation(windowWidth, 0);
    frame.setVisible(true);

    verticalWindowPlacement += frame.getBounds().height + frame.getBounds().y;
    horizontalWindowPlacement += frame.getBounds().width;
}

From source file:levelBuilder.DialogMaker.java

/**
 * Displays properties of the currently selected node.
 * Also allows changing of most node properties. 
 *///from  w ww  .  ja  va2 s.  c  om
private static void nodePropertiesWindow() {
    //Performs actions based on button pushes.
    class ActionHandler implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            switch (e.getActionCommand()) {
            case "probSet":
                //parsing new probSet string to double[]
                ArrayList<double[]> probSets = selectedNode.getProbSets();
                if (probSetField.getText().equals(""))
                    probSets.remove(strategy);
                else {
                    String[] probSetInput = probSetField.getText().split(",");
                    int numChildren = probSetInput.length;
                    double[] newProbSet = new double[numChildren];
                    for (int c = 0; c < numChildren; c++)
                        newProbSet[c] = Double.parseDouble(probSetInput[c]);
                    if (probSets.size() > strategy)//TODO is this right?
                        probSets.add(strategy, newProbSet);
                    else
                        probSets.set(strategy, newProbSet);
                }
                selectedNode.setProbSets(probSets);
            case "npc":
                if (isNPCBoxChecked)
                    selectedNode.setNPC();
                else
                    selectedNode.setPC();
            case "text":
                dg.changeNodeText(selectedNode, textField.getText());
            case "strategy":
                strategy = Integer.parseInt(strategyField.getText());
            }
        }
    }

    JPanel fieldPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel labelPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel masterPanel = new JPanel(new GridLayout(0, 3, 0, 0));

    //Buttons, ckeckboxes, textboxes, and labels
    textField = new JTextField("May I buy your wand?", 10);
    fieldPanel.add(textField);
    labelPanel.add(new JLabel("Node Text"));
    JButton button1 = new JButton("Change");
    button1.setActionCommand("text");
    button1.addActionListener(new ActionHandler());
    buttonPanel.add(button1);

    npcBox = new JCheckBox();
    npcBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.DESELECTED)
                isNPCBoxChecked = false;
            else
                isNPCBoxChecked = true;
        }
    });
    fieldPanel.add(npcBox);
    labelPanel.add(new JLabel("NPC"));
    JButton button2 = new JButton("Change");
    button2.setActionCommand("npc");
    button2.addActionListener(new ActionHandler());
    buttonPanel.add(button2);

    childrenField = new JTextField("child1,child2", 10);
    fieldPanel.add(childrenField);
    labelPanel.add(new JLabel("Children"));
    JButton button3 = new JButton("");
    buttonPanel.add(button3);

    probSetField = new JTextField("0.1,0.9", 10);
    fieldPanel.add(probSetField);
    labelPanel.add(new JLabel("Probability set"));
    JButton button4 = new JButton("Change");
    button4.setActionCommand("probSet");
    button4.addActionListener(new ActionHandler());
    buttonPanel.add(button4);

    strategyField = new JTextField("0", 10);
    fieldPanel.add(strategyField);
    labelPanel.add(new JLabel("Strategy"));
    JButton button5 = new JButton("Change");
    button5.setActionCommand("strategy");
    button5.addActionListener(new ActionHandler());
    buttonPanel.add(button5);

    masterPanel.add(buttonPanel);
    masterPanel.add(fieldPanel);
    masterPanel.add(labelPanel);

    JFrame frame = new JFrame("Node Properties");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fieldPanel.setOpaque(true);
    frame.setContentPane(masterPanel);
    frame.pack();
    frame.setLocation(windowWidth, verticalWindowPlacement);
    frame.setVisible(true);

    verticalWindowPlacement += frame.getBounds().height;
}

From source file:edu.ku.brc.specify.ui.AppBase.java

/**
 * Bring up the PPApp demo by showing the frame (only applicable if coming up
 * as an application, not an applet);//from   www.j a  v  a2  s  .  c  o m
 */
public void showApp() {
    JFrame f = getFrame();
    f.setTitle(getTitle());
    f.getContentPane().add(this, BorderLayout.CENTER);
    f.pack();

    f.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            doExit(true);
        }
    });

    UIHelper.centerWindow(f);
    Rectangle r = f.getBounds();
    int x = AppPreferences.getLocalPrefs().getInt("APP.X", r.x);
    int y = AppPreferences.getLocalPrefs().getInt("APP.Y", r.y);
    int w = AppPreferences.getLocalPrefs().getInt("APP.W", r.width);
    int h = AppPreferences.getLocalPrefs().getInt("APP.H", r.height);
    UIHelper.positionAndFitToScreen(f, x, y, w, h);

    f.setVisible(true);
}

From source file:edu.ku.brc.ui.UIRegistry.java

/**
 * Writes a string message into the BufferedImage on GlassPane and sets the main component's visibility to false and
 * shows the GlassPane.//from  w  w  w  .ja v a  2  s.  co  m
 * @param msg the message
 * @param pointSize the Font point size for the message to be writen in
 */
public static GhostGlassPane writeGlassPaneMsg(final String msg, final int pointSize) {
    GhostGlassPane glassPane = getGlassPane();
    if (glassPane != null) {
        glassPane.finishDnD();
    }

    glassPane.setMaskingEvents(true);

    Component mainComp = get(MAINPANE);
    if (mainComp != null && glassPane != null) {
        JFrame frame = (JFrame) get(FRAME);
        frameRect = frame.getBounds();

        int y = 0;
        JMenuBar menuBar = null;
        Dimension size = mainComp.getSize();
        if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) {
            menuBar = frame.getJMenuBar();
            size.height += menuBar.getSize().height;
            y += menuBar.getSize().height;
        }
        BufferedImage buffer = getGlassPaneBufferedImage(size.width, size.height);
        Graphics2D g2 = buffer.createGraphics();
        if (menuBar != null) {
            menuBar.paint(g2);
        }
        g2.translate(0, y);
        mainComp.paint(g2);
        g2.translate(0, -y);

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(new Color(255, 255, 255, 128));
        g2.fillRect(0, 0, size.width, size.height);

        g2.setFont(new Font((new JLabel()).getFont().getName(), Font.BOLD, pointSize));
        FontMetrics fm = g2.getFontMetrics();

        int tw = fm.stringWidth(msg);
        int th = fm.getHeight();
        int tx = (size.width - tw) / 2;
        int ty = (size.height - th) / 2;

        int expand = 20;
        int arc = expand * 2;
        g2.setColor(Color.WHITE);
        g2.fillRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc,
                arc);

        g2.setColor(Color.DARK_GRAY);
        g2.drawRoundRect(tx - (expand / 2), ty - fm.getAscent() - (expand / 2), tw + expand, th + expand, arc,
                arc);

        g2.setColor(Color.BLACK);
        g2.drawString(msg, tx, ty);
        g2.dispose();

        glassPane.setImage(buffer);
        glassPane.setPoint(new Point(0, 0), GhostGlassPane.ImagePaintMode.ABSOLUTE);
        glassPane.setOffset(new Point(0, 0));

        glassPane.setVisible(true);
        mainComp.setVisible(false);

        //Using paintImmediately fixes problems with glass pane not showing, such as for workbench saves initialed
        //during workbench or app shutdown. Don't know if there is a better way to fix it.
        //glassPane.repaint();
        glassPane.paintImmediately(glassPane.getBounds());
        showingGlassPane = true;
    }

    return glassPane;
}

From source file:levelBuilder.DialogMaker.java

/**
 * Provides instructions for using the program.
 *///from   w  w  w .  ja v a2s  . c o m
private static void instructionsWindow() {
    JFrame frame = new JFrame("Instructions");
    JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0));

    panel.add(new JLabel("DO NOT USE THE RIGHT CLICK MENU.", SwingConstants.LEFT));
    panel.add(new JLabel("DO NOT REMOVE NODES OR VERTICES WITH THIS GUI. EDIT THE XML FILE INSTEAD.",
            SwingConstants.LEFT));
    panel.add(new JLabel("", SwingConstants.LEFT));
    panel.add(
            new JLabel("The 'Check' button runs various checks to make sure the graph does not contain errors.",
                    SwingConstants.LEFT));
    panel.add(new JLabel("", SwingConstants.LEFT));
    panel.add(new JLabel("Transforming mode:", SwingConstants.LEFT));
    panel.add(new JLabel("Shift + click + drag to rotate", SwingConstants.LEFT));
    panel.add(new JLabel("Scroll to zoom", SwingConstants.LEFT));
    panel.add(new JLabel("Command + click + drag to to weird stretchy thing", SwingConstants.LEFT));
    panel.add(new JLabel("", SwingConstants.LEFT));
    panel.add(new JLabel("Picking mode:", SwingConstants.LEFT));
    panel.add(new JLabel("Click + drag to select multiple nodes", SwingConstants.LEFT));
    panel.add(new JLabel("Click + drag moves node or group of nodes", SwingConstants.LEFT));
    panel.add(new JLabel("Only in picking mode can you see different strategies", SwingConstants.LEFT));
    panel.add(new JLabel("New strategies will also only appear after refocusing on the main window",
            SwingConstants.LEFT));
    panel.add(new JLabel("", SwingConstants.LEFT));
    panel.add(new JLabel("Editing mode:", SwingConstants.LEFT));
    panel.add(new JLabel("Click + drag from one node to another creates an edge", SwingConstants.LEFT));
    panel.add(new JLabel("After drawing a new edge you have to click the 'new edge' button",
            SwingConstants.LEFT));
    panel.add(new JLabel("Click to add a new node", SwingConstants.LEFT));

    panel.setOpaque(true);
    frame.setContentPane(panel);
    frame.pack();
    frame.setLocation(windowWidth, verticalWindowPlacement);
    frame.setVisible(true);

    verticalWindowPlacement += frame.getBounds().height;
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Center and make the window visible//from  www.j a v  a 2 s  . co m
 * @param window the window to center
 * @param width sets the dialog to this width (can be null)
 * @param height sets the dialog to this height (can be null)
 */
public static void centerWindow(final java.awt.Window window, final Integer width, final Integer height) {
    JFrame topFrame = (JFrame) UIRegistry.getTopWindow();
    Insets screenInsets = null;
    Rectangle screenRect = null;

    if (width != null || height != null) {
        Dimension s = window.getSize();
        if (width != null)
            s.width = width;
        if (height != null)
            s.height = height;
        window.setSize(s);
    }

    // if there is a registered TOPFRAME, and it's not the same as the window being passed in...
    if (topFrame != null && topFrame != window) {
        screenRect = topFrame.getBounds();
        screenInsets = topFrame.getInsets();
    } else {
        screenRect = window.getGraphicsConfiguration().getBounds();
        screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration());
    }

    // Make sure we don't place the demo off the screen.
    int centerWidth = screenRect.width < window.getSize().width ? screenRect.x
            : screenRect.x + screenRect.width / 2 - window.getSize().width / 2;
    int centerHeight = screenRect.height < window.getSize().height ? screenRect.y
            : screenRect.y + screenRect.height / 2 - window.getSize().height / 2;

    centerHeight = centerHeight < screenInsets.top ? screenInsets.top : centerHeight;

    window.setLocation(centerWidth, centerHeight);
}

From source file:edu.ku.brc.specify.Specify.java

/**
 * Bring up the PPApp demo by showing the frame (only applicable if coming up
 * as an application, not an applet);//from  w w w  .  j  a v a2 s.  c om
 */
public void showApp() {
    JFrame f = getFrame();
    f.setTitle(getTitle());
    f.getContentPane().add(this, BorderLayout.CENTER);
    f.pack();

    f.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            doExit(true);
        }
    });

    UIHelper.centerWindow(f);
    Rectangle r = f.getBounds();
    int x = AppPreferences.getLocalPrefs().getInt("APP.X", r.x);
    int y = AppPreferences.getLocalPrefs().getInt("APP.Y", r.y);
    int w = AppPreferences.getLocalPrefs().getInt("APP.W", r.width);
    int h = AppPreferences.getLocalPrefs().getInt("APP.H", r.height);
    boolean isMacAndMaxed = UIHelper.isMacOS()
            && AppPreferences.getLocalPrefs().getBoolean("APP.MAXIMIZED", true);
    if (isMacAndMaxed) {
        f.setExtendedState(Frame.MAXIMIZED_BOTH);
    } else {
        UIHelper.positionAndFitToScreen(f, x, y, w, h);
    }
    f.setVisible(true);
}