Back to index

wims  3.65+svn20090927
HelpOp.java
Go to the documentation of this file.
00001 /*
00002  * @(#)HelpOp.java
00003  *
00004  * $Id: HelpOp.java,v 1.21 2002/08/08 05:15:05 huaz Exp $
00005  *
00006  * Created on October 22, 2000, 2:46 AM
00007  */
00008 package SharpTools;
00009 import java.awt.*;
00010 import java.awt.event.*;
00011 import java.io.*;
00012 import java.net.*;
00013 import javax.swing.*;
00014 import javax.swing.event.*;
00015 import javax.swing.text.*;
00016 import java.util.*;
00017 
00028 public class HelpOp {
00029     public static Properties translation=SharpTools.translation; 
00030     private JEditorPane htmlPane;
00031     private JScrollPane scrollPane;
00032     private JFrame frame;
00033     private Container container;
00034     private WindowListener exitListener;
00035     private HyperlinkListener linkListener;
00036     private URL url;
00037     
00038     
00039     public HelpOp(URL url) {
00040        frame = new JFrame("Help Browser: " + url);
00041        container = frame.getContentPane();
00042        container.setLayout(new BorderLayout());  
00043        try {
00044            htmlPane = new JEditorPane(url);
00045        } catch(IOException e) {
00046            e.printStackTrace();
00047            return;
00048        }
00049        
00050        // We only want to display the file, not edit it.
00051        htmlPane.setEditable(false);
00052        
00053        linkListener = new HyperlinkListener() {
00054               public void hyperlinkUpdate(HyperlinkEvent e) {
00055                   URL newURL;
00056                   Document currentDocument;
00057                   
00058                   if(e.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
00059          return;
00060                   
00061                   if((newURL = e.getURL()) == null)
00062                      return;
00063                   
00064                   currentDocument = htmlPane.getDocument();
00065                   
00066                   try {
00067                      htmlPane.setPage(newURL);
00068                   } catch(IOException ex) {
00069                      htmlPane.setDocument(currentDocument);
00070                   }
00071               }
00072            };
00073        
00074        htmlPane.addHyperlinkListener(linkListener);
00075 
00076        scrollPane = new JScrollPane(htmlPane);
00077        
00078        container.add(scrollPane);
00079        
00080        scrollPane.setPreferredSize(new Dimension(500, 500));
00081        
00082        exitListener = new WindowAdapter() {
00083               public void windowClosing(WindowEvent e) {
00084                   Window window = e.getWindow();
00085                   window.setVisible(false);
00086                   window.dispose();
00087               }
00088            };
00089        
00090        frame.addWindowListener(exitListener);
00091        
00092        frame.pack();
00093        frame.show();
00094     }
00095 
00096     final static String message =
00097        "<html><font size=3 color=black><p><font size=+1 color=blue><b>Sharp Tools Spreadsheet</b></font> Version 1.41</p>"+
00098        "<p><p>a product of the Sharp Tools Software Engineering Team"+
00099         "<p>Copyright (c) 2000-2002"+
00100        "<p><p><font color=green><b>Credits:</b><font></p>"+
00101        "<ul><li>Hua Zhong</li><li>Ricky Chin</li><li>Daniel Goldberg</li>"+
00102        "<li>Daniel Medina</li><li>Andrei Scudder</li></ul></p>"+
00103        "<font color=blue><u><p>http://www.cs.columbia.edu/sharptools/</p>"+
00104        "<p>mailto:sharp@cs.columbia.edu</p></u></font></font>"+
00105        "<p>5/2009 Converted into an Applet for WIMS usage";
00106 
00107     // display the About message box
00108     static void showAboutBox(JFrame frame) {
00109        SharpOptionPane.showMessageDialog
00110            (frame,
00111             message,
00112             translation.getProperty("About_SharpTools"),               
00113             JOptionPane.INFORMATION_MESSAGE,
00114             SharpTools.getImageIcon("images/wims.gif")
00115             );
00116     }
00117 
00118     // return a component that can do function name insertion!
00119     static public JComponent createFunctionListComponent(JFrame frame, JTable table) {
00120 
00121        JPanel comboxPanel = new JPanel();
00122        comboxPanel.setLayout(new BorderLayout());
00123        String[] funcNames = {          
00124            translation.getProperty("Functions") , "ABS", "AVERAGE", "COUNT", "E", "INT",
00125            "LOG", "MAX", "MEANDEV", "MEDIAN", "MIN", "PI", "RANGE", "ROUND",
00126            "SQRT", "SUM", "STDDEV",
00127            "SIN", "COS", "TAN", "ASIN", "ACOS", "ATAN"      
00128        };
00129        
00130        JComboBox funcList = new JComboBox(funcNames);
00131        Dimension combodim = funcList.getSize();
00132        funcList.setPreferredSize
00133            (new Dimension(100, (int)combodim.getHeight()));
00134        comboxPanel.add(funcList, BorderLayout.WEST);
00135 
00136        // if a cell is being edited then insert the function name into the cell
00137        funcList.addActionListener(new FunctionListListener(frame, table));
00138        return comboxPanel;
00139     }
00140        
00141 }
00142 
00150 class FunctionListListener implements ActionListener {
00151 
00152     public static Properties translation=SharpTools.translation; 
00153     JFrame frame;
00154     JTable table;
00155     final ImageIcon helpIcon=new ImageIcon(getClass().getResource("/images/help32.gif"));
00156     //final private ImageIcon helpIcon = SharpTools.getImageIcon("help32.gif");
00157 
00158     FunctionListListener(JFrame frame, JTable table) {
00159        this.frame = frame;
00160        this.table = table;
00161     }
00162     
00163     public void actionPerformed(ActionEvent e) {
00164        JComboBox cb = (JComboBox)e.getSource();
00165        String funcName = (String)cb.getSelectedItem();
00166               
00167        try {
00168            if (table.isEditing()) {
00169               int row = table.getEditingRow();
00170               int col = table.getEditingRow();
00171               // get the editor
00172               JTextField text = ((SharpCellEditor)table.getCellEditor(row, col)).getTextField();
00173 
00174               if (!funcName.equals(translation.getProperty("Functions"))) {
00175                   // insert our function name
00176                   text.replaceSelection(funcName+"()");
00177                   // set caret between parentheses if the user needs to input parameters
00178                   Function fh = Formula.getFuncHandler(funcName);
00179                   if (fh != null && fh.requireParams())
00180                      text.setCaretPosition(text.getCaretPosition()-1);
00181               }
00182               else
00183                   showGeneralFunctionHelp();
00184               text.requestFocus();
00185            }         
00186            else {
00187               // pop up help message box!
00188               Function fh = Formula.getFuncHandler(funcName);
00189               if (fh != null) {
00190                   
00191                   String message = "<html><font size=2 color=black><b>"+
00192                      fh.getUsage()+"</b><p><p>"+fh.getDescription()+"<p></font>";
00193 
00194                   SharpOptionPane.showMessageDialog(frame,
00195                                                 message,
00196                                                 translation.getProperty("Function"),
00197                                                 JOptionPane.INFORMATION_MESSAGE,
00198                                                 helpIcon);
00199               }
00200               else
00201                   showGeneralFunctionHelp();
00202               
00203               table.requestFocus();
00204            }
00205        }
00206        catch (Exception exception) {};
00207        // reset the selection and focus
00208        cb.setSelectedIndex(0);            
00209     }
00210 
00211     private void showGeneralFunctionHelp() {
00212        String message = translation.getProperty("helpmessage");
00213 /*     "<html><font size=2 color=black><b><font size=3>Functions</font></b><p>"+
00214            "<p>Functions are predefined formulas that perform calculations by"+
00215            "<p>using specific values, called arguments, in a particular order,"+"<p>or structure.<p>"+
00216            "<p><b>Arguments</b> Arguments can be numbers or cell references. A cell"+
00217            "<p>reference can be a single cell or a range of cells.  A single cell can"+
00218            "<p>use relative addressing (A1) or absolute addressing ($B$5).  A range"+
00219            "<p>of cell is specified by a pair of diagonal cells (A1:C5, $A$1:$C$5)."+
00220            "<p>Different functions may have different requirements on the number"+
00221            "<p>or type of parameters.<p>"+
00222            "<p><b>Structure</b> The structure of a function begins with the function"+
00223            "<p>name, followed by an opening parenthesis, the arguments for"+
00224            "<p>the function separated by commas, and a closing parenthesis."+
00225            "<p>If the function starts a formula, type an equal sign (=) before"+
00226            "<p>the function name.  As you are editing a formula that contains"+
00227            "<p>a function, you can click on a function in this list to insert the"+
00228            "<p>function name into the cell.<p>"+
00229            "<p><b>Examples:</b><p>"+
00230            "<p>=SUM(A10,B5:B10,50,37)"+
00231            "<p>=AVERAGE($B$5:$B$10)/10</font>";
00232 */
00233        SharpOptionPane.showMessageDialog(frame,
00234                                      message,
00235                                      "Function",
00236                                      JOptionPane.INFORMATION_MESSAGE,
00237                                      helpIcon);
00238 
00239     }
00240 }
00241 
00242 
00243 
00244 
00245 
00246 
00247