Search in sources :

Example 31 with SpringLayout

use of javax.swing.SpringLayout in project energy3d by concord-consortium.

the class MainFrame method showPreferences.

void showPreferences() {
    final Runtime runtime = Runtime.getRuntime();
    final JPanel gui = new JPanel(new BorderLayout());
    final JPanel inputPanel = new JPanel(new SpringLayout());
    inputPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    gui.add(inputPanel, BorderLayout.CENTER);
    JLabel label = new JLabel("Maximum memory: ");
    inputPanel.add(label);
    final JTextField maxMemoryField = new JTextField(Math.round(runtime.maxMemory() / (1024.0 * 1024.0)) + " MB");
    maxMemoryField.setEditable(false);
    label.setLabelFor(maxMemoryField);
    inputPanel.add(maxMemoryField);
    label = new JLabel("Total memory: ");
    inputPanel.add(label);
    final JTextField totalMemoryField = new JTextField(Math.round(runtime.totalMemory() / (1024.0 * 1024.0)) + " MB");
    totalMemoryField.setEditable(false);
    label.setLabelFor(totalMemoryField);
    inputPanel.add(totalMemoryField);
    SpringUtilities.makeCompactGrid(inputPanel, 2, 2, 6, 6, 6, 6);
    final Object[] options = new Object[] { "OK", "Cancel" };
    final JOptionPane optionPane = new JOptionPane(new Object[] { "<html><font size=2>System preferences apply to the software.<br>For setting properties of a model, use<br>Edit > Properities.</html>", gui }, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[1]);
    final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "System Information & Preferences");
    dialog.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) SpringLayout(javax.swing.SpringLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Example 32 with SpringLayout

use of javax.swing.SpringLayout in project bioformats by openmicroscopy.

the class SpringUtilities method makeGrid.

/**
 * Aligns the first <code>rows</code> * <code>cols</code>
 * components of <code>parent</code> in
 * a grid. Each component is as big as the maximum
 * preferred width and height of the components.
 * 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 makeGrid(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 makeGrid must use SpringLayout.");
        return;
    }
    Spring xPadSpring = Spring.constant(xPad);
    Spring yPadSpring = Spring.constant(yPad);
    Spring initialXSpring = Spring.constant(initialX);
    Spring initialYSpring = Spring.constant(initialY);
    int max = rows * cols;
    // Calculate Springs that are the max of the width/height so that all
    // cells have the same size.
    Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    for (int i = 1; i < max; i++) {
        SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
        maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
        maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
    }
    // components to have the same size.
    for (int i = 0; i < max; i++) {
        SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
        cons.setWidth(maxWidthSpring);
        cons.setHeight(maxHeightSpring);
    }
    // Then adjust the x/y constraints of all the cells so that they
    // are aligned in a grid.
    SpringLayout.Constraints lastCons = null;
    SpringLayout.Constraints lastRowCons = null;
    for (int i = 0; i < max; i++) {
        SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
        if (i % cols == 0) {
            // start of new row
            lastRowCons = lastCons;
            cons.setX(initialXSpring);
        } else {
            // x position depends on previous component
            cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), xPadSpring));
        }
        if (i / cols == 0) {
            // first row
            cons.setY(initialYSpring);
        } else {
            // y position depends on previous row
            cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), yPadSpring));
        }
        lastCons = cons;
    }
    // Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring.constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
    pCons.setConstraint(SpringLayout.EAST, Spring.sum(Spring.constant(xPad), lastCons.getConstraint(SpringLayout.EAST)));
}
Also used : SpringLayout(javax.swing.SpringLayout) Spring(javax.swing.Spring)

Example 33 with SpringLayout

use of javax.swing.SpringLayout in project uncommons-maths by dwdyer.

the class SpringUtilities method makeGrid.

/**
 * Aligns the first {@code rows} * {@code cols} components of {@code parent}
 * in a grid. Each component is as big as the maximum preferred width and
 * height of the components.  The parent is made just big enough to fit them
 * all.
 * @param parent The container to layout.
 * @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 makeGrid(Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad) {
    if (!(parent.getLayout() instanceof SpringLayout)) {
        throw new IllegalArgumentException("The first argument to makeGrid must use SpringLayout.");
    }
    SpringLayout layout = (SpringLayout) parent.getLayout();
    Spring xPadSpring = Spring.constant(xPad);
    Spring yPadSpring = Spring.constant(yPad);
    Spring initialXSpring = Spring.constant(initialX);
    Spring initialYSpring = Spring.constant(initialY);
    int max = rows * cols;
    // Calculate Springs that are the max of the width/height so that all
    // cells have the same size.
    Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    for (int i = 1; i < max; i++) {
        SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
        maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
        maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
    }
    // components to have the same size.
    for (int i = 0; i < max; i++) {
        SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
        cons.setWidth(maxWidthSpring);
        cons.setHeight(maxHeightSpring);
    }
    // Then adjust the x/y constraints of all the cells so that they
    // are aligned in a grid.
    SpringLayout.Constraints lastConstraints = null;
    SpringLayout.Constraints lastRowConstraints = null;
    for (int i = 0; i < max; i++) {
        SpringLayout.Constraints constraints = layout.getConstraints(parent.getComponent(i));
        if (// Start of new row.
        i % cols == 0) {
            lastRowConstraints = lastConstraints;
            constraints.setX(initialXSpring);
        } else // X position depends on previous component.
        {
            constraints.setX(Spring.sum(lastConstraints.getConstraint(SpringLayout.EAST), xPadSpring));
        }
        if (// First row.
        i / cols == 0) {
            constraints.setY(initialYSpring);
        } else // Y position depends on previous row.
        {
            constraints.setY(Spring.sum(lastRowConstraints.getConstraint(SpringLayout.SOUTH), yPadSpring));
        }
        lastConstraints = constraints;
    }
    // Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring.constant(yPad), lastConstraints.getConstraint(SpringLayout.SOUTH)));
    pCons.setConstraint(SpringLayout.EAST, Spring.sum(Spring.constant(xPad), lastConstraints.getConstraint(SpringLayout.EAST)));
}
Also used : SpringLayout(javax.swing.SpringLayout) Spring(javax.swing.Spring)

Example 34 with SpringLayout

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

the class TabPanel method init.

protected void init() {
    buttonGroup1.add(chkLocalScript);
    buttonGroup1.add(chkRemoteScript);
    chkLocalScript.setToolTipText("Run all of Acs on a single machine (localhost)");
    chkRemoteScript.setToolTipText("Run a distributed Acs on multiple hosts");
    chkLocalScript.setName("chk_Local");
    chkRemoteScript.setName("chk_Remote");
    chkLocalScript.setMnemonic(KeyEvent.VK_L);
    chkRemoteScript.setMnemonic(KeyEvent.VK_R);
    btnMoreContainers = new JButton(new ActionMoreContainers());
    btnLessContainers = new JButton(new ActionLessContainers());
    btnContainersAgainstManager = new JButton(new ActionConfigureAllContainers());
    btnMoveContainerUp = new JButton(new ActionMoveContainerUp());
    btnMoveContainerDown = new JButton(new ActionMoveContainerDown());
    Insets margin = new Insets(1, 0, 1, 0);
    btnMoreContainers.setMargin(margin);
    btnLessContainers.setMargin(margin);
    btnContainersAgainstManager.setMargin(margin);
    btnMoveContainerUp.setMargin(margin);
    btnMoveContainerDown.setMargin(margin);
    this.setLayout(new BorderLayout());
    // -------------------------------------------------------------------
    // general settings
    // -------------------------------------------------------------------
    JPanel generalTab = new JPanel(new BorderLayout());
    JPanel n = new JPanel(new SpringLayout());
    n.add(acsinstanceL = new JLabel("Acs Instance"));
    n.add(acsinstanceF);
    acsinstanceL.setLabelFor(acsinstanceF);
    acsinstanceF.addFocusListener(focusListener);
    acsinstanceF.setToolTipText("The desired Acs instance between 0 and 9)");
    acsinstanceL.setDisplayedMnemonic(KeyEvent.VK_I);
    n.add(cdbrootL = new JLabel("Cdb Root Dir"));
    n.add(cdbrootF);
    cdbrootL.setLabelFor(cdbrootF);
    cdbrootF.addFocusListener(focusListener);
    cdbrootL.setToolTipText("The Cdb describing all components");
    SpringUtilities.makeCompactGrid(n, 2, 0);
    generalTab.add(n);
    acsinstanceF.setName("txt_AcsInstance");
    cdbrootF.setName("txt_CdbRoot");
    // -------------------------------------------------------------------
    // local script settings
    // -------------------------------------------------------------------
    JPanel localScriptTab = new JPanel(new BorderLayout());
    JPanel h = new JPanel(new BorderLayout());
    h.add(chkLocalScript, BorderLayout.NORTH);
    chkLocalScript.addFocusListener(focusListener);
    localScriptTab.add(h);
    // -------------------------------------------------------------------
    // remote settings
    // -------------------------------------------------------------------
    JPanel remoteTab = new JPanel(new BorderLayout());
    JPanel j = new JPanel(new BorderLayout());
    j.add(chkRemoteScript, BorderLayout.NORTH);
    JPanel k = new JPanel(new GridBagLayout());
    buttonGroup3.add(chkRemoteBuiltin);
    buttonGroup3.add(chkRemoteNative);
    buttonGroup3.add(chkRemoteDaemons);
    chkRemoteBuiltin.setToolTipText("Run Acs using built-in ssh client");
    k.add(chkRemoteBuiltin, gridbagpos(0, 0).width(2).gapy(1));
    chkRemoteNative.setToolTipText("Run Acs using the local ssh program");
    k.add(chkRemoteNative, gridbagpos(0, 2).width(2).gapy(1));
    chkRemoteDaemons.setToolTipText("Run Acs using Daemons");
    k.add(chkRemoteDaemons, gridbagpos(1, 0).width(2).gapy(1));
    k.add(hostL = new JLabel("Host"), gridbagpos(2, 0));
    k.add(hostF, gridbagpos(2, 1).width(3));
    chkRemoteScript.addFocusListener(focusListener);
    chkRemoteBuiltin.addFocusListener(focusListener);
    chkRemoteNative.addFocusListener(focusListener);
    chkRemoteDaemons.addFocusListener(focusListener);
    hostF.addFocusListener(focusListener);
    k.add(accountL = new JLabel("User"), gridbagpos(3, 0));
    k.add(accountF, gridbagpos(3, 1));
    accountL.setLabelFor(accountF);
    accountF.addFocusListener(focusListener);
    k.add(passwordL = new JLabel("Pwd"), gridbagpos(3, 2));
    k.add(passwordF, gridbagpos(3, 3).weightx(0.2));
    passwordL.setLabelFor(passwordF);
    passwordF.addFocusListener(focusListener);
    k.setBorder(new EmptyBorder(0, 30, 0, 5));
    j.add(k, BorderLayout.CENTER);
    remoteTab.add(j);
    hostF.setName("txt_RemoteHost");
    accountF.setName("txt_RemoteUser");
    passwordF.setName("txt_RemotePassword");
    // -------------------------------------------------------------------
    // buttons / actions
    // -------------------------------------------------------------------
    actStartContainer = new ActionStartContainer();
    actStopContainer = new ActionStopContainer();
    actConfigureContainer = new ActionConfigureContainer();
    btnStartAcs = new JButton(actStartAcs = new ActionStartAcs());
    btnStopAcs = new JButton(actStopAcs = new ActionStopAcs());
    btnKillAcs = new JButton(actKillAcs = new ActionKillAcs());
    btnStartServices = new JButton(actStartServices = new ActionStartServices());
    btnStopServices = new JButton(actStopServices = new ActionStopServices());
    btnStartManager = new JButton(actStartManager = new ActionStartManager());
    btnStopManager = new JButton(actStopManager = new ActionStopManager());
    btnShowAdvanced = new MyCheckBox(actShowAdvanced = new ActionShowAdvanced());
    btnStartAllContainers = new JButton(actStartAllContainers = new ActionStartAllContainers());
    btnStopAllContainers = new JButton(actStopAllContainers = new ActionStopAllContainers());
    btnStartServices.setToolTipText("Start Services with the specified Common Settings");
    btnStopServices.setToolTipText("Stop the specified Services");
    btnStartManager.setToolTipText("Start a Manager with the specified Common Settings");
    btnStopManager.setToolTipText("Stop the specified Manager");
    btnStopAcs.setToolTipText("Stop Services and Manager AND Containers");
    btnKillAcs.setToolTipText("Terminate Everything related to Acs");
    btnStartAcs.setToolTipText("Start Services and Manager with the specified Common Settings");
    btnShowAdvanced.setToolTipText("Enable/Disable Advanced Controls");
    btnStartServices.setName("btn_Start_Services");
    btnStopServices.setName("btn_Stop_Services");
    btnStartManager.setName("btn_Start_Manager");
    btnStopManager.setName("btn_Stop_Manager");
    btnStopAcs.setName("btn_Stop_Acs");
    btnKillAcs.setName("btn_Kill_Acs");
    btnStartAcs.setName("btn_Start_Acs");
    btnShowAdvanced.setName("btn_Show_Advanced");
    btnStartAcs.setMnemonic(KeyEvent.VK_A);
    btnStopAcs.setMnemonic(KeyEvent.VK_S);
    btnKillAcs.setMnemonic(KeyEvent.VK_K);
    btnShowAdvanced.setMnemonic(KeyEvent.VK_V);
    margin = new Insets(1, 1, 1, 1);
    btnStartServices.setMargin(margin);
    btnStopServices.setMargin(margin);
    btnStartManager.setMargin(margin);
    btnStopManager.setMargin(margin);
    btnShowAdvanced.setMargin(margin);
    margin = new Insets(1, 3, 1, 3);
    btnStartAllContainers.setMargin(margin);
    btnStopAllContainers.setMargin(margin);
    // -------------------------------------------------------------------
    // control section
    // -------------------------------------------------------------------
    controlsPanel = new JPanel();
    controlsPanel.setBorder(master.createTitledBorder(" Acs Suite "));
    buttonPanel = new JPanel(new SpringLayout());
    buttonPanel.add(btnStartAcs);
    flowDialog.disenable(btnStartAcs);
    buttonPanel.add(btnStopAcs);
    flowDialog.disenable(btnStopAcs);
    buttonPanel.add(Box.createVerticalStrut(1));
    buttonPanel.add(new FixSizeSeparator(SwingConstants.HORIZONTAL, new Dimension(10, 3)));
    buttonPanel.add(btnKillAcs);
    flowDialog.disenable(btnKillAcs);
    buttonPanel.add(btnShowAdvanced);
    flowDialog.disenable(btnShowAdvanced);
    SpringUtilities.makeCompactGrid(buttonPanel, 0, 1);
    // -------------------------------------------------------------------
    // advanced section
    // -------------------------------------------------------------------
    panelAdvanced = new JPanel(new BorderLayout());
    buttonPanelAdvanced = new JPanel(new SpringLayout());
    buttonPanelAdvanced.add(new JLabel("Srv"));
    buttonPanelAdvanced.add(btnStartServices);
    flowDialog.disenable(btnStartServices);
    buttonPanelAdvanced.add(btnStopServices);
    flowDialog.disenable(btnStopServices);
    buttonPanelAdvanced.add(new JLabel("Mgr"));
    buttonPanelAdvanced.add(btnStartManager);
    flowDialog.disenable(btnStartManager);
    buttonPanelAdvanced.add(btnStopManager);
    flowDialog.disenable(btnStopManager);
    SpringUtilities.makeCompactGrid(buttonPanelAdvanced, 2, 0);
    panelAdvanced.add(buttonPanelAdvanced, BorderLayout.CENTER);
    controlsPanel.setLayout(new BoxLayout(controlsPanel, BoxLayout.Y_AXIS));
    controlsPanel.add(buttonPanel);
    controlsPanel.add(panelAdvanced);
    makeButtonPair(btnStartAcs, btnStopAcs);
    makeButtonPair(btnStartServices, btnStopServices);
    makeButtonPair(btnStartManager, btnStopManager);
    // -------------------------------------------------------------------
    // container section
    // -------------------------------------------------------------------
    containerPanel = new JPanel(new BorderLayout());
    containerPanel.setBorder(master.createTitledBorder(" Containers "));
    JPanel a = new JPanel(new GridLayout(1, 0));
    a.add(new JLabel("Name", JLabel.CENTER));
    a.add(new JLabel("Type", JLabel.CENTER));
    a.add(new JLabel("Remote Host", JLabel.CENTER));
    a.add(new JLabel());
    containerPanel.add(a, BorderLayout.NORTH);
    containerLinePanel = new JPanel();
    JPanel q = new JPanel(new SpringLayout());
    JPanel scpRoot = new JPanel(new BorderLayout());
    containerLinePanel.setLayout(new GridLayout(0, 1));
    scpRoot.add(containerLinePanel, BorderLayout.NORTH);
    q.add(scpRoot);
    SpringUtilities.makeCompactGrid(q, 1, 1);
    scp = new FixSizeScrollPane(q, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    containerPanel.add(scp, BorderLayout.CENTER);
    // freeze the size of the scrollpane to n containerlines
    ContainerLine filler = new ContainerLine();
    scp.validate();
    // can't find out this value before scrollpane is visible on screen
    int scrollbarWidth = 25;
    // number of lines
    int nLines = 5;
    scp.freezeSize(filler.getPreferredSize().width + scrollbarWidth, // <-- don't ask...
    (filler.getPreferredSize().height + 2) * nLines + 2);
    btnMoreContainers.setToolTipText("More Containers");
    btnLessContainers.setToolTipText("Less Containers (removes Last from List)");
    btnContainersAgainstManager.setToolTipText("Choose Manager and Services to Run Containers Against");
    btnMoveContainerUp.setToolTipText("Move Selected Container Up in List");
    btnMoveContainerDown.setToolTipText("Move Selected Container Down in List");
    btnStartAllContainers.setToolTipText("Start all Containers");
    btnStopAllContainers.setToolTipText("Stop all Containers");
    btnMoreContainers.setName("btn_More_Containers");
    btnLessContainers.setName("btn_Less_Containers");
    btnContainersAgainstManager.setName("btn_Containers_Against_Manager");
    btnMoveContainerUp.setName("btn_Move_Container_Up");
    btnMoveContainerDown.setName("btn_Move_Container_Down");
    btnStartAllContainers.setName("btn_Start_All_Containers");
    btnStopAllContainers.setName("btn_Stop_All_Containers");
    btnMoreContainers.setMnemonic(KeyEvent.VK_DOWN);
    btnLessContainers.setMnemonic(KeyEvent.VK_UP);
    btnContainersAgainstManager.setMnemonic(KeyEvent.VK_C);
    makeButtonPair(btnStartAllContainers, btnStopAllContainers);
    flowDialog.disenable(btnLessContainers);
    flowDialog.disenable(btnStartAllContainers);
    flowDialog.disenable(btnStopAllContainers);
    flowDialog.disenable(btnMoveContainerUp);
    flowDialog.disenable(btnMoveContainerDown);
    flowDialog.disenable(btnContainersAgainstManager);
    JPanel southwest = new JPanel();
    southwest.setLayout(new SpringLayout());
    southwest.add(btnMoreContainers);
    southwest.add(btnLessContainers);
    southwest.add(btnMoveContainerUp);
    southwest.add(btnMoveContainerDown);
    southwest.add(new FixSizeSeparator(SwingConstants.VERTICAL, new Dimension(4, 10)));
    southwest.add(btnContainersAgainstManager);
    SpringUtilities.makeCompactGrid(southwest, 1, 0);
    JPanel southeast = new JPanel(new SpringLayout());
    southeast.add(btnStartAllContainers);
    southeast.add(btnStopAllContainers);
    SpringUtilities.makeCompactGrid(southeast, 1, 0);
    JPanel south = new JPanel();
    south.setLayout(new BoxLayout(south, BoxLayout.X_AXIS));
    south.add(southwest);
    south.add(Box.createHorizontalGlue());
    south.add(southeast);
    containerPanel.add(south, BorderLayout.SOUTH);
    // -------------------------------------------------------------------
    // assemble / layout
    // -------------------------------------------------------------------
    Box commonSettingsPanel = new Box(BoxLayout.Y_AXIS);
    commonSettingsPanel.add(generalTab);
    commonSettingsPanel.add(Box.createVerticalStrut(10));
    commonSettingsPanel.add(localScriptTab);
    commonSettingsPanel.add(Box.createVerticalStrut(10));
    commonSettingsPanel.add(remoteTab);
    commonSettingsPanel.add(Box.createVerticalStrut(10));
    commonSettingsPanel.setBorder(master.createTitledBorder(" Common Settings "));
    JPanel tabbedPanelLeft = new JPanel(new BorderLayout());
    tabbedPanelLeft.add(commonSettingsPanel, BorderLayout.NORTH);
    Box tabbedPane1Right = new Box(BoxLayout.Y_AXIS);
    tabbedPane1Right.add(controlsPanel);
    tabbedPane1Right.add(Box.createVerticalStrut(10));
    tabbedPane1Right.add(containerPanel);
    Box tabbedPane1 = Box.createHorizontalBox();
    tabbedPane1.add(tabbedPanelLeft);
    tabbedPane1.add(tabbedPane1Right);
    this.setLayout(new GridBagLayout());
    this.add(commonSettingsPanel, gridbagpos(0, 0).weightx(0.2).align(GridBag.NORTHEAST));
    this.add(controlsPanel, gridbagpos(0, 1).align(GridBag.NORTHEAST));
    this.add(containerPanel, gridbagpos(1, 0).width(2).align(GridBag.NORTHEAST));
    // -------------------------------------------------------------------
    // select some checkboxes, etc.
    // -------------------------------------------------------------------
    disenabler = new Disenabler();
    chkRemoteBuiltin.setSelected(true);
    chkLocalScript.setSelected(true);
    btnShowAdvanced.setSelected(false);
}
Also used : JPanel(javax.swing.JPanel) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) EmptyBorder(javax.swing.border.EmptyBorder) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) SpringLayout(javax.swing.SpringLayout)

Example 35 with SpringLayout

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

the class SpringUtilities method makeGrid.

/**
    * Aligns the first <code>rows</code> * <code>cols</code>
    * components of <code>parent</code> in
    * a grid. Each component is as big as the maximum
    * preferred width and height of the components.
    * 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
    */
@SuppressWarnings("null")
public static void makeGrid(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 makeGrid must use SpringLayout.");
        return;
    }
    Spring xPadSpring = Spring.constant(xPad);
    Spring yPadSpring = Spring.constant(yPad);
    Spring initialXSpring = Spring.constant(initialX);
    Spring initialYSpring = Spring.constant(initialY);
    int max = rows * cols;
    //Calculate Springs that are the max of the width/height so that all
    //cells have the same size.
    Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).getWidth();
    for (int i = 1; i < max; i++) {
        SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
        maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
        maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
    }
    //components to have the same size.
    for (int i = 0; i < max; i++) {
        SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
        cons.setWidth(maxWidthSpring);
        cons.setHeight(maxHeightSpring);
    }
    //Then adjust the x/y constraints of all the cells so that they
    //are aligned in a grid.
    SpringLayout.Constraints lastCons = null;
    SpringLayout.Constraints lastRowCons = null;
    for (int i = 0; i < max; i++) {
        SpringLayout.Constraints cons = layout.getConstraints(parent.getComponent(i));
        if (i % cols == 0) {
            //start of new row
            lastRowCons = lastCons;
            cons.setX(initialXSpring);
        } else {
            //x position depends on previous component
            cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), xPadSpring));
        }
        if (i / cols == 0) {
            //first row
            cons.setY(initialYSpring);
        } else {
            //y position depends on previous row
            cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), yPadSpring));
        }
        lastCons = cons;
    }
    //Set the parent's size.
    SpringLayout.Constraints pCons = layout.getConstraints(parent);
    pCons.setConstraint(SpringLayout.SOUTH, Spring.sum(Spring.constant(yPad), lastCons.getConstraint(SpringLayout.SOUTH)));
    pCons.setConstraint(SpringLayout.EAST, Spring.sum(Spring.constant(xPad), lastCons.getConstraint(SpringLayout.EAST)));
}
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