1 /* 2 * Copyright (c) 2009-2010 jMonkeyEngine 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 package com.jme3.font; 34 35 import com.jme3.font.BitmapFont.Align; 36 import com.jme3.font.BitmapFont.VAlign; 37 import com.jme3.math.ColorRGBA; 38 39 /** 40 * Defines a String that is to be drawn in one block that can be constrained by a {@link Rectangle}. Also holds 41 * formatting information for the StringBlock 42 * 43 * @author dhdd 44 */ 45 class StringBlock implements Cloneable { 46 47 private String text; 48 private Rectangle textBox; 49 private Align alignment = Align.Left; 50 private VAlign valignment = VAlign.Top; 51 private float size; 52 private ColorRGBA color = new ColorRGBA(ColorRGBA.White); 53 private boolean kerning; 54 private int lineCount; 55 private LineWrapMode wrapType = LineWrapMode.Word; 56 private float[] tabPos; 57 private float tabWidth = 50; 58 private char ellipsisChar = 0x2026; 59 60 /** 61 * 62 * @param text the text that the StringBlock will hold 63 * @param textBox the rectangle that constrains the text 64 * @param alignment the initial alignment of the text 65 * @param size the size in pixels (vertical size of a single line) 66 * @param color the initial color of the text 67 * @param kerning 68 */ StringBlock(String text, Rectangle textBox, BitmapFont.Align alignment, float size, ColorRGBA color, boolean kerning)69 StringBlock(String text, Rectangle textBox, BitmapFont.Align alignment, float size, ColorRGBA color, 70 boolean kerning) { 71 this.text = text; 72 this.textBox = textBox; 73 this.alignment = alignment; 74 this.size = size; 75 this.color.set(color); 76 this.kerning = kerning; 77 } 78 StringBlock()79 StringBlock(){ 80 this.text = ""; 81 this.textBox = null; 82 this.alignment = Align.Left; 83 this.size = 100; 84 this.color.set(ColorRGBA.White); 85 this.kerning = true; 86 } 87 88 @Override clone()89 public StringBlock clone(){ 90 try { 91 StringBlock clone = (StringBlock) super.clone(); 92 clone.color = color.clone(); 93 if (textBox != null) 94 clone.textBox = textBox.clone(); 95 return clone; 96 } catch (CloneNotSupportedException ex) { 97 throw new AssertionError(); 98 } 99 } 100 getText()101 String getText() { 102 return text; 103 } 104 setText(String text)105 void setText(String text){ 106 this.text = text == null ? "" : text; 107 } 108 getTextBox()109 Rectangle getTextBox() { 110 return textBox; 111 } 112 setTextBox(Rectangle textBox)113 void setTextBox(Rectangle textBox) { 114 this.textBox = textBox; 115 } 116 getAlignment()117 BitmapFont.Align getAlignment() { 118 return alignment; 119 } 120 getVerticalAlignment()121 BitmapFont.VAlign getVerticalAlignment() { 122 return valignment; 123 } 124 setAlignment(BitmapFont.Align alignment)125 void setAlignment(BitmapFont.Align alignment) { 126 this.alignment = alignment; 127 } 128 setVerticalAlignment(BitmapFont.VAlign alignment)129 void setVerticalAlignment(BitmapFont.VAlign alignment) { 130 this.valignment = alignment; 131 } 132 getSize()133 float getSize() { 134 return size; 135 } 136 setSize(float size)137 void setSize(float size) { 138 this.size = size; 139 } 140 getColor()141 ColorRGBA getColor() { 142 return color; 143 } 144 setColor(ColorRGBA color)145 void setColor(ColorRGBA color) { 146 this.color.set(color); 147 } 148 isKerning()149 boolean isKerning() { 150 return kerning; 151 } 152 setKerning(boolean kerning)153 void setKerning(boolean kerning) { 154 this.kerning = kerning; 155 } 156 getLineCount()157 int getLineCount() { 158 return lineCount; 159 } 160 setLineCount(int lineCount)161 void setLineCount(int lineCount) { 162 this.lineCount = lineCount; 163 } 164 getLineWrapMode()165 LineWrapMode getLineWrapMode() { 166 return wrapType; 167 } 168 169 /** 170 * available only when bounding is set. <code>setBox()</code> method call is needed in advance. 171 * @param wrap true when word need not be split at the end of the line. 172 */ setLineWrapMode(LineWrapMode wrap)173 void setLineWrapMode(LineWrapMode wrap) { 174 this.wrapType = wrap; 175 } 176 setTabWidth(float tabWidth)177 void setTabWidth(float tabWidth) { 178 this.tabWidth = tabWidth; 179 } 180 setTabPosition(float[] tabs)181 void setTabPosition(float[] tabs) { 182 this.tabPos = tabs; 183 } 184 getTabWidth()185 float getTabWidth() { 186 return tabWidth; 187 } 188 getTabPosition()189 float[] getTabPosition() { 190 return tabPos; 191 } 192 setEllipsisChar(char c)193 void setEllipsisChar(char c) { 194 this.ellipsisChar = c; 195 } 196 getEllipsisChar()197 int getEllipsisChar() { 198 return ellipsisChar; 199 } 200 }