KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > plugins > codeeditor > InfoGlueCodeEditorApplet


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  */

23  
24 package org.infoglue.cms.plugins.codeeditor;
25
26 import java.awt.Color JavaDoc;
27 import java.awt.Dimension JavaDoc;
28
29 import javax.swing.BorderFactory JavaDoc;
30 import javax.swing.JApplet JavaDoc;
31 import javax.swing.JScrollPane JavaDoc;
32
33 import netscape.javascript.JSObject;
34
35
36 public class InfoGlueCodeEditorApplet extends JApplet JavaDoc implements InfoGlueCodeEditorController
37 {
38     private InfoGlueTextArea textArea = null;
39     
40     private String JavaDoc attributeId = "";
41     private String JavaDoc deliverySettingsUrl = "";
42     
43
44     public void init()
45     {
46         try
47         {
48             attributeId = this.getParameter("attributeId");
49             deliverySettingsUrl = this.getParameter("deliverySettingsUrl");
50             System.out.println("attributeId:" + attributeId);
51             System.out.println("deliverySettingsUrl:" + deliverySettingsUrl);
52         }
53         catch(Exception JavaDoc e)
54         {
55             e.printStackTrace();
56         }
57                 
58         this.setSize(500, 400);
59         this.getContentPane().setBackground(Color.WHITE);
60         
61         textArea = new InfoGlueTextArea(this);
62         textArea.setSize(700, 600);
63         textArea.setBounds(0, 0, 700, 600);
64         
65         JScrollPane JavaDoc areaScrollPane = new JScrollPane JavaDoc(textArea);
66         areaScrollPane.setPreferredSize(new Dimension JavaDoc(500, 400));
67         areaScrollPane.setBorder(BorderFactory.createLineBorder(Color.black));
68         
69         textArea.setScrollPane(areaScrollPane);
70         
71         this.getContentPane().add(areaScrollPane);
72         
73         Object JavaDoc[] args = {this.attributeId};
74         String JavaDoc text = (String JavaDoc)callJavascript("getValue", args);
75         this.setText(text);
76
77         callJavascript("setAppletIsActive", args);
78     }
79     
80     /**
81      * This method is used by external javascripts to set the initial value
82      */

83     
84     public void setText(String JavaDoc text)
85     {
86         //System.out.println("Trying to set the initial text through javascript:" + text);
87
this.textArea.setText(text);
88     }
89     
90     /**
91      * This method is used by external javascripts to get the text
92      */

93     
94     public String JavaDoc getText()
95     {
96         return this.textArea.getText();
97     }
98     
99     
100     /**
101      * This method returns a string with the url to the delivery-engine settings service.
102      */

103     
104     public String JavaDoc getDeliverySettingsUrl()
105     {
106         return this.deliverySettingsUrl;
107     }
108     
109     /**
110      * This method calls external javascript to set value and submit the form
111      */

112     
113     public void executeSave(String JavaDoc text)
114     {
115         //System.out.println("Going to tell the world that the user wants to save..." + text);
116
try
117         {
118             JSObject win = JSObject.getWindow(this);
119             Object JavaDoc[] args = {this.attributeId, text};
120             String JavaDoc functionName = "saveValue";
121             //System.out.println("Calling function " + functionName);
122
win.call(functionName, args);
123         }
124         catch(Exception JavaDoc e)
125         {
126             System.out.println("An error occurred while we tried to call a javascript: " + e);
127         }
128     }
129
130     /**
131      * This method calls external javascript to interact with the webpage
132      */

133     
134     public Object JavaDoc callJavascript(String JavaDoc functionName, Object JavaDoc[] args)
135     {
136         Object JavaDoc returnValue = null;
137         try
138         {
139             JSObject win = JSObject.getWindow(this);
140             //System.out.println("Calling function " + functionName);
141
returnValue = win.call(functionName, args);
142         }
143         catch(Exception JavaDoc e)
144         {
145             System.out.println("An error occurred while we tried to call a javascript: " + e);
146             e.printStackTrace();
147         }
148         return returnValue;
149     }
150
151 }
Popular Tags