コード例 #1
0
ファイル: FressaFunctions.java プロジェクト: vlady21/jclic
  public FressaFunctions(Options options) {

    msg = options.getMessages(BUNDLE);

    try {
      robot = new Robot();
    } catch (java.awt.AWTException ex) {
      System.err.println("Unable to create java.awt.Robot: " + ex.getMessage());
    }

    formExchange = new TFormExchange(INITIAL_FORM_EXCHANGE_POS, msg.get("acc_exchangeBtnChar"));
    formKeyboard = new TFormKeyboard(options, this);

    noHandCursor = options.getBoolean(NO_HAND_CURSOR, false);
    forceRectangularShapes = options.getBoolean(FORCE_RECTANGLES, false);

    scanTimerSpan = options.getInt(SCAN_TIMER_SPAN, DEFAULT_TIMER_SPAN);
    scanIncludingArrowButtons = options.getBoolean(SCAN_INCLUDING_ARROWS, true);
    withChangeZoneButton = options.getBoolean(CHANGE_ZONE_BUTTON, false);
    scanArrowsAtEndOfActivity = options.getBoolean(SCAN_ARROWS_AT_END, false);
    scanFlagButton = options.getBoolean(SCAN_FLAG, false);
    jumpWellPlaced = options.getBoolean(JUMP_WELL_PLACED, true);
    showKeyboard = options.getBoolean(SHOW_KEYBOARD, true);
    changeZoneIfNoClick = options.getBoolean(CHANGE_ZONE_IF_NO_CLICK, false);
    autoScanOnStart = options.getBoolean(AUTO_SCAN_ON_START, false);
    directedScanOnStart = options.getBoolean(DIRECTED_SCAN_ON_START, false);
    autoAutoScan = options.getBoolean(AUTO_AUTO_SCAN, false);
    withSwaying = options.getBoolean(SWAYING, false);
    readLabels = options.getBoolean(READ_LABELS, false);
    withVoice = options.getBoolean(WITH_VOICE, false);

    if (withVoice) {
      /*
      fressaVoice=new FressaVoice();
      fressaVoice.start();
      readText(msg.get("acc_voiceGreeting"));
      withVoice=fressaVoice.xxxxrunning;
       */
    }
  }
コード例 #2
0
ファイル: ExportTaskDlg.java プロジェクト: projectestac/jclic
  public static void doTask(
      ResourceBridge rb,
      AuthorSettings settings,
      Component parent,
      final String inputPath,
      final String outputPath,
      final String mainFileName,
      final JClicProject project,
      final boolean copyAll,
      final String scormFile) {

    final Messages msg = rb.getOptions().getMessages();
    final ExportTaskDlg exportDlg = new ExportTaskDlg(rb);
    final AuthorSettings set = settings;

    JDialog dlg = new JDialog(JOptionPane.getFrameForComponent(parent), true);
    dlg.setTitle(msg.get("export_project_exporting"));
    dlg.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    dlg.getContentPane().setLayout(new BorderLayout(10, 10));
    dlg.getContentPane().add(exportDlg, BorderLayout.CENTER);
    dlg.pack();
    dlg.setLocationRelativeTo(parent);
    dlg.setLocation(
        (parent.getWidth() - dlg.getWidth()) / 2, (parent.getHeight() - dlg.getHeight()) / 2);

    exportDlg.sw =
        new edu.xtec.util.SwingWorker() {

          @Override
          public Object construct() {
            try {

              ArrayList<String> fileList = new ArrayList<String>();
              fileList.add("imsmanifest.xml");

              if (!copyAll) {
                exportDlg.ps.println("Processing: " + inputPath);
                ProjectFileUtils.processSingleFile(inputPath, outputPath, fileList, exportDlg.ps);
              } else {
                exportDlg.ps.println("Processing all projects in: " + inputPath);
                ProjectFileUtils.processRootFolder(inputPath, outputPath, fileList, exportDlg.ps);
              }

              exportDlg.ps.println("Generating file " + outputPath + "/index.html");
              FileOutputStream fos = new FileOutputStream(new File(outputPath, "index.html"));
              PrintWriter pw = new PrintWriter(new OutputStreamWriter(fos, "UTF-8"));
              String s = indexHtml.replaceAll("%TITLE%", StrUtils.safeHtml(project.settings.title));
              s = StrUtils.replace(s, "%MAINFILE%", mainFileName);
              s = StrUtils.replace(s, "%JSCODEBASE%", set.jsCodeBase);
              pw.print(s);
              pw.flush();
              pw.close();
              fileList.add("index.html");

              JSONObject json = project.settings.toJSON(msg);
              json.put("mainFile", mainFileName);

              exportDlg.exportPath = new File(outputPath);

              String fn = "favicon.ico";
              exportDlg.ps.println("Copying " + fn);
              StreamIO.writeStreamTo(
                  getClass().getResourceAsStream("/edu/xtec/resources/icons/" + fn),
                  new FileOutputStream(new File(outputPath, fn)));
              fileList.add(fn);

              fn = "icon-192.png";
              exportDlg.ps.println("Copying " + fn);
              StreamIO.writeStreamTo(
                  getClass().getResourceAsStream("/edu/xtec/resources/icons/" + fn),
                  new FileOutputStream(new File(outputPath, fn)));
              fileList.add(fn);

              fn = "icon-72.png";
              exportDlg.ps.println("Copying " + fn);
              StreamIO.writeStreamTo(
                  getClass().getResourceAsStream("/edu/xtec/resources/icons/" + fn),
                  new FileOutputStream(new File(outputPath, fn)));
              fileList.add(fn);

              exportDlg.ps.println("Copying project cover model");
              StreamIO.writeStreamTo(
                  getClass().getResourceAsStream("/edu/xtec/resources/icons/cover-base.jpg"),
                  new FileOutputStream(new File(outputPath, "project-cover.jpg")));
              fileList.add("project-cover.jpg");
              json.put("cover", "project-cover.jpg");

              exportDlg.ps.println("Copying project thumbnail model");
              StreamIO.writeStreamTo(
                  getClass().getResourceAsStream("/edu/xtec/resources/icons/thumb-base.jpg"),
                  new FileOutputStream(new File(outputPath, "project-thumb.jpg")));
              fileList.add("project-thumb.jpg");
              json.put("thumbnail", "project-thumb.jpg");

              exportDlg.ps.println("Generating project.json");
              fileList.add("project.json");

              // Order fileList and remove duplicate values
              Collections.sort(fileList);
              fileList = new ArrayList<String>(new LinkedHashSet<String>(fileList));
              json.append("files", fileList);

              fos = new FileOutputStream(new File(outputPath, "project.json"));
              pw = new PrintWriter(new OutputStreamWriter(fos, "UTF-8"));
              pw.print(json.toString(2));
              pw.flush();
              pw.close();

              exportDlg.ps.println("Generating imsmanifest.xml");
              fos = new FileOutputStream(new File(outputPath, "imsmanifest.xml"));
              pw = new PrintWriter(new OutputStreamWriter(fos, "UTF-8"));
              s = imsmanifest.replaceAll("%SCORMTITLE%", StrUtils.safeHtml(project.settings.title));
              s =
                  StrUtils.replace(
                      s,
                      "%SCORMID%",
                      "JClic-"
                          + Integer.toHexString((int) (Math.random() * 0xEFFFFF + 0x100000))
                              .toUpperCase());
              StringBuilder sb = new StringBuilder();
              ListIterator<String> it = fileList.listIterator();
              while (it.hasNext()) {
                sb.append("   <file href=\"").append(it.next()).append("\"/>\n");
              }
              s = StrUtils.replace(s, "%FILETAGS%", sb.toString());
              pw.print(s);
              pw.flush();
              pw.close();

              if (scormFile != null) {
                final byte[] BUFFER = new byte[1024];
                exportDlg.ps.println(
                    "Generating file \"" + scormFile + "\" with all content inside");

                ZipOutputStream out = new ZipOutputStream(new FileOutputStream(scormFile));
                it = fileList.listIterator();
                while (it.hasNext()) {
                  String file = it.next();
                  FileInputStream in = new FileInputStream(new File(outputPath, file));
                  ZipEntry entry = new ZipEntry(file);
                  out.putNextEntry(entry);
                  int i;
                  while ((i = in.read(BUFFER)) != -1) {
                    out.write(BUFFER, 0, i);
                  }
                  out.closeEntry();
                }
                out.close();
              }

              exportDlg.ps.println("\n" + msg.get("export_project_finished") + " " + outputPath);

              exportDlg.ps.println("\n" + msg.get("export_project_notice"));

              if (scormFile != null) {
                exportDlg.ps.printf(
                    "\n" + msg.get("export_project_scorm_notice") + "\n\n", scormFile);
              }

              exportDlg.browserBtn.setEnabled(true);

            } catch (InterruptedException iex) {
              exportDlg.ps.println(
                  "\nWARNING: The process was interrupted! Contents of the output folder might be unsuitable.");
            } catch (Exception ex) {
              exportDlg.ps.println("\nERROR processing ZIP file: " + ex.getMessage());
            }
            return null;
          }

          @Override
          public void finished() {
            exportDlg.cancelBtn.setText(msg.get("OK"));
            exportDlg.copyBtn.setEnabled(true);
            exportDlg.sw = null;
          }
        };

    exportDlg.sw.start();

    dlg.setVisible(true);
  }