KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > about > AboutDialog


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.window.about;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import java.net.*;
24 import java.util.*;
25 import java.util.List JavaDoc;
26
27 import javax.swing.*;
28 import javax.swing.event.*;
29
30 import org.openharmonise.him.*;
31 import org.openharmonise.him.context.StateHandler;
32 import org.openharmonise.him.serverconfig.permissions.*;
33 import org.openharmonise.vfs.*;
34 import org.openharmonise.vfs.authentication.*;
35 import org.openharmonise.vfs.context.*;
36 import org.openharmonise.vfs.metadata.*;
37 import org.openharmonise.vfs.metadata.range.*;
38 import org.openharmonise.vfs.metadata.value.*;
39 import org.openharmonise.vfs.servers.*;
40
41
42 /**
43  * The about dialog which presents information to the user about this
44  * application.
45  *
46  * @author Matthew Large
47  * @version $Revision: 1.1 $
48  *
49  */

50 public class AboutDialog extends JDialog implements ActionListener, LayoutManager, ContextListener, ChangeListener {
51
52     /**
53      * OK button.
54      */

55     private JButton m_buttonOK = null;
56
57     /**
58      * Tabs.
59      */

60     private JTabbedPane m_tabs = null;
61     
62     /**
63      * Scroll pane containing the current user's details.
64      */

65     private JScrollPane m_userDetails = null;
66
67     /**
68      * Constructs a new about dialog.
69      *
70      * @param arg0
71      * @throws java.awt.HeadlessException
72      */

73     public AboutDialog(Frame arg0) throws HeadlessException {
74         super(arg0, "About", true);
75         this.setup();
76     }
77     
78     /**
79      * Initialises this component.
80      *
81      */

82     private void setup() {
83         
84         ContextHandler.getInstance().addListener(ContextType.CONTEXT_APP_FOCUS, this);
85             
86         this.setResizable(false);
87         
88         this.getContentPane().setLayout(this);
89         
90         this.setSize(400,500);
91         int x = this.getGraphicsConfiguration().getBounds().width/2-this.getSize().width/2;
92         int y = this.getGraphicsConfiguration().getBounds().height/2-this.getSize().height/2;
93         
94         this.setLocation(x, y);
95
96         String JavaDoc fontName = "Dialog";
97         int fontSize = 11;
98         Font font = new Font(fontName, Font.PLAIN, fontSize);
99         this.getContentPane().setBackground(new Color(224,224,224));
100         
101         this.m_buttonOK = new JButton("OK");
102         this.m_buttonOK.setActionCommand("OK");
103         this.m_buttonOK.addActionListener(this);
104         this.m_buttonOK.setFont(font);
105         this.getContentPane().add(this.m_buttonOK);
106         
107         this.m_tabs = new JTabbedPane();
108         this.m_tabs.setFont(font);
109         m_tabs.addChangeListener(this);
110         
111         this.getContentPane().add(this.m_tabs);
112         
113         this.addHTMLPane("Contact info", "/org/openharmonise/him/icons/files/contactinfo.html");
114         this.addHTMLPane("Credits", "/org/openharmonise/him/icons/files/credits.html");
115         this.addHTMLPane("Version", "/org/openharmonise/him/icons/files/version.html");
116         this.addHTMLPane("Legal", "/org/openharmonise/him/icons/files/licence.html");
117         
118         m_tabs.add("Who am I",null);
119     }
120
121     /* (non-Javadoc)
122      * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
123      */

124     public void actionPerformed(ActionEvent arg0) {
125         ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this);
126         this.hide();
127     }
128     
129     /**
130      * Adds a tab which contains a HTML page at the given resource URL (i.e. it
131      * is in the classpath).
132      *
133      * @param sTitle title for tab.
134      * @param sURL URL to the HTML for the tab contents.
135      */

136     private void addHTMLPane(String JavaDoc sTitle, String JavaDoc sURL) {
137         try {
138             URL url = getClass()
139                           .getResource(sURL);
140             JEditorPane html = new JEditorPane(url);
141             html.setEditable(false);
142     
143             JScrollPane scroller = new JScrollPane();
144             JViewport vp = scroller.getViewport();
145             vp.add(html);
146             this.m_tabs.addTab(sTitle, scroller);
147         } catch (Exception JavaDoc e) {
148             e.printStackTrace(System.out);
149         }
150     }
151
152     /* (non-Javadoc)
153      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
154      */

155     public void layoutContainer(Container arg0) {
156         this.m_tabs.setSize(this.getSize().width-10, 430);
157         this.m_tabs.setLocation(0, 0);
158         
159         this.m_buttonOK.setSize(70, 20);
160         this.m_buttonOK.setLocation(this.getSize().width-100, 440);
161         
162         
163     }
164
165     /* (non-Javadoc)
166      * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
167      */

168     public void contextMessage(ContextEvent ce) {
169         if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) {
170             this.toFront();
171         }
172     }
173     
174
175     /**
176      * @throws java.awt.HeadlessException
177      */

178     private AboutDialog() throws HeadlessException {
179         super();
180     }
181
182     /**
183      * @param arg0
184      * @throws java.awt.HeadlessException
185      */

186     private AboutDialog(Dialog arg0) throws HeadlessException {
187         super(arg0);
188     }
189
190     /**
191      * @param arg0
192      * @param arg1
193      * @throws java.awt.HeadlessException
194      */

195     private AboutDialog(Dialog arg0, boolean arg1) throws HeadlessException {
196         super(arg0, arg1);
197     }
198
199     /**
200      * @param arg0
201      * @param arg1
202      * @throws java.awt.HeadlessException
203      */

204     private AboutDialog(Frame arg0, boolean arg1) throws HeadlessException {
205         super(arg0, arg1);
206     }
207
208     /**
209      * @param arg0
210      * @param arg1
211      * @throws java.awt.HeadlessException
212      */

213     private AboutDialog(Dialog arg0, String JavaDoc arg1) throws HeadlessException {
214         super(arg0, arg1);
215     }
216
217     /**
218      * @param arg0
219      * @param arg1
220      * @param arg2
221      * @throws java.awt.HeadlessException
222      */

223     private AboutDialog(Dialog arg0, String JavaDoc arg1, boolean arg2)
224         throws HeadlessException {
225         super(arg0, arg1, arg2);
226     }
227
228     /**
229      * @param arg0
230      * @param arg1
231      * @throws java.awt.HeadlessException
232      */

233     private AboutDialog(Frame arg0, String JavaDoc arg1) throws HeadlessException {
234         super(arg0, arg1);
235     }
236
237     /**
238      * @param arg0
239      * @param arg1
240      * @param arg2
241      * @throws java.awt.HeadlessException
242      */

243     private AboutDialog(Frame arg0, String JavaDoc arg1, boolean arg2)
244         throws HeadlessException {
245         super(arg0, arg1, arg2);
246     }
247
248     /**
249      * @param arg0
250      * @param arg1
251      * @param arg2
252      * @param arg3
253      * @throws java.awt.HeadlessException
254      */

255     private AboutDialog(
256         Dialog arg0,
257         String JavaDoc arg1,
258         boolean arg2,
259         GraphicsConfiguration arg3)
260         throws HeadlessException {
261         super(arg0, arg1, arg2, arg3);
262     }
263
264     /**
265      * @param arg0
266      * @param arg1
267      * @param arg2
268      * @param arg3
269      */

270     private AboutDialog(
271         Frame arg0,
272         String JavaDoc arg1,
273         boolean arg2,
274         GraphicsConfiguration arg3) {
275         super(arg0, arg1, arg2, arg3);
276     }
277
278     /* (non-Javadoc)
279      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
280      */

281     public void removeLayoutComponent(Component arg0) {
282     }
283
284     /* (non-Javadoc)
285      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
286      */

287     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
288     }
289
290     /* (non-Javadoc)
291      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
292      */

293     public Dimension minimumLayoutSize(Container arg0) {
294         return this.getSize();
295     }
296
297     /* (non-Javadoc)
298      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
299      */

300     public Dimension preferredLayoutSize(Container arg0) {
301         return this.getSize();
302     }
303
304     /**
305      * Gets a user details panel.
306      *
307      * @return user details panel.
308      */

309     private JScrollPane getUserDetails() {
310         StateHandler.getInstance().addWait("USER_DETAILS",
311         "Getting user details...");
312         String JavaDoc sRole = "";
313         Server server = null;
314         boolean isSuper = false;
315         server = ServerList.getInstance().getHarmoniseServer();
316         AbstractVirtualFileSystem vfs = server.getVFS();
317         VirtualFileSystemView vfsView = vfs.getVirtualFileSystemView();
318         AuthInfo auth = vfs.getAuthentication();
319         StringBuffer JavaDoc sbuff = new StringBuffer JavaDoc();
320         if(auth.getUser().isSuperUser()){
321             sRole = "super";
322             isSuper = true;
323         }else {
324             Iterator itor = PermissionsServerConfigOptions.getObjectPropertyDefinitions().iterator();
325             String JavaDoc sRolePath = auth.getUser().getRolePath();
326             VirtualFile vfRole = vfs.getVirtualFile(sRolePath).getResource();
327             sRole = ValueCache.getInstance().getValue(sRolePath).getDisplayName();
328             sbuff.append("<table>");
329             sbuff.append("<tr><td><STRONG><font face='Arial'>Harmonise Object</font></STRONG></td>" +
330                     "<td><STRONG><font face='Arial'>Permissions</font></STRONG></td></tr>");
331             while (itor.hasNext()) {
332                 String JavaDoc sPermission = "";
333                 Property prop = (Property) itor.next();
334                 ValueRange range = (ValueRange)prop.getRange();
335                 PropertyInstance propInst = vfRole.getProperty(prop.getNamespace(), prop.getName());
336                 sbuff.append( "<tr><td><font face='Arial'>" + propInst.getName() + "</font></td>");
337                 sbuff.append( "<td bgColor=#efefef><font face='Arial'>" );
338                 List JavaDoc vals = propInst.getValues();
339                 int size = 0;
340                 if(vals==null || vals.size()==0){
341                     sPermission = "none";
342                 } else {
343                     size=vals.size();
344                 }
345                 for(int i=0;i<vals.size();i++){
346                     ValueValue valInst = (ValueValue)vals.get(i);
347                     Value val = ValueCache.getInstance().getValue(valInst.getValue());
348                     sPermission += val.getDisplayName();
349                     if(i<size-1){
350                         sPermission += ", ";
351                     }
352                 }
353                 sbuff.append(sPermission + "</font></td></tr>");
354             }
355             sbuff.append("</table>");
356         }
357         JEditorPane html = new JEditorPane();
358         html.setContentType("text/html");
359         String JavaDoc text = "<html><head></head>" +
360                 "<body><font face='Arial'>" +
361                 "<p>You are logged on as <b>" + auth.getUsername() + "</b>" +
362                 " with a role of <b>" + sRole + "</b>.";
363         if(isSuper){
364             text += "<p>A super user has a special privilege level, " +
365                     "with unlimited access to all Resources, " +
366                     "Collections, and commands.</p>";
367         } else {
368             text += "<p>You have the following permissions.</p>" +
369             "<p>" + sbuff.toString() + "</p>";
370         }
371         text += "</font></body></html>";
372         html.setText( text );
373         html.setEditable(false);
374         JScrollPane scroller = new JScrollPane();
375         JViewport vp = scroller.getViewport();
376         vp.add(html);
377         m_userDetails = scroller;
378         
379         StateHandler.getInstance().removeWait("USER_DETAILS");
380             
381         return scroller;
382     }
383
384     /* (non-Javadoc)
385      * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
386      */

387     public void stateChanged(ChangeEvent e) {
388         int index = m_tabs.getSelectedIndex();
389         String JavaDoc sTab = m_tabs.getTitleAt(index);
390         if(sTab.equalsIgnoreCase("Who am I")){
391             if(m_userDetails == null) {
392                 m_userDetails = getUserDetails();
393             }
394             m_tabs.setComponentAt(index, m_userDetails);
395             System.out.println(m_userDetails.getVerticalScrollBar().getValue());
396             m_userDetails.getVerticalScrollBar().setValue(0);
397         }
398     }
399
400 }
401
Popular Tags