View Javadoc

1   package org.catacomb.druid.swing;
2   
3   
4   import org.catacomb.icon.IconLoader;
5   import org.catacomb.interlish.structure.Labelled;
6   import org.catacomb.interlish.structure.Progressed;
7   import org.catacomb.interlish.structure.StateProcess;
8   
9   
10  import java.awt.*;
11  
12  import javax.swing.*;
13  
14  
15  
16  
17  public class DListProgressRenderer extends JPanel implements DListCellRenderer {
18  
19      static final long serialVersionUID = 1001;
20  
21      JLabel nameLabel;
22  
23      JLabel statusLabel;
24  
25      JLabel progressLabel;
26  
27      JProgressBar progressBar;
28      JPanel rtPanel;
29  
30  
31      Icon newIcon;
32      Icon readyIcon;
33      Icon runningIcon;
34      Icon doneIcon;
35      Icon stoppedIcon;
36      Icon errorIcon;
37  
38      Color csel = new Color(0xe6, 0xe6, 0Xdc);
39  
40  
41      public DListProgressRenderer() {
42          setLayout(new GridLayout(3, 1, 6, 2));
43          //     setLayout(new FlowLayout(FlowLayout.LEFT));
44  
45  
46          Font plainfont = new Font("sansserif", Font.PLAIN, 12);
47  
48  
49          nameLabel = new JLabel();
50  //      nameLabel.setOpaque(true);
51          nameLabel.setFont(plainfont);
52  
53  
54          statusLabel = new JLabel("");
55  //      statusLabel.setOpaque(false);
56          statusLabel.setFont(plainfont);
57  
58          progressLabel = new JLabel("             ", null, JLabel.TRAILING);
59  //      progressLabel.setOpaque(true);
60          progressLabel.setFont(plainfont);
61  
62          newIcon = IconLoader.createImageIcon("statusNew.gif");
63          doneIcon = IconLoader.createImageIcon("statusDone.gif");
64          readyIcon = IconLoader.createImageIcon("statusReady.gif");
65          runningIcon = IconLoader.createImageIcon("statusRunning.gif");
66          stoppedIcon = IconLoader.createImageIcon("statusStopped.gif");
67          errorIcon = IconLoader.createImageIcon("statusErr.gif");
68  
69  
70          statusLabel.setIcon(doneIcon);
71  
72  
73          progressBar = new JProgressBar(0, 100);
74          progressBar.setOpaque(false);
75          progressBar.setPreferredSize(new Dimension(140, 8));
76          progressBar.setBorderPainted(true);
77  
78          // progressBar.setForeground(new Color(0x80ff80));
79  
80  
81          Color borderC = new Color(0xa0a0a0);
82  
83  
84          progressBar.setBorder(BorderFactory.createCompoundBorder(
85                                    BorderFactory.createEmptyBorder(4, 4, 4, 4),
86                                    BorderFactory.createLineBorder(borderC)));
87  
88          rtPanel = new JPanel();
89          rtPanel.setBackground(Color.white);
90          rtPanel.setLayout(new BorderLayout(4, 4));
91          rtPanel.add("East", statusLabel);
92          rtPanel.add("Center", progressBar);
93  
94  
95  
96  
97          add(nameLabel);
98          add(rtPanel);
99          add(progressLabel);
100 
101     }
102 
103 
104 
105     public Component getListCellRendererComponent(JList list, Object value, int index,
106             boolean isSelected, boolean cellHasFocus) {
107 
108 
109         String s = "";
110         if (value instanceof Labelled) {
111             s = ((Labelled)value).getLabel();
112         } else {
113             s = value.toString();
114         }
115 
116         int istat = StateProcess.RAW;
117         if (value instanceof StateProcess) {
118             istat = ((StateProcess)value).getProcessState();
119         }
120 
121         double fprog = 0.0;
122         String tprog = "";
123         if (value instanceof Progressed) {
124             fprog = ((Progressed)value).getProgress();
125             tprog = ((Progressed)value).getProgressDescription();
126         }
127 
128 
129 
130         nameLabel.setText(s);
131 
132         Color cbg = (isSelected ? csel : list.getBackground());
133         Color cfg = (isSelected ? list.getSelectionForeground() : list.getForeground());
134 
135         setBackground(cbg);
136 
137 //      nameLabel.setBackground(cbg);
138         rtPanel.setBackground(cbg);
139 
140         nameLabel.setForeground(cfg);
141 
142 //       progressLabel.setBackground(cbg);
143         progressBar.setBackground(cbg);
144 
145         switch (istat) {
146         case StateProcess.RAW:
147             statusLabel.setIcon(newIcon);
148             break;
149 
150         case StateProcess.READY:
151             statusLabel.setIcon(readyIcon);
152             break;
153 
154         case StateProcess.RUNNING:
155             statusLabel.setIcon(runningIcon);
156             break;
157 
158         case StateProcess.ERROR:
159             statusLabel.setIcon(errorIcon);
160             break;
161 
162         case StateProcess.FINISHED:
163             statusLabel.setIcon(doneIcon);
164             break;
165 
166         case StateProcess.PAUSED:
167             statusLabel.setIcon(stoppedIcon);
168             break;
169 
170         }
171 
172 
173         progressBar.setValue((int)(100 * fprog));
174 
175         progressLabel.setText(tprog);
176 
177         /*
178          * setEnabled(list.isEnabled()); setFont(list.getFont()); setOpaque(true);
179          */
180         return this;
181     }
182 
183 
184 }