001    /*
002     * Copyright (C) 2009 Andre Schild (a.schild@aarboard.ch)
003     *
004     * Version: MPL 1.1/GPL 2.0/LGPL 2.1
005     *
006     * The contents of this file are subject to the Mozilla Public License Version
007     * 1.1 (the "License"); you may not use this file except in compliance with the
008     * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
009     *
010     * Software distributed under the License is distributed on an "AS IS" basis,
011     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
012     * the specific language governing rights and limitations under the License.
013     *
014     * Alternatively, the contents of this file may be used under the terms of
015     * either the GNU General Public License Version 2 or later (the "GPL"), or the
016     * GNU Lesser General Public License Version 2.1 or later (the "LGPL"), in which
017     * case the provisions of the GPL or the LGPL are applicable instead of those
018     * above. If you wish to allow use of your version of this file only under the
019     * terms of either the GPL or the LGPL, and not to allow others to use your
020     * version of this file under the terms of the MPL, indicate your decision by
021     * deleting the provisions above and replace them with the notice and other
022     * provisions required by the GPL or the LGPL. If you do not delete the
023     * provisions above, a recipient may use your version of this file under the
024     * terms of any one of the MPL, the GPL or the LGPL.
025     *
026     * @author Andre Schild Aarboard 2009-06-17
027     * @version $Id:  $
028     */
029    package echopoint;
030    
031    import java.util.Properties;
032    import nextapp.echo.app.Component;
033    import nextapp.echo.app.Extent;
034    
035    public class Fckeditor extends Component
036    {
037    
038        public static final String PROPERTY_FCKEDITOR_URL = "fckeditorURL";
039        public static final String PROPERTY_FCKEDITOR_CONFIG_URL = "fckeditorConfigURL";
040        public static final String PROPERTY_FCKEDITOR_CSS_URL = "fckeditorCssURL";
041        public static final String PROPERTY_WIDTH = "width";
042        public static final String PROPERTY_HEIGHT = "height";
043        public static final String PROPERTY_CONFIG = "config";
044        public static final String PROPERTY_TOOLBAR = "toolbar";
045        public static final String PROPERTY_DEBUG = "debug";
046        public static final String PROPERTY_TOOLBAR_COLLAPSED = "toolbarCollapsed";
047        public static final String PROPERTY_AUTOCOLLAPSE_TOOLBAR = "toolbarAutocollapse";
048        public static final String TEXT_CHANGED_PROPERTY = "text";
049    
050        public static final String Version = "0.5";
051        
052        private String text;    // Holding the editor content
053    
054        /**
055         * Works (at least) with Fckeditor versions 2.6.4 and 2.6.5
056         */
057        public Fckeditor()
058        {
059            super();
060        }
061    
062        public void setFckeditorURL(String newValue)
063        {
064            set(PROPERTY_FCKEDITOR_URL, newValue);
065        }
066    
067    
068        public void setFckeditorConfigURL(String newValue)
069        {
070            set(PROPERTY_FCKEDITOR_CONFIG_URL, newValue);
071        }
072    
073        public void setFckeditorCssURL(String newValue)
074        {
075            set(PROPERTY_FCKEDITOR_CSS_URL, newValue);
076        }
077    
078        /**
079         * Set the width of the editor
080         *
081         * @param width
082         */
083        public void setWidth(Extent width)
084        {
085            set(PROPERTY_WIDTH, width);
086        }
087    
088        /**
089         * Set the height of the editor
090         * 
091         * @param height
092         */
093        public void setHeight(Extent height)
094        {
095            set(PROPERTY_HEIGHT, height);
096        }
097    
098        /**
099         * Set content of editor
100         *
101         * @param newValue
102         */
103        public void setText(String newValue)
104        {
105            String oldValue= this.text;
106            this.text = newValue;
107            firePropertyChange(TEXT_CHANGED_PROPERTY, oldValue, newValue);
108        }
109    
110        /**
111         * Get content of editor
112         * 
113         * @return
114         */
115        public String getText()
116        {
117            return this.text;
118        }
119    
120        /**
121         * This is the method which received updates from the client and stores it on the local object
122         * 
123         * @see nextapp.echo.app.Component#processInput(java.lang.String, java.lang.Object)
124         */
125        @Override
126        public void processInput(String inputName, Object inputValue)
127        {
128            if (TEXT_CHANGED_PROPERTY.equals(inputName))
129            {
130                if (inputValue != null)
131                {
132                    this.text = inputValue.toString();
133                }
134                else
135                {
136                    this.text= null;
137                }
138            }
139        }
140    
141        /**
142         * Set editor configuration options
143         * 
144         * @param newValue
145         */
146        public void setConfig(Properties newValue)
147        {
148            set(PROPERTY_CONFIG, newValue);
149        }
150    
151        /**
152         * Use the toolbar with this name
153         * 
154         * @param newValue
155         */
156        public void setToolbar(String newValue)
157        {
158            set(PROPERTY_TOOLBAR, newValue);
159        }
160    
161        /**
162         * When turned on we write many log messages to the client side log window.
163         * To see the window just add ?debug to the url
164         * 
165         * @param newValue
166         */
167        public void setDebug(boolean newValue)
168        {
169            set(PROPERTY_DEBUG, newValue);
170        }
171    
172        /**
173         * Should the toolbar be shown in collapsed mode or not
174         * 
175         * @param newValue True = Toolbar collapsed
176         * 
177         */
178        public void setToolbarCollapsed(boolean newValue)
179        {
180            set(PROPERTY_TOOLBAR_COLLAPSED, newValue);
181        }
182    
183        /**
184         * When set to true the toolbar is collapsed when the editor does NOT have
185         * the focus.
186         * When the editor receives the focus the toolbar is expanded (and on loss
187         * of focus collapsed again)
188         *
189         * @param newValue 
190         */
191        public void setToolbarAutocollapse(boolean newValue)
192        {
193            set(PROPERTY_AUTOCOLLAPSE_TOOLBAR, newValue);
194        }
195    }