Author: slotia
Date: 2009-03-20 08:35:52 -0700 (Fri, 20 Mar 2009)
New Revision: 16315

Modified:
   
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/task/SwingTaskManager.java
   
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/task/TaskDialog.java
Log:
Updated SwingTaskManager such that it uses java.util.concurrent.ExecutorService 
to run Tasks instead of manually creating threads.


Modified: 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/task/SwingTaskManager.java
===================================================================
--- 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/task/SwingTaskManager.java
    2009-03-19 17:28:24 UTC (rev 16314)
+++ 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/task/SwingTaskManager.java
    2009-03-20 15:35:52 UTC (rev 16315)
@@ -1,21 +1,22 @@
 package org.cytoscape.work.internal.task;
 
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import javax.swing.event.*;
-
 import org.cytoscape.work.TaskManager;
 import org.cytoscape.work.Task;
 import org.cytoscape.work.TaskMonitor;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadFactory;
 
+import java.awt.Frame;
+
 /**
  * Uses Swing components to create a user interface for the <code>Task</code>.
  *
- * @author Samad Lotia
+ * This will not work if the application is running in headless mode.
  */
 public class SwingTaskManager implements TaskManager
 {
@@ -28,21 +29,74 @@
         * period of time before showing the dialog. This way, short lived
         * <code>Task</code>s won't have a dialog box.
         */
-       static final int DELAY_IN_MILLISECONDS_BEFORE_SHOWING_DIALOG = 1000;
+       static final long DELAY_BEFORE_SHOWING_DIALOG = 1;
+
+       /**
+        * The time unit of <code>DELAY_BEFORE_SHOWING_DIALOG</code>.
+        */
+       static final TimeUnit DELAY_TIMEUNIT = TimeUnit.SECONDS;
+
+       /**
+        * Used for calling <code>Task.run()</code>.
+        */
+       ExecutorService taskExecutorService;
+
+       /**
+        * Used for opening dialogs after a specific amount of delay.
+        */
+       ScheduledExecutorService timedDialogExecutorService;
+
+       /**
+        * Used for calling <code>Task.cancel()</code>.
+        * <code>Task.cancel()</code> must be called in a different
+        * thread from the thread running Swing. This is done to
+        * prevent Swing from freezing if <code>Task.cancel()</code>
+        * takes too long to finish.
+        *
+        * This can be the same as <code>taskExecutorService</code>.
+        */
+       ExecutorService cancelExecutorService;
+
        Frame owner;
 
+       /**
+        * Construct with default behavior.
+        * <ul>
+        * <li><code>owner</code> is set to null.</li>
+        * <li><code>taskExecutorService</code> is a cached thread pool.</li>
+        * <li><code>timedExecutorService</code> is a single thread 
executor.</li>
+        * <li><code>cancelExecutorService</code> is the same as 
<code>taskExecutorService</code>.</li>
+        * </ul>
+        */
        public SwingTaskManager()
        {
-               this(null);
+               owner = null;
+               taskExecutorService = Executors.newCachedThreadPool();
+               addShutdownHook(taskExecutorService);
+               timedDialogExecutorService = 
Executors.newSingleThreadScheduledExecutor();
+               addShutdownHook(timedDialogExecutorService);
+               cancelExecutorService = taskExecutorService;
        }
 
        /**
-        * @param owner JDialogs created by this object
-        * will have its owner set to this parameter.
+        * Adds a shutdown hook to the JVM that shuts down an
+        * <code>ExecutorService</code>. <code>ExecutorService</code>s
+        * need to be told to shut down, otherwise the JVM won't 
+        * cleanly terminate.
         */
-       public SwingTaskManager(Frame owner)
+       void addShutdownHook(final ExecutorService serviceToShutdown)
        {
-               setOwner(owner);
+               // Used to create a thread that is executed by the shutdown hook
+               ThreadFactory threadFactory = Executors.defaultThreadFactory();
+
+               Runnable shutdownHook = new Runnable()
+               {
+                       public void run()
+                       {
+                               serviceToShutdown.shutdownNow();
+                       }
+               };
+               
Runtime.getRuntime().addShutdownHook(threadFactory.newThread(shutdownHook));
        }
 
        /**
@@ -56,8 +110,8 @@
 
        public void execute(final Task task)
        {
-               final SwingTaskMonitor taskMonitor = new SwingTaskMonitor(task, 
owner);
-               final Thread executor = new Thread(new Runnable()
+               final SwingTaskMonitor taskMonitor = new SwingTaskMonitor(task, 
cancelExecutorService, owner);
+               final Runnable executor = new Runnable()
                {
                        public void run()
                        {
@@ -72,52 +126,49 @@
                                if (taskMonitor.isOpened() && 
!taskMonitor.isShowingException())
                                        taskMonitor.close();
                        }
-               });
+               };
+               final Future<?> executorFuture = 
taskExecutorService.submit(executor);
 
-               final ActionListener delayedDisplayer = new ActionListener()
+               final Runnable timedOpen = new Runnable()
                {
-                       public void actionPerformed(ActionEvent e)
+                       public void run()
                        {
-                               if (executor.getState() != 
Thread.State.TERMINATED)
+                               if (!(executorFuture.isDone() || 
executorFuture.isCancelled()))
                                        taskMonitor.open();
                        }
                };
-               Timer timer = new 
Timer(DELAY_IN_MILLISECONDS_BEFORE_SHOWING_DIALOG, delayedDisplayer);
-               timer.setRepeats(false);
-
-               executor.start();
-               timer.start();
+               timedDialogExecutorService.schedule(timedOpen, 
DELAY_BEFORE_SHOWING_DIALOG, DELAY_TIMEUNIT);
        }
 }
 
 class SwingTaskMonitor implements TaskMonitor
 {
-       static final String DEFAULT_TASK_TITLE = "Untitled Task";
-       static final String DEFAULT_STATUS_MESSAGE = "";
-
        final Task              task;
+       final ExecutorService   cancelExecutorService;
        final Frame             owner;
 
        TaskDialog      dialog                  = null;
-       String          title                   = DEFAULT_TASK_TITLE;
-       String          statusMessage           = DEFAULT_STATUS_MESSAGE;
+       String          title                   = null;
+       String          statusMessage           = null;
        int             progress                = 0;
 
-       public SwingTaskMonitor(Task task, Frame owner)
+       public SwingTaskMonitor(Task task, ExecutorService 
cancelExecutorService, Frame owner)
        {
                this.task = task;
+               this.cancelExecutorService = cancelExecutorService;
                this.owner = owner;
        }
 
-       // Why is open() and setException() synchronized?
-       // It is possible that open() can be called concurrently
-       // if an exception is thrown immediately by a Task,
-       // creating an undefined state in SwingTaskMonitor.
        public synchronized void open()
        {
+               if (dialog != null)
+                       return;
+
                dialog = new TaskDialog(owner, this);
-               dialog.setTaskTitle(title);
-               dialog.setStatus(statusMessage);
+               if (title != null)
+                       dialog.setTaskTitle(title);
+               if (statusMessage != null)
+                       dialog.setStatus(statusMessage);
                if (progress > 0)
                        dialog.setPercentCompleted(progress);
        }
@@ -133,34 +184,17 @@
 
        public void cancel()
        {
-               // The Close button has two possible states that we need
-               // to take into account:
-               // 1. Cancel: the user has requested to cancel the task
-               // 2. Close:  the Task threw an exception, and the
-               //            dialog should close
-               
-               if (isShowingException())
-                       close();
-               else
+               // we issue the Task's cancel method in its own thread
+               // to prevent Swing from freezing if the Tasks's cancel
+               // method takes too long to finish
+               Runnable cancel = new Runnable()
                {
-                       // we need to inform the Task to cancel
-
-                       // change the UI to show that we are cancelling the Task
-                       //closeButton.setEnabled(false);
-                       //closeButton.setText("Canceling...");
-
-                       // we issue the Task's cancel method in its own thread
-                       // to prevent Swing from freezing if the Tasks's cancel
-                       // method takes too long to finish
-                       Thread cancelThread = new Thread(new Runnable()
+                       public void run()
                        {
-                               public void run()
-                               {
-                                       task.cancel();
-                               }
-                       });
-                       cancelThread.start();
-               }
+                               task.cancel();
+                       }
+               };
+               cancelExecutorService.submit(cancel);
        }
 
        public void setTitle(String title)
@@ -179,15 +213,11 @@
 
        public void setProgress(double progress)
        {
-               this.progress = (int) (progress * 100);
+               this.progress = (int) Math.floor(progress * 100);
                if (dialog != null)
                        dialog.setPercentCompleted(this.progress);
        }
 
-       // Why is open() and setException() synchronized?
-       // It is possible that open() can be called concurrently
-       // if an exception is thrown immediately by a Task,
-       // creating an undefined state in SwingTaskMonitor.
        public synchronized void showException(Exception exception)
        {
                // force the dialog box to be created if

Modified: 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/task/TaskDialog.java
===================================================================
--- 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/task/TaskDialog.java
  2009-03-19 17:28:24 UTC (rev 16314)
+++ 
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/task/TaskDialog.java
  2009-03-20 15:35:52 UTC (rev 16315)
@@ -36,106 +36,124 @@
 
 package org.cytoscape.work.internal.task;
 
-import org.cytoscape.work.internal.task.StringUtils;
-
-import javax.swing.*;
-import javax.swing.border.EmptyBorder;
 import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
+import java.awt.event.*;
+import javax.swing.*;
+import javax.swing.border.*;
 import java.util.Date;
 
+class TaskDialog extends JDialog
+{
+       /**
+        * How much time between updating the "Estimated Time Remaining"
+        * field, stored in <code>timeLabel</code>.
+        */
+       static final int TIME_UPDATE_INTERVAL_IN_MILLISECONDS   = 1000;
 
-/**
- * Common UI element for visually monitoring task progress.
- */
-class TaskDialog extends JDialog implements ActionListener {
-       static final long serialVersionUID = 333614801L;
-       static final int TIME_INTERVAL = 500;
+       /**
+        * Description and status messages are stored in
+        * <code>JTextArea</code>s; this specifies the number of
+        * columns <code>JTextArea</code>s should have.
+        * This value has a big impact on the size of the dialog.
+        */
+       static final int TEXT_AREA_COLUMNS                      = 30;
 
-       final SwingTaskMonitor parent;
+       /**
+        * Constant used for <code>CardLayout.show()</code> and
+        * <code>CardLayout.add()</code> to switch between normal
+        * mode and exception mode.
+        */
+       static final String NORMAL_MODE                         = "normal";
 
-       JProgressBar    pBar;
-       JLabel          descriptionValue;
-       JTextArea       statusValue;
-       JLabel          statusLabel;
-       JLabel          timeLabel;
-       Timer           timer;
-       JButton         closeButton;
-       JPanel          progressPanel;
+       /**
+        * Constant used for <code>CardLayout.show()</code> and
+        * <code>CardLayout.add()</code> to switch between normal
+        * mode and exception mode.
+        */
+       static final String EXCEPTION_MODE                      = "exception";
 
-       Date            startTime;
-       boolean         haltRequested = false;
-       boolean         errorOccurred = false;
-
        /**
-        * Constructor.
+        * If the progress bar is indeterminate, the string format to use
+        * for <code>timeLabel</code>.
         */
-       public TaskDialog(Frame frame, SwingTaskMonitor parent) {
-               super(frame, false);
-               this.parent = parent;
+       static final String ELAPSED_FORMAT                      = "%s elapsed";
+       
+       /**
+        * If the progress bar is determinate, the string format to use
+        * for <code>timeLabel</code>.
+        */
+       static final String ELAPSED_AND_REMAINING_FORMAT        = "%s elapsed, 
%s remaining";
 
-               Container container = this.getContentPane();
-               container.setLayout(new BorderLayout());
-               progressPanel = new JPanel(new GridBagLayout());
-               progressPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
+       static final String CANCEL_LABEL                        = "   Cancel   
";
+       static final String CANCELLING_LABEL                    = "   
Cancelling...   ";
+       static final String CLOSE_LABEL                         = "   Close   ";
 
-               int y = 0;
-               addLabel("Description:  ", progressPanel, 0, y, 
GridBagConstraints.NORTHEAST, true);
-               descriptionValue = addLabel("", progressPanel, 1, y++, 
GridBagConstraints.NORTHWEST, true);
+       // State variables
+       boolean         haltRequested                   = false;
+       boolean         errorOccurred                   = false;
+       SwingTaskMonitor parentTaskMonitor              = null;
 
-               addLabel("Status:  ", progressPanel, 0, y, 
GridBagConstraints.NORTHEAST, true);
-               statusValue = addTextArea("", progressPanel, 1, y++, 
GridBagConstraints.NORTHWEST, true);
+       // Swing components
+       JTextArea       descriptionLabel                = new JTextArea();
+       JTextArea       descriptionLabel2               = new JTextArea();
+       JTextArea       statusLabel                     = new JTextArea();
+       JProgressBar    progressBar                     = new JProgressBar();
+       JTextArea       timeLabel                       = new JTextArea();
+       JButton         cancelButton                    = new 
JButton(CANCEL_LABEL);
+       JButton         closeButton                     = new 
JButton(CLOSE_LABEL);
+       JPanel          exceptionPanel                  = new JPanel();
 
-               addLabel("Progress:  ", progressPanel, 0, y, 
GridBagConstraints.NORTHEAST, true);
-               initProgressBar(progressPanel, y++);
+       // Specific for the timer
+       Timer           timer                           = null;
+       Date            startTime                       = new Date();
 
-               timeLabel = addLabel("", progressPanel, 1, y++, 
GridBagConstraints.NORTHWEST, true);
-
-               closeButton = addButton("   Cancel   ", progressPanel, 1, y, 
GridBagConstraints.NORTHEAST, true);
-               closeButton.addActionListener(this);
-
-               container.add(progressPanel, BorderLayout.PAGE_START);
-               //createFooter(container);
-
+       public TaskDialog(Frame parentFrame, SwingTaskMonitor parentTaskMonitor)
+       {
+               super(parentFrame);
+               this.parentTaskMonitor = parentTaskMonitor;
+               initComponents();
                initTimer();
-
-               //  Disable close operation until task is done.
-               this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
-               this.setResizable(false);
-               this.pack();
-               this.setVisible(true);
-
-               //  Center component relative to parent component
-               //  or relative to user's screen.
-               if (frame != null)
-                       setLocationRelativeTo(frame);
+               initLayout();
        }
 
-       public void setTaskTitle(String taskTitle)
+       public void setTaskTitle(final String taskTitle)
        {
-               setTitle(taskTitle);
-               
descriptionValue.setText(StringUtils.truncateOrPadString(taskTitle));
+               SwingUtilities.invokeLater(new Runnable()
+               {
+                       public void run() {
+                               setTitle(taskTitle);
+                               
//descriptionLabel.setText(StringUtils.truncateOrPadString(taskTitle));
+                               
//descriptionLabel2.setText(StringUtils.truncateOrPadString(taskTitle));
+                               descriptionLabel.setText(taskTitle);
+                               descriptionLabel2.setText(taskTitle);
+                               pack();
+                       }
+               });
        }
 
-       public void setPercentCompleted(final int percent) {
-               if (haltRequested || errorOccurred) return;
+       public void setPercentCompleted(final int percent)
+       {
+               if (haltRequested) return;
 
-               if (percent != pBar.getValue())
+               SwingUtilities.invokeLater(new Runnable()
                {
-                       SwingUtilities.invokeLater(new Runnable()
-                       {
-                               public void run() {
-                                       if (pBar.isIndeterminate()) {
-                                               pBar.setIndeterminate(false);
+                       public void run() {
+                               if (percent < 0)
+                               {
+                                       if (!progressBar.isIndeterminate()) {
+                                               
progressBar.setIndeterminate(true);
                                        }
+                               }
+                               else
+                               {
+                                       if (progressBar.isIndeterminate()) {
+                                               
progressBar.setIndeterminate(false);
+                                       }
 
-                                       pBar.setValue(percent);
+                                       progressBar.setValue(percent);
                                }
-                       });
-               }
+                       }
+               });
        }
 
        public void setException(final Throwable t, final String 
userErrorMessage)
@@ -145,24 +163,22 @@
                SwingUtilities.invokeLater(new Runnable()
                {
                        public void run() {
-                           closeButton.setEnabled(true);
-                           closeButton.setText("   Close   ");
-                           statusValue.setEnabled(false);
-                           progressPanel.setEnabled(false);
+                               //  Create Error Panel
+                               ErrorPanel errorPanel = new 
ErrorPanel(TaskDialog.this, t, userErrorMessage, t.getMessage());
+                               exceptionPanel.add(errorPanel);
+                               CardLayout cardLayout = (CardLayout) 
getContentPane().getLayout();
+                               cardLayout.show(getContentPane(), 
EXCEPTION_MODE);
+                               pack();
 
-                           //  Create Error Panel
-                           JPanel errorPanel = new ErrorPanel(TaskDialog.this, 
t, userErrorMessage, null);
-                           getContentPane().add(errorPanel, 
BorderLayout.CENTER);
-                           pack();
+                               //  Make sure TaskDialog is actually visible
+                               if (!TaskDialog.this.isShowing()) {
+                                       TaskDialog.this.setVisible(true);
+                               }
+                               setResizable(true);
+                       }
+               });
+       }
 
-                           //  Make sure JTask is actually visible
-                           if (!TaskDialog.this.isShowing()) {
-                               TaskDialog.this.setVisible(true);
-                           }
-               }
-           });
-    }
-
        /**
         * Sets the Status Message.
         * Called by a child task thread.
@@ -174,15 +190,25 @@
                if (!haltRequested) {
                        //  Update the UI
                        SwingUtilities.invokeLater(new Runnable() {
-                                       public void run() {
-                                               statusValue.setVisible(true);
-                                               
statusValue.setText(StringUtils.truncateOrPadString(message));
-                                               pack();
-                                       }
-                               });
+                               public void run() {
+                                       
//statusLabel.setText(StringUtils.truncateOrPadString(message));
+                                       statusLabel.setText(message);
+                                       pack();
+                               }
+                       });
                }
        }
 
+       public void setTimeMessage(final String message)
+       {
+               //  Update the UI
+               SwingUtilities.invokeLater(new Runnable() {
+                       public void run() {
+                               timeLabel.setText(message);
+                       }
+               });
+       }
+
        /**
         * Returns true if Task Has Encountered An Error.
         *
@@ -201,168 +227,137 @@
                return haltRequested;
        }
 
-       /**
-        * Creates Footer with Close, Cancel Buttons.
-        *
-        * @param container Container Object.
-        */
-       private void createFooter(Container container) {
-       /*
-               JPanel footer = new JPanel();
-               footer.setBorder(new EmptyBorder(5, 5, 5, 5));
-               footer.setLayout(new BoxLayout(footer, BoxLayout.Y_AXIS));
-               closeButton = new JButton("    Cancel    ");
-               closeButton.addActionListener(this);
-               footer.add(closeButton);
-               footer.add(Box.createHorizontalGlue());
+       synchronized void cancel()
+       {
+               if (haltRequested)
+                       return;
 
-               container.add(footer, BorderLayout.EAST);
-               */
+               haltRequested = true;
+               cancelButton.setText(CANCELLING_LABEL);
+               cancelButton.setEnabled(false);
+               progressBar.setIndeterminate(true);
+               parentTaskMonitor.cancel();
        }
 
-       /**
-        * Initializes the JProgressBar.
-        *
-        * @param progressPanel JPanel Object.
-        */
-       private void initProgressBar(JPanel progressPanel, int y) {
-               GridBagConstraints c = new GridBagConstraints();
-               pBar = new JProgressBar();
-               pBar.setIndeterminate(true);
-               pBar.setMaximum(100);
-               pBar.setValue(0);
-               pBar.setBorder(new EmptyBorder(5, 0, 5, 0));
-               pBar.setDoubleBuffered(true);
-               c.gridx = 1;
-               c.gridy = y;
-               c.fill = GridBagConstraints.HORIZONTAL;
-               progressPanel.add(pBar, c);
+       synchronized void close()
+       {
+               stopTimer();
+               parentTaskMonitor.close();
        }
 
-       /**
-        * Add New Label to Specified JPanel.
-        *
-        * @param text  Label Text.
-        * @param panel Container Panel.
-        * @param gridx X Location.
-        * @param gridy Y Location.
-        * @return JLabel Object.
-        */
-       private JLabel addLabel(String text, JPanel panel, int gridx, int 
gridy, int alignment,
-                               boolean addToPanel) {
-               JLabel label = new JLabel(text);
-               label.setHorizontalAlignment(JLabel.LEFT);
-               label.setBorder(new EmptyBorder(5, 5, 5, 5));
-               label.setFont(new Font(null, Font.PLAIN, 13));
+       void initComponents()
+       {
+               initTextArea(descriptionLabel);
+               initTextArea(descriptionLabel2);
+               initTextArea(statusLabel);
+               initTextArea(timeLabel);
+               closeButton.addActionListener(new ActionListener()
+               {
+                       public void actionPerformed(ActionEvent e)
+                       {
+                               close();
+                       }
+               });
 
-               GridBagConstraints c = new GridBagConstraints();
-               c.gridx = gridx;
-               c.gridy = gridy;
-               c.anchor = alignment;
+               cancelButton.addActionListener(new ActionListener()
+               {
+                       public void actionPerformed(ActionEvent e)
+                       {
+                               cancel();
+                       }
+               });
 
-               if (addToPanel) {
-                       panel.add(label, c);
-               }
+               setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
+               addWindowListener(new WindowAdapter()
+               {
+                       public void windowClosing(WindowEvent e)
+                       {
+                               cancel();
+                       }
+               });
+       }
 
+       JLabel initLabel(JLabel label)
+       {
+               label.setHorizontalAlignment(JLabel.LEFT);
+               label.setFont(new Font(null, Font.PLAIN, 13));
                return label;
        }
 
-       /**
-        * Add New TextArea to Specified JPanel.
-        *
-        * @param text  Label Text.
-        * @param panel Container Panel.
-        * @param gridx X Location.
-        * @param gridy Y Location.
-        * @return JLabel Object.
-        */
-       private JTextArea addTextArea(String text, JPanel panel, int gridx, int 
gridy, int alignment,
-                                     boolean addToPanel) {
-               JTextArea textArea = new JTextArea(text, 1, 25);
+       JTextArea initTextArea(JTextArea textArea)
+       {
                textArea.setEditable(false);
                textArea.setLineWrap(true);
                textArea.setWrapStyleWord(true);
-               textArea.setBorder(new EmptyBorder(5, 5, 5, 5));
+               textArea.setColumns(TEXT_AREA_COLUMNS);
+               //textArea.setBorder(new EmptyBorder(5, 5, 5, 5));
 
                textArea.setBackground((Color) 
UIManager.get("Label.background"));
                textArea.setForeground((Color) 
UIManager.get("Label.foreground"));
                textArea.setFont(new Font(null, Font.PLAIN, 13));
-
-               GridBagConstraints c = new GridBagConstraints();
-               c.gridx = gridx;
-               c.gridy = gridy;
-               c.anchor = alignment;
-
-               if (addToPanel) {
-                       panel.add(textArea, c);
-               }
-
                return textArea;
        }
 
-       private JButton addButton(String text, JPanel parentPanel, int gridx, 
int gridy, int alignment,
-                                     boolean addToPanel) {
-               JButton button = new JButton(text);
-               JPanel panel = new JPanel();
-               panel.setBorder(new EmptyBorder(5, 5, 5, 5));
-               panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
-               panel.add(button);
+       void initLayout()
+       {
+               getContentPane().setLayout(new CardLayout());
+               JPanel panel1 = new JPanel(new GridBagLayout());
+               JLabel element0 = initLabel(new JLabel("Description: "));
+               panel1.add(element0, new GridBagConstraints(0, 0, 1, 1, 0, 0, 
GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(10, 10, 0, 
0), 0, 0));
+               panel1.add(descriptionLabel, new GridBagConstraints(1, 0, 1, 1, 
1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new 
Insets(10, 10, 0, 10), 0, 0));
+               JLabel element1 = initLabel(new JLabel("Status: "));
+               panel1.add(element1, new GridBagConstraints(0, 1, 1, 1, 0, 0, 
GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(10, 10, 0, 
0), 0, 0));
+               panel1.add(statusLabel, new GridBagConstraints(1, 1, 1, 1, 1, 
0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(10, 
10, 0, 10), 0, 0));
+               JLabel element2 = initLabel(new JLabel("Progress: "));
+               panel1.add(element2, new GridBagConstraints(0, 2, 1, 1, 0, 0, 
GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(10, 10, 0, 0), 0, 
0));
+               panel1.add(progressBar, new GridBagConstraints(1, 2, 1, 1, 1, 
0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 
0, 10), 0, 0));
+               panel1.add(timeLabel, new GridBagConstraints(1, 3, 1, 1, 1, 0, 
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 0, 
10), 0, 0));
+               JSeparator element3 = new JSeparator();
+               panel1.add(element3, new GridBagConstraints(0, 4, 2, 1, 1, 0, 
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 0, 
10), 0, 0));
+               panel1.add(cancelButton, new GridBagConstraints(0, 5, 2, 1, 1, 
1, GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 10, 
10), 0, 0));
+               getContentPane().add(panel1, NORMAL_MODE);
 
-               GridBagConstraints c = new GridBagConstraints();
-               c.gridx = gridx;
-               c.gridy = gridy;
-               c.anchor = alignment;
+               JPanel panel2 = new JPanel(new GridBagLayout());
+               JLabel element4 = initLabel(new JLabel("Description: "));
+               panel2.add(element4, new GridBagConstraints(0, 0, 1, 1, 0, 0, 
GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(10, 10, 0, 
0), 0, 0));
+               panel2.add(descriptionLabel2, new GridBagConstraints(1, 0, 1, 
1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new 
Insets(10, 10, 0, 0), 0, 0));
+               panel2.add(exceptionPanel, new GridBagConstraints(0, 1, 2, 1, 
1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10, 10, 0, 
10), 0, 0));
+               JSeparator element6 = new JSeparator();
+               panel2.add(element6, new GridBagConstraints(0, 2, 2, 1, 1, 0, 
GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(10, 10, 0, 
10), 0, 0));
+               panel2.add(closeButton, new GridBagConstraints(0, 3, 2, 1, 1, 
0, GridBagConstraints.SOUTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 10, 
10), 0, 0));
+               getContentPane().add(panel2, EXCEPTION_MODE);
 
-               if (addToPanel) {
-                       parentPanel.add(panel, c);
-               }
+               exceptionPanel.setLayout(new GridLayout(1,1));
 
-               return button;
+               setResizable(false);
+               pack();
+               setVisible(true);
        }
 
-       /**
-        * Capture All Action Events.
-        * This  method is called by the Timer and by User Buttons.
-        * This method is called on the Swing Event Dispatch Thread.
-        *
-        * @param e Timer Event.
-        */
-       public void actionPerformed(ActionEvent e) {
-               stopTimer();
-               if (!errorOccurred)
-               {
-                       this.haltRequested = true;
-                       closeButton.setEnabled(false);
-                       closeButton.setText("  Cancelling...  ");
-               }
-               parent.cancel();
-       }
 
        /**
         * Initialize the Timer Object.
         * Note that timer events are sent to the Swing Event-Dispatch Thread.
         */
-       private void initTimer() {
-               //  Record Start Timestamp
-               startTime = new Date();
-
+       void initTimer() {
                //  Create Auto-Timer
-               timer = new Timer(TIME_INTERVAL,
+               timer = new Timer(TIME_UPDATE_INTERVAL_IN_MILLISECONDS,
                                  new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                        Date currentTime = new Date();
                                        long timeElapsed = 
currentTime.getTime() - startTime.getTime();
                                        String timeElapsedString = 
StringUtils.getTimeString(timeElapsed);
-                                       if (!pBar.isIndeterminate() && 
pBar.getValue() != 0)
+                                       if (!progressBar.isIndeterminate() && 
progressBar.getValue() != 0)
                                        {
-                                               long timeRemaining = (long) 
((100.0 / pBar.getValue() - 1.0) * timeElapsed);
+                                               long timeRemaining = (long) 
((100.0 / progressBar.getValue() - 1.0) * timeElapsed);
                                                String timeRemainingString = 
StringUtils.getTimeString(timeRemaining);
-                                               
timeLabel.setText(String.format("%s elapsed, %s remaining", timeElapsedString, 
timeRemainingString));
+                                               
timeLabel.setText(String.format(ELAPSED_AND_REMAINING_FORMAT, 
timeElapsedString, timeRemainingString));
                                        }
                                        else
                                        {
-                                               
timeLabel.setText(String.format("%s elapsed", timeElapsedString));
+                                               
timeLabel.setText(String.format(ELAPSED_FORMAT, timeElapsedString));
                                        }
+                                       pack();
                                }
                        });
                timer.start();
@@ -371,7 +366,7 @@
        /**
         * Stops the Internal Timer.
         */
-       private void stopTimer() {
+       void stopTimer() {
                if ((timer != null) && timer.isRunning()) {
                        timer.stop();
                }


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to