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  
24  /*************************************************************************************************
25  * ControlPanel.java
26  *
27  * Panel for controlling the other panels
28  *
29  ************************************************************************************************/
30  
31  package zeus.generator.util;
32  
33  import java.awt.*;
34  import java.awt.event.*;
35  import javax.swing.*;
36  import javax.swing.border.*;
37  import javax.swing.event.*;
38  
39  import zeus.util.*;
40  
41  public class ControlPanel extends JPanel
42                            implements ActionListener,
43                                       ChangeListener {
44  
45    protected JLabel        msgField       = new JLabel();
46    protected JButton       nextButton     = new JButton();
47    protected JButton       previousButton = new JButton();
48    protected JButton       saveButton     = new JButton();
49    protected JToggleButton infoButton;
50    
51    protected Editor editor;
52    
53    public ControlPanel(Editor editor, String title,
54                        boolean isFirst, boolean isLast) {
55      this.editor = editor;
56      editor.addChangeListener(this);
57      setBackground(java.awt.Color.yellow);
58      setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
59      
60      GridBagLayout gridBagLayout = new GridBagLayout();
61      setLayout(gridBagLayout);
62      
63      JLabel titleLabel = new JLabel(title);
64      titleLabel.setFont(new Font ("Helvetica", Font.BOLD, 20));
65  
66      GridBagConstraints gbc = new GridBagConstraints();
67      gbc.anchor = GridBagConstraints.WEST;
68      gbc.fill = GridBagConstraints.NONE;
69      gbc.gridwidth = 1;
70      gbc.insets = new Insets(0,8,0,0);
71      gridBagLayout.setConstraints(titleLabel,gbc);
72      add(titleLabel);
73  
74      gbc.anchor = GridBagConstraints.WEST;
75      gbc.fill = GridBagConstraints.HORIZONTAL;
76      gbc.insets = new Insets(0,16,0,16);
77      gridBagLayout.setConstraints(msgField,gbc);
78      add(msgField);
79  
80      JPanel iconPane = new JPanel();
81      iconPane.setBackground(Color.yellow);
82  
83      gbc.anchor = GridBagConstraints.EAST;
84      gbc.fill = GridBagConstraints.NONE;
85      gbc.weightx = gbc.weighty = 1;
86      gbc.insets = new Insets(0,0,0,8);
87      gridBagLayout.setConstraints(iconPane, gbc);
88      add(iconPane);
89  
90      String sep = System.getProperty("file.separator");
91      String path = SystemProps.getProperty("gif.dir") + "generator" + sep;
92      
93      //create the icon buttons to be added to this panel.
94      previousButton.setIcon(new ImageIcon(path + "previous.gif"));
95      previousButton.setDisabledIcon(new ImageIcon(path + "next.gif"));
96      previousButton.addActionListener(this);
97      previousButton.setOpaque(true);    
98      previousButton.setMargin(new Insets(0,0,0,0));
99      if ( isFirst ) {
100        previousButton.setEnabled(false);
101        previousButton.setToolTipText("No Earlier Stage");
102     }
103     else {    
104        previousButton.setToolTipText("Go Back to Previous Design Stage");
105     }
106     iconPane.add(previousButton);    
107     iconPane.add(Box.createHorizontalStrut(16));
108     
109     saveButton.setOpaque(true);
110     saveButton.setMargin(new Insets(0,0,0,0));
111     saveButton.setIcon(new ImageIcon(path + "save.gif"));
112     saveButton.setEnabled(false);
113     saveButton.addActionListener(this);
114     iconPane.add(saveButton);
115     
116     infoButton = new JToggleButton(new ImageIcon(path + "info.gif"));
117     infoButton.setMargin(new Insets(0,0,0,0));
118     infoButton.setOpaque(true);
119     infoButton.addActionListener(this);
120     infoButton.setToolTipText("Methodology Documentation");
121     iconPane.add(infoButton);
122     
123     iconPane.add(Box.createHorizontalStrut(16));
124 
125     nextButton.setIcon(new ImageIcon(path + "next.gif"));
126     nextButton.setMargin(new Insets(0,0,0,0));
127     nextButton.setDisabledIcon(new ImageIcon(path + "previous.gif"));
128     nextButton.addActionListener(this);
129     nextButton.setOpaque(true);
130     if ( isLast ) {
131        nextButton.setEnabled(false);
132        nextButton.setToolTipText("This is the Final Stage");
133     }
134     else {
135        nextButton.setToolTipText("Go to Next Design Stage");
136     }
137     iconPane.add(nextButton);
138 
139     msgField.setForeground(Color.green);    
140     msgField.setText(editor.getObjectName());
141     msgField.setMinimumSize(new Dimension(200,20));
142     msgField.setPreferredSize(new Dimension(200,20));
143   }
144   
145   public void stateChanged(ChangeEvent e) {
146     boolean changed = editor.hasChanged();
147     saveButton.setEnabled(changed);
148     String str = editor.getObjectName();
149     if (changed) {
150        str += " [Modified]";
151        saveButton.setToolTipText("Save Changes to Disk");
152     }
153     else {
154        saveButton.setToolTipText("No Save Necessary");
155     }
156     msgField.setText(str);
157     saveButton.repaint();
158   }
159   
160   public void actionPerformed(ActionEvent e) {
161     Object src = e.getSource();
162     if ( src == previousButton )
163       editor.previous();
164     else if ( src == infoButton )
165       editor.help(infoButton);
166     else if ( src == saveButton )
167       editor.save();
168     else if ( src == nextButton )
169       editor.next();
170   }
171 }