Beispiel #1
0
  public static String getNewFileInSandbox(Frame f, String a) {

    List namesvector = getFileList(a);

    JComboBox combobox = new JComboBox(RiskUtil.asVector(namesvector));

    // Messages
    Object[] message =
        new Object[] {TranslationBundle.getBundle().getString("core.error.applet"), combobox};

    // Options
    String[] options = {"OK", "Cancel"};

    int result =
        JOptionPane.showOptionDialog(
            f, // the parent that the dialog blocks
            message, // the dialog message array
            "select " + a, // the title of the dialog window
            JOptionPane.OK_CANCEL_OPTION, // option type
            JOptionPane.QUESTION_MESSAGE, // message type
            null, // optional icon, use null to use the default icon
            options, // options string array, will be made into buttons
            options[0] // option that should be made into a default button
            );

    if (result == JOptionPane.OK_OPTION) {
      return combobox.getSelectedItem() + "";
    }

    return null;
  }
Beispiel #2
0
  private static void setupLookAndFeel() {

    // set up system Look&Feel
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      RiskUtil.printStackTrace(e);
    }

    // only do this check if there is NO sandbox
    // as otherwise we will get an exception anyway
    if (checkForNoSandbox()) {

      // check for java bug with JFileChooser
      try {

        new JFileChooser();

      } catch (Throwable th) {

        try {
          UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (Exception e) {
          RiskUtil.printStackTrace(e);
        }
      }
    }
    /* OLD
    		// set up system Look&Feel
    		try {

    			String os = System.getProperty("os.name");
    			String jv = System.getProperty("java.version");

    			if ( jv.startsWith("1.4.2") && os != null && os.startsWith("Linux")) {
    				UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
    			}
    			else {
    				UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    			}
    		}
    		catch (Exception e) {
    			RiskUtil.printStackTrace(e);
    		}
    */
  }
Beispiel #3
0
  public static void donate(Component parent) {

    try {
      RiskUtil.donate();
    } catch (Exception e) {
      JOptionPane.showMessageDialog(
          parent,
          "Unable to open web browser: " + e.getMessage(),
          "Error",
          JOptionPane.ERROR_MESSAGE);
    }
  }
Beispiel #4
0
  public static String getNewMap(Frame f) {
    try {
      if (checkForNoSandbox()) {
        List mapsList = getFileList(RiskFileFilter.RISK_MAP_FILES);
        // try and start new map chooser,
        // on fail revert to using the old one
        return SwingMEWrapper.showMapChooser(f, mapsList);
      }
    } catch (Throwable th) {
      RiskUtil.printStackTrace(th);
    }

    // can not have the map store, fall back to normal map chooser
    return getNewFile(f, RiskFileFilter.RISK_MAP_FILES);
  }
Beispiel #5
0
  public static void runLobby(Risk risk) {

    try {

      if (lobbyURL != null) {

        URLClassLoader ucl =
            URLClassLoader.newInstance(
                new URL[] {new URL("jar:" + lobbyURL + "/LobbyClient.jar!/")});

        Class lobbyclass = ucl.loadClass("org.lobby.client.LobbyClientGUI");

        // TODO: should be like this
        // lobbyclass.newInstance();

        final javax.swing.JPanel panel =
            (javax.swing.JPanel)
                lobbyclass
                    .getConstructor(new Class[] {URL.class})
                    .newInstance(new Object[] {new URL(lobbyURL)});

        javax.swing.JFrame gui = new javax.swing.JFrame("yura.net Lobby");
        gui.setContentPane(panel);
        gui.setSize(800, 600);
        gui.setVisible(true);

        gui.addWindowListener(
            new java.awt.event.WindowAdapter() {
              public void windowClosing(java.awt.event.WindowEvent evt) {
                panel.setVisible(false);
              }
            });
        panel.setVisible(true);

      }
      // else if (lobbyAppletURL!=null) {
      else {

        // on older clients open URL
        RiskUtil.openURL(new URL(lobbyAppletURL));
      }

    } catch (Exception e) {

      risk.showMessageDialog("unable to run the lobby: " + e.toString());
    }
  }
Beispiel #6
0
  public static String getSystemInfoText() {

    ResourceBundle resb = TranslationBundle.getBundle();

    String netInfo, home, cpu, name, info;

    if (checkForNoSandbox()) {
      home = System.getProperty("java.home");
      cpu = System.getProperty("sun.cpu.isalist");
      name =
          System.getProperty("java.runtime.name")
              + " ("
              + System.getProperty("java.runtime.version")
              + ")";
      info = System.getProperty("java.vm.info");

      // we CAN do this outside the sandbox, but for some reason it promps the webstart
      try {
        netInfo =
            InetAddress.getLocalHost().getHostAddress()
                + " ("
                + InetAddress.getLocalHost().getHostName()
                + ")";
      } catch (UnknownHostException e) {
        netInfo = resb.getString("about.nonetwork");
      }
    } else {
      home = "?";
      cpu = "?";
      info = "?";

      if (applet != null) {
        name = "applet";
      } else if (webstart != null) {
        name = "web start (" + webstart + ")";
      } else {
        name = "?";
      }

      netInfo = "?";
    }

    String displayInfo;
    try {
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      displayInfo =
          toolkit.getScreenSize().width
              + "x"
              + toolkit.getScreenSize().height
              + " ("
              + toolkit.getScreenResolution()
              + "dpi) density="
              + GraphicsUtil.density
              + " scale="
              + GraphicsUtil.scale;
    } catch (HeadlessException ex) {
      displayInfo = ex.getMessage();
      if (displayInfo != null) displayInfo = RiskUtil.replaceAll(displayInfo, "\n", " ");
    }

    return " "
        + RiskUtil.RISK_VERSION
        + " (save: "
        + RiskGame.SAVE_VERSION
        + " network: "
        + RiskGame.NETWORK_VERSION
        + ") \n"
        + " "
        + "system:"
        + java.util.Locale.getDefault()
        + " current:"
        + resb.getLocale()
        + " \n"
        + " "
        + netInfo
        + " \n"
        + " "
        + getOSString()
        + " \n"
        + " "
        + cpu
        + " \n"
        + " "
        + UIManager.getLookAndFeel()
        + " \n"
        + " "
        + displayInfo
        + " \n"
        + " "
        + System.getProperty("java.vendor")
        + " \n"
        + " "
        + System.getProperty("java.vendor.url")
        + " \n"
        + " "
        + name
        + " \n"
        + " "
        + System.getProperty("java.vm.name")
        + " ("
        + System.getProperty("java.vm.version")
        + ", "
        + info
        + ") \n"
        + " "
        + System.getProperty("java.specification.version")
        + " ("
        + System.getProperty("java.version")
        + ") \n"
        + " "
        + home
        + " \n"
        + " "
        + System.getProperty("java.class.version");
  }