Revision 1723

View differences:

org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/task/impl/BaseTaskStatus.java
214 214
        }
215 215
    }
216 216

  
217
    public String getMessage() {
218
        return this.values.message;
219
    }
220
    
217 221
    @Override
218 222
    public void terminate() {
219 223
        if (!isRunning) {
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.lib/src/main/java/org/gvsig/tools/task/TaskStatus.java
64 64
     */
65 65
    public String getLabel();
66 66
    
67
    public String getMessage();
67 68
    /**
68 69
     * Return true if the task has cancelled by the
69 70
     * user or another task.
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/task/DefaultJTasksStatusList.java
37 37
import javax.swing.BoxLayout;
38 38
import javax.swing.JPanel;
39 39
import javax.swing.JScrollPane;
40
import javax.swing.SwingUtilities;
40 41

  
41 42
import org.gvsig.tools.observer.Observable;
42 43
import org.gvsig.tools.observer.Observer;
......
83 84
        for (JTaskStatus taskStatus : controlsToAdd) {
84 85
            listPanel.add(taskStatus);
85 86
        }
86
        listPanel.setAlignmentY(Component.BOTTOM_ALIGNMENT);
87
        listPanel.setAlignmentY(Component.TOP_ALIGNMENT);
87 88
        JScrollPane scroller = new JScrollPane(listPanel);
88
        scroller.setAlignmentY(Component.BOTTOM_ALIGNMENT);
89
        scroller.setAlignmentY(Component.TOP_ALIGNMENT);
89 90
        scroller.setPreferredSize(new Dimension(300, 150));
90 91
        this.add(scroller, BorderLayout.CENTER);
91 92
    }
......
113 114
    }
114 115

  
115 116
    @Override
116
    public void update(Observable observable, Object notification) {
117
    public void update(final Observable observable, final Object notification) {
117 118
        if (!(observable instanceof TaskStatusManager)) {
118 119
            return;
119 120
        }
121
        if( !SwingUtilities.isEventDispatchThread() ) {
122
            SwingUtilities.invokeLater(new Runnable() {
123
                @Override
124
                public void run() {
125
                    update(observable, notification);
126
                }
127
            });
128
            return;
129
        }
120 130
        if (notification == null || this.manager.isEmpty() ) {
121 131
            // remove task
122 132
            listPanel.removeAll();
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/task/DefaultJTaskStatus.java
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
}
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/task/DefaultJTasksStatus.java
188 188
				taskStatus = taskStatus2;
189 189
			}
190 190
 		}
191
 		String label = taskStatus.getLabel();
191
 		String label1 = taskStatus.getMessage();
192
 		String label2 = taskStatus.getLabel();
192 193
 		String title = taskStatus.getTitle();  		
193 194
 	
194 195
 		if (title == null) {
195 196
 			title = "Progress";
196 197
 		}
197
		if( label == null || label.trim().equals("") ) {
198
			label = title;
198
		if( StringUtils.isEmpty(label2) ) {
199
			label2 = title;
199 200
		} else {
200
			label = title + ": " + label;
201
			label2 = title + "\n" + label2;
201 202
		}
202 203
		
203
		this.label.setText( StringUtils.abbreviateMiddle(label, "...", this.maxLabelSize) );
204
		this.label.setToolTipText(label );
204
		this.label.setText( StringUtils.abbreviateMiddle(label1, "...", this.maxLabelSize) );
205
		this.label.setToolTipText(label2);
206
                if( taskStatus.isIndeterminate() ) {
207
                    this.progressBar.setString("");
208
                } else {
209
                    this.progressBar.setString(String.valueOf(taskStatus.getCompleted()));
210
                }
205 211
		this.progressBar.setIndeterminate( taskStatus.isIndeterminate() );
206 212
		this.progressBar.setValue( taskStatus.getCompleted() );
207 213
		if( !this.progressBar.isVisible() ) {

Also available in: Unified diff