Revision 2165 branches/gvSIG_GisPlanet/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/FFrameText.java
FFrameText.java | ||
---|---|---|
46 | 46 |
|
47 | 47 |
import com.iver.andami.PluginServices; |
48 | 48 |
|
49 |
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities; |
|
49 | 50 |
import com.iver.cit.gvsig.gui.layout.Layout; |
51 |
import com.iver.cit.gvsig.gui.layout.Size; |
|
50 | 52 |
|
51 | 53 |
import com.iver.utiles.StringUtilities; |
52 | 54 |
import com.iver.utiles.XMLEntity; |
... | ... | |
74 | 76 |
public static final int CENTER = 1; |
75 | 77 |
public static final int RIGTH = 2; |
76 | 78 |
private ArrayList m_text = new ArrayList(); |
77 |
private boolean m_isFixed = true;
|
|
79 |
private boolean m_isFixed = false;
|
|
78 | 80 |
private double m_rotation = 0; |
79 | 81 |
private int m_pos = LEFT; |
80 | 82 |
private Color textColor = Color.BLACK; |
83 |
//jaume |
|
84 |
private boolean surrounded = false; // The text field is surrounded by a rectangle |
|
85 |
private int cellPadding = 0; // The gap between the the text field and the surrounding rectangle |
|
81 | 86 |
|
82 | 87 |
//private int m_space=0; |
88 |
private boolean fixedFontSize = false; // The text field font size is constant fixed to the folio's size |
|
89 |
private int fontSize; // Text field's font size |
|
83 | 90 |
private Font m_f = null; |
84 |
|
|
91 |
private Layout layout; |
|
85 | 92 |
/** |
86 | 93 |
* Crea un nuevo FFrameText. |
87 | 94 |
*/ |
95 |
// public FFrameText(Layout l) { |
|
96 |
// layout=l; |
|
97 |
// m_f = new Font("SansSerif", Font.PLAIN, 9); |
|
98 |
// } |
|
88 | 99 |
public FFrameText() { |
89 |
m_f = new Font("SansSerif", Font.PLAIN, 9);
|
|
100 |
m_f = new Font("SansSerif", Font.PLAIN, 9);
|
|
90 | 101 |
} |
91 | 102 |
|
92 | 103 |
/** |
... | ... | |
107 | 118 |
return textColor; |
108 | 119 |
} |
109 | 120 |
|
121 |
/** |
|
122 |
* Obtiene el fixedFontSize |
|
123 |
* @return boolean |
|
124 |
*/ |
|
125 |
|
|
126 |
public boolean isFontSizeFixed() { |
|
127 |
return fixedFontSize; |
|
128 |
} |
|
129 |
/** |
|
130 |
* Establece fixedFontSize |
|
131 |
* @param fixedFontSize |
|
132 |
*/ |
|
133 |
public void setFixedFontSize(boolean fixedFontSize) { |
|
134 |
this.fixedFontSize = fixedFontSize; |
|
135 |
} |
|
136 |
/** |
|
137 |
* Obtiene el fontSize |
|
138 |
* @return int |
|
139 |
*/ |
|
140 |
|
|
141 |
public int getFontSize() { |
|
142 |
return fontSize; |
|
143 |
} |
|
144 |
/** |
|
145 |
* Establece fontSize |
|
146 |
* @param fontSize |
|
147 |
*/ |
|
148 |
public void setFontSize(int fontSize) { |
|
149 |
this.fontSize = fontSize; |
|
150 |
} |
|
151 |
/** |
|
152 |
* Obtiene el cellPadding |
|
153 |
* @return int |
|
154 |
*/ |
|
155 |
|
|
156 |
public int getCellPadding() { |
|
157 |
return cellPadding; |
|
158 |
} |
|
110 | 159 |
/** |
111 | 160 |
* Inserta el color del texto a escribir. |
112 | 161 |
* |
... | ... | |
162 | 211 |
*/ |
163 | 212 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
164 | 213 |
BufferedImage imgBase) { |
165 |
Rectangle2D.Double re = getBoundingBox(at); |
|
214 |
Rectangle2D.Double rec = getBoundingBox(at); |
|
215 |
Rectangle2D.Double raux = (Rectangle2D.Double)rec.clone(); |
|
166 | 216 |
int longmax = 1; |
167 |
|
|
168 |
if (intersects(rv, re)) {
|
|
217 |
Size folio = layout.getAtributes().m_sizePaper; |
|
218 |
if (intersects(rv, raux)) { // comprueba que no cae fuera de la pantalla
|
|
169 | 219 |
if (m_text.isEmpty()) { |
170 | 220 |
drawEmpty(g); |
171 | 221 |
} else { |
... | ... | |
174 | 224 |
longmax = ((String) m_text.get(i)).length(); |
175 | 225 |
} |
176 | 226 |
} |
177 |
|
|
178 | 227 |
FontRenderContext frc = g.getFontRenderContext(); |
179 |
int scale = ((int) (re.width * 2.2)) / longmax; |
|
228 |
int scaledFontSize; |
|
229 |
|
|
230 |
// TODO myScale es la escala sobre la que se extraen todos los escalados. Esto |
|
231 |
// funciona bien tal cual est? si la ratio de aspecto (alto/ancho) del folio es constante |
|
232 |
// porque se toma como medidas el ancho del folio real y el ancho del folio en pantalla. |
|
233 |
// No se que pasar? si la ratio cambia, por ejemplo si se usan USLetter en lugar de DIN A4 |
|
234 |
double myScale = FLayoutUtilities.fromSheetDistance(folio.getAncho(),at)/rv.getWidth(); |
|
235 |
|
|
236 |
if (isFontSizeFixed()){ |
|
237 |
scaledFontSize=(int)(myScale*fontSize); |
|
238 |
} else { |
|
239 |
scaledFontSize = ((int) (rec.width * 2.2)) / longmax; |
|
180 | 240 |
|
181 |
if (scale > (int) ((re.height * 10) / 4 / (m_text.size() * 1.3))) { |
|
182 |
scale = (int) (((re.height * 10) / 4) / (m_text.size() * 1.3)); |
|
241 |
if (scaledFontSize > (int) ((rec.height * 10) / 4 / (m_text.size() * 1.3))) { |
|
242 |
scaledFontSize = (int) (((rec.height * 10) / 4) / (m_text.size() * 1.3)); |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
if (isSurrounded()){ |
|
247 |
g.drawRect((int) rec.x, (int) rec.y, (int)rec.width, (int)rec.height); |
|
248 |
double scaledCellPadding = cellPadding*myScale; |
|
249 |
raux.setRect(rec.getX() + scaledCellPadding, rec.getY() - scaledCellPadding, |
|
250 |
rec.getWidth()- scaledCellPadding*2, rec.getHeight()- scaledCellPadding*2); |
|
251 |
|
|
183 | 252 |
} |
253 |
|
|
254 |
int ht = (int) (raux.height / m_text.size()); |
|
184 | 255 |
|
185 |
int ht = (int) (re.height / m_text.size()); |
|
186 |
|
|
187 | 256 |
if (m_f != null) { |
188 |
m_f = new Font(m_f.getFontName(), m_f.getStyle(), scale); |
|
257 |
m_f = new Font(m_f.getFontName(), m_f.getStyle(), scaledFontSize);
|
|
189 | 258 |
} else { |
190 |
m_f = new Font("SansSerif", Font.PLAIN, scale); |
|
259 |
m_f = new Font("SansSerif", Font.PLAIN, scaledFontSize);
|
|
191 | 260 |
} |
192 | 261 |
|
193 | 262 |
for (int i = 0; i < m_text.size(); i++) { |
194 | 263 |
if (!((String) m_text.get(i)).equals("")) { |
195 |
TextLayout layout = new TextLayout((String) m_text.get(
|
|
264 |
TextLayout textLayout = new TextLayout((String) m_text.get(
|
|
196 | 265 |
i), m_f, frc); |
197 | 266 |
g.setColor(textColor); |
198 | 267 |
g.rotate(Math.toRadians(m_rotation), |
199 |
re.x + (re.width / 2), re.y + (re.height / 2));
|
|
200 |
|
|
268 |
raux.x + (raux.width / 2), raux.y + (raux.height / 2));
|
|
269 |
|
|
201 | 270 |
int l = ((String) m_text.get(i)).length(); |
202 |
|
|
271 |
float textOffset = 0.0F; |
|
272 |
|
|
203 | 273 |
switch (m_pos) { |
204 | 274 |
case (LEFT): |
205 |
layout.draw(g, (float) re.getX(),
|
|
206 |
(float) (re.getY() + (ht * (i + 1)))); //- (ht / 2))));
|
|
207 |
|
|
275 |
textLayout.draw(g, (float) rec.getX(),
|
|
276 |
(float) (raux.getY() + (ht * (i +1))));
|
|
277 |
|
|
208 | 278 |
break; |
209 | 279 |
|
210 | 280 |
case (CENTER): |
211 |
|
|
212 |
float pos1 = (float) ((re.width - |
|
213 |
((l * scale) / 2.2)) / 2); |
|
214 |
layout.draw(g, (float) re.getX() + pos1, |
|
215 |
(float) (re.getY() + (ht * (i + 1)))); //- (ht / 2)))); |
|
216 |
|
|
281 |
float pos1 = (float) ((rec.width - |
|
282 |
((l * scaledFontSize) / 2.2)) / 2); |
|
283 |
textLayout.draw(g, (float) rec.getX() + pos1, |
|
284 |
(float) (raux.getY() + (ht * (i + 1)))); |
|
285 |
|
|
217 | 286 |
break; |
218 | 287 |
|
219 | 288 |
case (RIGTH): |
220 |
|
|
221 |
float pos2 = (float) ((re.width - |
|
222 |
((l * scale) / 2.2))); |
|
223 |
layout.draw(g, (float) re.getX() + pos2, |
|
224 |
(float) (re.getY() + (ht * (i + 1)))); //- (ht / 2)))); |
|
225 |
|
|
226 |
break; |
|
289 |
float pos2 = (float) ((raux.width - |
|
290 |
((l * scaledFontSize) / 2.2))); |
|
291 |
textLayout.draw(g, (float) raux.getX() + pos2, |
|
292 |
(float) (raux.getY() + (ht * (i + 1)))); //- (ht / 2)))); |
|
293 |
break; |
|
227 | 294 |
} |
228 | 295 |
|
229 | 296 |
g.rotate(Math.toRadians(-m_rotation), |
230 |
re.x + (re.width / 2), re.y + (re.height / 2)); |
|
297 |
raux.x + (raux.width / 2), raux.y + (raux.height / 2)); |
|
298 |
|
|
231 | 299 |
} |
232 | 300 |
} |
233 | 301 |
} |
... | ... | |
349 | 417 |
if (xml.contains("textColor")){//TODO Incluido en la versi?n 0.3 en posteriores versiones no hace falta esta comprobaci?n. |
350 | 418 |
this.textColor = StringUtilities.string2Color(xml.getStringProperty("textColor")); |
351 | 419 |
} |
420 |
|
|
421 |
//jaume |
|
422 |
if (xml.contains("cellPadding")) |
|
423 |
this.cellPadding = xml.getIntProperty("cellPadding"); |
|
424 |
if (xml.contains("fontSize")) |
|
425 |
this.fontSize = xml.getIntProperty("fontSize"); |
|
426 |
if (xml.contains("fixedFontSize")) |
|
427 |
this.fixedFontSize = xml.getBooleanProperty("fixedFontSize"); |
|
428 |
if (xml.contains("surrounded")) |
|
429 |
this.surrounded = xml.getBooleanProperty("surrounded"); |
|
352 | 430 |
} |
353 | 431 |
|
354 | 432 |
/** |
... | ... | |
373 | 451 |
this.m_rotation = xml.getDoubleProperty("m_rotation"); |
374 | 452 |
this.m_f = new Font(xml.getStringProperty("fontName"), |
375 | 453 |
xml.getIntProperty("fontStyle"), 9); |
454 |
this.cellPadding = xml.getIntProperty("cellPadding"); |
|
455 |
this.fontSize = xml.getIntProperty("fontSize"); |
|
456 |
this.fixedFontSize = xml.getBooleanProperty("fixedFontSize"); |
|
457 |
this.surrounded = xml.getBooleanProperty("surrounded"); |
|
376 | 458 |
if (xml.contains("textColor")){//TODO Incluido en la versi?n 0.3 en posteriores versiones no hace falta esta comprobaci?n. |
377 | 459 |
this.textColor = StringUtilities.string2Color(xml.getStringProperty("textColor")); |
378 | 460 |
} |
461 |
|
|
379 | 462 |
} |
380 | 463 |
|
381 | 464 |
/** |
... | ... | |
384 | 467 |
public String getNameFFrame() { |
385 | 468 |
return PluginServices.getText(this, "texto") + num; |
386 | 469 |
} |
470 |
|
|
471 |
/** |
|
472 |
* Sets FFrameText to draw an involving rectangle |
|
473 |
* @param b |
|
474 |
*/ |
|
475 |
public void setSurrounded(boolean b) { |
|
476 |
surrounded = b; |
|
477 |
} |
|
478 |
|
|
479 |
/** |
|
480 |
* True if the FFrameText is set to draw an involving rectangle, or false |
|
481 |
* if not. |
|
482 |
* @return boolean |
|
483 |
*/ |
|
484 |
public boolean isSurrounded(){ |
|
485 |
return surrounded; |
|
486 |
} |
|
487 |
/** |
|
488 |
* Sets the gap between the involving rectangle and the text |
|
489 |
* @param i |
|
490 |
*/ |
|
491 |
public void setCellPadding(int i) { |
|
492 |
cellPadding = i; |
|
493 |
} |
|
494 |
|
|
495 |
public void setLayout(Layout l){ |
|
496 |
layout = l; |
|
497 |
} |
|
387 | 498 |
} |
Also available in: Unified diff