use of javax.swing.event.ListSelectionListener in project keystore-explorer by kaikramer.
the class DAddExtensions method initComponents.
private void initComponents() {
jbAdd = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("DAddExtensions.jbAdd.image")))));
jbAdd.setMargin(new Insets(2, 2, 0, 0));
jbAdd.setToolTipText(res.getString("DAddExtensions.jbAdd.tooltip"));
jbAdd.setMnemonic(res.getString("DAddExtensions.jbAdd.mnemonic").charAt(0));
jbAdd.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DAddExtensions.this);
addPressed();
} finally {
CursorUtil.setCursorFree(DAddExtensions.this);
}
}
});
jbEdit = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("DAddExtensions.jbEdit.image")))));
jbEdit.setMargin(new Insets(2, 2, 0, 0));
jbEdit.setToolTipText(res.getString("DAddExtensions.jbEdit.tooltip"));
jbEdit.setMnemonic(res.getString("DAddExtensions.jbEdit.mnemonic").charAt(0));
jbEdit.setEnabled(false);
jbEdit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DAddExtensions.this);
editPressed();
} finally {
CursorUtil.setCursorFree(DAddExtensions.this);
}
}
});
jbToggleCriticality = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("DAddExtensions.jbToggleCriticality.image")))));
jbToggleCriticality.setMargin(new Insets(2, 2, 0, 0));
jbToggleCriticality.setToolTipText(res.getString("DAddExtensions.jbToggleCriticality.tooltip"));
jbToggleCriticality.setMnemonic(res.getString("DAddExtensions.jbToggleCriticality.mnemonic").charAt(0));
jbToggleCriticality.setEnabled(false);
jbToggleCriticality.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DAddExtensions.this);
toggleCriticalityPressed();
} finally {
CursorUtil.setCursorFree(DAddExtensions.this);
}
}
});
jbRemove = new JButton(new ImageIcon(Toolkit.getDefaultToolkit().createImage(getClass().getResource(res.getString("DAddExtensions.jbRemove.image")))));
jbRemove.setMargin(new Insets(2, 2, 0, 0));
jbRemove.setToolTipText(res.getString("DAddExtensions.jbRemove.tooltip"));
jbRemove.setMnemonic(res.getString("DAddExtensions.jbRemove.mnemonic").charAt(0));
jbRemove.setEnabled(false);
jbRemove.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DAddExtensions.this);
removePressed();
} finally {
CursorUtil.setCursorFree(DAddExtensions.this);
}
}
});
jpExtensionButtons = new JPanel();
jpExtensionButtons.setLayout(new BoxLayout(jpExtensionButtons, BoxLayout.Y_AXIS));
jpExtensionButtons.add(Box.createVerticalGlue());
jpExtensionButtons.add(jbAdd);
jpExtensionButtons.add(Box.createVerticalStrut(3));
jpExtensionButtons.add(jbEdit);
jpExtensionButtons.add(Box.createVerticalStrut(3));
jpExtensionButtons.add(jbToggleCriticality);
jpExtensionButtons.add(Box.createVerticalStrut(3));
jpExtensionButtons.add(jbRemove);
jpExtensionButtons.add(Box.createVerticalGlue());
ExtensionsTableModel extensionsTableModel = new ExtensionsTableModel();
jtExtensions = new JKseTable(extensionsTableModel);
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(extensionsTableModel);
sorter.setComparator(2, new ObjectIdComparator());
jtExtensions.setRowSorter(sorter);
jtExtensions.setShowGrid(false);
jtExtensions.setRowMargin(0);
jtExtensions.getColumnModel().setColumnMargin(0);
jtExtensions.getTableHeader().setReorderingAllowed(false);
jtExtensions.setAutoResizeMode(JKseTable.AUTO_RESIZE_ALL_COLUMNS);
jtExtensions.setRowHeight(Math.max(18, jtExtensions.getRowHeight()));
for (int i = 0; i < jtExtensions.getColumnCount(); i++) {
TableColumn column = jtExtensions.getColumnModel().getColumn(i);
column.setHeaderRenderer(new ExtensionsTableHeadRend(jtExtensions.getTableHeader().getDefaultRenderer()));
column.setCellRenderer(new ExtensionsTableCellRend());
}
TableColumn criticalCol = jtExtensions.getColumnModel().getColumn(0);
criticalCol.setResizable(false);
criticalCol.setMinWidth(28);
criticalCol.setMaxWidth(28);
criticalCol.setPreferredWidth(28);
ListSelectionModel selectionModel = jtExtensions.getSelectionModel();
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
selectionModel.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent evt) {
if (!evt.getValueIsAdjusting()) {
try {
CursorUtil.setCursorBusy(DAddExtensions.this);
updateButtonControls();
} finally {
CursorUtil.setCursorFree(DAddExtensions.this);
}
}
}
});
jtExtensions.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
maybeEditExtension(evt);
}
});
jtExtensions.addKeyListener(new KeyAdapter() {
boolean deleteLastPressed = false;
@Override
public void keyPressed(KeyEvent evt) {
// Record delete pressed on non-Macs
if (!OperatingSystem.isMacOs()) {
deleteLastPressed = evt.getKeyCode() == KeyEvent.VK_DELETE;
}
}
@Override
public void keyReleased(KeyEvent evt) {
// Delete on non-Mac if delete was pressed and is now released
if (!OperatingSystem.isMacOs() && deleteLastPressed && evt.getKeyCode() == KeyEvent.VK_DELETE) {
try {
CursorUtil.setCursorBusy(DAddExtensions.this);
deleteLastPressed = false;
removeSelectedExtension();
} finally {
CursorUtil.setCursorFree(DAddExtensions.this);
}
}
}
@Override
public void keyTyped(KeyEvent evt) {
// Delete on Mac if back space typed
if (OperatingSystem.isMacOs() && evt.getKeyChar() == 0x08) {
try {
CursorUtil.setCursorBusy(DAddExtensions.this);
removeSelectedExtension();
} finally {
CursorUtil.setCursorFree(DAddExtensions.this);
}
}
}
});
jspExtensionsTable = PlatformUtil.createScrollPane(jtExtensions, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
jspExtensionsTable.getViewport().setBackground(jtExtensions.getBackground());
jbLoadTemplate = new JButton(res.getString("DAddExtensions.jbLoadTemplate.text"));
jbLoadTemplate.setMnemonic(res.getString("DAddExtensions.jbLoadTemplate.mnemonic").charAt(0));
jbLoadTemplate.setToolTipText(res.getString("DAddExtensions.jbLoadTemplate.tooltip"));
jbLoadTemplate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DAddExtensions.this);
loadTemplatePressed();
} finally {
CursorUtil.setCursorFree(DAddExtensions.this);
}
}
});
jbSaveTemplate = new JButton(res.getString("DAddExtensions.jbSaveTemplate.text"));
jbSaveTemplate.setMnemonic(res.getString("DAddExtensions.jbSaveTemplate.mnemonic").charAt(0));
jbSaveTemplate.setToolTipText(res.getString("DAddExtensions.jbSaveTemplate.tooltip"));
jbSaveTemplate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
try {
CursorUtil.setCursorBusy(DAddExtensions.this);
saveTemplatePressed();
} finally {
CursorUtil.setCursorFree(DAddExtensions.this);
}
}
});
jpLoadSaveTemplate = new JPanel();
jpLoadSaveTemplate.setLayout(new BoxLayout(jpLoadSaveTemplate, BoxLayout.X_AXIS));
jpLoadSaveTemplate.add(Box.createHorizontalGlue());
jpLoadSaveTemplate.add(jbLoadTemplate);
jpLoadSaveTemplate.add(Box.createHorizontalStrut(5));
jpLoadSaveTemplate.add(jbSaveTemplate);
jpExtensions = new JPanel(new BorderLayout(5, 5));
jpExtensions.setPreferredSize(new Dimension(450, 200));
jpExtensions.add(jspExtensionsTable, BorderLayout.CENTER);
jpExtensions.add(jpExtensionButtons, BorderLayout.EAST);
jpExtensions.add(jpLoadSaveTemplate, BorderLayout.SOUTH);
jpExtensions.setBorder(new CompoundBorder(new EmptyBorder(5, 5, 5, 5), new CompoundBorder(new EtchedBorder(), new EmptyBorder(5, 5, 5, 5))));
jbOK = new JButton(res.getString("DAddExtensions.jbOK.text"));
jbOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
okPressed();
}
});
jbCancel = new JButton(res.getString("DAddExtensions.jbCancel.text"));
jbCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
cancelPressed();
}
});
jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL_KEY);
jbCancel.getActionMap().put(CANCEL_KEY, new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent evt) {
cancelPressed();
}
});
jpButtons = PlatformUtil.createDialogButtonPanel(jbOK, jbCancel, false);
reloadExtensionsTable();
selectFirstExtensionInTable();
updateButtonControls();
getContentPane().setLayout(new BorderLayout());
getContentPane().add(jpExtensions, BorderLayout.CENTER);
getContentPane().add(jpButtons, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) {
closeDialog();
}
});
setResizable(false);
getRootPane().setDefaultButton(jbOK);
pack();
}
use of javax.swing.event.ListSelectionListener in project pmd by pmd.
the class EvaluationResultsPanel method init.
private void init() {
model.addViewerModelListener(this);
list = new JList();
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (list.getSelectedValue() != null) {
model.selectNode((Node) list.getSelectedValue(), EvaluationResultsPanel.this);
}
}
});
add(new JScrollPane(list), BorderLayout.CENTER);
}
use of javax.swing.event.ListSelectionListener in project jbpm by kiegroup.
the class ChecklistUI method initializeComponent.
private void initializeComponent() {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
getRootPane().setLayout(new BorderLayout());
getRootPane().add(panel, BorderLayout.CENTER);
JButton createButton = new JButton("New...");
createButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
create();
}
});
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.WEST;
panel.add(createButton, c);
contexts = new JComboBox(new DefaultComboBoxModel());
contexts.setPreferredSize(new Dimension(80, 24));
contexts.setSize(new Dimension(80, 24));
c = new GridBagConstraints();
c.weightx = 1;
c.anchor = GridBagConstraints.EAST;
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 5, 5, 5);
panel.add(contexts, c);
contexts.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
refresh();
}
});
JButton refreshButton = new JButton("Refresh");
refreshButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
refresh();
}
});
c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
panel.add(refreshButton, c);
itemTable = new JTable(1, 6);
itemTable.setRowHeight(35);
itemTable.setShowHorizontalLines(false);
itemTable.setShowVerticalLines(false);
itemTable.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
ctrl = false;
}
public void keyPressed(KeyEvent e) {
if (e.isControlDown()) {
ctrl = true;
}
}
});
itemTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int index = e.getFirstIndex();
if (index >= 0 && index < items.size()) {
ChecklistItem item = items.get(index);
if (item.getStatus() == Status.Created) {
String actorId = getActorId();
try {
checklistManager.claimTask(actorId, item.getTaskId());
if (ctrl) {
checklistManager.abortTask(actorId, item.getTaskId());
} else {
checklistManager.completeTask(actorId, item.getTaskId());
}
} catch (Throwable t) {
// Do nothing
}
refresh();
} else if (item.getStatus() == Status.Reserved) {
String actorId = getActorId();
if (item.getActors().equals(actorId)) {
try {
if (ctrl) {
checklistManager.abortTask(actorId, item.getTaskId());
} else {
checklistManager.completeTask(actorId, item.getTaskId());
}
} catch (Throwable t) {
// Do nothing
}
refresh();
}
} else if (item.getStatus() == Status.Optional) {
try {
checklistManager.selectOptionalTask(item.getName(), Long.valueOf((String) contexts.getSelectedItem()));
} catch (Throwable t) {
// Do nothing
t.printStackTrace();
}
refresh();
}
}
}
});
// TODO:
// default width of columns
// icons for state
// not-editable
// no selection
// (scratch for aborted?)
// replace refresh, create, etc. by icon
c = new GridBagConstraints();
c.gridy = 1;
c.weightx = 1;
c.weighty = 1;
c.gridwidth = 3;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(5, 5, 5, 5);
panel.add(itemTable, c);
JLabel nameLabel = new JLabel("Logged in as:");
c = new GridBagConstraints();
c.gridy = 2;
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.WEST;
panel.add(nameLabel, c);
userNameTextField = new JTextField("krisv");
userNameTextField.setPreferredSize(new Dimension(80, 20));
userNameTextField.setSize(new Dimension(80, 20));
c = new GridBagConstraints();
c.gridy = 2;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.WEST;
panel.add(userNameTextField, c);
JButton createItemButton = new JButton("+");
createItemButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
createNewItem();
}
});
c = new GridBagConstraints();
c.gridy = 2;
c.insets = new Insets(5, 5, 5, 5);
c.anchor = GridBagConstraints.EAST;
panel.add(createItemButton, c);
panel.doLayout();
}
use of javax.swing.event.ListSelectionListener in project jbpm by kiegroup.
the class HumanTaskHandler method initializeComponent.
private void initializeComponent() {
JPanel panel = new JPanel();
panel.setLayout(new GridBagLayout());
getRootPane().setLayout(new BorderLayout());
getRootPane().add(panel, BorderLayout.CENTER);
JLabel label = new JLabel("Actor");
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
panel.add(label, c);
actorTextField = new JTextField();
c = new GridBagConstraints();
c.weightx = 1;
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(5, 5, 5, 5);
panel.add(actorTextField, c);
JButton updateButton = new JButton("Update");
updateButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
update();
}
});
c = new GridBagConstraints();
c.insets = new Insets(5, 5, 5, 5);
panel.add(updateButton, c);
workItemsList = new JList();
workItemsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
workItemsList.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
select();
}
}
});
workItemsList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
selectButton.setEnabled(getSelectedWorkItem() != null);
}
});
c = new GridBagConstraints();
c.gridy = 1;
c.weightx = 1;
c.weighty = 1;
c.gridwidth = 3;
c.fill = GridBagConstraints.BOTH;
c.insets = new Insets(5, 5, 5, 5);
panel.add(workItemsList, c);
selectButton = new JButton("Select");
selectButton.setEnabled(false);
selectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
select();
}
});
c = new GridBagConstraints();
c.gridy = 2;
c.weightx = 1;
c.gridwidth = 3;
c.anchor = GridBagConstraints.EAST;
c.insets = new Insets(5, 5, 5, 5);
panel.add(selectButton, c);
}
use of javax.swing.event.ListSelectionListener in project chatty by chatty.
the class FavoritesDialog method setupTable.
private void setupTable() {
table.setShowGrid(false);
table.setDefaultRenderer(Boolean.class, new FavoriteRenderer());
table.setDefaultRenderer(Long.class, new TimeRenderer());
table.getTableHeader().addMouseListener(sorter);
table.getTableHeader().setReorderingAllowed(false);
table.getTableHeader().setDefaultRenderer(new MyDefaultTableHeaderCellRenderer());
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
selectionChanged();
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
doneButton.doClick();
}
}
@Override
public void mousePressed(MouseEvent e) {
openContextMenu(e);
}
@Override
public void mouseReleased(MouseEvent e) {
openContextMenu(e);
}
});
// Shortcuts
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_J, 0), "done");
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "done");
table.getActionMap().put("done", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
doneButton.doClick();
}
});
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete");
table.getActionMap().put("delete", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
remove();
}
});
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F, 0), "addFav");
table.getActionMap().put("addFav", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
addToFavoritesButton.doClick();
}
});
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_U, 0), "unFav");
table.getActionMap().put("unFav", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
removeFromFavoritesButton.doClick();
}
});
// Column Sizes
TableColumn favColumn = table.getColumnModel().getColumn(COLUMN_FAV);
favColumn.setMaxWidth(FAV_COLUMN_WIDTH);
favColumn.setMinWidth(FAV_COLUMN_WIDTH);
TableColumn timeColumn = table.getColumnModel().getColumn(COLUMN_AGO);
timeColumn.setMaxWidth(TIME_COLUMN_WIDTH);
timeColumn.setMinWidth(TIME_COLUMN_WIDTH);
}
Aggregations