Blame view

src/osp/ui/OSPE_ImageCutLevelsDialog.java 3.2 KB
fe0fb87e   Elodie Bourrec   First push to cre...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package osp.ui;

import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDialog;

import jsky.image.BasicImageReadableProcessor;
import jsky.image.gui.OSPE_ImageCutLevelsPanel;
import osp.Image;

/**
 * Dialog to display and to modify image Cuts Levels. 
 * Call OSPE_imageCutlevel panel implemented from the JSky's imageCutLevel one.
 * 
 * @author SB 
 * Modifications EB, JMG
 */
public class OSPE_ImageCutLevelsDialog extends JDialog {
	private static final long serialVersionUID = 1L;
	private BasicImageReadableProcessor navigatorImageDisplay;
	private OSPE_ImageCutLevelsPanel imageCutLevelsPanel;
	private Image image;

	/**
	 * Constructor of OSPE_ImageCutLevelsPanel.
	 * 
	 * This is to change the image's cuts levels and to save them at window's
	 * close action
	 * @param ospe_NavigatorImageDisplay 
	 */
	public OSPE_ImageCutLevelsDialog(OSPE_NavigatorImageDisplay ospe_NavigatorImageDisplay) {
		navigatorImageDisplay = ospe_NavigatorImageDisplay;
		this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		
		// On close, if the image's cuts levels have changed, save them
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosed(WindowEvent e) {
				saveParamCuts();
				super.windowClosed(e);
			}

		});
	}

	public void saveParamCuts() {
		double hiIm, loIm;
	
		// get the original Cuts levels.
		if (image != null) 
		{
		hiIm = image.getHighCut();
		loIm = image.getLowCut();
	
		// Get the current cuts levels on display
		double highCutLevel = navigatorImageDisplay.getImageProcessor().getHighCut();
		double lowCutLevel = navigatorImageDisplay.getImageProcessor().getLowCut();
		imageCutLevelsPanel.setValues(lowCutLevel, highCutLevel);
		imageCutLevelsPanel.updateCutLevels();
	
		if ((hiIm != highCutLevel) || (loIm != lowCutLevel)) 
		{
			// save the change
			image.setHighCut(highCutLevel);
			image.setLowCut(lowCutLevel);
			image.cutsChanged = true;
			
		}
		}
	}
	/**
	 * Create the cut levels for the display in the OSPE_NavigatorImageDisplay
	 * interface.
	 * 
	 * @param navImageDisplay
	 *            : OSPE_NavigatorImageDisplay, the display windows for the
	 *            image displayed.
	 * @param im
	 *            : Image, the image displayed.
	 * 
	 */
	public void setDisplay(Image image) {

		this.image = image;
		
		if (imageCutLevelsPanel !=null){
			this.getContentPane().remove(imageCutLevelsPanel);
		}
		
		if (image == null) {
			imageCutLevelsPanel = null;
		} else {
			imageCutLevelsPanel = new OSPE_ImageCutLevelsPanel(navigatorImageDisplay, this);
			this.getContentPane().add(imageCutLevelsPanel, BorderLayout.CENTER);
			pack();
			setVisible(true);
			updateCutLevels(image.getLowCut(), image.getHighCut());
		}
	}

	/**
	 * Test if the cuts levels panel is displayed.
	 * 
	 * @return true/false
	 */
	public boolean hasDisplay() {
		return imageCutLevelsPanel != null;
	}

	public void updateCutLevels(double lo, double hi) {
		if (hasDisplay()){
			imageCutLevelsPanel.setValues(lo, hi);
			imageCutLevelsPanel.updateCutLevels();
		}
		
	}
	
	public Image getImage(){
		return image;
	}
}