use of javax.swing.event.ListSelectionEvent in project gitblit by gitblit.
the class TeamsPanel method initialize.
private void initialize() {
JButton refreshTeams = new JButton(Translation.get("gb.refresh"));
refreshTeams.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshTeams();
}
});
JButton createTeam = new JButton(Translation.get("gb.create"));
createTeam.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
createTeam();
}
});
final JButton editTeam = new JButton(Translation.get("gb.edit"));
editTeam.setEnabled(false);
editTeam.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
editTeam(getSelectedTeams().get(0));
}
});
final JButton delTeam = new JButton(Translation.get("gb.delete"));
delTeam.setEnabled(false);
delTeam.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteTeams(getSelectedTeams());
}
});
NameRenderer nameRenderer = new NameRenderer();
tableModel = new TeamsTableModel();
defaultSorter = new TableRowSorter<TeamsTableModel>(tableModel);
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
String name = table.getColumnName(TeamsTableModel.Columns.Name.ordinal());
table.getColumn(name).setCellRenderer(nameRenderer);
int w = 125;
name = table.getColumnName(TeamsTableModel.Columns.Members.ordinal());
table.getColumn(name).setMinWidth(w);
table.getColumn(name).setMaxWidth(w);
name = table.getColumnName(TeamsTableModel.Columns.Repositories.ordinal());
table.getColumn(name).setMinWidth(w);
table.getColumn(name).setMaxWidth(w);
table.setRowSorter(defaultSorter);
table.getRowSorter().toggleSortOrder(TeamsTableModel.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;
editTeam.setEnabled(singleSelection && selected);
delTeam.setEnabled(selected);
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
editTeam(getSelectedTeams().get(0));
}
}
});
filterTextfield = new JTextField();
filterTextfield.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
filterTeams(filterTextfield.getText());
}
});
filterTextfield.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
filterTeams(filterTextfield.getText());
}
});
JPanel teamFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
teamFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
teamFilterPanel.add(filterTextfield, BorderLayout.CENTER);
JPanel teamTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
teamTablePanel.add(teamFilterPanel, BorderLayout.NORTH);
teamTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
JPanel teamControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
teamControls.add(refreshTeams);
teamControls.add(createTeam);
teamControls.add(editTeam);
teamControls.add(delTeam);
setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
header = new HeaderPanel(Translation.get("gb.teams"), "users_16x16.png");
add(header, BorderLayout.NORTH);
add(teamTablePanel, BorderLayout.CENTER);
add(teamControls, BorderLayout.SOUTH);
}
use of javax.swing.event.ListSelectionEvent 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 javax.swing.event.ListSelectionEvent in project jmonkeyengine by jMonkeyEngine.
the class TestChooser method setup.
/**
* Code to create components and action listeners.
*
* @param classes
* what Classes to show in the list box
*/
private void setup(Vector<Class> classes) {
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
getContentPane().setLayout(new BorderLayout());
getContentPane().add(mainPanel, BorderLayout.CENTER);
mainPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
final FilteredJList list = new FilteredJList();
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
DefaultListModel model = new DefaultListModel();
for (Class c : classes) {
model.addElement(c);
}
list.setModel(model);
mainPanel.add(createSearchPanel(list), BorderLayout.NORTH);
mainPanel.add(new JScrollPane(list), BorderLayout.CENTER);
list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
selectedClass = list.getSelectedValues();
}
});
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && selectedClass != null) {
startApp(selectedClass);
}
}
});
list.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
startApp(selectedClass);
} else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
dispose();
}
}
});
final JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
mainPanel.add(buttonPanel, BorderLayout.PAGE_END);
final JButton okButton = new JButton("Ok");
okButton.setMnemonic('O');
buttonPanel.add(okButton);
getRootPane().setDefaultButton(okButton);
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
startApp(selectedClass);
}
});
final JButton cancelButton = new JButton("Cancel");
cancelButton.setMnemonic('C');
buttonPanel.add(cancelButton);
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
pack();
center();
}
use of javax.swing.event.ListSelectionEvent in project libgdx by libgdx.
the class EffectPanel method initializeComponents.
private void initializeComponents() {
setLayout(new GridBagLayout());
{
JScrollPane scroll = new JScrollPane();
add(scroll, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 6), 0, 0));
{
emitterTable = new JTable() {
public Class getColumnClass(int column) {
return column == 1 ? Boolean.class : super.getColumnClass(column);
}
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension dim = super.getPreferredScrollableViewportSize();
dim.height = getPreferredSize().height;
return dim;
}
};
emitterTable.getTableHeader().setReorderingAllowed(false);
emitterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
scroll.setViewportView(emitterTable);
emitterTableModel = new DefaultTableModel(new String[0][0], new String[] { "Emitter", "" });
emitterTable.setModel(emitterTableModel);
emitterTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent event) {
if (event.getValueIsAdjusting())
return;
emitterSelected();
}
});
emitterTableModel.addTableModelListener(new TableModelListener() {
public void tableChanged(TableModelEvent event) {
if (event.getColumn() != 1)
return;
emitterChecked(event.getFirstRow(), (Boolean) emitterTable.getValueAt(event.getFirstRow(), 1));
}
});
}
}
{
JPanel sideButtons = new JPanel(new GridBagLayout());
add(sideButtons, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
{
controllerTypeCombo = new JComboBox();
controllerTypeCombo.setModel(new DefaultComboBoxModel(ControllerType.values()));
sideButtons.add(controllerTypeCombo, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
}
{
JButton newButton = new JButton("New");
sideButtons.add(newButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
newButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
ControllerType item = (ControllerType) controllerTypeCombo.getSelectedItem();
createDefaultEmitter(item, true, true);
}
});
}
{
JButton deleteButton = new JButton("Delete");
sideButtons.add(deleteButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
deleteEmitter();
}
});
}
{
JButton cloneButton = new JButton("Clone");
sideButtons.add(cloneButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
cloneButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
cloneEmitter();
}
});
}
{
sideButtons.add(new JSeparator(JSeparator.HORIZONTAL), new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
}
{
JButton saveButton = new JButton("Save");
sideButtons.add(saveButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
saveEffect();
}
});
}
{
JButton openButton = new JButton("Open");
sideButtons.add(openButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
openEffect();
}
});
}
{
JButton importButton = new JButton("Import");
sideButtons.add(importButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
importButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
importEffect();
}
});
}
/*
{
JButton importButton = new JButton("Export");
sideButtons.add(importButton, new GridBagConstraints(0, -1, 1, 1, 0, 0, GridBagConstraints.CENTER,
GridBagConstraints.HORIZONTAL, new Insets(0, 0, 6, 0), 0, 0));
importButton.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent event) {
exportEffect();
}
});
}
*/
}
}
use of javax.swing.event.ListSelectionEvent in project gradle by gradle.
the class FavoriteTasksTab method createListPanel.
private Component createListPanel() {
model = new DefaultListModel();
list = new JList(model);
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
executeSelectedTasks();
} else if (e.getButton() == MouseEvent.BUTTON3) {
handleRightClick(e);
}
}
});
list.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
enableThingsAppropriately();
}
}
});
//hook 'enter' so it runs the selected tasks.
list.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
executeSelectedTasks();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
return new JScrollPane(list);
}
Aggregations