use of net.parostroj.timetable.gui.actions.impl.CloseableFileChooser in project grafikon by jub77.
the class MainFrame method ouputTemplatesMenuItemActionPerformed.
private void ouputTemplatesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// output templates list dialog
OutputTemplateListDialog dialog = new OutputTemplateListDialog(this, true);
dialog.setLocationRelativeTo(this);
dialog.registerContext(model.getGuiContext());
OutputSettings settings = model.getOutputSettings();
FileChooserFactory chooserFactory = FileChooserFactory.getInstance();
File outputDirectory = chooserFactory.getLocation(FileChooserFactory.Type.OUTPUT_DIRECTORY);
try (CloseableFileChooser allChooser = chooserFactory.getFileChooser(FileChooserFactory.Type.ALL_FILES)) {
dialog.showDialog(model.getDiagram(), outputDirectory, allChooser, new Settings(settings.getLocale()));
dialog.dispose();
}
}
use of net.parostroj.timetable.gui.actions.impl.CloseableFileChooser in project grafikon by jub77.
the class MainFrame method ouputMenuItemActionPerformed.
private void ouputMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
// dialog with outputs
EditOutputsDialog dialog = EditOutputsDialog.newInstance(this, true);
dialog.setSettings(new Settings(model.getOutputSettings().getLocale()));
GenerateOutputPM pm = new GenerateOutputPM(model.getLanguageLoader().getAvailableLocales(), model.getDiagram().getLocales());
try (CloseableFileChooser chooser = FileChooserFactory.getInstance().getFileChooser(FileChooserFactory.Type.OUTPUT_DIRECTORY)) {
pm.init(model.get(), chooser);
dialog.setPresentationModel(pm);
dialog.setLocationRelativeTo(this);
dialog.registerContext(model.getGuiContext());
dialog.showDialog(model.getDiagram());
dialog.dispose();
pm.writeBack();
}
}
use of net.parostroj.timetable.gui.actions.impl.CloseableFileChooser in project grafikon by jub77.
the class ExportAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent event) {
final Component parent = GuiComponentUtils.getTopLevelComponent(event.getSource());
ExportImportSelectionSource source = ExportImportSelectionSource.fromDiagramToLibrary(model.getDiagram());
exportDialog.setSelectionSource(source);
exportDialog.setLocationRelativeTo(parent);
exportDialog.setVisible(true);
boolean cancelled = exportDialog.isCancelled();
if (!cancelled) {
// saving library
try (CloseableFileChooser gtmlFileChooser = FileChooserFactory.getInstance().getFileChooser(FileChooserFactory.Type.GTML)) {
int retVal = gtmlFileChooser.showSaveDialog(parent);
if (retVal == JFileChooser.APPROVE_OPTION) {
ActionContext c = new ActionContext(parent);
ModelAction action = getSaveModelAction(c, gtmlFileChooser.getSelectedFile(), parent, this.createLibrary(exportDialog.getSelection()));
ActionHandler.getInstance().execute(action);
}
}
}
}
use of net.parostroj.timetable.gui.actions.impl.CloseableFileChooser in project grafikon by jub77.
the class NewOpenAction method open.
private void open(final Component parent, final File preselectedFile) {
// check changes
final int result = ModelUtils.checkModelChangedContinue(model, parent);
if (result == JOptionPane.CANCEL_OPTION) {
return;
}
// save old diagram
ActionContext context = new ActionContext(parent);
if (result == JOptionPane.YES_OPTION) {
ModelAction saveAction = SaveAction.getSaveModelAction(context, model.getOpenedFile(), parent, model);
ActionHandler.getInstance().execute(saveAction);
}
ModelAction openAction = new CombinedModelAction(context) {
private int retVal;
private TrainDiagram diagram;
private String errorMessage;
private Exception errorException;
private File selectedFile;
@Override
protected void eventDispatchActionBefore() {
if (preselectedFile == null) {
try (CloseableFileChooser modelFileChooser = FileChooserFactory.getInstance().getFileChooser(FileChooserFactory.Type.GTM)) {
retVal = modelFileChooser.showOpenDialog(parent);
if (retVal == JFileChooser.APPROVE_OPTION) {
selectedFile = modelFileChooser.getSelectedFile();
}
}
} else {
selectedFile = preselectedFile;
retVal = JFileChooser.APPROVE_OPTION;
}
}
@Override
protected void backgroundAction() {
if (retVal != JFileChooser.APPROVE_OPTION) {
return;
}
setWaitMessage(ResourceLoader.getString("wait.message.loadmodel"));
setWaitDialogVisible(true);
long time = System.currentTimeMillis();
try {
try {
model.setOpenedFile(selectedFile);
log.info("Loading: {}", selectedFile);
LSFile ls = LSFileFactory.getInstance().createForLoad(selectedFile);
diagram = ls.load(selectedFile);
} catch (LSException e) {
log.warn("Error loading model.", e);
if (e.getCause() instanceof FileNotFoundException) {
// remove from last opened
model.removeLastOpenedFile(selectedFile);
// create error message
errorMessage = ResourceLoader.getString("dialog.error.filenotfound");
} else if (e.getCause() instanceof IOException) {
errorMessage = ResourceLoader.getString("dialog.error.loading");
} else {
errorMessage = ResourceLoader.getString("dialog.error.loading");
errorException = e;
}
} catch (Exception e) {
log.warn("Error loading model.", e);
errorMessage = ResourceLoader.getString("dialog.error.loading");
}
} finally {
log.debug("Loaded in {}ms", System.currentTimeMillis() - time);
}
}
@Override
protected void eventDispatchActionAfter() {
try {
if (retVal != JFileChooser.APPROVE_OPTION) {
return;
}
if (diagram != null) {
model.setDiagram(diagram);
} else {
String text = errorMessage + " " + selectedFile.getName();
if (errorException != null) {
text = text + "\n(" + errorException.getMessage() + ")";
}
context.setAttribute("error", text);
model.setDiagram(null);
}
} finally {
setWaitDialogVisible(false);
}
}
};
ActionHandler.getInstance().execute(openAction);
ActionHandler.getInstance().execute(ModelAction.newEdtAction(context, () -> {
// show error
if (context.getAttribute("error") != null) {
GuiComponentUtils.showError((String) context.getAttribute("error"), parent);
}
}));
}
use of net.parostroj.timetable.gui.actions.impl.CloseableFileChooser in project grafikon by jub77.
the class SaveAction method saveAs.
private void saveAs(Component parent) {
if (model.getDiagram() == null) {
GuiComponentUtils.showError(ResourceLoader.getString("dialog.error.nodiagram"), parent);
return;
}
// saving train diagram
try (CloseableFileChooser gtmFileChooser = FileChooserFactory.getInstance().getFileChooser(FileChooserFactory.Type.GTM)) {
if (model.getOpenedFile() != null) {
gtmFileChooser.cancelSelection();
File cDir = gtmFileChooser.getCurrentDirectory();
gtmFileChooser.setSelectedFile(null);
File nFile = new File(cDir, model.getOpenedFile().getName());
gtmFileChooser.setSelectedFile(nFile);
}
int retVal = gtmFileChooser.showSaveDialog(parent);
if (retVal == JFileChooser.APPROVE_OPTION) {
model.setOpenedFile(gtmFileChooser.getSelectedFile());
ActionContext c = new ActionContext(parent);
ModelAction action = getSaveModelAction(c, gtmFileChooser.getSelectedFile(), parent, model);
ActionHandler.getInstance().execute(action);
}
}
}
Aggregations