use of javax.swing.GroupLayout.SequentialGroup in project cytoscape-api by cytoscape.
the class CyToolTip method init.
private void init() {
final Color bg = new Color(UIManager.getColor("Table.foreground").getRGB());
final Color fg = new Color(UIManager.getColor("Table.background").getRGB());
final JPanel content = new JPanel();
content.setBackground(bg);
int w = icon != null ? icon.getIconWidth() : 0;
final GroupLayout layout = new GroupLayout(content);
content.setLayout(layout);
layout.setAutoCreateContainerGaps(false);
layout.setAutoCreateGaps(true);
final ParallelGroup hGroup = layout.createParallelGroup(icon != null ? CENTER : LEADING, true);
final SequentialGroup vGroup = layout.createSequentialGroup();
layout.setHorizontalGroup(layout.createSequentialGroup().addGap(2).addGroup(hGroup).addGap(2));
layout.setVerticalGroup(layout.createSequentialGroup().addGap(icon != null ? 2 : 4).addGroup(vGroup).addGap(4));
if (icon != null) {
if (icon.getIconWidth() > 20)
w = icon.getIconWidth();
JLabel lbl = new JLabel(icon);
if (// In case the image is animated
icon instanceof ImageIcon)
((ImageIcon) icon).setImageObserver(lbl);
addComponent(lbl, hGroup, vGroup, w);
}
if (desc != null) {
JLabel lbl = new JLabel(desc);
lbl.setFont(lbl.getFont().deriveFont(Font.BOLD));
lbl.setForeground(fg);
addComponent(lbl, hGroup, vGroup, w);
}
if (longDesc != null && !longDesc.equalsIgnoreCase(desc)) {
// Don't show the same text twice!
JTextArea ta = new JTextArea(longDesc);
ta.setLineWrap(true);
ta.setWrapStyleWord(true);
ta.setEditable(false);
ta.setForeground(fg);
ta.setBackground(bg);
JScrollPane sp = new JScrollPane(ta);
// We cannot have scroll bars here, because it's a tool tip,
// so users would not be able to interact with the bars.
sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
sp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
sp.setBackground(bg);
sp.getViewport().setBackground(bg);
sp.setBorder(BorderFactory.createEmptyBorder());
addComponent(sp, hGroup, vGroup, w);
}
adjustSize(content);
setLayout(new BorderLayout());
add(content, BorderLayout.CENTER);
}
use of javax.swing.GroupLayout.SequentialGroup in project cytoscape-api by cytoscape.
the class LookAndFeelUtil method createOkCancelPanel.
/**
* Use this method to include a help button in the bottom left corner.
* @param helpStr can be a full url, a lookup, or a help page name
*/
public static JPanel createOkCancelPanel(final JButton okBtn, final JButton cancelBtn, String helpStr, JComponent... otherComponents) {
final JPanel panel = new JPanel();
final GroupLayout layout = new GroupLayout(panel);
panel.setLayout(layout);
layout.setAutoCreateContainerGaps(false);
layout.setAutoCreateGaps(true);
final SequentialGroup hg = layout.createSequentialGroup();
final ParallelGroup vg = layout.createParallelGroup(Alignment.CENTER, false);
if (helpStr != null && !helpStr.trim().isEmpty()) {
final JButton helpButton = createHelpButton(helpStr);
hg.addComponent(helpButton);
vg.addComponent(helpButton);
}
if (otherComponents != null) {
for (int i = 0; i < otherComponents.length; i++) {
final JComponent c = otherComponents[i];
hg.addComponent(c);
vg.addComponent(c);
}
}
hg.addGap(0, 0, Short.MAX_VALUE);
final JButton btn1 = isMac() ? cancelBtn : okBtn;
final JButton btn2 = isMac() ? okBtn : cancelBtn;
if (btn1 != null) {
hg.addComponent(btn1);
vg.addComponent(btn1);
}
if (btn2 != null) {
hg.addComponent(btn2);
vg.addComponent(btn2);
}
layout.setHorizontalGroup(hg);
layout.setVerticalGroup(vg);
if (okBtn != null && cancelBtn != null)
equalizeSize(okBtn, cancelBtn);
return panel;
}
use of javax.swing.GroupLayout.SequentialGroup 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