KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > Help


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps;
15
16 import java.awt.*;
17 import java.awt.event.*;
18 import javax.swing.*;
19 import java.io.*;
20 import java.net.*;
21
22 import org.compiere.model.*;
23 import org.compiere.grid.*;
24 import org.compiere.util.*;
25 import org.compiere.plaf.*;
26
27 /**
28  * Help and HTML Window
29  *
30  * @author Jorg Janke
31  * @version $Id: Help.java,v 1.9 2003/08/10 05:31:15 jjanke Exp $
32  */

33 public class Help extends JDialog implements ActionListener
34 {
35     /**
36      * Help System for Window Help
37      *
38      * @param frame Parent
39      * @param title Title
40      * @param mWindow Window Model
41      */

42     public Help (Frame frame, String JavaDoc title, MWindow mWindow)
43     {
44         super(frame, title, false);
45         try
46         {
47             jbInit();
48             loadInfo(mWindow);
49         }
50         catch(Exception JavaDoc ex)
51         {
52             Log.error("Help", ex);
53         }
54         AEnv.positionCenterWindow(frame, this);
55     } // Help
56

57     /**
58      * Help System
59      *
60      * @param frame Parent
61      * @param title Window
62      * @param url URL to display
63      */

64     public Help (Frame frame, String JavaDoc title, URL url)
65     {
66         super(frame, title, false);
67         try
68         {
69             jbInit();
70             info.setPage(url);
71         }
72         catch(Exception JavaDoc ex)
73         {
74             Log.error("Help", ex);
75         }
76         AEnv.positionCenterWindow(frame, this);
77     } // Help
78

79     /**
80      * Help System
81      *
82      * @param frame Parent
83      * @param title Window
84      * @param helpHtml Helptext
85      */

86     public Help (Frame frame, String JavaDoc title, String JavaDoc helpHtml)
87     {
88         super(frame, title, false);
89         try
90         {
91             jbInit();
92             info.setContentType("text/html");
93             info.setEditable(false);
94             info.setBackground(CompierePLAF.getFieldBackground_Inactive());
95             info.setText(helpHtml);
96         }
97         catch(Exception JavaDoc ex)
98         {
99             Log.error("Help", ex);
100         }
101         AEnv.positionCenterWindow(frame, this);
102     } // Help
103

104
105     private JPanel mainPanel = new JPanel();
106     private BorderLayout mainLayout = new BorderLayout();
107     private OnlineHelp info = new OnlineHelp();
108     private JScrollPane infoPane = new JScrollPane();
109     private ConfirmPanel confirmPanel = new ConfirmPanel();
110
111     /**
112      * Static Init
113      *
114      * @throws Exception
115      */

116     void jbInit() throws Exception JavaDoc
117     {
118         mainPanel.setLayout(mainLayout);
119         mainLayout.setHgap(2);
120         mainLayout.setVgap(2);
121         infoPane.setBorder(BorderFactory.createLoweredBevelBorder());
122         infoPane.setPreferredSize(new Dimension(500, 400));
123         getContentPane().add(mainPanel);
124         mainPanel.add(infoPane, BorderLayout.CENTER);
125         mainPanel.add(confirmPanel, BorderLayout.SOUTH);
126         infoPane.getViewport().add(info, null);
127         confirmPanel.addActionListener(this);
128     } // jbInit
129

130     /*************************************************************************/
131
132     /**
133      * Load Info - Windows Help
134      * @param mWindow window model
135      */

136     private void loadInfo(MWindow mWindow)
137     {
138         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
139         buffer.append("<HTML>");
140         buffer.append("<HEADER><TITLE>" + mWindow.getName() + "</TITLE></HEADER>");
141         buffer.append("<BODY>");
142         buffer.append("&copy;&nbsp;Compiere &nbsp; ");
143         buffer.append("<A HREF=\"http://www.compiere.org/help/\">Online Help</A>");
144         // Window
145
buffer.append("<H1>" + Msg.getMsg(Env.getCtx(), "Window") + ": " + mWindow.getName() + "</H1>");
146         if (mWindow.getDescription().length() != 0)
147             buffer.append("<P><I>" + mWindow.getDescription() + "</I></P>");
148         if (mWindow.getHelp().length() != 0)
149             buffer.append("<P>" + mWindow.getHelp() + "</P>");
150
151         // Links to Tabs
152
int size = mWindow.getTabCount();
153         for (int i = 0; i < size; i++)
154         {
155             MTab tab = mWindow.getTab(i);
156             buffer.append("<A HREF=\"#Tab").append(i).append("\">").append(tab.getName()).append("</A> - ");
157         }
158
159         // For all Tabs
160
for (int i = 0; i < size; i++)
161         {
162             MTab tab = mWindow.getTab(i);
163             buffer.append("<HR><H2><A NAME=\"Tab").append(i).append("\"><FONT COLOR=green>")
164                 .append(Msg.getMsg(Env.getCtx(), "Tab")).append(": ").append(tab.getName()).append("</FONT></A></H2>");
165             if (tab.getDescription().length() != 0)
166                 buffer.append("<P><I>").append(tab.getDescription()).append("</I></P>");
167             if (tab.getHelp().length() != 0)
168                 buffer.append("<P>").append(tab.getHelp()).append("</P>");
169
170             // Links to Fields
171
for (int j = 0; j < tab.getFieldCount(); j++)
172             {
173                 MField field = tab.getField(j);
174                 String JavaDoc hdr = field.getHeader();
175                 if (hdr != null && hdr.length() > 0)
176                     buffer.append("<A HREF=\"#Field").append(i).append(j).append("\">")
177                         .append(hdr).append("</A> - ");
178             }
179
180             // For all Fields
181
for (int j = 0; j < tab.getFieldCount(); j++)
182             {
183                 MField field = tab.getField(j);
184                 String JavaDoc hdr = field.getHeader();
185                 if (hdr != null && hdr.length() > 0)
186                 {
187                     buffer.append ("<H3><A NAME=\"Field").append (i).append (j)
188                         .append ("\"><FONT COLOR=\"#FF0000\">")
189                         .append (Msg.getMsg (Env.getCtx (), "Field"))
190                         .append (": ").append (hdr)
191                         .append ("</FONT></A></H3>");
192                     if (field.getDescription ().length () != 0)
193                         buffer.append ("<P><I>").append (field.getDescription ())
194                             .append ("</I></P>");
195                     if (field.getHelp ().length () != 0)
196                         buffer.append ("<P>").append (field.getHelp ())
197                             .append ("</P>");
198                 }
199             } // for all Fields
200

201         } // for all Tabs
202

203         // Finish
204
buffer.append("</BODY>");
205         buffer.append("</HTML>");
206
207         // Set Info
208
// System.out.println(buffer);
209
info.setText(buffer.toString());
210     } // loadInfo
211

212     /*************************************************************************/
213
214     /**
215      * Action Listener
216      * @param e event
217      */

218     public void actionPerformed(ActionEvent e)
219     {
220         if (e.getActionCommand().equals(ConfirmPanel.A_OK))
221             dispose();
222     } // actionPerformed
223

224 } // Help
225

226
Popular Tags