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  * FactTreePane.java
26  *
27  * The Container panel for the Fact Hierarchy
28  *****************************************************************************/
29  
30  package zeus.ontology.facts;
31  
32  import java.awt.*;
33  import java.awt.event.*;
34  import javax.swing.*;
35  import javax.swing.border.*;
36  import javax.swing.tree.*;
37  
38  import zeus.util.SystemProps;
39  import zeus.gui.help.*;
40  import zeus.concepts.*;
41  import zeus.ontology.*;
42  import zeus.ontology.attributes.*;
43  
44  
45  public class FactTreePane extends JSplitPane {
46    protected FactTreeUI          treeView;
47    protected AttributeTablePanel tablePanel;
48  
49    public FactTreePane(OntologyEditor editor, OntologyDb ontologyDb) {
50      super(JSplitPane.VERTICAL_SPLIT,true);
51      tablePanel = new AttributeTablePanel(editor,ontologyDb);
52      treeView   = new FactTreeUI(ontologyDb,tablePanel);
53  
54      JPanel innerPanel = new JPanel();
55      TitledBorder border = new TitledBorder(new EtchedBorder(),
56                                              "The Fact Hierarchy");
57      border.setTitlePosition(TitledBorder.TOP);
58      border.setTitleJustification(TitledBorder.RIGHT);
59      border.setTitleFont(new Font("Helvetica", Font.BOLD, 14));
60      border.setTitleColor(Color.blue);
61      innerPanel.setBorder(border);
62  
63      GridBagLayout gridBagLayout = new GridBagLayout();
64      GridBagConstraints gbc = new GridBagConstraints();
65      innerPanel.setLayout(gridBagLayout);
66      //innerPanel.setBackground(Color.lightGray);
67  
68      JToolBar factsToolbar = new FactTreeToolBar();
69      gbc.anchor = GridBagConstraints.WEST;
70      gbc.fill = GridBagConstraints.NONE;
71      gbc.gridwidth = GridBagConstraints.REMAINDER;
72      gbc.insets = new Insets(0,16,0,0);
73      gridBagLayout.setConstraints(factsToolbar, gbc);
74      innerPanel.add(factsToolbar);
75  
76      //Create the scroll pane and add the tree to it.
77      JScrollPane treePane = new JScrollPane();
78      treePane.getViewport().add(treeView);
79  
80      gbc = new GridBagConstraints();
81      gbc.gridwidth = GridBagConstraints.REMAINDER;
82      gbc.anchor = GridBagConstraints.WEST;
83      gbc.fill = GridBagConstraints.BOTH;
84      gbc.weightx = gbc.weighty = 1;
85      gbc.insets = new Insets(16,16,16,16);
86      gridBagLayout.setConstraints(treePane, gbc);
87      innerPanel.add(treePane);
88  
89      innerPanel.setPreferredSize(new Dimension(540,250));
90      innerPanel.setMinimumSize(new Dimension(0,0));
91      tablePanel.setPreferredSize(new Dimension(540,350));
92      tablePanel.setMinimumSize(new Dimension(0,0));
93      setTopComponent(innerPanel);
94      setBottomComponent(tablePanel);
95      setDividerSize(7);
96    }
97  
98  class FactTreeToolBar extends JToolBar implements ActionListener {
99    protected HelpWindow    helpWin;
100   protected JButton       newSBtn;
101   protected JButton       newPBtn;
102   protected JButton       deleteBtn;
103   protected JButton       cutBtn;
104   protected JButton       copyBtn;
105   protected JButton       pasteBtn;
106 
107   protected JToggleButton helpBtn;
108   protected JToggleButton showBtn;
109 
110   public FactTreeToolBar() {
111     setBorder( new BevelBorder(BevelBorder.LOWERED ) );
112     setFloatable(false);
113 
114     String sep = System.getProperty("file.separator");
115     String path = SystemProps.getProperty("gif.dir") + "ontology" + sep;
116 
117     // New Sub Button
118     newSBtn = new JButton(new ImageIcon(path + "newsub.gif"));
119     newSBtn.setMargin(new Insets(0,0,0,0));
120     add(newSBtn);
121     newSBtn.setToolTipText("Add new child fact");
122     newSBtn.addActionListener(this);
123 
124     // New Peer Button
125     newPBtn = new JButton(new ImageIcon(path + "newpeer.gif"));
126     newPBtn.setMargin(new Insets(0,0,0,0));
127     add(newPBtn);
128     newPBtn.setToolTipText("Add new peer fact");
129     newPBtn.addActionListener(this);
130 
131     // Delete Button
132     deleteBtn = new JButton(new ImageIcon(path + "delete.gif"));
133     deleteBtn.setMargin(new Insets(0,0,0,0));
134     add(deleteBtn);
135     deleteBtn.setToolTipText("Delete");
136     deleteBtn.addActionListener(this);
137 
138     addSeparator();
139 
140     // Cut Button
141     cutBtn = new JButton(new ImageIcon(path + "cut.gif"));
142     cutBtn.setMargin(new Insets(0,0,0,0));
143     add(cutBtn);
144     cutBtn.setToolTipText("Cut");
145     cutBtn.addActionListener(this);
146 
147     // Copy Button
148     copyBtn = new JButton(new ImageIcon(path + "copy.gif"));
149     copyBtn.setMargin(new Insets(0,0,0,0));
150     add(copyBtn);
151     copyBtn.setToolTipText("Copy");
152     copyBtn.addActionListener(this);
153 
154     // Paste Button
155     pasteBtn = new JButton(new ImageIcon(path + "paste.gif"));
156     pasteBtn.setMargin(new Insets(0,0,0,0));
157     add(pasteBtn);
158     pasteBtn.setToolTipText("Paste");
159     pasteBtn.addActionListener(this);
160 
161     addSeparator();
162 
163     // Attribute Toggle Button
164     showBtn = new JToggleButton(new ImageIcon(path + "expand.gif"), false);
165     showBtn.setSelectedIcon(new ImageIcon(path + "collapse.gif"));
166     showBtn.setMargin(new Insets(0,0,0,0));
167     add(showBtn);
168     showBtn.setToolTipText("Expand/Collapse hierarchy");
169     showBtn.addActionListener(this);
170 
171     addSeparator();
172 
173     // Help Button
174     helpBtn = new JToggleButton(new ImageIcon(path + "help.gif"));
175     helpBtn.setMargin(new Insets(0,0,0,0));
176     add(helpBtn);
177     helpBtn.setToolTipText("Help");
178     helpBtn.addActionListener(this);
179   }
180   public void actionPerformed(ActionEvent e) {
181     Object src = e.getSource();
182     if ( src == newPBtn )
183        treeView.addPeerNode();
184     else if ( src == newSBtn )
185        treeView.addSubNode();
186     else if ( src == deleteBtn )
187        treeView.removeNode();
188     else if ( src == showBtn ) {
189        if ( showBtn.isSelected() )
190           treeView.expandRow();
191        else
192           treeView.collapseRow();
193     }
194     else if ( src == cutBtn )
195        treeView.cutNode();
196     else if ( src == copyBtn )
197        treeView.copyNode();
198     else if ( src == pasteBtn )
199        treeView.pasteNode();
200     else if ( src == helpBtn ) {
201       if ( helpBtn.isSelected() ) {
202          Point dispos = getLocation();
203          helpWin = new HelpWindow(SwingUtilities.getRoot(helpBtn),
204 	    dispos, "ontology", "Fact Hierarchy");
205          helpWin.setSource(helpBtn);
206       }
207       else
208         helpWin.dispose();
209     }
210   }
211 }
212 }