Revision: 14879
          http://gate.svn.sourceforge.net/gate/?rev=14879&view=rev
Author:   thomas_heitz
Date:     2012-01-04 22:11:36 +0000 (Wed, 04 Jan 2012)
Log Message:
-----------
Remove a partial implementation of error popup. It should not be in the 
MainFrame class anyway. Better to extend the Err.println or Log4J.

Modified Paths:
--------------
    gate/trunk/src/gate/gui/MainFrame.java

Removed Paths:
-------------
    gate/trunk/src/gate/swing/ErrorDialog.java

Modified: gate/trunk/src/gate/gui/MainFrame.java
===================================================================
--- gate/trunk/src/gate/gui/MainFrame.java      2012-01-04 17:12:46 UTC (rev 
14878)
+++ gate/trunk/src/gate/gui/MainFrame.java      2012-01-04 22:11:36 UTC (rev 
14879)
@@ -28,7 +28,6 @@
 import java.text.NumberFormat;
 import java.util.*;
 import java.util.List;
-import java.util.Timer;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.lang.reflect.Constructor;
@@ -43,8 +42,6 @@
 
 import org.apache.log4j.*;
 
-import junit.framework.Assert;
-
 import com.ontotext.gate.vr.Gaze;
 
 import gate.*;
@@ -55,7 +52,6 @@
 import gate.gui.creole.manager.PluginUpdateManager;
 import gate.persist.PersistenceException;
 import gate.resources.img.svg.AvailableIcon;
-import gate.security.*;
 import gate.swing.*;
 import gate.util.*;
 import gate.util.persistence.PersistenceManager;
@@ -78,8 +74,6 @@
 
   protected JLabel statusBar;
 
-  protected JButton alertButton;
-
   protected JProgressBar progressBar;
 
   protected JProgressBar globalProgressBar;
@@ -502,7 +496,7 @@
     mainSplit.setOneTouchExpandable(true);
 
     // status and progress bars
-    statusBar = new JLabel();
+    statusBar = new JLabel("Welcome to GATE!");
     statusBar.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));
 
     UIManager.put("ProgressBar.cellSpacing", 0);
@@ -516,14 +510,6 @@
     globalProgressBar.setForeground(new Color(150, 75, 150));
     globalProgressBar.setStringPainted(true);
 
-    Icon alertIcon = getIcon("crystal-clear-app-error");
-    alertButton = new JButton(alertIcon);
-    alertButton.setToolTipText("There was no error");
-    alertButton.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 5));
-    alertButton.setPreferredSize(new Dimension(alertIcon.getIconWidth(),
-      alertIcon.getIconHeight()));
-    alertButton.setEnabled(false);
-
     JPanel southBox = new JPanel(new GridBagLayout());
     GridBagConstraints gbc = new GridBagConstraints();
     gbc.fill = GridBagConstraints.BOTH;
@@ -535,7 +521,6 @@
     gbc.weightx = 0;
     southBox.add(progressBar, gbc);
     southBox.add(globalProgressBar, gbc);
-    southBox.add(alertButton, gbc);
 
     this.getContentPane().add(southBox, BorderLayout.SOUTH);
     progressBar.setVisible(false);
@@ -1691,7 +1676,7 @@
         + "application\nmenu.  Your options/session will not be saved if "
         + "you exit\nwith \u2318Q, use the close button at the top-left"
         + "corner\nof this window instead.";
-      alertButton.setAction(new AlertAction(error, message, null));
+        log.error(message, error);
     }
   }
 
@@ -2189,7 +2174,7 @@
     }
     catch(Exception error) {
       String message = "Error when opening the Datastore.";
-      alertButton.setAction(new AlertAction(error, message, null));
+      log.error(message, error);
     }
     return ds;
   } // openWSDataStore()
@@ -2578,7 +2563,7 @@
           catch(Exception error) {
             String message =
               "There was an error when loading the ANNIE application.";
-            alertButton.setAction(new AlertAction(error, message, null));
+            log.error(message, error);
           }
           finally {
             unlockGUI();
@@ -2623,7 +2608,7 @@
             unlockGUI();
             String message =
               "There was an error when loading the ANNIE application.";
-            alertButton.setAction(new AlertAction(error, message, null));
+            log.error(message, error);
             return;
           }
 
@@ -2664,7 +2649,7 @@
                 catch(ResourceInstantiationException error) {
                   String message = "There was an error when creating"
                     + " the resource: " + pr.getName() + ".";
-                  alertButton.setAction(new AlertAction(error, message, null));
+                  log.error(message, error);
                 }
               } // for(Object loadedPR : loadedPRs)
             }
@@ -2717,7 +2702,7 @@
             String message =
                     "There was an error when loading the " + pluginDir
                             + " application.";
-            alertButton.setAction(new AlertAction(error, message, null));
+            log.error(message, error);
           } finally {
             unlockGUI();
           }
@@ -2787,7 +2772,7 @@
   }
 
   /**
-   * TODO: delete this method as it has moved to {@link PluginManagerUI}
+   * TODO: delete this method as it has moved to PluginManagerUI
    * @deprecated
    */
   class LoadCreoleRepositoryAction extends AbstractAction {
@@ -2861,7 +2846,7 @@
         catch(Exception error) {
           String message =
             "There was a problem when registering your CREOLE directory.";
-          alertButton.setAction(new AlertAction(error, message, null));
+          log.error(message, error);
         }
       }
     }
@@ -3565,7 +3550,7 @@
           SwingUtilities.invokeLater(new Runnable() {
             public void run() {
               String message = error.getMessage();
-              alertButton.setAction(new AlertAction(error, message, null));
+              log.error(message, error);
             }
           });
         }
@@ -3839,7 +3824,7 @@
           }
           catch(GateException error) {
             String message = "Failed to save config data.";
-            alertButton.setAction(new AlertAction(error, message, null));
+            log.error(message, error);
           }
 
           // save the session;
@@ -3862,7 +3847,7 @@
             }
             catch(Exception error) {
               String message = "Failed to save session data.";
-              alertButton.setAction(new AlertAction(error, message, null));
+              log.error(message, error);
             }
           }
           else {
@@ -4204,7 +4189,7 @@
             PersistenceManager.loadObjectFromFile(file);
           } catch(Exception e) {
             String message = "Couldn't reload application.\n" + e.getMessage();
-            alertButton.setAction(new AlertAction(e, message, null));
+            log.error(message, e);
             if (e instanceof IOException) {
               // remove selected element from the applications list
               locations.put("applications", list.replaceFirst(name + "(;|$)", 
""));
@@ -4604,7 +4589,7 @@
 
       } catch (UnsupportedEncodingException error) {
         String message = "The Character Encoding is not supported.";
-        alertButton.setAction(new AlertAction(error, message, null));
+        log.error(message, error);
       } finally {
         keywords = null;
       }
@@ -4664,13 +4649,6 @@
           actualURL.insert(insertPoint + 1, "gateVersion=" + 
gate.Main.version);
         }
 
-        Action[] actions = {
-          new AbstractAction("Show configuration") {
-            public void actionPerformed(ActionEvent e) {
-              optionsDialog.showDialog();
-              optionsDialog.dispose();
-        }}};
-
         String commandLine = Gate.getUserConfig().getString(
           MainFrame.class.getName()+".browsercommandline");
 
@@ -4708,7 +4686,7 @@
             String message = "Unable to determine the default browser.\n"
               + "Will use a Java browser. To use a custom command line\n"
               + "go to the Options menu then Configuration.";
-            alertButton.setAction(new AlertAction(null, message, actions));
+            log.info(message);
             // Java help browser
             displayJavaHelpBrowser(actualURL.toString());
             }}}}}
@@ -4732,7 +4710,7 @@
             String message = "Unable to call the custom browser command.\n" +
               "(" +  commandLine + ")\n\n" +
               "Please go to the Options menu then Configuration.";
-            alertButton.setAction(new AlertAction(error, message, actions));
+            log.error(message, error);
           }
 
         } else {
@@ -4761,7 +4739,7 @@
       helpFrame.setPage(new URL(urlString));
     } catch (IOException error) {
       String message = "Error when loading help page.";
-      alertButton.setAction(new AlertAction(error, message, null));
+      log.error(message, error);
       return;
     }
     helpFrame.setVisible(false);
@@ -5195,89 +5173,9 @@
       }
       catch(ResourceInstantiationException error) {
         String message = "Failed to instanciate the gazetteer editor.";
-        Action[] actions = {
-          new AbstractAction("Load plugins manager") {
-            public void actionPerformed(ActionEvent e) {
-              (new ManagePluginsAction()).actionPerformed(null);
-        }}};
-        alertButton.setAction(new AlertAction(error, message, actions));
+        log.error(message, error);
       }
     }// actionPerformed();
   }// class NewOntologyEditorAction
 
-  class AlertAction extends AbstractAction {
-    private Timer timer =
-      new java.util.Timer("MainFrame alert tooltip hide timer", true);
-
-    /**
-     * Action for the alert button that shows a message in a popup.
-     * A detailed dialog can be shown when the button or popup are clicked.
-     * Log the message and error as soon as the action is created.
-     * @param error can be null in case of info message.
-     * @param message text to be displayed in a popup and dialogue
-     * @param actions actions the user can choose in the dialogue
-     */
-    public AlertAction(Throwable error, String message, Action[] actions) {
-      if (error == null) {
-        log.info(message);
-      } else {
-        log.error(message, error);
-      }
-      String description = "<html>" + (error == null ?
-        "Important information:<br>" : "There was a problem:<br>") +
-        message.substring(0, Math.min(300, message.length()))
-          .replaceAll("(.{40,50}(?:\\b|\\.|/))", "$1<br>") + "</html>";
-      final int lines = description.split("<br>").length;
-      putValue(Action.SMALL_ICON, 
MainFrame.getIcon("crystal-clear-app-error"));
-      putValue(Action.SHORT_DESCRIPTION, description);
-
-      this.error = error;
-      this.message = message;
-      if (actions == null) {
-        this.actions = new Action[1];
-      } else {
-        this.actions = new Action[actions.length+1];
-        System.arraycopy(actions, 0, this.actions, 0, actions.length);
-      }
-      // add a 'search in mailing list' action
-      this.actions[this.actions.length-1] = new HelpMailingListAction(message);
-      // show for a few seconds a popup with the error message
-      SwingUtilities.invokeLater(new Runnable() {
-        public void run() {
-          if (!instance.isShowing()) { return; }
-          alertButton.setEnabled(true);
-          JToolTip toolTip = alertButton.createToolTip();
-          toolTip.setTipText(alertButton.getToolTipText());
-          PopupFactory popupFactory = PopupFactory.getSharedInstance();
-          final Popup popup = popupFactory.getPopup(alertButton, toolTip,
-            instance.getLocationOnScreen().x+instance.getWidth()/2-100,
-            
instance.getLocationOnScreen().y+instance.getHeight()-30-(lines*10));
-          toolTip.addMouseListener(new MouseAdapter() {
-            public void mouseClicked(MouseEvent e) {
-              popup.hide();
-              alertButton.doClick();
-            }
-          });
-          popup.show();
-          Date timeToRun = new Date(System.currentTimeMillis() + 4000);
-          timer.schedule(new TimerTask() {
-            public void run() {
-              SwingUtilities.invokeLater(new Runnable(){
-                public void run() {
-                  popup.hide(); // hide the tooltip after some time
-                }
-              });
-            }
-          }, timeToRun);
-        }
-      });
-    }
-    public void actionPerformed(ActionEvent e) {
-      ErrorDialog.show(error, message, instance, getIcon("root"), actions);
-    }
-    Throwable error;
-    String message;
-    Action[] actions;
-  }
-
 } // class MainFrame

Deleted: gate/trunk/src/gate/swing/ErrorDialog.java
===================================================================
--- gate/trunk/src/gate/swing/ErrorDialog.java  2012-01-04 17:12:46 UTC (rev 
14878)
+++ gate/trunk/src/gate/swing/ErrorDialog.java  2012-01-04 22:11:36 UTC (rev 
14879)
@@ -1,156 +0,0 @@
-/*
- *  Copyright (c) 1995-2010, The University of Sheffield. See the file
- *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
- *
- *  This file is part of GATE (see http://gate.ac.uk/), and is free
- *  software, licenced under the GNU Library General Public License,
- *  Version 2, June 1991 (in the distribution as file licence.html,
- *  and also available at http://gate.ac.uk/gate/licence.html).
- *
- *  Thomas Heitz, 02/19/2009
- *
- *  $Id$
- */
-package gate.swing;
-
-import gate.Main;
-
-import javax.swing.*;
-import java.awt.event.ActionEvent;
-import java.awt.*;
-import java.io.StringWriter;
-import java.io.PrintWriter;
-
-public class ErrorDialog extends JOptionPane {
-
-  public ErrorDialog(Object[] message, int errorMessage, int defaultOption,
-                     Icon icon, Object[] options, Object option) {
-    super(message, errorMessage, defaultOption, icon, options, option);
-  }
-
-  /**
-   * Display a user friendly error dialog with the possibility to show the
-   * stack trace and configuration and add actions as buttons.
-   *
-   * @param error exception that occurs, can be null; can contain newlines
-   * @param textMessage error message to display
-   * @param parentComponent determines the Frame in which the dialog is
-   *  displayed; if null, or if the parentComponent has no Frame, a default
-   *  Frame is used
-   * @param icon the icon to display in the dialog; null otherwise
-   * @param optionalActions optional actions that will be add as a button;
-   *  null otherwise
-   */
-  public static void show(Throwable error, String textMessage,
-                          Component parentComponent, Icon icon,
-                          Action[] optionalActions) {
-
-    if (textMessage == null) { textMessage = ""; }
-    final JDialog dialog;
-    String detailedMessage = "";
-
-    // add the error stack trace in a scrollable text area, hidden at start
-    if (error != null) {
-      detailedMessage += "<h2>Message</h2>";
-      detailedMessage += error.getMessage();
-      detailedMessage += "<h2>Stack trace</h2>";
-      StringWriter sw = new StringWriter();
-      error.printStackTrace(new PrintWriter(sw));
-      detailedMessage += sw.toString()
-        .replaceAll("(at |Caused by:)", "<strong>$1</strong> ")
-        .replaceAll("(\\([A-Za-z]+\\.java:[0-9])+\\)", "<strong>$1</strong>");
-    }
-    detailedMessage += "<h2>System configuration</h2>";
-    detailedMessage += "<strong>GATE Version</strong> = " + Main.version + 
"\n";
-    detailedMessage += "<strong>GATE Build</strong> = " + Main.build + "\n";
-    for (Object property : System.getProperties().keySet()) {
-      String propertyValue = System.getProperty((String)property);
-      if (((String)property).contains("path")) {
-        // add space after path separator to enable wrapping
-        propertyValue = propertyValue.replaceAll(":", ": ");
-      }
-      detailedMessage += "<strong>" + property + "</strong> = " +
-        propertyValue + '\n';
-    }
-    detailedMessage = detailedMessage.replace("\n", "<br>\n");
-    detailedMessage = detailedMessage.replace("\t", "&nbsp;&nbsp;");
-    JEditorPane messageArea = new JEditorPane("text/html", detailedMessage);
-    messageArea.setEditable(false);
-    messageArea.setMargin(new Insets(10, 10, 10 ,10));
-    final JScrollPane stackTracePane = new JScrollPane(messageArea);
-    stackTracePane.setVisible(false);
-
-    // put the message in an horizontal box
-    // with a toggle button to show/hide the stack trace
-    Box messageBox = Box.createHorizontalBox();
-    messageBox.add(new JLabel(textMessage.startsWith("<html>") ?
-      textMessage : "<html><body>" +
-      textMessage.replaceAll("\n", "<br>") + "</body></html>"));
-    messageBox.add(Box.createHorizontalStrut(5));
-    final JToggleButton toggleButton = new JToggleButton();
-    toggleButton.setToolTipText(
-      "Show the error stack trace and system configuration");
-    toggleButton.setMargin(new Insets(2, 4, 2, 2));
-    messageBox.add(toggleButton);
-    messageBox.add(Box.createHorizontalGlue());
-
-    // add new buttons from the optionalActions parameter
-    Object[] options =
-      new Object[(optionalActions == null) ? 1 : optionalActions.length + 1];
-    if (optionalActions != null) {
-      for (int i = 0; i < optionalActions.length; i++) {
-        options[i] = optionalActions[i].getValue(Action.NAME);
-      }
-    }
-    // add the cancel button
-    options[options.length-1] = "Let it be";
-    Object[] message = { messageBox, stackTracePane };
-
-    // create the dialog
-    ErrorDialog pane = new ErrorDialog(message, JOptionPane.ERROR_MESSAGE,
-      JOptionPane.DEFAULT_OPTION, icon, options, options[options.length-1]);
-    dialog = pane.createDialog(parentComponent,
-      "Gate has encountered a little problem...");
-    dialog.setResizable(true);
-
-    // add a listener for the Detail button
-    toggleButton.setAction(new AbstractAction("Detail") {
-      public void actionPerformed(ActionEvent e) {
-        SwingUtilities.invokeLater(new Runnable() {
-          public void run() {
-            stackTracePane.setVisible(toggleButton.isSelected());
-            if (toggleButton.isSelected()) {
-              Dimension screenSize =
-                Toolkit.getDefaultToolkit().getScreenSize();
-              dialog.setBounds(
-                (screenSize.width-700)/2, (screenSize.height-500)/2, 700, 500);
-            } else {
-              dialog.pack();
-            }
-          }
-        });
-      }
-    });
-
-    // show the dialog
-    dialog.pack();
-    dialog.setVisible(true);
-
-    // do the user selected action
-    Object choice = pane.getValue();
-    if (choice == null
-     || choice.equals("Let it be")
-     || optionalActions == null) {
-      dialog.dispose();
-      return;
-    }
-    for (int i = 0; i < optionalActions.length; i++) {
-      if (options[i].equals(choice)) {
-        optionalActions[i].actionPerformed(null);
-        pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
-        break;
-      }
-    }
-  }
-
-}

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Ridiculously easy VDI. With Citrix VDI-in-a-Box, you don't need a complex
infrastructure or vast IT resources to deliver seamless, secure access to
virtual desktops. With this all-in-one solution, easily deploy virtual 
desktops for less than the cost of PCs and save 60% on VDI infrastructure 
costs. Try it free! http://p.sf.net/sfu/Citrix-VDIinabox
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to