Package eas.miscellaneous.system.windowFrames

Examples of eas.miscellaneous.system.windowFrames.GeneralDialog


        }
       
        String search = "Search";
        String searchHidden = "Search including hidden plugins (not recommended)";
       
        GeneralDialog dia = new GeneralDialog(
            this,
            msg,
            "Search for new plugins...",
            new String[] {search, searchHidden, GeneralDialog.CANCEL},
            null);
       
        dia.setVisible(true);
       
        if (!dia.getResult().equals(GeneralDialog.CANCEL)) {
          // Make temp copy of plugin file.
          new FileCopy().copy(
              new File("./" + PluginFactory.PLUGIN_STORAGE_FILE_NAME),
              new File("./" + PluginFactory.PLUGIN_STORAGE_FILE_NAME + "--.tmp"));
         
          boolean includeHidden = dia.getResult().equals(searchHidden);
         
          dispose();
         
            final ParCollection parsNeu = new ParCollection(params);
            List<Class<Plugin<?>>> oldList = new ArrayList<Class<Plugin<?>>>(PluginFactory.STORED_PLUGINS);
           
            if (!StaticMethods.deleteDAT("./" + PluginFactory.PLUGIN_STORAGE_FILE_NAME)) {
                StaticMethods.speichereTextDatei(".", PluginFactory.PLUGIN_STORAGE_FILE_NAME, "MURKS", this.pars);
            }
           
            PluginFactory.STORED_PLUGINS = PluginFactory.loadPluginsFromFile(includeHidden);
           
            Starter.main(parsNeu.getAllParsArrayView());
            List<Class<Plugin<?>>> newList = new ArrayList<Class<Plugin<?>>>(PluginFactory.STORED_PLUGINS);
           
            newList.removeAll(oldList);
            oldList.removeAll(PluginFactory.STORED_PLUGINS);
           
            LinkedList<String> newListStr = new LinkedList<String>();
            LinkedList<String> oldListStr = new LinkedList<String>();
           
            for (Class<Plugin<?>> c : newList) {
                String name;
                try {
                    name = c.newInstance().id().toString();
                } catch (Exception e) {
                    name = "<ID not readable>";
                }
               
                newListStr.add(c.toString() + " (ID: " + name + ")");
            }
           
            for (Class<Plugin<?>> c : oldList) {
                String name;
                try {
                    name = c.newInstance().id().toString();
                } catch (Exception e) {
                    name = "<ID not readable>";
                }
               
                oldListStr.add(c.toString() + " (ID: " + name + ")");
            }
           
            String pluginsFound = " Plugins found (including master schedulers).\n \n"; // Alright.
           
            // Check if plugins have been found and restore old list if not.
            if (PluginFactory.STORED_PLUGINS == null || PluginFactory.STORED_PLUGINS.size() == 0) {
              pluginsFound = " Plugins reloaded. WARNING: The search for plugins was NOT successful (see log for details). \n \n"; // Not alright.
            new FileCopy().copy(
                new File("./" + PluginFactory.PLUGIN_STORAGE_FILE_NAME + ".tmp"),
                new File("./" + PluginFactory.PLUGIN_STORAGE_FILE_NAME));
              PluginFactory.STORED_PLUGINS = PluginFactory.loadPluginsFromFile(includeHidden);
            }
           
            GeneralDialog window = new GeneralDialog(
                    this,
                    null,
                    "Newly found plugins",
                    GeneralDialog.OK_BUTT,
                    PluginFactory.STORED_PLUGINS.size() + pluginsFound
                    + "New plugins: \n" + newListStr.toString().replace("[]","NONE.").replace("[", "").replace("]", "").replace(", ", "\n") + "\n \n \n"
                    + "Removed plugins: \n" + oldListStr.toString().replace("[]","NONE.").replace("[", "").replace("]", "").replace(", ", "\n")
                    );
            window.setVisible(true);
        }
    }
View Full Code Here


                            + ";\n";
                }
//            }
        }

        GeneralDialog dia;
        dia = new GeneralDialog(
                this,
                null,
                RESET_PARAMETERS_STRING,
                GeneralDialog.YES_NO,
                "Do you really want to reset all parameters to their standard values (except parameters in the 'Plugins' category)? "
                        + " This concerns the following parameters:\n"
                        + unterschiede);
        dia.setVisible(true);

        if (dia.getResult().equals(GeneralDialog.YES)) {
            dispose();
            Starter.main(params.getAllParsArrayView());
        }
       
        return;
View Full Code Here

            } catch (final Exception e) {
                e.printStackTrace();
            }
        }
        Collections.sort(pluginIds);
        final GeneralDialog dia = new GeneralDialog(
                this,
                "",
                "Available plugins and master schedulers",
                GeneralDialog.OK_BUTT,
                pluginIds.toString().replace("[", "").replace("]", "").replace(", ", "\n"),
                20,
                100,
                false);
        dia.resetTextBoxCaret();
        dia.setVisible(true);
    }
View Full Code Here

        // Wenn Parameter leere Strings als Wert erhalten.
        final String[] werte = ((JTextArea) arg0.getSource()).getText().split("\n");
        for (final String s : werte) {
            if ((s == null) || s.equals("")) {
                final GeneralDialog dia = new GeneralDialog(
                        this,
                        "ACHTUNG: Im Parameterwert-Feld ist ein Parameter "
                                + "mit einem leeren String assoziiert, was nicht "
                                + "erlaubt ist.",
                        "ACHTUNG: Leerer Parameterwert!",
                        GeneralDialog.OK_BUTT,
                        null);
                dia.setVisible(true);
            }
        }

        // Wenn ein Leerzeichen im Text auftaucht.
        String text = ((JTextArea) arg0.getSource()).getText();
        if (text.indexOf(' ') >= 0) {
            if (text.charAt(0) != '"' || text.charAt(text.length() - 1) != '"') {
                final GeneralDialog dia = new GeneralDialog(
                        this,
                        "CAUTION: A parameter value contains a white space. "
                                + "Parameter values must not contain white spaces except "
                                + "if they are enclosed in quotation marks ' \" '.",
                        "CAUTION: White spaces in parameter value!",
                        GeneralDialog.OK_BUTT,
                        null);
                dia.setVisible(true);
            }
        }

        // Wenn Plugins verändert wurden.
        if ((paramListe.getValueAt(paramListe.getSelectedRow(), SINGLE_PAR_COLUMN) != null)
                && (((SingleParameter) paramListe.getValueAt(paramListe.getSelectedRow(), SINGLE_PAR_COLUMN)).getParameterName()
                        .equalsIgnoreCase(eas.statistics.ConstantsStatistics.PLUGINS_PAR_NAME)
                || ((SingleParameter) paramListe.getValueAt(paramListe.getSelectedRow(), SINGLE_PAR_COLUMN)).getParameterName()
                        .equalsIgnoreCase(eas.statistics.ConstantsStatistics.MASTER_SCHEDULER_PAR_NAME))) {

            // Wenn Plugins benötigt werden und fehlen.
            final LinkedList<String> plugListe = new LinkedList<String>();
            for (final String s : pluginsAkt) {
                plugListe.add(s);
            }
            for (final String s : plugListe) {
                if (PluginFactory.getKonstPlug(s, null) != null) {
                    final List<String> reqListe = PluginFactory.getKonstPlug(s, null).getRequiredPlugins();
                    if (reqListe != null) {
                        if (!plugListe.containsAll(reqListe)) {
//                            final AllgemeinerDialog dia = new AllgemeinerDialog(
//                                    this,
//                                    null,
//                                    "Mindestens eines der folgenden benötigten"
//                                            + " Plugins werden nicht generiert.",
//                                    AllgemeinerDialog.OK_BUTT, reqListe
//                                            .toString());

//                            dia.setVisible(true);
                            break;
                        }
                    }
                }
            }

            // Wenn generische Parameter sich verändert haben (und falls NICHT aus der GUI heraus die Eingabe abgebrochen wurde!).
            if (!cancelledFromIntelligentInput && !aequiStrLists(pluginsOld, pluginsAkt)) {
                final GeneralDialog dia = new GeneralDialog(
                        this,
                        "Achtung! Die Plugins wurden so verändert, dass "
                                + "die Parameterliste geändert werden muss. Wenn die "
                                + "Änderungen beibehalten werden sollen,\n"
                                + "muss das Programm neu gestartet werden. "
                                + "Dabei werden alle generierten JoSchKa-Ausgaben "
                                + "zurückgesetzt.\n \n"
                                + "Sollen die Änderungen wirklich beibehalten "
                                + "und das Programm neu gestartet werden?\n \n \n"
                                + "(Hinweis: Bereits generierte Ausgaben können "
                                + "verwendet werden, indem die Plugins manuell in "
                                + "der Textdatei verändert werden. \nIn dem Fall muss "
                                + "jetzt 'Nein' angegeben werden!)",
                        "Plugins wurden verändert",
                        GeneralDialog.YES_NO,
                        null);
//                dia.setVisible(true);
                dia.setResult(GeneralDialog.YES);
               
                if (dia.getResult().equals(GeneralDialog.NO)) {
                    ((JTextArea) arg0.getSource()).setText(pluginsOldStr);
                } else if (dia.getResult().equals(GeneralDialog.YES)) {
                    final String[] params = generiereErstenSatz();
                    ParCollection paramsComplete = new ParCollection(params);
                    paramsComplete.complete();
                    dispose();
                    Starter.main(paramsComplete.getAllParsArrayView());
View Full Code Here

        this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                GeneralDialog dia = new GeneralDialog(
                        GraphBasedWindow.this,
                        "Do you want to kill all Sumatras with exiting?",
                        "Kill sumatras?",
                        GeneralDialog.YES_NO_CANCEL,
                        null);
                dia.setVisible(true);
                if (dia.getResult().equals(GeneralDialog.YES)) {
                    GraphBasedWindow.this.exitAndCloseSumatras();
                } else if (dia.getResult().equals(GeneralDialog.NO)) {
                    GraphBasedWindow.this.exit();
                }
            }
        });
//       
View Full Code Here

//            message += "SUMATRA PATH incorrect. Please change in starter configuration (.bat file) to correct sumatraPDF.exe location.\n";
//        }
       
        if (!message.equals("") && !shown) {
            shown = true;
            GeneralDialog dia = new GeneralDialog(this, message, "Status messages", GeneralDialog.OK_BUTT, null);
            dia.setVisible(true);
        }
    }
View Full Code Here

            try {StaticMethods.openDocument(GeneralDialog.promptForExternalFile(
                    "TEMP-DIRECTORY",
                    GlobalVariables.getPrematureParameters().getStdDirectory(),
                    false));} catch (IOException e1) {}

            GeneralDialog dia = new GeneralDialog(null, null, "Creation of " + repName + " exercise - output", GeneralDialog.OK_BUTT, output);
            dia.setVisible(true);
        } else if (e.getSource().equals(this.buttonAutoScript)) {
            RepresentableAsGraph rg = this.getApplicableGraphType();
            if (rg != null) {
                String script = rg.autoGenerateScript();
                if (script != null && !script.equals("")) {
                    setScriptAndManageUndo(script);
                } else if (script == null) {
                    GeneralDialog dia = new GeneralDialog(
                            this, "No auto-script for '" + this.getApplicableGraphType().getClass().getSimpleName() + "' implemented.",
                            "No auto-script",
                            GeneralDialog.OK_BUTT,
                            null);
                    dia.setVisible(true);
                }
            }
        } else if (e.getSource().equals(exitButton)) {
            this.exit();
        } else if (e.getSource().equals(exitButtonCloseSumatra)) {
            this.exitAndCloseSumatras();
        } else if (e.getSource().equals(undoButton)) {
            this.undo();
        } else if (e.getSource().equals(unundoButton)) {
            this.unundo();
        } else if (e.getSource().equals(abortButton)) {
            try {
//                System.out.println("djkljfdkldjflk");
//                t.stop();
            } catch (Exception e2) {
            }
        } else if (e.getSource().equals(this.graphVizButton) && this.graphVizButton.isEnabled()) {
            if (this.exceptionThrown == null) {
                for (RepresentableAsGraph r : this.graphTypes) {
                    if (r.isAcceptableCode(scriptText)) {
                        r.createInstanceFromCode(scriptText);
                        PDFProcessor gv = r.generatePDFcode(GeneralDialog.promptForExternalFile(
                                "TEMP-DIRECTORY",
                                GlobalVariables.getPrematureParameters().getStdDirectory(),
                                false).getAbsolutePath());
                       
                        if (gv.getSourceString() != null) {
                            String code = gv.getSourceString();
                            if (code.endsWith("\n")) {
                                code = code.substring(0, code.length()-1);
                            }
                            this.getScriptArea().setText(gv.getCodePrefix() + code);
                            this.manageUndo();
                            break;
                        } else {
                            GeneralDialog.message("PDF processor '" + gv.getClass().getSimpleName() + "' does not offer plain source code.", "GraphViz not available");
                        }
                    }
                }
            } else {
                GeneralDialog dia = new GeneralDialog(
                        this,
                        null,
                        "Could not parse the entered script. Error information:",
                        GeneralDialog.OK_BUTT,
                        this.exceptionThrown.toString() + "\n\n" + Arrays.deepToString(this.exceptionThrown.getStackTrace()).replace(",", ",\n"));
                dia.setVisible(true);
            }
        } else if (e.getSource().equals(this.buttonSaveCurrent)) {
            this.storeScriptToFile();
        } else if (e.getSource().equals(this.buttonRestartSumatra)) {
            this.pars.logInfo("Restarting Sumatra.");
View Full Code Here

               
                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

    }

    @Override
    public String autoGenerateScript() {
        Random rand = new Random();
        GeneralDialog dia = new GeneralDialog(
                null,
                null,
                "Create random FSM -- How many states? (The current script is being overwritten.)",
                GeneralDialog.OK_CANCEL_BUTT, "8", 5, 1, true);
        dia.setVisible(true);

        if (dia.getResult().equals(GeneralDialog.OK)) {
            boolean det = GeneralDialog.yesNoAnswer("Create deterministic FSM?", "Do you want to create a deterministic FSM?\n(No for nondeterministic FSM.)");
            HashSet<String> alphabet = new HashSet<>();
            alphabet.add("a");
            alphabet.add("b");
            int numStates = Integer.parseInt(dia.getText());
           
            FSM fsm = new FSM();
            if (det) {
                fsm.randomizeFSMdet(numStates, alphabet, rand);
            } else {
View Full Code Here

                    }
                       
                } catch (Exception e1) {}
            }

            GeneralDialog dia = new GeneralDialog(
                    this.myStarter,
                    null,
                    "Delete all plugins but the selected ones.",
                    GeneralDialog.OK_CANCEL_BUTT,
                    "Do you really want to delete all plugins (and master schedulers), but the selected ones, from the list of stored plugins?\n"
                            + "You will not be able to use any other plugins after this. To get back to the complete list, use the button '"
                            + Starter.FIND_NEW_PLUGINS_STRING + "'.\n\nThe selected plugins that will remain in the list are:\n\n"
                            + pluginsNew.toString().replace("]", "").replace("[", "").replace(", ", "\n")
                            + "\n\nWARNING: The program will be shut down to complete this procedure.");
            dia.setVisible(true);
           
            if (dia.getResult().equals(GeneralDialog.CANCEL)) {
                return;
            }
           
            try {
                PluginFactory.serializePlugins(pluginsNew, PluginFactory.PLUGIN_STORAGE_FILE_NAME);
                GlobalVariables.getPrematureParameters().logInfo("List of plugins has been reduced to selected ones. Program is shutting down to complete procedure.");
                System.exit(0);
            } catch (IOException e1) {
                GlobalVariables.getPrematureParameters().logError(
                        "List of plugins has NOT been reduced due to the following problem:\n"
                        + e1.getStackTrace().toString().replace("]", "").replace("[", "").replace(", ", "\n"));
                GeneralDialog dia2 = new GeneralDialog(
                        this.myStarter,
                        "The list of plugins has NOT been reduced. See log for details.",
                        "Error occured while reducing plugins list.",
                        GeneralDialog.OK_BUTT,
                        null);
                dia2.setVisible(true);
            }
        }
       
        // 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.
            this.myStarter.findNewPlugins(GlobalVariables.getPrematureParameters().getAllParsArrayView());
        }
    }
View Full Code Here

TOP

Related Classes of eas.miscellaneous.system.windowFrames.GeneralDialog

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.