KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > util > MiniBrowser


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.util;
15
16 import java.awt.BorderLayout JavaDoc;
17 import java.awt.Dimension JavaDoc;
18 import java.net.URL JavaDoc;
19
20 import javax.swing.JDialog JavaDoc;
21 import javax.swing.JEditorPane JavaDoc;
22 import javax.swing.JScrollPane JavaDoc;
23
24 import org.compiere.plaf.CompierePLAF;
25
26 /**
27  * Mini Browser
28  *
29  * @author Jorg Janke
30  * @version $Id: MiniBrowser.java,v 1.4 2003/09/27 11:13:27 jjanke Exp $
31  */

32 public class MiniBrowser extends JDialog JavaDoc
33 {
34     /**
35      * Default Constructor
36      */

37     public MiniBrowser()
38     {
39         this (null);
40     } // MiniBrowser
41

42     /**
43      * Create MiniBrowser with URL
44      * @param url
45      */

46     public MiniBrowser(String JavaDoc url)
47     {
48         this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
49         try
50         {
51             jbInit();
52         }
53         catch(Exception JavaDoc e)
54         {
55             e.printStackTrace();
56         }
57         setURL (url);
58         CompierePLAF.showCenterScreen(this);
59     } // MiniBrowser
60

61     private JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc();
62     private JEditorPane JavaDoc editorPane = new JEditorPane JavaDoc();
63
64     /**
65      * Static Init
66      * @throws Exception
67      */

68     private void jbInit() throws Exception JavaDoc
69     {
70         scrollPane.setPreferredSize(new Dimension JavaDoc(500, 500));
71         this.getContentPane().add(scrollPane, BorderLayout.CENTER);
72         scrollPane.getViewport().add(editorPane, null);
73     } // jbInit
74

75     /**
76      * Set URL
77      * @param url
78      */

79     private void setURL (String JavaDoc url)
80     {
81         String JavaDoc myURL = url;
82         if (url == null)
83             myURL = "http://www.compiere.org";
84         this.setTitle(myURL);
85
86         // Set URL
87
URL JavaDoc realURL = null;
88         try
89         {
90             realURL = new URL JavaDoc(myURL);
91         }
92         catch (Exception JavaDoc e)
93         {
94             System.err.println("MiniBrowser.setURL (set) - " + e.toString());
95         }
96         if (realURL == null)
97             return;
98
99         // Open
100
try
101         {
102             editorPane.setPage(realURL);
103         }
104         catch (Exception JavaDoc e)
105         {
106             System.err.println("MiniBrowser.setURL (open) - " + e.toString());
107         }
108     } // setURL
109
} // MiniBrowser
110
Popular Tags