Changeset 1767


Ignore:
Timestamp:
11/08/06 17:21:27 (13 years ago)
Author:
curtis
Message:

Make SlimPlotter one monolithic window.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/apps/slim/SlimPlotter.java

    r1756 r1767  
    2727import loci.formats.DataTools; 
    2828import loci.formats.ExtensionFileFilter; 
     29import loci.visbio.util.BreakawayPanel; 
    2930import loci.visbio.util.OutputConsole; 
    3031import visad.*; 
     
    9394  private JRadioButton fitSurface, fitLines; 
    9495  private JRadioButton resSurface, resLines; 
    95   private JCheckBox showData, showLog; 
    96   private JCheckBox showBox, showScale; 
     96  private JCheckBox showData, showScale; 
     97  private JCheckBox showBox, showLine; 
    9798  private JCheckBox showFit, showResiduals; 
    9899  private JSpinner numCurves; 
     
    108109  private FunctionType bcvFunc, bcvFuncFit, bcvFuncRes; 
    109110  private ScalarMap zMap, zMapFit, zMapRes, vMap, vMapFit, vMapRes; 
    110   private DataRenderer decayRend, fitRend, resRend; 
     111  private DataRenderer decayRend, fitRend, resRend, lineRend; 
    111112  private DataReferenceImpl decayRef, fitRef, resRef; 
    112113  private DisplayImpl iPlot, decayPlot; 
     
    118119    console = new OutputConsole("Log"); 
    119120    System.setErr(new ConsoleStream(new PrintStream(console))); 
     121    console.getTextArea().setColumns(54); 
     122    console.getTextArea().setRows(20); 
    120123 
    121124    ProgressMonitor progress = new ProgressMonitor(null, 
     
    485488 
    486489      // add yellow line to indicate adjusted peak position 
     490      lineRend = new DefaultRendererJ3D(); 
    487491      DataReferenceImpl peakRef = new DataReferenceImpl("peaks"); 
    488492      float peakTime = (float) (maxPeak * timeRange / timeBins); 
    489493      peakRef.setData(new Gridded2DSet(bc, 
    490494        new float[][] {{peakTime, peakTime}, {minWave, maxWave}}, 2)); 
    491       decayPlot.addReference(peakRef, new ConstantMap[] { 
     495      decayPlot.addReferences(lineRend, peakRef, new ConstantMap[] { 
    492496        new ConstantMap(-1, Display.ZAxis), 
    493497        new ConstantMap(0, Display.Blue), 
     
    496500    } 
    497501 
    498     // construct 2D window 
     502    // construct 2D pane 
    499503    progress.setNote("Creating plots"); 
    500     JFrame intensityFrame = new JFrame("Intensity Data - " + file.getName()); 
    501     intensityFrame.addWindowListener(this); 
     504    JFrame masterWindow = new JFrame("Slim Plotter - " + file.getName()); 
     505    masterWindow.addWindowListener(this); 
     506    JPanel masterPane = new JPanel(); 
     507    masterPane.setLayout(new BorderLayout()); 
     508    masterWindow.setContentPane(masterPane); 
    502509    JPanel intensityPane = new JPanel(); 
    503510    intensityPane.setLayout(new BorderLayout()); 
    504     intensityFrame.setContentPane(intensityPane); 
    505     intensityPane.add(iPlot.getComponent(), BorderLayout.CENTER); 
     511    JPanel iPlotPane = new JPanel() { 
     512      private int height = 380; 
     513      public Dimension getMinimumSize() { 
     514        Dimension min = super.getMinimumSize(); 
     515        return new Dimension(min.width, height); 
     516      } 
     517      public Dimension getPreferredSize() { 
     518        Dimension pref = super.getPreferredSize(); 
     519        return new Dimension(pref.width, height); 
     520      } 
     521      public Dimension getMaximumSize() { 
     522        Dimension max = super.getMaximumSize(); 
     523        return new Dimension(max.width, height); 
     524      } 
     525    }; 
     526    iPlotPane.setLayout(new BorderLayout()); 
     527    iPlotPane.add(iPlot.getComponent(), BorderLayout.CENTER); 
     528    intensityPane.add(iPlotPane, BorderLayout.CENTER); 
    506529 
    507530    JPanel sliderPane = new JPanel(); 
     
    527550    if (progress.isCanceled()) System.exit(0); 
    528551 
    529     // construct 3D window 
    530     JFrame decayFrame = new JFrame("Spectral Lifetime Data - " + 
    531       file.getName()); 
    532     decayFrame.addWindowListener(this); 
     552    // construct 3D pane 
    533553    JPanel decayPane = new JPanel(); 
    534554    decayPane.setLayout(new BorderLayout()); 
     
    539559 
    540560    JPanel options = new JPanel(); 
    541     options.setBorder(new EmptyBorder(8, 5, 8, 5)); 
     561    options.setBorder(new EmptyBorder(8, 5, 8, 20)); 
    542562    options.setLayout(new BoxLayout(options, BoxLayout.X_AXIS)); 
    543563 
     
    569589    showData.addActionListener(this); 
    570590    showPanel1.add(showData); 
    571     showLog = new JCheckBox("Log", true); 
    572     showLog.addActionListener(this); 
    573     showPanel1.add(showLog); 
     591    showScale = new JCheckBox("Scale", true); 
     592    showScale.addActionListener(this); 
     593    showPanel1.add(showScale); 
    574594    showBox = new JCheckBox("Box", true); 
    575595    showBox.addActionListener(this); 
    576596    showPanel2.add(showBox); 
    577     showScale = new JCheckBox("Scale", true); 
    578     showScale.addActionListener(this); 
    579     showPanel2.add(showScale); 
     597    showLine = new JCheckBox("Line", adjustPeaks); 
     598    showLine.setEnabled(adjustPeaks); 
     599    showLine.addActionListener(this); 
     600    showPanel2.add(showLine); 
    580601    showFit = new JCheckBox("Fit", false); 
    581602    showFit.setEnabled(adjustPeaks); 
     
    594615    exportData.addActionListener(this); 
    595616 
    596     console.getWindow().addWindowListener(new WindowAdapter() { 
    597       public void windowClosing(WindowEvent e) { showLog.setSelected(false); } 
    598     }); 
     617    JPanel leftPanel = new JPanel() { 
     618      public Dimension getMaximumSize() { 
     619        Dimension pref = getPreferredSize(); 
     620        Dimension max = super.getMaximumSize(); 
     621        return new Dimension(pref.width, max.height); 
     622      } 
     623    }; 
     624    leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS)); 
     625    leftPanel.add(intensityPane); 
     626    leftPanel.add(console.getWindow().getContentPane()); 
     627    BreakawayPanel breakawayPanel = new BreakawayPanel(masterPane, 
     628      "Intensity Data - " + file.getName(), false); 
     629    breakawayPanel.setEdge(BorderLayout.WEST); 
     630    breakawayPanel.setUpEnabled(false); 
     631    breakawayPanel.setDownEnabled(false); 
     632    breakawayPanel.setContentPane(leftPanel); 
    599633 
    600634    options.add(makeRadioPanel("Scale", linear, log)); 
     
    608642    options.add(exportData); 
    609643    decayPane.add(options, BorderLayout.SOUTH); 
    610     decayFrame.setContentPane(decayPane); 
    611  
    612     // adjust window sizes 
    613     intensityFrame.pack(); 
    614     int intensityWidth = intensityFrame.getSize().width; 
    615     int intensityHeight = intensityFrame.getSize().height; 
    616     if (intensityWidth < 400) { 
    617       // enforce minimum reasonable width 
    618       intensityHeight = 400 * intensityHeight / intensityWidth; 
    619       intensityWidth = 400; 
    620     } 
    621     int decayHeight = intensityHeight; 
    622     int decayWidth = 100 * decayHeight / 100; // 100% of width 
    623  
    624     // enlarge 3D window to fill more of the screen 
    625     int padWidth = 30, padHeight = 70; 
    626     int pw = padWidth / 2, ph = padHeight / 2; 
    627     int availWidth = screenSize.width - intensityWidth - padWidth; 
    628     int availHeight = screenSize.height - padHeight; 
    629     int growWidth = availWidth - decayWidth; 
    630     int growHeight = availHeight - decayHeight; 
    631     int grow = growWidth < growHeight ? growWidth : growHeight; 
    632     if (grow > 0) { 
    633       decayWidth += grow; 
    634       decayHeight += grow; 
    635     } 
    636  
    637     // widen 2D window to fill any leftover space 
    638     grow = screenSize.width - intensityWidth - decayWidth - padWidth; 
    639     intensityWidth += grow; 
    640     intensityHeight += grow; 
    641     decayFrame.setBounds(pw + intensityWidth, ph, decayWidth, decayHeight); 
    642     intensityFrame.setBounds(pw, ph, intensityWidth, intensityHeight); 
    643  
    644     // adjust console window to match 
    645     console.getWindow().setBounds(pw, ph + intensityHeight, 
    646       intensityWidth, decayHeight - intensityHeight); 
    647  
    648     // show windows on screen 
    649     intensityFrame.setVisible(true); 
    650     decayFrame.setVisible(true); 
    651     console.setVisible(true); 
     644    masterPane.add(decayPane, BorderLayout.CENTER); 
     645 
     646    // show window on screen 
     647    masterWindow.pack(); 
     648    masterWindow.setVisible(true); 
    652649    progress.setProgress(++p); 
    653650    progress.close(); 
     
    734731      catch (Exception exc) { exc.printStackTrace(); } 
    735732    } 
    736     else if (src == showData) { 
    737       decayRend.toggle(showData.isSelected()); 
    738     } 
    739     else if (src == showLog) { console.setVisible(showLog.isSelected()); } 
     733    else if (src == showData) decayRend.toggle(showData.isSelected()); 
     734    else if (src == showLine) lineRend.toggle(showLine.isSelected()); 
    740735    else if (src == showBox) { 
    741736      try { decayPlot.getDisplayRenderer().setBoxOn(showBox.isSelected()); } 
Note: See TracChangeset for help on using the changeset viewer.