diff --git a/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java b/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java index d01c518..90f3ca1 100644 --- a/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java +++ b/AlgebraicDataflowArchitectureModel/src/application/actions/OpenAction.java @@ -1,62 +1,63 @@ package application.actions; -import java.awt.event.ActionEvent; -import java.io.File; - -import javax.swing.JFileChooser; -import javax.swing.filechooser.FileFilter; -import javax.swing.filechooser.FileNameExtensionFilter; - import application.ApplicationWindow; import application.editor.Editor; +import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileNameExtensionFilter; +import java.awt.event.ActionEvent; +import java.io.File; + public class OpenAction extends AbstractSystemAction { - /** - * - */ - private static final long serialVersionUID = -8290761032629599683L; - - private String lastDir = null; - - public OpenAction(ApplicationWindow frame) { - super("Open...", frame); - } - @Override - public void actionPerformed(ActionEvent e) { - Editor editor = frame.getEditor(); - if (editor != null) { - String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); + private static final long serialVersionUID = -8290761032629599683L; - JFileChooser fc = new JFileChooser(wd); + private String lastDir = null; - FileFilter model = new FileNameExtensionFilter("model","model"); - FileFilter dtram = new FileNameExtensionFilter("dtram", "dtram"); - - // Adds file filter for supported file format - FileFilter defaultFilter = new FileFilter() { + public OpenAction(ApplicationWindow frame) { + super("Open...", frame); + } - public boolean accept(File file) { - String lcase = file.getName().toLowerCase(); - return lcase.endsWith(".model"); - } + @Override + public void actionPerformed(ActionEvent e) { + Editor editor = frame.getEditor(); + if (editor == null) { + return; + } + String wd = (lastDir != null) ? lastDir : System.getProperty("user.dir"); - @Override - public String getDescription() { - return null; - } - }; - - fc.addChoosableFileFilter(defaultFilter); - fc.addChoosableFileFilter(model); - fc.addChoosableFileFilter(dtram); - int rc = fc.showDialog(null, "Open Model File"); - if (rc == JFileChooser.APPROVE_OPTION) { - lastDir = fc.getSelectedFile().getParent(); - editor.open(fc.getSelectedFile()); - frame.setTitle(frame.title + " - " + fc.getSelectedFile().getAbsolutePath()); - } - } - } + JFileChooser fc = buildFileChooser(wd); + int option = fc.showDialog(null, "Open Model File"); + if (option == JFileChooser.APPROVE_OPTION) { + lastDir = fc.getSelectedFile().getParent(); + editor.open(fc.getSelectedFile()); + frame.setTitle(ApplicationWindow.title + " - " + fc.getSelectedFile().getAbsolutePath()); + } + } + private static JFileChooser buildFileChooser(String wd) { + JFileChooser fc = new JFileChooser(wd); + + FileFilter model = new FileNameExtensionFilter("model", "model"); + FileFilter dtram = new FileNameExtensionFilter("dtram", "dtram"); + + // Adds file filter for supported file format + FileFilter defaultFilter = new FileFilter() { + public boolean accept(File file) { + String lowerCase = file.getName().toLowerCase(); + return lowerCase.endsWith(".model"); + } + + @Override + public String getDescription() { + return null; + } + }; + + fc.addChoosableFileFilter(defaultFilter); + fc.addChoosableFileFilter(model); + fc.addChoosableFileFilter(dtram); + return fc; + } }