Home » openjdk-7 » javax » swing » text » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   /**
   18    * @author Evgeniya G. Maenkova
   19    */
   20   package javax.swing.text;
   21   
   22   import java.awt.Component;
   23   import java.awt.Graphics;
   24   import java.awt.Rectangle;
   25   import java.awt.Shape;
   26   import javax.swing.event.DocumentEvent;
   27   
   28   import org.apache.harmony.awt.text.TextUtils;
   29   
   30   
   31   class FieldViewI18N extends PlainViewI18N {
   32       public FieldViewI18N(final Element elem) {
   33           super(elem);
   34       }
   35   
   36      protected Shape adjustAllocation(final Shape shape) {
   37          Component comp = getComponent();
   38          allocation = TextUtils
   39              .getFieldViewAllocation(this,
   40                                      TextUtils.getTextFieldKit(comp),
   41                                      shape,
   42                                      comp.getComponentOrientation());
   43          return allocation;
   44      }
   45   
   46       private Shape getAllocation() {
   47           return allocation;
   48       }
   49   
   50       public int getResizeWeight(final int axis) {
   51          return (axis == View.X_AXIS) ? 1 : 0;
   52       }
   53   
   54       private Shape allocation;
   55   
   56       public void insertUpdate(final DocumentEvent changes, final Shape a,
   57                                final ViewFactory f) {
   58          super.insertUpdate(changes, adjustAllocation(a), f);
   59          Rectangle toUpdate = adjustAllocation(a).getBounds();
   60          getComponent().repaint(toUpdate.x,
   61                                 toUpdate.y,
   62                                 toUpdate.width,
   63                                 toUpdate.height);
   64       }
   65   
   66       public Shape modelToView(final int pos, final Shape a,
   67                                final Position.Bias b)
   68           throws BadLocationException {
   69          return super.modelToView(pos, adjustAllocation(a), b);
   70       }
   71   
   72       public void paint(final Graphics g, final Shape a) {
   73           super.paint(g, adjustAllocation(a));
   74       }
   75   
   76       public void removeUpdate(final DocumentEvent changes, final Shape a,
   77                                final ViewFactory f) {
   78           Shape oldAllocation = getAllocation();
   79           adjustAllocation(a);
   80           super.removeUpdate(changes, oldAllocation, f);
   81       }
   82   
   83       public int viewToModel(final float fx, final float fy, final Shape a,
   84                              final Position.Bias[] bias) {
   85           return super.viewToModel(fx, fy, adjustAllocation(a), bias);
   86       }
   87   
   88       public void setSize(final float width, final float height) {
   89           super.setSize(getPreferredSpan(X_AXIS), height);
   90       }
   91   }

Home » openjdk-7 » javax » swing » text » [javadoc | source]