use of org.openide.DialogDescriptor in project gephi by gephi.
the class GraphFileExporterUI method action.
public void action(final GraphFileExporterBuilder[] exporterBuilders) {
final String LAST_PATH = "GraphFileExporterUI_Last_Path";
final String LAST_PATH_DEFAULT = "GraphFileExporterUI_Last_Path_Default";
final String LAST_FILE_FILTER = "GraphFileExporterUI_Last_File_Filter";
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);
String lastFileFilterString = NbPreferences.forModule(GraphFileExporterUI.class).get(LAST_FILE_FILTER, null);
// 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);
File lastPathDir = null;
if (lastPath != null) {
lastPathDir = new File(lastPath).getParentFile();
while (lastPathDir != null && !lastPathDir.exists()) {
lastPathDir = lastPathDir.getParentFile();
}
}
// Optionable file chooser
final JFileChooser chooser = new JFileChooser(lastPathDir) {
@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();
// Save last file filter
NbPreferences.forModule(GraphFileExporterUI.class).put(LAST_FILE_FILTER, fileFilter.getExtensions().toString());
// Options panel enabling
selectedBuilder = getExporter(exporterBuilders, 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 defaultFileFilter = null;
DialogFileFilter lastFileFilter = null;
for (GraphFileExporterBuilder graphFileExporter : exporterBuilders) {
for (FileType fileType : graphFileExporter.getFileTypes()) {
DialogFileFilter dialogFileFilter = new DialogFileFilter(fileType.getName());
dialogFileFilter.addExtensions(fileType.getExtensions());
if (defaultFileFilter == null) {
defaultFileFilter = dialogFileFilter;
}
if (lastFileFilterString != null) {
if (dialogFileFilter.getExtensions().toString().equals(lastFileFilterString)) {
lastFileFilter = dialogFileFilter;
}
}
chooser.addChoosableFileFilter(dialogFileFilter);
}
}
chooser.setAcceptAllFileFilterUsed(false);
if (lastFileFilter != null) {
defaultFileFilter = lastFileFilter;
}
chooser.setFileFilter(defaultFileFilter);
selectedFile = new File(chooser.getCurrentDirectory(), "Untitled" + defaultFileFilter.getExtensions().get(0));
if (lastPathDir != null && lastPathDir.exists() && lastPathDir.isDirectory()) {
selectedFile = new File(lastPath);
}
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 org.openide.DialogDescriptor in project gephi by gephi.
the class ReportPanel method showDialog.
public void showDialog() {
Object[] options = new Object[2];
options[0] = NbBundle.getMessage(ReportPanel.class, "ReportPanel.dialog.sendButton");
options[1] = DialogDescriptor.CANCEL_OPTION;
String title = NbBundle.getMessage(ReportPanel.class, "ReportPanel.dialog.title");
DialogDescriptor dd = new DialogDescriptor(this, title, true, options, options[0], DialogDescriptor.DEFAULT_ALIGN, null, null);
if (DialogDisplayer.getDefault().notify(dd) == options[0]) {
// Set
report.setUserDescription(problemArea.getText());
report.setUserEmail(emailTextField.getText());
reportController.sendReport(report);
}
}
use of org.openide.DialogDescriptor in project gephi by gephi.
the class DataTableTopComponent method availableColumnsButtonActionPerformed.
// GEN-LAST:event_configurationButtonActionPerformed
private void availableColumnsButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_availableColumnsButtonActionPerformed
Table table;
AvailableColumnsModel availableColumnsModel;
if (isShowingNodesTable()) {
table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getNodeTable();
} else {
table = Lookup.getDefault().lookup(GraphController.class).getGraphModel().getEdgeTable();
}
availableColumnsModel = getTableAvailableColumnsModel(table);
DialogDescriptor dd = new DialogDescriptor(new AvailableColumnsPanel(table, availableColumnsModel).getValidationPanel(), NbBundle.getMessage(DataTableTopComponent.class, "AvailableColumnsPanel.title"));
dd.setOptions(new Object[] { DialogDescriptor.OK_OPTION });
DialogDisplayer.getDefault().notify(dd);
refreshAllOnce();
}
use of org.openide.DialogDescriptor 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 String LAST_FILE_FILTER = "VectorialFileExporterUI_Last_File_Filter";
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);
String lastFileFilterString = NbPreferences.forModule(VectorialFileExporterUI.class).get(LAST_FILE_FILTER, null);
// 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();
// Save file filter
NbPreferences.forModule(VectorialFileExporterUI.class).put(LAST_FILE_FILTER, fileFilter.getExtensions().toString());
// 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 defaultFileFilter = null;
DialogFileFilter lastFileFilter = 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 (defaultFileFilter == null) {
defaultFileFilter = dialogFileFilter;
}
if (lastFileFilterString != null) {
if (dialogFileFilter.getExtensions().toString().equals(lastFileFilterString)) {
lastFileFilter = dialogFileFilter;
}
}
chooser.addChoosableFileFilter(dialogFileFilter);
}
}
chooser.setAcceptAllFileFilterUsed(false);
if (lastFileFilter != null) {
defaultFileFilter = lastFileFilter;
}
chooser.setFileFilter(defaultFileFilter);
selectedFile = new File(chooser.getCurrentDirectory(), "Untitled" + defaultFileFilter.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 org.openide.DialogDescriptor in project netbeans-mmd-plugin by raydac.
the class MMDCfgPanel method buttonFontActionPerformed.
private void buttonFontActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_buttonFontActionPerformed
final PropertyEditor editor = PropertyEditorManager.findEditor(Font.class);
if (editor == null) {
LOGGER.error("Can't find any font editor");
NbUtils.msgError(null, "Can't find editor! Unexpected state! Contact developer!");
return;
}
editor.setValue(this.config.getFont());
final DialogDescriptor descriptor = new DialogDescriptor(editor.getCustomEditor(), "Mind map font");
DialogDisplayer.getDefault().createDialog(descriptor).setVisible(true);
if (descriptor.getValue() == DialogDescriptor.OK_OPTION) {
this.config.setFont((Font) editor.getValue());
updateFontButton(this.config);
if (changeNotificationAllowed) {
this.controller.changed();
}
}
}
Aggregations