예제 #1
0
 // open default mail client (use the mailto: protocol as the URI), eg.:
 // mailto:[email protected]?SUBJECT=Love me tender&BODY=love me sweet
 public static void mail(URI document) throws IOException {
   if (Desktop.isDesktopSupported()) Desktop.getDesktop().mail(document);
 }
예제 #2
0
 // print a file
 public static void print(File document) throws IOException {
   if (Desktop.isDesktopSupported()) Desktop.getDesktop().print(document);
 }
예제 #3
0
 public void actionPerformed(ActionEvent evt) {
   String cmd = evt.getActionCommand();
   try {
     if (cmd != null) {
       if (cmd.equalsIgnoreCase("Exit")) {
         System.exit(0);
       }
       if (cmd.equalsIgnoreCase("View Images")) {
         if (Desktop.isDesktopSupported()) {
           // if(Desktop.getDesktop().isSupported(Action.OPEN)) {
           Desktop.getDesktop().open(new File("C:/.hack3rClient/Scre"));
           // }
         }
       }
       if (cmd.equalsIgnoreCase("Toggle 10x Damage")) {
         newDamage = true;
       }
       if (cmd.equalsIgnoreCase("Untoggle 10x Damage")) {
         newDamage = false;
       }
       if (cmd.equalsIgnoreCase("Website")) {
         openUpWebSite("http://vestigex.com");
       }
       if (cmd.equalsIgnoreCase("Forums")) {
         openUpWebSite("http://vestigex.com/forums/forum.php");
       }
       if (cmd.equalsIgnoreCase("Vote")) {
         openUpWebSite("http://vestigex.com/vote.php");
       }
       if (cmd.equalsIgnoreCase("Donate")) {
         openUpWebSite("http://vestigex.com/donate.html");
       }
       if (cmd.equalsIgnoreCase("Highscores")) {
         openUpWebSite("http://vestigex.com/highscores/");
       }
       if (cmd.equalsIgnoreCase("Guides")) {
         openUpWebSite("http://vestigex.com/forums/forum.php");
       }
       if (cmd.equalsIgnoreCase("Support")) {
         openUpWebSite("vestigex.com/forums/forum.php");
         JOptionPane.showMessageDialog(
             this,
             "A link to our support center on our forums has Popped up. Please create a new thread!",
             "Client Support",
             JOptionPane.INFORMATION_MESSAGE);
       }
       if (cmd.equalsIgnoreCase("Client Information")) {
         JOptionPane.showMessageDialog(
             this,
             "Vestige-x is Developed By Bill. We hope you enjoy the server!",
             "Client Updates",
             JOptionPane.INFORMATION_MESSAGE);
       }
       if (cmd.equalsIgnoreCase("World Map")) {
         launchURL("3. WorldMap.jar");
       }
       if (cmd.equalsIgnoreCase("Item Search")) {
         launchURL("1. ItemList.bat");
       }
       if (cmd.equalsIgnoreCase("Screenshot")) {
         takeScreenshot(true);
       }
     }
   } catch (Exception e) {
   }
 }
예제 #4
0
  /**
   * Try to determine whether this application is running under Windows or some other platform by
   * examining the "os.name" property.
   */
  static {
    String os = System.getProperty("os.name");
    // String version = System.getProperty("os.version"); // for Win7, reports "6.0" on JDK7, should
    // be "6.1"; for Win8, reports "6.2" as of JDK7u17

    if (SystemUtils.startsWithIgnoreCase(os, "windows 7"))
      isWin7 = true; // reports "Windows Vista" on JDK7
    else if (SystemUtils.startsWithIgnoreCase(os, "windows 8"))
      isWin7 = true; // reports "Windows 8" as of JDK7u17
    else if (SystemUtils.startsWithIgnoreCase(os, "windows vista")) isVista = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows xp")) isWinXP = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows 2000")) isWin2k = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows nt")) isWinNT = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "windows"))
      isWin9X = true; // win95 or win98 (what about WinME?)
    else if (SystemUtils.startsWithIgnoreCase(os, "mac")) isMac = true;
    else if (SystemUtils.startsWithIgnoreCase(os, "so")) isSolaris = true; // sunos or solaris
    else if (os.equalsIgnoreCase("linux")) isLinux = true;
    else isUnix = true; // assume UNIX, e.g. AIX, HP-UX, IRIX

    String osarch = System.getProperty("os.arch");
    String arch = (osarch != null && osarch.contains("64")) ? "_x64" /* eg. 'amd64' */ : "_x32";
    String syslib = SYSLIB + arch;

    try { // loading a native lib in a static initializer ensures that it is available before any
          // method in this class is called:
      System.loadLibrary(syslib);
      System.out.println(
          "Done loading '" + System.mapLibraryName(syslib) + "', PID=" + getProcessID());
    } catch (Error e) {
      System.err.println(
          "Native library '"
              + System.mapLibraryName(syslib)
              + "' not found in 'java.library.path': "
              + System.getProperty("java.library.path"));
      throw e; // re-throw
    }

    if (isWinPlatform()) {
      System.setProperty(
          "line.separator", "\n"); // so we won't have to mess with DOS line endings ever again
      comSpec =
          getEnv(
              "comSpec"); // use native method here since getEnvironmentVariable() needs to know
                          // comSpec
      comSpec = (comSpec != null) ? comSpec + " /c " : "";

      try (BufferedReader br =
          new BufferedReader(
              new InputStreamReader(
                  RUNTIME.exec(comSpec + "ver").getInputStream()))) { // fix for Win7,8
        for (String line = null; (line = br.readLine()) != null; ) {
          if (isVista && (line.contains("6.1" /*Win7*/) || line.contains("6.2" /*Win8*/))) {
            isVista = false;
            isWin7 = true;
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }

      String cygdir = getEnv("cygdir"); // this is set during CygWin install to "?:/cygwin/bin"
      isCygWin = (cygdir != null && !cygdir.equals("%cygdir%"));
      cygstartPath = cygdir + "/cygstart.exe"; // path to CygWin's cygutils' "cygstart" binary

      if (getDebug() && Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        for (Desktop.Action action : Desktop.Action.values())
          System.out.println(
              "Desktop action " + action + " supported?  " + desktop.isSupported(action));
      }
    }
  }
예제 #5
0
  public DesktopAppFrame() {
    setLayout(new GridBagLayout());
    final JFileChooser chooser = new JFileChooser();
    JButton fileChooserButton = new JButton("...");
    final JTextField fileField = new JTextField(20);
    fileField.setEditable(false);
    JButton openButton = new JButton("Open");
    JButton editButton = new JButton("Edit");
    JButton printButton = new JButton("Print");
    final JTextField browseField = new JTextField();
    JButton browseButton = new JButton("Browse");
    final JTextField toField = new JTextField();
    final JTextField subjectField = new JTextField();
    JButton mailButton = new JButton("Mail");

    openButton.setEnabled(false);
    editButton.setEnabled(false);
    printButton.setEnabled(false);
    browseButton.setEnabled(false);
    mailButton.setEnabled(false);

    if (Desktop.isDesktopSupported()) {
      Desktop desktop = Desktop.getDesktop();
      if (desktop.isSupported(Desktop.Action.OPEN)) openButton.setEnabled(true);
      if (desktop.isSupported(Desktop.Action.EDIT)) editButton.setEnabled(true);
      if (desktop.isSupported(Desktop.Action.PRINT)) printButton.setEnabled(true);
      if (desktop.isSupported(Desktop.Action.BROWSE)) browseButton.setEnabled(true);
      if (desktop.isSupported(Desktop.Action.MAIL)) mailButton.setEnabled(true);
    }

    fileChooserButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (chooser.showOpenDialog(DesktopAppFrame.this) == JFileChooser.APPROVE_OPTION)
              fileField.setText(chooser.getSelectedFile().getAbsolutePath());
          }
        });

    openButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              Desktop.getDesktop().open(chooser.getSelectedFile());
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    editButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              Desktop.getDesktop().edit(chooser.getSelectedFile());
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    printButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              Desktop.getDesktop().print(chooser.getSelectedFile());
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    browseButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              Desktop.getDesktop().browse(new URI(browseField.getText()));
            } catch (URISyntaxException ex) {
              ex.printStackTrace();
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    mailButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            try {
              String subject = percentEncode(subjectField.getText());
              URI uri = new URI("mailto:" + toField.getText() + "?subject=" + subject);

              System.out.println(uri);
              Desktop.getDesktop().mail(uri);
            } catch (URISyntaxException ex) {
              ex.printStackTrace();
            } catch (IOException ex) {
              ex.printStackTrace();
            }
          }
        });

    JPanel buttonPanel = new JPanel();
    ((FlowLayout) buttonPanel.getLayout()).setHgap(2);
    buttonPanel.add(openButton);
    buttonPanel.add(editButton);
    buttonPanel.add(printButton);

    add(fileChooserButton, new GBC(0, 0).setAnchor(GBC.EAST).setInsets(2));
    add(fileField, new GBC(1, 0).setFill(GBC.HORIZONTAL));
    add(buttonPanel, new GBC(2, 0).setAnchor(GBC.WEST).setInsets(0));
    add(browseField, new GBC(1, 1).setFill(GBC.HORIZONTAL));
    add(browseButton, new GBC(2, 1).setAnchor(GBC.WEST).setInsets(2));
    add(new JLabel("To:"), new GBC(0, 2).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2));
    add(toField, new GBC(1, 2).setFill(GBC.HORIZONTAL));
    add(mailButton, new GBC(2, 2).setAnchor(GBC.WEST).setInsets(2));
    add(new JLabel("Subject:"), new GBC(0, 3).setAnchor(GBC.EAST).setInsets(5, 2, 5, 2));
    add(subjectField, new GBC(1, 3).setFill(GBC.HORIZONTAL));

    pack();
  }