This project has retired. For details please refer to its Attic page.
InfoDialog xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.workbench;
20  
21  import java.awt.Dimension;
22  import java.awt.FlowLayout;
23  import java.awt.Font;
24  import java.awt.Frame;
25  import java.io.BufferedReader;
26  import java.io.InputStream;
27  import java.io.InputStreamReader;
28  import java.util.Properties;
29  import java.util.TreeSet;
30  
31  import javax.swing.BorderFactory;
32  import javax.swing.BoxLayout;
33  import javax.swing.JDialog;
34  import javax.swing.JFrame;
35  import javax.swing.JLabel;
36  import javax.swing.JPanel;
37  import javax.swing.JScrollPane;
38  import javax.swing.JTextArea;
39  import javax.swing.UIManager;
40  
41  public class InfoDialog extends JDialog {
42  
43      private static final long serialVersionUID = 1L;
44  
45      public InfoDialog(Frame owner) {
46          super(owner, "Info", true);
47          createGUI();
48      }
49  
50      private void createGUI() {
51          setPreferredSize(new Dimension(800, 500));
52          setMinimumSize(new Dimension(600, 400));
53  
54          setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS));
55  
56          JPanel topPanel = new JPanel(new FlowLayout());
57  
58          JLabel cmisLogo = new JLabel(ClientHelper.getIcon("icon.png"));
59          topPanel.add(cmisLogo);
60  
61          Font labelFont = UIManager.getFont("Label.font");
62          Font titleFont = labelFont.deriveFont(Font.BOLD, labelFont.getSize2D() * 2f);
63  
64          JLabel titleLabel = new JLabel("CMIS Workbench");
65          titleLabel.setFont(titleFont);
66          topPanel.add(titleLabel);
67  
68          add(topPanel);
69  
70          StringBuilder readme = new StringBuilder();
71  
72          readme.append(loadText("/META-INF/README", "CMIS Workbench"));
73          readme.append("\n---------------------------------------------------------\n");
74  
75          readme.append("\nCurrent System Properties:\n\n");
76  
77          Properties sysProps = System.getProperties();
78          for (Object key : new TreeSet<Object>(sysProps.keySet())) {
79              readme.append(key).append(" = ").append(sysProps.get(key)).append("\n");
80          }
81  
82          readme.append("\n---------------------------------------------------------\n");
83          readme.append(loadText("/META-INF/build-timestamp.txt", ""));
84  
85          JTextArea ta = new JTextArea(readme.toString());
86          ta.setEditable(false);
87          ta.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
88          JScrollPane readmePane = new JScrollPane(ta);
89          readmePane.setBorder(BorderFactory.createEmptyBorder(0, 5, 5, 5));
90  
91          add(readmePane);
92  
93          ClientHelper.installEscapeBinding(this, getRootPane(), false);
94  
95          setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
96          pack();
97          setLocationRelativeTo(null);
98      }
99  
100     public void showDialog() {
101         setVisible(true);
102     }
103 
104     public void hideDialog() {
105         setVisible(false);
106     }
107 
108     private String loadText(String file, String defaultText) {
109         StringBuilder result = new StringBuilder();
110 
111         InputStream stream = getClass().getResourceAsStream(file);
112         if (stream != null) {
113             try {
114                 BufferedReader br = new BufferedReader(new InputStreamReader(stream));
115 
116                 String s = null;
117                 while ((s = br.readLine()) != null) {
118                     result.append(s);
119                     result.append('\n');
120                 }
121 
122                 br.close();
123             } catch (Exception e) {
124             }
125         } else {
126             result.append(defaultText);
127         }
128 
129         return result.toString();
130     }
131 }