OSPE_MaskPropPanel.java
13 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
package osp.ui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import jsky.coords.DMS;
import jsky.coords.HMS;
import jsky.coords.WorldCoords;
import osp.Image;
import osp.Mask;
import osp.MaskHistory;
import osp.MaskInterface;
import osp.utils.CustomJDialog;
import osp.utils.PropertiesPanel;
/**
* This class represents the mask properties panel found under the project tree.
* It displays the alpha, delta and omega values of the currently displayed mask
* (if there is any) and allows the omega value to be changed manually.
*/
//public class OSPE_MaskPropPanel extends PropertiesPanel implements ChangeListener {
public class OSPE_MaskPropPanel extends PropertiesPanel {
private static final long serialVersionUID = 1L;
/** Name of the panel */
private String title = " Mask Properties ";
/** Number of the "alpha" field */
public static final int alphaC = 0;
/** Number of the "delta" field */
public static final int deltaC = 1;
/** Number of the "set" button field */
// public static final int idBt = 2;
/** Number of the "omega" field (spinner) */
public static final int omegaC = 2;
private String mess;
private FieldOfViewInterface fov;
private Image im;
private MaskInterface currentMaskI;
private StatusInterface mainFrame;
private JComponent compAlpha, compDelta, compOmega;
private JTextField textFieldAlpha, textFieldDelta;
private JSpinner omegaSpin;
/**
* Constructs a new mask properties panel with disabled fields.
*
* @param p The select panel of the application.
* @param fov
* @param mainFrame
*/
public OSPE_MaskPropPanel(final FieldOfViewInterface fov, StatusInterface mainFrame2) {
this.fov = fov;
if (fov.getNbrImages()>0)
{
im=fov.getCurrentImage();
if (im.getNbrMasks()>0)
currentMaskI=fov.getCurrentImage().getCurrentMask();
}
this.mainFrame = mainFrame2;
setTitle(title);
addTextField(alphaC, "Alpha Center");
compAlpha = getJComponent(alphaC);
compAlpha.setEnabled(false);
textFieldAlpha=(JTextField)compAlpha;
addTextField(deltaC, "Delta Center");
compDelta = getJComponent(deltaC);
compDelta.setEnabled(false);
textFieldDelta=(JTextField)compDelta;
textFieldAlpha.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String a=textFieldAlpha.getText();
if (verifyingCoords(a))
maskCenterUpdate();
else
{
new CustomJDialog("The coords format is not correct ! \n (HH:mn:ss.sss)",
CustomJDialog._ERROR_,CustomJDialog._CLOSE_BUTTON_,mainFrame.getVisuPanel() );
}
}
}); // End Action Listener on alpha field
textFieldDelta.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String b= textFieldDelta.getText();
if (verifyingCoords(b))
maskCenterUpdate();
else
{
//System.out.println("MaskPropPan coord pas top");
new CustomJDialog("The coords format is not correct !",
CustomJDialog._ERROR_,CustomJDialog._CLOSE_BUTTON_,mainFrame.getVisuPanel() );
}
}
}); // End Action Listener on delta field
// addButton(idBt," ");
// JButton setBt=(JButton) getJComponent(idBt);
// setBt.addActionListener(new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// System.out.println("M PropPan - set bt ");
// //maskCenterUpdate();
// }
// });
addSpinner(omegaC, "Omega");
compOmega = getJComponent(omegaC);
compOmega.setEnabled(false);
compOmega.setInputVerifier(new DoubleInputVerifier());
omegaSpin= (JSpinner) compOmega;
omegaSpin.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e) {
double newOmg=Double.parseDouble(omegaSpin.getValue().toString());
if (fov.getNbrImages()>0)
{
im=fov.getCurrentImage();
if ((im.getNbrMasks()>0) && (im.getSelectedMask()>-1))
{
currentMaskI= fov.getCurrentMaskOfCurrentImage();
double oOmg=currentMaskI.getOmega();
double diff = Math.abs(oOmg-newOmg);
if (diff > 0.00001)
{
currentMaskI.getHistory().addEntry("Rotate mask");
currentMaskI.getHistory().addAction("setOmega", oOmg);
currentMaskI.setOmega(newOmg);
currentMaskI.update();
mainFrame.getVisuPanel().updateByHand();
mainFrame.updateButtons();
mainFrame.getOspeControl().setSaveNeed(true);
}
}
}
}
});
//
// ActionListener maskCenterListener = new ActionListener() {
// @Override
// public void actionPerformed(ActionEvent e) {
// //currentMask.setAlpha( );
// //currentMask.set
// maskCenterUpdate();
// currentMaskI.update();
// }
// };
// textFieldAlpha.addActionListener(maskCenterListener);
// textFieldDelta.addActionListener(maskCenterListener);
}
protected boolean verifyingCoords(String b) {
// TODO Auto-generated method stub
String chn=b;
if (chn.matches("\\d\\d+:+\\d\\d+:+\\d\\d+\\.+\\d\\d\\d")) return true;
else
return false;
}
protected void maskCenterUpdate() {
// TODO Auto-generated method stub
Double valAlpha, valDelta;
//System.out.println("MaskPropPan - Mask update");
WorldCoords wc=new WorldCoords(textFieldAlpha.getText(),textFieldDelta.getText());
//System.out.println(" Alp "+textFieldAlpha.getText()+ " Delt "+textFieldDelta.getText());
if (fov.getNbrImages()>0)
{
im=fov.getCurrentImage();
if (im.getNbrMasks()>0)
{
currentMaskI = (Mask) fov.getCurrentMaskOfCurrentImage();
valAlpha =wc.getRaDeg();
valDelta = wc.getDecDeg();
Point2D.Double oldMaskCenterWc=new Point2D.Double(currentMaskI.getCenterDeg().getX(),currentMaskI.getCenterDeg().getY());
Point2D.Double oldMaskCenter=new Point2D.Double(currentMaskI.getCenter().getX(),currentMaskI.getCenter().getY());
MaskHistory maskHist=currentMaskI.getHistory();
maskHist.addEntry("Move mask");
maskHist.addAction("setCenter", oldMaskCenter);
maskHist.addAction("setCenterDeg", oldMaskCenterWc);
maskHist.addAction("setCenterWc", oldMaskCenterWc);
Point2D.Double newCenter= new Point2D.Double(valAlpha,valDelta);
Point2D.Double pt=mainFrame.getVisuPanel().setNewMaskCenter(newCenter);
currentMaskI.setCenterWc(newCenter.getX(),newCenter.getY());
currentMaskI.setCenterDeg(newCenter);
currentMaskI.setCenter(pt);
currentMaskI.update();
mainFrame.getVisuPanel().updateByHand();
mainFrame.updateButtons();
mainFrame.getOspeControl().setSaveNeed(true);
}
}
}
/**
* Called automatically when the spinner value is changed by entering a
* value in the spinner's text field. If the value is correct, it changes
* the mask angle to the specified value.
*/
// public void actionPerformed(ActionEvent e) {
// JTextField tf = (JTextField) e.getSource();
// double value;
//
// if (tf == getJComponent(omegaC)) // Omega spinner
// {
// if (tf.getInputVerifier().verify(getJComponent(omegaC))) {
// value = Double.valueOf(tf.getText()).doubleValue();
// fov.getCurrentMaskOfCurrentImage().setOmega(value);
// fov.getCurrentMaskOfCurrentImage().update();
// mainFrame.setStatusBarText(Color.blue, "INFO: Mask angle value is " + value);
// } else
// mainFrame.setStatusBarText(Color.red,
// "WARNING: Mask angle value must be a double !!!");
// }
// }
//TODO to remove?
/**
* Called automatically when the spinner value is changed by clicking on the
* spinner's arrows. It changes the mask angle to the specified value.
* 01/06/2015 NON ! Ne fonctionne pas.
*
*/
// public void stateChanged(ChangeEvent arg0) {
//
// JSpinner tf = (JSpinner) arg0.getSource();
// double value;
//
// if (tf == getJComponent(omegaC)) // Omega spinner
// {
// if (fov.getSelectedImage() >= 0) {
// value = Double.valueOf(String.valueOf(tf.getModel().getValue())).doubleValue();
// if (fov.getSelectedMaskOfCurrentImage() >= 0) {
// MaskInterface currentMask = fov.getCurrentMaskOfCurrentImage();
//
// Double oldOmega = new Double(currentMask.getOmega());
// if (oldOmega.doubleValue() != value && !currentMask.isTurning()) {
// currentMask.addEntryToHistory("Change mask angle");
// currentMask.addActionToHistory("setOmega", oldOmega);
// }
//
// currentMask.setOmega(value);
// currentMask.update();
//
// mainFrame.setStatusBarText(Color.blue, "INFO: Mask angle value is " + value);
// }
// }
// }
// }
//
/**
* Updates the masks data (alpha, delta & omega) in the mask properties
* panel.
* @param isMask
*/
public void updateMaskProp(boolean isMask) {
if (fov.getSelectedImage() >= 0 && fov.getSelectedMaskOfCurrentImage() >= 0) {
MaskInterface currentMask = fov.getCurrentMaskOfCurrentImage();
setValue(OSPE_MaskPropPanel.alphaC, currentMask.getMaskCenterWordlCoord().getRA());
setValue(OSPE_MaskPropPanel.deltaC, currentMask.getMaskCenterWordlCoord().getDec());
setSpinnerValue(OSPE_MaskPropPanel.omegaC, currentMask.getOmega());
getJComponent(OSPE_MaskPropPanel.alphaC).setEnabled(true);
getJComponent(OSPE_MaskPropPanel.deltaC).setEnabled(true);
// getJComponent(OSPE_MaskPropPanel.idBt).setEnabled(true);
getJComponent(OSPE_MaskPropPanel.omegaC).setEnabled(true);
} else {
setValue(OSPE_MaskPropPanel.alphaC, "");
setValue(OSPE_MaskPropPanel.deltaC, "");
setSpinnerValue(OSPE_MaskPropPanel.omegaC, 0);
getJComponent(OSPE_MaskPropPanel.alphaC).setEnabled(false);
getJComponent(OSPE_MaskPropPanel.deltaC).setEnabled(false);
// getJComponent(OSPE_MaskPropPanel.idBt).setEnabled(false);
getJComponent(OSPE_MaskPropPanel.omegaC).setEnabled(false);
}
}
public static void main(String[] args) {
OSPE_MaskPropPanel maskPropPanel = new OSPE_MaskPropPanel(new FieldOfViewInterface() {
private double omega = 0.;
Point2D.Double p = new Point2D.Double(0.0,0.0);
@Override
public int getSelectedMaskOfCurrentImage() {
return 0;
}
@Override
public int getSelectedImage() {
return 0;
}
@Override
public int getNbrImages() {
return 0;
}
@Override
public MaskInterface getCurrentMaskOfCurrentImage() {
return new MaskInterface() {
@Override
public void update() {
}
public void setCenter(Point2D.Double pt) {
p=pt;
}
public void setCenterDeg(Point2D.Double pt) {
p=pt;
}
@Override
public void setOmega(double value) {
omega = value;
}
@Override
public boolean isTurning() {
return false;
}
@Override
public MaskHistory getHistory() {
return null;
}
@Override
public double getOmega() {
return omega;
}
@Override
public void addEntryToHistory(String string) {
}
@Override
public void addActionToHistory(String string, Double oldOmega) {
}
@Override
public HMS getAlpha() {
return new HMS(5.0);
}
@Override
public DMS getDelta() {
return new DMS(2.0);
}
@Override
public java.awt.geom.Point2D.Double getCenter() {
// TODO Auto-generated method stub
return null;
}
@Override
public java.awt.geom.Point2D.Double getCenterDeg() {
// TODO Auto-generated method stub
return null;
}
@Override
public WorldCoords getMaskCenterWordlCoord() {
// TODO Auto-generated method stub
return null;
}
@Override
public void setCenterWc(double ra, double dec) {
// TODO Auto-generated method stub
}
};
}
@Override
public Image getCurrentImage() {
// TODO Auto-generated method stub
return null;
}
}, new StatusInterface() {
@Override
public void setStatusBarText(Color blue, String val) {
System.out.println("Color ="+ blue + ": " + val);
}
@Override
public OSPE_VisuPanel getVisuPanel() {
return null;
}
@Override
public OspeControl getOspeControl() {
return null;
}
@Override
public void setStatusBarText(String val) {
System.out.println(val);
}
@Override
public void updateButtons(){};
});
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(maskPropPanel);
frame.setVisible(true);
frame.pack();
// maskPropPanel.updateMaskProp(false);
}
}