Search in sources :

Example 11 with SequentialGroup

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ParallelGroup(javax.swing.GroupLayout.ParallelGroup) ImageIcon(javax.swing.ImageIcon) JTextArea(javax.swing.JTextArea) BorderLayout(java.awt.BorderLayout) Color(java.awt.Color) SequentialGroup(javax.swing.GroupLayout.SequentialGroup) GroupLayout(javax.swing.GroupLayout) JLabel(javax.swing.JLabel)

Example 12 with SequentialGroup

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;
}
Also used : JPanel(javax.swing.JPanel) ParallelGroup(javax.swing.GroupLayout.ParallelGroup) SequentialGroup(javax.swing.GroupLayout.SequentialGroup) GroupLayout(javax.swing.GroupLayout) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent)

Example 13 with SequentialGroup

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;
}
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)13 SequentialGroup (javax.swing.GroupLayout.SequentialGroup)13 GroupLayout (javax.swing.GroupLayout)11 JPanel (javax.swing.JPanel)7 Component (java.awt.Component)3 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 Group (javax.swing.GroupLayout.Group)1 ImageIcon (javax.swing.ImageIcon)1 JDialog (javax.swing.JDialog)1