Search in sources :

Example 16 with ParallelGroup

use of javax.swing.GroupLayout.ParallelGroup in project litiengine by gurkenlabs.

the class PropertyPanel method createLayout.

protected LayoutManager createLayout(LayoutItem[] layoutItems, Component... additionalComponents) {
    GroupLayout groupLayout = new GroupLayout(this);
    // prepare the parallel group for the labels
    // add additional components to the group
    ParallelGroup parallel = groupLayout.createParallelGroup(Alignment.TRAILING);
    for (Component component : additionalComponents) {
        parallel.addComponent(component, Alignment.LEADING, CONTROL_MIN_WIDTH, CONTROL_WIDTH, Short.MAX_VALUE);
    }
    for (LayoutItem item : layoutItems) {
        SequentialGroup horGrp = groupLayout.createSequentialGroup();
        if (item.getLabel() != null) {
            horGrp.addComponent(item.getLabel(), LABEL_WIDTH, LABEL_WIDTH, Short.MAX_VALUE).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(item.getComponent(), CONTROL_MIN_WIDTH, CONTROL_WIDTH, Short.MAX_VALUE);
        } else {
            horGrp.addComponent(item.getComponent(), CONTROL_MIN_WIDTH, CONTROL_WIDTH, Short.MAX_VALUE);
        }
        parallel.addGroup(Alignment.LEADING, horGrp);
    }
    // initialize the horizontal layout group with the parallel groups for
    // labels and components and some additional gaps
    groupLayout.setHorizontalGroup(groupLayout.createParallelGroup(Alignment.LEADING).addGroup(groupLayout.createSequentialGroup().addGroup(parallel)));
    // now prepare the vertical groups
    SequentialGroup seq = groupLayout.createSequentialGroup();
    SequentialGroup current = seq.addGap(CONTROL_MARGIN);
    for (LayoutItem item : layoutItems) {
        ParallelGroup verGrp = groupLayout.createParallelGroup(Alignment.LEADING);
        if (item.getLabel() != null) {
            verGrp.addComponent(item.getComponent(), item.getMinHeight(), item.getMinHeight(), item.getMinHeight()).addComponent(item.getLabel(), GroupLayout.PREFERRED_SIZE, item.getMinHeight(), item.getMinHeight()).addGap(CONTROL_MARGIN);
        } else {
            verGrp.addComponent(item.getComponent(), item.getMinHeight(), item.getMinHeight(), item.getMinHeight());
        }
        current = current.addGroup(verGrp);
    }
    current.addPreferredGap(ComponentPlacement.UNRELATED);
    for (Component component : additionalComponents) {
        current = current.addComponent(component, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE).addGap(CONTROL_MARGIN);
    }
    groupLayout.setVerticalGroup(groupLayout.createParallelGroup(Alignment.TRAILING).addGroup(seq));
    return groupLayout;
}
Also used : ParallelGroup(javax.swing.GroupLayout.ParallelGroup) SequentialGroup(javax.swing.GroupLayout.SequentialGroup) GroupLayout(javax.swing.GroupLayout) Component(java.awt.Component)

Aggregations

ParallelGroup (javax.swing.GroupLayout.ParallelGroup)16 SequentialGroup (javax.swing.GroupLayout.SequentialGroup)14 GroupLayout (javax.swing.GroupLayout)11 JPanel (javax.swing.JPanel)7 Component (java.awt.Component)4 Group (javax.swing.GroupLayout.Group)4 JLabel (javax.swing.JLabel)3 JButton (javax.swing.JButton)2 JComponent (javax.swing.JComponent)2 JSeparator (javax.swing.JSeparator)2 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 ActionEvent (java.awt.event.ActionEvent)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 AbstractAction (javax.swing.AbstractAction)1 AbstractButton (javax.swing.AbstractButton)1 ButtonGroup (javax.swing.ButtonGroup)1 ImageIcon (javax.swing.ImageIcon)1 JDialog (javax.swing.JDialog)1