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