use of java.awt.event.ComponentAdapter in project vcell by virtualcell.
the class DialogUtils method showComponentOptionsTableList.
public static TableListResult showComponentOptionsTableList(final Component requester, final String title, final String[] columnNames, final Object[][] rowDataOrig, final Integer listSelectionModel_SelectMode, final ListSelectionListener listSelectionListener, final String[] options, final String initOption, final Comparator<Object> rowSortComparator, final boolean bModal) throws UserCancelException {
// //Create hidden column with original row index so original row index can
// //be returned for user selections even if rows are sorted
// final int hiddenColumnIndex = rowDataOrig[0].length;
// final Object[][] rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex+1];
// for (int i = 0; i < rowDataHiddenIndex.length; i++) {
// for (int j = 0; j < rowDataOrig[i].length; j++) {
// rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
// }
// rowDataHiddenIndex[i][hiddenColumnIndex] = i;
// }
Producer<TableListResult> prod = () -> {
// Create hidden column with original row index so original row index can
// be returned for user selections even if rows are sorted
int hiddenColumnIndex = rowDataOrig[0].length;
Object[][] rowDataHiddenIndex = rowDataOrig;
if (rowSortComparator != null) {
rowDataHiddenIndex = new Object[rowDataOrig.length][hiddenColumnIndex + 1];
for (int i = 0; i < rowDataHiddenIndex.length; i++) {
for (int j = 0; j < rowDataOrig[i].length; j++) {
rowDataHiddenIndex[i][j] = rowDataOrig[i][j];
}
rowDataHiddenIndex[i][hiddenColumnIndex] = i;
}
}
@SuppressWarnings("serial") VCellSortTableModel<Object[]> tableModel = new VCellSortTableModel<Object[]>(columnNames, rowDataOrig.length) {
@Override
public boolean isSortable(int col) {
if (rowSortComparator != null) {
return true;
}
return false;
}
public Object getValueAt(int row, int column) {
return getValueAt(row)[column];
}
@Override
public Comparator<Object[]> getComparator(final int col, final boolean ascending) {
return new Comparator<Object[]>() {
public int compare(Object[] o1, Object[] o2) {
if (ascending) {
return rowSortComparator.compare(o1[col], o2[col]);
}
return rowSortComparator.compare(o2[col], o1[col]);
}
};
}
};
final JSortTable table = new JSortTable();
// table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
table.setModel(tableModel);
tableModel.setData(Arrays.asList(rowDataHiddenIndex));
if (listSelectionModel_SelectMode != null) {
table.setSelectionMode(listSelectionModel_SelectMode);
} else {
table.setRowSelectionAllowed(false);
table.setColumnSelectionAllowed(false);
}
table.setPreferredScrollableViewportSize(new Dimension(500, 250));
table.disableUneditableForeground();
OKEnabler tableListOKEnabler = null;
if (listSelectionModel_SelectMode != null) {
tableListOKEnabler = new OKEnabler() {
private JOptionPane jop;
public void setJOptionPane(JOptionPane joptionPane) {
jop = joptionPane;
setInternalNotCancelEnabled(joptionPane, false, false);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
if (table.getSelectedRowCount() != 0) {
setInternalNotCancelEnabled(jop, true, false);
} else {
setInternalNotCancelEnabled(jop, false, false);
}
}
}
});
}
};
}
if (listSelectionListener != null) {
table.getSelectionModel().addListSelectionListener(listSelectionListener);
}
TableListResult tableListResult = new TableListResult();
// HACK to fix horizontal scrollbar not showing for large horizontal tables
// workaround code from: http://bugs.sun.com/view_bug.do?bug_id=4127936
final JScrollPane[] jScrollPaneArr = new JScrollPane[1];
Component[] components = table.getEnclosingScrollPane().getComponents();
for (int i = 0; i < components.length; i++) {
if (components[i] instanceof JScrollPane) {
jScrollPaneArr[0] = (JScrollPane) components[i];
break;
}
}
if (jScrollPaneArr[0] != null) {
jScrollPaneArr[0].addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
super.componentResized(e);
if (table.getPreferredSize().width <= jScrollPaneArr[0].getViewport().getExtentSize().width) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
} else {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
}
});
}
if (options == null) {
if (bModal) {
if (showComponentOKCancelDialog(requester, table.getEnclosingScrollPane(), title, tableListOKEnabler) != JOptionPane.OK_OPTION) {
throw UserCancelException.CANCEL_GENERIC;
}
} else {
// display non-modal
JOptionPane jOptionPane = new JOptionPane(table.getEnclosingScrollPane(), JOptionPane.INFORMATION_MESSAGE);
JDialog jDialog = jOptionPane.createDialog(requester, title);
jDialog.setResizable(true);
jDialog.setModal(false);
jDialog.pack();
jDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
jDialog.setVisible(true);
}
tableListResult.selectedTableRows = table.getSelectedRows();
} else {
tableListResult.selectedOption = showOptionsDialog(requester, table.getEnclosingScrollPane(), JOptionPane.QUESTION_MESSAGE, options, initOption, tableListOKEnabler, title);
tableListResult.selectedTableRows = table.getSelectedRows();
}
if (rowSortComparator != null) {
// return the index of the original unsorted object array that corresponds to the user row selections
for (int i = 0; i < tableListResult.selectedTableRows.length; i++) {
tableListResult.selectedTableRows[i] = (Integer) (tableModel.getValueAt(tableListResult.selectedTableRows[i])[hiddenColumnIndex]);
}
}
return tableListResult;
};
return VCSwingFunction.executeAsRuntimeException(prod);
}
use of java.awt.event.ComponentAdapter in project vcell by virtualcell.
the class BasicGraphEditor method insertPalette.
/**
*/
public EditorPalette insertPalette(String title) {
final EditorPalette palette = new EditorPalette();
final JScrollPane scrollPane = new JScrollPane(palette);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
libraryPane.add(title, scrollPane);
// Updates the widths of the palettes if the container size changes
libraryPane.addComponentListener(new ComponentAdapter() {
/**
*/
public void componentResized(ComponentEvent e) {
int w = scrollPane.getWidth() - scrollPane.getVerticalScrollBar().getWidth();
palette.setPreferredWidth(w);
}
});
return palette;
}
use of java.awt.event.ComponentAdapter in project cytoscape-impl by cytoscape.
the class NetworkViewComparisonPanel method init.
private void init() {
final Set<CyNetworkView> views = new LinkedHashSet<>();
for (ViewPanel vp : viewPanels.values()) {
vp.getNetworkViewContainer().setComparing(true);
views.add(vp.getNetworkView());
}
setName(createUniqueKey(views));
setLayout(new BorderLayout());
add(getGridPanel(), BorderLayout.CENTER);
add(getComparisonToolBar(), BorderLayout.SOUTH);
addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
requestFocusInWindow();
for (ViewPanel vp : viewPanels.values()) {
if (vp.isCurrent()) {
vp.getNetworkViewContainer().getContentPane().requestFocusInWindow();
break;
}
}
arrangePanels();
update();
}
@Override
public void componentResized(ComponentEvent e) {
arrangePanels();
}
});
setKeyBindings(this);
arrangePanels();
update();
}
use of java.awt.event.ComponentAdapter in project cytoscape-impl by cytoscape.
the class VisualPropertySheetItem method getShowMappingBtn.
protected ExpandCollapseButton getShowMappingBtn() {
if (expandCollapseBtn == null) {
expandCollapseBtn = new ExpandCollapseButton(false, evt -> {
if (getMappingPnl().isShowing())
collapse();
else
expand();
});
final Dimension d = new Dimension(VALUE_ICON_WIDTH, VALUE_ICON_HEIGHT);
expandCollapseBtn.setMinimumSize(d);
expandCollapseBtn.setPreferredSize(d);
expandCollapseBtn.setMaximumSize(d);
expandCollapseBtn.setBorder(BorderFactory.createEmptyBorder(BUTTON_V_PAD, BUTTON_H_PAD, BUTTON_V_PAD, BUTTON_H_PAD));
getMappingPnl().addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(final ComponentEvent ce) {
if (expandCollapseBtn != null && !expandCollapseBtn.isSelected())
expandCollapseBtn.setSelected(true);
}
@Override
public void componentHidden(final ComponentEvent ce) {
if (expandCollapseBtn != null && expandCollapseBtn.isSelected())
expandCollapseBtn.setSelected(false);
}
});
}
return expandCollapseBtn;
}
use of java.awt.event.ComponentAdapter in project cytoscape-impl by cytoscape.
the class VisualPropertySheet method setItems.
public void setItems(final Set<VisualPropertySheetItem<?>> newItems) {
// Remove current items
vpItemMap.clear();
depItemMap.clear();
items.clear();
if (newItems != null) {
items.addAll(newItems);
// Create the internal panel that contains the visual property editors
final JPanel p = new JPanel(new GridBagLayout());
final GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.gridx = 0;
c.weightx = 1;
// Add the visual property editors to the internal panel
int y = 0;
int minWidth = 120;
for (final VisualPropertySheetItem<?> i : items) {
c.gridy = y++;
p.add(i, c);
// Save it for future use
if (i.getModel().getVisualPropertyDependency() == null)
vpItemMap.put(i.getModel().getVisualProperty(), i);
else
depItemMap.put(i.getModel().getVisualPropertyDependency().getIdString(), i);
// Add listeners
i.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
onMousePressedItem(e, i);
}
});
if (i.getModel().isVisualMappingAllowed()) {
i.addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(final ComponentEvent e) {
updateCollapseExpandButtons();
}
@Override
public void componentHidden(final ComponentEvent e) {
if (selectionHead == i)
selectionHead = null;
if (selectionTail == i)
selectionTail = null;
updateCollapseExpandButtons();
}
});
i.addPropertyChangeListener("enabled", evt -> {
updateCollapseExpandButtons();
});
i.addPropertyChangeListener("expanded", evt -> {
updateCollapseExpandButtons();
});
i.getPropSheetPnl().getTable().addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(final MouseEvent e) {
onMousePressedItem(e, i);
}
});
}
minWidth = Math.max(minWidth, i.getPreferredSize().width);
}
// Add an empty panel to fill the vertical gap
final JPanel fillPnl = new JPanel();
fillPnl.setBackground(VisualPropertySheetItem.getBackgroundColor());
c.fill = GridBagConstraints.BOTH;
c.weighty = 1;
p.add(fillPnl, c);
fillPnl.addMouseListener(new MouseAdapter() {
@Override
@SuppressWarnings("unchecked")
public void mouseClicked(final MouseEvent e) {
if (// Deselect all items
!e.isShiftDown() || e.isControlDown())
setSelectedItems(Collections.EMPTY_SET);
}
});
getVpListScr().setViewportView(p);
minWidth = Math.min((minWidth += 10), 400);
getVpListScr().setMinimumSize(new Dimension(minWidth, 140));
if (getParent() != null) {
minWidth = Math.max(minWidth + 8, getParent().getMinimumSize().width);
getParent().setMinimumSize(new Dimension(minWidth, getParent().getMinimumSize().height));
}
}
updateCollapseExpandButtons();
createMenuItems();
}
Aggregations