use of java.awt.event.ActionListener in project gephi by gephi.
the class VectorialFileExporterUI method action.
@Override
public void action() {
final String LAST_PATH = "VectorialFileExporterUI_Last_Path";
final String LAST_PATH_DEFAULT = "VectorialFileExporterUI_Last_Path_Default";
final ExportControllerUI exportController = Lookup.getDefault().lookup(ExportControllerUI.class);
if (exportController == null) {
return;
}
//Get last directory
String lastPathDefault = NbPreferences.forModule(VectorialFileExporterUI.class).get(LAST_PATH_DEFAULT, null);
String lastPath = NbPreferences.forModule(VectorialFileExporterUI.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(VectorialFileExporterUI.class, "VectorialFileExporterUI_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(VectorialFileExporterUI.class, "VectorialFileExporterUI_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);
//Optionable file chooser
final JFileChooser chooser = new JFileChooser(lastPath) {
@Override
protected JDialog createDialog(Component parent) throws HeadlessException {
dialog = super.createDialog(parent);
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(VectorialFileExporterUI.class, "VectorialFileExporterUI_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 (selectedExporter != 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 (VectorFileExporterBuilder vectorFileExporter : Lookup.getDefault().lookupAll(VectorFileExporterBuilder.class)) {
for (FileType fileType : vectorFileExporter.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(VectorialFileExporterUI.class).put(LAST_PATH, file.getAbsolutePath());
//Do
exportController.exportFile(fileObject, selectedExporter);
}
dialog = null;
}
use of java.awt.event.ActionListener in project gephi by gephi.
the class WelcomeTopComponent method initAction.
private void initAction() {
openAction = new AbstractAction("", ImageUtilities.loadImageIcon("org/gephi/desktop/welcome/resources/gephifile20.png", false)) {
@Override
public void actionPerformed(ActionEvent e) {
JXHyperlink link = (JXHyperlink) e.getSource();
File file = (File) link.getClientProperty(LINK_PATH);
FileObject fileObject = FileUtil.toFileObject(file);
if (fileObject.hasExt(GEPHI_EXTENSION)) {
ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
try {
pc.openProject(file);
} catch (Exception ex) {
ex.printStackTrace();
NotifyDescriptor.Message msg = new NotifyDescriptor.Message(NbBundle.getMessage(WelcomeTopComponent.class, "WelcomeTopComponent.openGephiError"), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notify(msg);
}
} else {
ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
if (importController.getImportController().isFileSupported(FileUtil.toFile(fileObject))) {
importController.importFile(fileObject);
}
}
closeDialog();
}
};
newProjectLink.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
pc.newProject();
closeDialog();
}
});
openFileLink.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ProjectControllerUI pc = Lookup.getDefault().lookup(ProjectControllerUI.class);
pc.openFile();
closeDialog();
}
});
}
use of java.awt.event.ActionListener in project gephi by gephi.
the class DataTableTopComponent method preparePluginGeneralActionsButton.
/**
* Prepare a button for the popup panel for plugin general actions.
*
* @param m PluginGeneralActionsManipulator for the button
* @return JCommandButton for the manipulator
*/
private JCommandButton preparePluginGeneralActionsButton(final PluginGeneralActionsManipulator m) {
//Convert icon to Image if it is not null
JCommandButton button = new JCommandButton(m.getName(), m.getIcon() != null ? ImageWrapperResizableIcon.getIcon(ImageUtilities.icon2Image(m.getIcon()), new Dimension(16, 16)) : null);
button.setDisplayState(CommandButtonDisplayState.BIG);
button.setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY);
if (m.getDescription() != null && !m.getDescription().isEmpty()) {
button.setPopupRichTooltip(new RichTooltip(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.RichToolTip.title.text"), m.getDescription()));
}
if (m.canExecute()) {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
DataLaboratoryHelper.getDefault().executeManipulator(m);
}
});
} else {
button.setEnabled(false);
}
return button;
}
use of java.awt.event.ActionListener in project gephi by gephi.
the class DataTableTopComponent method prepareAddColumnButton.
/**
* Create the special Add new column button.
*/
private void prepareAddColumnButton() {
JCommandButtonStrip strip = new JCommandButtonStrip(JCommandButtonStrip.StripOrientation.HORIZONTAL);
strip.setDisplayState(CommandButtonDisplayState.BIG);
JCommandButton button = new JCommandButton(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.addColumnButton.text"), ImageWrapperResizableIcon.getIcon(ImageUtilities.loadImage("org/gephi/desktop/datalab/resources/table-insert-column.png", true), new Dimension(16, 16)));
button.setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_ONLY);
button.setDisplayState(CommandButtonDisplayState.BIG);
if (isShowingNodesTable()) {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showAddColumnUI(AddColumnUI.Mode.NODES_TABLE);
}
});
} else {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showAddColumnUI(AddColumnUI.Mode.EDGES_TABLE);
}
});
}
strip.add(button);
columnManipulatorsPanel.add(strip);
}
use of java.awt.event.ActionListener in project gephi by gephi.
the class DataTableTopComponent method initEvents.
private void initEvents() {
//Workspace Listener
pc.addWorkspaceListener(new WorkspaceListener() {
@Override
public void initialize(Workspace workspace) {
//Prepare DataTablesEvent listener
Lookup.getDefault().lookup(DataTablesController.class).setDataTablesEventListener(DataTableTopComponent.this);
if (workspace.getLookup().lookup(DataTablesModel.class) == null) {
workspace.add(new DataTablesModel(workspace));
}
}
@Override
public void select(Workspace workspace) {
activateWorkspace(workspace);
setAutoRefreshEnabled(true);
}
@Override
public void unselect(Workspace workspace) {
deactivateAll();
setAutoRefreshEnabled(false);
}
@Override
public void close(Workspace workspace) {
}
@Override
public void disable() {
clearAll();
//No more workspaces active, disable the DataTablesEvent listener
Lookup.getDefault().lookup(DataTablesController.class).setDataTablesEventListener(null);
setAutoRefreshEnabled(false);
}
});
if (pc.getCurrentWorkspace() != null) {
activateWorkspace(pc.getCurrentWorkspace());
setAutoRefreshEnabled(true);
}
observersTimer = new java.util.Timer("DataLaboratoryGraphObservers");
observersTimer.schedule(new TimerTask() {
@Override
public void run() {
if (!autoRefreshEnabled) {
return;
}
if (dataTablesObservers != null) {
if (dataTablesObservers.hasChanges()) {
//Execute refresh
graphChanged();
}
}
}
}, 0, //Check graph and tables for changes every 100 ms
AUTO_REFRESH_RATE_MILLISECONDS);
//Filter
if (dynamicFiltering) {
filterTextField.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent e) {
refreshAppliedFilter();
}
@Override
public void removeUpdate(DocumentEvent e) {
refreshAppliedFilter();
}
@Override
public void changedUpdate(DocumentEvent e) {
}
});
} else {
filterTextField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshAppliedFilter();
}
});
}
columnComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
refreshAppliedFilter();
}
});
initKeyEventContextMenuActionMappings();
}
Aggregations