use of java.awt.event.ActionEvent 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.ActionEvent 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.ActionEvent in project gephi by gephi.
the class ImportDB method getMenuPresenter.
@Override
public JMenuItem getMenuPresenter() {
JMenu menu = new JMenu(NbBundle.getMessage(ImportDB.class, "CTL_ImportDB"));
final ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
if (importController != null) {
for (final DatabaseImporterBuilder dbb : Lookup.getDefault().lookupAll(DatabaseImporterBuilder.class)) {
ImporterUI ui = importController.getImportController().getUI(dbb.buildImporter());
String menuName = dbb.getName();
if (ui != null) {
menuName = ui.getDisplayName();
}
JMenuItem menuItem = new JMenuItem(new AbstractAction(menuName) {
@Override
public void actionPerformed(ActionEvent e) {
importController.importDatabase(dbb.buildImporter());
}
});
menu.add(menuItem);
}
}
return menu;
}
use of java.awt.event.ActionEvent in project gephi by gephi.
the class Export method getMenuPresenter.
@Override
public JMenuItem getMenuPresenter() {
for (final ExporterClassUI ui : Lookup.getDefault().lookupAll(ExporterClassUI.class)) {
String menuName = ui.getName();
JMenuItem menuItem = new JMenuItem(new AbstractAction(menuName) {
@Override
public void actionPerformed(ActionEvent e) {
ui.action();
}
});
menu.add(menuItem);
menuItem.setEnabled(ui.isEnable());
}
return menu;
}
use of java.awt.event.ActionEvent 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;
}
Aggregations