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  package zeus.agentviewer;
25  
26  import javax.swing.*;
27  import java.awt.*;
28  import java.util.*;
29  
30  public class InternalFramesPanel extends JPanel {
31      private JScrollPane scrollPane;
32      private JDesktopPane desktopPane;
33      final int WIDTH =750;
34      final int HEIGHT = 300;
35      final int DELTAw = 25;
36      final int DELTAh = 80;
37      public JFrame frame;
38      boolean TILE = false;
39  
40  //------------------------------------------------------------------------------
41      public InternalFramesPanel(){
42          super();
43          setLayout(new BorderLayout());
44          desktopPane = new JDesktopPane() {
45             public Dimension getMinimumSize() {
46                return new Dimension(10, 10);
47             }
48  
49             public Dimension getPreferredSize() {
50                return new Dimension(4000, 4000);// 700, 250
51             }
52          };
53          desktopPane.setOpaque(false);
54          scrollPane = new JScrollPane(desktopPane,
55                                       ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
56                                       ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS ){
57                       public boolean isOpaque() {
58                         return true;
59  
60                       }
61  
62          };
63          this.add(BorderLayout.CENTER,scrollPane);
64          this.setBorder(BorderFactory.createEtchedBorder(Color.black,Color.gray));
65          this.setSize(WIDTH,HEIGHT);
66      }
67  //------------------------------------------------------------------------------
68      public InternalFramesPanel(AgentViewer frame){
69        this();
70        this.frame = frame;
71      }
72  //------------------------------------------------------------------------------
73      public InternalFramesPanel(BasicAgentViewer bframe){
74        this();
75        this.frame = bframe;
76      }
77  
78  //------------------------------------------------------------------------------
79      public void addInternalFrame(JInternalFrame iframe){
80          desktopPane.add(iframe,JLayeredPane.PALETTE_LAYER);
81          positionInternalFrame(iframe);
82      }
83  //------------------------------------------------------------------------------
84      private void positionInternalFrame(JInternalFrame iframe){
85          try {
86             iframe.setSelected(true);
87          }
88  	catch(java.beans.PropertyVetoException e2) {
89          }
90          desktopPane.validate();
91          JInternalFrame[] allFrames = desktopPane.getAllFrames();
92  
93          if (allFrames.length > 1)
94            cascade();
95          else {
96              
97             Dimension frameSize = new Dimension (600,300); 
98             int width = (frameSize.width * 2) /4;
99             int height = (frameSize.height * 2) / 4;
100            iframe.setBounds(20,20, width,height );
101            iframe.setSize (width,height); 
102         }
103         repaint(); 
104     }
105 
106 
107 //------------------------------------------------------------------------------
108     private Vector getDisplayedFrames(){
109           Vector displayFrames = new Vector();
110           JInternalFrame[] allFrames = desktopPane.getAllFrames();
111           for (int i=0; i < allFrames.length; i++) {
112             if  (allFrames[i].isIcon() == false )
113              displayFrames.addElement(allFrames[i]);
114 
115           }
116         return displayFrames;
117     }
118 //------------------------------------------------------------------------------
119     public void tile() {
120           Vector displayFrames = getDisplayedFrames();
121           int numFrames = displayFrames.size();
122 
123           if ( numFrames== 0)
124             return;
125 
126           Dimension frameSize = desktopPane.getSize();
127           int width = frameSize.width;
128           int height = frameSize.height / numFrames;
129           Dimension newSize = new Dimension(width, height);
130           int currentY = 0;
131           Enumeration enum = displayFrames.elements();
132           while (enum.hasMoreElements()) {
133               JInternalFrame internalFrame = (JInternalFrame) enum.nextElement();
134               internalFrame.setSize(newSize);
135               internalFrame.setLocation(new Point(0, currentY));
136               currentY = currentY + height;
137           }
138           TILE = true;
139     }
140 //------------------------------------------------------------------------------
141 
142     public void cascade(){
143 
144           Vector displayFrames = getDisplayedFrames();
145           int numFrames = displayFrames.size();
146           int width, height;
147 
148           if ( numFrames== 0)
149             return;
150 
151           Dimension frameSize = this.getSize();
152 
153           if ( numFrames > 1 ) {
154              width = (frameSize.width * 4) /5;
155              height = (frameSize.height * 2) / 3;
156           }
157 
158           else {
159              width = frameSize.width-10;
160              height = frameSize.height-10;
161            }
162 
163           Dimension newSize = new Dimension(width, height);
164           int currentX = 0;
165           int currentY = 0;
166           Enumeration enum = displayFrames.elements();
167           while (enum.hasMoreElements()) {
168               JInternalFrame internalFrame = (JInternalFrame) enum.nextElement();
169               internalFrame.setSize(newSize);
170               internalFrame.setLocation(new Point(currentX, currentY));
171               currentX = currentX + (width / (numFrames + 1));
172               currentY = currentY + (height / (numFrames + 1));
173           }
174           TILE = false;
175     }
176 //------------------------------------------------------------------------------
177     public boolean tileOn(){
178          return TILE;
179     }
180 }