< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1997, 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


 985             boolean ret = (justification == StyleConstants.ALIGN_JUSTIFIED);
 986 
 987             //no justification for i18n documents
 988             ret = ret && isJustifiableDocument();
 989 
 990             //no justification for the last row
 991             ret = ret && ! isLastRow();
 992 
 993             //no justification for the broken rows
 994             ret = ret && ! isBrokenRow();
 995 
 996             return ret;
 997         }
 998 
 999 
1000         //Calls super method after setting spaceAddon to 0.
1001         //Justification should not affect MajorAxisRequirements
1002         @Override
1003         protected SizeRequirements calculateMajorAxisRequirements(int axis,
1004                 SizeRequirements r) {
1005             int oldJustficationData[] = justificationData;
1006             justificationData = null;
1007             SizeRequirements ret = super.calculateMajorAxisRequirements(axis, r);
1008             if (isJustifyEnabled()) {
1009                 justificationData = oldJustficationData;
1010             }
1011             return ret;
1012         }
1013 
1014         @Override
1015         protected void layoutMajorAxis(int targetSpan, int axis,
1016                                        int[] offsets, int[] spans) {
1017             int oldJustficationData[] = justificationData;
1018             justificationData = null;
1019             super.layoutMajorAxis(targetSpan, axis, offsets, spans);
1020             if (! isJustifyEnabled()) {
1021                 return;
1022             }
1023 
1024             int currentSpan = 0;
1025             for (int span : spans) {
1026                 currentSpan += span;
1027             }
1028             if (currentSpan == targetSpan) {
1029                 //no need to justify
1030                 return;
1031             }
1032 
1033             // we justify text by enlarging spaces by the {@code spaceAddon}.
1034             // justification is started to the right of the rightmost TAB.
1035             // leading and trailing spaces are not extendable.
1036             //
1037             // GlyphPainter1 uses
1038             // justificationData
1039             // for all painting and measurement.
1040 
1041             int extendableSpaces = 0;
1042             int startJustifiableContent = -1;
1043             int endJustifiableContent = -1;
1044             int lastLeadingSpaces = 0;
1045 
1046             int rowStartOffset = getStartOffset();
1047             int rowEndOffset = getEndOffset();
1048             int spaceMap[] = new int[rowEndOffset - rowStartOffset];
1049             Arrays.fill(spaceMap, 0);
1050             for (int i = getViewCount() - 1; i >= 0 ; i--) {
1051                 View view = getView(i);
1052                 if (view instanceof GlyphView) {
1053                     GlyphView.JustificationInfo justificationInfo =
1054                         ((GlyphView) view).getJustificationInfo(rowStartOffset);
1055                     final int viewStartOffset = view.getStartOffset();
1056                     final int offset = viewStartOffset - rowStartOffset;
1057                     for (int j = 0; j < justificationInfo.spaceMap.length(); j++) {
1058                         if (justificationInfo.spaceMap.get(j)) {
1059                             spaceMap[j + offset] = 1;
1060                         }
1061                     }
1062                     if (startJustifiableContent > 0) {
1063                         if (justificationInfo.end >= 0) {
1064                             extendableSpaces += justificationInfo.trailingSpaces;
1065                         } else {
1066                             lastLeadingSpaces += justificationInfo.trailingSpaces;
1067                         }
1068                     }


1162             if ((parentView = getParent()) != null) { //use firstLineIdent for the first row
1163                 if (this == parentView.getView(0)) {
1164                     adjustment = firstLineIndent;
1165                 }
1166             }
1167             return (short)(super.getLeftInset() + adjustment);
1168         }
1169 
1170         protected short getBottomInset() {
1171             return (short)(super.getBottomInset() +
1172                            ((minorRequest != null) ? minorRequest.preferred : 0) *
1173                            lineSpacing);
1174         }
1175 
1176         static final int SPACE_ADDON = 0;
1177         static final int SPACE_ADDON_LEFTOVER_END = 1;
1178         static final int START_JUSTIFIABLE = 2;
1179         //this should be the last index in justificationData
1180         static final int END_JUSTIFIABLE = 3;
1181 
1182         int justificationData[] = null;
1183     }
1184 
1185 }
   1 /*
   2  * Copyright (c) 1997, 2018, 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


 985             boolean ret = (justification == StyleConstants.ALIGN_JUSTIFIED);
 986 
 987             //no justification for i18n documents
 988             ret = ret && isJustifiableDocument();
 989 
 990             //no justification for the last row
 991             ret = ret && ! isLastRow();
 992 
 993             //no justification for the broken rows
 994             ret = ret && ! isBrokenRow();
 995 
 996             return ret;
 997         }
 998 
 999 
1000         //Calls super method after setting spaceAddon to 0.
1001         //Justification should not affect MajorAxisRequirements
1002         @Override
1003         protected SizeRequirements calculateMajorAxisRequirements(int axis,
1004                 SizeRequirements r) {
1005             int[] oldJustficationData = justificationData;
1006             justificationData = null;
1007             SizeRequirements ret = super.calculateMajorAxisRequirements(axis, r);
1008             if (isJustifyEnabled()) {
1009                 justificationData = oldJustficationData;
1010             }
1011             return ret;
1012         }
1013 
1014         @Override
1015         protected void layoutMajorAxis(int targetSpan, int axis,
1016                                        int[] offsets, int[] spans) {
1017             int[] oldJustficationData = justificationData;
1018             justificationData = null;
1019             super.layoutMajorAxis(targetSpan, axis, offsets, spans);
1020             if (! isJustifyEnabled()) {
1021                 return;
1022             }
1023 
1024             int currentSpan = 0;
1025             for (int span : spans) {
1026                 currentSpan += span;
1027             }
1028             if (currentSpan == targetSpan) {
1029                 //no need to justify
1030                 return;
1031             }
1032 
1033             // we justify text by enlarging spaces by the {@code spaceAddon}.
1034             // justification is started to the right of the rightmost TAB.
1035             // leading and trailing spaces are not extendable.
1036             //
1037             // GlyphPainter1 uses
1038             // justificationData
1039             // for all painting and measurement.
1040 
1041             int extendableSpaces = 0;
1042             int startJustifiableContent = -1;
1043             int endJustifiableContent = -1;
1044             int lastLeadingSpaces = 0;
1045 
1046             int rowStartOffset = getStartOffset();
1047             int rowEndOffset = getEndOffset();
1048             int[] spaceMap = new int[rowEndOffset - rowStartOffset];
1049             Arrays.fill(spaceMap, 0);
1050             for (int i = getViewCount() - 1; i >= 0 ; i--) {
1051                 View view = getView(i);
1052                 if (view instanceof GlyphView) {
1053                     GlyphView.JustificationInfo justificationInfo =
1054                         ((GlyphView) view).getJustificationInfo(rowStartOffset);
1055                     final int viewStartOffset = view.getStartOffset();
1056                     final int offset = viewStartOffset - rowStartOffset;
1057                     for (int j = 0; j < justificationInfo.spaceMap.length(); j++) {
1058                         if (justificationInfo.spaceMap.get(j)) {
1059                             spaceMap[j + offset] = 1;
1060                         }
1061                     }
1062                     if (startJustifiableContent > 0) {
1063                         if (justificationInfo.end >= 0) {
1064                             extendableSpaces += justificationInfo.trailingSpaces;
1065                         } else {
1066                             lastLeadingSpaces += justificationInfo.trailingSpaces;
1067                         }
1068                     }


1162             if ((parentView = getParent()) != null) { //use firstLineIdent for the first row
1163                 if (this == parentView.getView(0)) {
1164                     adjustment = firstLineIndent;
1165                 }
1166             }
1167             return (short)(super.getLeftInset() + adjustment);
1168         }
1169 
1170         protected short getBottomInset() {
1171             return (short)(super.getBottomInset() +
1172                            ((minorRequest != null) ? minorRequest.preferred : 0) *
1173                            lineSpacing);
1174         }
1175 
1176         static final int SPACE_ADDON = 0;
1177         static final int SPACE_ADDON_LEFTOVER_END = 1;
1178         static final int START_JUSTIFIABLE = 2;
1179         //this should be the last index in justificationData
1180         static final int END_JUSTIFIABLE = 3;
1181 
1182         int[] justificationData = null;
1183     }
1184 
1185 }
< prev index next >