use of java.awt.event.ActionListener in project gitblit by gitblit.
the class SettingsPanel method initialize.
private void initialize() {
JButton refreshSettings = new JButton(Translation.get("gb.refresh"));
refreshSettings.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshSettings();
}
});
final JButton editSetting = new JButton(Translation.get("gb.edit"));
editSetting.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int viewRow = table.getSelectedRow();
int modelRow = table.convertRowIndexToModel(viewRow);
String key = tableModel.keys.get(modelRow);
SettingModel setting = tableModel.settings.get(key);
editSetting(setting);
}
});
NameRenderer nameRenderer = new NameRenderer();
final SettingPanel settingPanel = new SettingPanel();
tableModel = new SettingsTableModel();
defaultSorter = new TableRowSorter<SettingsTableModel>(tableModel);
table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
table.setDefaultRenderer(SettingModel.class, new SettingCellRenderer());
String name = table.getColumnName(UsersTableModel.Columns.Name.ordinal());
table.getColumn(name).setCellRenderer(nameRenderer);
table.setRowSorter(defaultSorter);
table.getRowSorter().toggleSortOrder(SettingsTableModel.Columns.Name.ordinal());
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
boolean singleSelection = table.getSelectedRows().length == 1;
editSetting.setEnabled(singleSelection);
if (singleSelection) {
int viewRow = table.getSelectedRow();
int modelRow = table.convertRowIndexToModel(viewRow);
SettingModel setting = tableModel.get(modelRow);
settingPanel.setSetting(setting);
} else {
settingPanel.clear();
}
}
});
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int viewRow = table.getSelectedRow();
int modelRow = table.convertRowIndexToModel(viewRow);
SettingModel setting = tableModel.get(modelRow);
editSetting(setting);
}
}
});
filterTextfield = new JTextField();
filterTextfield.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
filterSettings(filterTextfield.getText());
}
});
filterTextfield.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
filterSettings(filterTextfield.getText());
}
});
JPanel settingFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
settingFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
settingFilterPanel.add(filterTextfield, BorderLayout.CENTER);
JPanel settingsTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
settingsTablePanel.add(settingFilterPanel, BorderLayout.NORTH);
settingsTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
settingsTablePanel.add(settingPanel, BorderLayout.SOUTH);
JPanel settingsControls = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 0));
settingsControls.add(refreshSettings);
settingsControls.add(editSetting);
setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
header = new HeaderPanel(Translation.get("gb.settings"), "settings_16x16.png");
add(header, BorderLayout.NORTH);
add(settingsTablePanel, BorderLayout.CENTER);
add(settingsControls, BorderLayout.SOUTH);
}
use of java.awt.event.ActionListener in project gitblit by gitblit.
the class StatusPanel method initialize.
private void initialize() {
JButton refreshStatus = new JButton(Translation.get("gb.refresh"));
refreshStatus.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshStatus();
}
});
version = new JLabel();
releaseDate = new JLabel();
bootDate = new JLabel();
url = new JLabel();
servletContainer = new JLabel();
heapMaximum = new JLabel();
heapAllocated = new JLabel();
heapUsed = new JLabel();
JPanel fieldsPanel = new JPanel(new GridLayout(0, 1, 0, Utils.MARGIN)) {
private static final long serialVersionUID = 1L;
@Override
public Insets getInsets() {
return Utils.INSETS;
}
};
fieldsPanel.add(createFieldPanel("gb.version", version));
fieldsPanel.add(createFieldPanel("gb.releaseDate", releaseDate));
fieldsPanel.add(createFieldPanel("gb.bootDate", bootDate));
fieldsPanel.add(createFieldPanel("gb.url", url));
fieldsPanel.add(createFieldPanel("gb.servletContainer", servletContainer));
fieldsPanel.add(createFieldPanel("gb.heapUsed", heapUsed));
fieldsPanel.add(createFieldPanel("gb.heapAllocated", heapAllocated));
fieldsPanel.add(createFieldPanel("gb.heapMaximum", heapMaximum));
tableModel = new PropertiesTableModel();
JTable propertiesTable = Utils.newTable(tableModel, Utils.DATE_FORMAT);
String name = propertiesTable.getColumnName(PropertiesTableModel.Columns.Name.ordinal());
NameRenderer nameRenderer = new NameRenderer();
propertiesTable.getColumn(name).setCellRenderer(nameRenderer);
JPanel centerPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
centerPanel.add(fieldsPanel, BorderLayout.NORTH);
centerPanel.add(new JScrollPane(propertiesTable), BorderLayout.CENTER);
JPanel controls = new JPanel(new FlowLayout(FlowLayout.CENTER, Utils.MARGIN, 0));
controls.add(refreshStatus);
header = new HeaderPanel(Translation.get("gb.status"), "health_16x16.png");
setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
add(header, BorderLayout.NORTH);
add(centerPanel, BorderLayout.CENTER);
add(controls, BorderLayout.SOUTH);
}
use of java.awt.event.ActionListener in project gephi by gephi.
the class GraphFileExporterUI method action.
@Override
public void action() {
final String LAST_PATH = "GraphFileExporterUI_Last_Path";
final String LAST_PATH_DEFAULT = "GraphFileExporterUI_Last_Path_Default";
final ExportControllerUI exportController = Lookup.getDefault().lookup(ExportControllerUI.class);
if (exportController == null) {
return;
}
//Get last directory
String lastPathDefault = NbPreferences.forModule(GraphFileExporterUI.class).get(LAST_PATH_DEFAULT, null);
String lastPath = NbPreferences.forModule(GraphFileExporterUI.class).get(LAST_PATH, lastPathDefault);
//Options panel
FlowLayout layout = new FlowLayout(FlowLayout.RIGHT);
JPanel optionsPanel = new JPanel(layout);
final JButton optionsButton = new JButton(NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_optionsButton_name"));
optionsPanel.add(optionsButton);
optionsButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ExporterUI exporterUI = exportController.getExportController().getUI(selectedExporter);
if (exporterUI != null) {
JPanel panel = exporterUI.getPanel();
exporterUI.setup(selectedExporter);
DialogDescriptor dd = new DialogDescriptor(panel, NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_optionsDialog_title", selectedBuilder.getName()));
TopDialog topDialog = new TopDialog(dialog, dd.getTitle(), dd.isModal(), dd, dd.getClosingOptions(), dd.getButtonListener());
topDialog.setVisible(true);
Object result = (dd.getValue() != null) ? dd.getValue() : NotifyDescriptor.CLOSED_OPTION;
// Object result = DialogDisplayer.getDefault().notify(dd);
exporterUI.unsetup(result == NotifyDescriptor.OK_OPTION);
}
}
});
//Graph Settings Panel
final JPanel southPanel = new JPanel(new BorderLayout());
southPanel.add(optionsPanel, BorderLayout.NORTH);
GraphFileExporterUIPanel graphSettings = new GraphFileExporterUIPanel();
graphSettings.setVisibleOnlyGraph(visibleOnlyGraph);
southPanel.add(graphSettings, BorderLayout.CENTER);
//Optionable file chooser
final JFileChooser chooser = new JFileChooser(lastPath) {
@Override
protected JDialog createDialog(Component parent) throws HeadlessException {
dialog = super.createDialog(parent);
dialog.setSize(640, 480);
dialog.setResizable(true);
Component c = dialog.getContentPane().getComponent(0);
if (c != null && c instanceof JComponent) {
Insets insets = ((JComponent) c).getInsets();
southPanel.setBorder(BorderFactory.createEmptyBorder(insets.top, insets.left, insets.bottom, insets.right));
}
dialog.getContentPane().add(southPanel, BorderLayout.SOUTH);
return dialog;
}
@Override
public void approveSelection() {
if (canExport(this)) {
super.approveSelection();
}
}
};
chooser.setDialogTitle(NbBundle.getMessage(GraphFileExporterUI.class, "GraphFileExporterUI_filechooser_title"));
chooser.addPropertyChangeListener(JFileChooser.FILE_FILTER_CHANGED_PROPERTY, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
DialogFileFilter fileFilter = (DialogFileFilter) evt.getNewValue();
//Options panel enabling
selectedBuilder = getExporter(fileFilter);
if (selectedBuilder != null) {
selectedExporter = selectedBuilder.buildExporter();
}
if (selectedBuilder != null && exportController.getExportController().getUI(selectedExporter) != null) {
optionsButton.setEnabled(true);
} else {
optionsButton.setEnabled(false);
}
//Selected file extension change
if (selectedFile != null && fileFilter != null) {
String fileName = selectedFile.getName();
String directoryPath = chooser.getCurrentDirectory().getAbsolutePath();
if (fileName.lastIndexOf(".") != -1) {
fileName = fileName.substring(0, fileName.lastIndexOf("."));
fileName = fileName.concat(fileFilter.getExtensions().get(0));
selectedFile = new File(directoryPath, fileName);
chooser.setSelectedFile(selectedFile);
}
}
}
});
chooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getNewValue() != null) {
selectedFile = (File) evt.getNewValue();
}
}
});
//File filters
DialogFileFilter defaultFilter = null;
for (GraphFileExporterBuilder graphFileExporter : Lookup.getDefault().lookupAll(GraphFileExporterBuilder.class)) {
for (FileType fileType : graphFileExporter.getFileTypes()) {
DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
dialogFileFilter.addExtensions(fileType.getExtensions());
if (defaultFilter == null) {
defaultFilter = dialogFileFilter;
}
chooser.addChoosableFileFilter(dialogFileFilter);
}
}
chooser.setAcceptAllFileFilterUsed(false);
chooser.setFileFilter(defaultFilter);
selectedFile = new File(chooser.getCurrentDirectory(), "Untitled" + defaultFilter.getExtensions().get(0));
chooser.setSelectedFile(selectedFile);
//Show
int returnFile = chooser.showSaveDialog(null);
if (returnFile == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
file = FileUtil.normalizeFile(file);
FileObject fileObject = FileUtil.toFileObject(file);
//Save last path
NbPreferences.forModule(GraphFileExporterUI.class).put(LAST_PATH, file.getAbsolutePath());
//Save variable
visibleOnlyGraph = graphSettings.isVisibleOnlyGraph();
//Do
selectedExporter.setExportVisible(visibleOnlyGraph);
exportController.exportFile(fileObject, selectedExporter);
}
dialog = null;
}
use of java.awt.event.ActionListener in project gephi by gephi.
the class TopDialog method updateOptions.
public void updateOptions() {
Set<Object> addedOptions = new HashSet<>(5);
Object[] options = nd.getOptions();
if (options == null) {
switch(nd.getOptionType()) {
case NotifyDescriptor.DEFAULT_OPTION:
case NotifyDescriptor.OK_CANCEL_OPTION:
options = new Object[] { NotifyDescriptor.OK_OPTION, NotifyDescriptor.CANCEL_OPTION };
break;
case NotifyDescriptor.YES_NO_OPTION:
options = new Object[] { NotifyDescriptor.YES_OPTION, NotifyDescriptor.NO_OPTION };
break;
case NotifyDescriptor.YES_NO_CANCEL_OPTION:
options = new Object[] { NotifyDescriptor.YES_OPTION, NotifyDescriptor.NO_OPTION, NotifyDescriptor.CANCEL_OPTION };
break;
default:
throw new IllegalArgumentException();
}
}
//System.err.println("prep: " + Arrays.asList(options) + " " + Arrays.asList(closingOptions) + " " + buttonListener);
buttonPanel.removeAll();
JRootPane rp = getRootPane();
for (int i = 0; i < options.length; i++) {
addedOptions.add(options[i]);
buttonPanel.add(option2Button(options[i], nd, makeListener(options[i]), rp));
}
options = nd.getAdditionalOptions();
if (options != null) {
for (int i = 0; i < options.length; i++) {
addedOptions.add(options[i]);
buttonPanel.add(option2Button(options[i], nd, makeListener(options[i]), rp));
}
}
if (closingOptions != null) {
for (int i = 0; i < closingOptions.length; i++) {
if (addedOptions.add(closingOptions[i])) {
ActionListener l = makeListener(closingOptions[i]);
attachActionListener(closingOptions[i], l);
}
}
}
}
use of java.awt.event.ActionListener 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);
}
});
}
Aggregations