KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > impl > RichTextAreaImplOpera


1 /*
2  * Copyright 2007 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package com.google.gwt.user.client.ui.impl;
17
18 import com.google.gwt.user.client.Element;
19 import com.google.gwt.user.client.ui.RichTextArea;
20
21 /**
22  * Opera implementation of rich-text editing.
23  */

24 public class RichTextAreaImplOpera extends RichTextAreaImplStandard {
25
26   private static RichTextAreaImpl old;
27   private static boolean richTextSupported = detectEditingSupport();
28
29   static {
30     // If rich text is not supported by this version of Opera, create an
31
// instance of the default impl and shunt all calls to it.
32
if (!richTextSupported) {
33       old = new RichTextAreaImpl();
34     }
35   }
36
37   private static native boolean detectEditingSupport() /*-{
38     return !!$doc.designMode;
39   }-*/
;
40
41   public Element createElement() {
42     if (old != null) {
43       return old.createElement();
44     }
45     return super.createElement();
46   }
47
48   public Element getElement() {
49     if (old != null) {
50       return old.getElement();
51     }
52     return super.getElement();
53   }
54
55   public void hookEvents(RichTextArea owner) {
56     if (old != null) {
57       old.hookEvents(owner);
58       return;
59     }
60     super.hookEvents(owner);
61   }
62
63   public void initElement() {
64     if (old != null) {
65       old.initElement();
66       return;
67     }
68     super.initElement();
69   }
70
71   public boolean isBasicEditingSupported() {
72     return richTextSupported;
73   }
74
75   public boolean isExtendedEditingSupported() {
76     return richTextSupported;
77   }
78
79   public void setBackColor(String JavaDoc color) {
80     // Opera uses 'BackColor' for the *entire area's* background. 'HiliteColor'
81
// does what we actually want.
82
execCommand("HiliteColor", color);
83   }
84
85   public native void setFocus(boolean focused) /*-{
86     // Opera needs the *iframe* focused, not its window.
87     if (focused) {
88       this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem.focus();
89     } else {
90       this.@com.google.gwt.user.client.ui.impl.RichTextAreaImpl::elem.blur();
91     }
92   }-*/
;
93
94   public void unhookEvents() {
95     if (old != null) {
96       old.unhookEvents();
97     }
98     super.unhookEvents();
99   }
100
101   protected String JavaDoc getHTMLImpl() {
102     if (old != null) {
103       return old.getHTML();
104     }
105     return super.getHTMLImpl();
106   }
107
108   protected String JavaDoc getTextImpl() {
109     if (old != null) {
110       return old.getText();
111     }
112     return super.getTextImpl();
113   }
114
115   protected void setHTMLImpl(String JavaDoc html) {
116     if (old != null) {
117       old.setHTML(html);
118       return;
119     }
120     super.setHTMLImpl(html);
121   }
122
123   protected void setTextImpl(String JavaDoc text) {
124     if (old != null) {
125       old.setText(text);
126       return;
127     }
128     super.setTextImpl(text);
129   }
130 }
131
Popular Tags