KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > specifier > components > DjHtmlArea


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.specifier.components;
31
32 import java.awt.BorderLayout JavaDoc;
33 import java.awt.Frame JavaDoc;
34 import java.awt.event.ActionEvent JavaDoc;
35 import java.awt.event.FocusEvent JavaDoc;
36 import java.awt.event.FocusListener JavaDoc;
37 import java.awt.event.KeyEvent JavaDoc;
38
39 import javax.swing.JComponent JavaDoc;
40 import javax.swing.JPanel JavaDoc;
41
42 import com.genimen.djeneric.repository.exceptions.DjenericException;
43 import com.genimen.djeneric.tools.specifier.interfaces.ObjectViewer;
44 import com.genimen.djeneric.ui.Util;
45 import com.genimen.djeneric.util.DjLogger;
46 import com.hexidec.ekit.EkitCore;
47
48 public class DjHtmlArea extends JPanel JavaDoc implements DjBindable, FocusListener JavaDoc
49 {
50   private static final long serialVersionUID = 1L;
51   private BindingMediator _mediator;
52   private EkitCore _ekitCore;
53
54   public DjHtmlArea(ObjectViewer viewer, String JavaDoc propertyName) throws DjenericException
55   {
56     super();
57     setLayout(new BorderLayout JavaDoc());
58     _ekitCore = new EkitCore();
59     add(_ekitCore.getToolBar(true), BorderLayout.NORTH);
60     add(_ekitCore, BorderLayout.CENTER);
61     _ekitCore.getTextPane().addFocusListener(this);
62     _mediator = new BindingMediator(this, viewer, propertyName);
63
64     // At least support the keyboard shortcuts.
65
// Later try to convert the menu into a popup menu
66
_ekitCore.getTextPane().add(_ekitCore.getMenuBar());
67
68     _ekitCore.getTextPane().addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
69     {
70       public void keyPressed(KeyEvent JavaDoc e)
71       {
72         if (e.getKeyCode() == KeyEvent.VK_ENTER && (e.getModifiers() & KeyEvent.CTRL_MASK) != 0)
73         {
74           _ekitCore.actionPerformed(new ActionEvent JavaDoc(this, 0, "insertbreak"));
75         }
76       }
77     });
78
79   }
80
81   public void clear()
82   {
83     _ekitCore.setDocumentText("");
84   }
85
86   public boolean isComponentWritable()
87   {
88     return _mediator.isComponentWritable();
89   }
90
91   public void setToolTipText(String JavaDoc text)
92   {
93     _ekitCore.getTextPane().setToolTipText(text);
94   }
95
96   public void apply() throws DjenericException
97   {
98     _mediator.setValue(_ekitCore.getDocumentText());
99   }
100
101   Frame JavaDoc _frame = null;
102
103   public void focusGained(FocusEvent JavaDoc e)
104   {
105     _mediator.getViewer().focusReceived(this);
106
107     if (_frame == null)
108     {
109       _frame = Util.findFrame(this);
110       if (_frame != null) _ekitCore.setFrame(_frame);
111     }
112   }
113
114   public void focusLost(FocusEvent JavaDoc e)
115   {
116     try
117     {
118       apply();
119     }
120     catch (Exception JavaDoc x)
121     {
122       DjLogger.log(x);
123     }
124   }
125
126   public void setPropertyName(String JavaDoc propertyName) throws DjenericException
127   {
128     _mediator.setPropertyName(propertyName);
129   }
130
131   public void setViewer(ObjectViewer viewer)
132   {
133     _mediator.setViewer(viewer);
134   }
135
136   public void synchronize() throws DjenericException
137   {
138     _ekitCore.getTextPane().setText(_mediator.getPropertyValueString());
139     _ekitCore.setCaretPosition(0);
140   }
141
142   public Object JavaDoc getDisplayedValue()
143   {
144     return _ekitCore.getDocumentText();
145   }
146
147   public String JavaDoc getPropertyName()
148   {
149     return _mediator.getPropertyName();
150   }
151
152   public JComponent JavaDoc getFocussableComponent()
153   {
154     return _ekitCore;
155   }
156
157   public synchronized void addFocusListener(FocusListener JavaDoc l)
158   {
159     if (_ekitCore != null) _ekitCore.addFocusListener(l);
160   }
161
162   public synchronized void removeFocusListener(FocusListener JavaDoc l)
163   {
164     if (_ekitCore != null) _ekitCore.removeFocusListener(l);
165   }
166
167   public void requestFocus()
168   {
169     _ekitCore.getTextPane().requestFocus();
170   }
171
172 }
Popular Tags