Changeset 531


Ignore:
Timestamp:
10/12/05 19:26:45 (15 years ago)
Author:
curtis
Message:

Initial implementation of streamlined VisBio interface with dedicated
background tasks panel for reporting status of multiple simultaneous tasks.

Location:
trunk/loci/visbio
Files:
3 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/visbio/ControlPanel.java

    r465 r531  
    2626import java.awt.BorderLayout; 
    2727import javax.swing.JPanel; 
    28 import javax.swing.JScrollPane; 
    29 import loci.visbio.util.SwingUtil; 
    3028 
    3129/** ControlPanel is the superclass of all control panel types. */ 
    32 public class ControlPanel extends JScrollPane { 
     30public class ControlPanel extends JPanel { 
    3331 
    3432  // -- Fields -- 
     
    4341  protected String tip; 
    4442 
    45   /** Panel for placing controls. */ 
    46   protected JPanel controls; 
    47  
    4843 
    4944  // -- Constructor -- 
     
    5146  /** Constructs a control panel. */ 
    5247  public ControlPanel(LogicManager logic, String name, String tip) { 
    53     super(new JPanel()); 
     48    super(); 
    5449    lm = logic; 
    5550    this.name = name; 
    5651    this.tip = tip; 
    57     controls = (JPanel) getViewport().getView(); 
    58     controls.setLayout(new BorderLayout()); 
    59     SwingUtil.configureScrollPane(this); 
     52    setLayout(new BorderLayout()); 
    6053  } 
    6154 
    6255 
    6356  // -- ControlPanel API methods -- 
    64  
    65   /** 
    66    * Enlarges this control panel to its preferred 
    67    * width and/or height if it is too small. 
    68    */ 
    69   public void repack() { 
    70     PanelManager pm = (PanelManager) 
    71       lm.getVisBio().getManager(PanelManager.class); 
    72     pm.repack(this); 
    73   } 
    7457 
    7558  /** Gets control panel's logic manager. */ 
  • trunk/loci/visbio/PanelManager.java

    r465 r531  
    2424package loci.visbio; 
    2525 
     26import com.jgoodies.forms.builder.PanelBuilder; 
     27import com.jgoodies.forms.layout.CellConstraints; 
     28import com.jgoodies.forms.layout.FormLayout; 
     29import java.awt.Dimension; 
     30import java.awt.Point; 
     31import java.util.Arrays; 
    2632import java.util.Vector; 
    2733import javax.swing.*; 
    2834import loci.visbio.help.HelpManager; 
    29 import loci.visbio.util.SwingUtil; 
    3035 
    3136/** PanelManager is the manager encapsulating VisBio's control panel logic. */ 
     
    3540 
    3641  /** Control panels. */ 
    37   private Vector panels; 
     42  private Vector panels = new Vector(); 
    3843 
    39   /** Tabbed pane containing control panels. */ 
    40   private JTabbedPane tabs; 
     44  /** (X, Y) coordinates for each control panel. */ 
     45  private Vector coords = new Vector(); 
     46 
     47  /** Width and height for each control panel. */ 
     48  private Vector sizes = new Vector(); 
     49 
     50  /** Column string for each control panel. */ 
     51  private Vector colStrings = new Vector(); 
     52 
     53  /** Row string for each control panel. */ 
     54  private Vector rowStrings = new Vector(); 
     55 
     56  /** Number of rows in panel layout. */ 
     57  private int numRows = 0; 
     58 
     59  /** Number of columns in panel layout. */ 
     60  private int numCols = 0; 
     61 
     62  /** Pane containing control panels. */ 
     63  private JPanel pane; 
    4164 
    4265 
     
    5073 
    5174  /** Adds a new control panel. */ 
    52   public void addPanel(ControlPanel cpl) { 
    53     String name = cpl.getName(); 
    54  
    55     // create control panel containers 
    56     JFrame w = new JFrame(name); 
    57     WindowManager wm = (WindowManager) bio.getManager(WindowManager.class); 
    58     wm.addWindow(w); 
    59     panels.add(cpl); 
    60  
    61     tabs.addTab(name, null, cpl, cpl.getTip()); 
    62  
    63     bio.generateEvent(this, "add " + name + " panel", false); 
     75  public void addPanel(ControlPanel cpl, int x, int y, int w, int h) { 
     76    addPanel(cpl, x, y, w, h, null, null); 
    6477  } 
    6578 
    66   /** 
    67    * Enlarges a control panel to its preferred width 
    68    * and/or height if it is too small. 
    69    */ 
    70   public void repack(ControlPanel cpl) { 
    71     int ndx = panels.indexOf(cpl); 
    72     if (ndx < 0) return; 
    73     SwingUtil.repack(bio); 
     79  /** Adds a new control panel. */ 
     80  public void addPanel(ControlPanel cpl, int x, int y, int w, int h, 
     81    String colString, String rowString) 
     82  { 
     83    panels.add(cpl); 
     84    int xx = 2 * x + 1; 
     85    int yy = 4 * y + 1; 
     86    int ww = w; 
     87    int hh = 4 * h - 3; 
     88    if (xx + ww - 1 > numCols) numCols = xx + ww - 1; 
     89    if (yy + hh + 1 > numRows) numRows = yy + hh + 1; 
     90    coords.add(new Point(xx, yy)); 
     91    sizes.add(new Dimension(ww, hh)); 
     92    colStrings.add(colString == null ? "pref:grow" : colString); 
     93    rowStrings.add(rowString == null ? "pref:grow" : rowString); 
     94    bio.generateEvent(this, "add " + cpl.getName() + " panel", false); 
    7495  } 
    7596 
     
    92113      Object src = evt.getSource(); 
    93114      if (src == this) doGUI(); 
     115      else if (src instanceof ExitManager) { 
     116        // HACK - finalize control panel layout 
     117        bio.setSplashStatus("Initializing control panels"); 
     118 
     119        // lay out control panels 
     120        String pad = "9dlu"; 
     121        String[] cols = new String[numCols]; 
     122        String[] rows = new String[numRows]; 
     123        Arrays.fill(cols, pad); 
     124        Arrays.fill(rows, pad); 
     125        for (int i=0; i<panels.size(); i++) { 
     126          ControlPanel cpl = (ControlPanel) panels.elementAt(i); 
     127          Point p = (Point) coords.elementAt(i); 
     128          Dimension d = (Dimension) sizes.elementAt(i); 
     129          int xx = p.x; 
     130          int yy = p.y; 
     131          int ww = d.width; 
     132          int hh = d.height; 
     133          String colString = (String) colStrings.elementAt(i); 
     134          String rowString = (String) rowStrings.elementAt(i); 
     135          cols[xx - 1] = colString; 
     136          rows[yy - 1] = "pref"; 
     137          rows[yy] = "3dlu"; 
     138          rows[yy + 1] = rowString; 
     139        } 
     140        StringBuffer cbuf = new StringBuffer(cols[0]); 
     141        for (int i=1; i<cols.length; i++) { 
     142          cbuf.append(","); 
     143          cbuf.append(cols[i]); 
     144        } 
     145        StringBuffer rbuf = new StringBuffer(rows[0]); 
     146        for (int i=1; i<rows.length; i++) { 
     147          rbuf.append(","); 
     148          rbuf.append(rows[i]); 
     149        } 
     150        PanelBuilder builder = new PanelBuilder( 
     151          new FormLayout(cbuf.toString(), rbuf.toString())); 
     152        builder.setDefaultDialogBorder(); 
     153        CellConstraints cc = new CellConstraints(); 
     154        for (int i=0; i<panels.size(); i++) { 
     155          ControlPanel cpl = (ControlPanel) panels.elementAt(i); 
     156          Point p = (Point) coords.elementAt(i); 
     157          Dimension d = (Dimension) sizes.elementAt(i); 
     158          int xx = p.x; 
     159          int yy = p.y; 
     160          int ww = d.width; 
     161          int hh = d.height; 
     162          builder.addSeparator(cpl.getName(), cc.xyw(xx, yy, ww)); 
     163          builder.add(cpl, cc.xywh(xx, yy + 2, ww, hh, "fill,fill")); 
     164        } 
     165        bio.setContentPane(builder.getPanel()); 
     166      } 
    94167    } 
    95168  } 
     
    103176  /** Adds base control panel GUI components to VisBio. */ 
    104177  private void doGUI() { 
    105     bio.setSplashStatus("Initializing control panel logic"); 
    106     panels = new Vector(); 
    107  
    108     // control panel containers 
    109     tabs = new JTabbedPane(); 
    110     bio.getContentPane().add(tabs); 
    111  
    112178    // help window 
    113179    bio.setSplashStatus(null); 
  • trunk/loci/visbio/SystemControls.java

    r503 r531  
    217217    builder.add(stereoField, cc.xyw(3, row, 3)); 
    218218    row += 2; 
    219     controls.add(builder.getPanel()); 
     219    add(builder.getPanel()); 
    220220 
    221221    // update system information twice per second 
     
    260260      } 
    261261      sm.writeScript(maxHeap, null); 
    262       JOptionPane.showMessageDialog(controls, 
     262      JOptionPane.showMessageDialog(this, 
    263263        "The change will take effect next time you run VisBio.", 
    264264        "VisBio", JOptionPane.INFORMATION_MESSAGE); 
     
    280280      if (ndx < 0 || lafs[1][ndx].equals(laf[1])) return; 
    281281      sm.writeScript(-1, lafs[1][ndx]); 
    282       JOptionPane.showMessageDialog(controls, 
     282      JOptionPane.showMessageDialog(this, 
    283283        "The change will take effect next time you run VisBio.", 
    284284        "VisBio", JOptionPane.INFORMATION_MESSAGE); 
  • trunk/loci/visbio/SystemManager.java

    r487 r531  
    204204    bio.setSplashStatus("Initializing system information logic"); 
    205205    systemControls = new SystemControls(this); 
    206     PanelManager pm = (PanelManager) bio.getManager(PanelManager.class); 
    207     pm.addPanel(systemControls); 
     206//    PanelManager pm = (PanelManager) bio.getManager(PanelManager.class); 
     207//    pm.addPanel(systemControls); 
    208208 
    209209    // help window 
  • trunk/loci/visbio/VisBio.java

    r526 r531  
    4646 
    4747  /** Application version. */ 
    48   public static final String VERSION = "v3.11"; 
     48  public static final String VERSION = "v3.12"; 
    4949 
    5050  /** Application author. */ 
     
    5252 
    5353  /** Application build date. */ 
    54   public static final String DATE = "10 October 2005"; 
     54  public static final String DATE = "?? October 2005"; 
    5555 
    5656  /** Port to use for communicating between application instances. */ 
  • trunk/loci/visbio/VisBioFrame.java

    r500 r531  
    3232import java.util.Vector; 
    3333import javax.swing.*; 
    34 import javax.swing.border.BevelBorder; 
    35 import javax.swing.border.CompoundBorder; 
    3634import loci.visbio.data.DataManager; 
    3735import loci.visbio.data.DataTransform; 
     
    6967  protected SplashScreen splash; 
    7068 
    71   /** Status bar. */ 
    72   protected JProgressBar status; 
    73  
    74   /** Stop button for various operations. */ 
    75   protected JButton stop; 
    76  
    7769  /** VisBio program icon. */ 
    7870  protected Image icon; 
     
    126118      getMenu("Window"); 
    127119      getMenu("Help"); 
    128  
    129       // create status bar 
    130       status = new JProgressBar(); 
    131       status.setStringPainted(true); 
    132       status.setToolTipText("Reports status of VisBio operations"); 
    133       status.setBorder(new BevelBorder(BevelBorder.RAISED)); 
    134  
    135       // HACK - make progress bar an easier-to-read color for Plastic L&F 
    136       if (LAFUtil.isPlasticLookAndFeel()) status.setForeground(Color.blue); 
    137  
    138       // create stop button 
    139       stop = new JButton("Stop"); 
    140       if (!LAFUtil.isMacLookAndFeel()) stop.setMnemonic('s'); 
    141       stop.setToolTipText("Stops the currently reported VisBio operation"); 
    142       stop.setBorder(new CompoundBorder( 
    143         new BevelBorder(BevelBorder.RAISED), stop.getBorder())); 
    144       stop.setPreferredSize(stop.getPreferredSize()); // force constant size 
    145  
    146       // add status bar and stop button 
    147       JPanel statusPanel = new JPanel(); 
    148       statusPanel.setLayout(new BorderLayout()); 
    149       statusPanel.add(status, BorderLayout.CENTER); 
    150       statusPanel.add(stop, BorderLayout.EAST); 
    151       Container c = getContentPane(); 
    152       c.setLayout(new BorderLayout()); 
    153       c.add(statusPanel, BorderLayout.SOUTH); 
    154       resetStatus(); 
    155120 
    156121      // create logic managers 
     
    166131        new HelpManager(this), 
    167132        new PanelManager(this), 
     133        new TaskManager(this), 
    168134        new DataManager(this), 
    169135        new MathManager(this), 
     
    385351  } 
    386352 
    387   /** Gets the status bar's progress bar. */ 
    388   public JProgressBar getProgressBar() { return status; } 
    389  
    390   /** Gets the status bar's stop button. */ 
    391   public JButton getStopButton() { return stop; } 
    392  
    393   /** 
    394    * Sets the status bar to display the given message, 
    395    * using the AWT event thread. 
    396    */ 
    397   public void setStatus(String message) { 
    398     final String msg = message; 
    399     SwingUtilities.invokeLater(new Runnable() { 
    400       public void run() { 
    401         status.setString(msg == null ? 
    402           (VisBio.TITLE + " " + VisBio.VERSION) : msg); 
    403         status.setStringPainted(true); 
    404         status.setIndeterminate(false); 
    405         status.setValue(0); 
    406         stop.setEnabled(false); 
    407       } 
    408     }); 
    409   } 
    410  
    411   /** Resets status bar to an idle state. */ 
    412   public void resetStatus() { setStatus(null); } 
    413  
    414353  /** Gets VisBio program icon. */ 
    415354  public Image getIcon() { return icon; } 
  • trunk/loci/visbio/classes.txt

    r516 r531  
    21182118javax.vecmath.Vector4f 
    21192119loci.visbio.BioDropHandler 
     2120loci.visbio.BioTask 
    21202121loci.visbio.ClassManager 
    21212122loci.visbio.ConsoleManager 
     
    21262127loci.visbio.SystemControls 
    21272128loci.visbio.SystemManager 
     2129loci.visbio.TaskControls 
     2130loci.visbio.TaskManager 
    21282131loci.visbio.VisBio 
    21292132loci.visbio.VisBioEvent 
  • trunk/loci/visbio/data/DataControls.java

    r508 r531  
    3939import loci.visbio.*; 
    4040import loci.visbio.ome.OMEManager; 
    41 import loci.visbio.state.StateManager; 
    4241import loci.visbio.util.*; 
    4342import loci.visbio.view.DisplayWindow; 
     
    9493  /** Table of control frames corresponding to each data transform. */ 
    9594  private Hashtable frameTable; 
    96  
    97   /** Thumbnail handler for selected data object. */ 
    98   private ThumbnailHandler thumbHandler; 
    9995 
    10096 
     
    202198      "pref:grow, 3dlu, pref", 
    203199      "fill:pref, 5dlu, fill:50:grow")); 
    204     builder.setDefaultDialogBorder(); 
    205200    CellConstraints cc = new CellConstraints(); 
    206201    builder.add(treePane, cc.xy(1, 1)); 
    207202    builder.add(buttons, cc.xy(3, 1)); 
    208203    builder.add(infoPane, cc.xyw(1, 3, 3)); 
    209     controls.add(builder.getPanel()); 
     204    add(builder.getPanel()); 
    210205 
    211206    // handle file drag and drop 
     
    266261 
    267262    selectNode(node); 
    268     repack(); 
    269263  } 
    270264 
     
    616610      display3D.setEnabled(DisplayUtil.canDo3D() && canDisplay3D); 
    617611    } 
    618  
    619     if (thumbHandler != null) thumbHandler.setControls(null, null); 
    620     thumbHandler = null; 
    621  
    622     StateManager sm = (StateManager) bio.getManager(StateManager.class); 
    623     if (sm.isRestoring()) return; // no touching progress bar during restore 
    624  
    625     // link in thumbnail progress bar and generation button 
    626     if (data == null) bio.resetStatus(); 
    627     else { 
    628       ThumbnailHandler th = data.getThumbHandler(); 
    629       if (th == null) bio.resetStatus(); 
    630       else { 
    631         JProgressBar thumbProgress = bio.getProgressBar(); 
    632         JButton thumbGen = bio.getStopButton(); 
    633         th.setControls(thumbProgress, thumbGen); 
    634         thumbGen.setEnabled(true); 
    635       } 
    636       thumbHandler = th; 
    637     } 
    638612  } 
    639613 
  • trunk/loci/visbio/data/DataManager.java

    r522 r531  
    8484  public void addData(DataTransform data) { 
    8585    dataControls.addData(data); 
     86    ThumbnailHandler thumbHandler = data.getThumbHandler(); 
     87    if (thumbHandler != null) { 
     88      // register at task for thumbnail generation 
     89      TaskManager tm = (TaskManager) bio.getManager(TaskManager.class); 
     90      thumbHandler.setTask(tm.createTask(data.getName() + " thumbnails")); 
     91    } 
    8692    bio.generateEvent(this, "add data", true); 
    8793  } 
     
    188194    final String zipName = name + ".zip"; 
    189195    final String location = SAMPLE_PREFIX + zipName; 
    190  
    191     // prepare sample dataset in a separate thread 
    192     new Thread(new Runnable() { 
     196    TaskManager tm = (TaskManager) bio.getManager(TaskManager.class); 
     197    final BioTask task = tm.createTask(name + " sample"); 
     198    task.setStoppable(true); 
     199    new Thread() { 
    193200      public void run() { 
    194201        // create samples folder if it does not already exist 
     
    201208          dir.mkdir(); 
    202209          try { 
    203             bio.setStatus("Downloading " + zipName + "..."); 
     210            task.setStatus("Downloading " + zipName); 
    204211            URL url = new URL(location); 
    205212            ZipInputStream in = new ZipInputStream(url.openStream()); 
    206213            byte[] buf = new byte[8192]; 
    207214            while (true) { 
     215              if (task.isStopped()) break; 
    208216              ZipEntry entry = in.getNextEntry(); 
    209217              if (entry == null) break; // eof 
    210218              String entryName = entry.getName(); 
    211               bio.setStatus("Extracting " + entryName + "..."); 
     219              task.setStatus("Extracting " + entryName); 
    212220              FileOutputStream out = new FileOutputStream( 
    213221                new File(dir, entryName)); 
     
    227235          } 
    228236        } 
     237        if (task.isStopped()) { 
     238          task.setCompleted(); 
     239          return; 
     240        } 
    229241 
    230242        // create dataset object 
    231         bio.setStatus("Organizing data..."); 
     243        task.setStatus("Organizing data"); 
    232244        File[] files = dir.listFiles(); 
    233245        String pattern = null; 
    234246        for (int i=0; i<files.length; i++) { 
     247          if (task.isStopped()) break; 
    235248          if (files[i].getName().endsWith(".visbio")) continue; 
    236249          pattern = FilePattern.findPattern(files[i]); 
    237250          if (pattern == null) pattern = files[i].getAbsolutePath(); 
     251        } 
     252        if (task.isStopped()) { 
     253          task.setCompleted(); 
     254          return; 
    238255        } 
    239256        if (pattern == null) { 
     
    252269        dims[len] = "Slice"; 
    253270 
    254         bio.setStatus("Creating " + dirName + " dataset..."); 
    255         addData(new Dataset(dirName, pattern, fp.getFiles(), lengths, dims)); 
     271        if (task.isStopped()) { 
     272          task.setCompleted(); 
     273          return; 
     274        } 
     275        task.setStoppable(false); 
     276        task.setStatus("Creating dataset"); 
     277        TaskListener tl = new TaskListener() { 
     278          public void taskUpdated(TaskEvent e) { 
     279            int val = e.getProgressValue(); 
     280            int max = e.getProgressMaximum(); 
     281            String msg = e.getStatusMessage(); 
     282            task.setStatus(val, max, msg); 
     283          } 
     284        }; 
     285        Dataset dataset = new Dataset(dirName, pattern, 
     286          fp.getFiles(), lengths, dims, Float.NaN, Float.NaN, Float.NaN, tl); 
     287        task.setCompleted(); 
     288        addData(dataset); 
    256289      } 
    257     }).start(); 
     290    }.start(); 
    258291  } 
    259292 
     
    401434    dataControls = new DataControls(this); 
    402435    PanelManager pm = (PanelManager) bio.getManager(PanelManager.class); 
    403     pm.addPanel(dataControls); 
     436    pm.addPanel(dataControls, 0, 0, 1, 2, "350:grow", null); 
    404437 
    405438    // data transform registration 
  • trunk/loci/visbio/data/Dataset.java

    r529 r531  
    473473 
    474474    // make sure each file exists 
    475     status(0, numTasks, "Reading files..."); 
     475    status(0, numTasks, "Reading files"); 
    476476    for (int i=0; i<ids.length; i++) { 
    477477      File file = new File(ids[i]); 
     
    595595    // load metadata for each source file 
    596596    for (int i=0; i<ids.length; i++) { 
    597       status(i + 1, numTasks, "Reading metadata for " + ids[i] + "..."); 
    598597      String fname = new File(ids[i]).getName(); 
     598      status(i + 1, numTasks, "Reading " + fname + " metadata"); 
    599599      try { metadata[i] = loaders[i].getMetadata(ids[i]); } 
    600600      catch (IOException exc) { metadata[i] = null; } 
     
    608608 
    609609    // construct metadata controls 
    610     status(ids.length + 2, numTasks, "Finishing..."); 
     610    status(ids.length + 2, numTasks, "Finishing"); 
    611611    controls = new DatasetWidget(this); 
    612612 
  • trunk/loci/visbio/data/ExportPane.java

    r503 r531  
    3333import java.util.*; 
    3434import javax.swing.*; 
    35 import loci.visbio.VisBioFrame; 
     35import loci.visbio.*; 
    3636import loci.visbio.util.*; 
    3737import visad.*; 
     
    192192    final int numImages = excl < 0 ? 1 : lengths[excl]; 
    193193    final int numTotal = numFiles * numImages; 
    194     final JProgressBar progress = bio.getProgressBar(); 
    195     progress.setString("Exporting data"); 
    196     progress.setValue(0); 
    197     progress.setMaximum(numTotal + numFiles); 
    198  
    199     Thread t = new Thread(new Runnable() { 
     194    TaskManager tm = (TaskManager) bio.getManager(TaskManager.class); 
     195    final BioTask task = tm.createTask("Export " + 
     196      trans.getName() + " to disk"); 
     197    new Thread() { 
    200198      public void run() { 
    201199        try { 
     200          int count = 0; 
     201          int max = numTotal + numFiles; 
     202          task.setStatus(0, max, "Exporting data"); 
    202203          boolean padZeroes = leadingZeroes.isSelected(); 
    203204          int[] plen = new int[stars]; 
     
    215216            FieldImpl data = null; 
    216217            if (excl < 0) { 
    217               progress.setString("Reading image #" + (i + 1) + "/" + numTotal); 
     218              task.setStatus(count++, max, 
     219                "Reading image #" + (i + 1) + "/" + numTotal); 
    218220              data = (FlatField) trans.getData(npos, 2, null); 
    219               progress.setValue(progress.getValue() + 1); 
    220221            } 
    221222            else { 
     
    223224              for (int j=0; j<lengths[excl]; j++) { 
    224225                int img = numImages * i + j + 1; 
    225                 progress.setString("Reading image #" + img + "/" + numTotal); 
     226                task.setStatus(count++, max, 
     227                  "Reading image #" + img + "/" + numTotal); 
    226228                npos[excl] = j; 
    227229                FlatField image = (FlatField) trans.getData(npos, 2, null); 
     
    232234                } 
    233235                data.setSample(j, image, false); 
    234                 progress.setValue(progress.getValue() + 1); 
    235236              } 
    236237            } 
     
    251252            // save data to file 
    252253            String filename = sb.toString(); 
    253             progress.setString("Exporting file " + filename); 
     254            task.setStatus(count++, max, "Exporting file " + filename); 
    254255            saver.save(filename, data, false); 
    255             progress.setValue(progress.getValue() + 1); 
    256           } 
    257           bio.resetStatus(); 
     256          } 
     257          task.setCompleted(); 
    258258        } 
    259259        catch (VisADException exc) { 
    260           bio.resetStatus(); 
    261260          exc.printStackTrace(); 
    262261          JOptionPane.showMessageDialog(dialog, 
     
    265264        } 
    266265        catch (IOException exc) { 
    267           bio.resetStatus(); 
    268266          exc.printStackTrace(); 
    269267          JOptionPane.showMessageDialog(dialog, 
     
    272270        } 
    273271      } 
    274     }); 
    275     t.start(); 
     272    }.start(); 
    276273  } 
    277274 
  • trunk/loci/visbio/data/SendToIJPane.java

    r508 r531  
    3030import ij.ImageStack; 
    3131import ij.process.ImageProcessor; 
    32 import loci.visbio.VisBioFrame; 
     32import loci.visbio.*; 
    3333import loci.visbio.view.BioSlideWidget; 
    3434import loci.visbio.util.*; 
    3535import java.awt.event.ActionEvent; 
    3636import javax.swing.JOptionPane; 
    37 import javax.swing.JProgressBar; 
    3837import visad.FlatField; 
    3938import visad.VisADException; 
     
    8281    final int[] pos = new int[bsw.length]; 
    8382    for (int i=0; i<bsw.length; i++) pos[i] = bsw[i].getValue(); 
    84     final JProgressBar progress = bio.getProgressBar(); 
    85     progress.setString("Sending data to ImageJ"); 
    86     progress.setValue(0); 
     83    TaskManager tm = (TaskManager) bio.getManager(TaskManager.class); 
     84    final BioTask task = tm.createTask("Export " + 
     85      trans.getName() + " to ImageJ"); 
    8786 
    88     Thread t = new Thread(new Runnable() { 
     87    new Thread() { 
    8988      public void run() { 
    9089        try { 
    9190          // collect images to send to ImageJ 
    92           progress.setMaximum(1); 
     91          task.setStatus(0, 1, "Sending data to ImageJ"); 
    9392          int axis = stackAxis.getSelectedIndex() - 1; 
    9493          FlatField[] data; 
    9594          if (axis < 0) { 
    96             progress.setString("Reading image"); 
     95            task.setStatus("Reading image"); 
    9796            data = new FlatField[1]; 
    9897            data[0] = (FlatField) trans.getData(pos, 2, null); 
    99             progress.setValue(1); 
     98            task.setStatus(1, 1); 
    10099          } 
    101100          else { 
    102101            int len = lengths[axis]; 
    103             progress.setMaximum(len); 
    104102            data = new FlatField[len]; 
    105103            for (int i=0; i<len; i++) { 
    106               progress.setValue(i); 
    107               progress.setString("Reading image #" + (i + 1) + "/" + len); 
     104              task.setStatus(i, len, "Reading image #" + (i + 1) + "/" + len); 
    108105              pos[axis] = i; 
    109106              data[i] = (FlatField) trans.getData(pos, 2, null); 
    110107            } 
    111             progress.setValue(len); 
     108            task.setStatus(len, len); 
    112109          } 
    113110 
    114111          // convert FlatFields into ImagePlus object 
    115           progress.setString("Sending data to ImageJ"); 
     112          task.setStatus("Sending data to ImageJ"); 
    116113          ImagePlus image; 
    117114          String name = trans.getName() + " (from VisBio)"; 
     
    135132 
    136133          // send ImagePlus object to ImageJ 
     134          task.setCompleted(); 
    137135          ImageJUtil.sendToImageJ(image, bio); 
    138           bio.resetStatus(); 
    139136        } 
    140137        catch (VisADException exc) { 
    141           bio.resetStatus(); 
    142138          exc.printStackTrace(); 
    143139          JOptionPane.showMessageDialog(dialog, 
     
    146142        } 
    147143      } 
    148     }); 
    149     t.start(); 
     144    }.start(); 
    150145  } 
    151146 
  • trunk/loci/visbio/data/ThumbnailHandler.java

    r503 r531  
    2424package loci.visbio.data; 
    2525 
    26 import java.awt.event.ActionEvent; 
    27 import java.awt.event.ActionListener; 
    2826import java.rmi.RemoteException; 
    29 import javax.swing.*; 
     27import loci.visbio.BioTask; 
    3028import loci.visbio.util.*; 
    3129import visad.*; 
    3230 
    3331/** Provides logic for handling data transform thumbnails. */ 
    34 public class ThumbnailHandler 
    35   implements ActionListener, Runnable, TransformListener 
    36 { 
     32public class ThumbnailHandler implements Runnable, TransformListener { 
    3733 
    3834  // -- Fields -- 
     
    5652  protected boolean global = false; 
    5753 
    58   /** Progress bar reporting background thumbnail generation progress. */ 
    59   protected JProgressBar progress; 
    60  
    61   /** Button for toggling background thumbnail generation. */ 
    62   protected JButton toggle; 
     54  /** Task used for reporting background thumbnail generation progress. */ 
     55  protected BioTask task; 
    6356 
    6457  /** Background thumbnail generation thread. */ 
     
    7568 
    7669  /** Creates a thumbnail handler. */ 
    77   public ThumbnailHandler(DataTransform data, 
    78     String filename) 
    79   { 
     70  public ThumbnailHandler(DataTransform data, String filename) { 
    8071    this.data = data; 
    8172    data.addTransformListener(this); 
     
    144135  } 
    145136 
    146   /** Sets the progress bar for reporting thumbnail generation progress. */ 
    147   public void setControls(JProgressBar bar, JButton button) { 
    148     synchronized (data) { 
    149       progress = bar; 
    150       if (toggle != null) toggle.removeActionListener(this); 
    151       toggle = button; 
    152       if (toggle != null) toggle.addActionListener(this); 
    153     } 
    154     updateControls(); 
     137  /** Sets the task for reporting thumbnail generation progress. */ 
     138  public void setTask(BioTask task) { 
     139    this.task = task; 
     140    task.setStoppable(true); 
    155141  } 
    156142 
     
    199185 
    200186 
    201   // -- ActionListener API methods -- 
    202  
    203   /** Handles toggling of background generation. */ 
    204   public void actionPerformed(ActionEvent e) { toggleGeneration(!on); } 
    205  
    206  
    207187  // -- Runnable API methods -- 
    208188 
     
    210190  public void run() { 
    211191    for (int i=count; i<thumbs.length; i++) { 
    212       updateControls(); 
     192      if (task != null) { 
     193        if (task.isStopped()) break; 
     194        String message = on && count < thumbs.length ? 
     195          ("Generating " + (count + 1) + " of " + thumbs.length) : 
     196          (count + " of " + thumbs.length + " generated"); 
     197        task.setStatus(count, thumbs.length, message); 
     198      } 
    213199      loadThumb(i); 
    214200      if (!on) break; 
    215201    } 
    216     updateControls(); 
     202    if (task != null) { 
     203      task.setCompleted(); 
     204      task = null; 
     205    } 
    217206  } 
    218207 
     
    228217 
    229218  // -- Helper methods -- 
    230  
    231   /** Updates the linked progress bar to match thumbnail generation status. */ 
    232   private void updateControls() { 
    233     SwingUtilities.invokeLater(new Runnable() { 
    234       public void run() { 
    235         synchronized (data) { 
    236           if (progress == null || toggle == null) return; 
    237           progress.setMaximum(thumbs.length); 
    238           if (count < thumbs.length) { 
    239             if (on) { 
    240               progress.setString("Generating thumbnail " + 
    241                 (count + 1) + " of " + thumbs.length); 
    242             } 
    243             else { 
    244               progress.setString(count + " of " + thumbs.length + 
    245                 " thumbnails generated"); 
    246             } 
    247             toggle.setEnabled(true); 
    248           } 
    249           else { 
    250             progress.setString(count + " thumbnail" + 
    251               (count == 1 ? "" : "s") + " generated"); 
    252             toggle.setEnabled(false); 
    253           } 
    254           progress.setValue(count); 
    255           if (on) { 
    256             toggle.setText("Stop"); 
    257             if (!LAFUtil.isMacLookAndFeel()) toggle.setMnemonic('s'); 
    258           } 
    259           else { 
    260             toggle.setText("Go"); 
    261             if (!LAFUtil.isMacLookAndFeel()) toggle.setMnemonic('g'); 
    262           } 
    263         } 
    264       } 
    265     }); 
    266   } 
    267219 
    268220  /** Generates thumbnails in a new background thread. */ 
  • trunk/loci/visbio/ome/OMEManager.java

    r495 r531  
    2626import java.awt.Component; 
    2727import javax.swing.JOptionPane; 
    28 import javax.swing.JProgressBar; 
    29 import javax.swing.SwingUtilities; 
    3028import loci.visbio.*; 
    3129import loci.visbio.data.*; 
     
    3634 * VisBio and the Open Microscopy Environment. 
    3735 */ 
    38 public class OMEManager extends LogicManager implements TaskListener { 
     36public class OMEManager extends LogicManager { 
    3937 
    4038  // -- Fields -- 
     
    9492    // upload data to OME in a new thread 
    9593    final ImageUploader uploader = new ImageUploader(); 
    96     uploader.addTaskListener(this); 
     94    TaskManager tm = (TaskManager) bio.getManager(TaskManager.class); 
     95    final BioTask task = tm.createTask("Upload " + dt.getName() + " to OME"); 
     96    uploader.addTaskListener(new TaskListener() { 
     97      public void taskUpdated(TaskEvent e) { 
     98        // update task with latest database communication status 
     99        int value = e.getProgressValue(); 
     100        int max = e.getProgressMaximum(); 
     101        String msg = e.getStatusMessage(); 
     102        if (msg.endsWith("...")) msg = msg.substring(0, msg.length() - 3); 
     103        task.setStatus(value, max, msg); 
     104      } 
     105    }); 
    97106    new Thread(new Runnable() { 
    98107      public void run() { 
     
    138147 
    139148 
    140   // -- TaskListener API methods -- 
    141  
    142   /** Called when an OME-related task is updated. */ 
    143   public void taskUpdated(TaskEvent e) { 
    144     // update VisBio progress bar with latest database communication status 
    145     final JProgressBar progress = bio.getProgressBar(); 
    146     final int value = e.getProgressValue(); 
    147     final int max = e.getProgressMaximum(); 
    148     final String message = e.getStatusMessage(); 
    149     SwingUtilities.invokeLater(new Runnable() { 
    150       public void run() { 
    151         progress.setMaximum(max); 
    152         progress.setValue(value); 
    153         progress.setString(message); 
    154       } 
    155     }); 
    156   } 
    157  
    158  
    159149  // -- Helper methods -- 
    160150 
  • trunk/loci/visbio/state/StateManager.java

    r499 r531  
    164164        bio.getManager(WindowManager.class); 
    165165      wm.setWaitCursor(true); 
    166       JProgressBar status = bio.getProgressBar(); 
    167       status.setString("Restoring state..."); 
    168       status.setIndeterminate(true); 
    169       Thread restoreThread = new Thread(new Runnable() { 
     166      new Thread(new Runnable() { 
    170167        public void run() { 
    171168          restoreState(stateBox.getSelectedFile()); 
    172169          SwingUtilities.invokeLater(new Runnable() { 
    173             public void run() { 
    174               bio.resetStatus(); 
    175               wm.setWaitCursor(false); 
    176             } 
     170            public void run() { wm.setWaitCursor(false); } 
    177171          }); 
    178172        } 
    179       }); 
    180       restoreThread.start(); 
     173      }).start(); 
    181174    } 
    182175  } 
  • trunk/loci/visbio/view/DisplayControls.java

    r503 r531  
    7070  public DisplayControls(LogicManager logic) { 
    7171    super(logic, "Displays", "Controls for managing displays"); 
    72     controls.setLayout(new BoxLayout(controls, BoxLayout.Y_AXIS)); 
    7372 
    7473    // list of displays 
    7574    listModel = new DefaultListModel(); 
    7675    displayList = new JList(listModel); 
    77     displayList.setFixedCellWidth(120); 
     76    displayList.setFixedCellWidth(250); 
    7877    displayList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 
    7978    displayList.addListSelectionListener(this); 
     
    131130    // lay out components 
    132131    PanelBuilder builder = new PanelBuilder(new FormLayout( 
    133       "default:grow, 3dlu, pref", 
    134       "fill:pref:grow")); 
    135     builder.setDefaultDialogBorder(); 
     132      "default, 3dlu, pref", "fill:pref:grow")); 
    136133    CellConstraints cc = new CellConstraints(); 
    137134    builder.add(listPane, cc.xy(1, 1)); 
    138135    builder.add(buttons, cc.xy(3, 1)); 
    139     controls.add(builder.getPanel()); 
     136    add(builder.getPanel()); 
    140137  } 
    141138 
  • trunk/loci/visbio/view/DisplayManager.java

    r493 r531  
    214214    displayControls = new DisplayControls(this); 
    215215    PanelManager pm = (PanelManager) bio.getManager(PanelManager.class); 
    216     pm.addPanel(displayControls); 
     216    pm.addPanel(displayControls, 1, 0, 1, 1, "350", null); 
    217217 
    218218    // options 
  • trunk/loci/visbio/whatsnew.txt

    r530 r531  
    11v3.12 - Not yet released 
     2 
     3- ADDED: Separate task tracking for each background task VisBio is performing 
     4- ADDED: Rearrange main VisBio window to be more streamlined 
    25 
    36- TWEAK: Report more information during initial dataset creation 
    47- TWEAK: Don't create errors.log unless necessary 
     8- TWEAK: Eliminate some debugging messages from the output console 
    59 
    610 
Note: See TracChangeset for help on using the changeset viewer.