< prev index next >

src/java.desktop/share/classes/javax/swing/text/TextLayoutStrategy.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  71         super.insertUpdate(fv, e, alloc);
  72     }
  73 
  74     /**
  75      * Gives notification that something was removed from the document
  76      * in a location that the given flow view is responsible for.
  77      *
  78      * @param e the change information from the associated document
  79      * @param alloc the current allocation of the view inside of the insets.
  80      * @see View#removeUpdate
  81      */
  82     public void removeUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) {
  83         sync(fv);
  84         super.removeUpdate(fv, e, alloc);
  85     }
  86 
  87     /**
  88      * Gives notification from the document that attributes were changed
  89      * in a location that this view is responsible for.
  90      *
  91      * @param changes the change information from the associated document
  92      * @param a the current allocation of the view
  93      * @param f the factory to use to rebuild if the view has children
  94      * @see View#changedUpdate
  95      */
  96     public void changedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) {
  97         sync(fv);
  98         super.changedUpdate(fv, e, alloc);
  99     }
 100 
 101     /**
 102      * Does a a full layout on the given View.  This causes all of
 103      * the rows (child views) to be rebuilt to match the given
 104      * constraints for each row.  This is called by a FlowView.layout
 105      * to update the child views in the flow.
 106      *
 107      * @param fv the view to reflow
 108      */
 109     public void layout(FlowView fv) {
 110         super.layout(fv);
 111     }
 112 
 113     /**
 114      * Creates a row of views that will fit within the
 115      * layout span of the row.  This is implemented to execute the
 116      * superclass functionality (which fills the row with child
 117      * views or view fragments) and follow that with bidi reordering
 118      * of the unidirectional view fragments.
 119      *
 120      * @param row the row to fill in with views.  This is assumed
 121      *   to be empty on entry.
 122      * @param pos  The current position in the children of
 123      *   this views element from which to start.
 124      * @return the position to start the next row
 125      */
 126     protected int layoutRow(FlowView fv, int rowIndex, int p0) {
 127         int p1 = super.layoutRow(fv, rowIndex, p0);
 128         View row = fv.getView(rowIndex);
 129         Document doc = fv.getDocument();
 130         Object i18nFlag = doc.getProperty(AbstractDocument.I18NProperty);
 131         if ((i18nFlag != null) && i18nFlag.equals(Boolean.TRUE)) {
 132             int n = row.getViewCount();
 133             if (n > 1) {
 134                 AbstractDocument d = (AbstractDocument)fv.getDocument();
 135                 Element bidiRoot = d.getBidiRootElement();
 136                 byte[] levels = new byte[n];
 137                 View[] reorder = new View[n];
 138 
 139                 for( int i=0; i<n; i++ ) {
 140                     View v = row.getView(i);
 141                     int bidiIndex =bidiRoot.getElementIndex(v.getStartOffset());
 142                     Element bidiElem = bidiRoot.getElement( bidiIndex );
 143                     levels[i] = (byte)StyleConstants.getBidiLevel(bidiElem.getAttributes());
 144                     reorder[i] = v;
 145                 }
 146 
 147                 BidiUtils.reorderVisually( levels, reorder );
 148                 row.replace(0, n, reorder);
 149             }
 150         }
 151         return p1;
 152     }
 153 
 154     /**
 155      * Adjusts the given row if possible to fit within the
 156      * layout span.  Since all adjustments were already
 157      * calculated by the LineBreakMeasurer, this is implemented
 158      * to do nothing.
 159      *
 160      * @param r the row to adjust to the current layout
 161      *  span.
 162      * @param desiredSpan the current layout span >= 0
 163      * @param x the location r starts at.
 164      */
 165     protected void adjustRow(FlowView fv, int rowIndex, int desiredSpan, int x) {
 166     }
 167 
 168     /**
 169      * Creates a unidirectional view that can be used to represent the
 170      * current chunk.  This can be either an entire view from the
 171      * logical view, or a fragment of the view.
 172      *
 173      * @param fv the view holding the flow
 174      * @param startOffset the start location for the view being created
 175      * @param spanLeft the about of span left to fill in the row
 176      * @param rowIndex the row the view will be placed into
 177      */
 178     protected View createView(FlowView fv, int startOffset, int spanLeft, int rowIndex) {
 179         // Get the child view that contains the given starting position
 180         View lv = getLogicalView(fv);


   1 /*
   2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  71         super.insertUpdate(fv, e, alloc);
  72     }
  73 
  74     /**
  75      * Gives notification that something was removed from the document
  76      * in a location that the given flow view is responsible for.
  77      *
  78      * @param e the change information from the associated document
  79      * @param alloc the current allocation of the view inside of the insets.
  80      * @see View#removeUpdate
  81      */
  82     public void removeUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) {
  83         sync(fv);
  84         super.removeUpdate(fv, e, alloc);
  85     }
  86 
  87     /**
  88      * Gives notification from the document that attributes were changed
  89      * in a location that this view is responsible for.
  90      *
  91      * @param e the change information from the associated document
  92      * @param alloc the current allocation of the view inside of the insets.

  93      * @see View#changedUpdate
  94      */
  95     public void changedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc) {
  96         sync(fv);
  97         super.changedUpdate(fv, e, alloc);
  98     }
  99 
 100     /**
 101      * Does a a full layout on the given View.  This causes all of
 102      * the rows (child views) to be rebuilt to match the given
 103      * constraints for each row.  This is called by a FlowView.layout
 104      * to update the child views in the flow.
 105      *
 106      * @param fv the view to reflow
 107      */
 108     public void layout(FlowView fv) {
 109         super.layout(fv);
 110     }
 111 
 112     /**
 113      * Creates a row of views that will fit within the
 114      * layout span of the row.  This is implemented to execute the
 115      * superclass functionality (which fills the row with child
 116      * views or view fragments) and follow that with bidi reordering
 117      * of the unidirectional view fragments.
 118      *
 119      * @param rowIndex the row to fill in with views.  This is assumed
 120      *   to be empty on entry.
 121      * @param p0  The current position in the children of
 122      *   this views element from which to start.
 123      * @return the position to start the next row
 124      */
 125     protected int layoutRow(FlowView fv, int rowIndex, int p0) {
 126         int p1 = super.layoutRow(fv, rowIndex, p0);
 127         View row = fv.getView(rowIndex);
 128         Document doc = fv.getDocument();
 129         Object i18nFlag = doc.getProperty(AbstractDocument.I18NProperty);
 130         if ((i18nFlag != null) && i18nFlag.equals(Boolean.TRUE)) {
 131             int n = row.getViewCount();
 132             if (n > 1) {
 133                 AbstractDocument d = (AbstractDocument)fv.getDocument();
 134                 Element bidiRoot = d.getBidiRootElement();
 135                 byte[] levels = new byte[n];
 136                 View[] reorder = new View[n];
 137 
 138                 for( int i=0; i<n; i++ ) {
 139                     View v = row.getView(i);
 140                     int bidiIndex =bidiRoot.getElementIndex(v.getStartOffset());
 141                     Element bidiElem = bidiRoot.getElement( bidiIndex );
 142                     levels[i] = (byte)StyleConstants.getBidiLevel(bidiElem.getAttributes());
 143                     reorder[i] = v;
 144                 }
 145 
 146                 BidiUtils.reorderVisually( levels, reorder );
 147                 row.replace(0, n, reorder);
 148             }
 149         }
 150         return p1;
 151     }
 152 
 153     /**
 154      * Adjusts the given row if possible to fit within the
 155      * layout span.  Since all adjustments were already
 156      * calculated by the LineBreakMeasurer, this is implemented
 157      * to do nothing.
 158      *
 159      * @param rowIndex the row to adjust to the current layout
 160      *  span.
 161      * @param desiredSpan the current layout span >= 0
 162      * @param x the location r starts at.
 163      */
 164     protected void adjustRow(FlowView fv, int rowIndex, int desiredSpan, int x) {
 165     }
 166 
 167     /**
 168      * Creates a unidirectional view that can be used to represent the
 169      * current chunk.  This can be either an entire view from the
 170      * logical view, or a fragment of the view.
 171      *
 172      * @param fv the view holding the flow
 173      * @param startOffset the start location for the view being created
 174      * @param spanLeft the about of span left to fill in the row
 175      * @param rowIndex the row the view will be placed into
 176      */
 177     protected View createView(FlowView fv, int startOffset, int spanLeft, int rowIndex) {
 178         // Get the child view that contains the given starting position
 179         View lv = getLogicalView(fv);


< prev index next >