use of java.awt.event.ActionEvent 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.ActionEvent 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.ActionEvent 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.ActionEvent in project gephi by gephi.
the class WelcomeTopComponent method loadSamples.
private void loadSamples() {
net.miginfocom.swing.MigLayout migLayout1 = new net.miginfocom.swing.MigLayout();
migLayout1.setColumnConstraints("[pref]");
samplesPanel.setLayout(migLayout1);
String[] samplePath = new String[3];
samplePath[0] = "/org/gephi/desktop/welcome/samples/Les Miserables.gexf";
samplePath[1] = "/org/gephi/desktop/welcome/samples/Java.gexf";
samplePath[2] = "/org/gephi/desktop/welcome/samples/Power Grid.gml";
String[] sampleTooltip = new String[3];
sampleTooltip[0] = "Coappearance Network of Characters in 'Les Miserables' (D. E. Knuth)";
sampleTooltip[1] = "Java Programming Language Dependency graph (V. Batagelj)";
sampleTooltip[2] = "Topology of the Western States Power Grid of the US (D. Watts & S. Strogatz)";
try {
for (int i = 0; i < samplePath.length; i++) {
final String s = samplePath[i];
String tooltip = sampleTooltip[i];
String fileName = s.substring(s.lastIndexOf('/') + 1, s.length());
final String importer = fileName.substring(fileName.lastIndexOf('.'), fileName.length());
JXHyperlink fileLink = new JXHyperlink(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
final InputStream stream = WelcomeTopComponent.class.getResourceAsStream(s);
ImportControllerUI importController = Lookup.getDefault().lookup(ImportControllerUI.class);
importController.importStream(stream, importer);
closeDialog();
}
});
fileLink.setText(fileName);
fileLink.setToolTipText(tooltip);
fileLink.putClientProperty(LINK_PATH, importer);
samplesPanel.add(fileLink, "wrap");
}
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
}
use of java.awt.event.ActionEvent 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;
}
Aggregations