| 1 | /** |
| 2 | * Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of 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, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.deduced.viewer.web.shared; |
| 17 | |
| 18 | import com.google.gwt.i18n.client.HasDirection.Direction; |
| 19 | import com.google.gwt.user.client.ui.TextArea; |
| 20 | import com.google.gwt.user.client.ui.UIObject; |
| 21 | |
| 22 | /** |
| 23 | * TextArea Model |
| 24 | * |
| 25 | * @author Steve McDuff |
| 26 | * |
| 27 | */ |
| 28 | public class TextAreaModel extends TextBoxBaseModel |
| 29 | { |
| 30 | |
| 31 | /** |
| 32 | * serialVersionUID |
| 33 | */ |
| 34 | private static final long serialVersionUID = -856763511695284066L; |
| 35 | |
| 36 | /** |
| 37 | * The number of lines visible in the text area. If null, the default text |
| 38 | * area widget value will be used. |
| 39 | */ |
| 40 | private Integer visibleLines; |
| 41 | |
| 42 | /** |
| 43 | * the character width of the text area. If null, the default text area |
| 44 | * character width will be used. |
| 45 | */ |
| 46 | private Integer characterWidth; |
| 47 | |
| 48 | /** |
| 49 | * TextAreaModel constructor |
| 50 | */ |
| 51 | public TextAreaModel() |
| 52 | { |
| 53 | |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * (non-JSDoc) |
| 58 | * |
| 59 | * @see org.deduced.viewer.web.shared.WidgetModel#createUIObject() |
| 60 | */ |
| 61 | @Override |
| 62 | public UIObject createUIObject() |
| 63 | { |
| 64 | TextArea textArea = new TextArea(); |
| 65 | textArea.addValueChangeHandler(this); |
| 66 | textArea.addKeyUpHandler(this); |
| 67 | textArea.addMouseUpHandler(this); |
| 68 | createTextBoxBaseDropController(textArea); |
| 69 | return textArea; |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * get TextArea |
| 74 | * |
| 75 | * @return the text area |
| 76 | */ |
| 77 | public TextArea getTextArea() |
| 78 | { |
| 79 | return (TextArea) getUIObject(); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * (non-JSDoc) |
| 84 | * |
| 85 | * @see org.deduced.viewer.web.shared.TextBoxBaseModel#internalSynchronizeWithUI() |
| 86 | */ |
| 87 | @Override |
| 88 | public void internalSynchronizeWithUI() |
| 89 | { |
| 90 | TextArea label = getTextArea(); |
| 91 | Direction setDirection = getDirectionConstant(); |
| 92 | if (setDirection != null) |
| 93 | { |
| 94 | label.setDirection(setDirection); |
| 95 | } |
| 96 | if (getVisibleLines() != null) |
| 97 | { |
| 98 | label.setVisibleLines(getVisibleLines().intValue()); |
| 99 | } |
| 100 | if (getCharacterWidth() != null) |
| 101 | { |
| 102 | label.setCharacterWidth(getCharacterWidth().intValue()); |
| 103 | } |
| 104 | |
| 105 | super.internalSynchronizeWithUI(); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * (non-JSDoc) |
| 110 | * |
| 111 | * @see org.deduced.viewer.web.shared.TextBoxBaseModel#propertyChanged(org.deduced.viewer.web.shared.ChangeEvent) |
| 112 | */ |
| 113 | @Override |
| 114 | public void propertyChanged( |
| 115 | ChangeEvent event) |
| 116 | { |
| 117 | if (Utilities.equals(event.getName(), "visible lines")) |
| 118 | { |
| 119 | setVisibleLines((Integer) event.getSerializableValue()); |
| 120 | synchronizeWithUI(); |
| 121 | } |
| 122 | else if (Utilities.equals(event.getName(), "character width")) |
| 123 | { |
| 124 | setCharacterWidth((Integer) event.getSerializableValue()); |
| 125 | synchronizeWithUI(); |
| 126 | } |
| 127 | else |
| 128 | { |
| 129 | super.propertyChanged(event); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * @param setCharacterWidth the characterWidth to set |
| 135 | */ |
| 136 | public void setCharacterWidth( |
| 137 | Integer setCharacterWidth) |
| 138 | { |
| 139 | characterWidth = setCharacterWidth; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @return the characterWidth |
| 144 | */ |
| 145 | public Integer getCharacterWidth() |
| 146 | { |
| 147 | return characterWidth; |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * @param setVisibleLines the visibleLines to set |
| 152 | */ |
| 153 | public void setVisibleLines( |
| 154 | Integer setVisibleLines) |
| 155 | { |
| 156 | visibleLines = setVisibleLines; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @return the visibleLines |
| 161 | */ |
| 162 | public Integer getVisibleLines() |
| 163 | { |
| 164 | return visibleLines; |
| 165 | } |
| 166 | |
| 167 | } |