Changeset 4215


Ignore:
Timestamp:
07/21/08 16:16:09 (12 years ago)
Author:
curtis
Message:

Improve color min/max widgets.

Location:
trunk/loci/slim
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/slim/IntensityPane.java

    r4214 r4215  
    3636import javax.swing.*; 
    3737import javax.swing.border.EmptyBorder; 
    38 import javax.swing.event.ChangeEvent; 
    39 import javax.swing.event.ChangeListener; 
     38import javax.swing.event.*; 
    4039import visad.*; 
    4140import visad.bom.CurveManipulationRendererJ3D; 
     
    5352 */ 
    5453public class IntensityPane extends JPanel 
    55   implements ActionListener, ChangeListener, DisplayListener 
     54  implements ActionListener, ChangeListener, DisplayListener, DocumentListener 
    5655{ 
    5756 
     
    6968  // ROI parameters 
    7069  private float[][] roiGrid; 
    71   private boolean[][] roiMask; 
    7270  private UnionSet curveSet; 
    7371  private Irregular2DSet roiSet; 
    7472  private DataReferenceImpl roiRef; 
    75   private int roiX, roiY; 
     73 
    7674  private int roiCount; 
    7775  private double roiPercent; 
     76  private int roiX, roiY; 
     77  private boolean[][] roiMask; 
    7878 
    7979  // GUI components for intensity pane 
    8080  private JSlider cSlider; 
    81   private JLabel minLabel, maxLabel; 
    82   private JSlider minSlider, maxSlider; 
     81  private JTextField minField, maxField; 
    8382  private JCheckBox cToggle; 
    8483 
     
    158157      iPlot.make_matrix(0, 0, 0, 0.85, 0, 0, 0)); 
    159158 
     159    intensityRef.setData(field); 
     160    ColorControl cc = (ColorControl) iPlot.getControl(ColorControl.class); 
     161    cc.setTable(ColorControl.initTableGreyWedge(new float[3][256])); 
     162 
    160163    // lay out components 
    161164    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 
     
    182185    sliderPane.setLayout(new BoxLayout(sliderPane, BoxLayout.X_AXIS)); 
    183186    add(sliderPane); 
     187 
     188    JPanel minMaxPane = new JPanel(); 
     189    minMaxPane.setLayout(new BoxLayout(minMaxPane, BoxLayout.Y_AXIS)); 
     190    minMaxPane.setBorder(new EmptyBorder(3, 3, 3, 3)); 
     191    sliderPane.add(minMaxPane); 
     192 
     193    JPanel minPane = new JPanel(); 
     194    minPane.setLayout(new BoxLayout(minPane, BoxLayout.X_AXIS)); 
     195    minMaxPane.add(minPane); 
     196    JLabel minLabel = new JLabel("Min"); 
     197    minLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); 
     198    minPane.add(minLabel); 
     199    minField = new JTextField("0", 4); 
     200    minField.setMaximumSize(minField.getPreferredSize()); 
     201    minField.setToolTipText("<html>" + 
     202      "Adjusts intensity plot's minimum color value.<br>" + 
     203      "Anything less than this value appears black.</html>"); 
     204    minField.getDocument().addDocumentListener(this); 
     205    minPane.add(minField); 
     206 
     207    JPanel maxPane = new JPanel(); 
     208    maxPane.setLayout(new BoxLayout(maxPane, BoxLayout.X_AXIS)); 
     209    minMaxPane.add(maxPane); 
     210    JLabel maxLabel = new JLabel("Max"); 
     211    maxLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); 
     212    minLabel.setPreferredSize(maxLabel.getPreferredSize()); 
     213    maxPane.add(maxLabel); 
     214    maxField = new JTextField("" + max, 4); 
     215    maxField.setMaximumSize(maxField.getPreferredSize()); 
     216    maxField.setToolTipText("<html>" + 
     217      "Adjusts intensity plot's maximum color value.<br>" + 
     218      "Anything greater than this value appears white.</html>"); 
     219    maxField.getDocument().addDocumentListener(this); 
     220    maxPane.add(maxField); 
     221 
    184222    cSlider = new JSlider(1, channels, 1); 
    185223    cSlider.setToolTipText( 
     
    200238    sliderPane.add(cToggle); 
    201239 
     240    cSlider.setValue(maxChan + 1); 
     241    rescaleMinMax(); 
     242    /* 
    202243    JPanel minMaxPane = new JPanel(); 
    203244    minMaxPane.setLayout(new BoxLayout(minMaxPane, BoxLayout.X_AXIS)); 
     
    230271    maxPane.add(maxLabel); 
    231272    maxSlider = new JSlider(0, max, max); 
    232     maxSlider.setToolTipText("<html>" + 
    233       "Adjusts intensity plot's maximum color value.<br>" + 
    234       "Anything greater than this value appears white.</html>"); 
    235273    maxSlider.setMajorTickSpacing(max); 
    236274    maxSlider.setMinorTickSpacing(minor); 
     
    239277    maxSlider.setBorder(new EmptyBorder(0, 5, 8, 5)); 
    240278    maxPane.add(maxSlider); 
    241  
    242     intensityRef.setData(field); 
    243     ColorControl cc = (ColorControl) iPlot.getControl(ColorControl.class); 
    244     cc.setTable(ColorControl.initTableGreyWedge(new float[3][256])); 
    245  
    246     cSlider.setValue(maxChan + 1); 
     279    */ 
    247280  } 
    248281 
     
    278311      cToggle.setSelected(cVisible[c]); 
    279312      cToggle.addActionListener(this); 
    280     } 
    281     else if (src == minSlider) { 
    282       int min = minSlider.getValue(); 
    283       int max = maxSlider.getMaximum(); 
    284       maxSlider.setMajorTickSpacing(max - min); 
    285       int minor = (max - min) / 16; 
    286       if (minor < 1) minor = 1; 
    287       maxSlider.setMinorTickSpacing(minor); 
    288       maxSlider.setMinimum(min); 
    289       minLabel.setText("min=" + min); 
    290       rescaleMinMax(); 
    291     } 
    292     else if (src == maxSlider) { 
    293       int max = maxSlider.getValue(); 
    294       minSlider.setMajorTickSpacing(max); 
    295       int minor = max / 16; 
    296       if (minor < 1) minor = 1; 
    297       minSlider.setMinorTickSpacing(minor); 
    298       minSlider.setMaximum(max); 
    299       maxLabel.setText("max=" + max); 
    300       rescaleMinMax(); 
    301313    } 
    302314  } 
     
    362374  } 
    363375 
     376  // -- DocumentListener methods -- 
     377 
     378  public void changedUpdate(DocumentEvent e) { rescaleMinMax(); } 
     379  public void insertUpdate(DocumentEvent e) { rescaleMinMax(); } 
     380  public void removeUpdate(DocumentEvent e) { rescaleMinMax(); } 
     381 
    364382  // -- Helper methods -- 
    365383 
     
    378396 
    379397  private void rescaleMinMax() { 
    380     int min = minSlider.getValue(); 
    381     int max = maxSlider.getValue(); 
    382     try { intensityMap.setRange(min, max); } 
     398    try { 
     399      int min = Integer.parseInt(minField.getText()); 
     400      int max = Integer.parseInt(maxField.getText()); 
     401      intensityMap.setRange(min, max); 
     402    } 
     403    catch (NumberFormatException exc) { } 
    383404    catch (VisADException exc) { exc.printStackTrace(); } 
    384405    catch (RemoteException exc) { exc.printStackTrace(); } 
  • trunk/loci/slim/SlimPlotter.java

    r4214 r4215  
    3636import java.io.*; 
    3737import java.rmi.RemoteException; 
    38 import java.util.*; 
     38import java.util.Arrays; 
     39import java.util.Hashtable; 
    3940import javax.swing.*; 
    4041import javax.swing.border.EmptyBorder; 
     
    120121  private float timeRange; 
    121122  private int minWave, waveStep, maxWave; 
     123  private int numExp; 
    122124  private boolean adjustPeaks, computeFWHMs, cutEnd; 
    123125  private boolean[] cVisible; 
     
    141143  // GUI components for parameter dialog box 
    142144  private JDialog paramDialog; 
    143   private JTextField wField, hField, tField, cField, trField, wlField, sField; 
     145  private JTextField wField, hField, tField, cField; 
     146  private JTextField trField, wlField, sField; 
     147  private JTextField fitField; 
    144148  private JCheckBox peaksBox, fwhmBox, cutBox; 
    145149 
     
    161165  private JRadioButton resSurface, resLines; 
    162166  private JRadioButton colorHeight, colorTau; 
    163   private JSpinner numCurves; 
    164167  private JCheckBox showData, showScale; 
    165168  private JCheckBox showBox, showLine; 
     
    284287      paramPane.setBorder(new EmptyBorder(10, 10, 10, 10)); 
    285288      paramDialog.setContentPane(paramPane); 
    286       paramPane.setLayout(new GridLayout(12, 3)); 
     289      paramPane.setLayout(new GridLayout(13, 3)); 
    287290      wField = addRow(paramPane, "Image width", width, "pixels"); 
    288291      hField = addRow(paramPane, "Image height", height, "pixels"); 
     
    292295      wlField = addRow(paramPane, "Starting wavelength", minWave, "nanometers"); 
    293296      sField = addRow(paramPane, "Channel width", waveStep, "nanometers"); 
     297      fitField = addRow(paramPane, "Exponential fit", 1, "components"); 
    294298      JButton ok = new JButton("OK"); 
    295299      paramDialog.getRootPane().setDefaultButton(ok); 
     
    760764      exportData.addActionListener(this); 
    761765 
    762       numCurves = new JSpinner(new SpinnerNumberModel(1, 1, 2, 1)); 
    763       numCurves.setToolTipText("Number of components in exponential fit"); 
    764       numCurves.setMaximumSize(numCurves.getPreferredSize()); 
    765       numCurves.addChangeListener(this); 
    766  
    767766      setProgress(progress, 990); // estimate: 99% 
    768767      if (progress.isCanceled()) System.exit(0); 
     
    820819      miscRow3.add(scalePanel); 
    821820      miscRow3.add(Box.createHorizontalStrut(5)); 
    822 //      miscRow3.add(numCurves); 
    823 //      miscRow3.add(Box.createHorizontalStrut(5)); 
    824821      miscRow3.add(exportData); 
    825822 
     
    10871084        minWave = parse(wlField.getText(), minWave); 
    10881085        waveStep = parse(sField.getText(), waveStep); 
     1086        numExp = parse(fitField.getText(), numExp); 
    10891087        adjustPeaks = peaksBox.isSelected(); 
    10901088        computeFWHMs = fwhmBox.isSelected(); 
     
    11091107  public void insertUpdate(DocumentEvent e) { documentUpdate(e); } 
    11101108  public void removeUpdate(DocumentEvent e) { documentUpdate(e); } 
     1109 
     1110  private void documentUpdate(DocumentEvent e) { 
     1111    Document doc = e.getDocument(); 
     1112    if (doc == zScaleValue.getDocument()) updateZAxis(); 
     1113    else updateColorScale(); // cMinValue or cMaxValue 
     1114  } 
    11111115 
    11121116  // -- Runnable methods -- 
     
    12441248      // curve fitting 
    12451249      double[][] fitResults = null; 
    1246       int numExp = ((Integer) numCurves.getValue()).intValue(); 
    12471250      if (adjustPeaks && doRefit) { 
    12481251        // perform exponential curve fitting: y(x) = a * e^(-b*t) + c 
     
    16041607  } 
    16051608 
    1606   private void documentUpdate(DocumentEvent e) { 
    1607     Document doc = e.getDocument(); 
    1608     if (doc == zScaleValue.getDocument()) updateZAxis(); 
    1609     else updateColorScale(); // cMinValue or cMaxValue 
    1610   } 
    1611  
    16121609  private void updateZAxis() { 
    16131610    float f = Float.NaN; 
Note: See TracChangeset for help on using the changeset viewer.