View Javadoc

1   /*
2    * Copyright 2004-2008 the Seasar Foundation and the Others.
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, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
15   */
16  package org.seasar.uruma.renderer.impl;
17  
18  import org.eclipse.swt.SWT;
19  import org.eclipse.swt.widgets.Text;
20  import org.seasar.uruma.component.jface.TextComponent;
21  
22  /**
23   * {@link Text} のレンダリングを行うクラスです。<br />
24   * 
25   * @author bskuroneko
26   */
27  public class TextRenderer extends AbstractControlRenderer<TextComponent, Text> {
28  
29      /*
30       * @see org.seasar.uruma.renderer.impl.AbstractControlRenderer#doRenderControl(org.seasar.uruma.component.jface.ControlComponent,
31       *      org.eclipse.swt.widgets.Control)
32       */
33      @Override
34      protected void doRenderControl(final TextComponent controlComponent,
35              final Text control) {
36          setSelection(controlComponent, control);
37      }
38  
39      private void setSelection(final TextComponent controlComponent,
40              final Text control) {
41          if (controlComponent.selectionStart == null
42                  && controlComponent.selectionEnd == null) {
43              return;
44          }
45  
46          int start = 0;
47          if (controlComponent.selectionStart != null) {
48              start = Integer.parseInt(controlComponent.selectionStart);
49          }
50  
51          if (controlComponent.selectionEnd == null) {
52              control.setSelection(start);
53          } else {
54              int end = Integer.parseInt(controlComponent.selectionEnd);
55              control.setSelection(start, end);
56          }
57      }
58  
59      /*
60       * @see org.seasar.uruma.renderer.impl.AbstractWidgetRenderer#getWidgetType()
61       */
62      @Override
63      protected Class<Text> getWidgetType() {
64          return Text.class;
65      }
66  
67      /*
68       * @see org.seasar.uruma.renderer.impl.AbstractRenderer#getDefaultStyle()
69       */
70      @Override
71      protected int getDefaultStyle() {
72          return SWT.SINGLE | SWT.BORDER;
73      }
74  
75  }