use of org.openide.DialogDescriptor 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 org.openide.DialogDescriptor in project gephi by gephi.
the class DataTableTopComponent method showMergeColumnsUI.
private void showMergeColumnsUI(MergeColumnsUI.Mode mode) {
JButton okButton = new JButton(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.dialogs.okButton.text"));
MergeColumnsUI mergeColumnsUI = new MergeColumnsUI();
mergeColumnsUI.setup(mode);
mergeColumnsUI.setOkButton(okButton);
DialogDescriptor dd = new DialogDescriptor(MergeColumnsUI.createValidationPanel(mergeColumnsUI), mergeColumnsUI.getDisplayName());
dd.setOptions(new Object[] { okButton, DialogDescriptor.CANCEL_OPTION });
if (DialogDisplayer.getDefault().notify(dd).equals(okButton)) {
mergeColumnsUI.execute();
}
}
use of org.openide.DialogDescriptor in project gephi by gephi.
the class DataTableTopComponent method showAddColumnUI.
private void showAddColumnUI(AddColumnUI.Mode mode) {
JButton okButton = new JButton(NbBundle.getMessage(DataTableTopComponent.class, "DataTableTopComponent.dialogs.okButton.text"));
AddColumnUI addColumnUI = new AddColumnUI();
addColumnUI.setup(mode);
addColumnUI.setOkButton(okButton);
DialogDescriptor dd = new DialogDescriptor(AddColumnUI.createValidationPanel(addColumnUI), addColumnUI.getDisplayName());
dd.setOptions(new Object[] { okButton, DialogDescriptor.CANCEL_OPTION });
if (DialogDisplayer.getDefault().notify(dd).equals(okButton)) {
addColumnUI.execute();
}
addColumnUI.unSetup();
}
use of org.openide.DialogDescriptor in project gephi by gephi.
the class DataTableTopComponent method showCSVExportUI.
private void showCSVExportUI(Table table, boolean edgesTable, String fileName) {
CSVExportUI csvUI = new CSVExportUI(table, edgesTable);
DialogDescriptor dd = new DialogDescriptor(csvUI, csvUI.getDisplayName());
if (DialogDisplayer.getDefault().notify(dd).equals(DialogDescriptor.OK_OPTION)) {
DataTableTopComponent.exportTableAsCSV(this, this.visibleOnly, table, edgesTable, csvUI.getSelectedSeparator(), csvUI.getSelectedCharset(), csvUI.getSelectedColumnsIndexes(), fileName);
}
csvUI.unSetup();
}
use of org.openide.DialogDescriptor in project gephi by gephi.
the class DesktopGeneratorController method generate.
@Override
public void generate(final Generator generator) {
String title = generator.getName();
GeneratorUI ui = generator.getUI();
if (ui != null) {
ui.setup(generator);
JPanel panel = ui.getPanel();
final DialogDescriptor dd = new DialogDescriptor(panel, title);
if (panel instanceof ValidationPanel) {
ValidationPanel vp = (ValidationPanel) panel;
vp.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
dd.setValid(!((ValidationPanel) e.getSource()).isProblem());
}
});
}
Object result = DialogDisplayer.getDefault().notify(dd);
if (result != NotifyDescriptor.OK_OPTION) {
return;
}
ui.unsetup();
}
final Container container = Lookup.getDefault().lookup(Container.Factory.class).newContainer();
container.setSource("" + generator.getName());
container.setReport(new Report());
String taskname = NbBundle.getMessage(DesktopGeneratorController.class, "DesktopGeneratorController.taskname", generator.getName());
// Error handler
LongTaskErrorHandler errorHandler = new LongTaskErrorHandler() {
@Override
public void fatalError(Throwable t) {
Exceptions.printStackTrace(t);
}
};
// Execute
executor.execute(generator, new Runnable() {
@Override
public void run() {
generator.generate(container.getLoader());
finishGenerate(container);
}
}, taskname, errorHandler);
}
Aggregations