Exemplo n.º 1
0
  /**
   * ZombieFrame's constructor.
   *
   * @param contents Optional JPanel(s) to add to content pane. Arguments > 0 are ignored.
   */
  public ZombieFrame(JPanel... contents) {
    super("ZombieHouse");

    // Request keyboard focus for the frame.
    setFocusable(true);
    requestFocusInWindow();
    requestFocus();

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setUndecorated(true);
    setResizable(false);
    setBackground(Color.BLACK);

    // The content pane. An optional JPanel may be passed into the
    // constructor. It creates an empty pane with a black background if
    // one isn't provided.
    pane = getContentPane();
    pane.setBackground(Color.BLACK);
    pane.setFocusable(false);
    pane.setVisible(true);
    if (contents.length > 0) {
      pane.add(contents[0]);
    }

    keys = new ZombieKeyBinds((JComponent) pane);

    // Get the graphics device information.
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice graphics = environment.getDefaultScreenDevice();

    pack();

    // Go full screen, if supported.
    if (graphics.isFullScreenSupported()) {
      try {
        graphics.setFullScreenWindow(this);
        // Having gone full screen, retrieve the display size.
        // size = Toolkit.getDefaultToolkit().getScreenSize();

        // This double-switching of setVisible is to fix a bug with
        // full-screen-exclusive mode on OS X. Versions 10.8 and later
        // don't send keyboard events properly without it.
        if (System.getProperty("os.name").contains("OS X")) {
          setVisible(false);
        }
      } catch (HeadlessException ex) {
        System.err.println(
            "Error: primary display not set or found. "
                + "Your experience of life may be suboptimal.");
        ex.printStackTrace();
      }
    } else {
      // If full-screen-exclusive mode isn't supported, switch to
      // maximized window mode.
      System.err.println("Full-screen-exclusive mode not supported.");
      setExtendedState(Frame.MAXIMIZED_BOTH);
    }
    setVisible(true);
  }
 public void actionPerformed(ActionEvent e) {
   final String S_ProcName = "actionPerformed";
   CFBamSwingMainJFrame mainJFrame = null;
   {
     Container cont = getParent();
     while ((cont != null) && (!(cont instanceof CFBamSwingMainJFrame))) {
       cont = cont.getParent();
     }
     if (cont != null) {
       mainJFrame = (CFBamSwingMainJFrame) cont;
     }
   }
   char pw[] = textKeystorePassword.getPassword();
   String keystorePassword;
   if (pw != null) {
     keystorePassword = new String(pw);
   } else {
     keystorePassword = null;
   }
   CFBamClientConfigurationFile configFile = swingSchema.getClientConfigurationFile();
   String keystoreFileName = configFile.getKeyStore();
   boolean exitApp = false;
   boolean exitForm = false;
   boolean creatingKeystore = false;
   KeyStore keyStore = null;
   File keystoreFile = new File(keystoreFileName);
   if (!keystoreFile.exists()) {
     int userOption = JOptionPane.NO_OPTION;
     try {
       userOption =
           JOptionPane.showOptionDialog(
               null,
               "Would you like to create the keystore \""
                   + keystoreFileName
                   + "\"?\n"
                   + "Selecting No will exit the application so you can edit the client configuration file and restart.",
               "Create Keystore?",
               JOptionPane.YES_NO_OPTION,
               JOptionPane.QUESTION_MESSAGE,
               null,
               null,
               null);
     } catch (HeadlessException x) {
       throw CFLib.getDefaultExceptionFactory()
           .newRuntimeException(
               getClass(), S_ProcName, "Caught HeadlessException -- " + x.getMessage(), x);
     }
     if (userOption == JOptionPane.YES_OPTION) {
       creatingKeystore = true;
       JInternalFrame nextForm = swingSchema.newCreateKeystoreJInternalFrame();
       getDesktopPane().add(nextForm);
       nextForm.setVisible(true);
       nextForm.show();
       Container cont = getParent();
       while ((cont != null) && (!(cont instanceof JInternalFrame))) {
         cont = cont.getParent();
       }
       if (cont != null) {
         JInternalFrame frame = (JInternalFrame) cont;
         try {
           frame.setClosed(true);
         } catch (Exception x) {
         }
       }
     } else {
       exitApp = true;
     }
   } else if (!keystoreFile.isFile()) {
     JOptionPane.showMessageDialog(
         null,
         "The referenced JCEKS keystore \"" + keystoreFileName + "\" is not a file.",
         "Error",
         JOptionPane.ERROR_MESSAGE,
         null);
     exitApp = true;
   } else if (!keystoreFile.canRead()) {
     JOptionPane.showMessageDialog(
         null,
         "Permission denied attempting to access JCEKS keystore \"" + keystoreFileName + "\".",
         "Error",
         JOptionPane.ERROR_MESSAGE,
         null);
     exitApp = true;
   }
   if ((!exitApp) && (!creatingKeystore)) {
     try {
       keyStore = KeyStore.getInstance("jceks");
       char[] caPassword = keystorePassword.toCharArray();
       FileInputStream input = new FileInputStream(keystoreFileName);
       keyStore.load(input, caPassword);
       input.close();
       swingSchema.setKeyStore(keyStore);
       exitForm = true;
     } catch (CertificateException x) {
       keyStore = null;
       JOptionPane.showMessageDialog(
           null,
           "Could not open keystore due to CertificateException -- " + x.getMessage(),
           "Error",
           JOptionPane.ERROR_MESSAGE,
           null);
       exitApp = true;
     } catch (IOException x) {
       keyStore = null;
       JOptionPane.showMessageDialog(
           null,
           "Could not open keystore due to IOException -- " + x.getMessage(),
           "Error",
           JOptionPane.ERROR_MESSAGE,
           null);
     } catch (KeyStoreException x) {
       keyStore = null;
       JOptionPane.showMessageDialog(
           null,
           "Could not open keystore due to KeyStoreException -- " + x.getMessage(),
           "Error",
           JOptionPane.ERROR_MESSAGE,
           null);
       exitApp = true;
     } catch (NoSuchAlgorithmException x) {
       keyStore = null;
       JOptionPane.showMessageDialog(
           null,
           "Could not open keystore due to NoSuchAlgorithmException -- " + x.getMessage(),
           "Error",
           JOptionPane.ERROR_MESSAGE,
           null);
       exitApp = true;
     }
   }
   if (exitApp) {
     swingSchema.setKeyStore(null);
     mainJFrame.exitApplication();
   } else if (exitForm) {
     JInternalFrame nextForm = swingSchema.newOpenDeviceKeyJInternalFrame();
     getDesktopPane().add(nextForm);
     nextForm.setVisible(true);
     nextForm.show();
     Container cont = getParent();
     while ((cont != null) && (!(cont instanceof JInternalFrame))) {
       cont = cont.getParent();
     }
     if (cont != null) {
       JInternalFrame frame = (JInternalFrame) cont;
       try {
         frame.setClosed(true);
       } catch (Exception x) {
       }
     }
   }
 }