Beispiel #1
0
  public static boolean openFolderAvailable() {
    if (Base.isWindows() || Base.isMacOS()) return true;

    if (Base.isLinux()) {
      // Assume that this is set to something valid
      if (preferences.get("launcher.linux", null) != null) {
        return true;
      }

      // Attempt to use gnome-open
      try {
        Process p = Runtime.getRuntime().exec(new String[] {"gnome-open"});
        p.waitFor();
        // Not installed will throw an IOException (JDK 1.4.2, Ubuntu
        // 7.04)
        preferences.put("launcher.linux", "gnome-open");
        return true;
      } catch (Exception e) {
      }

      // Attempt with kde-open
      try {
        Process p = Runtime.getRuntime().exec(new String[] {"kde-open"});
        p.waitFor();
        preferences.put("launcher.linux", "kde-open");
        return true;
      } catch (Exception e) {
      }
    }
    return false;
  }
Beispiel #2
0
  /**
   * Implements the other cross-platform headache of opening a folder in the machine's native file
   * browser.
   */
  public static void openFolder(File file) {
    try {
      String folder = file.getAbsolutePath();

      if (Base.isWindows()) {
        // doesn't work
        // Runtime.getRuntime().exec("cmd /c \"" + folder + "\"");

        // works fine on winxp, prolly win2k as well
        Runtime.getRuntime().exec("explorer \"" + folder + "\"");

        // not tested
        // Runtime.getRuntime().exec("start explorer \"" + folder +
        // "\"");

      } else if (Base.isMacOS()) {
        openURL(folder); // handles char replacement, etc

      } else if (Base.isLinux()) {
        String launcher = preferences.get("launcher.linux", null);
        if (launcher != null) {
          Runtime.getRuntime().exec(new String[] {launcher, folder});
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Beispiel #3
0
 public void mouseDragged(MouseEvent e) {
   if (startPoint == null) return;
   Point p = e.getPoint();
   DragMode mode = DragMode.NONE;
   if (Base.isMacOS()) {
     if (button == MouseEvent.BUTTON1 && !e.isShiftDown()) {
       mode = DragMode.TRANSLATE_OBJECT;
     }
   } else {
     if (button == MouseEvent.BUTTON1) {
       mode = DragMode.TRANSLATE_OBJECT;
     }
   }
   double xd = (double) (p.x - startPoint.x);
   double yd = -(double) (p.y - startPoint.y);
   switch (mode) {
     case NONE:
       super.mouseDragged(e);
       break;
     case TRANSLATE_OBJECT:
       doTranslate(xd, yd);
       break;
   }
   startPoint = p;
 }
Beispiel #4
0
  /**
   * Implements the cross-platform headache of opening URLs TODO This code should be replaced by
   * PApplet.link(), however that's not a static method (because it requires an AppletContext when
   * used as an applet), so it's mildly trickier than just removing this method.
   */
  public static void openURL(String url) {
    // System.out.println("opening url " + url);
    try {
      if (Base.isWindows()) {
        // this is not guaranteed to work, because who knows if the
        // path will always be c:\progra~1 et al. also if the user has
        // a different browser set as their default (which would
        // include me) it'd be annoying to be dropped into ie.
        // Runtime.getRuntime().exec("c:\\progra~1\\intern~1\\iexplore "
        // + currentDir

        // the following uses a shell execute to launch the .html file
        // note that under cygwin, the .html files have to be chmodded
        // +x
        // after they're unpacked from the zip file. i don't know why,
        // and don't understand what this does in terms of windows
        // permissions. without the chmod, the command prompt says
        // "Access is denied" in both cygwin and the "dos" prompt.
        // Runtime.getRuntime().exec("cmd /c " + currentDir +
        // "\\reference\\" +
        // referenceFile + ".html");
        if (url.startsWith("http://")) {
          // open dos prompt, give it 'start' command, which will
          // open the url properly. start by itself won't work since
          // it appears to need cmd
          Runtime.getRuntime().exec("cmd /c start " + url);
        } else {
          // just launching the .html file via the shell works
          // but make sure to chmod +x the .html files first
          // also place quotes around it in case there's a space
          // in the user.dir part of the url
          Runtime.getRuntime().exec("cmd /c \"" + url + "\"");
        }

      } else if (Base.isMacOS()) {
        // com.apple.eio.FileManager.openURL(url);

        if (!url.startsWith("http://")) {
          // prepend file:// on this guy since it's a file
          url = "file://" + url;

          // replace spaces with %20 for the file url
          // otherwise the mac doesn't like to open it
          // can't just use URLEncoder, since that makes slashes into
          // %2F characters, which is no good. some might say
          // "useless"
          if (url.indexOf(' ') != -1) {
            StringBuffer sb = new StringBuffer();
            char c[] = url.toCharArray();
            for (int i = 0; i < c.length; i++) {
              if (c[i] == ' ') {
                sb.append("%20");
              } else {
                sb.append(c[i]);
              }
            }
            url = sb.toString();
          }
        }
        com.apple.mrj.MRJFileUtils.openURL(url);

      } else if (Base.isLinux()) {
        String launcher = preferences.get("launcher.linux", "gnome-open");
        if (launcher != null) {
          Runtime.getRuntime().exec(new String[] {launcher, url});
        }
      } else {
        String launcher = preferences.get("launcher", null);
        if (launcher != null) {
          Runtime.getRuntime().exec(new String[] {launcher, url});
        } else {
          Base.logger.warning("Unspecified platform, no launcher available.");
        }
      }

    } catch (IOException e) {
      Base.showWarning("Could not open URL", "An error occurred while trying to open\n" + url, e);
    }
  }
Beispiel #5
0
  public Base() {
    // set the look and feel before opening the window
    try {
      if (Base.isMacOS()) {
        // Only override the UI's necessary for ColorChooser and
        // FileChooser:
        Set<Object> includes = new HashSet<Object>();
        includes.add("ColorChooser");
        includes.add("FileChooser");
        includes.add("Component");
        includes.add("Browser");
        includes.add("Tree");
        includes.add("SplitPane");
        QuaquaManager.setIncludedUIs(includes);

        // set the Quaqua Look and Feel in the UIManager
        UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
        System.setProperty("apple.laf.useScreenMenuBar", "true");

      } else if (Base.isLinux()) {
        // For 0120, trying out the gtk+ look and feel as the default.
        // This is available in Java 1.4.2 and later, and it can't
        // possibly
        // be any worse than Metal. (Ocean might also work, but that's
        // for
        // Java 1.5, and we aren't going there yet)
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");

      } else {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    // use native popups so they don't look so crappy on osx
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            // build the editor object
            editor = new MainWindow();
            // Get sizing preferences. This is an issue of contention; let's look at how
            // other programs decide how to size themselves.
            editor.restorePreferences();
            // add shutdown hook to store preferences
            Runtime.getRuntime()
                .addShutdownHook(
                    new Thread("Shutdown Hook") {
                      private final MainWindow w = editor;

                      public void run() {
                        w.onShutdown();
                      }
                    });

            boolean autoconnect = Base.preferences.getBoolean("replicatorg.autoconnect", true);
            String machineName = preferences.get("machine.name", null);

            editor.loadMachine(machineName, autoconnect);

            // show the window
            editor.setVisible(true);
            UpdateChecker.checkLatestVersion(editor);
          }
        });

    if (logger.isLoggable(Level.FINE)) {
      logger.fine(
          "OS: "
              + System.getProperty("os.name")
              + " "
              + System.getProperty("os.version")
              + " ("
              + System.getProperty("os.arch")
              + ")");
      logger.fine(
          "JVM: "
              + System.getProperty("java.version")
              + " "
              + System.getProperty("java.vm.name")
              + " ("
              + System.getProperty("java.vm.version")
              + " "
              + System.getProperty("java.vendor")
              + ")");
    }
  }
Beispiel #6
0
  public static void main(String args[]) {

    // make sure that this is running on java 1.5 or better.
    if (Base.javaVersion < 1.5f) {
      Base.quitWithError(
          "Need to install Java 1.5",
          "This version of ReplicatorG requires\n"
              + "Java 1.5 or later to run properly.\n"
              + "Please visit java.com to upgrade.",
          null);
    }

    if (Base.isMacOS()) {
      // Default to sun's XML parser, PLEASE.  Some apps are installing some janky-ass xerces.
      System.setProperty(
          "javax.xml.parsers.DocumentBuilderFactory",
          "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
      System.setProperty("com.apple.mrj.application.apple.menu.about.name", "ReplicatorG");
    }

    // parse command line input
    for (int i = 0; i < args.length; i++) {
      // grab any opened file from the command line
      if (supportedExtension(args[i])) {
        Base.openedAtStartup = args[i];
      }

      // Allow for [--debug] [DEBUGLEVEL]
      if (args[i].equals("--debug")) {
        int debugLevelArg = 2;
        if ((i + 1) < args.length) {
          try {
            debugLevelArg = Integer.parseInt(args[i + 1]);
          } catch (NumberFormatException e) {
          }
          ;
        }
        if (debugLevelArg == 0) {
          logger.setLevel(Level.INFO);
          logger.info("Debug level is 'INFO'");
        } else if (debugLevelArg == 1) {
          logger.setLevel(Level.FINE);
          logger.info("Debug level is 'FINE'");
        } else if (debugLevelArg == 2) {
          logger.setLevel(Level.FINER);
          logger.info("Debug level is 'FINER'");
        } else if (debugLevelArg == 3) {
          logger.setLevel(Level.FINEST);
          logger.info("Debug level is 'FINEST'");
        } else if (debugLevelArg >= 4) {
          logger.setLevel(Level.ALL);
          logger.info("Debug level is 'ALL'");
        }
      } else if (args[i].startsWith("-")) {
        System.out.println("Usage: ./replicatorg [[--debug] [DEBUGLEVEL]] [filename.stl]");
        System.exit(1);
      }
    }

    // Warn about read-only directories
    {
      File userDir = getUserDirectory();
      String header = null;
      if (!userDir.exists()) header = new String("Unable to create user directory");
      else if (!userDir.canWrite()) header = new String("Unable to write to user directory");
      else if (!userDir.isDirectory()) header = new String("User directory must be a directory");
      if (header != null) {
        Base.showMessage(
            header,
            "<html><body>ReplicatorG can not write to the directory "
                + userDir.getAbsolutePath()
                + ".<br>"
                + "Some functions of ReplicatorG, like toolpath generation and firmware updates,<br>"
                + "require ReplicatorG to write data to this directory.  You should end this<br>"
                + "session, change the permissions on this directory, and start again.");
      }
    }

    // Use the default system proxy settings
    System.setProperty("java.net.useSystemProxies", "true");
    // Use antialiasing implicitly
    System.setProperty("j3d.implicitAntialiasing", "true");

    // Start the firmware check thread.
    FirmwareUploader.checkFirmware();

    // MAC OS X ONLY:
    // register a temporary/early version of the mrj open document handler,
    // because the event may be lost (sometimes, not always) by the time
    // that MainWindow is properly constructed.
    MRJOpenDocumentHandler startupOpen =
        new MRJOpenDocumentHandler() {
          public void handleOpenFile(File file) {
            // this will only get set once.. later will be handled
            // by the MainWindow version of this fella
            if (Base.openedAtStartup == null) {
              Base.openedAtStartup = file.getAbsolutePath();
            }
          }
        };
    MRJApplicationUtils.registerOpenDocumentHandler(startupOpen);

    // Create the new application "Base" class.
    new Base();
  }
Beispiel #7
0
 public String getInstructions() {
   return Base.isMacOS()
       ? "<html><body>Drag to move object<br>Shift-drag to rotate view<br>Mouse wheel to zoom</body></html>"
       : "<html><body>Left drag to move object<br>Right drag to rotate view<br>Mouse wheel to zoom</body></html>";
 }