001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.plugins.commonplugin.help.actions; 005 006 import graphlab.plugins.commonplugin.help.Utils; 007 import graphlab.plugins.commonplugin.reporter.Browser; 008 009 import javax.swing.*; 010 import java.awt.*; 011 import java.awt.event.MouseAdapter; 012 import java.awt.event.MouseEvent; 013 import java.net.URL; 014 015 public class HelpWindow extends JFrame { 016 017 /** 018 * 019 */ 020 private static final long serialVersionUID = -6779084226685712613L; 021 022 public HelpWindow() throws HeadlessException { 023 super(); 024 initComponents(); 025 } 026 027 private void initComponents() {// GEN-BEGIN:initComponents 028 java.awt.GridBagConstraints gridBagConstraints; 029 030 jList1 = new javax.swing.JList(); 031 jPanel1 = new javax.swing.JPanel(); 032 jButton1 = new javax.swing.JButton(); 033 jButton2 = new javax.swing.JButton(); 034 commentLabel = new JLabel(""); 035 036 getContentPane().setLayout(new java.awt.GridBagLayout()); 037 038 jList1.setToolTipText("Select a plugin to show the help of it:"); 039 040 DefaultListModel list = new DefaultListModel(); 041 for (String pluginName : Utils.pluginHelps.keySet()) { 042 list.addElement(pluginName); 043 } 044 045 jList1.setModel(list); 046 jList1.addMouseListener(new MouseAdapter() { 047 public void mouseClicked(MouseEvent e) { 048 if (e.getClickCount() == 2) { 049 showSelectedPluginHelp(); 050 } 051 } 052 }); 053 054 setPreferredSize(new Dimension(250, 320)); 055 056 gridBagConstraints = new java.awt.GridBagConstraints(); 057 gridBagConstraints.gridx = 0; 058 gridBagConstraints.gridy = 0; 059 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 060 gridBagConstraints.weightx = 1.0; 061 gridBagConstraints.weighty = 0.85; 062 getContentPane().add(jList1, gridBagConstraints); 063 064 jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); 065 066 jPanel1.setPreferredSize(new java.awt.Dimension(191, 5)); 067 068 jPanel1.add(commentLabel); 069 070 jButton1.setText("Show"); 071 jButton1.addActionListener(new java.awt.event.ActionListener() { 072 public void actionPerformed(java.awt.event.ActionEvent evt) { 073 jButton1ActionPerformed(evt); 074 } 075 }); 076 077 jPanel1.add(jButton1); 078 079 jButton2.setText("Close"); 080 jButton2.addActionListener(new java.awt.event.ActionListener() { 081 public void actionPerformed(java.awt.event.ActionEvent evt) { 082 jButton2ActionPerformed(evt); 083 } 084 }); 085 086 jPanel1.add(jButton2); 087 088 gridBagConstraints = new java.awt.GridBagConstraints(); 089 gridBagConstraints.gridx = 0; 090 gridBagConstraints.gridy = 1; 091 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 092 gridBagConstraints.weightx = 1.0; 093 gridBagConstraints.weighty = 0.15; 094 getContentPane().add(jPanel1, gridBagConstraints); 095 096 pack(); 097 } 098 099 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton2ActionPerformed 100 setVisible(false); 101 } 102 103 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_jButton1ActionPerformed 104 showSelectedPluginHelp(); 105 } 106 107 private void showSelectedPluginHelp() { 108 for (Object obj : jList1.getSelectedValues()) { 109 String pluginName = obj.toString(); 110 URL url = Utils.pluginHelps.get(pluginName); 111 System.out.println(url); 112 if (url != null) { 113 // Browser b = new Browser(); 114 // b.pack(); 115 // b.setVisible(true); 116 Browser.browse(url); 117 } 118 119 } 120 } 121 122 private JLabel commentLabel; 123 124 private javax.swing.JButton jButton1; 125 126 private javax.swing.JButton jButton2; 127 128 public javax.swing.JList jList1; 129 130 private javax.swing.JPanel jPanel1; 131 132 }