Example usage for com.jgoodies.forms.builder DefaultFormBuilder DefaultFormBuilder

List of usage examples for com.jgoodies.forms.builder DefaultFormBuilder DefaultFormBuilder

Introduction

In this page you can find the example usage for com.jgoodies.forms.builder DefaultFormBuilder DefaultFormBuilder.

Prototype

public DefaultFormBuilder(FormLayout layout) 

Source Link

Document

Constructs a DefaultFormBuilder for the given layout.

Usage

From source file:ai.aitia.meme.utils.FormsUtils.java

License:Open Source License

/**
 * Returns a DefaultFormBuilder containing the specified components and layout.
 * @param cols This parameter corresponds to the <code>encodedColumnSpecs</code> 
 *   parameter of FormLayout's ctor. Besides the encoding defined by FormLayout, 
 *   the following extensions are also available: the characters defined in the 
 *   global <code>{@link #gapLength}</code> variable (hereafter: gap-characters) 
 *   can be used to insert gap-columns. Gap columns must not appear in the 
 *   cell-specification (explained below) and they're automatically included in
 *   column spans. /*from   w  ww  .  j a va 2 s .  com*/
 *   Consecutive gap-characters are coalesced into 1 gap column by calculating
 *   their cumulated pixel size.
 * @param rows A string describing general builder settings + cell-specification 
 *   + row/colum spans + row heights + row groups. See the examples. 
 *   The digits and underscores specify which component goes into which cell(s) 
 *   of the layout grid (cell-specification). There can be at most one character 
 *   for every (non-gap) column specified by <code>cols</code>. Rows must be 
 *   separated by the '|' character. Only underscores, digits and letters are 
 *   allowed in the cell-specification (space isn't). Underscore means that a 
 *   cell is empty. A digit/letter character refers to a component in the varargs 
 *   list: '0'..'9', 'A'..'Z', 'a'..'z' (in this order) denote the first 62 
 *   components of the <code>args</code> list. Repeating the same digit specifies
 *   the component's column span (and row span, if repeated in consecutive rows
 *   in the same columns, like '3' in the example).<br> 
 *   After the cell-specification, but before the newline ('|') character
 *   the row height and row grouping can also be specified. It must begin 
 *   with a space to separate it from the cell-specification. The row
 *   height can be a gap-character (for constant heights only) or a string
 *   that is interpreted by RowSpec.decodeSpecs(). If omitted, the height 
 *   spec. of the most recent row is inherited. Content rows inherit the 
 *   height of the previous content row, gap rows inherit the height of 
 *   the previous gap row. A row is a gap row if its cell-specification is
 *   omitted.<br> 
 *   Row grouping forces equal heights to every member of the group. It  
 *   can be specified by "grp?" strings using any character in place of
 *   '?' (except space and '|'. In the example 'grp1' uses '1'). Rows 
 *   using the same grouping character will be in the same group.
 *   By default there're no groups.
 *    <br>
 *   General builder-settings can be specified at the beginning of the 
 *   string, enclosed in square brackets ([..]). (No space is allowed
 *   after the closing ']'). This is intended for future extensions, too. 
 *   The list of available settings is described at the {@link Prop} 
 *   enumeration. Note that setting names are case-sensitive, and should 
 *   be separated by commas.
 * @param args List of components. Besides java.awt.Component objects,
 *   the caller may use plain strings and instances of the {@link Separator}
 *   class. Plain strings are used to create labels (with mnemonic-expansion). 
 *   Separator objects will create and add separators to the form. 
 *   Any of these objects may be followed optionally by a {@link CellConstraints},
 *   a {@link CellConstraints.Alignment} or a {@link CellInsets} object, 
 *   which overrides the cell's default alignment, can extend its row/column 
 *   span and adjust its insets.<br>
 *   If the first element of <code>args</code> is a java.util.Map object,
 *   it is treated as an additional mapping for gap-characters. This 
 *   overrides the default global mapping. Note that gap-characters can 
 *   help you to set up uniform spacing on your forms. For example, if
 *   you use "-" as normal column-gap and "~" as normal row-gap, fine-tuning
 *   the sizes of these gaps later is as easy as changing the mapping for "-"
 *   and "~" &mdash; there's no need to update all the dlu sizes in all layouts.
 * @see   
 *   Example1: <pre>
  *       build("6dlu, p, 6dlu, 50dlu, 6dlu", 
  *                "_0_1_ pref| 6dlu|" + 
 *                "_2_33 pref:grow(0.5) grp1||" +
 *                "_4_33 grp1",
 *                component0, component1, component2, component3,
 *                component4, cellConstraintsForComponent4).getPanel()
 * </pre>
 *   The same exaple with gap-characters: <pre>
  *       build("~ p ~ 50dlu, 6dlu", 
  *                "01_ pref|~|" + 
 *                "233 pref:grow(0.5) grp1||" +
 *                "433 grp1",
 *                component0, component1, component2, component3,
 *                component4, cellConstraintsForComponent4).getPanel()
 * </pre>
 *   Example3 (only the second argument): <pre>
 *       "[LineGapSize=6dlu, ParagraphGapSize=20dlu]_0_1||_2_3||_4_5"
 * </pre>
 *  Note: this method can be used with no components and empty cell-specification,
 *  too. In this case only a {@link DefaultFormBuilder} is created, configured 
 *  and returned. Its operations can then be used to append components to the form.
 */
@SuppressWarnings("unchecked")
public static DefaultFormBuilder build(String cols, String rows, Object... args) {
    Context ctx = new Context();

    // Parse column widths
    //
    int firstArg = 0;
    if (args.length > 0 && args[0] instanceof java.util.Map) {
        ctx.localGapSpec = (java.util.Map<Character, String>) args[0];
        firstArg += 1;
    }
    StringBuilder colstmp = new StringBuilder();
    ctx.contentCol = parseColumnWidths(colstmp, cols, ctx.localGapSpec, 0);

    // Parse the list of components (may include individual cell-constraints)
    //
    ctx.components = new ArrayList<Rec>(args.length);
    for (int i = firstArg; i < args.length; ++i) {
        Rec r = new Rec(args[i]);
        if (i + 1 < args.length) {
            if (args[i + 1] instanceof CellConstraints) {
                r.cc = (CellConstraints) args[++i];
                r.useAlignment = true;
            } else if (args[i + 1] instanceof CellConstraints.Alignment) {
                CellConstraints.Alignment a = (CellConstraints.Alignment) args[++i];
                if (a == CellConstraints.BOTTOM || a == CellConstraints.TOP)
                    r.cc = new CellConstraints(1, 1, CellConstraints.DEFAULT, a);
                else if (a == CellConstraints.LEFT || a == CellConstraints.RIGHT)
                    r.cc = new CellConstraints(1, 1, a, CellConstraints.DEFAULT);
                else if (a == CellConstraints.CENTER || a == CellConstraints.FILL)
                    r.cc = new CellConstraints(1, 1, a, a);
                r.useAlignment = (r.cc != null);
            } else if (args[i + 1] instanceof CellInsets) {
                CellInsets ci = ((CellInsets) args[++i]);
                r.cc = ci.cc;
                r.useAlignment = ci.useAlignment;
                r.useInsets = true;
                //}
                //else if (args[i+1] == null) {   // this would allow superfluous 'null' values
                //   i += 1;
            }
        }
        ctx.components.add(r);
    }

    // Parse general settings (but don't apply yet) 
    //
    EnumMap<Prop, Object> props = null;
    int i = rows.indexOf(']');
    if (i >= 0) {
        String defaults = rows.substring(0, i);
        rows = rows.substring(++i);
        i = defaults.indexOf('[');
        ctx.input = defaults.substring(++i);
        props = Prop.parseGeneralSettings(ctx);
    }

    // Parse cell-specification, row heights and row groups
    //
    String cells[] = rows.split("\\|", -1);
    StringBuilder rowstmp = new StringBuilder();
    java.util.HashMap<Character, int[]> rowGroups = new HashMap<Character, int[]>();
    String lastContentRowHeight = "p", lastGapRowHeight = null;
    int rowcnt = 0;
    for (i = 0; i < cells.length; ++i) {
        rowcnt += 1;
        // See if it begins with a gap-character
        String g = (cells[i].length() > 0) ? getGap(cells[i].charAt(0), ctx.localGapSpec) : null;
        if (g != null)
            cells[i] = ' ' + cells[i];
        int j = cells[i].indexOf(' ');
        boolean gapRow = (j == 0) || (cells[i].length() == 0);
        String rh = null;
        if (j >= 0) {
            String tmp[] = cells[i].substring(j + 1).split("\\s"); // expect height and grouping specifications 
            cells[i] = cells[i].substring(0, j);
            ArrayList<String> gaps = new ArrayList<String>();
            for (j = 0; j < tmp.length; ++j) {
                if (tmp[j].length() == 0)
                    continue;
                if (tmp[j].length() == 4 && tmp[j].toLowerCase().startsWith("grp")) {
                    Character groupch = tmp[j].charAt(3);
                    rowGroups.put(groupch, appendIntArray(rowGroups.get(groupch), rowcnt));
                } else {
                    rh = tmp[j];
                    for (int k = 0, n = tmp[j].length(); k < n
                            && addGap(gaps, getGap(tmp[j].charAt(k), ctx.localGapSpec)); ++k)
                        ;
                }
            }
            if (!gaps.isEmpty()) {
                StringBuilder sb = new StringBuilder();
                flushGaps(gaps, sb, false);
                rh = sb.substring(0, sb.length() - 1);
            }
        }
        if (rh == null) {
            if (gapRow && lastGapRowHeight == null) {
                ctx.b = new DefaultFormBuilder(new FormLayout(colstmp.toString(), ""));
                Prop.setBuilder(props, ctx);
                lastGapRowHeight = parseableRowSpec(ctx.b.getLineGapSpec());
            }
            rh = gapRow ? lastGapRowHeight : lastContentRowHeight;
        } else {
            if (gapRow)
                lastGapRowHeight = rh;
            else
                lastContentRowHeight = rh;
        }
        if (i > 0)
            rowstmp.append(',');
        rowstmp.append(rh);
    }

    // Create builder
    //
    FormLayout fml = new FormLayout(colstmp.toString(), rowstmp.toString());
    ctx.b = new DefaultFormBuilder(fml, debuggable());

    // Apply builder settings (e.g. column groups)
    //
    Prop.setBuilder(props, ctx);
    props = null;

    // Set row groups
    //
    if (!rowGroups.isEmpty()) {
        int[][] tmp = new int[rowGroups.size()][]; // ???
        i = 0;
        for (int[] a : rowGroups.values())
            tmp[i++] = a;
        fml.setRowGroups(tmp);
    }
    rowGroups = null;

    JLabel lastLabel = null;
    java.util.HashSet<Character> done = new java.util.HashSet<Character>(ctx.components.size());
    int h = cells.length;
    for (int y = 0; y < cells.length; ++y) {
        int w = cells[y].length();
        int first = -1;
        for (int x = 0; x < w; ++x) {
            char ch = cells[y].charAt(x);
            if (ch == '_' || done.contains(ch))
                continue;
            int idx = intValue(ch);

            Rec rec;
            try {
                rec = ctx.components.get(idx);
            } catch (IndexOutOfBoundsException e) {
                throw new IndexOutOfBoundsException(
                        String.format("build() cells=\"%s\" ch=%c rows=\"%s\"", cells[y], ch, rows));
            }
            CellConstraints cc = (rec.cc == null) ? new CellConstraints() : (CellConstraints) rec.cc.clone();

            int sx = cc.gridWidth, sy = cc.gridHeight; // span x, span y
            while (x + sx < w && cells[y].charAt(x + sx) == ch)
                sx += 1;
            while (y + sy < h && ((x < cells[y + sy].length() && cells[y + sy].charAt(x) == ch)
                    || (cells[y + sy].length() == 0 && y + sy + 1 < h && x < cells[y + sy + 1].length()
                            && cells[y + sy + 1].charAt(x) == ch))) {
                sy += 1;
            }
            int colSpan = ctx.contentCol[x + sx - 1] - ctx.contentCol[x] + 1;
            ctx.b.setBounds(ctx.contentCol[x] + 1, ctx.b.getRow(), colSpan, sy);
            ctx.b.setLeadingColumnOffset(first & ctx.contentCol[x]); // 0 vagy x (itt nem kell a +1)
            first = 0;
            x += (sx - 1);

            Object comp = ctx.components.get(idx).component;
            if (comp instanceof Component) {
                ctx.b.append((Component) comp, colSpan);
                if (comp instanceof JLabel)
                    lastLabel = (JLabel) comp;
                else {
                    if (lastLabel != null)
                        lastLabel.setLabelFor((Component) comp);
                    lastLabel = null;
                }
            } else if (comp instanceof Separator) {
                comp = ctx.b.appendSeparator(comp.toString());
                lastLabel = null;
            } else {
                comp = lastLabel = ctx.b.getComponentFactory().createLabel(comp.toString());
                ctx.b.append(lastLabel, colSpan);
            }
            if (rec.useAlignment || rec.useInsets) {
                CellConstraints cc2 = fml.getConstraints((Component) comp);
                cc2.insets = cc.insets;
                cc2.hAlign = cc.hAlign;
                cc2.vAlign = cc.vAlign;
                fml.setConstraints((Component) comp, cc2);
            }

            done.add(ch);
        }
        lastLabel = null;
        ctx.b.nextLine();
    }
    return ctx.b;
}

From source file:be.ac.ua.comp.scarletnebula.gui.addproviderwizard.ChooseNamePage.java

License:Open Source License

ChooseNamePage(final AddProviderWizardDataRecorder recorder) {
    setLayout(new BorderLayout());
    final BetterTextLabel text = new BetterTextLabel(
            "What name would you like to use to describe this account with " + recorder.getTemplate().getName()
                    + "?");
    text.setBorder(BorderFactory.createEmptyBorder(10, 10, 20, 10));
    add(text, BorderLayout.NORTH);

    // And the textfields below
    final FormLayout layout = new FormLayout("right:max(40dlu;p), 4dlu, max(50dlu;p):grow, 7dlu", "");

    final DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();//from  w  w w.j  a  va  2  s . co m

    builder.append("Account Name", name);
    add(builder.getPanel());

    // Prefill the textfield with something useful

    name.setText(recorder.getTemplate().getShortName()
            + (recorder.getEndpoint() != null ? " (" + recorder.getEndpoint().getShortName() + ")" : ""));
    name.setPreferredSize(name.getMinimumSize());

}

From source file:be.ac.ua.comp.scarletnebula.gui.addproviderwizard.ProvideAccessPage.java

License:Open Source License

public ProvideAccessPage(final AddProviderWizardDataRecorder rec) {
    setLayout(new BorderLayout());

    final String toptext;
    if (rec.getTemplate().getAccessMethod() == AccessMethod.KEY) {
        toptext = "Please enter the API Access Key that identifies your account and the API Secret that represents your password.";
    } else {/*from www . jav  a  2s .  c o  m*/
        toptext = "Enter the email address and password you used to register with "
                + rec.getTemplate().getName() + ".";
    }

    // The text on top
    final BetterTextLabel txt = new BetterTextLabel(toptext);

    txt.setBorder(BorderFactory.createEmptyBorder(10, 10, 20, 10));

    // And the textfields below
    final FormLayout layout = new FormLayout("right:max(40dlu;p), 4dlu, max(50dlu;p):grow", "");

    final DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();

    final String loginLabel;
    final String passwordLabel;
    if (rec.getTemplate().getAccessMethod() == AccessMethod.KEY) {
        loginLabel = "API Key";
        passwordLabel = "API Secret";
    } else {
        loginLabel = "Email address";
        passwordLabel = "Password";
    }
    builder.append(loginLabel, apiKey);
    builder.nextLine();
    builder.append(passwordLabel, apiSecret);

    add(txt, BorderLayout.NORTH);
    add(builder.getPanel());
}

From source file:be.ac.ua.comp.scarletnebula.gui.addserverwizard.FinalServerAddPage.java

License:Open Source License

public FinalServerAddPage(final AddServerWizardDataRecorder rec) {
    super(new BorderLayout());
    final BetterTextLabel lbl = new BetterTextLabel(
            "<html><font size=\"4\">Press <b><font color=\"green\">Finish</font></b> to start the server.</font>");
    lbl.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
    lbl.setAlignmentX(CENTER_ALIGNMENT);

    add(lbl, BorderLayout.NORTH);

    instanceNameField.setInputVerifier(new ServernameInputVerifier(instanceNameField));
    instanceNameField.setText(rec.provider.getName() + "-" + rec.provider.listLinkedServers().size());
    instanceNameField.selectAll();//from   w w  w . ja  va  2 s.c o  m

    final FormLayout layout = new FormLayout("right:max(40dlu;p):grow, 7dlu, max(80dlu;p):grow", "");

    final DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();

    builder.append("Instance Name", instanceNameField);
    builder.nextLine();
    instanceCountTextField
            .setInputVerifier(new NumberInputVerifier(instanceCountTextField, "Only number allowed."));

    builder.append("Nr of instances to start", new LabelEditSwitcherPanel("1", instanceCountTextField));

    vlanField.setInputVerifier(new PlainTextVerifier(vlanField, "Only plain text allowed."));
    // builder.append("VLAN id", new LabelEditSwitcherPanel("(None)",
    // vlanField));

    if (rec.provider.supportsSSHKeys()) {
        rec.keypairOrPassword = rec.provider.getDefaultKeypair();
        final ChangeableLabel sshKeyLabel = new ChangeableLabel(rec.keypairOrPassword,
                new Executable<JLabel>() {

                    @Override
                    public void run(final JLabel param) {
                        new SelectKeyWindow((JDialog) Utils.findWindow(FinalServerAddPage.this), rec.provider) {
                            private static final long serialVersionUID = 1L;

                            @Override
                            public void onOk(final String keyname) {
                                if (!keyname.isEmpty()) {
                                    rec.keypairOrPassword = keyname;
                                    param.setText(keyname);
                                    dispose();
                                } else {
                                    JOptionPane.showMessageDialog(this, "Please select a key", "Select Key",
                                            JOptionPane.ERROR_MESSAGE);
                                }
                            }
                        };
                    }
                });

        builder.append("SSH Key", sshKeyLabel);
    }
    final JPanel panel = builder.getPanel();
    panel.setBorder(BorderFactory.createEmptyBorder(50, 20, 20, 80));
    add(panel, BorderLayout.CENTER);

    addToFavoritesBox.setBorder(BorderFactory.createEmptyBorder(0, 20, 10, 20));
    if (rec.provider.imageInFavorites(rec.image)) {
        addToFavoritesBox.setSelected(false);
        addToFavoritesBox.setEnabled(false);
    } else {
        addToFavoritesBox.setSelected(true);
    }

    add(addToFavoritesBox, BorderLayout.SOUTH);
}

From source file:be.ac.ua.comp.scarletnebula.gui.keywizards.SelectNewKeynamePage.java

License:Open Source License

public SelectNewKeynamePage(final CloudProvider provider) {
    super(new BorderLayout());
    final BetterTextLabel toptext = new BetterTextLabel(
            "Choose a name for the SSH key you'll use to establish SSH connections to servers.");
    toptext.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

    namefield.setInputVerifier(new PlainTextVerifier(namefield,
            "An SSH key name must be at least 1 character long and may only contain letters and digits."));
    final String username = System.getProperty("user.name");
    namefield.setText((username != null ? username : "default") + "key");

    final FormLayout layout = new FormLayout("right:max(40dlu;p), 4dlu, min(50dlu;p):grow", "");
    final DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();/*from ww  w  .j av a  2  s  .c o  m*/
    builder.append("Name", namefield);

    final JPanel namepanel = builder.getPanel();
    namepanel.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 20));
    add(namepanel, BorderLayout.CENTER);
    add(toptext, BorderLayout.NORTH);
    this.provider = provider;
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.AddFirewallRuleWindow.java

License:Open Source License

public AddFirewallRuleWindow(final JDialog parent, final CloudProvider provider, final Firewall firewall) {
    super(parent, "Add Rule", true);
    this.firewall = firewall;
    setLayout(new BorderLayout());
    setSize(400, 250);/*w w  w  . j a  va2 s. c o m*/
    setLocationRelativeTo(null);
    setLocationByPlatform(true);

    final FormLayout layout = new FormLayout("right:max(40dlu;p), 4dlu, min(50dlu;p):grow", "");
    // add rows dynamically
    final DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();
    builder.appendSeparator("New Rule");
    portRangeField.setInputVerifier(new PortRangeInputVerifier(portRangeField));
    builder.append("Port range", portRangeField);

    builder.append("Protocol", protocolDropdown);

    builder.append("IP", ipField);

    final JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(builder.getPanel(), BorderLayout.CENTER);
    final JLabel bottomLabel = new JLabel(
            "<html><font size=\"6pt\" color=\"#657383\">Note: Use the IP address 0.0.0.0/0 to allow "
                    + "traffic from and to everyone. </font></html>");
    bottomLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    mainPanel.add(bottomLabel, BorderLayout.PAGE_END);

    add(mainPanel, BorderLayout.CENTER);

    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
    buttonPanel.add(Box.createHorizontalGlue());
    final JButton cancelButton = ButtonFactory.createCancelButton();
    cancelButton.addActionListener(new CancelActionListener());
    buttonPanel.add(cancelButton);
    buttonPanel.add(Box.createHorizontalStrut(5));
    final JButton okButton = ButtonFactory.createOkButton();
    okButton.addActionListener(new OkActionListener());
    buttonPanel.add(okButton);
    buttonPanel.add(Box.createHorizontalStrut(10));
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0));
    add(buttonPanel, BorderLayout.PAGE_END);

}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.ChangeServerSshLoginMethodWindow.java

License:Open Source License

public ChangeServerSshLoginMethodWindow(final JDialog parent, final Server server) {
    super(parent, "Change login method", true);
    setSize(400, 350);//from w w w . j av  a2s. co m
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setLocationRelativeTo(null);
    setLocationByPlatform(true);

    this.server = server;

    final char standardEchoChar = normalPassword.getEchoChar();

    normalPassword.addMouseListener(new MouseListener() {
        @Override
        public void mouseReleased(final MouseEvent e) {
        }

        @Override
        public void mousePressed(final MouseEvent e) {

        }

        @Override
        public void mouseExited(final MouseEvent e) {
            normalPassword.setEchoChar(standardEchoChar);
        }

        @Override
        public void mouseEntered(final MouseEvent e) {
            normalPassword.setEchoChar('\0');
        }

        @Override
        public void mouseClicked(final MouseEvent e) {
        }
    });

    useLoginButton.setMnemonic(KeyEvent.VK_P);
    useLoginButton.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));

    useKeyButton.setMnemonic(KeyEvent.VK_K);
    useKeyButton.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));

    // Group the radio buttons.
    radioButtonGroup.add(useLoginButton);
    radioButtonGroup.add(useKeyButton);

    getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));

    final BetterTextLabel topText = new BetterTextLabel(
            "<html>Select the default way of logging into this server. "
                    + "<font color=\"red\">Warning: </font>the server itself needs to be configured to accept this login method.</html>");
    topText.setAlignmentX(Component.LEFT_ALIGNMENT);
    topText.setBorder(BorderFactory.createEmptyBorder(15, 15, 10, 15));

    final String layoutString = "right:max(40dlu;p), 4dlu, max(20dlu;p):grow, 7dlu:grow";
    final FormLayout layout = new FormLayout(layoutString, "");
    // add rows dynamically
    final DefaultFormBuilder loginPanelsBuilder = new DefaultFormBuilder(layout);
    loginPanelsBuilder.setDefaultDialogBorder();
    loginPanelsBuilder.append("Username", normalUsername);
    loginPanelsBuilder.nextLine();
    loginPanelsBuilder.append("Password", normalPassword);
    final JPanel loginPanel = loginPanelsBuilder.getPanel();
    loginPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    loginPanel.setBorder(BorderFactory.createEmptyBorder(0, 40, 0, 0));

    final FormLayout layout2 = new FormLayout(layoutString, "");
    final DefaultFormBuilder keyPanelsBuilder = new DefaultFormBuilder(layout2);
    keyPanelsBuilder.setDefaultDialogBorder();
    keyPanelsBuilder.append("Username", keyUsername);
    keyPanelsBuilder.nextLine();

    final Collection<String> keynames = KeyManager.getKeyNames(server.getCloud().getName());
    keypairCombo = new JComboBox(keynames.toArray(new String[0]));
    keyPanelsBuilder.append("Keypair", keypairCombo);

    final JPanel keyPanel = keyPanelsBuilder.getPanel();
    keyPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    keyPanel.setBorder(BorderFactory.createEmptyBorder(0, 40, 0, 0));

    final UsePasswordButtonActionListener usePasswordButtonActionListener = new UsePasswordButtonActionListener();
    useLoginButton.addActionListener(usePasswordButtonActionListener);
    final UseKeyButtonActionListener useKeyButtonActionListener = new UseKeyButtonActionListener();
    useKeyButton.addActionListener(useKeyButtonActionListener);

    if (server.usesSshPassword()) {
        useLoginButton.setSelected(true);
        usePasswordButtonActionListener.actionPerformed(null);
    } else {
        useKeyButton.setSelected(true);
        useKeyButtonActionListener.actionPerformed(null);
    }

    add(topText);
    add(useLoginButton);
    add(Box.createVerticalStrut(5));
    add(loginPanel);

    add(useKeyButton);
    add(Box.createVerticalStrut(5));
    add(keyPanel);

    add(Box.createVerticalGlue());

    final JPanel buttonPanel = getButtonPanel();
    add(buttonPanel);
    add(Box.createVerticalStrut(15));

    prefillTextfields(server);
}

From source file:be.ac.ua.comp.scarletnebula.gui.windows.ServerPropertiesWindow.java

License:Open Source License

private void createOverviewPanel(final Collection<Server> servers) {
    overviewTab.setLayout(new BorderLayout());

    final FormLayout layout = new FormLayout("right:max(40dlu;p), 4dlu, min(50dlu;p):grow, 7dlu, "
            + "right:max(40dlu;p), 4dlu, min(50dlu;p):grow", "");
    // add rows dynamically
    final DefaultFormBuilder builder = new DefaultFormBuilder(layout);
    builder.setDefaultDialogBorder();//w ww  . ja  v  a  2  s  .  c  o  m
    builder.appendSeparator("General Information");

    Component servernameComponent = null;
    Component servertagComponent = null;
    Component sshLoginMethodComponent = null;
    Component providerComponent = null;
    Component vncComponent = null;
    Component statisticsCommandComponent = null;

    if (servers.size() == 1) {
        final Server server = servers.iterator().next();

        servernameComponent = getSingleServerServerNameComponent(server);
        servertagComponent = getSingleServerTagComponent(server);
        sshLoginMethodComponent = getSingleServerSshLoginMethodComponent(server);
        providerComponent = getSingleProviderComponent(server);
        vncComponent = getSingleVNCComponent(server);
        statisticsCommandComponent = getSingleStatisticsCommandComponent(server);
    } else {
        servernameComponent = getMultipleServerServerNameComponent(servers);
        servertagComponent = getMultipleServerTagComponent(servers);
        sshLoginMethodComponent = new JLabel("...");
        providerComponent = getMultipleServersProviderComponent(servers);
        vncComponent = new JLabel("...");
        statisticsCommandComponent = new JLabel("...");
    }

    builder.append("Name", servernameComponent);
    builder.append("Tags", servertagComponent);
    builder.nextLine();

    builder.append("SSH Login", sshLoginMethodComponent);
    builder.append("Statistics Command", statisticsCommandComponent);
    builder.nextLine();

    builder.append("Provider", providerComponent);
    builder.append("VNC Password", vncComponent);
    builder.nextLine();

    builder.append("Architecture", architectureLabel);
    builder.append("Platform", platformLabel);
    builder.nextLine();

    builder.append("DNS Address", dnsLabel);
    builder.append("IP Address", ipLabel);
    builder.nextLine();

    builder.append("Status", statusLabel);
    builder.nextLine();

    builder.appendSeparator("Cloud Specific Information");
    builder.append("Name", unfriendlyNameLabel);
    builder.append("Size", sizeLabel);
    builder.nextLine();

    builder.append("Image", imageLabel);
    builder.nextLine();

    final JScrollPane bodyScrollPane = new JScrollPane(builder.getPanel());
    bodyScrollPane.setBorder(null);
    overviewTab.add(bodyScrollPane);
}

From source file:br.com.loja.view.swing.PanelEntity.java

public JPanel getPanel(Class<? extends Switchable> entityClass) {

    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(""));
    builder.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    builder.appendColumn("right:pref");
    builder.appendColumn("3dlu");
    builder.appendColumn("fill:max(pref; 180px)");

    builder.appendSeparator(entityClass.getSimpleName());

    for (Field f : ReflectionUtil.getAllFields(entityClass)) {

        if (!isMappable(f)) {
            continue;
        }/*  ww  w .  j av a  2s.c  o  m*/

        ComponentFactoryOld factory = new ComponentFactoryOld(f, serviceFactory);
        Component component = factory.getComponent();

        if (component != null) {
            if (component instanceof JTable) {
                JScrollPane scrollPane = new JScrollPane();
                scrollPane.setName("List " + component.getName());
                scrollPane.setPreferredSize(new Dimension(180, 240));
                scrollPane.setViewportView(component);
                builder.nextLine();
                builder.append(scrollPane.getName(), scrollPane);

            } else {
                builder.nextLine();
                builder.append(component.getName(), component);
            }
        }
    }

    return builder.getPanel();

}

From source file:br.com.loja.view.swing.PanelEntityEditor.java

private JPanel getPanelEntity() throws ServiceException {

    DefaultFormBuilder builder = new DefaultFormBuilder(new FormLayout(""));
    builder.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    builder.appendColumn("right:pref");
    builder.appendColumn("3dlu");
    builder.appendColumn("fill:max(pref; 180px)");

    builder.appendSeparator(entityClass.getSimpleName());

    for (Field field : ReflectionUtil.getAllFields(entityClass)) {

        if (!isMappable(field)) {
            continue;
        }/*from  w ww  .  j  a  va  2  s .c  o  m*/

        ComponentFactory factory = new ComponentProducer(field).getComponentFactory();
        Component component = factory.getComponent();

        if (component != null) {

            component.setName(field.getName());

            component = buildScrollPane(component);

            builder.nextLine();
            builder.append(component.getName(), component);

            if (Collection.class.isAssignableFrom(field.getType())) {
                addCardPanel(getPanelEditor(field), field.getName());
            }
        }
    }

    JPanel panel = builder.getPanel();
    panel.setName(entityClass.getSimpleName());
    componentsAttributes = ComponentUtil.getComponents(panel);

    return panel;

}