001    /*
002     * $Id: AboutFrame.java,v 1.7 2012/02/19 17:35:51 davep Exp $
003     *
004     * This file is part of McIDAS-V
005     *
006     * Copyright 2007-2012
007     * Space Science and Engineering Center (SSEC)
008     * University of Wisconsin - Madison
009     * 1225 W. Dayton Street, Madison, WI 53706, USA
010     * https://www.ssec.wisc.edu/mcidas
011     * 
012     * All Rights Reserved
013     * 
014     * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015     * some McIDAS-V source code is based on IDV and VisAD source code.  
016     * 
017     * McIDAS-V is free software; you can redistribute it and/or modify
018     * it under the terms of the GNU Lesser Public License as published by
019     * the Free Software Foundation; either version 3 of the License, or
020     * (at your option) any later version.
021     * 
022     * McIDAS-V is distributed in the hope that it will be useful,
023     * but WITHOUT ANY WARRANTY; without even the implied warranty of
024     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
025     * GNU Lesser Public License for more details.
026     * 
027     * You should have received a copy of the GNU Lesser Public License
028     * along with this program.  If not, see http://www.gnu.org/licenses.
029     */
030    
031    package edu.wisc.ssec.mcidasv.ui;
032    
033    import java.awt.Color;
034    import java.awt.Cursor;
035    import java.awt.event.MouseAdapter;
036    import java.awt.event.MouseEvent;
037    import java.net.MalformedURLException;
038    import java.net.URL;
039    
040    import ucar.unidata.util.GuiUtils;
041    
042    import edu.wisc.ssec.mcidasv.Constants;
043    import edu.wisc.ssec.mcidasv.McIDASV;
044    import edu.wisc.ssec.mcidasv.StateManager;
045    import edu.wisc.ssec.mcidasv.util.SystemState;
046    
047    public class AboutFrame extends javax.swing.JFrame {
048    
049        private final McIDASV mcv;
050    
051        /** Creates new form AboutFrame */
052        public AboutFrame(final McIDASV mcv) {
053            this.mcv = mcv;
054            initComponents();
055        }
056    
057        private javax.swing.JPanel buildAboutMcv() {
058            StateManager stateManager = (StateManager)mcv.getStateManager();
059    
060            javax.swing.JEditorPane editor = new javax.swing.JEditorPane();
061            editor.setEditable(false);
062            editor.setContentType("text/html");
063            String html = stateManager.getMcIdasVersionAbout();
064            editor.setText(html);
065            editor.setBackground(new javax.swing.JPanel().getBackground());
066            editor.addHyperlinkListener(mcv);
067    
068            final javax.swing.JLabel iconLbl = new javax.swing.JLabel(
069                GuiUtils.getImageIcon(mcv.getProperty(Constants.PROP_SPLASHICON, ""))
070            );
071            iconLbl.setToolTipText("McIDAS-V homepage");
072            iconLbl.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
073            iconLbl.addMouseListener(new MouseAdapter() {
074                public void mouseClicked(MouseEvent evt) {
075                    javax.swing.event.HyperlinkEvent link = null;
076                    try {
077                        link = new javax.swing.event.HyperlinkEvent(
078                            iconLbl,
079                            javax.swing.event.HyperlinkEvent.EventType.ACTIVATED,
080                            new URL(mcv.getProperty(Constants.PROP_HOMEPAGE, ""))
081                        );
082                    } catch (MalformedURLException e) {}
083                    mcv.hyperlinkUpdate(link);
084                }
085            });
086            javax.swing.JPanel contents = GuiUtils.topCenter(
087                GuiUtils.inset(iconLbl, 5),
088                GuiUtils.inset(editor, 5)
089            );
090            contents.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED,
091                    Color.gray, Color.gray));
092            return contents;
093        }
094    
095        private String getSystemInformation() {
096    //        return new SystemState(mcv).getStateAsString(true);
097            return SystemState.getStateAsString(mcv, true);
098        }
099    
100        /** This method is called from within the constructor to
101         * initialize the form.
102         * WARNING: Do NOT modify this code. The content of this method is
103         * always regenerated by the Form Editor.
104         */
105        @SuppressWarnings("unchecked")
106        // <editor-fold defaultstate="collapsed" desc="Generated Code">
107        private void initComponents() {
108    
109            tabbedPanel = new javax.swing.JTabbedPane();
110            mcvTab = new javax.swing.JPanel();
111            mcvPanel = buildAboutMcv();
112            sysTab = new javax.swing.JPanel();
113            sysScrollPane = new javax.swing.JScrollPane();
114            sysTextArea = new javax.swing.JTextArea();
115    
116            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
117            setTitle("About McIDAS-V");
118    
119            javax.swing.GroupLayout mcvTabLayout = new javax.swing.GroupLayout(mcvTab);
120            mcvTab.setLayout(mcvTabLayout);
121            mcvTabLayout.setHorizontalGroup(
122                mcvTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
123    //            .addComponent(mcvPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
124                .addComponent(mcvPanel)
125            );
126            mcvTabLayout.setVerticalGroup(
127                mcvTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
128    //            .addComponent(mcvPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
129                .addComponent(mcvPanel)
130            );
131    
132            tabbedPanel.addTab("McIDAS-V", mcvTab);
133            sysTextArea.setText(getSystemInformation());
134            sysTextArea.setEditable(false);
135            sysTextArea.setFont(new java.awt.Font(java.awt.Font.MONOSPACED, 0, 12)); // NOI18N
136            sysTextArea.setCaretPosition(0);
137            sysTextArea.setLineWrap(false);
138            sysScrollPane.setViewportView(sysTextArea);
139    
140            javax.swing.GroupLayout sysTabLayout = new javax.swing.GroupLayout(sysTab);
141            sysTab.setLayout(sysTabLayout);
142            sysTabLayout.setHorizontalGroup(
143                sysTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
144                .addGroup(sysTabLayout.createSequentialGroup()
145    //                .addContainerGap()
146    //                .addComponent(sysScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE)
147    //                .addContainerGap())
148                    .addComponent(sysScrollPane))
149            );
150            sysTabLayout.setVerticalGroup(
151                sysTabLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
152                .addGroup(sysTabLayout.createSequentialGroup()
153    //                .addComponent(sysScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 307, Short.MAX_VALUE)
154    //                .addContainerGap())
155                    .addComponent(sysScrollPane))
156            );
157    
158            tabbedPanel.addTab("System Information", sysTab);
159    
160            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
161            getContentPane().setLayout(layout);
162            layout.setHorizontalGroup(
163                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164    //            .addComponent(tabbedPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE)
165                .addComponent(tabbedPanel)
166            );
167            layout.setVerticalGroup(
168                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
169    //            .addComponent(tabbedPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 359, Short.MAX_VALUE)
170                .addComponent(tabbedPanel)
171            );
172    
173            pack();
174            setSize(450, 375);
175            setLocationRelativeTo(mcv.getIdvUIManager().getFrame());
176        }// </editor-fold>
177    
178        // Variables declaration - do not modify
179        private javax.swing.JPanel mcvPanel;
180        private javax.swing.JPanel mcvTab;
181        private javax.swing.JScrollPane sysScrollPane;
182        private javax.swing.JPanel sysTab;
183        private javax.swing.JTextArea sysTextArea;
184        private javax.swing.JTabbedPane tabbedPanel;
185        // End of variables declaration
186    
187    }