001    /**
002       ##############################################################################
003       ##                                                                          ##
004       ## EnvInfo                                                                  ##
005       ##                                                                          ##
006       ## Copyright (C) 2009  Frederic Roudaut  <frederic.roudaut@free.fr>         ##
007       ##                                                                          ##
008       ##                                                                          ##
009       ## This program is free software: you can redistribute it and/or modify     ##
010       ## it under the terms of the GNU General Public License as published by     ##
011       ## the Free Software Foundation, either version 3 of the License, or        ##
012       ## (at your option) any later version.                                      ##
013       ##                                                                          ##
014       ## This program is distributed in the hope that it will be useful,          ##
015       ## but WITHOUT ANY WARRANTY; without even the implied warranty of           ##
016       ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            ##
017       ## GNU General Public License for more details.                             ##
018       ##                                                                          ##
019       ## You should have received a copy of the GNU General Public License        ##
020       ## along with this program.  If not, see <http://www.gnu.org/licenses/>.    ##
021       ##                                                                          ##
022       ##                                                                          ##
023       ##############################################################################
024     **/
025    
026    
027    
028    package com.envInfo;
029    
030    
031    import java.awt.BorderLayout;
032    import java.awt.GridBagLayout;
033    import java.awt.GridBagConstraints;
034    import java.awt.event.*;
035    import java.awt.Insets;
036    import java.awt.Font;
037    import java.awt.Dimension;
038    import javax.swing.*;
039    
040    import com.awt.GridBagLayoutConstraint;
041    
042    import java.util.*;
043    
044    
045    
046    /**
047     * An helpful class for tierce information, for showing Java Info  
048     *
049     */
050    public class JavaInfo extends JFrame
051    {
052    
053            private static final long serialVersionUID = 1L;
054    
055    
056            /**
057             * Draw a Frame with Java Info.
058             *
059             */       
060            public JavaInfo()
061            {
062                    this(new Dimension(500, 300));
063            }
064    
065            /**
066             * Draw a Frame with Java Info.
067             * @param d the text Panel Dimension.
068             *
069             */       
070            public JavaInfo(Dimension d)
071            {
072                    super(Info.ressources.getObject("Java_Info").toString());       
073                    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
074                    setVisible(true);
075    
076                    JLabel entryText;                       
077                    JPanel textPanel = new JPanel();
078    
079                    GridBagLayout gb = new GridBagLayout();
080                    textPanel.setLayout(gb);
081    
082                    entryText = new JLabel(Info.ressources.getObject("java_specification_name").toString());
083                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
084                    textPanel.add(entryText);
085                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,11,
086                                    new Insets(0,8,0,15)));
087    
088                    entryText = new JLabel("= " + System.getProperty("java.specification.name"));
089                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
090                    textPanel.add(entryText);
091                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,11,
092                                    new Insets(0,8,0,15)));         
093    
094                    entryText = new JLabel(Info.ressources.getObject("java_specification_version").toString());
095                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
096                    textPanel.add(entryText);
097                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,12,
098                                    new Insets(0,8,0,15))); 
099    
100                    entryText = new JLabel("= " + System.getProperty("java.specification.version"));
101                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
102                    textPanel.add(entryText);
103                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,12,
104                                    new Insets(0,8,0,15)));         
105    
106                    entryText = new JLabel(Info.ressources.getObject("java_version").toString());
107                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
108                    textPanel.add(entryText);
109                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,13,
110                                    new Insets(0,8,0,15)));
111    
112    
113                    entryText = new JLabel("= " + System.getProperty("java.version"));
114                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
115                    textPanel.add(entryText);
116                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,13,
117                                    new Insets(0,8,0,15)));         
118    
119                    entryText = new JLabel(Info.ressources.getObject("java_vendor").toString());
120                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
121                    textPanel.add(entryText);
122                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,14,
123                                    new Insets(0,8,0,15)));
124    
125                    entryText = new JLabel("= " + System.getProperty("java.vendor"));
126                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
127                    textPanel.add(entryText);
128                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,14,
129                                    new Insets(0,8,0,15)));         
130    
131                    entryText = new JLabel(Info.ressources.getObject("java_vm_version").toString());
132                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
133                    textPanel.add(entryText);
134                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,15,
135                                    new Insets(0,8,0,15)));
136    
137                    entryText = new JLabel("= " + System.getProperty("java.vm.version"));
138                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
139                    textPanel.add(entryText);
140                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,15,
141                                    new Insets(0,8,0,15)));         
142    
143                    entryText = new JLabel(Info.ressources.getObject("java_class_version").toString());
144                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
145                    textPanel.add(entryText);
146                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,16,
147                                    new Insets(0,8,0,15)));
148    
149                    entryText = new JLabel("= " + System.getProperty("java.class.version"));
150                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
151                    textPanel.add(entryText);
152                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,16,
153                                    new Insets(0,8,0,15)));         
154    
155                    entryText = new JLabel(Info.ressources.getObject("java_runtime_name").toString());
156                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
157                    textPanel.add(entryText);
158                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,17,
159                                    new Insets(0,8,0,15)));
160    
161                    entryText = new JLabel("= " + System.getProperty("java.runtime.name"));
162                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
163                    textPanel.add(entryText);
164                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,17,
165                                    new Insets(0,8,0,15)));         
166    
167                    entryText = new JLabel(Info.ressources.getObject("java_runtime_version").toString());
168                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
169                    textPanel.add(entryText);
170                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,18,
171                                    new Insets(0,8,0,15)));
172    
173                    entryText = new JLabel("= " + System.getProperty("java.runtime.version"));
174                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
175                    textPanel.add(entryText);
176                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,18,
177                                    new Insets(0,8,0,15)));         
178    
179                    entryText = new JLabel(Info.ressources.getObject("java_home").toString());
180                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
181                    textPanel.add(entryText);
182                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,19,
183                                    new Insets(0,8,0,15))); 
184    
185                    entryText = new JLabel("= " + System.getProperty("java.home"));
186                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
187                    textPanel.add(entryText);
188                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,19,
189                                    new Insets(0,8,0,15)));         
190    
191                    entryText = new JLabel(Info.ressources.getObject("java_ext_dirs").toString());
192                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
193                    textPanel.add(entryText);
194                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,20,
195                                    new Insets(0,8,0,15)));
196    
197                    entryText = new JLabel("= " + System.getProperty("java.ext.dirs"));
198                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
199                    textPanel.add(entryText);
200                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,20,
201                                    new Insets(0,8,0,15)));         
202    
203                    entryText = new JLabel(Info.ressources.getObject("java_class_path").toString());
204                    entryText.setFont(new Font("SansSerif", Font.BOLD, 11));
205                    textPanel.add(entryText);
206                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,21,
207                                    new Insets(0,8,0,15)));
208    
209    
210                    entryText = new JLabel("= " + System.getProperty("java.class.path"));
211                    entryText.setFont(new Font("SansSerif", Font.PLAIN, 10));
212                    textPanel.add(entryText);
213                    gb.setConstraints(entryText, new GridBagLayoutConstraint(GridBagConstraints.WEST,1,21,
214                                    new Insets(0,8,0,15)));         
215    
216    
217                    JScrollPane textScrolled = new JScrollPane(textPanel);
218                    textScrolled.setPreferredSize(d);       
219                    JPanel javaInfoBoxPanel = new JPanel(new BorderLayout());
220                    GridBagLayout gbMain = new GridBagLayout();
221                    javaInfoBoxPanel.setLayout(gbMain);
222                    javaInfoBoxPanel.add(textScrolled);
223                    GridBagConstraints gbc = new GridBagLayoutConstraint(GridBagConstraints.EAST,0,0,
224                                    new Insets(15,15,15,15));
225                    gbc.gridwidth = 3;
226                    gbMain.setConstraints(textScrolled, gbc);
227    
228                    JButton packagesbutton = new JButton("PKGs");
229                    javaInfoBoxPanel.add(packagesbutton);
230                    gbMain.setConstraints(packagesbutton, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,1,
231                                    new Insets(8,8,8,2)));
232                    packagesbutton.addActionListener(new ActionListener() { 
233                            public void actionPerformed(ActionEvent e) {
234                                    showJavaPackagesInfo();
235                            }});     
236    
237                    JButton propertiesbutton = new JButton(Info.ressources.getObject("Properties").toString());
238                    javaInfoBoxPanel.add(propertiesbutton);
239                    gbMain.setConstraints(propertiesbutton, new GridBagLayoutConstraint(GridBagConstraints.EAST,1,1,
240                                    new Insets(8,2,8,8)));
241                    propertiesbutton.addActionListener(new ActionListener() {       
242                            public void actionPerformed(ActionEvent e) {
243                                    showJavaPropertiesInfo();
244                            }});     
245    
246    
247    
248                    JButton okbutton = new JButton(Info.ressources.getObject("OK").toString());
249                    javaInfoBoxPanel.add(okbutton);
250                    gbMain.setConstraints(okbutton, new GridBagLayoutConstraint(GridBagConstraints.EAST,2,1,
251                                    new Insets(8,8,8,8)));
252                    okbutton.addActionListener(new ActionListener() {
253                            public void actionPerformed(ActionEvent e) {
254                                    setVisible(false);
255                                    dispose();
256                            }
257                    });      
258    
259                    getContentPane().add(javaInfoBoxPanel, BorderLayout.CENTER);            
260                    pack();
261                    setResizable(false);
262                    setVisible(true);
263            }
264    
265    
266    
267            /**
268             * Draw a Frame with the Java Packages Info.
269             *
270             */      
271            public static void showJavaPackagesInfo()
272            {
273                    showJavaPackagesInfo(new Dimension(650, 800));
274            }
275    
276            /**
277             * Draw a Frame with the Java Packages Info.
278             * @param d the text Panel Dimension
279             *
280             */      
281            public static void showJavaPackagesInfo(Dimension d)
282            {
283                    final JFrame pkgsFrame = new JFrame(Info.ressources.getObject("Packages_Info").toString());
284                    pkgsFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);   
285    
286                    JTextArea text = new JTextArea();
287                    text.setFont(new Font("SansSerif", Font.PLAIN, 12));       
288                    JPanel textPanel = new JPanel();
289                    JPanel pkgsPanel = new JPanel();
290                    GridBagLayout gb = new GridBagLayout();
291                    pkgsPanel.setLayout(gb);
292    
293                    Package pkgs[];
294                    pkgs = Package.getPackages();           
295                    JScrollPane textScrolled = new JScrollPane(text);       
296                    textScrolled.setPreferredSize(d);   
297                    textPanel.add(textScrolled);    
298                    pkgsPanel.add(textPanel);
299                    gb.setConstraints(textPanel, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,0,
300                                    new Insets(15,15,15,15)));
301    
302                    String [] pkgsTab = new String [pkgs.length];
303                    String textContent = "";
304    
305                    for(int i=0; i < pkgs.length; i++)
306                    {                           
307                            pkgsTab[i] = " " + pkgs[i].getName() + " : " +
308                            pkgs[i].getImplementationTitle() + ", " +
309                            pkgs[i].getImplementationVendor() + ", " +
310                            pkgs[i].getImplementationVersion() + "\n";                  
311                    }
312                    Arrays.sort(pkgsTab);
313                    for(int i=0; i < pkgs.length; i++)
314                    {
315                            textContent += pkgsTab[i];
316                    }
317    
318                    text.append(textContent);
319                    text.setCaretPosition(0);
320    
321                    JButton okbutton = new JButton(Info.ressources.getObject("OK").toString());
322                    pkgsPanel.add(okbutton);
323                    gb.setConstraints(okbutton, new GridBagLayoutConstraint(GridBagConstraints.EAST,0,1,
324                                    new Insets(15,8,8,8)));
325                    okbutton.addActionListener(new ActionListener() {
326                            public void actionPerformed(ActionEvent e) {
327                                    pkgsFrame.setVisible(false);
328                                    pkgsFrame.dispose();
329                            }
330                    });
331    
332                    pkgsFrame.getContentPane().add(pkgsPanel);              
333                    pkgsFrame.setResizable(false);
334                    pkgsFrame.pack();
335                    pkgsFrame.setVisible(true);
336    
337            }
338    
339    
340            /**
341             * Draw a Frame with all the Java Properties Info.
342             *
343             */      
344            public static void showJavaPropertiesInfo()
345            {
346                    showJavaPropertiesInfo(new Dimension(650, 800));
347            }
348    
349            /**
350             * Draw a Frame with all the Java Properties Info.
351             * @param d the text Panel Dimension.
352             *
353             */      
354            public static void showJavaPropertiesInfo(Dimension d)
355            {
356                    final JFrame propertiesFrame = new JFrame(Info.ressources.getObject("System_Properties_Info").toString());      
357                    propertiesFrame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);     
358    
359                    JTextArea text = new JTextArea();
360                    text.setFont(new Font("Courier", Font.PLAIN, 12));       
361                    JPanel textPanel = new JPanel();
362                    JPanel propertiesPanel = new JPanel();
363                    GridBagLayout gb = new GridBagLayout();
364                    propertiesPanel.setLayout(gb);
365    
366                    Properties properties = System.getProperties();
367    
368                    JScrollPane textScrolled = new JScrollPane(text);       
369                    textScrolled.setPreferredSize(d);   
370                    textPanel.add(textScrolled);    
371                    propertiesPanel.add(textPanel);
372                    gb.setConstraints(textPanel, new GridBagLayoutConstraint(GridBagConstraints.WEST,0,0,
373                                    new Insets(15,15,15,15)));
374    
375                    String textContent = "";
376                    Vector propertiesTab = new Vector();
377                    for (Enumeration e = properties.propertyNames() ; e.hasMoreElements() ;) 
378                    {       
379                            propertiesTab.addElement(e.nextElement());
380                    }       
381    
382                    Collections.sort(propertiesTab);
383                    String blkString = "                         ";
384                    blkString += blkString;
385                    for(int i=0; i < propertiesTab.size(); i++)
386                    {
387                            if(((String)propertiesTab.get(i)).length() < blkString.length())
388                                    textContent += " " + ((String)propertiesTab.get(i)).trim() 
389                                    + blkString.substring(((String)propertiesTab.get(i)).length()) 
390                                    + "= " + System.getProperty((String)propertiesTab.get(i)) 
391                                    + "\n";         
392                            else textContent += ((String)propertiesTab.get(i)).trim()                        
393                            + "= " + System.getProperty((String)propertiesTab.get(i)) 
394                            + "\n";                             
395                    }       
396    
397                    text.append(textContent);
398                    text.setCaretPosition(0);
399    
400                    JButton okbutton = new JButton(Info.ressources.getObject("OK").toString());
401                    propertiesPanel.add(okbutton);
402                    gb.setConstraints(okbutton, new GridBagLayoutConstraint(GridBagConstraints.EAST,0,1,
403                                    new Insets(15,8,8,8)));
404                    okbutton.addActionListener(new ActionListener() {
405                            public void actionPerformed(ActionEvent e) {
406                                    propertiesFrame.setVisible(false);
407                                    propertiesFrame.dispose();
408                            }
409                    });
410    
411                    propertiesFrame.getContentPane().add(propertiesPanel);          
412                    propertiesFrame.setResizable(false);
413                    propertiesFrame.pack();
414                    propertiesFrame.setVisible(true);
415    
416            }
417    
418    
419    
420    
421    }