use of java.awt.event.KeyAdapter in project gitblit by gitblit.
the class RepositoriesPanel method initialize.
private void initialize() {
final JButton browseRepository = new JButton(Translation.get("gb.browse"));
browseRepository.setEnabled(false);
browseRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RepositoryModel model = getSelectedRepositories().get(0);
String url = gitblit.getURL("summary", model.name, null);
Utils.browse(url);
}
});
JButton refreshRepositories = new JButton(Translation.get("gb.refresh"));
refreshRepositories.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshRepositories();
}
});
clearCache = new JButton(Translation.get("gb.clearCache"));
clearCache.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clearCache();
}
});
createRepository = new JButton(Translation.get("gb.create"));
createRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createRepository();
}
});
editRepository = new JButton(Translation.get("gb.edit"));
editRepository.setEnabled(false);
editRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editRepository(getSelectedRepositories().get(0));
}
});
delRepository = new JButton(Translation.get("gb.delete"));
delRepository.setEnabled(false);
delRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteRepositories(getSelectedRepositories());
}
});
final JButton subscribeRepository = new JButton(Translation.get("gb.subscribe") + "...");
subscribeRepository.setEnabled(false);
subscribeRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List<FeedModel> feeds = gitblit.getAvailableFeeds(getSelectedRepositories().get(0));
subscribeFeeds(feeds);
}
});
final JButton logRepository = new JButton(Translation.get("gb.log") + "...");
logRepository.setEnabled(false);
logRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RepositoryModel model = getSelectedRepositories().get(0);
showSearchDialog(false, model);
}
});
final JButton searchRepository = new JButton(Translation.get("gb.search") + "...");
searchRepository.setEnabled(false);
searchRepository.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
RepositoryModel model = getSelectedRepositories().get(0);
showSearchDialog(true, model);
}
});
SubscribedRepositoryRenderer nameRenderer = new SubscribedRepositoryRenderer(gitblit);
IndicatorsRenderer typeRenderer = new IndicatorsRenderer();
DefaultTableCellRenderer sizeRenderer = new DefaultTableCellRenderer();
sizeRenderer.setHorizontalAlignment(SwingConstants.RIGHT);
sizeRenderer.setForeground(new Color(0, 0x80, 0));
DefaultTableCellRenderer ownerRenderer = new DefaultTableCellRenderer();
ownerRenderer.setForeground(Color.gray);
ownerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
tableModel = new RepositoriesTableModel();
defaultSorter = new TableRowSorter<RepositoriesTableModel>(tableModel);
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
table.setRowSorter(defaultSorter);
table.getRowSorter().toggleSortOrder(RepositoriesTableModel.Columns.Name.ordinal());
setRepositoryRenderer(RepositoriesTableModel.Columns.Name, nameRenderer, -1);
setRepositoryRenderer(RepositoriesTableModel.Columns.Indicators, typeRenderer, 100);
setRepositoryRenderer(RepositoriesTableModel.Columns.Owner, ownerRenderer, -1);
setRepositoryRenderer(RepositoriesTableModel.Columns.Size, sizeRenderer, 60);
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
boolean singleSelection = table.getSelectedRowCount() == 1;
boolean selected = table.getSelectedRow() > -1;
if (singleSelection) {
RepositoryModel repository = getSelectedRepositories().get(0);
browseRepository.setEnabled(repository.hasCommits);
logRepository.setEnabled(repository.hasCommits);
searchRepository.setEnabled(repository.hasCommits);
subscribeRepository.setEnabled(repository.hasCommits);
} else {
browseRepository.setEnabled(false);
logRepository.setEnabled(false);
searchRepository.setEnabled(false);
subscribeRepository.setEnabled(false);
}
delRepository.setEnabled(selected);
if (selected) {
int viewRow = table.getSelectedRow();
int modelRow = table.convertRowIndexToModel(viewRow);
RepositoryModel model = ((RepositoriesTableModel) table.getModel()).list.get(modelRow);
editRepository.setEnabled(singleSelection && (gitblit.allowManagement() || gitblit.isOwner(model)));
} else {
editRepository.setEnabled(false);
}
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && gitblit.allowManagement()) {
editRepository(getSelectedRepositories().get(0));
}
}
});
filterTextfield = new JTextField();
filterTextfield.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
filterRepositories(filterTextfield.getText());
}
});
filterTextfield.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
filterRepositories(filterTextfield.getText());
}
});
JPanel repositoryFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
repositoryFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
repositoryFilterPanel.add(filterTextfield, BorderLayout.CENTER);
JPanel repositoryTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
repositoryTablePanel.add(repositoryFilterPanel, BorderLayout.NORTH);
repositoryTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
JPanel repositoryControls = new JPanel(new FlowLayout(FlowLayout.CENTER, Utils.MARGIN, 0));
repositoryControls.add(clearCache);
repositoryControls.add(refreshRepositories);
repositoryControls.add(browseRepository);
repositoryControls.add(createRepository);
repositoryControls.add(editRepository);
repositoryControls.add(delRepository);
repositoryControls.add(subscribeRepository);
repositoryControls.add(logRepository);
repositoryControls.add(searchRepository);
setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
header = new HeaderPanel(Translation.get("gb.repositories"), "git-orange-16x16.png");
add(header, BorderLayout.NORTH);
add(repositoryTablePanel, BorderLayout.CENTER);
add(repositoryControls, BorderLayout.SOUTH);
}
use of java.awt.event.KeyAdapter in project processing by processing.
the class Sketch method promptForTabName.
/**
* Displays a dialog for renaming or creating a new tab
*/
protected void promptForTabName(String prompt, String oldName) {
final JTextField field = new JTextField(oldName);
field.addKeyListener(new KeyAdapter() {
// Forget ESC, the JDialog should handle it.
// Use keyTyped to catch when the feller is actually added to the text
// field. With keyTyped, as opposed to keyPressed, the keyCode will be
// zero, even if it's enter or backspace or whatever, so the keychar
// should be used instead. Grr.
public void keyTyped(KeyEvent event) {
//System.out.println("got event " + event);
char ch = event.getKeyChar();
if (// allow.pde and .java
(ch == '_') || (ch == '.') || (('A' <= ch) && (ch <= 'Z')) || (('a' <= ch) && (ch <= 'z'))) {
// These events are allowed straight through.
} else if (ch == ' ') {
String t = field.getText();
int start = field.getSelectionStart();
int end = field.getSelectionEnd();
field.setText(t.substring(0, start) + "_" + t.substring(end));
field.setCaretPosition(start + 1);
event.consume();
} else if ((ch >= '0') && (ch <= '9')) {
// with whatever is typed.
if (field.getCaretPosition() == 0 || field.getSelectionStart() == 0) {
// number not allowed as first digit
event.consume();
}
} else if (ch == KeyEvent.VK_ENTER) {
// Slightly ugly hack that ensures OK button of the dialog consumes
// the Enter key event. Since the text field is the default component
// in the dialog, OK doesn't consume Enter key event, by default.
Container parent = field.getParent();
while (!(parent instanceof JOptionPane)) {
parent = parent.getParent();
}
JOptionPane pane = (JOptionPane) parent;
final JPanel pnlBottom = (JPanel) pane.getComponent(pane.getComponentCount() - 1);
for (int i = 0; i < pnlBottom.getComponents().length; i++) {
Component component = pnlBottom.getComponents()[i];
if (component instanceof JButton) {
final JButton okButton = (JButton) component;
if (okButton.getText().equalsIgnoreCase("OK")) {
ActionListener[] actionListeners = okButton.getActionListeners();
if (actionListeners.length > 0) {
actionListeners[0].actionPerformed(null);
event.consume();
}
}
}
}
} else {
event.consume();
}
}
});
int userReply = JOptionPane.showOptionDialog(editor, new Object[] { prompt, field }, Language.text("editor.tab.new"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, new Object[] { Language.getPrompt("ok"), Language.getPrompt("cancel") }, field);
if (userReply == JOptionPane.OK_OPTION) {
nameCode(field.getText());
}
}
use of java.awt.event.KeyAdapter in project jadx by skylot.
the class CommonSearchDialog method initResultsTable.
protected JPanel initResultsTable() {
ResultsTableCellRenderer renderer = new ResultsTableCellRenderer();
resultsModel = new ResultsModel(renderer);
resultsTable = new ResultsTable(resultsModel);
resultsTable.setShowHorizontalLines(false);
resultsTable.setDragEnabled(false);
resultsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
resultsTable.setBackground(CodeArea.BACKGROUND);
resultsTable.setColumnSelectionAllowed(false);
resultsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
resultsTable.setAutoscrolls(false);
Enumeration<TableColumn> columns = resultsTable.getColumnModel().getColumns();
while (columns.hasMoreElements()) {
TableColumn column = columns.nextElement();
column.setCellRenderer(renderer);
}
resultsTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
if (evt.getClickCount() == 2) {
openSelectedItem();
}
}
});
resultsTable.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
openSelectedItem();
}
}
});
warnLabel = new JLabel();
warnLabel.setForeground(Color.RED);
warnLabel.setVisible(false);
JPanel resultsPanel = new JPanel();
resultsPanel.setLayout(new BoxLayout(resultsPanel, BoxLayout.PAGE_AXIS));
resultsPanel.add(warnLabel);
resultsPanel.add(new JScrollPane(resultsTable, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED));
resultsPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
return resultsPanel;
}
use of java.awt.event.KeyAdapter in project android by JetBrains.
the class ThemeSelectionPanel method createUIComponents.
private void createUIComponents() {
myFilter = new ThemeFilterComponent("ANDROID_THEME_HISTORY", 10, true);
// Allow arrow up/down to navigate the filtered matches
myFilter.getTextEditor().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(final KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) {
myThemeList.dispatchEvent(e);
e.consume();
}
}
});
}
use of java.awt.event.KeyAdapter in project intellij-community by JetBrains.
the class SlicePanel method createTree.
@NotNull
private JTree createTree() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
final Tree tree = new Tree(new DefaultTreeModel(root));
tree.setOpaque(false);
tree.setToggleClickCount(-1);
SliceUsageCellRendererBase renderer = myProvider.getRenderer();
renderer.setOpaque(false);
tree.setCellRenderer(renderer);
UIUtil.setLineStyleAngled(tree);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setSelectionPath(new TreePath(root.getPath()));
//ActionGroup group = (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_METHOD_HIERARCHY_POPUP);
//PopupHandler.installPopupHandler(tree, group, ActionPlaces.METHOD_HIERARCHY_VIEW_POPUP, ActionManager.getInstance());
EditSourceOnDoubleClickHandler.install(tree);
new TreeSpeedSearch(tree);
TreeUtil.installActions(tree);
ToolTipManager.sharedInstance().registerComponent(tree);
myAutoScrollToSourceHandler.install(tree);
tree.getSelectionModel().addTreeSelectionListener(e -> treeSelectionChanged());
tree.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (KeyEvent.VK_ENTER == e.getKeyCode()) {
List<Navigatable> navigatables = getNavigatables();
if (navigatables.isEmpty())
return;
for (Navigatable navigatable : navigatables) {
if (navigatable instanceof AbstractTreeNode && ((AbstractTreeNode) navigatable).getValue() instanceof Usage) {
navigatable = (Usage) ((AbstractTreeNode) navigatable).getValue();
}
if (navigatable.canNavigateToSource()) {
navigatable.navigate(false);
if (navigatable instanceof Usage) {
((Usage) navigatable).highlightInEditor();
}
}
}
e.consume();
}
}
});
tree.addTreeWillExpandListener(new TreeWillExpandListener() {
@Override
public void treeWillCollapse(TreeExpansionEvent event) {
}
@Override
public void treeWillExpand(TreeExpansionEvent event) {
TreePath path = event.getPath();
SliceNode node = fromPath(path);
node.calculateDupNode();
}
});
return tree;
}
Aggregations