OSPE_PickObjectFrame.java
3.96 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
package osp.ui;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Point2D;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import jsky.image.gui.PickObjectFrame;
import osp.utils.CustomJDialog;
/**
* Jsky utility to choose objects on the image with theirs characteristics and
* their center
*
* @author SB Update : EB
*/
public class OSPE_PickObjectFrame extends PickObjectFrame {
private static final long serialVersionUID = 1L;
protected OSPE_VisuPanel visuPanel;
protected JButton closeButton;
protected int addedObjects;
private JButton btCancel;
public OSPE_PickObjectFrame(OSPE_VisuPanel v) {
super(v.getNavigatorImageDisplay());
visuPanel = v;
this.setLocationRelativeTo(visuPanel);
Container c = getContentPane();
JPanel p0 = (JPanel) c.getComponent(0); // Main Panel
/*
* Il n'ya qu'un seul panel dans le Container p0 a 3 panels : 0 : image
* zoom de l'objet qd bt pick selectionne 1 : Image statistics. 2 :
* Boutons panel 3 : Multi-pick option (checkBox)
*/
// Multi-Pick option
JPanel p3 = (JPanel) getPickObject().getComponent(3);
JPanel p2 = (JPanel) p0.getComponent(2); // buttons panel
JButton addButton = (JButton) p2.getComponent(1);
addButton.setVisible(false);
JButton pickButton = (JButton) p2.getComponent(0);
pickButton.setVisible(false);
closeButton = (JButton) p2.getComponent(2); // Close button
getPickObject().remove(3); // enleve (aussi) le panel Multi-Pick option
this.setAlwaysOnTop(true);
this.setVisible(true);
pickButton.doClick();
// keep the windows on first plan during pick operation
// Active le bouton Pick
// btP.doClick();
// selection of the multi-Pick option
this.setTitle("Add Objects");
((JCheckBox) p3.getComponent(0)).setSelected(true);
addedObjects = 0;
p2.add(getCancelButton(), 0);
// Add objects
getPickObject().addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Point2D.Double pos = new Point2D.Double(getPickObject().getStatistics().getImageX(),
getPickObject().getStatistics().getImageY());
visuPanel.addObject("-1",-1," ", pos,0);
if (visuPanel.getFov().getCurrentImage().getNbrObjects() > 0 &&
visuPanel.getFov().getCurrentImage().getLastObject().getPosition().equals(pos))
addedObjects++;
}
});
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
close();
}
});
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
closeButton.doClick();
}
});
}
private JButton getCancelButton() {
if (btCancel == null){
btCancel = new JButton("Cancel");
btCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (addedObjects > 0) {
String mess = "You are going to cancel and remove all the objects you added. Are you sure?";
CustomJDialog dialog = new CustomJDialog(mess, CustomJDialog._WARNING_,
CustomJDialog._YESNO_BUTTON_, OSPE_PickObjectFrame.this);
if (dialog.getValue() == JOptionPane.YES_OPTION) {
for (int i = 0; i < addedObjects; i++)
visuPanel.getFov().getCurrentImage().removeLastObject();
visuPanel.getNavigatorImageDisplay().updateImage();
visuPanel.updateByHand();
visuPanel.getOspeControl().getActionControl().setSaveNeeded(false);
closeButton.doClick();
}
} else{
closeButton.doClick();
}
}
});
}
return btCancel;
}
/**
*
*/
private void close() {
visuPanel.closePickObjFrame();
}
}