Package de.yaams.maker.helper.gui

Examples of de.yaams.maker.helper.gui.YProgressWindowRepeat


      // Open file and seek to the end of it.
      file = new RandomAccessFile(dest, "rw");
      file.seek(downloaded);

      final YProgressWindowRepeat p = new YProgressWindowRepeat(I18N.t("Download {0} ({1})", url.toString(),
          FileHelper.humanReadableByteCount(size, false)), "web");
      stream = connection.getInputStream();
      while (status == DOWNLOADING) {
        /*
         * Size buffer according to how much of the file is left to
         * download.
         */
        byte buffer[];
        if (size - downloaded > MAX_BUFFER_SIZE) {
          buffer = new byte[MAX_BUFFER_SIZE];
        } else {
          buffer = new byte[size - downloaded];
        }

        // Read from server into buffer.
        int read = stream.read(buffer);
        if (read == -1) {
          break;
        }

        // Write buffer to file.
        file.write(buffer, 0, read);
        downloaded += read;
        if (viewMonitor) {
          p.setNote(I18N.t("{0}% / {1}", Math.round(getProgress()), FileHelper.humanReadableByteCount(downloaded, false)));

        }
        stateChanged();
      }

      p.close();

      /*
       * Change status to complete if this point was reached because
       * downloading has finished.
       */
 
View Full Code Here


   * Send feeback to yaams
   *
   * @param data
   */
  public static void sendData(String type, String title, final HashMap<String, String> data) {
    YProgressWindowRepeat y = new YProgressWindowRepeat(I18N.t("Sende Daten zu yaams.de"), "web");

    BufferedReader rd = null;

    try {
      File cap = new File(YAamsCore.tmpFolder, "cap.jpg");
      if (cap.exists()) {
        FileHelper.deleteFile(cap);
      }
      // create screenshot
      try {
        BufferedImage bufferedImage = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
        ImageIO.write(bufferedImage, "jpg", cap);
      } catch (Throwable t) {
        Log.ger.info("Can not create capture " + cap, t);
        FileHelper.deleteFile(cap);
      }

      // add basic data
      data.put("title", title);
      data.put("type", type);
      data.put("yaams", YAamsCore.TITLE);
      data.put("log", FileHelper.readFileToString(Log.file));

      ClientHttpRequest post = new ClientHttpRequest("http://www.yaams.de/file/sendFeedback.php");

      // add files
      post.setParameter("cap", cap);

      // Construct data
      // final StringBuffer send = new StringBuffer("1=1");
      for (final String key : data.keySet()) {
        String d = data.get(key);
        post.setParameter(key, d == null ? "null" : d);
      }

      // // data
      // final URL url = new
      // URL("http://www.yaams.de/launcher/feedback.php");
      // final URLConnection conn = url.openConnection();
      // conn.setDoOutput(true);
      // final OutputStreamWriter wr = new
      // OutputStreamWriter(conn.getOutputStream());
      // wr.write(send.toString());
      // wr.flush();
      //
      // Get the response
      rd = new BufferedReader(new InputStreamReader(post.post()));
      String line;
      final StringBuffer erg = new StringBuffer("");
      while ((line = rd.readLine()) != null) {
        erg.append(line);
      }

      // clean up
      FileHelper.deleteFile(cap);

      // show it & close all
      YDialog.ok(I18N.t("Feedback"), erg.toString(), "monitor");
      // wr.close();
      rd.close();

    } catch (final Throwable t) {
      YEx.info("Can not send feedback to http://www.yaams.de/file/sendFeedback.php", t);
    } finally {
      try {
        if (rd != null) {
          rd.close();
        }
      } catch (Throwable t) {
      }
    }
    y.close();
  }
View Full Code Here

   * Copy all files in the path to another path
   *
   * @param infopath
   */
  public static void copyTree(final File source, final File dest) {
    YProgressWindowRepeat y = new YProgressWindowRepeat(I18N.t("Kopiere {0} nach {1}", source, dest), "folder_copy");
    for (final File file : source.listFiles()) {
      final File d = new File(dest + File.separator + file.getName());
      y.setNote(d.getName());
      if (file.isDirectory()) {
        mkdirs(d);
        copyTree(file, d);
      } else {
        copy(file, d);
      }
    }
    y.close();
  }
View Full Code Here

    // do it
    final ZipFile zipFile = new ZipFile(archive);
    final Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zipFile.entries();

    // progress
    YProgressWindowRepeat y = new YProgressWindowRepeat(I18N.t("Entpacke {0} nach", archive.getName()), "archive_folder");

    final byte[] buffer = new byte[16384];
    int len;
    while (entries.hasMoreElements()) {
      // update progress

      final ZipEntry entry = entries.nextElement();

      final String entryFileName = entry.getName();

      final File dir = buildDirectoryHierarchyFor(entryFileName, destDir);
      FileHelper.mkdirs(dir);

      y.setNote(dir.getAbsolutePath());

      if (!entry.isDirectory()) {
        final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(destDir, entryFileName)));

        final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));

        while ((len = bis.read(buffer)) > 0) {
          bos.write(buffer, 0, len);
        }

        bos.flush();
        bos.close();
        bis.close();
      }
    }

    y.close();

    return erg;
  }
View Full Code Here

   * @author http://www.wsoftware.de/practices/file-io.html
   * @param zip
   * @param goal
   */
  public static void packZip(final File dir, final File goal) {
    YProgressWindowRepeat y = new YProgressWindowRepeat(I18N.t("Packe {0} nach {1}", dir, goal.getName()), "archive_setup");
    try {
      int prefixLength;
      ZipOutputStream zipOut;
      prefixLength = dir.getAbsolutePath().length() + 1;
      zipOut = new ZipOutputStream(new FileOutputStream(goal.getAbsolutePath()));
      try {
        createZipFrom(y, zipOut, prefixLength, dir);
      } finally {
        zipOut.close();
      }
    } catch (final Throwable t) {
      YEx.warn("Can not pack zip from " + dir + " to " + goal, t);
    }
    y.close();
  }
View Full Code Here

   * @throws NoSuchAlgorithmException
   * @throws NoSuchPaddingException
   */
  public static void encryptFile(File originalFile, File encryptedFile, String password, String type) throws NoSuchAlgorithmException, NoSuchPaddingException {

    YProgressWindowRepeat y = new YProgressWindowRepeat(I18N.t("Verschlüssle " + originalFile.getName()), "lock");

    FileInputStream in = null;
    CipherOutputStream out = null;
    try {
      // set basics
      Cipher cipher = Cipher.getInstance(type);
      SecretKey key = new SecretKeySpec(password.getBytes(), type);
      cipher.init(Cipher.ENCRYPT_MODE, key);

      // do it
      in = new FileInputStream(originalFile);
      out = new CipherOutputStream(new FileOutputStream(encryptedFile), cipher);
      byte[] byteBuffer = new byte[1024];
      for (int n; (n = in.read(byteBuffer)) != -1; out.write(byteBuffer, 0, n)) {
        ;
      }
      in.close();
      out.close();
      // new File(originalFile).delete();
    } catch (Throwable t) {
      YEx.warn("Can not encrypt File " + originalFile + " to " + encryptedFile, t);
    } finally {
      // close it
      try {
        if (in != null) {
          in.close();
        }
      } catch (IOException e) {
      }
      // close it
      try {
        if (out != null) {
          out.close();
        }
      } catch (IOException e) {
      }
    }

    y.close();
  }
View Full Code Here

   * @throws NoSuchPaddingException
   */
  public static void decryptFile(File encryptedFile, File decryptedFile, String password, String type) throws NoSuchAlgorithmException,
      NoSuchPaddingException {

    YProgressWindowRepeat y = new YProgressWindowRepeat(I18N.t("Entschlüssle " + encryptedFile.getName()), "unlock");

    CipherInputStream in = null;
    OutputStream out = null;
    try {
      // set basics
      Cipher cipher = Cipher.getInstance(type);
      SecretKey key = new SecretKeySpec(password.getBytes(), type);
      cipher.init(Cipher.DECRYPT_MODE, key);
      // do it
      in = new CipherInputStream(new FileInputStream(encryptedFile), cipher);
      out = new FileOutputStream(decryptedFile);
      byte[] byteBuffer = new byte[1024];
      for (int n; (n = in.read(byteBuffer)) != -1; out.write(byteBuffer, 0, n)) {
        ;
      }
      in.close();
      out.close();
      // new File(encryptedFile).delete();
    } catch (Throwable t) {
      YEx.warn("Can not decrypt File " + encryptedFile + " to " + decryptedFile, t);
    } finally {
      // close it
      try {
        if (in != null) {
          in.close();
        }
      } catch (IOException e) {
      }
      // close it
      try {
        if (out != null) {
          out.close();
        }
      } catch (IOException e) {
      }

    }

    y.close();
  }
View Full Code Here

        }

        // imageeditor exist?
        final File f = new File(YAamsCore.programPath, "imageeditor.jar");

        YProgressWindowRepeat y = new YProgressWindowRepeat("Starting " + f.getAbsolutePath(), "imageeditor");
        if (!f.exists()) {
          // dl it
          NetHelper.downloadFile(f, "http://www.yaams.de/file/plugins/ImageEditor.jar");
        }

        // check file
        if (RessRess.endWithExtention(file, new String[] { "ie", "jpg", "jpeg", "jpe", "gif", "png", "psd", "bmp", "pict", "tga",
            "ras", "pcx" })
            || !RessRess.endWithExtention(file, new String[] { "ie", "jpg", "jpeg", "jpe", "gif", "png", "psd", "bmp", "pict",
                "tga", "ras", "pcx" })
            && YDialog.askUser(I18N.t("Bild {0} wird nicht unterstützt.", file.getName()), "ress.imageeditor",
                "imageeditor_warn",
                I18N.t("Wahrscheinlich kann ImageEditor die Datei nicht öffnen. Soll Sie dennoch geöffnet werden?"),
                I18N.t("Trotzdem öffnen"), I18N.CANCEL, "imageeditor_ok", "cancel")) {
          // run it
          SystemHelper.runExternal(
              new String[] { "java", "-jar", "-Xms128m", "-Xmx512M", f.getAbsolutePath(), file.getAbsolutePath() }, true);
        }

        y.close();
      }
    }));

    imagepanel.add(bar, BorderLayout.NORTH);
  }
View Full Code Here

TOP

Related Classes of de.yaams.maker.helper.gui.YProgressWindowRepeat

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.