use of javax.swing.GroupLayout.Alignment in project cytoscape-impl by cytoscape.
the class GUIDefaults method updateFieldPanel.
private static void updateFieldPanel(final JPanel p, final Component label, final Component control, final boolean horizontalForm) {
if (p instanceof TunableFieldPanel) {
((TunableFieldPanel) p).setControl(control);
if (label instanceof JLabel)
((TunableFieldPanel) p).setLabel((JLabel) label);
else if (label instanceof JTextArea)
((TunableFieldPanel) p).setMultiLineLabel((JTextArea) label);
return;
}
p.removeAll();
final GroupLayout layout = new GroupLayout(p);
p.setLayout(layout);
layout.setAutoCreateContainerGaps(false);
layout.setAutoCreateGaps(true);
final Alignment vAlign = control instanceof JPanel || control instanceof JScrollPane ? Alignment.LEADING : Alignment.CENTER;
if (horizontalForm) {
p.setBorder(BorderFactory.createEmptyBorder(0, 4, 0, 4));
layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(label, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(control, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
layout.setVerticalGroup(layout.createParallelGroup(vAlign, false).addComponent(label).addComponent(control));
} else {
p.setBorder(BorderFactory.createEmptyBorder(2, 0, 2, 0));
int w = Math.max(label.getPreferredSize().width, control.getPreferredSize().width);
// So the label and control are centered
int gap = w - control.getPreferredSize().width;
layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.TRAILING, true).addComponent(label, w, w, Short.MAX_VALUE)).addGroup(layout.createParallelGroup(Alignment.LEADING, true).addGroup(layout.createSequentialGroup().addComponent(control, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addGap(gap, gap, Short.MAX_VALUE))));
layout.setVerticalGroup(layout.createParallelGroup(vAlign, false).addComponent(label).addComponent(control));
}
}
Aggregations