use of javax.swing.GroupLayout in project cytoscape-impl by cytoscape.
the class ListMultipleHandler method init.
private void init() {
listModel = new DefaultListModel<>();
itemsContainerList = new JList<>(listModel);
// Select All/None buttons
selectAllButton = new JButton("Select All");
selectAllButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (listModel.getSize() > 0)
itemsContainerList.getSelectionModel().setSelectionInterval(0, listModel.getSize() - 1);
}
});
selectNoneButton = new JButton("Select None");
selectNoneButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
itemsContainerList.getSelectionModel().clearSelection();
}
});
selectNoneButton.setEnabled(false);
if (isAquaLAF()) {
selectAllButton.putClientProperty("JButton.buttonType", "gradient");
selectAllButton.putClientProperty("JComponent.sizeVariant", "small");
selectNoneButton.putClientProperty("JButton.buttonType", "gradient");
selectNoneButton.putClientProperty("JComponent.sizeVariant", "small");
}
LookAndFeelUtil.equalizeSize(selectAllButton, selectNoneButton);
ListMultipleSelection<T> multipleSelection = getMultipleSelection();
// put the items in a list
if (multipleSelection != null) {
for (T value : multipleSelection.getPossibleValues()) listModel.addElement(value);
}
itemsContainerList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
// selected items
List<T> selVals = multipleSelection != null ? multipleSelection.getSelectedValues() : Collections.emptyList();
List<T> allValues = multipleSelection != null ? multipleSelection.getPossibleValues() : Collections.emptyList();
final int[] selectedIdx = new int[selVals.size()];
int index = 0;
for (T selected : selVals) {
for (int i = 0; i < allValues.size(); i++) {
if (itemsContainerList.getModel().getElementAt(i).equals(selected)) {
selectedIdx[index] = i;
index++;
}
}
}
itemsContainerList.setSelectedIndices(selectedIdx);
itemsContainerList.addListSelectionListener(this);
// use a JscrollPane to visualize the items
final JScrollPane scrollpane = new JScrollPane(itemsContainerList);
scrollpane.setAutoscrolls(true);
scrollpane.setOpaque(false);
final JPanel controlPanel = new JPanel();
if (LookAndFeelUtil.isAquaLAF())
controlPanel.setOpaque(false);
final GroupLayout layout = new GroupLayout(controlPanel);
controlPanel.setLayout(layout);
layout.setAutoCreateGaps(LookAndFeelUtil.isWinLAF());
layout.setAutoCreateContainerGaps(false);
layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(scrollpane, 100, DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createParallelGroup(Alignment.LEADING, false).addComponent(selectAllButton).addComponent(selectNoneButton)));
layout.setVerticalGroup(layout.createParallelGroup(Alignment.LEADING, true).addComponent(scrollpane, 80, 120, PREFERRED_SIZE).addGroup(layout.createSequentialGroup().addComponent(selectAllButton).addComponent(selectNoneButton)));
String description = getDescription();
if (description != null && description.length() > 80) {
// Use JTextArea for long descriptions
final JTextArea textArea = new JTextArea(description);
updateFieldPanel(panel, textArea, controlPanel, horizontal);
setTooltip(getTooltip(), textArea, scrollpane);
} else if (description != null && description.length() > 0) {
// Otherwise, use JLabel
final JLabel label = new JLabel(description);
updateFieldPanel(panel, label, controlPanel, horizontal);
setTooltip(getTooltip(), label, scrollpane);
} else {
updateFieldPanel(panel, controlPanel, horizontal);
setTooltip(getTooltip(), scrollpane);
}
panel.setVisible(itemsContainerList.getModel().getSize() > 0);
}
use of javax.swing.GroupLayout 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));
}
}
use of javax.swing.GroupLayout in project cytoscape-impl by cytoscape.
the class AboutDialog method initComponents.
@SuppressWarnings("serial")
private void initComponents() {
setTitle("About");
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
mainEditorPane = new JEditorPane();
mainEditorPane.setBorder(BorderFactory.createEmptyBorder());
mainEditorPane.setEditable(false);
mainEditorPane.setBackground(getBackground());
if (LookAndFeelUtil.isNimbusLAF()) {
// Nimbus does not respect background color settings for JEditorPane,
// so this is necessary to override its color:
final UIDefaults defaults = new UIDefaults();
defaults.put("EditorPane[Enabled].backgroundPainter", getBackground());
mainEditorPane.putClientProperty("Nimbus.Overrides", defaults);
mainEditorPane.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
}
mainScrollPane = new JScrollPane();
mainScrollPane.setBorder(BorderFactory.createEmptyBorder());
mainScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
mainScrollPane.setViewportView(mainEditorPane);
// Client name to be set here...
titleLabel = new JLabel();
titleLabel.setFont(new Font(titleLabel.getName(), Font.BOLD, 18));
titleLabel.setHorizontalAlignment(JLabel.CENTER);
final JButton closeButton = new JButton(new AbstractAction("Close") {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
final JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(closeButton, null);
final JPanel contents = new JPanel();
final JSeparator sep1 = new JSeparator();
final JSeparator sep2 = new JSeparator();
final GroupLayout layout = new GroupLayout(contents);
contents.setLayout(layout);
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup().addGap(20).addGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(titleLabel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(sep1, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(mainScrollPane, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(sep2, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(buttonPanel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)).addGap(20));
layout.setVerticalGroup(layout.createSequentialGroup().addComponent(titleLabel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(sep1, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(mainScrollPane, DEFAULT_SIZE, 215, Short.MAX_VALUE).addComponent(sep2, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(buttonPanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
getContentPane().add(contents);
LookAndFeelUtil.setDefaultOkCancelKeyStrokes(getRootPane(), closeButton.getAction(), closeButton.getAction());
getRootPane().setDefaultButton(closeButton);
pack();
}
use of javax.swing.GroupLayout in project cytoscape-impl by cytoscape.
the class WebServiceImportDialog method initComponents.
private void initComponents() {
mainTabbedPane = new JTabbedPane();
searchTermScrollPane = new JScrollPane();
queryTextPane = new JTextPane();
propertyPanel = new JPanel();
queryTextPane.setFont(new java.awt.Font("SansSerif", 0, 12));
queryTextPane.setText("Please enter search terms...");
searchTermScrollPane.setViewportView(queryTextPane);
mainTabbedPane.addTab("Query", searchTermScrollPane);
GroupLayout propertyPanelLayout = new GroupLayout(propertyPanel);
propertyPanel.setLayout(propertyPanelLayout);
propertyPanelLayout.setHorizontalGroup(propertyPanelLayout.createParallelGroup(Alignment.LEADING).addGap(0, 408, Short.MAX_VALUE));
propertyPanelLayout.setVerticalGroup(propertyPanelLayout.createParallelGroup(Alignment.LEADING).addGap(0, 303, Short.MAX_VALUE));
propertyScrollPane = new JScrollPane();
propertyScrollPane.setViewportView(propertyPanel);
mainTabbedPane.addTab("Search Property", propertyScrollPane);
titlePanel = new JPanel();
titleIconLabel = new JLabel();
datasourcePanel = new JPanel();
datasourceLabel = new JLabel();
datasourceComboBox = new JComboBox();
datasourceComboBox.setRenderer(new ClientComboBoxCellRenderer());
aboutButton = new JButton();
searchButton = new JButton();
cancelButton = new JButton();
clearButton = new JButton();
dataQueryPanel = new JPanel();
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
GroupLayout titlePanelLayout = new GroupLayout(titlePanel);
titlePanel.setLayout(titlePanelLayout);
titlePanelLayout.setHorizontalGroup(titlePanelLayout.createParallelGroup(Alignment.LEADING).addComponent(titleIconLabel, PREFERRED_SIZE, 461, PREFERRED_SIZE));
titlePanelLayout.setVerticalGroup(titlePanelLayout.createParallelGroup(Alignment.LEADING).addComponent(titleIconLabel));
datasourceLabel.setText("Data Source:");
datasourceComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
datasourceComboBoxActionPerformed(evt);
}
});
aboutButton.setText("About");
aboutButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
aboutButtonActionPerformed(evt);
}
});
GroupLayout dataSourceLayout = new GroupLayout(datasourcePanel);
datasourcePanel.setLayout(dataSourceLayout);
dataSourceLayout.setAutoCreateContainerGaps(false);
dataSourceLayout.setAutoCreateGaps(true);
dataSourceLayout.setHorizontalGroup(dataSourceLayout.createParallelGroup(Alignment.LEADING).addGroup(dataSourceLayout.createSequentialGroup().addContainerGap().addComponent(datasourceLabel).addComponent(datasourceComboBox, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addGap(20, 20, Short.MAX_VALUE).addComponent(aboutButton).addContainerGap()));
dataSourceLayout.setVerticalGroup(dataSourceLayout.createParallelGroup(Alignment.LEADING).addGroup(dataSourceLayout.createSequentialGroup().addGroup(dataSourceLayout.createParallelGroup(Alignment.BASELINE).addComponent(datasourceLabel).addComponent(aboutButton).addComponent(datasourceComboBox, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE))));
searchButton.setText("Search");
searchButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
searchButtonActionPerformed();
}
});
cancelButton.setText("Cancel");
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
clearButton.setText("Clear");
clearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
clearButtonActionPerformed(evt);
}
});
buttonPanel = LookAndFeelUtil.createOkCancelPanel(searchButton, cancelButton, clearButton);
GroupLayout dataQueryPanelLayout = new GroupLayout(dataQueryPanel);
dataQueryPanel.setLayout(dataQueryPanelLayout);
dataQueryPanelLayout.setHorizontalGroup(dataQueryPanelLayout.createParallelGroup(Alignment.LEADING).addGap(0, 461, Short.MAX_VALUE));
dataQueryPanelLayout.setVerticalGroup(dataQueryPanelLayout.createParallelGroup(Alignment.LEADING).addGap(0, 247, Short.MAX_VALUE));
queryPanel = new JPanel();
GroupLayout layout = new GroupLayout(queryPanel);
queryPanel.setLayout(layout);
layout.setAutoCreateContainerGaps(true);
layout.setAutoCreateGaps(true);
layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING).addComponent(titlePanel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(datasourcePanel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(dataQueryPanel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(buttonPanel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE));
layout.setVerticalGroup(layout.createSequentialGroup().addComponent(titlePanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(datasourcePanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(dataQueryPanel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(buttonPanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
dataQueryPanel.setLayout(new BorderLayout());
}
use of javax.swing.GroupLayout in project cytoscape-impl by cytoscape.
the class AbstractChartEditor method getLabelsPnl.
protected JPanel getLabelsPnl() {
if (labelsPnl == null) {
labelsPnl = new JPanel();
// Transparent if Aqua
labelsPnl.setOpaque(!isAquaLAF());
labelsPnl.setVisible(setItemLabels || setDomainLabels || setRangeLabels);
if (!labelsPnl.isVisible())
return labelsPnl;
final GroupLayout layout = new GroupLayout(labelsPnl);
labelsPnl.setLayout(layout);
layout.setAutoCreateContainerGaps(false);
layout.setAutoCreateGaps(!isAquaLAF());
final ParallelGroup hGroup = layout.createParallelGroup(Alignment.LEADING, true);
final SequentialGroup vGroup = layout.createSequentialGroup();
layout.setHorizontalGroup(hGroup);
layout.setVerticalGroup(vGroup);
if (setItemLabels) {
hGroup.addGroup(layout.createSequentialGroup().addComponent(getItemLabelsVisibleCkb()).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(itemLabelsColumnLbl).addComponent(getItemLabelsColumnCmb(), PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(itemFontSizeLbl).addComponent(getItemFontSizeTxt(), PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
vGroup.addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(getItemLabelsVisibleCkb()).addComponent(itemLabelsColumnLbl).addComponent(getItemLabelsColumnCmb()).addComponent(itemFontSizeLbl).addComponent(getItemFontSizeTxt()));
}
if (setRangeLabels) {
hGroup.addGroup(layout.createSequentialGroup().addComponent(rangeLabelsColumnLbl).addComponent(getRangeLabelsColumnCmb(), PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
vGroup.addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(rangeLabelsColumnLbl).addComponent(getRangeLabelsColumnCmb()));
}
if (setDomainLabels) {
hGroup.addGroup(layout.createSequentialGroup().addComponent(domainLabelsColumnLbl).addComponent(getDomainLabelsColumnCmb(), PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
vGroup.addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(domainLabelsColumnLbl).addComponent(getDomainLabelsColumnCmb()));
}
hGroup.addGroup(layout.createSequentialGroup().addComponent(domainLabelPositionLbl).addComponent(getDomainLabelPositionCmb(), PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
vGroup.addGroup(layout.createParallelGroup(Alignment.CENTER, false).addComponent(domainLabelPositionLbl).addComponent(getDomainLabelPositionCmb()));
final JSeparator sep = new JSeparator();
hGroup.addComponent(sep);
vGroup.addComponent(sep, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE);
}
return labelsPnl;
}
Aggregations