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;
}
Aggregations