Package java.awt

Examples of java.awt.FileDialog


            this.dispose();
            SteuerFenster.main(
                    parsNeu.parStrPlain().replace('\n', ' ').split(" "));
        } else if (
                arg0.getActionCommand().equals("Starte Tracebetrachter...")) {
            FileDialog dia = new FileDialog(
                    this,
                    "Tracedatei zum Betrachten ausw�hlen",
                    FileDialog.LOAD);
            dia.setFile("*.dat.gz");
            dia.setDirectory(this.pars.getStdPfad());
            dia.setVisible(true);
            if (dia.getFile() == null) {
                return;
            }
            filename = dia.getDirectory() + dia.getFile();
            filename = filename.substring(0, filename.length() - 3);
            paramsTrace = new String[params.length + 2];
            paramsTrace[0] = filename;
            paramsTrace[1] = "dummy";
            for (int i = 0; i < params.length; i++) {
View Full Code Here


       
        this.maxNumTerminals = params.getParValueInt("MaxNumTerminals");
        this.maxNumWords = params.getParValueInt("MaxNumWords");
        this.storeDerivation = params.getParValueBoolean("StoreDerivation?");
       
        FileDialog dia = new FileDialog((Dialog) null, "Select grammar to load.", FileDialog.LOAD);
        dia.setVisible(true);
       
        if (dia.getDirectory() == null || dia.getFile() == null) {
            env.getSimTime().timeTerminate();
            System.exit(0);
        }
       
        grammar = new Grammar(new File(dia.getDirectory() + File.separator + dia.getFile()), new Nonterminal(new StringBuffer("S")));
       
        env.addAgent(
                new GrammarAgent(
                        env.getFirstFreeID(),
                        env,
View Full Code Here

            }
            this.liveWindow.metaInfVis.repaint();
        } else if (arg0.getActionCommand().equals("Generate PDF...")) {
            boolean pause = liveWindow.vidParent.getPause();
            liveWindow.vidParent.pause();
            FileDialog dia = new FileDialog(
                    this,
                    "Save environment view as pdf (works with AbstractEnvironment2D<?> only)...",
                    FileDialog.SAVE);

            dia.setFilenameFilter(new FileNamePostfixFilter("pdf"));

            dia.setVisible(true);

            if (dia.getDirectory() != null && dia.getFile() != null) {
                StaticMethods.saveEnvironmentViewAsPDF(
                        new File(dia.getDirectory() + "/" + dia.getFile()),
                        // dia.getFiles()[0],
                        (AbstractEnvironment2D<?>) this.liveWindow.vidParent
                                .getEnvironment(), new DefaultFontMapper());
            }
            if (!pause) {
                liveWindow.vidParent.depause();
            }
        } else if (arg0.getActionCommand().equals(this.saveString)) {
            AllroundVideoPlugin vid = this.videoPlugin;
            if (vid != null) {
                vid.pause();

                // Ask for executable simState.
                String butt1 = "SimState only";
                String butt2 = "Executable SimState";
                String text = "Saving the simState allows to continue the simulation at another time and on another computer.\n"
                        + "However, problems may occur if the EAS version to run the simulation on is different from the current.\n \n"
                        + "Choose \"" + butt1 + "\" to keep track of the EAS version yourself or \"" + butt2 + "\" to create a package\n"
                        + "containing EAS and everything else required to load the simState including an executable batch file\n"
                        + "(only available when not already running an exectuable simState).";
                String[] buttons = {butt1, GeneralDialog.CANCEL};
                File testFile = new File("./" + GlobalVariables.ROOT_PACKAGE_NAME);
               
                if (testFile.exists() && testFile.isDirectory()) {
                    buttons = new String[] {butt1, butt2, GeneralDialog.CANCEL};
                }
               
                GeneralDialog dia2 = new GeneralDialog(
                        null,
                        text,
                        "Save simState on its own or create executable simState (may take a bit)?",
                        buttons,
                        null);
               
                dia2.setVisible(true);

                if (dia2.getResult().equals(GeneralDialog.CANCEL)) {
                    return;
                }
               
                // Ask for location.
                FileDialog dia = new FileDialog(this, "Select a place to store simulation state", FileDialog.SAVE);
                dia.setFilenameFilter(new FileNamePostfixFilter(".eas"));
                dia.setVisible(true);

                if (dia.getDirectory() != null && dia.getFile() != null) {
                    File easFile;
                    if (dia.getFile().endsWith(".eas")) {
                        easFile = new File(dia.getDirectory() + File.separator + dia.getFile());
                    } else {
                        easFile = new File(dia.getDirectory() + File.separator + dia.getFile() + ".eas");
                    }
                   
                    SerializableSimulationState simState = new SerializableSimulationState(
                            this.liveWindow.environment.getSimTime(), easFile);
                   
                    try {
                        if (dia2.getResult().equals(butt1)) {
                            simState.save();
                        } else if (dia2.getResult().equals(butt2)) {
                            GlobalVariables.getPrematureParameters().logInfo("Creating executable simState (this may take a while).");
                            simState.createExecutableSimState();
                        }
                    } catch (SimStateUnserializableException e) {
                        String info =
                                  "The simulation state could not be saved. This probably means that one or more objects\n"
                                + "stored as field variables are not implementing the Serializable interface.\n"
                                + "Most EAS classes are serializable, so you should check field types from the\n"
                                + "Java internal or possibly external libraries. A good starting point often appears\n"
                                + "to be objects of type BufferedImage (or Graphics, Graphics2D etc). Another known problem\n"
                                + "is given by the unseriablizable Stroke classes - when using " + new AllroundChartPlugin().id() + ",\n"
                                + "try avoiding to specifically set the Stroke. Note that all 3D simulation currently cannot\n"
                                + "be serialized. Concerning AVI and GIF recording, both should be turned off for now\n"
                                + "as errors will occur on reloading the simState (this is work in progress).\n\n"
                                + "A list of unserializable fields in the currently used plugins and environments follows.\n"
                                + "You should first look into them as the trouble-causing field(s) is/are probably among them:\n\n";
                       
                        LinkedList<Class<?>> classes = new LinkedList<>();
                        for (Plugin<?> p : this.videoPlugin.getCurrentEnv().getSimTime().getPlugins()) {
                            classes.add(p.getClass());
                        }
                       
                        classes.add(this.videoPlugin.getCurrentEnv().getClass());
                       
                        for (AbstractAgent<?> a : this.videoPlugin.getCurrentEnv().getAgents()) {
                            classes.add(a.getClass());
                        }
                       
                        HashMap<Field, HashSet<String>> result = Crawler.initiateCrawling(classes);
                        String resString = "";
                       
                        for (Field field : result.keySet()) {
                            resString += "<UnSer> "
                                    + field.getType().getSimpleName() + " "
                                    + field.getName() + " ("
                                    + field.getDeclaringClass().getName() + ") => " + result.get(field) + "\n";
                        }
                       
                        info += resString + "\n\n";
                       
                        GeneralDialog dia3 = new GeneralDialog(
                                null,
                                null,
                                "Simulation state not serialized",
                                new String[] {GeneralDialog.OK, "Throw exception"},
                                info
                                + "Exception caught: " + e.toString() + "\n" + Arrays.toString(e.getStackTrace()).replace(", ", "\n"));
                        dia3.setVisible(true);
                        if (dia3.getResult().equals("Throw exception")) {
                            GlobalVariables.getPrematureParameters().logDebug("Full stack trace of exception: ");
                            e.printStackTrace();
                            GlobalVariables.getPrematureParameters().logError("Throwing exception: ");
                            throw new RuntimeException(e);
                        }
                    }
                }
               
                vid.depause();
            }
        } else if (arg0.getActionCommand().equals(this.pluginManagerString)) {
            liveWindow.vidParent
                    .getEnvironment()
                    .getSimTime()
                    .registerPlugin(PluginFactory.getKonstPlug(
                            new AllroundPluginManager().id(),
                            GlobalVariables.getPrematureParameters()));
        } else if (arg0.getActionCommand().equals("Exit!")) {
            liveWindow.vidParent.pause();

            GeneralDialog dia = new GeneralDialog(
                    null,
                    "Do you really want to exit?\n\nUnsaved changes will be lost!",
                    "Exit request", GeneralDialog.YES_NO, null);
            dia.setLocationRelativeTo(null);
            dia.setVisible(true);

            if (dia.getResult().equals(GeneralDialog.YES)) {
                System.exit(0);
            }

            liveWindow.vidParent.depause();
        }
View Full Code Here

                        }
                    }
                   
                } else if (cmd.equals(
                           Messages.getString("SteuerFenster.ErzeugeHEX"))) {
                    FileDialog dia;

                    dia = new FileDialog(this,
                                         Messages.getString("SteuerFenster."
                                                        + "ErzeugeHEXTitel"),
                                         FileDialog.SAVE);
                    dia.setVisible(true);

                    if (!(dia.getDirectory() == null)
                        && !(dia.getFile() == null)) {
                        LinkedList<Integer> seq
                            = this.aktGrph.getRob().erzeugeSequenz(
                                    this.aktGrph.getAktAut());
                        FileWriter f = new FileWriter(dia.getDirectory()
                                                      + File.separatorChar
                                                      + dia.getFile());
                        Iterator<Integer> it = seq.iterator();

                        while (it.hasNext()) {
                            f.write(((Integer) it.next()).intValue());
                        }
                        f.close();
                    }
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.Vereinfache"))) {
                    this.aktGrph.getRob().vAuts()[
                                   this.aktGrph.getAktAut()].vereinfache();
                    Condition condSimp =
                        this.aktGrph.getRob().getConds()[
                                  this.aktGrph.getAktAut()].simplify();
                    this.aktGrph.getRob().setCond(this.aktGrph.getAktAut(),
                                                  condSimp);
                   
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.VereinfacheAlle"))) {
                    Iterator<Vis> it = this.graphen.iterator();
                    Condition condSimp;
                    Vis aktVis;
                    while (it.hasNext()) {
                        aktVis = (Vis) it.next();
                        for (int i = 0;
                             i < aktVis.getRob().vAuts().length;
                             i++) {
                            aktVis.getRob().vAuts()[i].vereinfache();

                            condSimp = this.aktGrph.getRob().getConds()[
                                          i].simplify();
                            this.aktGrph.getRob().setCond(i, condSimp);
                            aktVis.neuZeichnen();
                        }
                    }
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.InterpretScript"))) {
                   
                    this.aktGrph.getRob().vAuts()[
                        this.aktGrph.getAktAut()].erzeugeAusScript(
                            this.aktGrph.holeAktTxtSeq());
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.Automatenzahl"))) {
                   
                    ArrayList<String> b
                        = new ArrayList<String>(1);
                    b.add(Messages.getString(
                        "SteuerFenster.OK"));
                    AllgemeinerDialog dia2
                        = new AllgemeinerDialog(
                            this,
                            "reef",
                            "Anzahl der Automaten "
                            + "(wirkt sich nur auf zuk�nftige Roboter aus)",
                            b,
                            "" + this.autAnz,
                            1,
                            50,
                            true);

                    dia2.setVisible(true);
                   
                    this.autAnz = Integer.parseInt(dia2.getText());
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.Gesamtautomat"))) {
                    EndlicherAutomat[] eas = this.aktGrph.getRob().getVAut();
                    Condition[] conds = this.aktGrph.getRob().getConds();
                   
                    this.neuerGraph();
                    this.waehleGraph(this.graphZaehl - 1);
                    this.aktGrph.erzeugeAktAusSequenz(
                       SonstMeth.gesamtAutomat(eas, conds).erzeugeStringSeq(),
                       SonstMeth.ausBed("t"),
                       false);
                } else if (cmd.equals(
                        Messages.getString("SteuerFenster.Fancy"))) {
                    this.pars.setEinfacheDar(!this.pars.getEinfacheDar());
                    if (this.pars.getEinfacheDar()) {
                        this.pars.setBezier(
                          fmg.fmg8.graphVis.zeichenModi.Konstanten.BEZ_FANCY);
                    } else {
                        this.pars.setBezier(
                          fmg.fmg8.graphVis.zeichenModi.Konstanten.BEZ_NORMAL);
                    }
                } else if (cmd.equals("PNG...")) {
                    FileDialog dia;
                    String oldVerz;
                   
                    dia = new FileDialog(this,
                                         "Automatendarstellung als PNG "
                                         + "speichern",
                                         FileDialog.SAVE);
                   
                    dia.setFilenameFilter(new DateiFilter("png"));
                   
                    dia.setVisible(true);

                    if (!(dia.getDirectory() == null)
                        && !(dia.getFile() == null)) {
                        oldVerz = this.pars.getStdPfad();
                        this.pars.setStdPfad(dia.getDirectory());
                        this.aktGrph.savePNG(dia.getFile());
                        this.pars.setStdPfad(oldVerz);
                    }
                } else if (cmd.equals("Alle l�schen!")) {
                    ArrayList<String> butts = new ArrayList<String>(2);
                    ArrayList<String> choices = new ArrayList<String>(5);
                    ArrayList<Boolean> aktiv = new ArrayList<Boolean>(5);
                   
                    String gra, tra, con, koo, png, tmp, dat, gz;
                   
                    butts.add("Abbrechen");
                    butts.add("OK");

                    gra = "Alle GRA-Dateien l�schen";
                    tra = "Alle TRA-Dateien l�schen";
                    con = "Alle CON-Dateien l�schen";
                    koo = "Alle KOO-Dateien l�schen";
                    png = "Alle PNG-Dateien l�schen";
                    tmp = "Alle TMP-Dateien l�schen";
                    dat = "Alle DAT-Dateien l�schen";
                    gz = "Alle GZ-Dateien l�schen";
                   
                   
                    choices.add(gra);
                    aktiv.add(false);
                    choices.add(tra);
                    aktiv.add(false);
                    choices.add(con);
                    aktiv.add(false);
                    choices.add(koo);
                    aktiv.add(false);
                    choices.add(png);
                    aktiv.add(true);
                    choices.add(tmp);
                    aktiv.add(true);
                    choices.add(dat);
                    aktiv.add(false);
                    choices.add(gz);
                    aktiv.add(false);

                   
                    Ankreuzdialog dia = new Ankreuzdialog(
                            this,
                            "Geben Sie an, welche Dateitypen aus"
                                + " dem Verzeichnis '"
                                + this.pars.getStdPfad()
                                + "' gel�scht werden sollen",
                            "L�schen best�tigen",
                            butts,
                            choices,
                            aktiv);
                   
                    dia.setVisible(true);
                   
                    if (dia.getResult().equals("OK")) {
                        if (dia.getAuswahl().contains(tmp)) {
                            SonstMeth.deleteALL(
                                    fmg.fmg8.graphVis.Konstanten.TEMP_ENDUNG,
                                    this.pars);
                        }
                       
                        if (dia.getAuswahl().contains(con)) {
                            SonstMeth.deleteALL(
                                    fmg.fmg8.graphVis.Konstanten.BED_ENDUNG,
                                    this.pars);
                        }
                       
                        if (dia.getAuswahl().contains(koo)) {
                            SonstMeth.deleteALL(
                                    fmg.fmg8.graphVis.Konstanten.KOORD_ENDUNG,
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(gra)) {
                            SonstMeth.deleteALL(
                                    fmg.fmg8.graphVis.Konstanten.GRAPH_ENDUNG,
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(tra)) {
                            SonstMeth.deleteALL(
                                    fmg.fmg8.graphVis.Konstanten.TRANS_ENDUNG,
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(png)) {
                            SonstMeth.deleteALL(
                                    fmg.fmg8.graphVis.Konstanten.PNG_ENDUNG,
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(dat)) {
                            SonstMeth.deleteALL(
                                    "dat",
                                    this.pars);
                        }

                        if (dia.getAuswahl().contains(gz)) {
                            SonstMeth.deleteALL(
                                    "gz",
                                    this.pars);
                        }
                    }
View Full Code Here

            parsNeu.complete();
            dispose();
            SteuerFenster.main(StaticMethods.processStringAsCommandLineParameters(
                    parsNeu.parStrPlain().replace('\n', ' ')));
        } else if (arg0.getActionCommand().equals(START_XML_TRACE_VIEWER_STRING)) {
            final FileDialog dia = new FileDialog(
                    this,
                    "Tracedatei zum Betrachten auswählen",
                    FileDialog.LOAD);
            dia.setFile("*.xml*");
            dia.setDirectory(pars.getStdDirectory());
            dia.setVisible(true);
            if (dia.getFile() == null) {
                this.setCursor(new Cursor(0));
                return;
            }
            filename = dia.getDirectory() + dia.getFile();
            // filename = filename.substring(0, filename.length() - 3);
            paramsTrace = new String[params.length + 2];
            paramsTrace[0] = filename;
            paramsTrace[1] = "dummy";
            for (int i = 0; i < params.length; i++) {
                paramsTrace[i + 2] = params[i];
            }

            dispose();
            TraceBetrachter.main(paramsTrace);
        } else if (arg0.getActionCommand().equals(FITNESS_STATISTICS_XML_STRING)) {
            final JFileChooser dia = new JFileChooser();
            dia.setDialogTitle(
                    "Verzeichnis zum Extrahieren der Statistiken auswählen");
            dia.setCurrentDirectory(new File(pars.getStdDirectory()));
            dia.setVisible(true);
            dia.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            final int returnVal = dia.showOpenDialog(this);
            File f = null;
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                f = dia.getSelectedFile();
                filename = f.getAbsolutePath();
                paramsTrace = new String[params.length + 2];
                paramsTrace[0] = filename;
                paramsTrace[1] = "allefitnesswerte";
                for (int i = 0; i < params.length; i++) {
                    paramsTrace[i + 2] = params[i];
                }

                TraceBetrachter.main(paramsTrace);
            }
        } else if (arg0.getActionCommand().equals(COMBINE_STATISTICS_XML_STRING)) {
            final JFileChooser dia = new JFileChooser();
            final FileNamePostfixFilter filter = new FileNamePostfixFilter("txt");
            filter.setVerzZulassen(true);
            dia.setDialogTitle(
                    "Dateien zum Zusammenfassen auswählen");
            dia.setCurrentDirectory(new File(pars.getStdDirectory()));
            dia.setBounds(0, 0, 800, 600);
            dia.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            dia.setMultiSelectionEnabled(true);
            dia.setFileFilter(filter);

            final int returnVal = dia.showOpenDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                final File[] fs = dia.getSelectedFiles();
                String verzeichnis = null;
                String zieldatei;
                final String[] quelldateien = new String[fs.length];
                final String trennzeichen = ";";
                int i = 0;

                for (final File f : fs) {
                    verzeichnis = f.getParentFile().getAbsolutePath();
                    quelldateien[i] = f.getName();
                    i++;
                }

                // Zieldateiname generieren:
                zieldatei = "durchschnitt";
                for (final String s : quelldateien) {
                    final String zwisch = StaticMethods.datNamOhneErw(s);
                    zieldatei += "_" + zwisch.substring(zwisch.length() - 4);
                }
                if (zieldatei.length() > 100) {
                    zieldatei = zieldatei.substring(0, 100);
                }
                zieldatei += ".txt";

                StatisticMethods.erzeugeDurchDatei(
                        verzeichnis,
                        quelldateien,
                        zieldatei,
                        trennzeichen,
                        pars);
            }
        } else if (arg0.getActionCommand().equals(START_ARROW_MASTER_STRING)) {
            dispose();
            PfeilController.main(params);
        } else if (arg0.getActionCommand().equals(SET_PARAMETER_COLLECTION_STRING)) {
            final GeneralDialog dia = new GeneralDialog(
                    this,
                    null,
                    "Set new parameters as collection "
                            + "(caution: program restart after click on OK button!)",
                    GeneralDialog.OK_CANCEL_BUTT,
                    "Fill in parameters alternating as name / value pairs separated by space "
                            + "(caution: program restart after click on OK button).");
            dia.setVisible(true);

            if (dia.getResult().equals(GeneralDialog.OK)) {
                final String[] args = StaticMethods.processStringAsCommandLineParameters(dia.getText());
                final ParCollection paramsNeu = new ParCollection(pars);
                paramsNeu.complete();
                paramsNeu.overwriteParameterList(args);
                dispose();
                Starter.main(StaticMethods.processStringAsCommandLineParameters(
View Full Code Here

            }
        }
       
        // Export plugins.
        if (e.getSource().equals(buttOK)) {
            FileDialog dia = new FileDialog(this.myStarter, "Choose JAR file to store plugins", FileDialog.SAVE);
            frame.dispose();
            dia.setFilenameFilter(new FileNamePostfixFilter(".jar"));
            dia.setVisible(true);

            if (dia.getDirectory() == null || dia.getFile() == null) {
                return;
            }
           
            File storeFile = new File(dia.getDirectory() + File.separator + dia.getFile());
      @SuppressWarnings("deprecation")
            Object[] selected = list.getSelectedValues();
            String dirPrefixPlugin = dirPrefix;
            StaticMethods.delDir(new File(dirPrefix));
           
            for (Object o : selected) {
              Class<Plugin<?>> c = (Class<Plugin<?>>) o;
             
              try {
                    dirPrefixPlugin = dirPrefix + c.newInstance().id() + "/";
                } catch (Exception e2) {
                    throw new RuntimeException("Plugin instance not created.");
                }
              File dir = new File(dirPrefixPlugin + "/" + c.getPackage().getName().replace('.', '/'));
              File dirOwn = new File("./" + c.getPackage().getName().replace('.', '/'));
              FileCopy copy = new FileCopy();
              dir.mkdirs();
             
              try {
          copy.copyFolder(dirOwn, dir, true, false);
        } catch (IOException e1) {
          GlobalVariables.getPrematureParameters().logError("Could not copy directory '" + dirOwn + "':" + e1.getMessage() + "\n" + Arrays.deepToString(e1.getStackTrace()).replace(',', '\n'));
          GlobalVariables.getPrematureParameters().logInfo("Plugin export aborted due to errors.");
          return;
        }
            }
           
            try {
        ZipIt.createJARfromDirectory(dirPrefix, storeFile, null);
      } catch (IOException e1) {
        GlobalVariables.getPrematureParameters().logError("Could not create JAR file '" + storeFile + "'.");
      }
           
            StaticMethods.delDir(new File(dirPrefix));
           
            GlobalVariables.getPrematureParameters().logInfo("Plugin JAR file '" + storeFile + "' exported.");
           
            GeneralDialog dia2 = new GeneralDialog(
                myStarter,
                null,
                "Export successful (" + selected.length + " plugins)",
                GeneralDialog.OK_BUTT,
                "Plugin JAR file '" + storeFile + "' exported:\n\n- " + Arrays.deepToString(selected).replace("[", "").replace("]", "").replace(", ", "\n- "));
            dia2.setVisible(true);
           
            return;
        } else if (e.getSource().equals(buttCancel)) {
            frame.dispose();
            return;
        }
       
        myStarter.actionPerformed(e);
       
        if (e.getActionCommand().equals(Starter.EXIT_STRING)) {
            myStarter.dispose();
            System.exit(0);
        } else if (e.getActionCommand().equals(Starter.LOAD_STORED_SIMULATION)) {
            if (loadSimState()) {
                this.myStarter.dispose();
            }
        } else if (e.getActionCommand().equals(Starter.EXPORT_PLUGINS_STRING)) {
            frame = new JDialog(myStarter, Starter.EXPORT_PLUGINS_STRING + " NOTE: all necessary classes have to be located in the package of the main plugin class.");
            JPanel panel = new JPanel(new GridLayout(2, 1));
            Object[] items = convertListToArray(getSharablePlugins());
            list = new JList(items);
            JScrollPane jScrollPane1 = new JScrollPane(list);
            panel.add(jScrollPane1);
           
            JPanel mainPanel = new JPanel();
            JPanel panel1 = new JPanel(new GridLayout(1, 4));
            panel1.add(buttOK);
            panel1.add(buttCancel);
           
            buttOK.addActionListener(this);
            buttCancel.addActionListener(this);
           
            panel.add(mainPanel);
            mainPanel.add(panel1);
           
            frame.getContentPane().add(panel);
            frame.setSize(750, 400);
            frame.setVisible(true);
        } else if (e.getActionCommand().equals(Starter.IMPORT_PLUGINS_STRING)) {
           
            // User selects file to import.
            FileDialog dia = new FileDialog(this.myStarter, "Choose JAR file to store plugins", FileDialog.LOAD);
            dia.setFilenameFilter(new FileNamePostfixFilter(".jar"));
            dia.setVisible(true);

            if (dia.getDirectory() == null || dia.getFile() == null) {
                return;
            }

            // Delete temp dir if existing.
            StaticMethods.delDir(new File(dirPrefix));

            // Extract ZIP archive from JAR.
            try {
                ZipIt.extractZIPArchive(
                        new File(dia.getDirectory() + File.separator + dia.getFile()),
                        new File("."));
            } catch (Exception e1) {
                e1.printStackTrace();
            }
           
            // Create list of plugin ids.
            LinkedList<Class<Plugin<?>>> list = PluginFactory.findAllNonAbstractPluginClasses(false);
            LinkedList<String> listPlugStr = new LinkedList<String>();
            for (Class<Plugin<?>> c : list) {
                try {
                    listPlugStr.add(c.newInstance().id());
                } catch (Exception e1) {
                    GlobalVariables.getPrematureParameters().logError("Plugin instance not created: " + c.getName());
                }
            }
           
            // Check if some new plugin id already exists.
            File[] files = new File(this.dirPrefix).listFiles();
            String[] selected = new String[files.length];
            int num = 0;
           
            for (File f : files) {
                boolean ignore = false;
               
                if (listPlugStr.contains(f.getName())) {
                    GeneralDialog dia2 = new GeneralDialog(
                            this.myStarter,
                            "A Plugin with id '" + f.getName() + "' already exists in local class tree. Do you wish to continue?",
                            "Plugin id exists",
                            GeneralDialog.YES_NO,
                            null);
                    dia2.setVisible(true);
                    if (dia2.getResult().equals(GeneralDialog.NO)) {
                        ignore = true;
                    }
                }
               
                if (!ignore) {
                    // Import plugin.
                    selected[num] = f.getName();
                   
                    String destDir = ".";
                    File destDirFile = new File(destDir);
                    try {
                        new FileCopy().copyFolder(f, destDirFile, true, true);
                    } catch (IOException e1) {
                        GlobalVariables.getPrematureParameters().logError("Could not copy directory '" + f + "':" + e1.getMessage() + "\n" + Arrays.deepToString(e1.getStackTrace()).replace(',', '\n'));
                    }
                } else {
                    selected[num] = f.getName() + " (NOT IMPORTED).";
                }
               
                num++;
            }
           
            // Delete temp dir.
            StaticMethods.delDir(new File(dirPrefix));

            GeneralDialog dia2 = new GeneralDialog(
                    myStarter,
                    null,
                    "Import successful (" + files.length + " plugins)",
                    GeneralDialog.OK_BUTT,
                    "Plugin JAR file '"
                            + dia.getDirectory()
                            + dia.getFile()
                            + "' imported:\n\n- "
                            + Arrays.deepToString(selected).replace("[", "").replace("]", "").replace(", ", "\n- "));
            dia2.setVisible(true);

            // Find new plugins.
View Full Code Here

            this.myStarter.findNewPlugins(GlobalVariables.getPrematureParameters().getAllParsArrayView());
        }
    }

    public static boolean loadSimState() {
        FileDialog dia = new FileDialog((JFrame) null, "Select a simulation to load", FileDialog.LOAD);
        dia.setFilenameFilter(new FileNamePostfixFilter(".eas"));
        dia.setVisible(true);

        if (dia.getDirectory() == null || dia.getFile() == null) {
            return false;
        }
       
        File easFile = new File(dia.getDirectory() + File.separator + dia.getFile());
        SimulationTime<?> simTime = new SerializableSimulationState(null, easFile).load();
        simTime.resumeLoadedSimulation();
        informAboutPausedSimulation();
        return true;
    }
View Full Code Here

    public void rShowMessage(Rengine re, String message) {
        System.out.println("rShowMessage \""+message+"\"");
    }
 
    public String rChooseFile(Rengine re, int newFile) {
  FileDialog fd = new FileDialog(new Frame(), (newFile==0)?"Select a file":"Select a new file", (newFile==0)?FileDialog.LOAD:FileDialog.SAVE);
  fd.show();
  String res=null;
  if (fd.getDirectory()!=null) res=fd.getDirectory();
  if (fd.getFile()!=null) res=(res==null)?fd.getFile():(res+fd.getFile());
  return res;
    }
View Full Code Here

    public void rShowMessage(Rengine re, String message) {
        System.out.println("rShowMessage \""+message+"\"");
    }
 
    public String rChooseFile(Rengine re, int newFile) {
  FileDialog fd = new FileDialog(new Frame(), (newFile==0)?"Select a file":"Select a new file", (newFile==0)?FileDialog.LOAD:FileDialog.SAVE);
  fd.show();
  String res=null;
  if (fd.getDirectory()!=null) res=fd.getDirectory();
  if (fd.getFile()!=null) res=(res==null)?fd.getFile():(res+fd.getFile());
  return res;
    }
View Full Code Here

    public void rShowMessage(Rengine re, String message) {
        System.out.println("rShowMessage \""+message+"\"");
    }
 
    public String rChooseFile(Rengine re, int newFile) {
  FileDialog fd = new FileDialog(new Frame(), (newFile==0)?"Select a file":"Select a new file", (newFile==0)?FileDialog.LOAD:FileDialog.SAVE);
  fd.show();
  String res=null;
  if (fd.getDirectory()!=null) res=fd.getDirectory();
  if (fd.getFile()!=null) res=(res==null)?fd.getFile():(res+fd.getFile());
  return res;
    }
View Full Code Here

TOP

Related Classes of java.awt.FileDialog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.