46 |
46 |
|
47 |
47 |
/**
|
48 |
48 |
* Default implementation of the {@link JTaskStatus}.
|
49 |
|
*
|
|
49 |
*
|
50 |
50 |
* @author gvSIG Team
|
51 |
51 |
* @version $Id$
|
52 |
52 |
*/
|
53 |
53 |
public class DefaultJTaskStatus extends JTaskStatus implements Observer {
|
54 |
54 |
|
55 |
|
private static final long serialVersionUID = -1908456747637477552L;
|
|
55 |
private static final long serialVersionUID = -1908456747637477552L;
|
56 |
56 |
|
57 |
|
private JLabel titlelabel = null;
|
58 |
|
private JLabel messagelabel = null;
|
59 |
|
private JProgressBar progressBar = null;
|
60 |
|
private JButton cancelRequestButton = null;
|
61 |
|
private JButton removeTaskButton;
|
|
57 |
private JLabel titlelabel = null;
|
|
58 |
private JLabel messagelabel = null;
|
|
59 |
private JProgressBar progressBar = null;
|
|
60 |
private JButton cancelRequestButton = null;
|
|
61 |
private JButton removeTaskButton;
|
62 |
62 |
|
63 |
|
private boolean showCancelButton;
|
64 |
|
private boolean showRemoveTaskButton;
|
|
63 |
private boolean showCancelButton;
|
|
64 |
private boolean showRemoveTaskButton;
|
65 |
65 |
|
66 |
|
private TaskStatus taskStatus;
|
|
66 |
private TaskStatus taskStatus;
|
67 |
67 |
|
68 |
|
public DefaultJTaskStatus() {
|
69 |
|
this.taskStatus = null;
|
70 |
|
this.showCancelButton = true;
|
71 |
|
this.createComponents();
|
72 |
|
}
|
73 |
|
|
74 |
|
public DefaultJTaskStatus(TaskStatus taskStatus) {
|
75 |
|
this();
|
76 |
|
this.bind(taskStatus);
|
77 |
|
}
|
78 |
|
|
79 |
|
public boolean getShowCancelButton() {
|
80 |
|
return this.showCancelButton;
|
81 |
|
}
|
82 |
|
|
83 |
|
public void setShowCancelButton(boolean showCancelButton) {
|
84 |
|
this.showCancelButton = showCancelButton;
|
85 |
|
if( this.cancelRequestButton != null ) {
|
86 |
|
this.cancelRequestButton.setVisible(this.showCancelButton);
|
87 |
|
}
|
88 |
|
}
|
89 |
|
|
90 |
|
public boolean getShowRemoveTaskButton() {
|
91 |
|
return this.showRemoveTaskButton;
|
92 |
|
}
|
93 |
|
|
94 |
|
public void setShowRemoveTaskButton(boolean showRemoveTaskButton) {
|
95 |
|
this.showRemoveTaskButton = showRemoveTaskButton;
|
96 |
|
if( this.removeTaskButton != null ) {
|
97 |
|
this.removeTaskButton.setVisible(this.showRemoveTaskButton);
|
98 |
|
}
|
99 |
|
}
|
100 |
|
|
101 |
|
public JComponent asJComponent() {
|
102 |
|
return this;
|
103 |
|
}
|
|
68 |
public DefaultJTaskStatus() {
|
|
69 |
this.taskStatus = null;
|
|
70 |
this.showCancelButton = true;
|
|
71 |
this.createComponents();
|
|
72 |
}
|
104 |
73 |
|
105 |
|
public void bind(TaskStatus taskStatus) {
|
106 |
|
if( this.taskStatus!=null ) {
|
107 |
|
this.taskStatus.deleteObserver(this);
|
108 |
|
}
|
109 |
|
this.taskStatus = taskStatus;
|
110 |
|
if( this.taskStatus!=null ) {
|
111 |
|
this.taskStatus.addObserver(this);
|
112 |
|
}
|
113 |
|
}
|
|
74 |
public DefaultJTaskStatus(TaskStatus taskStatus) {
|
|
75 |
this();
|
|
76 |
this.bind(taskStatus);
|
|
77 |
}
|
114 |
78 |
|
115 |
|
private void createComponents() {
|
116 |
|
this.titlelabel = new JLabel();
|
117 |
|
|
118 |
|
this.progressBar = new JProgressBar(1,100);
|
|
79 |
public boolean getShowCancelButton() {
|
|
80 |
return this.showCancelButton;
|
|
81 |
}
|
|
82 |
|
|
83 |
public void setShowCancelButton(boolean showCancelButton) {
|
|
84 |
this.showCancelButton = showCancelButton;
|
|
85 |
if (this.cancelRequestButton != null) {
|
|
86 |
this.cancelRequestButton.setVisible(this.showCancelButton);
|
|
87 |
}
|
|
88 |
}
|
|
89 |
|
|
90 |
public boolean getShowRemoveTaskButton() {
|
|
91 |
return this.showRemoveTaskButton;
|
|
92 |
}
|
|
93 |
|
|
94 |
public void setShowRemoveTaskButton(boolean showRemoveTaskButton) {
|
|
95 |
this.showRemoveTaskButton = showRemoveTaskButton;
|
|
96 |
if (this.removeTaskButton != null) {
|
|
97 |
this.removeTaskButton.setVisible(this.showRemoveTaskButton);
|
|
98 |
}
|
|
99 |
}
|
|
100 |
|
|
101 |
public JComponent asJComponent() {
|
|
102 |
return this;
|
|
103 |
}
|
|
104 |
|
|
105 |
public void bind(TaskStatus taskStatus) {
|
|
106 |
if (this.taskStatus != null) {
|
|
107 |
this.taskStatus.deleteObserver(this);
|
|
108 |
}
|
|
109 |
this.taskStatus = taskStatus;
|
|
110 |
if (this.taskStatus != null) {
|
|
111 |
this.taskStatus.addObserver(this);
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
private void createComponents() {
|
|
116 |
this.titlelabel = new JLabel();
|
|
117 |
|
|
118 |
this.progressBar = new JProgressBar(1, 100);
|
119 |
119 |
this.progressBar.setPreferredSize(new Dimension(200, 10));
|
120 |
|
this.progressBar.setIndeterminate(false);
|
121 |
|
this.progressBar.setBorderPainted(true);
|
122 |
|
|
123 |
|
this.cancelRequestButton = new JButton();
|
124 |
|
this.cancelRequestButton.setPreferredSize( new Dimension(16, 16));
|
125 |
|
this.cancelRequestButton.setBorderPainted(false);
|
126 |
|
this.cancelRequestButton.setIcon( getIcon("cancelRequestButton.png"));
|
127 |
|
this.cancelRequestButton.setDisabledIcon( getIcon("disabledCancelRequestButton.png") );
|
128 |
|
if( !this.showCancelButton ) {
|
129 |
|
this.cancelRequestButton.setVisible(this.showCancelButton);
|
130 |
|
}
|
131 |
|
this.cancelRequestButton.addActionListener(new ActionListener() {
|
132 |
|
public void actionPerformed(ActionEvent arg0) {
|
133 |
|
cancelRequestButton.setEnabled(false);
|
134 |
|
taskStatus.cancelRequest();
|
135 |
|
}
|
136 |
|
});
|
137 |
|
this.removeTaskButton = new JButton();
|
138 |
|
this.removeTaskButton.setPreferredSize( new Dimension(16, 16));
|
139 |
|
this.removeTaskButton.setBorderPainted(false);
|
140 |
|
this.removeTaskButton.setIcon( getIcon("removeTaskButton.png"));
|
141 |
|
this.removeTaskButton.setDisabledIcon( getIcon("disabledRemoveTaskButton.png") );
|
142 |
|
this.removeTaskButton.setEnabled(false);
|
143 |
|
this.removeTaskButton.addActionListener(new ActionListener() {
|
144 |
|
public void actionPerformed(ActionEvent arg0) {
|
145 |
|
if( !taskStatus.isRunning() ) {
|
146 |
|
taskStatus.getManager().remove(taskStatus);
|
147 |
|
}
|
148 |
|
}
|
149 |
|
});
|
150 |
|
|
151 |
|
this.messagelabel = new JLabel();
|
|
120 |
this.progressBar.setIndeterminate(false);
|
|
121 |
this.progressBar.setBorderPainted(true);
|
152 |
122 |
|
153 |
|
this.setLayout(new GridBagLayout());
|
154 |
|
|
155 |
|
this.add(this.titlelabel, 0, 0, GridBagConstraints.HORIZONTAL, 0.98, 0);
|
156 |
|
this.add(this.progressBar, 0, 1, GridBagConstraints.HORIZONTAL, 0.98, 0);
|
157 |
|
this.add(this.messagelabel, 0, 2, GridBagConstraints.HORIZONTAL, 0.98, 0);
|
158 |
|
this.add(this.cancelRequestButton, 1, 1, GridBagConstraints.NONE, 0.01, 0);
|
159 |
|
this.add(this.removeTaskButton, 2, 1, GridBagConstraints.NONE, 0.01, 0);
|
160 |
|
}
|
|
123 |
this.cancelRequestButton = new JButton();
|
|
124 |
this.cancelRequestButton.setPreferredSize(new Dimension(16, 16));
|
|
125 |
this.cancelRequestButton.setBorderPainted(false);
|
|
126 |
this.cancelRequestButton.setIcon(getIcon("cancelRequestButton.png"));
|
|
127 |
this.cancelRequestButton.setDisabledIcon(getIcon("disabledCancelRequestButton.png"));
|
|
128 |
if (!this.showCancelButton) {
|
|
129 |
this.cancelRequestButton.setVisible(this.showCancelButton);
|
|
130 |
}
|
|
131 |
this.cancelRequestButton.addActionListener(new ActionListener() {
|
|
132 |
public void actionPerformed(ActionEvent arg0) {
|
|
133 |
cancelRequestButton.setEnabled(false);
|
|
134 |
taskStatus.cancelRequest();
|
|
135 |
}
|
|
136 |
});
|
|
137 |
this.removeTaskButton = new JButton();
|
|
138 |
this.removeTaskButton.setPreferredSize(new Dimension(16, 16));
|
|
139 |
this.removeTaskButton.setBorderPainted(false);
|
|
140 |
this.removeTaskButton.setIcon(getIcon("removeTaskButton.png"));
|
|
141 |
this.removeTaskButton.setDisabledIcon(getIcon("disabledRemoveTaskButton.png"));
|
|
142 |
this.removeTaskButton.setEnabled(true);
|
|
143 |
this.removeTaskButton.addActionListener(new ActionListener() {
|
|
144 |
public void actionPerformed(ActionEvent arg0) {
|
|
145 |
if (taskStatus.isRunning()) {
|
|
146 |
if( (arg0.getModifiers() & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK ) {
|
|
147 |
taskStatus.getManager().remove(taskStatus);
|
|
148 |
}
|
|
149 |
} else {
|
|
150 |
taskStatus.getManager().remove(taskStatus);
|
|
151 |
}
|
|
152 |
}
|
|
153 |
});
|
161 |
154 |
|
162 |
|
private ImageIcon getIcon(String name) {
|
163 |
|
URL iconurl = this.getClass().getResource(name);
|
164 |
|
if( iconurl == null ) {
|
165 |
|
return new ImageIcon();
|
166 |
|
}
|
167 |
|
return new ImageIcon(iconurl);
|
168 |
|
}
|
169 |
|
|
170 |
|
private void add(Component comp, int gridx, int gridy, int fill, double weightx, double weighty) {
|
171 |
|
GridBagConstraints c = new GridBagConstraints();
|
172 |
|
c.fill = fill;
|
173 |
|
c.gridx = gridx;
|
174 |
|
c.gridy = gridy;
|
175 |
|
c.weightx = weightx;
|
176 |
|
c.weighty = weighty;
|
177 |
|
this.add(comp, c);
|
178 |
|
}
|
|
155 |
this.messagelabel = new JLabel();
|
179 |
156 |
|
180 |
|
|
181 |
|
public void update(final Observable observable, final Object notification) {
|
|
157 |
this.setLayout(new GridBagLayout());
|
182 |
158 |
|
183 |
|
if(observable != null && !(observable instanceof TaskStatus) ) {
|
184 |
|
return;
|
185 |
|
}
|
186 |
|
if( !SwingUtilities.isEventDispatchThread()) {
|
187 |
|
SwingUtilities.invokeLater( new Runnable() {
|
188 |
|
public void run() {
|
189 |
|
update(observable, notification);
|
190 |
|
}
|
191 |
|
});
|
192 |
|
return;
|
193 |
|
}
|
194 |
|
TaskStatus taskStatus = (TaskStatus) observable;
|
195 |
|
if( taskStatus == null || !taskStatus.isRunning() ) {
|
196 |
|
this.messagelabel.setText(taskStatus.getLabel());
|
197 |
|
|
198 |
|
this.progressBar.setIndeterminate(false);
|
199 |
|
this.progressBar.setValue(100);
|
200 |
|
this.cancelRequestButton.setEnabled(false);
|
201 |
|
this.removeTaskButton.setEnabled(true);
|
202 |
|
return;
|
203 |
|
}
|
204 |
|
|
|
159 |
this.add(this.titlelabel, 0, 0, GridBagConstraints.HORIZONTAL, 0.98, 0);
|
|
160 |
this.add(this.progressBar, 0, 1, GridBagConstraints.HORIZONTAL, 0.98, 0);
|
|
161 |
this.add(this.messagelabel, 0, 2, GridBagConstraints.HORIZONTAL, 0.98, 0);
|
|
162 |
this.add(this.cancelRequestButton, 1, 1, GridBagConstraints.NONE, 0.01, 0);
|
|
163 |
this.add(this.removeTaskButton, 2, 1, GridBagConstraints.NONE, 0.01, 0);
|
|
164 |
}
|
|
165 |
|
|
166 |
private ImageIcon getIcon(String name) {
|
|
167 |
URL iconurl = this.getClass().getResource(name);
|
|
168 |
if (iconurl == null) {
|
|
169 |
return new ImageIcon();
|
|
170 |
}
|
|
171 |
return new ImageIcon(iconurl);
|
|
172 |
}
|
|
173 |
|
|
174 |
private void add(Component comp, int gridx, int gridy, int fill, double weightx, double weighty) {
|
|
175 |
GridBagConstraints c = new GridBagConstraints();
|
|
176 |
c.fill = fill;
|
|
177 |
c.gridx = gridx;
|
|
178 |
c.gridy = gridy;
|
|
179 |
c.weightx = weightx;
|
|
180 |
c.weighty = weighty;
|
|
181 |
this.add(comp, c);
|
|
182 |
}
|
|
183 |
|
|
184 |
public void update(final Observable observable, final Object notification) {
|
|
185 |
|
|
186 |
if (observable != null && !(observable instanceof TaskStatus)) {
|
|
187 |
return;
|
|
188 |
}
|
|
189 |
if (!SwingUtilities.isEventDispatchThread()) {
|
|
190 |
SwingUtilities.invokeLater(new Runnable() {
|
|
191 |
public void run() {
|
|
192 |
update(observable, notification);
|
|
193 |
}
|
|
194 |
});
|
|
195 |
return;
|
|
196 |
}
|
|
197 |
TaskStatus taskStatus = (TaskStatus) observable;
|
|
198 |
if (taskStatus == null || !taskStatus.isRunning()) {
|
|
199 |
this.messagelabel.setText(taskStatus.getLabel());
|
|
200 |
|
|
201 |
this.progressBar.setIndeterminate(false);
|
|
202 |
this.progressBar.setValue(100);
|
|
203 |
this.cancelRequestButton.setEnabled(false);
|
|
204 |
this.removeTaskButton.setEnabled(true);
|
|
205 |
return;
|
|
206 |
}
|
|
207 |
|
205 |
208 |
if (taskStatus.getTitle() == null) {
|
206 |
209 |
this.titlelabel.setText("Unknown");
|
207 |
210 |
} else {
|
208 |
211 |
this.titlelabel.setText(taskStatus.getTitle());
|
209 |
212 |
}
|
210 |
213 |
this.messagelabel.setText(taskStatus.getLabel());
|
211 |
|
this.progressBar.setIndeterminate( taskStatus.isIndeterminate() );
|
212 |
|
this.progressBar.setValue( taskStatus.getCompleted() );
|
213 |
|
|
214 |
|
if( !this.cancelRequestButton.isEnabled() ) {
|
215 |
|
this.cancelRequestButton.setEnabled(true);
|
216 |
|
}
|
217 |
|
|
218 |
|
}
|
|
214 |
this.progressBar.setIndeterminate(taskStatus.isIndeterminate());
|
|
215 |
this.progressBar.setValue(taskStatus.getCompleted());
|
219 |
216 |
|
220 |
|
public TaskStatus getTaskStatus() {
|
221 |
|
return this.taskStatus;
|
222 |
|
}
|
|
217 |
if (!this.cancelRequestButton.isEnabled()) {
|
|
218 |
this.cancelRequestButton.setEnabled(true);
|
|
219 |
}
|
223 |
220 |
|
224 |
|
public void setTittle(String tittle) {
|
|
221 |
}
|
|
222 |
|
|
223 |
public TaskStatus getTaskStatus() {
|
|
224 |
return this.taskStatus;
|
|
225 |
}
|
|
226 |
|
|
227 |
public void setTittle(String tittle) {
|
225 |
228 |
setTitle(tittle);
|
226 |
229 |
}
|
227 |
230 |
|
... | ... | |
230 |
233 |
if (this.taskStatus instanceof SimpleTaskStatus) {
|
231 |
234 |
((SimpleTaskStatus) this.taskStatus).setTitle(title);
|
232 |
235 |
}
|
233 |
|
}
|
|
236 |
}
|
234 |
237 |
|
235 |
|
public void message(String message) {
|
236 |
|
if( this.taskStatus instanceof SimpleTaskStatus ) {
|
237 |
|
((SimpleTaskStatus)this.taskStatus).message(message);
|
238 |
|
}
|
239 |
|
}
|
|
238 |
public void message(String message) {
|
|
239 |
if (this.taskStatus instanceof SimpleTaskStatus) {
|
|
240 |
((SimpleTaskStatus) this.taskStatus).message(message);
|
|
241 |
}
|
|
242 |
}
|
240 |
243 |
|
241 |
|
public void setCurValue(long value) {
|
242 |
|
if( this.taskStatus instanceof SimpleTaskStatus ) {
|
243 |
|
((SimpleTaskStatus)this.taskStatus).setCurValue(value);
|
244 |
|
}
|
245 |
|
}
|
|
244 |
public void setCurValue(long value) {
|
|
245 |
if (this.taskStatus instanceof SimpleTaskStatus) {
|
|
246 |
((SimpleTaskStatus) this.taskStatus).setCurValue(value);
|
|
247 |
}
|
|
248 |
}
|
246 |
249 |
|
247 |
|
|
248 |
250 |
}
|