Search in sources :

Example 1 with SpringLayout

use of javax.swing.SpringLayout in project ACS by ACS-Community.

the class SpringUtilities method makeCompactGrid.

/**
    * Aligns the first <code>rows</code> * <code>cols</code>
    * components of <code>parent</code> in
    * a grid. Each component in a column is as wide as the maximum
    * preferred width of the components in that column;
    * height is similarly determined for each row.
    * The parent is made just big enough to fit them all.
    *
    * @param rows number of rows - 0 means 'as needed'
    * @param cols number of columns - 0 means 'as needed'
    * @param initialX x location to start the grid at
    * @param initialY y location to start the grid at
    * @param xPad x padding between cells
    * @param yPad y padding between cells
    */
public static void makeCompactGrid(Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad) {
    // msc: added ----------
    if (rows == 0 && cols == 0)
        throw new IllegalArgumentException("rows and cols cannot both be 0");
    if (rows == 0) {
        rows = (int) Math.ceil(parent.getComponentCount() / cols);
    }
    if (cols == 0) {
        cols = (int) Math.ceil(parent.getComponentCount() / rows);
    }
    // ---------------------
    SpringLayout layout;
    try {
        layout = (SpringLayout) parent.getLayout();
    } catch (ClassCastException exc) {
        System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
        return;
    }
    //Align all cells in each column and make them the same width.
    Spring x = Spring.constant(initialX);
    for (int c = 0; c < cols; c++) {
        Spring width = Spring.constant(0);
        for (int r = 0; r < rows; r++) {
            width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
        }
        for (int r = 0; r < rows; r++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setX(x);
            constraints.setWidth(width);
        }
        x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
    }
    //Align all cells in each row and make them the same height.
    Spring y = Spring.constant(initialY);
    for (int r = 0; r < rows; r++) {
        Spring height = Spring.constant(0);
        for (int c = 0; c < cols; c++) {
            height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
        }
        for (int c = 0; c < cols; c++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setY(y);
            constraints.setHeight(height);
        }
        y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
    }
    //Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(SpringLayout.SOUTH, y);
    pCons.setConstraint(SpringLayout.EAST, x);
}
Also used : SpringLayout(javax.swing.SpringLayout) Spring(javax.swing.Spring)

Example 2 with SpringLayout

use of javax.swing.SpringLayout in project ACS by ACS-Community.

the class SpringUtilities method getConstraintsForCell.

/* Used by makeCompactGrid. */
private static SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent, int cols) {
    SpringLayout layout = (SpringLayout) parent.getLayout();
    Component c = parent.getComponent(row * cols + col);
    return layout.getConstraints(c);
}
Also used : SpringLayout(javax.swing.SpringLayout) Component(java.awt.Component)

Example 3 with SpringLayout

use of javax.swing.SpringLayout in project ACS by ACS-Community.

the class CommandCenterGui method prepare.

public void prepare() {
    boolean setLookAndFeel = false;
    if (setLookAndFeel) {
        String lafName = UIManager.getSystemLookAndFeelClassName();
        try {
            UIManager.setLookAndFeel(lafName);
        } catch (Exception exc) {
            log.fine("Couldn't set look and feel " + lafName + " due to " + exc);
        }
    }
    // title added later in doFrameTitle()
    frame = new JFrame("");
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent evt) {
            controller.stop();
        }
    });
    dlgContainerSettings = new EditContainerSettingsDialog(this);
    frontPanel = new TabPanel(this);
    writeModelToFrontPanel();
    // Splitter between tree and the rest
    splitLeftRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitLeftRight.setOneTouchExpandable(true);
    JPanel p2 = new JPanel(new BorderLayout());
    p2.setBorder(new EmptyBorder(10, 10, 10, 10));
    p2.add(frontPanel, BorderLayout.NORTH);
    splitLeftRight.setLeftComponent(p2);
    // Deployment Tree
    deploymentInfoPanel = new JPanel(new BorderLayout());
    deploymentInfoPanel.setBorder(new CompoundBorder(new EmptyBorder(5, 7, 5, 7), new TitledBorder(LineBorder.createBlackLineBorder(), " Deployment Info ")));
    deployTree = new DeploymentTree(controller.deploymentTreeControllerImpl);
    JPanel addToDeployTree = new AddToDeployTree(this, deployTree);
    deploymentInfoPanel.add(addToDeployTree, BorderLayout.NORTH);
    deploymentInfoPanel.add(new JScrollPane(deployTree), BorderLayout.CENTER);
    splitLeftRight.setRightComponent(deploymentInfoPanel);
    // Feedback Area
    feedbackTabs = new FeedbackTabs(this, FeedbackTabs.BOTTOM);
    // Logo Panel
    JPanel logoPanel = new LogoPanel(COLOR_LogoBackground_A, COLOR_LogoBackground_B);
    logoPanel.setLayout(new BorderLayout());
    JLabel alma = new JLabel(new ImageIcon(controller.findResource("alma.jpg")));
    logoPanel.add(alma, BorderLayout.WEST);
    JLabel text = new JLabel("Acs Command Center");
    text.setForeground(COLOR_LogoForeground);
    text.setHorizontalTextPosition(SwingConstants.CENTER);
    text.setFont(text.getFont().deriveFont((float) (text.getFont().getSize() * 2.5)));
    text.setBorder(new EmptyBorder(5, 30, 5, 30));
    logoPanel.add(text, BorderLayout.CENTER);
    //		JLabel version = new JLabel(controller.version());
    //		version.setForeground(COLOR_LogoForeground);
    //		version.setBorder(new EmptyBorder(0, 0, 0, 4));
    //		JPanel pnl2 = new JPanel(new BorderLayout());
    //		pnl2.setOpaque(false);
    //		pnl2.add(version, BorderLayout.SOUTH);
    //		logoPanel.add(pnl2, BorderLayout.EAST);
    menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu("Project");
    fileMenu.setMnemonic(KeyEvent.VK_P);
    {
        JMenu newMenu = new JMenu("New");
        newMenu.add(new ActionNewProject("Project"));
        fileMenu.add(newMenu);
    }
    fileMenu.add(new ActionOpenProject("Open..."));
    fileMenu.add(new ActionSaveProject("Save"));
    fileMenu.add(new ActionSaveAsProject("Save As..."));
    fileMenu.addSeparator();
    fileMenu.add(new ActionExit("Exit"));
    menuBar.add(fileMenu);
    toolsMenu = new JMenu("Tools");
    toolsMenu.setMnemonic(KeyEvent.VK_T);
    toolsMenu.add(new ActionConfigureTools("Configure Tools..."));
    toolsMenu.addSeparator();
    menuBar.add(toolsMenu);
    // ---
    JMenu extrasMenu = new JMenu("Expert");
    extrasMenu.setMnemonic(KeyEvent.VK_E);
    {
        //				JMenu sshMode = new JMenu("SSH Library");
        //				sshMode.add(new ActionSetSshMode("Platform-independent", false, false));
        //				sshMode.add(new ActionSetSshMode("Natively installed ssh", true, true));
        //				extrasMenu.add(sshMode);
        //				extrasMenu.add(new JSeparator());
        JMenu extraTools = new JMenu("Tools Menu");
        extraTools.add(new ActionShowExtraTools("View..."));
        extraTools.add(new ActionInstallExtraTools("Replace..."));
        extrasMenu.add(extraTools);
        JMenu builtinTools = new JMenu("Acs Scripts");
        builtinTools.add(new ActionShowBuiltinTools("View..."));
        builtinTools.add(new ActionLoadBuiltinTools("Replace..."));
        extrasMenu.add(builtinTools);
    }
    extrasMenu.add(new JSeparator());
    extrasMenu.add(new ActionShowVariables("Variables..."));
    menuBar.add(extrasMenu);
    // ---
    JMenuItem item;
    JMenu helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);
    item = helpMenu.add(new ActionShowHelp("Online Help"));
    item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    item = helpMenu.add(new ActionShowAbout("About"));
    menuBar.add(Box.createHorizontalGlue());
    menuBar.add(helpMenu);
    // ---
    JPanel h = new JPanel(new SpringLayout());
    h.add(logoPanel);
    h.add(menuBar);
    SpringUtilities.makeCompactGrid(h, 0, 1);
    frame.getContentPane().add(h, BorderLayout.NORTH);
    // ---
    pnlManagerLocationForTools = new ManagerLocationPanel.ForTools();
    managerLocationDialog1 = new BasicDialog(this, "Specify Manager and Services for Tools", "Set", pnlManagerLocationForTools);
    // ---
    pnlManagerLocationForContainers = new ManagerLocationPanel.ForContainers();
    managerLocationDialog2 = new BasicDialog(this, "Specify Manager and Services for Containers", "Set", pnlManagerLocationForContainers);
    // ---
    splitTopBottom = new JSplitPane(JSplitPane.VERTICAL_SPLIT, splitLeftRight, feedbackTabs);
    splitTopBottom.setOneTouchExpandable(true);
    // --- 
    // 2009-04: Introducing a desktop layout so i can make the
    // progress dialog a lightweight window on top the front panel
    AccInternalFrame bigInternalFrame = new AccInternalFrame();
    bigInternalFrame.add(splitTopBottom);
    desktop = new JDesktopPane();
    bigInternalFrame.setVisible(true);
    desktop.add(bigInternalFrame);
    frame.getContentPane().add(desktop, BorderLayout.CENTER);
    try {
        bigInternalFrame.setSelected(true);
        bigInternalFrame.setMaximum(true);
    } catch (PropertyVetoException exc) {
    }
    // for mysterious swing reasons, the desktop has a preferred size
    // of (1,1) instead of picking up the preferred size of its child
    // component, so i'm doing this manually here.
    desktop.setPreferredSize(bigInternalFrame.getPreferredSize());
    doFrameTitle();
}
Also used : JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) JDesktopPane(javax.swing.JDesktopPane) WindowAdapter(java.awt.event.WindowAdapter) TitledBorder(javax.swing.border.TitledBorder) JSeparator(javax.swing.JSeparator) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) JMenuItem(javax.swing.JMenuItem) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) PropertyVetoException(java.beans.PropertyVetoException) UnresolvableException(alma.acs.commandcenter.util.VariableString.UnresolvableException) PropertyVetoException(java.beans.PropertyVetoException) WindowEvent(java.awt.event.WindowEvent) SpringLayout(javax.swing.SpringLayout) JSplitPane(javax.swing.JSplitPane) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 4 with SpringLayout

use of javax.swing.SpringLayout in project BIMserver by opensourceBIM.

the class SpringUtilities method getConstraintsForCell.

/* Used by makeCompactGrid. */
private static SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent, int cols) {
    SpringLayout layout = (SpringLayout) parent.getLayout();
    Component c = parent.getComponent(row * cols + col);
    return layout.getConstraints(c);
}
Also used : SpringLayout(javax.swing.SpringLayout) Component(java.awt.Component)

Example 5 with SpringLayout

use of javax.swing.SpringLayout in project BIMserver by opensourceBIM.

the class SpringUtilities method makeCompactGrid.

/**
 * Aligns the first <code>rows</code> * <code>cols</code>
 * components of <code>parent</code> in
 * a grid. Each component in a column is as wide as the maximum
 * preferred width of the components in that column;
 * height is similarly determined for each row.
 * The parent is made just big enough to fit them all.
 *
 * @param rows number of rows
 * @param cols number of columns
 * @param initialX x location to start the grid at
 * @param initialY y location to start the grid at
 * @param xPad x padding between cells
 * @param yPad y padding between cells
 */
public static void makeCompactGrid(Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad) {
    SpringLayout layout;
    try {
        layout = (SpringLayout) parent.getLayout();
    } catch (ClassCastException exc) {
        System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
        return;
    }
    // Align all cells in each column and make them the same width.
    Spring x = Spring.constant(initialX);
    for (int c = 0; c < cols; c++) {
        Spring width = Spring.constant(0);
        for (int r = 0; r < rows; r++) {
            width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
        }
        for (int r = 0; r < rows; r++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setX(x);
            constraints.setWidth(width);
        }
        x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
    }
    // Align all cells in each row and make them the same height.
    Spring y = Spring.constant(initialY);
    for (int r = 0; r < rows; r++) {
        Spring height = Spring.constant(0);
        for (int c = 0; c < cols; c++) {
            height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
        }
        for (int c = 0; c < cols; c++) {
            SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
            constraints.setY(y);
            constraints.setHeight(height);
        }
        y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
    }
    // Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(SpringLayout.SOUTH, y);
    pCons.setConstraint(SpringLayout.EAST, x);
}
Also used : SpringLayout(javax.swing.SpringLayout) Spring(javax.swing.Spring)

Aggregations

SpringLayout (javax.swing.SpringLayout)57 JLabel (javax.swing.JLabel)21 JPanel (javax.swing.JPanel)21 Spring (javax.swing.Spring)21 BorderLayout (java.awt.BorderLayout)18 JTextField (javax.swing.JTextField)17 ActionEvent (java.awt.event.ActionEvent)15 ActionListener (java.awt.event.ActionListener)15 Component (java.awt.Component)12 JDialog (javax.swing.JDialog)12 Dimension (java.awt.Dimension)11 JButton (javax.swing.JButton)10 JScrollPane (javax.swing.JScrollPane)10 EmptyBorder (javax.swing.border.EmptyBorder)9 FlowLayout (java.awt.FlowLayout)8 JMenuItem (javax.swing.JMenuItem)7 Constraints (javax.swing.SpringLayout.Constraints)6 ItemEvent (java.awt.event.ItemEvent)5 Callable (java.util.concurrent.Callable)5 JMenu (javax.swing.JMenu)5