uniformize filechooser in xcos
antoine ELIAS [Tue, 15 Dec 2009 08:57:30 +0000 (09:57 +0100)]
scilab/modules/gui/src/java/org/scilab/modules/gui/utils/SciFileFilter.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/actions/OpenAction.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/graph/XcosDiagram.java
scilab/modules/xcos/src/java/org/scilab/modules/xcos/palette/actions/LoadAsPalAction.java

index 33a18d2..5e5f038 100644 (file)
@@ -50,6 +50,10 @@ public class SciFileFilter extends FileFilter {
                                description = Messages.gettext("All Scilab files") + "(*.sc*)";
                        } else if (fileMask.equals("*.xcos")) {
                                description = Messages.gettext("Xcos files") + "(*.xcos)";
+                       } else if (fileMask.equals("*.cos*")) {
+                               description = Messages.gettext("Scicos files") + "(*.cos*)";
+                       } else if (fileMask.equals("*.*")) {
+                               description = Messages.gettext("All files") +  "(*.*)";
                        } else {
                                description = String.format(Messages.gettext("All %s files"), fileMask);
                        }
index 08f4a9a..ab31895 100644 (file)
@@ -15,6 +15,7 @@ package org.scilab.modules.xcos.actions;
 import java.awt.Toolkit;
 import java.awt.event.KeyEvent;
 
+import javax.swing.JFileChooser;
 import javax.swing.KeyStroke;
 
 import org.scilab.modules.graph.ScilabGraph;
@@ -22,8 +23,10 @@ import org.scilab.modules.graph.actions.DefaultAction;
 import org.scilab.modules.gui.bridge.filechooser.SwingScilabFileChooser;
 import org.scilab.modules.gui.filechooser.FileChooser;
 import org.scilab.modules.gui.filechooser.ScilabFileChooser;
+import org.scilab.modules.gui.filechooser.SimpleFileChooser;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.utils.SciFileFilter;
 import org.scilab.modules.xcos.Xcos;
 import org.scilab.modules.xcos.XcosTab;
 import org.scilab.modules.xcos.graph.XcosDiagram;
@@ -71,28 +74,37 @@ public final class OpenAction extends DefaultAction {
         * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
         */
        public void doAction() {
-               FileChooser fc = ScilabFileChooser.createFileChooser();
+           SwingScilabFileChooser fc = ((SwingScilabFileChooser) ScilabFileChooser.createFileChooser().getAsSimpleFileChooser());
 
                /* Standard files */
-               String[] mask = XcosFileType.getValidFileMask();
-               String[] desc = XcosFileType.getValidFileDescription();
-               ((SwingScilabFileChooser) fc.getAsSimpleFileChooser()).addMask(mask , desc);
-               
-               fc.setMultipleSelection(false);
-               fc.displayAndWait();
+           fc.setTitle(XcosMessages.OPEN);
+           fc.setUiDialogType(JFileChooser.OPEN_DIALOG);
+           fc.setMultipleSelection(false);
+           
 
-               if (fc.getSelection() == null || fc.getSelection().length == 0 || fc.getSelection()[0].equals("")) {
-                       return;
-               }
-               ConfigXcosManager.saveToRecentOpenedFiles(fc.getSelection()[0]);
-               
-               if (getGraph(null) == null) { // Called from palettes
-                       //save to recentopenedfile while opening from palettes is handle in Xcos.xcos(filename)
-                       Xcos.xcos(fc.getSelection()[0]);
-               }
-               else {
-                       ((XcosDiagram) getGraph(null)).openDiagramFromFile(fc.getSelection()[0]);
-               }
-               XcosTab.updateRecentOpenedFilesMenu(((XcosDiagram) getGraph(null)));
+           SciFileFilter xcosFilter = new SciFileFilter("*.xcos", null, 0);
+           SciFileFilter cosFilter = new SciFileFilter("*.cos*", null, 1);
+           SciFileFilter allFilter = new SciFileFilter("*.*", null, 2);
+           fc.addChoosableFileFilter(xcosFilter);
+           fc.addChoosableFileFilter(cosFilter);
+           fc.addChoosableFileFilter(allFilter);
+           fc.setFileFilter(xcosFilter);
+
+           fc.setAcceptAllFileFilterUsed(false);
+           fc.displayAndWait();
+
+           if (fc.getSelection() == null || fc.getSelection().length == 0 || fc.getSelection()[0].equals("")) {
+               return;
+           }
+           ConfigXcosManager.saveToRecentOpenedFiles(fc.getSelection()[0]);
+
+           if (getGraph(null) == null) { // Called from palettes
+               //save to recentopenedfile while opening from palettes is handle in Xcos.xcos(filename)
+               Xcos.xcos(fc.getSelection()[0]);
+           }
+           else {
+               ((XcosDiagram) getGraph(null)).openDiagramFromFile(fc.getSelection()[0]);
+           }
+           XcosTab.updateRecentOpenedFilesMenu(((XcosDiagram) getGraph(null)));
        }
 }
index 1c2b17b..448ff23 100644 (file)
@@ -1520,10 +1520,14 @@ public class XcosDiagram extends ScilabGraph {
            if (this.getSavedFile() != null) {
                fc.setSelectedFile(new File(this.getSavedFile()));
            }
-           XcosFileType defaultFileType = XcosFileType.getDefault();
-           SciFileFilter xcosFilter = new SciFileFilter("*." + defaultFileType.getExtension(), defaultFileType.getDescription(), 0);
+
+           SciFileFilter xcosFilter = new SciFileFilter("*.xcos", null, 0);
+           SciFileFilter allFilter = new SciFileFilter("*.*", null, 1);
            fc.addChoosableFileFilter(xcosFilter);
+           fc.addChoosableFileFilter(allFilter);
            fc.setFileFilter(xcosFilter);
+
+           fc.setAcceptAllFileFilterUsed(false);
            fc.displayAndWait();
 
            if (fc.getSelection() == null || fc.getSelection().length == 0 || fc.getSelection()[0].equals("")) {
index dc8edb7..ab93371 100644 (file)
@@ -3,6 +3,7 @@ package org.scilab.modules.xcos.palette.actions;
 import java.awt.Toolkit;
 import java.awt.event.KeyEvent;
 
+import javax.swing.JFileChooser;
 import javax.swing.KeyStroke;
 
 import org.scilab.modules.graph.ScilabGraph;
@@ -12,6 +13,7 @@ import org.scilab.modules.gui.filechooser.FileChooser;
 import org.scilab.modules.gui.filechooser.ScilabFileChooser;
 import org.scilab.modules.gui.menuitem.MenuItem;
 import org.scilab.modules.gui.pushbutton.PushButton;
+import org.scilab.modules.gui.utils.SciFileFilter;
 import org.scilab.modules.xcos.palette.XcosPaletteManager;
 import org.scilab.modules.xcos.utils.XcosFileType;
 import org.scilab.modules.xcos.utils.XcosMessages;
@@ -52,14 +54,23 @@ public class LoadAsPalAction extends DefaultAction {
      * @see org.scilab.modules.graph.actions.DefaultAction#doAction()
      */
     public void doAction() {
-       FileChooser fc = ScilabFileChooser.createFileChooser();
+       SwingScilabFileChooser fc = ((SwingScilabFileChooser) ScilabFileChooser.createFileChooser().getAsSimpleFileChooser());
 
        /* Standard files */
-       String[] mask = XcosFileType.getValidFileMask();
-       String[] desc = XcosFileType.getValidFileDescription();
-       ((SwingScilabFileChooser) fc.getAsSimpleFileChooser()).addMask(mask , desc);
-
+       fc.setTitle(XcosMessages.OPEN);
+       fc.setUiDialogType(JFileChooser.OPEN_DIALOG);
        fc.setMultipleSelection(false);
+
+
+       SciFileFilter xcosFilter = new SciFileFilter("*.xcos", null, 0);
+       SciFileFilter cosFilter = new SciFileFilter("*.cos*", null, 1);
+       SciFileFilter allFilter = new SciFileFilter("*.*", null, 2);
+       fc.addChoosableFileFilter(xcosFilter);
+       fc.addChoosableFileFilter(cosFilter);
+       fc.addChoosableFileFilter(allFilter);
+       fc.setFileFilter(xcosFilter);
+
+       fc.setAcceptAllFileFilterUsed(false);
        fc.displayAndWait();
 
        if (fc.getSelection() == null || fc.getSelection().length == 0 || fc.getSelection()[0].equals("")) {
@@ -67,15 +78,5 @@ public class LoadAsPalAction extends DefaultAction {
        }
 
        XcosPaletteManager.loadUserPalette(fc.getSelection()[0]);
-       
-       //      ConfigXcosManager.saveToRecentOpenedFiles(fc.getSelection()[0]);
-//     if (getGraph(null) == null) { // Called from palettes
-//         //save to recentopenedfile while opening from palettes is handle in Xcos.xcos(filename)
-//         Xcos.xcos(fc.getSelection()[0]);
-//     }
-//     else {
-//         ((XcosDiagram) getGraph(null)).openDiagramFromFile(fc.getSelection()[0]);
-//     }
-//     XcosTab.updateRecentOpenedFilesMenu(((XcosDiagram) getGraph(null)));
     }
 }
\ No newline at end of file