| 1 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 ; 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 50 public class AboutDialog extends JDialog implements ActionListener, LayoutManager, ContextListener, ChangeListener { 51 52 55 private JButton m_buttonOK = null; 56 57 60 private JTabbedPane m_tabs = null; 61 62 65 private JScrollPane m_userDetails = null; 66 67 73 public AboutDialog(Frame arg0) throws HeadlessException { 74 super(arg0, "About", true); 75 this.setup(); 76 } 77 78 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 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 124 public void actionPerformed(ActionEvent arg0) { 125 ContextHandler.getInstance().removeListener(ContextType.CONTEXT_APP_FOCUS, this); 126 this.hide(); 127 } 128 129 136 private void addHTMLPane(String sTitle, String 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 e) { 148 e.printStackTrace(System.out); 149 } 150 } 151 152 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 168 public void contextMessage(ContextEvent ce) { 169 if(ce.CONTEXT_TYPE==ContextType.CONTEXT_APP_FOCUS) { 170 this.toFront(); 171 } 172 } 173 174 175 178 private AboutDialog() throws HeadlessException { 179 super(); 180 } 181 182 186 private AboutDialog(Dialog arg0) throws HeadlessException { 187 super(arg0); 188 } 189 190 195 private AboutDialog(Dialog arg0, boolean arg1) throws HeadlessException { 196 super(arg0, arg1); 197 } 198 199 204 private AboutDialog(Frame arg0, boolean arg1) throws HeadlessException { 205 super(arg0, arg1); 206 } 207 208 213 private AboutDialog(Dialog arg0, String arg1) throws HeadlessException { 214 super(arg0, arg1); 215 } 216 217 223 private AboutDialog(Dialog arg0, String arg1, boolean arg2) 224 throws HeadlessException { 225 super(arg0, arg1, arg2); 226 } 227 228 233 private AboutDialog(Frame arg0, String arg1) throws HeadlessException { 234 super(arg0, arg1); 235 } 236 237 243 private AboutDialog(Frame arg0, String arg1, boolean arg2) 244 throws HeadlessException { 245 super(arg0, arg1, arg2); 246 } 247 248 255 private AboutDialog( 256 Dialog arg0, 257 String arg1, 258 boolean arg2, 259 GraphicsConfiguration arg3) 260 throws HeadlessException { 261 super(arg0, arg1, arg2, arg3); 262 } 263 264 270 private AboutDialog( 271 Frame arg0, 272 String arg1, 273 boolean arg2, 274 GraphicsConfiguration arg3) { 275 super(arg0, arg1, arg2, arg3); 276 } 277 278 281 public void removeLayoutComponent(Component arg0) { 282 } 283 284 287 public void addLayoutComponent(String arg0, Component arg1) { 288 } 289 290 293 public Dimension minimumLayoutSize(Container arg0) { 294 return this.getSize(); 295 } 296 297 300 public Dimension preferredLayoutSize(Container arg0) { 301 return this.getSize(); 302 } 303 304 309 private JScrollPane getUserDetails() { 310 StateHandler.getInstance().addWait("USER_DETAILS", 311 "Getting user details..."); 312 String 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 sbuff = new StringBuffer (); 320 if(auth.getUser().isSuperUser()){ 321 sRole = "super"; 322 isSuper = true; 323 }else { 324 Iterator itor = PermissionsServerConfigOptions.getObjectPropertyDefinitions().iterator(); 325 String 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 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 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 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 387 public void stateChanged(ChangeEvent e) { 388 int index = m_tabs.getSelectedIndex(); 389 String 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 |