001/*
002$Source: v:/cvsroot/open/projects/WebARTS/ca/bc/webarts/widgets/JAboutBox.java,v $
003$Name:  $
004
005Current File Status:
006$Revision: 567 $
007$Date: 2012-11-03 20:36:02 -0700 (Sat, 03 Nov 2012) $
008$Locker:  $
009
010Copyright (C) 2001 WebARTS Design, North Vancouver Canada
011*/
012
013package ca.bc.webarts.widgets;
014
015import java.awt.*;
016import java.awt.event.*;
017import java.util.*;
018import java.lang.System;
019import javax.swing.*;
020import javax.swing.event.*;
021import ca.bc.webarts.widgets.ImageCanvas;
022
023
024
025public class JAboutBox extends JFrame
026{
027  Toolkit toolkit = Toolkit.getDefaultToolkit();
028  ImageCanvas canvas;
029  String imageJarFilename_ = "";
030  String graphicFilename_ = "";
031  String versionStr_ = "";
032  static String helpHtmlStr_ = "";
033  Image image_ = null;
034
035//      TBGJPanel mainPanel = new TBGJPanel();
036  JPanel mainPanel = new JPanel();
037  JPanel titlePanel = new JPanel();
038  JPanel innerPanel = new JPanel();
039  JPanel graphicPanel = new JPanel();
040  JPanel textPanel = new JPanel();
041  JPanel buttonPanel = new JPanel();
042  JPanel topPanel = new JPanel();
043  String htmlTitle, tag;
044  JButton vmButton, sysButton, dbButton, helpButton, closeButton;
045  Color defaultColour = new Color(156,154,206); // this is the Java L&F Purple!
046  javax.swing.border.BevelBorder mainBevelBorder =
047     new javax.swing.border.BevelBorder(javax.swing.border.BevelBorder.LOWERED);
048
049/* Constructor */
050/***************/
051public JAboutBox( String parentTitle,
052                  String detailedTitle,
053                  String versionString)
054{
055  this(null, parentTitle, detailedTitle, versionString, "No Help Available.");
056}
057
058
059/* Constructor */
060/***************/
061public JAboutBox( String parentTitle,
062                  String detailedTitle )
063{
064  this(null, parentTitle, detailedTitle, "", "No Help Available." );
065}
066
067/* Constructor */
068/***************/
069public JAboutBox( Image i, String parentTitle, String detailedTitle,
070                  String versionString, String helpHtml )
071{
072
073    /* get the super class frame to build a frame with a title */
074    super(parentTitle);
075    versionStr_ = versionString;
076    helpHtmlStr_ = helpHtml;
077    image_ = i;
078        try
079        {
080          final String jvmVer = System.getProperty("java.version");
081          final String JVMvendor = System.getProperty("java.vendor") + " " +
082            System.getProperty("java.vendor.url");
083          final String OSname = System.getProperty("os.name");
084          final String OSarch = System.getProperty("os.arch");
085          final String OSver = System.getProperty("os.version");
086          final String UserName = System.getProperty("user.name");
087          final String UserDir = System.getProperty("user.home");
088/*              final String dbVendor = parentApplet.getdbVendorParam();
089          final String dbName = parentApplet.getdbNameParam();
090          final String dbUsername = parentApplet.getdbUsernameParam();
091          final String dbdbPassword = parentApplet.getdbPasswordParam();
092          final String dbServer = parentApplet.getdbServerParam();
093          final String dbPort = parentApplet.getdbPortParam();
094*/
095/*
096java.version    Java Runtime Environment version
097java.vendor     Java Runtime Environment vendor
098java.vendor.url Java vendor URL
099java.home       Java installation directory
100java.vm.specification.version   Java Virtual Machine specification version
101java.vm.specification.vendor    Java Virtual Machine specification vendor
102java.vm.specification.name      Java Virtual Machine specification name
103java.vm.version Java Virtual Machine implementation version
104java.vm.vendor  Java Virtual Machine implementation vendor
105java.vm.name    Java Virtual Machine implementation name
106java.specification.version      Java Runtime Environment specification version
107java.specification.vendor       Java Runtime Environment specification vendor
108java.specification.name Java Runtime Environment specification name
109java.class.version      Java class format version number
110java.class.path Java class path
111os.name Operating system name
112os.arch Operating system architecture
113os.version      Operating system version
114file.separator  File separator ("/" on UNIX)
115path.separator  Path separator (":" on UNIX)
116line.separator  Line separator ("\n" on UNIX)
117user.name       User's account name
118user.home       User's home directory
119user.dir   User's current working directory
120*/
121
122      /* set the layout Manager and borders for the JFrame */
123      mainPanel.setLayout(new BorderLayout()); //10,10));
124      mainPanel.setBackground(defaultColour);
125      mainPanel.setBorder(mainBevelBorder);
126      buttonPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
127
128
129      /* place The Title Label into the app frame */
130      htmlTitle = new String("<html><body bgcolor=\"#eeeeee\"><p align=\"center\"><FONT FACE=\"QuillScript\" SIZE=\"+1\">");
131      htmlTitle += "Web<I>ARTS</I> Design</FONT></body></html>";
132      titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
133      titlePanel.add(new JLabel(htmlTitle));
134
135      /* make up the text that will go into the text area */
136      tag = new String("<html><body bgcolor=\"#dddddd\"><p align=\"center\">"+
137                detailedTitle);
138      tag += "<p align=\"center\">" +versionStr_+ "<BR>";
139      tag += "<p align=\"center\">Tom B. Gutwin P.Eng.</body></html>";
140
141      /* make the Displayed panels */
142//      topPanel.setLayout(new GridLayout(0,2));
143      buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,10));
144      graphicPanel.setLayout(new BorderLayout(10,10)); //FlowLayout(FlowLayout.CENTER,0,0));
145      textPanel.setLayout(new BorderLayout(10,10)); //FlowLayout(FlowLayout.CENTER,0,0));
146      innerPanel.setLayout(new BorderLayout(10,10));
147
148      /* fill the text panel */
149      textPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
150      textPanel.add(new JLabel(tag),"Center");
151
152      /* fill the graphic Panel */
153      if(image_ == null)
154        image_   = toolkit.getImage("images/DONT_PAN.GIF");
155      canvas  = new ImageCanvas(image_);
156      graphicPanel.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
157      graphicPanel.add(canvas,"Center");
158
159      /* create the buttons */
160      vmButton = new JButton("Java VM Info.");
161      sysButton = new JButton("System Info.");
162      dbButton = new JButton("Database Info.");
163      helpButton = new JButton("Help");
164      closeButton = new JButton("Close");
165      Dimension tempSize =new Dimension(85,30);
166      Font tempFont = new Font("Dialog",Font.PLAIN,10);
167      vmButton.setPreferredSize(tempSize);vmButton.setFont(tempFont);vmButton.setMargin(new Insets(6,6,6,6));
168      sysButton.setPreferredSize(tempSize);sysButton.setFont(tempFont);sysButton.setMargin(new Insets(6,6,6,6));
169      dbButton.setPreferredSize(tempSize);dbButton.setFont(tempFont);dbButton.setMargin(new Insets(6,6,6,6));
170      helpButton.setPreferredSize(tempSize);helpButton.setFont(tempFont);helpButton.setMargin(new Insets(6,6,6,6));
171      closeButton.setPreferredSize(tempSize);closeButton.setFont(tempFont);closeButton.setMargin(new Insets(6,6,6,6));
172
173      buttonPanel.add(vmButton);
174      buttonPanel.add(sysButton);
175//      buttonPanel.add(dbButton);
176      buttonPanel.add(closeButton);
177      buttonPanel.add(helpButton);
178
179      /*  Add the Button Action Listeners */
180      /************************************/
181      /* JDK VM Button */
182      vmButton.addActionListener(new ActionListener() {
183        public void actionPerformed(ActionEvent event)
184        {
185          /* now add the specific stuff for this Menu Item */
186          /* open a dialog to find out what version to print the text output*/
187          Object [] options = {"Okay"};
188          JScrollPane js = new JScrollPane();
189
190          JOptionPane pane = new JOptionPane(
191                (Object) new JLabel("<html><body><B><U>Java Vendor:</U> " +
192                                    JVMvendor + "<BR><U>Java VM Version:</U> " +
193                                    jvmVer+ "<BR><U>JVM Free Memory:</U> " +
194                                    java.lang.Runtime.getRuntime().freeMemory() +
195                                    "/" +java.lang.Runtime.getRuntime().totalMemory()+
196                                    " bytes"+
197                                    "</B></body></html>"),
198                JOptionPane.INFORMATION_MESSAGE,
199                JOptionPane.DEFAULT_OPTION,
200                new ImageIcon(),
201                options) ;
202           JDialog dialog = pane.createDialog(getParent(), "Java VM Information");
203           dialog.show();
204        }/* action performed */
205      });
206
207      /* System Info Button */
208      sysButton.addActionListener(new ActionListener() {
209        public void actionPerformed(ActionEvent event)
210        {
211          /* now add the specific stuff for this Menu Item */
212          Object [] options = {"Okay"};
213           JOptionPane pane = new JOptionPane((Object) new JLabel("<html><body><B>" +
214                                      "<U>User's account name:</U> " + UserName +
215                                      "<BR><U>User Home Directory:</U> "+UserDir +
216                                      "<BR><U>Operating system name:</U> " +OSname+
217                                      "<BR><U>Operating system version:</U> " +OSver+
218                                      "<BR><U>Operating system architecture:</U> " +OSarch+
219                                      "</B></body></html>"),
220                            JOptionPane.INFORMATION_MESSAGE,
221                            JOptionPane.DEFAULT_OPTION,
222                            new ImageIcon(),
223                            options) ;
224           JDialog dialog = pane.createDialog(getParent(), "User System Information");
225           dialog.show();
226        }/* action performed */
227      });
228
229      /* Database Info. Button */
230      dbButton.addActionListener(new ActionListener() {
231        public void actionPerformed(ActionEvent event)
232        {
233          /* now add the specific stuff for this Menu Item */
234          Object [] options = {"Okay"};
235//                                       JOptionPane pane = new JOptionPane((Object) new JLabel("<html><body><U>Database Vendor:</U> "+ dbVendor +
236//                                                                                                                                                      "<BR><U>Database Name:</U> " +dbName +
237//                                                                                                                                                      "<BR><U>Database Server:</U> " +dbServer +
238//                                                                                                                                                      "<BR><U>Database Server Port:</U> " +dbPort +
239//                                                                                                                                                      "</body></html>"),
240//                                                                                                              JOptionPane.INFORMATION_MESSAGE,
241//                                                                                                              JOptionPane.DEFAULT_OPTION,
242//                                                                                                              new ImageIcon(),
243//                                                                                                              options) ;
244//                                       JDialog dialog = pane.createDialog(getParent(), "Database Information");
245//                                       dialog.show();
246      }/* action performed */
247      });
248
249      /* Help Button */
250      helpButton.addActionListener(new ActionListener() {
251        public void actionPerformed(ActionEvent event)
252        {
253          /* now add the specific stuff for this Menu Item */
254            Object [] options = {"Done"};
255            JEditorPane htmlPane = new JEditorPane("text/html",
256                           "<html><body>" +
257                            helpHtmlStr_+
258                            "</body></html>");
259            htmlPane.setEditable(false);
260
261            JScrollPane htmlScrollPane = new JScrollPane(htmlPane);
262            htmlScrollPane.setVerticalScrollBarPolicy(
263                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
264            htmlScrollPane.setPreferredSize(new Dimension(640, 480));
265            JOptionPane pane = new JOptionPane(
266                            (Object) htmlScrollPane,
267                            JOptionPane.INFORMATION_MESSAGE,
268                            JOptionPane.DEFAULT_OPTION,
269                            new ImageIcon(),
270                            options) ;
271            JDialog dialog = pane.createDialog(getParent(), "Help");
272            dialog.show();
273        }/* action performed */
274      });
275
276      /* window Close Button */
277      closeButton.addActionListener(new ActionListener() {
278        public void actionPerformed(ActionEvent event)
279        {
280          /* now add the specific stuff for this Menu Item */
281            dispose();
282        }/* action performed */
283      });
284
285
286      /* Stitch it all together so it is laid out */
287      topPanel.add(graphicPanel);
288      topPanel.add(textPanel);
289      innerPanel.add(topPanel,"Center");
290      innerPanel.add(buttonPanel, "South");
291      mainPanel.add(titlePanel, "North");
292      mainPanel.add(innerPanel, "Center");
293
294      /* place The Main Panels into the app frame */
295      getContentPane().add(mainPanel);
296      doLayout();
297
298      /* set the size and placement on the screen */
299      Dimension overallSize;
300      Point location;
301      try {
302        Dimension myDialogSize = getPreferredSize();
303        overallSize = toolkit.getScreenSize();
304        location = new Point(0,0);;
305        int windowWidth = overallSize.width;
306        int     windowHeight = overallSize.height;
307        int myWidth = myDialogSize.width;
308        int myHeight = myDialogSize.height;
309        int newX= location.x +  (windowWidth/2) - myWidth/2;
310        int newY=  location.y + (windowHeight/2) - myHeight/2;
311        setLocation( newX,newY);
312      }
313      catch (Exception ex){
314        System.out.println("Caught Exception: AboutBox ");
315        ex.printStackTrace();
316      }
317
318
319      setSize(500,225);
320      setResizable(false);
321      setVisible(true);
322      pack();
323      show();
324      toFront();
325      validate();
326
327      /* listen for closing */
328      addWindowListener(new WindowAdapter()
329      {
330        public void windowClosing(WindowEvent event)
331        {
332          dispose();
333        }
334      }); /* inner WindowAdapter class */
335    }
336    catch (Throwable t)
337    {
338            System.out.println("About Box caught an exception: " + t);
339            t.printStackTrace();
340        }
341  }
342}
343/*
344Here is the revision log
345------------------------
346$Log: JAboutBox.java,v $
347Revision 1.7  2001/12/16 07:16:32  tgutwin
348
349Added user.home to the system info that is output when the button
350is pressed.
351
352Revision 1.6  2001/12/12 14:37:43  tgutwin
353
354Added the API to send a String of HTML to be used as help Text when the help button is pressed.
355
356Revision 1.5  2001/09/02 03:24:18  tgutwin
357
358Initial Rev of my custom DropDown Boxes.
359
360Revision 1.4  2001/06/16 21:55:15  tgutwin
361No Changes
362
363Revision 1.3  2001/06/16 21:47:45  tgutwin
364Added CVS Keywords and headers
365
366
367*/