- Timestamp:
- 10/18/18 15:20:04 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gio/swing/SwingTextLayoutManager.java
r1144 r1184 31 31 public static SwingTextLayoutManager getInstance() 32 32 { 33 if (_instance == null) _instance = new SwingTextLayoutManager(); 33 if (_instance == null) { 34 _instance = new SwingTextLayoutManager(); 35 } 34 36 35 37 return _instance; … … 46 48 private synchronized void register(TextLayout layout, java.awt.font.TextLayout swingLayout) 47 49 { 48 if (layout == null || swingLayout == null) return; 50 if (layout == null || swingLayout == null) { 51 return; 52 } 49 53 50 54 _layoutMap.put(layout.getHandle(), swingLayout); … … 53 57 public synchronized java.awt.font.TextLayout getInternalLayout(TextLayout layout) 54 58 { 55 if (!isTextLayoutValid(layout)) return null; 59 if (!isTextLayoutValid(layout)) { 60 return null; 61 } 56 62 57 63 return _layoutMap.get(layout.getHandle()); … … 60 66 public synchronized boolean isTextLayoutValid(TextLayout layout) 61 67 { 62 if (layout == null) return false; 68 if (layout == null) { 69 return false; 70 } 63 71 64 72 return _layoutMap.containsKey(layout.getHandle()); … … 68 76 public float getAdvance(TextLayout layout) 69 77 { 70 if (!isTextLayoutValid(layout)) return Float.NaN; 78 if (!isTextLayoutValid(layout)) { 79 return Float.NaN; 80 } 71 81 72 82 return getInternalLayout(layout).getAdvance(); … … 76 86 public int getCharacterCount(TextLayout layout) 77 87 { 78 if (!isTextLayoutValid(layout)) return 0; 88 if (!isTextLayoutValid(layout)) { 89 return 0; 90 } 79 91 80 92 return getInternalLayout(layout).getCharacterCount(); … … 84 96 public TextHitInfo getNextLeftHit(TextLayout layout, int offset) 85 97 { 86 if (!isTextLayoutValid(layout)) return null; 98 if (!isTextLayoutValid(layout)) { 99 return null; 100 } 87 101 88 102 return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).getNextLeftHit(offset)); … … 92 106 public TextHitInfo getNextLeftHit(TextLayout layout, TextHitInfo hit) 93 107 { 94 if (!isTextLayoutValid(layout)) return null; 108 if (!isTextLayoutValid(layout)) { 109 return null; 110 } 95 111 96 112 return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).getNextLeftHit(SwingConversions.toSwingTextHitInfo(hit))); … … 100 116 public TextHitInfo getNextRightHit(TextLayout layout, int offset) 101 117 { 102 if (!isTextLayoutValid(layout)) return null; 118 if (!isTextLayoutValid(layout)) { 119 return null; 120 } 103 121 104 122 return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).getNextRightHit(offset)); … … 108 126 public TextHitInfo getNextRightHit(TextLayout layout, TextHitInfo hit) 109 127 { 110 if (!isTextLayoutValid(layout)) return null; 128 if (!isTextLayoutValid(layout)) { 129 return null; 130 } 111 131 112 132 return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).getNextRightHit(SwingConversions.toSwingTextHitInfo(hit))); … … 116 136 public float[] getCaretInfo(TextLayout layout, TextHitInfo hit) 117 137 { 118 if (!isTextLayoutValid(layout)) return null; 138 if (!isTextLayoutValid(layout)) { 139 return null; 140 } 119 141 120 142 return getInternalLayout(layout).getCaretInfo(SwingConversions.toSwingTextHitInfo(hit)); … … 124 146 public TextHitInfo hitTestChar(TextLayout layout, float x, float y) 125 147 { 126 if (!isTextLayoutValid(layout)) return null; 148 if (!isTextLayoutValid(layout)) { 149 return null; 150 } 127 151 128 152 return SwingConversions.fromSwingTextHitInfo(getInternalLayout(layout).hitTestChar(x, y)); … … 132 156 public AxisAlignedBoxBounds getPixelBounds(TextLayout layout, float x, float y) 133 157 { 134 if (!isTextLayoutValid(layout)) return null; 158 if (!isTextLayoutValid(layout)) { 159 return null; 160 } 135 161 136 162 return SwingConversions.fromSwingRectangle(getInternalLayout(layout).getPixelBounds(null, x, y)); … … 140 166 public AxisAlignedBoxBounds getLogicalHighlightShape(TextLayout layout, int firstEndpoint, int secondEndpoint) 141 167 { 142 if (!isTextLayoutValid(layout)) return null; 168 if (!isTextLayoutValid(layout)) { 169 return null; 170 } 143 171 144 172 Rectangle rect = getInternalLayout(layout).getLogicalHighlightShape(firstEndpoint, secondEndpoint).getBounds(); … … 150 178 public float getAscent(TextLayout layout) 151 179 { 152 if (!isTextLayoutValid(layout)) return Float.NaN; 180 if (!isTextLayoutValid(layout)) { 181 return Float.NaN; 182 } 153 183 154 184 return getInternalLayout(layout).getAscent(); … … 158 188 public float getDescent(TextLayout layout) 159 189 { 160 if (!isTextLayoutValid(layout)) return Float.NaN; 190 if (!isTextLayoutValid(layout)) { 191 return Float.NaN; 192 } 161 193 162 194 return getInternalLayout(layout).getDescent(); … … 166 198 public float getLeading(TextLayout layout) 167 199 { 168 if (!isTextLayoutValid(layout)) return Float.NaN; 200 if (!isTextLayoutValid(layout)) { 201 return Float.NaN; 202 } 169 203 170 204 return getInternalLayout(layout).getLeading(); … … 174 208 public synchronized void releaseLayout(TextLayout layout) 175 209 { 176 if (!isTextLayoutValid(layout)) return; 210 if (!isTextLayoutValid(layout)) { 211 return; 212 } 177 213 178 214 _layoutMap.remove(layout.getHandle()); … … 182 218 public List<TextLayout> layoutString(String string, Font font, Point start, Line[] lineBreakers, int widthLimit, int lineSpacing, boolean dontBreakWords, boolean fullJustify) 183 219 { 184 if (string == null || font == null || start == null) return null; 220 if (string == null || font == null || start == null) { 221 return null; 222 } 185 223 186 224 // Make sure we have a swing font to use 187 225 java.awt.Font swingFont; 188 226 SwingFontManager fontManager = SwingMiscManager.getIfUsingSwingFontManager(); 189 if (fontManager == null) return null; 227 if (fontManager == null) { 228 return null; 229 } 190 230 swingFont = fontManager.getInternalFont(font); 191 if (swingFont == null) return null; 231 if (swingFont == null) { 232 return null; 233 } 192 234 193 235 // Temporary list to accumulate the TextLayouts in to … … 209 251 210 252 int width = widthLimit; 211 if (lineBreakers != null) width = Math.min(width, (int) getLineWidth(start, lineBreakers)); 253 if (lineBreakers != null) { 254 width = Math.min(width, (int) getLineWidth(start, lineBreakers)); 255 } 212 256 213 257 int end = string.length(); … … 223 267 // If it's impossible to layout any more text without breaking a word, just do it 224 268 if (layout == null && width == widthLimit) { 225 layout = lineBreaker.nextLayout( width, end, false);269 layout = lineBreaker.nextLayout(Integer.MAX_VALUE, end, false); 226 270 // If still impossible, give up 227 if (layout == null) break; 271 272 if (layout == null) { 273 break; 274 } 228 275 } 229 276 … … 266 313 SwingFontManager f = SwingMiscManager.getIfUsingSwingFontManager(); 267 314 268 if (g == null || f == null) return -1; 315 if (g == null || f == null) { 316 return -1; 317 } 269 318 270 319 if (font != null) {
Note:
See TracChangeset
for help on using the changeset viewer.