01: //The contents of this file are subject to the Mozilla Public License Version 1.1
02: //(the "License"); you may not use this file except in compliance with the
03: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
04: //
05: //Software distributed under the License is distributed on an "AS IS" basis,
06: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
07: //for the specific language governing rights and
08: //limitations under the License.
09: //
10: //The Original Code is "The Columba Project"
11: //
12: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14: //
15: //All Rights Reserved.
16: package org.columba.core.gui.statusbar;
17:
18: import java.awt.BorderLayout;
19: import java.awt.Component;
20:
21: import javax.swing.BorderFactory;
22: import javax.swing.JLabel;
23: import javax.swing.JList;
24: import javax.swing.JPanel;
25: import javax.swing.JProgressBar;
26: import javax.swing.ListCellRenderer;
27:
28: import org.columba.core.command.Worker;
29:
30: /**
31: * Custom renderer using a JLabel for status messages and a JProgressBar for
32: * worker progress.
33: *
34: * @author fdietz
35: */
36: public class TaskRenderer extends JPanel implements ListCellRenderer {
37:
38: private JLabel label;
39:
40: private JProgressBar progressBar;
41:
42: private JPanel progressPanel;
43:
44: public TaskRenderer() {
45: super ();
46:
47: setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
48:
49: label = new JLabel();
50: progressBar = new JProgressBar();
51: progressPanel = new JPanel();
52: progressPanel.setLayout(new BorderLayout());
53: progressPanel.setBorder(BorderFactory.createEmptyBorder(2, 10,
54: 2, 10));
55: progressPanel.add(progressBar, BorderLayout.CENTER);
56:
57: setLayout(new BorderLayout());
58: add(label, BorderLayout.NORTH);
59: add(progressPanel, BorderLayout.CENTER);
60: }
61:
62: /*
63: * (non-Javadoc)
64: *
65: * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList,
66: * java.lang.Object, int, boolean, boolean)
67: */
68: public Component getListCellRendererComponent(JList list,
69: Object value, int index, boolean isSelected,
70: boolean hasFocus) {
71:
72: if (isSelected) {
73: setBackground(list.getSelectionBackground());
74: setForeground(list.getSelectionForeground());
75: progressPanel.setBackground(list.getSelectionBackground());
76: progressPanel.setForeground(list.getSelectionForeground());
77: } else {
78: setBackground(list.getBackground());
79: setForeground(list.getForeground());
80: progressPanel.setBackground(list.getBackground());
81: progressPanel.setForeground(list.getForeground());
82: }
83:
84: Worker worker = (Worker) value;
85: label.setText(worker.getDisplayText());
86: progressBar.setMaximum(worker.getProgessBarMaximum());
87: progressBar.setValue(worker.getProgressBarValue());
88:
89: // return super.getListCellRendererComponent(arg0, arg1, arg2, arg3,
90: // arg4);
91: return this;
92: }
93: }
|