/**
  * @autor Jack Krauser
  * @param tituloMensaje El título del mensaje
  * @param mensaje El mensaje
  * @param nombreBotones Un arreglo de String que contiene el nombre de los botones y tiene este
  *     formato: new String[]{"Boton4", "Boton3", "Boton2", "Boton1",} Así como se visualiza es el
  *     orden en el que aparecerá en el diálogo pero inverso, o sea, "Boton4", "Boton3", "Boton2",
  *     "Boton1" se visualiza asi: "Boton1", "Boton2", "Boton3", "Boton4"
  * @param nombreBotonFoco Nombre del botón que obtendrá el foco al iniciar el formulario
  * @param jFrame Define quien será el jFrame padre de este diálogo
  * @param jInternalFrame Define quien será el jInternalFrame padre de este diálogo
  * @return Retorno un entero indicando que botón fue presionado siendo 3 el primer botón de
  *     izquierda a derecha (es decir de 3 a 0)
  */
 public static int presentarInformacionConCuatroBotones(
     String tituloMensaje,
     String mensaje,
     String[] nombreBotones,
     String nombreBotonFoco,
     javax.swing.JFrame jFrame,
     javax.swing.JInternalFrame jInternalFrame) {
   int retorno = 0;
   if (mensaje.charAt(0) == 'T') {
     if (jFrame != null)
       retorno =
           javax.swing.JOptionPane.showOptionDialog(
               jFrame,
               mensaje.substring(1),
               tituloMensaje,
               javax.swing.JOptionPane.YES_NO_OPTION,
               javax.swing.JOptionPane.INFORMATION_MESSAGE,
               null,
               nombreBotones,
               nombreBotonFoco);
     if (jInternalFrame != null)
       retorno =
           javax.swing.JOptionPane.showInternalOptionDialog(
               jInternalFrame,
               mensaje.substring(1),
               tituloMensaje,
               javax.swing.JOptionPane.YES_NO_OPTION,
               javax.swing.JOptionPane.INFORMATION_MESSAGE,
               null,
               nombreBotones,
               nombreBotonFoco);
   } else {
     if (jFrame != null) javax.swing.JOptionPane.showMessageDialog(jFrame, mensaje.substring(1));
     if (jInternalFrame != null)
       javax.swing.JOptionPane.showInternalMessageDialog(jInternalFrame, mensaje.substring(1));
   }
   return retorno;
 }
Example #2
0
  /**
   * Displays and about dialog box, regardless of the event, and offers to display the GNU GPL,
   * offering to download it if it is not found locally.
   *
   * @param e ignored action event
   */
  public void actionPerformed(ActionEvent e) {
    // We only want to open one About Dialog at a time
    // So if we already have, stop right here
    if (alreadyOpen) {
      return;
    }

    // Set aleadyOpen to true so we won't open another dialog
    // if this method is called again while we're still displaying
    // something
    alreadyOpen = true;

    // Open a standard about dialog with the option to
    // view the GPL or just say OK

    String message =
        name
            + " v"
            + version
            + "\n"
            + blurb
            + "\n\n"
            + copyright
            + "\n\nThis program is Open Source software, or more"
            + "\nspecifically, free software. You can redistribute"
            + "\nit and/or modify it under the terms of the GNU"
            + "\nGeneral Public License (GPL) as published by the "
            + "\nFree Software Foundation; either version 2 of the"
            + "\nLicense, or (at your option) any later version.\n";

    int viewGPL;

    Object[] optionButtons = {"View GPL", "OK"};
    if (internalFrames) {
      viewGPL =
          JOptionPane.showInternalOptionDialog(
              parent,
              message,
              "About " + name,
              0,
              JOptionPane.INFORMATION_MESSAGE,
              programLogo,
              optionButtons,
              optionButtons[1]);
    } else {
      viewGPL =
          JOptionPane.showOptionDialog(
              parent,
              message,
              "About " + name,
              0,
              JOptionPane.INFORMATION_MESSAGE,
              programLogo,
              optionButtons,
              optionButtons[1]);
    }

    // If they wanted to view the GPL, try and read the file
    // from the current directory
    if (viewGPL == JOptionPane.YES_OPTION) {
      // Set up the scrollpane to hold the GPL once we read it
      JTextArea textArea = new JTextArea(15, 60);
      textArea.setEditable(false);
      textArea.setWrapStyleWord(true);
      textArea.setLineWrap(true);
      //	    textArea.setFont(new Font("Courier", Font.PLAIN, 10));

      JScrollPane scrollPane = new JScrollPane(textArea);

      // The URL for the Free Software foundation
      // in case we need to download a new copy of the GPL
      URL gplURL = null;

      try {
        gplURL = new URL("http://www.fsf.org/copyleft/gpl.txt");
      } catch (MalformedURLException urlException) {
      }

      boolean loadedGPL = false;
      BufferedReader inGPL = null;

      // If we have a problem, bring up a dialog
      // and ask if we should grab it from the net
      gplURL = GPLAboutDialog.class.getResource("/com/hackerdude/devtools/db/sqlide/copying");
      try {
        inGPL = new BufferedReader(new InputStreamReader(gplURL.openStream()));
        String textLine = null;
        StringBuffer sb = new StringBuffer(8192);
        while ((textLine = inGPL.readLine()) != null) {
          if (textLine.equals("")) sb.append("\n\n");
          else sb.append(textLine).append(' ');
        }
        textArea.setText(sb.toString());
        textArea.setCaretPosition(0);
        loadedGPL = true;
      } catch (IOException exc) {
      }
      ;

      // If we actually got a hold of the file,
      // display it
      if (loadedGPL == true) {
        scrollPane.setPreferredSize(textArea.getPreferredScrollableViewportSize());
        if (internalFrames) {
          JOptionPane.showInternalMessageDialog(
              parent,
              scrollPane,
              "GNU General Public License",
              JOptionPane.INFORMATION_MESSAGE,
              gnuLogo);
        } else {
          JOptionPane.showMessageDialog(
              parent,
              scrollPane,
              "GNU General Public License",
              JOptionPane.INFORMATION_MESSAGE,
              gnuLogo);
        }
      }
    }
    // We're done, so if they want to open the window up again,
    // it's okay
    alreadyOpen = false;
  }