Example #1
0
  /** Al ejecutar la aplicación, crea y muestra la ventana principal. */
  @Override
  protected void startup() {
    org.jdesktop.application.ResourceMap resourceMap =
        org.jdesktop.application.Application.getInstance(delphsim.DelphSimApp.class)
            .getContext()
            .getResourceMap(DelphSimView.class);

    // Sólo permitir una instancia (mediante sockets)
    try {
      // Se intenta bloquear el socket por defecto
      ss = new java.net.ServerSocket(PORT);
    } catch (java.net.BindException be) {
      // Si no se puede, ya hay otra instancia, mensaje y cerrar
      JOptionPane.showMessageDialog(
          null,
          resourceMap.getString("YaEjecutandose.msg"),
          resourceMap.getString("YaEjecutandose.title"),
          JOptionPane.INFORMATION_MESSAGE); // NOI18N
      System.exit(1);
    } catch (java.io.IOException ioe) {
      // Si ocurre otro problema, se vuelca el error y se cierra
      ioe.printStackTrace();
      System.exit(1);
    }

    // Crear y mostrar la vista general
    this.interfaz = new DelphSimView(this);
    show(this.interfaz);
    // Establecer icono, tamaño, posición y el listener para confirmar salida
    Image img =
        new ImageIcon(DelphSimApp.class.getResource(resourceMap.getString("Application.icon")))
            .getImage(); // NOI18N
    DelphSimApp.getApplication().getMainFrame().setIconImage(img);
    DelphSimApp.getApplication()
        .getMainFrame()
        .setSize(
            resourceMap.getInteger("Application.initialSize.width"),
            resourceMap.getInteger("Application.initialSize.height")); // NOI18N
    DelphSimApp.getApplication().getMainFrame().setLocationRelativeTo(null);
    DelphSimApp.getApplication().getMainFrame().setVisible(true);
    DelphSimApp.getApplication().addExitListener(new ConfirmExit());
    // Eliminar archivos temporales si es que queda alguno
    File[] fs =
        new File(
                new File(System.getProperty("java.class.path")).getParent()
                    + // NOI18N
                    File.separator
                    + "temp"
                    + File.separator)
            .listFiles(); // NOI18N
    if (fs != null) {
      for (int i = 0; i < fs.length; i++) {
        fs[i].delete();
      }
    }
    // Comprobar si hay una copia de respaldo
    this.interfaz.comprobarCopiaRespaldo();
  }
Example #2
0
 /**
  * Método que pide confirmación al usuario antes de salir de la aplicación.
  *
  * @param e El evento generado.
  * @return Si se puede salir o no (elección del usuario).
  */
 public boolean canExit(EventObject e) {
   // Si se ha modificado el modelo, pedir confirmación de salida
   if (DelphSimApp.getApplication().getInterfaz().getArchivoModificado()) {
     org.jdesktop.application.ResourceMap resourceMap =
         org.jdesktop.application.Application.getInstance(delphsim.DelphSimApp.class)
             .getContext()
             .getResourceMap(DelphSimView.class);
     Object source = (e != null) ? e.getSource() : null;
     Component owner = (source instanceof Component) ? (Component) source : null;
     String[] opciones = {"Sí", "No"};
     int option =
         JOptionPane.showOptionDialog(
             owner,
             resourceMap.getString("ExitListener.msg"),
             resourceMap.getString("ExitListener.title"),
             JOptionPane.YES_NO_OPTION,
             JOptionPane.WARNING_MESSAGE,
             null,
             opciones,
             opciones[1]); // NOI18N
     return option == JOptionPane.YES_OPTION;
   } else {
     return true;
   }
 }