@Override public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (CANCEL_COMMAND.equals(command)) { closeDialog(); setTextBox(originalText); } else { // must be CLOSE or SAVE_CLOSE COMMANDS closeDialog(); } }
private void init(String text) { createDialogBox(); setTextBox(text); dialog.setVisible(true); }
/** * Dialog text box */ public TextBoxDialoger() { // Empty box init(""); //$NON-NLS-1$ }
@Override public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2) { // double (pressed) click TableModel tm = table.getModel(); Object value = tm.getValueAt(table.getSelectedRow(), table.getSelectedColumn()); if (value instanceof String) { if (table.getCellEditor() != null) { table.getCellEditor().cancelCellEditing(); // in main table (evt mousePressed because cell is editable) } TextBoxDialoger tbd = new TextBoxDialoger(value.toString(), true); tm.setValueAt(tbd.getTextBox(), table.getSelectedRow(), table.getSelectedColumn()); } // else do nothing (cell isn't a string to edit) } }
@Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { // double click TableModel tm = table.getModel(); Object value = tm.getValueAt(table.getSelectedRow(), table.getSelectedColumn()); new TextBoxDialoger(value.toString(), false); // view only NOSONAR this instantiation opens a popup } } }
/** * Dialog text box * @param text - text to display in a box */ public TextBoxDialoger(String text) { init(text); }
/** * Dialog text box * @param text - text to display in a box * @param editable - allow to modify text */ public TextBoxDialoger(String text, boolean editable) { this.editable = editable; init(text); }