View Javadoc

1   /*
2   * The contents of this file are subject to the BT "ZEUS" Open Source 
3   * Licence (L77741), Version 1.0 (the "Licence"); you may not use this file 
4   * except in compliance with the Licence. You may obtain a copy of the Licence
5   * from $ZEUS_INSTALL/licence.html or alternatively from
6   * http://www.labs.bt.com/projects/agents/zeus/licence.htm
7   * 
8   * Except as stated in Clause 7 of the Licence, software distributed under the
9   * Licence is distributed WITHOUT WARRANTY OF ANY KIND, either express or 
10  * implied. See the Licence for the specific language governing rights and 
11  * limitations under the Licence.
12  * 
13  * The Original Code is within the package zeus.*.
14  * The Initial Developer of the Original Code is British Telecommunications
15  * public limited company, whose registered office is at 81 Newgate Street, 
16  * London, EC1A 7AJ, England. Portions created by British Telecommunications 
17  * public limited company are Copyright 1996-9. All Rights Reserved.
18  * 
19  * THIS NOTICE MUST BE INCLUDED ON ANY COPY OF THIS FILE
20  */
21  
22  /***
23      Change Log
24      ----------
25      Simon 28/08/00 - implemented code for Task Externals. 
26      
27      */
28  
29  /*****************************************************************************
30  * TaskPanel.java
31  *
32  *
33  ***************************************************************************/
34  
35  package zeus.generator.code;
36  
37  import java.util.*;
38  import java.awt.*;
39  import java.awt.event.*;
40  import javax.swing.*;
41  import javax.swing.border.*;
42  import javax.swing.table.*;
43  import javax.swing.event.*;
44  
45  import zeus.util.*;
46  import zeus.gui.help.*;
47  import zeus.gui.editors.*;
48  import zeus.gui.fields.*;
49  
50  public class TaskPanel extends JPanel {
51    protected GenerationPlan  genplan;
52    protected TaskModel       taskModel;
53    protected JTable          taskTable;
54  
55    public TaskPanel(GenerationPlan genplan) {
56       this.genplan = genplan;
57  
58       taskModel = new TaskModel(genplan);
59  
60       TableColumnModel tm = new DefaultTableColumnModel();
61       TableColumn column;
62       JCheckBox checkbox = new JCheckBox();
63       checkbox.setHorizontalAlignment(JCheckBox.CENTER);
64       DefaultCellEditor cellEditor = new DefaultCellEditor(checkbox);
65  
66       column = new TableColumn(TaskModel.GENERATE,8,
67          new CheckBoxCellRenderer(), cellEditor);
68       column.setHeaderValue(taskModel.getColumnName(TaskModel.GENERATE));
69       tm.addColumn(column);
70  
71       column = new TableColumn(TaskModel.STATUS,24);
72       column.setHeaderValue(taskModel.getColumnName(TaskModel.STATUS));
73       tm.addColumn(column);
74  
75       column = new TableColumn(TaskModel.NAME,24);
76       column.setHeaderValue(taskModel.getColumnName(TaskModel.NAME));
77       tm.addColumn(column);
78          // 25/08/00 addition by simon
79       column = new TableColumn(TaskModel.EXTERNAL,24,
80          new DefaultTableCellRenderer(),new DefaultCellEditor(new NameField()));
81       column.setHeaderValue(taskModel.getColumnName(TaskModel.EXTERNAL));
82       tm.addColumn(column);
83  
84       taskTable = new JTable(taskModel,tm);
85       taskTable.getTableHeader().setReorderingAllowed(false);
86       taskTable.setColumnSelectionAllowed(false);
87  
88       TitledBorder border = BorderFactory.createTitledBorder("Tasks");
89       border.setTitlePosition(TitledBorder.TOP);
90       border.setTitleJustification(TitledBorder.RIGHT);
91       border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
92       border.setTitleColor(Color.blue);
93       setBorder(border);
94  
95       JScrollPane scrollPane = new JScrollPane(taskTable);
96       scrollPane.setBorder(new BevelBorder(BevelBorder.LOWERED));
97       scrollPane.setMinimumSize(new Dimension(160,80));
98       scrollPane.setPreferredSize(new Dimension(200,80));
99       taskTable.setBackground(Color.white);
100 
101      GridBagLayout gridBagLayout = new GridBagLayout();
102      setLayout(gridBagLayout);
103      GridBagConstraints gbc;
104      setBackground(Color.lightGray);
105 
106      JToolBar toolbar = new TaskToolBar();
107      gbc = new GridBagConstraints();
108      gbc.anchor = GridBagConstraints.NORTHWEST;
109      gbc.fill = GridBagConstraints.NONE;
110      gbc.gridwidth = GridBagConstraints.REMAINDER;
111      gbc.insets = new Insets(0,8,0,0);
112      gridBagLayout.setConstraints(toolbar,gbc);
113      add(toolbar);
114 
115      gbc = new GridBagConstraints();
116      gbc.gridwidth = GridBagConstraints.REMAINDER;
117      gbc.anchor = GridBagConstraints.NORTHWEST;
118      gbc.fill = GridBagConstraints.BOTH;
119      gbc.weightx = gbc.weighty = 1;
120      gbc.insets = new Insets(8,8,8,8);
121      gridBagLayout.setConstraints(scrollPane,gbc);
122      add(scrollPane);
123 
124   }
125 
126   protected class CheckBoxCellRenderer extends JCheckBox
127                                        implements TableCellRenderer,
128                                        java.io.Serializable {
129 
130      public CheckBoxCellRenderer() {
131         setHorizontalAlignment(JCheckBox.CENTER);
132      }
133 
134      public Component getTableCellRendererComponent(JTable table,
135         Object value, boolean isSelected, boolean hasFocus,
136         int row, int column) {
137             if ( value != null )
138                 this.setSelected(((Boolean)value).booleanValue());
139             return this;
140         }
141     }
142 
143   protected class TaskToolBar extends JToolBar
144                                implements ActionListener {
145 
146      protected JToggleButton helpBtn;
147      protected HelpWindow    helpWin;
148 
149      public TaskToolBar() {
150         setBackground(Color.lightGray);
151         setBorder( new BevelBorder(BevelBorder.LOWERED ) );
152         setFloatable(false);
153         String path = SystemProps.getProperty("gif.dir") + "generator" +
154            System.getProperty("file.separator");
155 
156         // Help Button
157         helpBtn = new JToggleButton(new ImageIcon(path + "help.gif"));
158 	helpBtn.setMargin(new Insets(0,0,0,0));
159         add(helpBtn);
160         helpBtn.setToolTipText("Help");
161         helpBtn.addActionListener(this);
162      }
163 
164      public void actionPerformed(ActionEvent e) {
165         Object src = e.getSource();
166         if ( src == helpBtn ) {
167            if ( helpBtn.isSelected() ) {
168               helpWin = new HelpWindow(SwingUtilities.getRoot(this),
169                  getLocation(), "generator", "Generation Plan: Tasks");
170               helpWin.setSource(helpBtn);
171            }
172            else {
173               helpWin.dispose();
174            }
175         }
176      }
177   }
178 }