Esempio n. 1
0
 public File showDirOpenDialog(Component parent, File defaultDir) {
   if (Platform.isMacOS()) {
     System.setProperty("apple.awt.fileDialogForDirectories", "true");
     FileDialog dialog = null;
     if (parent instanceof JFrame == false && parent instanceof JDialog == false) {
       parent = ((JComponent) parent).getTopLevelAncestor();
     }
     if (parent instanceof JFrame) dialog = new FileDialog((JFrame) parent);
     else dialog = new FileDialog((JDialog) parent);
     if (defaultDir != null) dialog.setDirectory(defaultDir.getAbsolutePath());
     dialog.setVisible(true);
     if (dialog.getDirectory() == null || dialog.getFile() == null) return null;
     File file = new File(dialog.getDirectory(), dialog.getFile());
     System.setProperty("apple.awt.fileDialogForDirectories", "false");
     return file;
   } else {
     JFileChooser chooser = new JFileChooser();
     if (defaultDir != null) chooser.setCurrentDirectory(defaultDir);
     chooser.setDialogType(JFileChooser.OPEN_DIALOG);
     chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     chooser.showOpenDialog(parent);
     File file = chooser.getSelectedFile();
     return file;
   }
 }
Esempio n. 2
0
  protected Application() throws Exception {
    UIUtil.runUITaskNow(
        new Runnable() {
          public void run() {
            Thread.currentThread()
                .setUncaughtExceptionHandler(
                    new UncaughtExceptionHandler() {
                      public void uncaughtException(Thread thread, Throwable exception) {
                        Application.getInstance()
                            .showUnhandledErrorDialog(
                                LanguageBundle.getString("general.errors.uncaughtexception.title"),
                                LanguageBundle.getString(
                                    "general.errors.uncaughtexception.message"),
                                exception);
                      }
                    });
          }
        });

    String applicationClassName = "";
    switch (Platform.getOS()) {
      case MAC:
        applicationClassName = Registry.getProperty("application_classname_osx");
        break;
      case WIN:
        applicationClassName = Registry.getProperty("application_classname_windows");
        break;
      case NIX:
        applicationClassName = Registry.getProperty("application_classname_linux");
        break;
    }
    platformApplication = (IApplication) Class.forName(applicationClassName).newInstance();

    UIUtil.setUpLAF();

    resourceEditActions.put(ResourceType.SNU, new EditSnuAction());
    resourceEditActions.put(ResourceType.VIDEO, new EditVideoAction());
    resourceEditActions.put(ResourceType.IMAGE, new EditImageAction());
    resourceEditActions.put(ResourceType.TEXT, new EditTextAction());
    resourceEditActions.put(ResourceType.SOUND, new EditSoundAction());
    resourceEditActions.put(ResourceType.INTERFACE, new EditInterfaceAction());
    resourceEditActions.put(ResourceType.PROJECT, new ProjectEditAction());

    undoManager = new UndoManager();
    undoManager.setLimit(999);

    UIManager.put("AbstractUndoableEdit.undoText", "");
    UIManager.put("AbstractUndoableEdit.redoText", "");
  }
Esempio n. 3
0
  private void checkUpdate()
      throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
    String url;
    try {
      url = Registry.getProperty("updater.url");
    } catch (Exception e) {
      throw new IOException(e.getMessage()); // i hate leaking "exception"
    }
    HttpClient client = new HttpClient();

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("version", Build.getVersion());
    params.put("release", "" + Build.getRelease());
    if (PreferencesManager.getVersionIndependentPreferences()
        .getBoolean("updater.include.usageData", true)) {
      params.put("uuid", Application.getUUID());
      params.put("platform.arch", Platform.getArch());
      params.put("platform.os", Platform.getOS().getCanonicalName());
      params.put("platform.os.version", Platform.getOS().getVersion());
      params.put("locale.country", LanguageBundle.getCurrentLocale().getCountry());
      params.put("locale.language", LanguageBundle.getCurrentLocale().getLanguage());
    }

    List<NameValuePair> nvp = new ArrayList<NameValuePair>();
    for (String key : params.keySet()) nvp.add(new NameValuePair(key, "" + params.get(key)));

    GetMethod request = new GetMethod(url);
    request.setQueryString(nvp.toArray(new NameValuePair[nvp.size()]));
    LogFactory.getLog(getClass()).info(String.format("Checking for updates: %s", request.getURI()));
    client.executeMethod(request);
    String response = request.getResponseBodyAsString();
    Document doc = DomUtil.parseXMLString(response);
    availableRelease = XPathHelper.xpathAsDouble(doc, "/korsakow/release");
    availableVersion = XPathHelper.xpathAsString(doc, "/korsakow/version");
    message = XPathHelper.xpathAsString(doc, "/korsakow/message");
  }
Esempio n. 4
0
  /** TODO: refactor this, perhaps into the Platform class, or maybe into Application */
  public static String getKorsakowHome() {
    final String home;
    switch (Platform.getOS()) {
      case MAC:
        home =
            Util.join(
                Arrays.asList(
                    Application.getUserHome(), "Library", "Application Support", "Korsakow"),
                File.separator);
        break;
      case WIN:
        home = Util.join(Arrays.asList(System.getenv("AppData"), "Korsakow"), File.separator);
        break;

      default:
      case NIX:
        home = Util.join(Arrays.asList(getUserHome(), ".korsakow"), File.separator);
        break;
    }
    return home;
  }