use of java.awt.event.KeyAdapter in project jadx by skylot.
the class MainWindow method initUI.
private void initUI() {
mainPanel = new JPanel(new BorderLayout());
JSplitPane splitPane = new JSplitPane();
splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
mainPanel.add(splitPane);
DefaultMutableTreeNode treeRoot = new DefaultMutableTreeNode(NLS.str("msg.open_file"));
treeModel = new DefaultTreeModel(treeRoot);
tree = new JTree(treeModel);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
treeClickAction();
}
});
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
treeClickAction();
}
}
});
tree.setCellRenderer(new DefaultTreeCellRenderer() {
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean isLeaf, int row, boolean focused) {
Component c = super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, focused);
if (value instanceof JNode) {
setIcon(((JNode) value).getIcon());
}
return c;
}
});
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException {
TreePath path = event.getPath();
Object node = path.getLastPathComponent();
if (node instanceof JClass) {
JClass cls = (JClass) node;
cls.getRootClass().load();
}
}
@Override
public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException {
}
});
progressPane = new ProgressPanel(this, true);
JPanel leftPane = new JPanel(new BorderLayout());
leftPane.add(new JScrollPane(tree), BorderLayout.CENTER);
leftPane.add(progressPane, BorderLayout.PAGE_END);
splitPane.setLeftComponent(leftPane);
tabbedPane = new TabbedPane(this);
splitPane.setRightComponent(tabbedPane);
dropTarget = new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
setContentPane(mainPanel);
setTitle(DEFAULT_TITLE);
}
use of java.awt.event.KeyAdapter in project jadx by skylot.
the class SearchDialog method initUI.
private void initUI() {
JLabel findLabel = new JLabel(NLS.str("search_dialog.open_by_name"));
searchField = new JTextField();
searchField.setAlignmentX(LEFT_ALIGNMENT);
searchField.getDocument().addDocumentListener(new SearchFieldListener());
new TextStandardActions(searchField);
JCheckBox clsChBox = makeOptionsCheckBox(NLS.str("search_dialog.class"), SearchOptions.CLASS);
JCheckBox mthChBox = makeOptionsCheckBox(NLS.str("search_dialog.method"), SearchOptions.METHOD);
JCheckBox fldChBox = makeOptionsCheckBox(NLS.str("search_dialog.field"), SearchOptions.FIELD);
JCheckBox codeChBox = makeOptionsCheckBox(NLS.str("search_dialog.code"), SearchOptions.CODE);
JPanel searchOptions = new JPanel(new FlowLayout(FlowLayout.LEFT));
searchOptions.setBorder(BorderFactory.createTitledBorder(NLS.str("search_dialog.search_in")));
searchOptions.add(clsChBox);
searchOptions.add(mthChBox);
searchOptions.add(fldChBox);
searchOptions.add(codeChBox);
searchOptions.setAlignmentX(LEFT_ALIGNMENT);
JPanel searchPane = new JPanel();
searchPane.setLayout(new BoxLayout(searchPane, BoxLayout.PAGE_AXIS));
findLabel.setLabelFor(searchField);
searchPane.add(findLabel);
searchPane.add(Box.createRigidArea(new Dimension(0, 5)));
searchPane.add(searchField);
searchPane.add(Box.createRigidArea(new Dimension(0, 5)));
searchPane.add(searchOptions);
searchPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
initCommon();
JPanel resultsPanel = initResultsTable();
JPanel buttonPane = initButtonsPanel();
Container contentPane = getContentPane();
contentPane.add(searchPane, BorderLayout.PAGE_START);
contentPane.add(resultsPanel, BorderLayout.CENTER);
contentPane.add(buttonPane, BorderLayout.PAGE_END);
searchField.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (resultsModel.getRowCount() != 0) {
resultsTable.setRowSelectionInterval(0, 0);
}
resultsTable.requestFocus();
}
}
});
setTitle(NLS.str("menu.text_search"));
pack();
setSize(800, 500);
setLocationRelativeTo(null);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
setModalityType(ModalityType.MODELESS);
}
use of java.awt.event.KeyAdapter in project jgnash by ccavanaugh.
the class AbstractTransactionEntryPanel method init.
private void init() {
amountField = new JFloatField(account.getCurrencyNode());
accountPanel = new AccountExchangePanel(account.getCurrencyNode(), account, amountField);
enterButton = new JButton(rb.getString("Button.Enter"));
cancelButton = new JButton(rb.getString("Button.Clear"));
memoField = AutoCompleteFactory.getMemoField();
reconciledButton = new IndeterminateCheckBox(rb.getString("Button.Reconciled"));
reconciledButton.setHorizontalTextPosition(SwingConstants.LEADING);
reconciledButton.setMargin(new Insets(0, 0, 0, 0));
/* Connect the buttons to the form */
cancelButton.addActionListener(this);
enterButton.addActionListener(this);
/* Allows the user to submit the form from the keyboard when the enter button is selected */
KeyAdapter enterKeyListener = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
enterAction();
}
}
};
enterButton.addKeyListener(enterKeyListener);
amountField.addKeyListener(enterKeyListener);
// focus will return to the first field
setFocusCycleRoot(true);
}
use of java.awt.event.KeyAdapter in project jgnash by ccavanaugh.
the class RecurringPanel method initComponents.
private void initComponents() {
JPanel toolPanel = new JPanel(new BorderLayout());
JToolBar toolBar = new JToolBar();
toolBar.setFloatable(false);
toolBar.setRollover(true);
newButton = new RollOverButton(rb.getString("Button.New"), IconUtils.getIcon("/jgnash/resource/document-new.png"));
modifyButton = new RollOverButton(rb.getString("Button.Modify"), IconUtils.getIcon("/jgnash/resource/document-properties.png"));
deleteButton = new RollOverButton(rb.getString("Button.Delete"), IconUtils.getIcon("/jgnash/resource/edit-delete.png"));
remindersButton = new RollOverButton(rb.getString("Button.CheckReminders"), IconUtils.getIcon("/jgnash/resource/view-refresh.png"));
reminderTable = new FormattedJTable();
reminderTable.setAutoCreateRowSorter(true);
reminderTable.setFillsViewportHeight(true);
reminderTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
reminderTable.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(final KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DELETE) {
deleteReminder();
}
}
});
reminderTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2) {
showModifyDialog();
}
}
});
setLayout(new BorderLayout());
toolBar.add(newButton);
toolBar.add(modifyButton);
toolBar.add(deleteButton);
toolBar.addSeparator();
toolBar.add(remindersButton);
toolPanel.add(toolBar, BorderLayout.NORTH);
toolPanel.add(new JSeparator(), BorderLayout.CENTER);
add(toolPanel, java.awt.BorderLayout.NORTH);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(new EmptyBorder(new Insets(0, 0, 0, 0)));
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setAutoscrolls(true);
scrollPane.setViewportView(reminderTable);
add(scrollPane, java.awt.BorderLayout.CENTER);
deleteButton.addActionListener(this);
modifyButton.addActionListener(this);
newButton.addActionListener(this);
remindersButton.addActionListener(this);
}
use of java.awt.event.KeyAdapter in project JMRI by JMRI.
the class PanelEditor method init.
@Override
protected void init(String name) {
Runnable r = new Runnable() {
@Override
public void run() {
try {
// Build resource catalog and load CatalogTree.xml now
jmri.jmrit.catalog.CatalogPanel catalog = new jmri.jmrit.catalog.CatalogPanel();
catalog.createNewBranch("IFJAR", "Program Directory", "resources");
} catch (Exception ex) {
log.error("Error in trying to setup preferences " + ex.toString());
}
}
};
Thread thr = new Thread(r);
thr.start();
java.awt.Container contentPane = this.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// common items
JPanel common = new JPanel();
common.setLayout(new FlowLayout());
common.add(new JLabel(" x:"));
common.add(nextX);
common.add(new JLabel(" y:"));
common.add(nextY);
contentPane.add(common);
setAllEditable(true);
setShowHidden(true);
super.setTargetPanel(null, makeFrame(name));
super.setTargetPanelSize(400, 300);
super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("SansSerif", Font.PLAIN, 12), Color.black, new Color(215, 225, 255), Color.black));
// set scrollbar initial state
setScroll(SCROLL_BOTH);
// add menu - not using PanelMenu, because it now
// has other stuff in it?
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
menuBar.add(fileMenu);
fileMenu.add(new jmri.jmrit.display.NewPanelAction(Bundle.getMessage("MenuItemNew")));
fileMenu.add(new jmri.configurexml.StoreXmlUserAction(Bundle.getMessage("MenuItemStore")));
JMenuItem storeIndexItem = new JMenuItem(Bundle.getMessage("MIStoreImageIndex"));
fileMenu.add(storeIndexItem);
storeIndexItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
jmri.jmrit.catalog.ImageIndexEditor.storeImageIndex();
}
});
JMenuItem editItem = new JMenuItem(Bundle.getMessage("editIndexMenu"));
editItem.addActionListener(new ActionListener() {
PanelEditor panelEd;
@Override
public void actionPerformed(ActionEvent e) {
ImageIndexEditor ii = ImageIndexEditor.instance(panelEd);
ii.pack();
ii.setVisible(true);
}
ActionListener init(PanelEditor pe) {
panelEd = pe;
return this;
}
}.init(this));
fileMenu.add(editItem);
editItem = new JMenuItem(Bundle.getMessage("CPEView"));
fileMenu.add(editItem);
editItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
changeView("jmri.jmrit.display.controlPanelEditor.ControlPanelEditor");
}
});
fileMenu.addSeparator();
JMenuItem deleteItem = new JMenuItem(Bundle.getMessage("DeletePanel"));
fileMenu.add(deleteItem);
deleteItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (deletePanel()) {
dispose(true);
}
}
});
setJMenuBar(menuBar);
addHelpMenu("package.jmri.jmrit.display.PanelEditor", true);
// allow naming the panel
{
JPanel namep = new JPanel();
namep.setLayout(new FlowLayout());
JButton b = new JButton(Bundle.getMessage("ButtonSetName"));
b.addActionListener(new ActionListener() {
PanelEditor editor;
@Override
public void actionPerformed(ActionEvent e) {
// prompt for name
String newName = JOptionPane.showInputDialog(null, Bundle.getMessage("PromptNewName"));
if (newName == null) {
// cancelled
return;
}
if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(newName)) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("CanNotRename"), Bundle.getMessage("PanelExist"), JOptionPane.ERROR_MESSAGE);
return;
}
if (getTargetPanel().getTopLevelAncestor() != null) {
((JFrame) getTargetPanel().getTopLevelAncestor()).setTitle(newName);
}
editor.setTitle();
jmri.jmrit.display.PanelMenu.instance().renameEditorPanel(editor);
}
ActionListener init(PanelEditor e) {
editor = e;
return this;
}
}.init(this));
namep.add(b);
this.getContentPane().add(namep);
}
// add a text label
{
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(labelAdd);
labelAdd.setEnabled(false);
labelAdd.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
panel.add(nextLabel);
labelAdd.addActionListener(new ActionListener() {
PanelEditor editor;
@Override
public void actionPerformed(ActionEvent a) {
editor.addLabel(nextLabel.getText());
}
ActionListener init(PanelEditor e) {
editor = e;
return this;
}
}.init(this));
nextLabel.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent a) {
if (nextLabel.getText().equals("")) {
labelAdd.setEnabled(false);
labelAdd.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
} else {
labelAdd.setEnabled(true);
labelAdd.setToolTipText(null);
}
}
});
this.getContentPane().add(panel);
}
// Selection of the type of entity for the icon to represent is done from a combobox
_addIconBox = new JComboBox<ComboBoxItem>();
_addIconBox.setMinimumSize(new Dimension(75, 75));
_addIconBox.setMaximumSize(new Dimension(200, 200));
_addIconBox.addItem(new ComboBoxItem("RightTurnout"));
_addIconBox.addItem(new ComboBoxItem("LeftTurnout"));
_addIconBox.addItem(new ComboBoxItem("SlipTOEditor"));
// NOI18N
_addIconBox.addItem(new ComboBoxItem("Sensor"));
_addIconBox.addItem(new ComboBoxItem("SignalHead"));
_addIconBox.addItem(new ComboBoxItem("SignalMast"));
_addIconBox.addItem(new ComboBoxItem("Memory"));
_addIconBox.addItem(new ComboBoxItem("BlockLabel"));
_addIconBox.addItem(new ComboBoxItem("Reporter"));
_addIconBox.addItem(new ComboBoxItem("Light"));
_addIconBox.addItem(new ComboBoxItem("Background"));
_addIconBox.addItem(new ComboBoxItem("MultiSensor"));
_addIconBox.addItem(new ComboBoxItem("RPSreporter"));
_addIconBox.addItem(new ComboBoxItem("FastClock"));
_addIconBox.addItem(new ComboBoxItem("Icon"));
_addIconBox.setSelectedIndex(-1);
// must be AFTER no selection is set
_addIconBox.addItemListener(this);
JPanel p1 = new JPanel();
p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
JPanel p2 = new JPanel();
p2.setLayout(new FlowLayout());
p2.add(new JLabel(Bundle.getMessage("selectTypeIcon")));
p1.add(p2);
p1.add(_addIconBox);
contentPane.add(p1);
// edit, position, control controls
{
// edit mode item
contentPane.add(editableBox);
editableBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setAllEditable(editableBox.isSelected());
hiddenCheckBoxListener();
}
});
editableBox.setSelected(isEditable());
// positionable item
contentPane.add(positionableBox);
positionableBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setAllPositionable(positionableBox.isSelected());
}
});
positionableBox.setSelected(allPositionable());
// controlable item
contentPane.add(controllingBox);
controllingBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setAllControlling(controllingBox.isSelected());
}
});
controllingBox.setSelected(allControlling());
// hidden item
contentPane.add(hiddenBox);
hiddenCheckBoxListener();
hiddenBox.setSelected(showHidden());
/*
contentPane.add(showCoordinatesBox);
showCoordinatesBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setShowCoordinates(showCoordinatesBox.isSelected());
}
});
showCoordinatesBox.setSelected(showCoordinates());
*/
contentPane.add(showTooltipBox);
showTooltipBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setAllShowTooltip(showTooltipBox.isSelected());
}
});
showTooltipBox.setSelected(showTooltip());
contentPane.add(menuBox);
menuBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setPanelMenuVisible(menuBox.isSelected());
}
});
menuBox.setSelected(true);
// Show/Hide Scroll Bars
JPanel scrollPanel = new JPanel();
scrollPanel.setLayout(new FlowLayout());
scrollableLabel.setLabelFor(scrollableComboBox);
scrollPanel.add(scrollableLabel);
scrollPanel.add(scrollableComboBox);
contentPane.add(scrollPanel);
scrollableComboBox.addItem(Bundle.getMessage("ScrollNone"));
scrollableComboBox.addItem(Bundle.getMessage("ScrollBoth"));
scrollableComboBox.addItem(Bundle.getMessage("ScrollHorizontal"));
scrollableComboBox.addItem(Bundle.getMessage("ScrollVertical"));
scrollableComboBox.setSelectedIndex(SCROLL_BOTH);
scrollableComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setScroll(scrollableComboBox.getSelectedIndex());
}
});
}
// register the resulting panel for later configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerUser(this);
}
// when this window closes, set contents of target uneditable
addWindowListener(new java.awt.event.WindowAdapter() {
HashMap<String, JFrameItem> iconAdderFrames;
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
Iterator<JFrameItem> iter = iconAdderFrames.values().iterator();
while (iter.hasNext()) {
JFrameItem frame = iter.next();
frame.dispose();
}
}
WindowAdapter init(HashMap<String, JFrameItem> f) {
iconAdderFrames = f;
return this;
}
}.init(_iconEditorFrame));
// and don't destroy the window
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
// move this editor panel off the panel's position
getTargetFrame().setLocationRelativeTo(this);
getTargetFrame().pack();
getTargetFrame().setVisible(true);
log.debug("PanelEditor ctor done.");
}
Aggregations