01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @version $Revision$
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: class FieldViewI18N extends PlainViewI18N {
31: public FieldViewI18N(final Element elem) {
32: super (elem);
33: }
34:
35: protected Shape adjustAllocation(final Shape shape) {
36: Component comp = getComponent();
37: allocation = TextUtils.getFieldViewAllocation(this , TextUtils
38: .getTextFieldKit(comp), shape, comp
39: .getComponentOrientation());
40: return allocation;
41: }
42:
43: private Shape getAllocation() {
44: return allocation;
45: }
46:
47: public int getResizeWeight(final int axis) {
48: return (axis == View.X_AXIS) ? 1 : 0;
49: }
50:
51: private Shape allocation;
52:
53: public void insertUpdate(final DocumentEvent changes,
54: final Shape a, final ViewFactory f) {
55: super .insertUpdate(changes, adjustAllocation(a), f);
56: Rectangle toUpdate = adjustAllocation(a).getBounds();
57: getComponent().repaint(toUpdate.x, toUpdate.y, toUpdate.width,
58: toUpdate.height);
59: }
60:
61: public Shape modelToView(final int pos, final Shape a,
62: final Position.Bias b) throws BadLocationException {
63: return super .modelToView(pos, adjustAllocation(a), b);
64: }
65:
66: public void paint(final Graphics g, final Shape a) {
67: super .paint(g, adjustAllocation(a));
68: }
69:
70: public void removeUpdate(final DocumentEvent changes,
71: final Shape a, final ViewFactory f) {
72: Shape oldAllocation = getAllocation();
73: adjustAllocation(a);
74: super .removeUpdate(changes, oldAllocation, f);
75: }
76:
77: public int viewToModel(final float fx, final float fy,
78: final Shape a, final Position.Bias[] bias) {
79: return super .viewToModel(fx, fy, adjustAllocation(a), bias);
80: }
81:
82: public void setSize(final float width, final float height) {
83: super.setSize(getPreferredSpan(X_AXIS), height);
84: }
85: }
|