Changeset 7847 for trunk/projects
- Timestamp:
- 12/21/11 17:55:34 (8 years ago)
- Location:
- trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/ColorBarPanel.java
r7844 r7847 59 59 private int _inset; 60 60 private Color[] _color; 61 double _min ;62 double _max ;61 double _minView; 62 double _maxView; 63 63 double _minLUT; 64 64 double _maxLUT; 65 65 66 66 /** 67 * Constructor 67 * Constructor. Note that for best results width should be 254, so that 68 * there is a 1:1 relationship between colors and pixels. 68 69 * 69 70 * @param width … … 80 81 setPreferredSize(new Dimension(width + 2 * inset, height)); 81 82 82 _min = _max= _minLUT = _maxLUT = 0.0f;83 _minView = _maxView = _minLUT = _maxLUT = 0.0f; 83 84 } 84 85 … … 98 99 * Changes the values and redraws. 99 100 * 100 * @param min 101 * @param max 101 * @param minView 102 * @param maxView 102 103 * @param minLUT 103 104 * @param maxLUT 104 105 */ 105 public void setMinMax(double min, double max, double minLUT, double maxLUT) { 106 public void setMinMax(double minView, double maxView, 107 double minLUT, double maxLUT) { 106 108 synchronized (_synchObject) { 107 _min = min;108 _max = max;109 _minView = minView; 110 _maxView = maxView; 109 111 _minLUT = minLUT; 110 112 _maxLUT = maxLUT; … … 161 163 162 164 /* 163 * Given a pixel value 0...253 165 * Given a pixel value 0..253 show appropriate color. 166 * 164 167 * @param i 165 168 * @return 166 169 */ 167 //TODO this is WRONGO!!!!! 256 color version168 170 private Color colorize(int i) { 171 // default color 169 172 Color color = _color[0]; 170 // wait till we have initial range 171 if (_min < _max) { 172 double value = _min + (_max - _min) * i / _width; 173 174 // wait till we have initial range before any colorization 175 if (_minView < _maxView) { 176 177 // what is the value for this pixel? 178 double value = _minView + (_maxView - _minView) * i / _width; 179 180 // if value within palette range 173 181 if (value >= _minLUT && value <= _maxLUT) { 174 int index = (int)((value - _minLUT) 182 183 // compute color index 184 int index = 1 + (int)((value - _minLUT) 175 185 * _color.length / (_maxLUT - _minLUT)); 176 index = Math.max(index, 0); 177 index = Math.min(index, _color.length - 1); 186 187 // constrain to 1..253 188 index = Math.max(index, 1); 189 index = Math.min(index, _color.length - 3); 190 191 // get the color 178 192 color = _color[index]; 179 193 } -
trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/HistogramData.java
r7845 r7847 15 15 private HistogramDataChannel[] _channel; 16 16 private int _channelIndex; 17 private boolean _auto Scale;17 private boolean _autoRange; 18 18 private boolean _combineChannels; 19 19 private boolean _displayChannels; … … 32 32 _title = title; 33 33 _channel = channel; 34 _auto Scale = true;34 _autoRange = true; 35 35 _combineChannels = true; 36 36 _displayChannels = true; … … 41 41 } 42 42 43 /** 44 * Sets a listener for histogram data changes. Listener is unique. 45 * 46 * @param listener 47 */ 43 48 public void setListener(IHistogramDataListener listener) { 44 49 _listener = listener; … … 63 68 } 64 69 65 66 70 /** 67 71 * Sets current channel index. … … 73 77 } 74 78 79 /** 80 * Gets whether or not histogram should automatically scale to values. 81 * 82 * @return whether automatically scales 83 */ 84 public boolean getAutoRange() { 85 return _autoRange; 86 } 87 88 /** 89 * Sets whether or not histogram should automatically scale to values. 90 * 91 * @param auto whether automatically scales 92 */ 93 public void setAutoRange(boolean autoRange) { 94 _autoRange = autoRange; 95 } 96 97 /** 98 * Gets whether or not histogram should combine all the channels. 99 * 100 * @return whether to combine all the channels 101 */ 102 public boolean getCombineChannels() { 103 return _combineChannels; 104 } 105 106 /** 107 * Sets whether or not histogram should combine all the channels. 108 * 109 * @param combineChannels 110 */ 111 public void setCombineChannels(boolean combineChannels) { 112 _combineChannels = combineChannels; 113 } 114 115 /** 116 * Gets whether or not histogram should display all channels. 117 * 118 * @return 119 */ 75 120 public boolean getDisplayChannels() { 76 121 return _displayChannels; 77 122 } 78 123 124 /** 125 * Sets whether or not histogram should display all channels. 126 * 127 * @param displayChannels 128 */ 79 129 public void setDisplayChannels(boolean displayChannels) { 80 81 } 82 83 /** 84 * Gets whether or not histogram should combine all the channels. 85 * 86 * @return whether to combine all the channels 87 */ 88 public boolean getCombineChannels() { 89 return _combineChannels; 90 } 91 92 /** 93 * Sets whether or not histogram should combine all the channels. 94 * 95 * @param combineChannels 96 */ 97 public void setCombineChannels(boolean combineChannels) { 98 _combineChannels = combineChannels; 99 } 100 101 /** 102 * Gets whether or not histogram should automatically scale to values. 103 * 104 * @return whether automatically scales 105 */ 106 public boolean getAutoScale() { 107 return _autoScale; 108 } 109 110 /** 111 * Sets whether or not histogram should automatically scale to values. 112 * 113 * @param auto whether automatically scales 114 */ 115 public void setAutoScale(boolean autoScale) { 116 _autoScale = autoScale; 117 } 118 130 _displayChannels = displayChannels; 131 } 132 119 133 /** 120 134 * Gets minimum and maximum extents of the view. … … 207 221 } 208 222 209 if (_auto Scale) {223 if (_autoRange) { 210 224 if (_combineChannels) { 211 225 // LUT and view bounded by data for all channels -
trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/HistogramPanel.java
r7838 r7847 19 19 * bounds of the view. Dragging the cursor off the edge stretches those bounds. 20 20 * 21 * @author Aivar Grislis 21 * @author Aivar Grislis grislis at wisc dot edu 22 22 */ 23 23 public class HistogramPanel extends JPanel { 24 static final int ONE_HEIGHT = 20;25 static final int FUDGE_FACTOR = 4;24 private static final int ONE_HEIGHT = 20; 25 private static final int FUDGE_FACTOR = 4; 26 26 private IHistogramPanelListener _listener; 27 27 private final Object _synchObject = new Object(); … … 30 30 private int _inset; 31 31 private int[] _bins; 32 private int _max ;32 private int _maxBinCount; 33 33 private Integer _minCursor; 34 34 private Integer _maxCursor; … … 75 75 public void mouseReleased(MouseEvent e) { 76 76 boolean changed = false; 77 int min = 0; // makes the compiler happy 78 int max = 0; 77 79 synchronized (_synchObject) { 78 80 if (_draggingMinCursor) { … … 101 103 _draggingMaxCursor = false; 102 104 changed = true; 103 } 105 } 106 if (changed) { 107 // convert to 0..width-1 range 108 min = _minCursor - _inset + 1; 109 max = _maxCursor - _inset - 1; 110 } 104 111 } 105 112 if (changed) { 113 if (null != _listener) { 114 _listener.setMinMaxLUTPixels(min, max); 115 } 106 116 repaint(); 107 if (null != _listener) {108 // convert to 0..width - 1 range109 int min = _minCursor - _inset + 1; //TODO _min/_maxCursor c/b changed by now110 int max = _maxCursor - _inset - 1;111 _listener.setMinMax(min, max);112 }113 117 } 114 118 } … … 133 137 public void mouseDragged(MouseEvent e) { 134 138 boolean changed = false; 139 int min = 0; // makes the compiler happy 140 int max = 0; 135 141 synchronized (_synchObject) { 136 142 if (_draggingMinCursor) { … … 155 161 } 156 162 changed = true; 157 } 163 } 164 if (changed) { 165 // convert to 0..width-1 range 166 min = _minCursor - _inset + 1; 167 max = _maxCursor - _inset - 1; 168 } 169 158 170 } 159 171 if (changed) { 172 if (null != _listener) { 173 // report dragged cursor position 174 _listener.dragMinMaxPixels(min, max); 175 } 160 176 repaint(); 161 162 if (null != _listener) {163 // convert to 0..width - 1 range164 int min = _minCursor - _inset + 1;165 int max = _maxCursor - _inset - 1;166 // report dragged cursor position167 _listener.dragMinMax(min, max);168 }169 177 } 170 178 } … … 187 195 */ 188 196 public void setBins(int[] bins) { 189 System.out.println("SET BINS");190 197 synchronized (_synchObject) { 191 198 _bins = bins; 192 _max = Integer.MIN_VALUE;199 _maxBinCount = Integer.MIN_VALUE; 193 200 for (int i = 0; i < bins.length; ++i) { 194 if (bins[i] > _max ) {195 _max = bins[i];201 if (bins[i] > _maxBinCount) { 202 _maxBinCount = bins[i]; 196 203 } 197 204 } … … 201 208 202 209 /** 203 * Changes cursors and redraws. 210 * Changes cursors and redraws. Note that when they are both null no 211 * cursor is diaplayed. 204 212 * 205 213 * @param minCursor … … 213 221 _draggingMinCursor = _draggingMaxCursor = false; 214 222 } 223 else { 224 // the cursors actually bracket the specified pixels 225 --_minCursor; 226 ++_maxCursor; 227 } 215 228 } 216 229 repaint(); 217 230 } 231 218 232 219 233 @Override … … 232 246 } 233 247 else { 234 height = (int) ((_height - ONE_HEIGHT) * Math.log(_bins[i]) / Math.log(_max )) + ONE_HEIGHT;248 height = (int) ((_height - ONE_HEIGHT) * Math.log(_bins[i]) / Math.log(_maxBinCount)) + ONE_HEIGHT; 235 249 } 236 250 if (height > _height) { -
trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/HistogramTool.java
r7846 r7847 33 33 34 34 /** 35 * This is the main class for th ishistogram tool. It handles layout and wiring35 * This is the main class for the histogram tool. It handles layout and wiring 36 36 * of UI components and the logic of updating the histogram. 37 37 * … … 49 49 private static HistogramTool INSTANCE = null; 50 50 private final Object _synchObject = new Object(); 51 private JFrame _frame; 51 52 private HistogramData _histogramData; 52 private JFrame _frame;53 53 private HistogramPanel _histogramPanel; 54 54 private ColorBarPanel _colorBarPanel; … … 64 64 _colorBarPanel = new ColorBarPanel(WIDTH, INSET, COLORBAR_HEIGHT); 65 65 _colorBarPanel.setLUT(getLUT()); 66 _uiPanel = new UIPanel( );66 _uiPanel = new UIPanel(true); 67 67 _uiPanel.setListener(new UIPanelListener()); 68 68 … … 75 75 _frame.pack(); 76 76 _frame.setVisible(true); 77 78 //TODO FOR A TEST:79 _histogramPanel.setCursors(3, 44);80 77 } 81 78 … … 107 104 } 108 105 109 //TODO ARG Kludge:110 106 // IJ converts the FloatProcessor to 8-bits and then uses this palette 111 107 // for display. Unfortunately values less than or greater than the LUT 112 108 // range still get displayed with LUT colors. To work around this, use 113 // only 254 of the LUT colors. 109 // only 254 of the LUT colors. The first and last colors will represent 110 // values less than and greater than the LUT range respectively. 114 111 115 112 colorModel = PaletteFix.fixIndexColorModel(colorModel, Color.BLACK, Color.WHITE); … … 118 115 119 116 /** 120 * Gets a LUT. 117 * Gets a LUT. Temporary expedient, belongs elsewhere. 121 118 * 122 119 * @return … … 129 126 130 127 /** 128 * This method should be called whenever a new set of histogram values is 129 * to be displayed (i.e. when a different image gets focus). 130 * 131 131 * @param histogramData 132 132 */ 133 //TODO this method is called from the focus listener only???134 // what about changes during the fit?135 // How is initial histogramData aassigned?136 133 public void setHistogramData(HistogramData histogramData) { 134 double[] minMaxView; 135 double[] minMaxLUT; 137 136 synchronized (_synchObject) { 138 137 _histogramData = histogramData; 139 } 138 _histogramData.setListener(new HistogramDataListener()); 139 minMaxView = _histogramData.getMinMaxView(); 140 minMaxLUT = _histogramData.getMinMaxLUT(); 141 } 142 140 143 if (_frame.isVisible()) { 141 144 _frame.setVisible(true); 142 145 } 143 146 _frame.setTitle(histogramData.getTitle()); 147 144 148 _histogramPanel.setBins(histogramData.binValues(WIDTH)); 145 _histogramData.setListener(new HistogramDataListener()); //TODO a new one, or reuse existing? 149 //_histogramPanel.setCursors(0.0, 0.0); set cursors if not autoranging 150 151 _uiPanel.setAutoRange(histogramData.getAutoRange()); 152 _uiPanel.setCombineChannels(histogramData.getCombineChannels()); 153 _uiPanel.setDisplayChannels(histogramData.getDisplayChannels()); 154 _uiPanel.setMinMaxLUT(minMaxLUT[0], minMaxLUT[1]); 155 156 _colorBarPanel.setMinMax(minMaxView[0], minMaxView[1], 157 minMaxLUT[0], minMaxLUT[1]); 146 158 } 147 159 … … 180 192 int[] bins = _histogramData.binValues(WIDTH); 181 193 _histogramPanel.setBins(bins); 182 //TODO does this need to be fixed 256->254???183 194 _colorBarPanel.setMinMax(minView, maxView, minLUT, maxLUT); 184 195 } … … 189 200 */ 190 201 private class HistogramDataListener implements IHistogramDataListener { 202 203 @Override 191 204 public void minMaxChanged(double minView, double maxView, 192 205 double minLUT, double maxLUT) { … … 201 214 private Timer _timer = null; 202 215 private volatile int _dragPixels; 203 204 private HistogramPanelListener() { }205 216 206 217 /** … … 212 223 * @param max 213 224 */ 214 public void setMinMax (int min, int max) {225 public void setMinMaxLUTPixels(int min, int max) { 215 226 killTimer(); 216 227 … … 218 229 double minLUT = pixelToValue(min); 219 230 double maxLUT = pixelToValue(max); 220 231 221 232 // set min and max on UI panel 222 233 _uiPanel.setMinMaxLUT(minLUT, maxLUT); 223 234 224 // redraw image and save225 _histogramData.setMinMaxLUT(minLUT, maxLUT);226 227 235 // redraw color bar 228 236 _colorBarPanel.setMinMaxLUT(minLUT, maxLUT); 237 238 // save and redraw image 239 synchronized (_synchObject) { 240 _histogramData.setMinMaxLUT(minLUT, maxLUT); 241 } 229 242 } 230 243 … … 237 250 */ 238 251 @Override 239 public void dragMinMax (int min, int max) {252 public void dragMinMaxPixels(int min, int max) { 240 253 System.out.println("dragMinMax(" + min + "," + max + ")"); 241 254 if (min < 0 || max >= PaletteFix.ADJUSTED_SIZE) { … … 255 268 } 256 269 else { 257 // dragging within bounds now, kill the periodic task 270 // dragging within bounds now, kill the periodic task, if any 258 271 killTimer(); 272 _uiPanel.dragMinMaxLUT(pixelToValue(min), pixelToValue(max)); 259 273 } 260 274 } … … 310 324 _colorBarPanel.setMinMax(minView, maxView, minLUT, maxLUT); 311 325 System.out.println("set to " + minView + " " + maxView); 312 // _colorBarPanel. update color bar also313 326 } 314 327 } … … 317 330 318 331 private class UIPanelListener implements IUIPanelListener { 319 //tOEOprivate UIPanelListener() { } 320 @Override 321 public void setAuto(boolean auto) { 332 @Override 333 public void setAutoRange(boolean autoRange) { 334 System.out.println("HistogramTool.UIPanelListener.setAutoRange(" + autoRange + ")"); 335 synchronized (_synchObject) { 336 _histogramData.setAutoRange(autoRange); 337 } 322 338 // turn on/off the cursors 323 339 // they are usually at -1 & 255 … … 327 343 // autorange on, should calculate new bounds 328 344 } 329 330 @Override 331 public void setMinMaxLUT(double min, double max) { 332 // user has typed in some new values 333 // can't be autoranging 334 // adjust cursors and color bar and possibly histogram 345 346 @Override 347 public void setCombineChannels(boolean combineChannels) { 348 synchronized (_synchObject) { 349 _histogramData.setCombineChannels(combineChannels); 350 } 351 //TODO 352 System.out.println("HistogramTool.UIPanelListener.setCombineChannels(" + combineChannels + ")"); 353 } 354 355 @Override 356 public void setDisplayChannels(boolean displayChannels) { 357 synchronized (_synchObject) { 358 _histogramData.setDisplayChannels(displayChannels); 359 } 360 //TODO 361 System.out.println("HistogramTool.UIPanelListener.setDisplayChannels(" + displayChannels + ")"); 362 } 363 364 @Override 365 public void setMinMaxLUT(double minLUT, double maxLUT) { 366 boolean changed = false; 367 double minView = 0; 368 double maxView = 0; 369 370 // silently ignores errors; c/b temporary condition such as setting 371 // maximum before minimum 372 if (minLUT < maxLUT) { 373 changed = true; 374 375 synchronized (_synchObject) { 376 // expand the view to fit the LUT 377 double[] minMaxView = _histogramData.getMinMaxView(); 378 minView = Math.min(minLUT, minMaxView[0]); 379 maxView = Math.max(maxLUT, minMaxView[1]); 380 _histogramData.setMinMaxView(minView, maxView); 381 _histogramData.setMinMaxLUT(minLUT, maxLUT); 382 } 383 } 384 385 if (changed) { 386 System.out.println("CHANGED:" + minView + " " + maxView); 387 // update histogram and color bar 388 changed(minView, maxView, minLUT, maxLUT); 389 } 390 System.out.println("new min LUT is " + minLUT + "new max LUT is " + maxLUT); 335 391 } 336 392 } -
trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/IHistogramPanelListener.java
r7838 r7847 21 21 * @param max 22 22 */ 23 public void setMinMax (int min, int max);23 public void setMinMaxLUTPixels(int min, int max); 24 24 25 25 /** … … 29 29 * @param max 30 30 */ 31 public void dragMinMax (int min, int max);31 public void dragMinMaxPixels(int min, int max); 32 32 33 33 /** -
trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/IUIPanelListener.java
r7845 r7847 13 13 14 14 /** 15 * User has clicked the auto checkbox.15 * User has clicked the auto ranging checkbox. 16 16 * 17 * @param auto 17 * @param autoRange 18 18 */ 19 public void setAuto(boolean auto); 19 public void setAutoRange(boolean autoRange); 20 21 /** 22 * User has clicked the combine channels checkbox. 23 */ 24 public void setCombineChannels(boolean combineChannels); 20 25 21 26 /** 22 * User has entered new min or max LUT values. 27 * User has clicked the display channels checkbox. 28 * 29 * @param displayChannels 30 */ 31 public void setDisplayChannels(boolean displayChannels); 32 33 /** 34 * User has entered new min/max LUT value. 23 35 * 24 36 * @param min -
trunk/projects/slim-plugin/src/main/java/imagej/slim/histogram/UIPanel.java
r7846 r7847 12 12 import javax.swing.BoxLayout; 13 13 import javax.swing.JCheckBox; 14 import javax.swing.JComponent;15 import javax.swing.JFrame;16 import javax.swing.JLabel;17 14 import javax.swing.JPanel; 18 import javax.swing.JFormattedTextField;19 15 import javax.swing.JTextField; 20 16 21 17 /** 22 * 23 * @author aivar 18 * This class holds the text fields that show the current minimum and maximum 19 * LUT range. It also has checkboxes to control how the ranges are derived 20 * and displayed. 21 * 22 * @author Aivar Grislis grislis at wisc dot edu 24 23 */ 25 24 public class UIPanel extends JPanel { 25 private static final int DIGITS = 4; 26 26 IUIPanelListener _listener; 27 JCheckBox m_autoCheckBox; 28 JTextField m_startTextField; 29 JTextField m_stopTextField; 30 boolean m_auto; 31 double m_start; 32 double m_stop; 33 double m_min; 34 double m_max; 35 36 /** 37 * Constructor. Passed in an initial state and a state change //TODO this doc. et. al. outdated 38 * listener. 39 * 40 * @param auto 41 * @param start 42 * @param stop 43 */ 44 UIPanel() { 27 JCheckBox _autoRangeCheckBox; 28 JCheckBox _combineChannelsCheckBox; 29 JCheckBox _displayChannelsCheckBox; 30 JTextField _minTextField; 31 JTextField _maxTextField; 32 boolean _autoRange; 33 boolean _combineChannels; 34 boolean _displayChannels; 35 double _minLUT; 36 double _maxLUT; 37 38 /** 39 * Constructor. 40 * 41 * @param hasChannels 42 */ 43 public UIPanel(boolean hasChannels) { 45 44 super(); 46 //m_listener = listener; 47 48 m_auto= true;49 m_start = m_stop = m_min = m_max = 0.0; //TODO gotta be a better way45 46 // initial state 47 _autoRange = true; 48 _minLUT = _maxLUT = 0.0; 50 49 51 50 setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); 52 51 52 // make a panel for the min/max readouts 53 53 JPanel readOutPanel = new JPanel(); 54 54 readOutPanel.setLayout(new BoxLayout(readOutPanel, BoxLayout.X_AXIS)); 55 55 56 m_startTextField = new JTextField(); 57 m_startTextField.setText("" + m_start); 58 m_startTextField.addActionListener( 56 _minTextField = new JTextField(); 57 _minTextField.addActionListener( 59 58 new ActionListener() { 60 public void actionPerformed(ActionEvent e) { 61 m_start = Double.parseDouble(m_startTextField.getText()); 62 // m_listener.setRange(m_auto, m_start, m_stop, m_min, m_max); 59 public void actionPerformed(ActionEvent event) { 60 try { 61 _minLUT = Double.parseDouble(_minTextField.getText()); 62 if (null != _listener) { 63 _listener.setMinMaxLUT(_minLUT, _maxLUT); 64 } 65 } 66 catch (NumberFormatException exception) { 67 _minTextField.setText("" + _minLUT); 68 } 63 69 } 64 70 } 65 71 ); 66 readOutPanel.add(m_startTextField); 67 68 m_stopTextField = new JTextField(); 69 m_startTextField.setText("" + m_stop); 70 m_stopTextField.addActionListener( 72 readOutPanel.add(_minTextField); 73 74 _maxTextField = new JTextField(); 75 _maxTextField.addActionListener( 71 76 new ActionListener() { 72 public void actionPerformed(ActionEvent e) { 73 m_stop = Double.parseDouble(m_stopTextField.getText()); 74 // m_listener.setRange(m_auto, m_start, m_stop, m_min, m_max); 77 public void actionPerformed(ActionEvent event) { 78 try { 79 _maxLUT = Double.parseDouble(_maxTextField.getText()); 80 if (null != _listener) { 81 _listener.setMinMaxLUT(_minLUT, _maxLUT); 82 } 83 } 84 catch (NumberFormatException exception) { 85 _maxTextField.setText("" + _maxLUT); 86 } 75 87 } 76 88 } 77 89 ); 78 readOutPanel.add( m_stopTextField);90 readOutPanel.add(_maxTextField); 79 91 add(readOutPanel); 80 92 81 m_autoCheckBox = new JCheckBox("Auto", m_auto);82 m_autoCheckBox.addItemListener(93 _autoRangeCheckBox = new JCheckBox("Automatic Ranging", _autoRange); 94 _autoRangeCheckBox.addItemListener( 83 95 new ItemListener() { 84 96 public void itemStateChanged(ItemEvent e) { 85 m_auto = m_autoCheckBox.isSelected(); 86 if (m_auto) { 87 m_start = m_min; 88 m_startTextField.setText("" + m_start); 89 90 m_stop = m_max; 91 m_stopTextField.setText("" + m_stop); 92 } 93 enableAppropriately(); 94 // m_listener.setRange(m_auto, m_start, m_stop, m_min, m_max); 97 _autoRange = _autoRangeCheckBox.isSelected(); 98 enableTextFields(_autoRange); 99 if (null != _listener) { 100 _listener.setAutoRange(_autoRange); 101 } 95 102 } 96 103 } 97 104 ); 98 add(m_autoCheckBox); 99 100 101 enableAppropriately(); 102 } 103 105 add(_autoRangeCheckBox); 106 107 if (hasChannels) { 108 _combineChannelsCheckBox = 109 new JCheckBox("Combine Channels", _combineChannels); 110 _combineChannelsCheckBox.addItemListener( 111 new ItemListener() { 112 public void itemStateChanged(ItemEvent e) { 113 _combineChannels = _combineChannelsCheckBox.isSelected(); 114 if (null != _listener) { 115 _listener.setCombineChannels(_combineChannels); 116 } 117 } 118 } 119 ); 120 add(_combineChannelsCheckBox); 121 122 _displayChannelsCheckBox = 123 new JCheckBox("Display Channels", _displayChannels); 124 _displayChannelsCheckBox.addItemListener( 125 new ItemListener() { 126 public void itemStateChanged(ItemEvent e) { 127 _displayChannels = _displayChannelsCheckBox.isSelected(); 128 if (null != _listener) { 129 _listener.setDisplayChannels(_displayChannels); 130 } 131 } 132 } 133 ); 134 add(_displayChannelsCheckBox); 135 } 136 137 enableTextFields(_autoRange); 138 } 139 140 /** 141 * Sets a listener for this UI panel. Listener is unique. 142 * 143 * @param listener 144 */ 104 145 public void setListener(IUIPanelListener listener) { 105 146 _listener = listener; 106 147 } 107 148 108 public void setAuto(boolean auto) { 109 110 } 111 149 public void setAutoRange(boolean autoRange) { 150 _autoRange = autoRange; 151 _autoRangeCheckBox.setSelected(autoRange); 152 enableTextFields(autoRange); 153 } 154 155 public void setCombineChannels(boolean combineChannels) { 156 _combineChannels = combineChannels; 157 _combineChannelsCheckBox.setSelected(combineChannels); 158 } 159 160 public void setDisplayChannels(boolean displayChannels) { 161 _displayChannels = displayChannels; 162 _displayChannelsCheckBox.setSelected(displayChannels); 163 } 164 165 /** 166 * Called when the user is dragging the cursors on the histogram panel. 167 * 168 * @param min 169 * @param max 170 */ 171 public void dragMinMaxLUT(double min, double max) { 172 System.out.println("UIPanel.dragMinMaxLUT"); 173 showMinMaxLUT(min, max); 174 } 175 176 /** 177 * Called when the user sets new cursors on the histogram panel. 178 * 179 * @param min 180 * @param max 181 */ 112 182 public void setMinMaxLUT(double min, double max) { 113 System.out.println("SetMinMaxLUT " + min + " " + max); 114 m_startTextField.setText("" + min); 115 m_stopTextField.setText("" + max); 116 } 117 118 // not 119 /** 120 * IColorizeRangeListener method. Gets external changes to settings. 121 * 122 * @param auto 123 * @param start 124 * @param stop 125 * @param min 126 * @param max 127 */ 128 public void setRange(boolean auto, double start, double stop, double min, double max) { 129 if (auto != m_auto) { 130 m_auto = auto; 131 m_autoCheckBox.setSelected(auto); 132 enableAppropriately(); 133 } 134 135 if (start != m_start) { 136 m_start = start; 137 m_startTextField.setText("" + start); 138 } 139 140 if (stop != m_stop) { 141 m_stop = stop; 142 m_stopTextField.setText("" + stop); 143 } 144 m_min = min; 145 m_max = max; 146 } 147 148 /** 149 * Enable/disable start/stop text fields. 150 */ 151 private void enableAppropriately() { 152 m_startTextField.setEnabled(!m_auto); 153 m_stopTextField.setEnabled(!m_auto); 154 } 183 System.out.println("UIPanel.setMinMaxLUT"); 184 showMinMaxLUT(min, max); 185 //TODO anything else? if not combine these two methods 186 } 187 188 /** 189 * Enable/disable min/max text fields as appropriate. 190 */ 191 private void enableTextFields(boolean auto) { 192 _minTextField.setEnabled(!auto); 193 _maxTextField.setEnabled(!auto); 194 } 195 196 /* 197 * Shows the minimum and maximum LUT readouts. Limits number of digits 198 * shown. 199 */ 200 private void showMinMaxLUT(double min, double max) { 201 DoubleFormatter minFormatter = new DoubleFormatter(true, DIGITS, min); 202 _minTextField.setText(minFormatter.getText()); 203 _minLUT = Double.parseDouble(_minTextField.getText()); 204 DoubleFormatter maxFormatter = new DoubleFormatter(false, DIGITS, max); 205 _maxTextField.setText(maxFormatter.getText()); 206 _maxLUT = Double.parseDouble(_maxTextField.getText()); 207 } 155 208 }
Note: See TracChangeset
for help on using the changeset viewer.