home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.text;
-
- import java.awt.Rectangle;
- import java.awt.Shape;
-
- public abstract class CompositeView extends View {
- private static View[] ONE = new View[1];
- private static View[] ZERO = new View[0];
- private View[] children = new View[1];
- private int nchildren = 0;
- private short left;
- private short right;
- private short top;
- private short bottom;
-
- public CompositeView(Element var1) {
- super(var1);
- }
-
- protected void loadChildren(ViewFactory var1) {
- Element var2 = ((View)this).getElement();
- int var3 = var2.getElementCount();
- if (var3 > 0) {
- View[] var4 = new View[var3];
-
- for(int var5 = 0; var5 < var3; ++var5) {
- var4[var5] = var1.create(var2.getElement(var5));
- }
-
- this.replace(0, 0, var4);
- }
-
- }
-
- public void removeAll() {
- this.replace(0, this.nchildren, ZERO);
- }
-
- public void insert(int var1, View var2) {
- ONE[0] = var2;
- this.replace(var1, 0, ONE);
- }
-
- public void append(View var1) {
- ONE[0] = var1;
- this.replace(this.nchildren, 0, ONE);
- }
-
- public void replace(int var1, int var2, View[] var3) {
- for(int var4 = var1; var4 < var1 + var2; ++var4) {
- this.children[var4].setParent((View)null);
- }
-
- int var5 = var3.length - var2;
- int var6 = var1 + var2;
- int var7 = this.nchildren - var6;
- int var8 = var6 + var5;
- if (this.nchildren + var5 >= this.children.length) {
- int var9 = Math.max(2 * this.children.length, this.nchildren + var5);
- View[] var10 = new View[var9];
- System.arraycopy(this.children, 0, var10, 0, var1);
- System.arraycopy(var3, 0, var10, var1, var3.length);
- System.arraycopy(this.children, var6, var10, var8, var7);
- this.children = var10;
- } else {
- System.arraycopy(this.children, var6, this.children, var8, var7);
- System.arraycopy(var3, 0, this.children, var1, var3.length);
- }
-
- this.nchildren += var5;
-
- for(int var11 = 0; var11 < var3.length; ++var11) {
- var3[var11].setParent(this);
- }
-
- }
-
- public void setParent(View var1) {
- super.setParent(var1);
- if (var1 != null) {
- ViewFactory var2 = ((View)this).getViewFactory();
- this.loadChildren(var2);
- }
-
- }
-
- public int getViewCount() {
- return this.nchildren;
- }
-
- public View getView(int var1) {
- return this.children[var1];
- }
-
- public Shape getChildAllocation(int var1, Shape var2) {
- Rectangle var3 = var2.getBounds();
- this.childAllocation(var1, var3);
- return var3;
- }
-
- public Shape modelToView(int var1, Shape var2) throws BadLocationException {
- Rectangle var3 = this.getInsideAllocation(var2);
- View var4 = this.getViewAtPosition(var1, var3);
- if (var4 != null) {
- int var5 = var4.getStartOffset();
- int var6 = var4.getEndOffset();
- if (var1 >= var5 && var1 < var6) {
- return var4.modelToView(var1, var3);
- }
- }
-
- throw new BadLocationException("Position not represented by view", var1);
- }
-
- public int viewToModel(float var1, float var2, Shape var3) {
- Rectangle var4 = this.getInsideAllocation(var3);
- if (this.isBefore((int)var1, (int)var2, var4)) {
- return ((View)this).getStartOffset();
- } else if (this.isAfter((int)var1, (int)var2, var4)) {
- return ((View)this).getEndOffset() - 1;
- } else {
- View var5 = this.getViewAtPoint((int)var1, (int)var2, var4);
- return var5 != null ? var5.viewToModel(var1, var2, var4) : -1;
- }
- }
-
- protected abstract boolean isBefore(int var1, int var2, Rectangle var3);
-
- protected abstract boolean isAfter(int var1, int var2, Rectangle var3);
-
- protected abstract View getViewAtPoint(int var1, int var2, Rectangle var3);
-
- protected abstract void childAllocation(int var1, Rectangle var2);
-
- protected View getViewAtPosition(int var1, Rectangle var2) {
- Element var3 = ((View)this).getElement();
- int var4 = var3.getElementIndex(var1);
- Element var5 = var3.getElement(var4);
- if (var5 != null && var4 < this.getViewCount()) {
- View var6 = this.getView(var4);
- if (var6.getElement() == var5) {
- if (var2 != null) {
- this.childAllocation(var4, var2);
- }
-
- return var6;
- }
- }
-
- return null;
- }
-
- protected Rectangle getInsideAllocation(Shape var1) {
- if (var1 != null) {
- Rectangle var2 = new Rectangle(var1.getBounds());
- var2.x += this.left;
- var2.y += this.top;
- var2.width -= this.left + this.right;
- var2.height -= this.top + this.bottom;
- return var2;
- } else {
- return null;
- }
- }
-
- protected final void setParagraphInsets(AttributeSet var1) {
- this.top = (short)((int)StyleConstants.getSpaceAbove(var1));
- this.left = (short)((int)StyleConstants.getLeftIndent(var1));
- this.bottom = (short)((int)StyleConstants.getSpaceBelow(var1));
- this.right = (short)((int)StyleConstants.getRightIndent(var1));
- }
-
- protected final void setInsets(short var1, short var2, short var3, short var4) {
- this.top = var1;
- this.left = var2;
- this.right = var4;
- this.bottom = var3;
- }
-
- protected final short getLeftInset() {
- return this.left;
- }
-
- protected final short getRightInset() {
- return this.right;
- }
-
- protected final short getTopInset() {
- return this.top;
- }
-
- protected final short getBottomInset() {
- return this.bottom;
- }
- }
-