use of javax.swing.AbstractAction in project vcell by virtualcell.
the class ReactionCartoonTool method editInPlace.
private void editInPlace(final Shape selectedShape, Point worldPoint) {
if (getGraphPane().getComponentCount() > 0) {
// remove any existing editor
getGraphPane().remove(0);
}
Rectangle labelOutline = null;
// What kind of thing is being edited
if (selectedShape instanceof ReactionContainerShape) {
labelOutline = ((ReactionContainerShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
if (!labelOutline.contains(worldPoint)) {
return;
}
} else if (selectedShape instanceof SpeciesContextShape) {
labelOutline = ((SpeciesContextShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
} else if (selectedShape instanceof SimpleReactionShape) {
labelOutline = ((SimpleReactionShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
} else if (selectedShape instanceof FluxReactionShape) {
labelOutline = ((FluxReactionShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
} else if (selectedShape instanceof ReactionRuleDiagramShape) {
labelOutline = ((ReactionRuleDiagramShape) selectedShape).getLabelOutline(selectedShape.getAbsX(), selectedShape.getAbsY());
} else {
return;
}
// Add press 'Enter' action, 'Escape' action, editor gets focus and mouse 'Exit' parent action
if (true) {
final JTextField jTextField = new JTextField(selectedShape.getLabel());
jTextField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
// Type specific edit actions
if (selectedShape instanceof ReactionContainerShape) {
((ReactionContainerShape) selectedShape).getStructure().setName(jTextField.getText(), true);
} else if (selectedShape instanceof SpeciesContextShape) {
((SpeciesContextShape) selectedShape).getSpeciesContext().setName(jTextField.getText());
} else if (selectedShape instanceof SimpleReactionShape) {
((SimpleReactionShape) selectedShape).getReactionStep().setName(jTextField.getText());
} else if (selectedShape instanceof FluxReactionShape) {
((FluxReactionShape) selectedShape).getReactionStep().setName(jTextField.getText());
} else if (selectedShape instanceof ReactionRuleDiagramShape) {
((ReactionRuleDiagramShape) selectedShape).getReactionRule().setName(jTextField.getText());
}
} catch (Exception e2) {
e2.printStackTrace();
DialogUtils.showErrorDialog(ReactionCartoonTool.this.getGraphPane(), e2.getMessage());
}
stopEditing();
}
});
// just to be sure
ReactionCartoonTool.this.getGraphPane().removeMouseListener(myStopEditAdapter);
ReactionCartoonTool.this.getGraphPane().addMouseListener(myStopEditAdapter);
getGraphModel().removeGraphListener(myGraphListener);
getGraphModel().addGraphListener(myGraphListener);
InputMap im = jTextField.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
ActionMap am = jTextField.getActionMap();
im.put(KeyStroke.getKeyStroke("ESCAPE"), "cancelChange");
am.put("cancelChange", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
stopEditing();
}
});
GraphResizeManager grm = getGraphModel().getResizeManager();
jTextField.setBounds((int) grm.zoom(labelOutline.x), (int) grm.zoom(labelOutline.y), Math.max((int) grm.zoom(labelOutline.width + 2), 100), Math.max((int) grm.zoom(labelOutline.height + 2), 20));
getGraphPane().add(jTextField);
getGraphPane().validate();
jTextField.requestFocus();
}
return;
}
use of javax.swing.AbstractAction in project gephi by gephi.
the class Generate method getMenuPresenter.
@Override
public JMenuItem getMenuPresenter() {
JMenu menu = new JMenu(NbBundle.getMessage(Generate.class, "CTL_Generate"));
final GeneratorController generatorController = Lookup.getDefault().lookup(GeneratorController.class);
if (generatorController != null) {
for (final Generator gen : generatorController.getGenerators()) {
String menuName = gen.getName() + "...";
JMenuItem menuItem = new JMenuItem(new AbstractAction(menuName) {
@Override
public void actionPerformed(ActionEvent e) {
generatorController.generate(gen);
}
});
menu.add(menuItem);
}
}
return menu;
}
use of javax.swing.AbstractAction in project gephi by gephi.
the class UIExporterPDFPanel method initEvents.
private void initEvents() {
pageSizeCombo.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
Object selectedItem = pageSizeCombo.getSelectedItem();
if (selectedItem != customSizeString) {
PageSizeItem pageSize = (PageSizeItem) selectedItem;
setPageSize(pageSize);
}
}
});
widthTextField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updatePageSize();
}
});
heightTextField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updatePageSize();
}
});
unitLink.setAction(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
millimeter = !millimeter;
refreshUnit(true);
}
});
}
use of javax.swing.AbstractAction in project languagetool by languagetool-org.
the class FontChooser method initComponents.
private void initComponents() {
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(stroke, "Hide");
getRootPane().getActionMap().put("Hide", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
selectedFont = null;
setVisible(false);
}
});
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
selectedFont = null;
setVisible(false);
}
});
setTitle(messages.getString("FontChooser.title"));
fontStylesArray = new String[] { messages.getString("FontChooser.style.plain"), messages.getString("FontChooser.style.bold"), messages.getString("FontChooser.style.italic"), messages.getString("FontChooser.style.bold_italic") };
String[] fontNamesArray = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
c.insets = new Insets(4, 4, 4, 4);
JPanel fontPanel = new JPanel(new GridBagLayout());
c.gridx = 0;
c.gridy = 0;
c.fill = GridBagConstraints.HORIZONTAL;
JLabel fontNameLabel = new JLabel(messages.getString("FontChooser.label.name"));
fontPanel.add(fontNameLabel, c);
c.gridx = 1;
c.gridy = 0;
JLabel fontStyleLabel = new JLabel(messages.getString("FontChooser.label.style"));
fontPanel.add(fontStyleLabel, c);
c.gridx = 2;
c.gridy = 0;
JLabel fontSizeLabel = new JLabel(messages.getString("FontChooser.label.size"));
fontPanel.add(fontSizeLabel, c);
c.gridx = 0;
c.gridy = 1;
c.weightx = 1.0;
c.fill = GridBagConstraints.HORIZONTAL;
fontNameTextField = new JTextField();
fontNameTextField.setEnabled(false);
fontNameTextField.getDocument().addDocumentListener(this);
fontPanel.add(fontNameTextField, c);
c.weightx = 0.0;
c.gridx = 1;
c.gridy = 1;
fontStyleTextField = new JTextField();
fontStyleTextField.setEnabled(false);
fontStyleTextField.getDocument().addDocumentListener(this);
fontPanel.add(fontStyleTextField, c);
c.gridx = 2;
c.gridy = 1;
fontSizeTextField = new JTextField();
fontSizeTextField.setColumns(4);
fontSizeTextField.getDocument().addDocumentListener(this);
fontPanel.add(fontSizeTextField, c);
c.gridx = 0;
c.gridy = 2;
c.weightx = 1.0;
c.weighty = 1;
c.fill = GridBagConstraints.BOTH;
fontNameList = new JList<>(fontNamesArray);
fontNameList.addListSelectionListener(this);
fontNameList.setVisibleRowCount(5);
fontNameList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane fontNameListPane = new JScrollPane(fontNameList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
fontPanel.add(fontNameListPane, c);
c.gridx = 1;
c.gridy = 2;
c.weightx = 0.5;
fontStyleList = new JList<>(fontStylesArray);
fontStyleList.addListSelectionListener(this);
fontStyleList.setVisibleRowCount(5);
fontStyleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
JScrollPane fontStyleListPane = new JScrollPane(fontStyleList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
fontPanel.add(fontStyleListPane, c);
c.gridx = 2;
c.gridy = 2;
fontSizeList = new JList<>(fontSizesArray);
fontSizeList.addListSelectionListener(this);
fontSizeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fontSizeList.setVisibleRowCount(5);
JScrollPane fontSizeListPane = new JScrollPane(fontSizeList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
fontPanel.add(fontSizeListPane, c);
c.insets = new Insets(8, 8, 4, 8);
c.gridx = 0;
c.gridy = 0;
c.weightx = 0.0;
c.weighty = 0.4;
getContentPane().add(fontPanel, c);
c.insets = new Insets(4, 8, 4, 8);
c.gridx = 0;
c.gridy = 1;
c.weightx = 1.0;
c.weighty = 0.6;
previewArea = new JTextArea(messages.getString("FontChooser.pangram"));
previewArea.setLineWrap(true);
previewArea.setRows(4);
JScrollPane pane = new JScrollPane(previewArea);
TitledBorder border = BorderFactory.createTitledBorder(messages.getString("FontChooser.preview"));
pane.setBorder(border);
getContentPane().add(pane, c);
JPanel buttonPanel = new JPanel(new GridBagLayout());
c.insets = new Insets(4, 4, 4, 4);
c.gridx = 0;
c.gridy = 0;
c.weightx = 1.0;
c.weighty = 0.0;
c.anchor = GridBagConstraints.LINE_START;
c.fill = GridBagConstraints.NONE;
JButton resetButton = new JButton(Tools.getLabel(messages.getString("FontChooser.reset")));
resetButton.setMnemonic(Tools.getMnemonic(messages.getString("FontChooser.reset")));
resetButton.setActionCommand(ACTION_COMMAND_RESET);
resetButton.addActionListener(this);
buttonPanel.add(resetButton, c);
c.gridx = 1;
c.gridy = 0;
c.weightx = 0.0;
c.weighty = 0.0;
c.anchor = GridBagConstraints.LINE_END;
c.fill = GridBagConstraints.NONE;
JButton cancelButton = new JButton(Tools.getLabel(messages.getString("guiCancelButton")));
cancelButton.setMnemonic(Tools.getMnemonic(messages.getString("guiCancelButton")));
cancelButton.setActionCommand(ACTION_COMMAND_CANCEL);
cancelButton.addActionListener(this);
buttonPanel.add(cancelButton, c);
c.gridx = 2;
c.gridy = 0;
JButton okButton = new JButton(Tools.getLabel(messages.getString("guiOKButton")));
okButton.setMnemonic(Tools.getMnemonic(messages.getString("guiOKButton")));
okButton.setActionCommand(ACTION_COMMAND_OK);
okButton.addActionListener(this);
buttonPanel.add(okButton, c);
c.insets = new Insets(4, 8, 8, 8);
c.gridx = 0;
c.gridy = 2;
c.anchor = GridBagConstraints.LINE_START;
c.fill = GridBagConstraints.HORIZONTAL;
getContentPane().add(buttonPanel, c);
this.defaultFont = previewArea.getFont();
setDefaultFont();
getRootPane().setDefaultButton(cancelButton);
this.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));
pack();
}
use of javax.swing.AbstractAction in project Smack by igniterealtime.
the class EnhancedDebugger method addBasicPanels.
private void addBasicPanels() {
JSplitPane allPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
allPane.setOneTouchExpandable(true);
messagesTable = new DefaultTableModel(new Object[] { "Hide", "Timestamp", "", "", "Message", "Id", "Type", "To", "From" }, 0) {
// CHECKSTYLE:OFF
private static final long serialVersionUID = 8136121224474217264L;
@Override
public boolean isCellEditable(int rowIndex, int mColIndex) {
// CHECKSTYLE:ON
return false;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
if (columnIndex == 2 || columnIndex == 3) {
return Icon.class;
}
return super.getColumnClass(columnIndex);
}
};
JTable table = new JTable(messagesTable);
// Allow only single a selection
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// Hide the first column
table.getColumnModel().getColumn(0).setMaxWidth(0);
table.getColumnModel().getColumn(0).setMinWidth(0);
table.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
table.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
// Set the column "timestamp" size
table.getColumnModel().getColumn(1).setMaxWidth(300);
table.getColumnModel().getColumn(1).setPreferredWidth(90);
// Set the column "direction" icon size
table.getColumnModel().getColumn(2).setMaxWidth(50);
table.getColumnModel().getColumn(2).setPreferredWidth(30);
// Set the column "packet type" icon size
table.getColumnModel().getColumn(3).setMaxWidth(50);
table.getColumnModel().getColumn(3).setPreferredWidth(30);
// Set the column "Id" size
table.getColumnModel().getColumn(5).setMaxWidth(100);
table.getColumnModel().getColumn(5).setPreferredWidth(55);
// Set the column "type" size
table.getColumnModel().getColumn(6).setMaxWidth(200);
table.getColumnModel().getColumn(6).setPreferredWidth(50);
// Set the column "to" size
table.getColumnModel().getColumn(7).setMaxWidth(300);
table.getColumnModel().getColumn(7).setPreferredWidth(90);
// Set the column "from" size
table.getColumnModel().getColumn(8).setMaxWidth(300);
table.getColumnModel().getColumn(8).setPreferredWidth(90);
// Create a table listener that listen for row selection events
SelectionListener selectionListener = new SelectionListener(table);
table.getSelectionModel().addListSelectionListener(selectionListener);
table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener);
allPane.setTopComponent(new JScrollPane(table));
messageTextArea = new JTextArea();
messageTextArea.setEditable(false);
// Add pop-up menu.
JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem1 = new JMenuItem("Copy");
menuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// Set the sent text as the new content of the clipboard
clipboard.setContents(new StringSelection(messageTextArea.getText()), null);
}
});
menu.add(menuItem1);
// Add listener to the text area so the popup menu can come up.
messageTextArea.addMouseListener(new PopupListener(menu));
// CHECKSTYLE:OFF
JPanel sublayout = new JPanel(new BorderLayout());
sublayout.add(new JScrollPane(messageTextArea), BorderLayout.CENTER);
JButton clearb = new JButton("Clear All Packets");
clearb.addActionListener(new AbstractAction() {
private static final long serialVersionUID = -8576045822764763613L;
@Override
public void actionPerformed(ActionEvent e) {
messagesTable.setRowCount(0);
}
});
// CHECKSTYLE:ON
sublayout.add(clearb, BorderLayout.NORTH);
allPane.setBottomComponent(sublayout);
allPane.setDividerLocation(150);
tabbedPane.add("All Packets", allPane);
tabbedPane.setToolTipTextAt(0, "Sent and received packets processed by Smack");
// Create UI elements for client generated XML traffic.
final JTextArea sentText = new JTextArea();
sentText.setWrapStyleWord(true);
sentText.setLineWrap(true);
sentText.setEditable(false);
sentText.setForeground(new Color(112, 3, 3));
tabbedPane.add("Raw Sent Packets", new JScrollPane(sentText));
tabbedPane.setToolTipTextAt(1, "Raw text of the sent packets");
// Add pop-up menu.
menu = new JPopupMenu();
menuItem1 = new JMenuItem("Copy");
menuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// Set the sent text as the new content of the clipboard
clipboard.setContents(new StringSelection(sentText.getText()), null);
}
});
JMenuItem menuItem2 = new JMenuItem("Clear");
menuItem2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
sentText.setText("");
}
});
// Add listener to the text area so the popup menu can come up.
sentText.addMouseListener(new PopupListener(menu));
menu.add(menuItem1);
menu.add(menuItem2);
// Create UI elements for server generated XML traffic.
final JTextArea receivedText = new JTextArea();
receivedText.setWrapStyleWord(true);
receivedText.setLineWrap(true);
receivedText.setEditable(false);
receivedText.setForeground(new Color(6, 76, 133));
tabbedPane.add("Raw Received Packets", new JScrollPane(receivedText));
tabbedPane.setToolTipTextAt(2, "Raw text of the received packets before Smack process them");
// Add pop-up menu.
menu = new JPopupMenu();
menuItem1 = new JMenuItem("Copy");
menuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Get the clipboard
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// Set the sent text as the new content of the clipboard
clipboard.setContents(new StringSelection(receivedText.getText()), null);
}
});
menuItem2 = new JMenuItem("Clear");
menuItem2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
receivedText.setText("");
}
});
// Add listener to the text area so the popup menu can come up.
receivedText.addMouseListener(new PopupListener(menu));
menu.add(menuItem1);
menu.add(menuItem2);
// Create a special Reader that wraps the main Reader and logs data to the GUI.
ObservableReader debugReader = new ObservableReader(reader);
readerListener = new ReaderListener() {
@Override
public void read(final String str) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER && !EnhancedDebuggerWindow.getInstance().isVisible()) {
// Do not add content if the parent is not visible
return;
}
int index = str.lastIndexOf(">");
if (index != -1) {
if (receivedText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
try {
receivedText.replaceRange("", 0, receivedText.getLineEndOffset(0));
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "Error with line offset, MAX_TABLE_ROWS is set too low: " + EnhancedDebuggerWindow.MAX_TABLE_ROWS, e);
}
}
receivedText.append(str.substring(0, index + 1));
receivedText.append(NEWLINE);
if (str.length() > index) {
receivedText.append(str.substring(index + 1));
}
} else {
receivedText.append(str);
}
}
});
}
};
debugReader.addReaderListener(readerListener);
// Create a special Writer that wraps the main Writer and logs data to the GUI.
ObservableWriter debugWriter = new ObservableWriter(writer);
writerListener = new WriterListener() {
@Override
public void write(final String str) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
if (EnhancedDebuggerWindow.PERSISTED_DEBUGGER && !EnhancedDebuggerWindow.getInstance().isVisible()) {
// Do not add content if the parent is not visible
return;
}
if (sentText.getLineCount() >= EnhancedDebuggerWindow.MAX_TABLE_ROWS) {
try {
sentText.replaceRange("", 0, sentText.getLineEndOffset(0));
} catch (BadLocationException e) {
LOGGER.log(Level.SEVERE, "Error with line offset, MAX_TABLE_ROWS is set too low: " + EnhancedDebuggerWindow.MAX_TABLE_ROWS, e);
}
}
sentText.append(str);
if (str.endsWith(">")) {
sentText.append(NEWLINE);
}
}
});
}
};
debugWriter.addWriterListener(writerListener);
// Assign the reader/writer objects to use the debug versions. The packet reader
// and writer will use the debug versions when they are created.
reader = debugReader;
writer = debugWriter;
}
Aggregations