use of java.awt.event.MouseEvent in project gephi by gephi.
the class LayoutPanel method initEvents.
private void initEvents() {
layoutCombobox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
if (layoutCombobox.getSelectedItem().equals(NO_SELECTION) && model.getSelectedLayout() != null) {
setSelectedLayout(null);
} else if (layoutCombobox.getSelectedItem() instanceof LayoutBuilderWrapper) {
LayoutBuilder builder = ((LayoutBuilderWrapper) layoutCombobox.getSelectedItem()).getLayoutBuilder();
if (model.getSelectedLayout() == null || model.getSelectedBuilder() != builder) {
setSelectedLayout(builder);
}
}
}
});
infoLabel.addMouseListener(new MouseAdapter() {
RichTooltip richTooltip;
@Override
public void mouseEntered(MouseEvent e) {
if (infoLabel.isEnabled() && model != null && model.getSelectedLayout() != null) {
richTooltip = buildTooltip(model.getSelectedBuilder());
richTooltip.showTooltip(infoLabel, e.getLocationOnScreen());
}
}
@Override
public void mouseExited(MouseEvent e) {
if (richTooltip != null) {
richTooltip.hideTooltip();
richTooltip = null;
}
}
});
presetsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JPopupMenu menu = new JPopupMenu();
List<Preset> presets = layoutPresetPersistence.getPresets(model.getSelectedLayout());
if (presets != null && !presets.isEmpty()) {
for (final Preset p : presets) {
JMenuItem item = new JMenuItem(p.toString());
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
layoutPresetPersistence.loadPreset(p, model.getSelectedLayout());
refreshProperties();
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.loadPreset", model.getSelectedBuilder().getName(), p.toString()));
}
});
menu.add(item);
}
} else {
menu.add("<html><i>" + NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.nopreset") + "</i></html>");
}
JMenuItem saveItem = new JMenuItem(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset"));
saveItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String lastPresetName = NbPreferences.forModule(LayoutPanel.class).get("LayoutPanel.lastPresetName", "");
NotifyDescriptor.InputLine question = new NotifyDescriptor.InputLine(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input"), NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.presetsButton.savePreset.input.name"));
question.setInputText(lastPresetName);
if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
String input = question.getInputText();
if (input != null && !input.isEmpty()) {
layoutPresetPersistence.savePreset(input, model.getSelectedLayout());
StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(LayoutPanel.class, "LayoutPanel.status.savePreset", model.getSelectedBuilder().getName(), input));
NbPreferences.forModule(LayoutPanel.class).put("LayoutPanel.lastPresetName", input);
}
}
}
});
menu.add(new JSeparator());
menu.add(saveItem);
menu.show(layoutToolbar, 0, -menu.getPreferredSize().height);
}
});
}
use of java.awt.event.MouseEvent in project gephi by gephi.
the class DirectoryChooserUI method createTree.
private JComponent createTree() {
final DirectoryHandler dirHandler = createDirectoryHandler(fileChooser);
// #106011: don't show "colors, food, sports" sample model after init :-)
tree = new JTree(new Object[0]) {
@Override
protected void processMouseEvent(MouseEvent e) {
dirHandler.preprocessMouseEvent(e);
super.processMouseEvent(e);
}
// For speed (#127170):
@Override
public boolean isLargeModel() {
return true;
}
// To work with different font sizes (#106223); see: http://www.javalobby.org/java/forums/t19562.html
private boolean firstPaint = true;
@Override
public void setFont(Font f) {
firstPaint = true;
super.setFont(f);
}
@Override
public void paint(Graphics g) {
if (firstPaint) {
g.setFont(getFont());
setRowHeight(Math.max(/* icon height plus insets? */
17, g.getFontMetrics().getHeight()));
firstPaint = false;
// Setting the fixed height will generate another paint request, no need to complete this one
return;
}
super.paint(g);
}
};
// #105642: start with right content in tree
File curDir = fileChooser.getCurrentDirectory();
if (curDir == null) {
curDir = fileChooser.getFileSystemView().getRoots()[0];
}
updateTree(curDir);
tree.setFocusable(true);
tree.setOpaque(true);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.setToggleClickCount(0);
tree.addTreeExpansionListener(new TreeExpansionHandler());
TreeKeyHandler keyHandler = new TreeKeyHandler();
tree.addKeyListener(keyHandler);
tree.addFocusListener(keyHandler);
tree.addMouseListener(dirHandler);
tree.addFocusListener(dirHandler);
tree.addTreeSelectionListener(dirHandler);
if (fileChooser.isMultiSelectionEnabled()) {
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
} else {
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
}
TreeCellEditor tce = new DirectoryCellEditor(tree, fileChooser, new JTextField());
tree.setCellEditor(tce);
tce.addCellEditorListener(dirHandler);
tree.setCellRenderer(new DirectoryTreeRenderer());
JScrollPane scrollBar = new JScrollPane(tree);
scrollBar.setViewportView(tree);
tree.setInvokesStopCellEditing(true);
return scrollBar;
}
use of java.awt.event.MouseEvent in project gitblit by gitblit.
the class RegistrationsDialog method initialize.
private void initialize() {
NameRenderer nameRenderer = new NameRenderer();
model = new RegistrationsTableModel(registrations);
registrationsTable = Utils.newTable(model, Utils.DATE_FORMAT);
String id = registrationsTable.getColumnName(RegistrationsTableModel.Columns.Name.ordinal());
registrationsTable.getColumn(id).setCellRenderer(nameRenderer);
registrationsTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
login();
}
}
});
final JButton create = new JButton(Translation.get("gb.create"));
create.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
create();
}
});
final JButton login = new JButton(Translation.get("gb.login"));
login.setEnabled(false);
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
login();
}
});
final JButton edit = new JButton(Translation.get("gb.edit"));
edit.setEnabled(false);
edit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
edit();
}
});
final JButton delete = new JButton(Translation.get("gb.delete"));
delete.setEnabled(false);
delete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
delete();
}
});
registrationsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
boolean singleSelection = registrationsTable.getSelectedRowCount() == 1;
boolean selected = registrationsTable.getSelectedRow() > -1;
login.setEnabled(singleSelection);
edit.setEnabled(singleSelection);
delete.setEnabled(selected);
}
});
JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
controls.add(create);
controls.add(login);
controls.add(edit);
controls.add(delete);
final Insets insets = new Insets(5, 5, 5, 5);
JPanel centerPanel = new JPanel(new BorderLayout(5, 5)) {
private static final long serialVersionUID = 1L;
@Override
public Insets getInsets() {
return insets;
}
};
centerPanel.add(new HeaderPanel(Translation.get("gb.servers"), null), BorderLayout.NORTH);
centerPanel.add(new JScrollPane(registrationsTable), BorderLayout.CENTER);
centerPanel.add(controls, BorderLayout.SOUTH);
getContentPane().setLayout(new BorderLayout(5, 5));
getContentPane().add(centerPanel, BorderLayout.CENTER);
}
use of java.awt.event.MouseEvent in project gitblit by gitblit.
the class SearchDialog method initialize.
private void initialize() {
prev = new JButton("<");
prev.setToolTipText(Translation.get("gb.pagePrevious"));
prev.setEnabled(false);
prev.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
search(--page);
}
});
next = new JButton(">");
next.setToolTipText(Translation.get("gb.pageNext"));
next.setEnabled(false);
next.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
search(++page);
}
});
final JButton search = new JButton(Translation.get(isSearch ? "gb.search" : "gb.refresh"));
search.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
search(0);
}
});
final JButton viewCommit = new JButton(Translation.get("gb.view"));
viewCommit.setEnabled(false);
viewCommit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
viewCommit();
}
});
final JButton viewCommitDiff = new JButton(Translation.get("gb.commitdiff"));
viewCommitDiff.setEnabled(false);
viewCommitDiff.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
viewCommitDiff();
}
});
final JButton viewTree = new JButton(Translation.get("gb.tree"));
viewTree.setEnabled(false);
viewTree.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
viewTree();
}
});
JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, Utils.MARGIN, 0));
controls.add(viewCommit);
controls.add(viewCommitDiff);
controls.add(viewTree);
NameRenderer nameRenderer = new NameRenderer();
tableModel = new FeedEntryTableModel();
header = new HeaderPanel(Translation.get(isSearch ? "gb.search" : "gb.log"), isSearch ? "search-icon.png" : "commit_changes_16x16.png");
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
String name = table.getColumnName(FeedEntryTableModel.Columns.Author.ordinal());
table.getColumn(name).setCellRenderer(nameRenderer);
name = table.getColumnName(FeedEntryTableModel.Columns.Repository.ordinal());
table.getColumn(name).setCellRenderer(nameRenderer);
name = table.getColumnName(FeedEntryTableModel.Columns.Branch.ordinal());
table.getColumn(name).setCellRenderer(new BranchRenderer());
name = table.getColumnName(FeedEntryTableModel.Columns.Message.ordinal());
table.getColumn(name).setCellRenderer(new MessageRenderer());
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
if (e.isControlDown()) {
viewCommitDiff();
} else {
viewCommit();
}
}
}
});
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
boolean singleSelection = table.getSelectedRowCount() == 1;
viewCommit.setEnabled(singleSelection);
viewCommitDiff.setEnabled(singleSelection);
viewTree.setEnabled(singleSelection);
}
});
repositorySelector = new JComboBox(gitblit.getRepositories().toArray());
repositorySelector.setRenderer(nameRenderer);
repositorySelector.setForeground(nameRenderer.getForeground());
repositorySelector.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
// repopulate the branch list based on repository selection
// preserve branch selection, if possible
String selectedBranch = null;
if (branchSelector.getSelectedIndex() > -1) {
selectedBranch = branchSelector.getSelectedItem().toString();
}
updateBranches();
if (StringUtils.isEmpty(selectedBranch)) {
// do not select branch
branchSelector.setSelectedIndex(-1);
} else {
if (branchChoices.getIndexOf(selectedBranch) > -1) {
// select branch
branchChoices.setSelectedItem(selectedBranch);
} else {
// branch does not exist, do not select branch
branchSelector.setSelectedIndex(-1);
}
}
}
});
branchChoices = new DefaultComboBoxModel();
branchSelector = new JComboBox(branchChoices);
branchSelector.setRenderer(new BranchRenderer());
searchTypeSelector = new JComboBox(Constants.SearchType.values());
searchTypeSelector.setSelectedItem(Constants.SearchType.COMMIT);
maxHitsSelector = new JComboBox(new Integer[] { 25, 50, 75, 100 });
maxHitsSelector.setSelectedIndex(0);
searchFragment = new JTextField(25);
searchFragment.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
search(0);
}
});
JPanel queryPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));
queryPanel.add(new JLabel(Translation.get("gb.repository")));
queryPanel.add(repositorySelector);
queryPanel.add(new JLabel(Translation.get("gb.branch")));
queryPanel.add(branchSelector);
if (isSearch) {
queryPanel.add(new JLabel(Translation.get("gb.type")));
queryPanel.add(searchTypeSelector);
}
queryPanel.add(new JLabel(Translation.get("gb.maxHits")));
queryPanel.add(maxHitsSelector);
JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, Utils.MARGIN, 0));
actionsPanel.add(search);
actionsPanel.add(prev);
actionsPanel.add(next);
JPanel northControls = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
northControls.add(queryPanel, BorderLayout.WEST);
if (isSearch) {
northControls.add(searchFragment, BorderLayout.CENTER);
}
northControls.add(actionsPanel, BorderLayout.EAST);
JPanel northPanel = new JPanel(new BorderLayout(0, Utils.MARGIN));
northPanel.add(header, BorderLayout.NORTH);
northPanel.add(northControls, BorderLayout.CENTER);
JPanel contentPanel = new JPanel() {
private static final long serialVersionUID = 1L;
@Override
public Insets getInsets() {
return Utils.INSETS;
}
};
contentPanel.setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
contentPanel.add(northPanel, BorderLayout.NORTH);
contentPanel.add(new JScrollPane(table), BorderLayout.CENTER);
contentPanel.add(controls, BorderLayout.SOUTH);
setLayout(new BorderLayout());
add(contentPanel, BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent event) {
if (isSearch) {
searchFragment.requestFocus();
} else {
search(0);
}
}
@Override
public void windowActivated(WindowEvent event) {
if (isSearch) {
searchFragment.requestFocus();
}
}
});
}
use of java.awt.event.MouseEvent in project gitblit by gitblit.
the class UsersPanel method initialize.
private void initialize() {
JButton refreshUsers = new JButton(Translation.get("gb.refresh"));
refreshUsers.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshUsers();
}
});
JButton createUser = new JButton(Translation.get("gb.create"));
createUser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createUser();
}
});
final JButton editUser = new JButton(Translation.get("gb.edit"));
editUser.setEnabled(false);
editUser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editUser(getSelectedUsers().get(0));
}
});
final JButton delUser = new JButton(Translation.get("gb.delete"));
delUser.setEnabled(false);
delUser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteUsers(getSelectedUsers());
}
});
NameRenderer nameRenderer = new NameRenderer();
tableModel = new UsersTableModel();
defaultSorter = new TableRowSorter<UsersTableModel>(tableModel);
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
String name = table.getColumnName(UsersTableModel.Columns.Name.ordinal());
table.getColumn(name).setCellRenderer(nameRenderer);
int w = 130;
name = table.getColumnName(UsersTableModel.Columns.Type.ordinal());
table.getColumn(name).setMinWidth(w);
table.getColumn(name).setMaxWidth(w);
name = table.getColumnName(UsersTableModel.Columns.Teams.ordinal());
table.getColumn(name).setMinWidth(w);
table.getColumn(name).setMaxWidth(w);
name = table.getColumnName(UsersTableModel.Columns.Repositories.ordinal());
table.getColumn(name).setMinWidth(w);
table.getColumn(name).setMaxWidth(w);
table.setRowSorter(defaultSorter);
table.getRowSorter().toggleSortOrder(UsersTableModel.Columns.Name.ordinal());
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
boolean selected = table.getSelectedRow() > -1;
boolean singleSelection = table.getSelectedRows().length == 1;
editUser.setEnabled(singleSelection && selected);
delUser.setEnabled(selected);
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
editUser(getSelectedUsers().get(0));
}
}
});
filterTextfield = new JTextField();
filterTextfield.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
filterUsers(filterTextfield.getText());
}
});
filterTextfield.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
filterUsers(filterTextfield.getText());
}
});
JPanel userFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
userFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
userFilterPanel.add(filterTextfield, BorderLayout.CENTER);
JPanel userTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
userTablePanel.add(userFilterPanel, BorderLayout.NORTH);
userTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
JPanel userControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
userControls.add(refreshUsers);
userControls.add(createUser);
userControls.add(editUser);
userControls.add(delUser);
setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
header = new HeaderPanel(Translation.get("gb.users"), "user_16x16.png");
add(header, BorderLayout.NORTH);
add(userTablePanel, BorderLayout.CENTER);
add(userControls, BorderLayout.SOUTH);
}
Aggregations