1 19 20 package taskblocks.app; 21 22 import java.awt.Component ; 23 import java.awt.GridBagConstraints ; 24 import java.awt.GridBagLayout ; 25 26 import javax.swing.DefaultComboBoxModel ; 27 import javax.swing.JComboBox ; 28 import javax.swing.JLabel ; 29 import javax.swing.JList ; 30 import javax.swing.JPanel ; 31 import javax.swing.JSpinner ; 32 import javax.swing.JTextField ; 33 import javax.swing.ListCellRenderer ; 34 import javax.swing.SpinnerNumberModel ; 35 36 import taskblocks.modelimpl.ColorLabel; 37 import taskblocks.modelimpl.TaskImpl; 38 import taskblocks.modelimpl.TaskModelImpl; 39 40 public class TaskConfigPanel extends JPanel { 41 42 private TaskImpl _task; 43 private TaskModelImpl _model; 44 45 JComboBox manCB; 46 JTextField nameTF; 47 JSpinner durationSP; 48 JComboBox _colorLabelCB; 49 50 public TaskConfigPanel(TaskImpl task, TaskModelImpl model) { 51 _task = task; 52 _model = model; 53 buildGui(); 54 } 55 56 private void buildGui() { 57 JPanel contentP = this; 59 JLabel nameL = new JLabel ("Task name:"); 60 nameTF = new JTextField (15); 61 JLabel manL = new JLabel ("Worker:"); 62 manCB = new JComboBox (new DefaultComboBoxModel (_model._mans)); 63 JLabel durationL = new JLabel ("Duration:"); 64 durationSP = new JSpinner (new SpinnerNumberModel ((int)_task.getDuration(), 1, 365, 1)); 65 JLabel colorL = new JLabel ("Color Label:"); 66 _colorLabelCB = new JComboBox (new DefaultComboBoxModel (ColorLabel.COLOR_LABELS)); 67 _colorLabelCB.setRenderer(new ColorLabelRenderer(_colorLabelCB.getRenderer())); 68 69 contentP.setLayout(new GridBagLayout ()); 71 GridBagConstraints gc = new GridBagConstraints (); 72 73 gc.gridx = 0; gc.gridy = 0; 75 gc.fill = GridBagConstraints.NONE; 76 gc.insets.bottom = 5; 77 gc.anchor = GridBagConstraints.EAST; 78 contentP.add(nameL, gc); 80 gc.gridy++; contentP.add(durationL, gc); 81 gc.gridy++; contentP.add(manL, gc); 82 gc.gridy++; contentP.add(colorL, gc); 83 84 gc.gridx++; gc.gridy=0; 86 gc.fill = GridBagConstraints.HORIZONTAL; 87 gc.weightx = 1; 88 gc.insets.left = 8; 89 contentP.add(nameTF, gc); 91 gc.gridy++; contentP.add(durationSP, gc); 92 gc.gridy++; contentP.add(manCB, gc); 93 gc.gridy++; contentP.add(_colorLabelCB, gc); 94 95 nameTF.setText(_task.getName()); 97 manCB.setSelectedItem(_task.getMan()); 98 if(_task.getColorLabel() != null) { 99 _colorLabelCB.setSelectedItem(_task.getColorLabel()); 100 } 101 } 102 103 public static class ColorLabelRenderer implements ListCellRenderer { 104 ListCellRenderer _orig; 105 public ColorLabelRenderer(ListCellRenderer orig) { 106 _orig = orig; 107 } 108 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 109 Component c = _orig.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 110 111 if(c instanceof JLabel ) { 112 ((JLabel )c).setIcon(((ColorLabel)value)._icon); 113 } 114 return c; 115 } 116 } 117 118 } 119 | Popular Tags |