Revision 12131 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/fmap/edition/Annotation_EditableAdapter.java
Annotation_EditableAdapter.java | ||
---|---|---|
51 | 51 |
import com.hardcode.driverManager.DriverLoadException; |
52 | 52 |
import com.hardcode.gdbms.engine.values.NumericValue; |
53 | 53 |
import com.hardcode.gdbms.engine.values.Value; |
54 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
55 |
import com.iver.andami.PluginServices; |
|
54 | 56 |
import com.iver.cit.gvsig.fmap.DriverException; |
55 | 57 |
import com.iver.cit.gvsig.fmap.DriverIOExceptionType; |
56 | 58 |
import com.iver.cit.gvsig.fmap.DriverNotLoadedExceptionType; |
... | ... | |
62 | 64 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
63 | 65 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
64 | 66 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
67 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
|
65 | 68 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
66 | 69 |
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer; |
67 | 70 |
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping; |
71 |
import com.iver.cit.gvsig.fmap.operation.strategies.Annotation_Strategy; |
|
72 |
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend; |
|
68 | 73 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
74 |
import com.iver.cit.gvsig.project.documents.view.legend.preferences.Annotation_Preferences; |
|
75 |
import com.iver.utiles.StringUtilities; |
|
76 |
import com.iver.utiles.XMLEntity; |
|
69 | 77 |
import com.vividsolutions.jts.geom.Envelope; |
70 | 78 |
|
71 | 79 |
|
... | ... | |
75 | 83 |
* @author Vicente Caballero Navarro |
76 | 84 |
*/ |
77 | 85 |
public class Annotation_EditableAdapter extends VectorialEditableAdapter { |
78 |
private ArrayList labels; |
|
86 |
private static String DEFAULT_ANNOTATION_TEXT = "default_annotation_text"; |
|
87 |
|
|
88 |
private static String DEFAULT_ANNOTATION_TYPEFONT = "default_annotation_typefont"; |
|
89 |
|
|
90 |
private static String DEFAULT_ANNOTATION_ROTATE = "default_annotation_rotate"; |
|
91 |
|
|
92 |
private static String DEFAULT_ANNOTATION_STYLEFONT = "default_annotation_stylefont"; |
|
93 |
|
|
94 |
private static String DEFAULT_ANNOTATION_HEIGHT = "default_annotation_height"; |
|
95 |
|
|
96 |
private static String DEFAULT_ANNOTATION_COLOR = "default_annotation_color"; |
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
private ArrayList labels; |
|
79 | 101 |
private Annotation_Mapping mapping; |
80 | 102 |
private Legend legend; |
81 | 103 |
|
... | ... | |
84 | 106 |
private LabelExpansion labelExpansion = new LabelExpansion(); |
85 | 107 |
private boolean isToSave = false; |
86 | 108 |
|
87 |
// public int doAddRow(IRow feat, int sourceType) throws DriverIOException, |
|
88 |
// IOException { |
|
89 |
// boolean cancel = fireBeforeRowAdded(sourceType); |
|
90 |
// if (cancel) |
|
91 |
// return -1; |
|
92 |
// Value[] values=feat.getAttributes(); |
|
93 |
// values[mapping.getColumnText()]=ValueFactory.createValue("New"); |
|
94 |
// FLabel label=createLabel(feat); |
|
95 |
// //Rectangle2D r=((DefaultFeature)feat).getGeometry().getBounds2D(); |
|
96 |
// //r.setRect(r.getX()-r.getWidth()*4,r.getY()-r.getHeight()*4,r.getWidth()*10,r.getHeight()*4); |
|
97 |
// //label.setBoundBox(r); |
|
98 |
// Annotation_Strategy strategy = |
|
99 |
// (Annotation_Strategy)lyrAnnotation.getStrategy(); |
|
100 |
// Rectangle2D |
|
101 |
// r=strategy.getBoundBox(label.getOrig(),(float)label.getHeight(),label.getJustification(),label.getString()); |
|
102 |
// label.setBoundBox(r); |
|
103 |
// IGeometry geom=getGeometry(label.getBoundBox()); |
|
104 |
// feat=new DefaultFeature(geom,values,feat.getID()); |
|
105 |
// |
|
106 |
// ///lyrAnnotation.deleteSpatialIndex(); |
|
107 |
// |
|
108 |
// int calculatedIndex = -1; |
|
109 |
// calculatedIndex = (int) getRowCount()+delRows.cardinality() ; |
|
110 |
// |
|
111 |
// int pos = expansionFile.addRow(feat, IRowEdited.STATUS_ADDED, |
|
112 |
// actualIndexFields); |
|
113 |
// labelExpansion.addLabel(label); |
|
114 |
// relations.put(new Integer(calculatedIndex), new Integer(pos)); |
|
115 |
// numAdd++; |
|
116 |
// |
|
117 |
// index.insert(new Envelope(r.getX(), r.getX() + r.getWidth(), r.getY(), |
|
118 |
// r.getY() + r.getHeight()), new Integer(calculatedIndex)); |
|
119 |
// //lyrAnnotation.getFMap().invalidate(); |
|
120 |
// fireAfterRowAdded(feat,calculatedIndex, sourceType); |
|
121 |
// return calculatedIndex; |
|
122 |
// } |
|
109 |
public int doAddRow(IRow feat, int sourceType) throws DriverIOException, |
|
110 |
IOException { |
|
111 |
int position = super.doAddRow(feat, sourceType); |
|
112 |
PluginServices ps = PluginServices |
|
113 |
.getPluginServices("com.iver.cit.gvsig.annotation"); |
|
114 |
XMLEntity xml = ps.getPersistentXML(); |
|
115 |
String newFID=getNewFID(); |
|
116 |
boolean cancel = fireBeforeRowAdded(sourceType,newFID); |
|
117 |
if (cancel) |
|
118 |
return -1; |
|
119 |
Value[] values = feat.getAttributes(); |
|
120 |
String stringColor = xml.getStringProperty(DEFAULT_ANNOTATION_COLOR); |
|
121 |
String text = xml.getStringProperty(DEFAULT_ANNOTATION_TEXT); |
|
122 |
String type = xml.getStringProperty(DEFAULT_ANNOTATION_TYPEFONT); |
|
123 |
int style = xml.getIntProperty(DEFAULT_ANNOTATION_STYLEFONT); |
|
124 |
int height = xml.getIntProperty(DEFAULT_ANNOTATION_HEIGHT); |
|
125 |
int rotate = xml.getIntProperty(DEFAULT_ANNOTATION_ROTATE); |
|
126 |
values[mapping.getColumnText()] = ValueFactory.createValue(text); |
|
127 |
values[mapping.getColumnTypeFont()] = ValueFactory.createValue(type); |
|
128 |
values[mapping.getColumnStyleFont()] = ValueFactory.createValue(style); |
|
129 |
values[mapping.getColumnHeight()] = ValueFactory.createValue(height); |
|
130 |
values[mapping.getColumnRotate()] = ValueFactory.createValue(rotate); |
|
131 |
int rgb = StringUtilities.string2Color(stringColor).getRGB(); |
|
132 |
values[mapping.getColumnColor()] = ValueFactory.createValue(rgb); |
|
133 |
IGeometry geom; |
|
134 |
// try { |
|
135 |
geom = lyrAnnotation.getTextWrappingGeometry(height, text, rotate, |
|
136 |
position); |
|
137 |
// } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
138 |
// throw new DriverIOException(e); |
|
139 |
// } |
|
140 |
feat = new DefaultFeature(geom, values, feat.getID()); |
|
141 |
return position; |
|
142 |
} |
|
123 | 143 |
// public int doModifyRow(int calculatedIndex, IRow feat,int sourceType) |
124 | 144 |
// throws IOException, DriverIOException { |
125 | 145 |
// boolean cancel = fireBeforeModifyRow(feat,calculatedIndex, sourceType); |
... | ... | |
352 | 372 |
this.lyrAnnotation = lyrAnnotation; |
353 | 373 |
} |
354 | 374 |
|
355 |
/** |
|
356 |
* DOCUMENT ME! |
|
357 |
* |
|
358 |
* @param row DOCUMENT ME! |
|
359 |
* |
|
360 |
* @return DOCUMENT ME! |
|
361 |
*/ |
|
362 |
public FLabel createLabel(IRow row) { |
|
363 |
// FSymbol symbol; |
|
364 |
// // El mapping[0] es el text |
|
365 |
// int fieldId = mapping.getColumnText(); |
|
366 |
// // El mapping[1] es el ?ngulo |
|
367 |
// int idFieldRotationText = mapping.getColumnRotate(); |
|
368 |
// // El mapping[2] es el color |
|
369 |
// int idFieldColorText = mapping.getColumnColor(); |
|
370 |
// // El mapping[3] es el alto |
|
371 |
// int idFieldHeightText = mapping.getColumnHeight(); |
|
372 |
// // El mapping[4] es el tipo de fuente |
|
373 |
// int idFieldTypeFontText = mapping.getColumnTypeFont(); |
|
374 |
// // El mapping[5] es el estilo de fuente |
|
375 |
// int idFieldStyleFontText = mapping.getColumnStyleFont(); |
|
376 |
// |
|
377 |
// IGeometry geom = ((IFeature) row).getGeometry(); |
|
378 |
// String t = new String(); |
|
379 |
// Value val = row.getAttribute(fieldId); |
|
380 |
// t = val.toString(); |
|
381 |
// if (idFieldColorText != -1) { |
|
382 |
// Value value=row.getAttribute(idFieldColorText); |
|
383 |
// if (!(value instanceof NullValue)){ |
|
384 |
// DoubleValue valColor = (DoubleValue) value; |
|
385 |
// t = t.concat(valColor.toString()); |
|
386 |
// } |
|
387 |
// } |
|
388 |
// if (idFieldTypeFontText != -1) { |
|
389 |
// Value value=row.getAttribute(idFieldTypeFontText); |
|
390 |
// if (!(value instanceof NullValue)){ |
|
391 |
// StringValue valTypeFont = (StringValue) value; |
|
392 |
// t = t.concat(valTypeFont.toString()); |
|
393 |
// } |
|
394 |
// } |
|
395 |
// if (idFieldStyleFontText != -1) { |
|
396 |
// Value value=row.getAttribute(idFieldStyleFontText); |
|
397 |
// if (!(value instanceof NullValue)){ |
|
398 |
// IntValue valStyleFont = (IntValue) value; |
|
399 |
// t = t.concat(valStyleFont.toString()); |
|
400 |
// } |
|
401 |
// } |
|
402 |
// |
|
403 |
// Value total = ValueFactory.createValue(t); |
|
404 |
// |
|
405 |
// FLabel[] lbls = geom.createLabels(0, true); |
|
406 |
// double rotat = 0; |
|
407 |
// FSymbol sym = (FSymbol) legend.getDefaultSymbol(); |
|
408 |
// for (int j = 0; j < lbls.length; j++) { |
|
409 |
// if (lbls[j] != null) { |
|
410 |
// lbls[j].setString(val.toString()); |
|
411 |
// if (idFieldRotationText != -1) { |
|
412 |
// Value value=row.getAttribute(idFieldRotationText); |
|
413 |
// if (value instanceof NullValue){ |
|
414 |
// rotat = sym.getRotation(); |
|
415 |
// }else{ |
|
416 |
// NumericValue rotation = (NumericValue) value; |
|
417 |
// rotat = rotation.doubleValue(); |
|
418 |
// } |
|
419 |
// } else { |
|
420 |
// rotat = sym.getRotation(); |
|
421 |
// } |
|
422 |
// lbls[j].setRotation(rotat); |
|
423 |
// |
|
424 |
// float height; |
|
425 |
// if (idFieldHeightText != -1) { |
|
426 |
// Value value=row.getAttribute(idFieldHeightText); |
|
427 |
// if (value instanceof NullValue){ |
|
428 |
// height = sym.getFontSize(); |
|
429 |
// lbls[j].setHeight(height); |
|
430 |
// }else{ |
|
431 |
// NumericValue h = (NumericValue) value; |
|
432 |
// height = h.floatValue(); |
|
433 |
// lbls[j].setHeight(height); |
|
434 |
// } |
|
435 |
// |
|
436 |
// } else { |
|
437 |
// height = sym.getFontSize(); |
|
438 |
// lbls[j].setHeight(height); |
|
439 |
// } |
|
440 |
// Annotation_Legend vuvl = (Annotation_Legend) legend; |
|
441 |
// if (vuvl.getSymbolByValue(total) == null) { |
|
442 |
// Color color; |
|
443 |
// if (idFieldColorText != -1) { |
|
444 |
// DoubleValue c = (DoubleValue) row |
|
445 |
// .getAttribute(idFieldColorText); |
|
446 |
// color = new Color((int) c.getValue()); |
|
447 |
// } else { |
|
448 |
// color = sym.getFontColor(); |
|
449 |
// } |
|
450 |
// String typeFont; |
|
451 |
// if (idFieldTypeFontText != -1) { |
|
452 |
// StringValue tf = (StringValue) row |
|
453 |
// .getAttribute(idFieldTypeFontText); |
|
454 |
// typeFont = tf.getValue(); |
|
455 |
// } else { |
|
456 |
// typeFont = sym.getFont() |
|
457 |
// .getFontName(); |
|
458 |
// } |
|
459 |
// int style; |
|
460 |
// if (idFieldStyleFontText != -1) { |
|
461 |
// IntValue sf = (IntValue) row |
|
462 |
// .getAttribute(idFieldStyleFontText); |
|
463 |
// style = sf.getValue(); |
|
464 |
// } else { |
|
465 |
// style = sym.getFont().getStyle(); |
|
466 |
// } |
|
467 |
// symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT); |
|
468 |
// symbol.setFontSizeInPixels(isInPixels); |
|
469 |
// symbol.setFont(new Font(typeFont, style, (int) height)); |
|
470 |
// symbol.setDescription(lbls[j].getString()); |
|
471 |
// symbol.setFontColor(color); |
|
472 |
// vuvl.addSymbol(total, symbol); |
|
473 |
// } |
|
474 |
// |
|
475 |
// } |
|
476 |
// return lbls[0]; |
|
477 |
// } |
|
478 |
return null; |
|
479 |
} |
|
375 |
// /** |
|
376 |
// * DOCUMENT ME! |
|
377 |
// * |
|
378 |
// * @param row DOCUMENT ME! |
|
379 |
// * |
|
380 |
// * @return DOCUMENT ME! |
|
381 |
// */ |
|
382 |
// public FLabel createLabel(IRow row) { |
|
383 |
// FSymbol symbol; |
|
384 |
// // El mapping[0] es el text |
|
385 |
// int fieldId = mapping.getColumnText(); |
|
386 |
// // El mapping[1] es el ?ngulo |
|
387 |
// int idFieldRotationText = mapping.getColumnRotate(); |
|
388 |
// // El mapping[2] es el color |
|
389 |
// int idFieldColorText = mapping.getColumnColor(); |
|
390 |
// // El mapping[3] es el alto |
|
391 |
// int idFieldHeightText = mapping.getColumnHeight(); |
|
392 |
// // El mapping[4] es el tipo de fuente |
|
393 |
// int idFieldTypeFontText = mapping.getColumnTypeFont(); |
|
394 |
// // El mapping[5] es el estilo de fuente |
|
395 |
// int idFieldStyleFontText = mapping.getColumnStyleFont(); |
|
396 |
// |
|
397 |
// IGeometry geom = ((IFeature) row).getGeometry(); |
|
398 |
// FLabel. |
|
399 |
// |
|
400 |
// String t = new String(); |
|
401 |
// Value val = row.getAttribute(fieldId); |
|
402 |
// t = val.toString(); |
|
403 |
// if (idFieldColorText != -1) { |
|
404 |
// Value value=row.getAttribute(idFieldColorText); |
|
405 |
// if (!(value instanceof NullValue)){ |
|
406 |
// DoubleValue valColor = (DoubleValue) value; |
|
407 |
// t = t.concat(valColor.toString()); |
|
408 |
// } |
|
409 |
// } |
|
410 |
// if (idFieldTypeFontText != -1) { |
|
411 |
// Value value=row.getAttribute(idFieldTypeFontText); |
|
412 |
// if (!(value instanceof NullValue)){ |
|
413 |
// StringValue valTypeFont = (StringValue) value; |
|
414 |
// t = t.concat(valTypeFont.toString()); |
|
415 |
// } |
|
416 |
// } |
|
417 |
// if (idFieldStyleFontText != -1) { |
|
418 |
// Value value=row.getAttribute(idFieldStyleFontText); |
|
419 |
// if (!(value instanceof NullValue)){ |
|
420 |
// IntValue valStyleFont = (IntValue) value; |
|
421 |
// t = t.concat(valStyleFont.toString()); |
|
422 |
// } |
|
423 |
// } |
|
424 |
// |
|
425 |
// Value total = ValueFactory.createValue(t); |
|
426 |
// |
|
427 |
// FLabel[] lbls = geom.createLabels(0, true); |
|
428 |
// double rotat = 0; |
|
429 |
// FSymbol sym = (FSymbol) legend.getDefaultSymbol(); |
|
430 |
// for (int j = 0; j < lbls.length; j++) { |
|
431 |
// if (lbls[j] != null) { |
|
432 |
// lbls[j].setString(val.toString()); |
|
433 |
// if (idFieldRotationText != -1) { |
|
434 |
// Value value=row.getAttribute(idFieldRotationText); |
|
435 |
// if (value instanceof NullValue){ |
|
436 |
// rotat = sym.getRotation(); |
|
437 |
// }else{ |
|
438 |
// NumericValue rotation = (NumericValue) value; |
|
439 |
// rotat = rotation.doubleValue(); |
|
440 |
// } |
|
441 |
// } else { |
|
442 |
// rotat = sym.getRotation(); |
|
443 |
// } |
|
444 |
// lbls[j].setRotation(rotat); |
|
445 |
// |
|
446 |
// float height; |
|
447 |
// if (idFieldHeightText != -1) { |
|
448 |
// Value value=row.getAttribute(idFieldHeightText); |
|
449 |
// if (value instanceof NullValue){ |
|
450 |
// height = sym.getFontSize(); |
|
451 |
// lbls[j].setHeight(height); |
|
452 |
// }else{ |
|
453 |
// NumericValue h = (NumericValue) value; |
|
454 |
// height = h.floatValue(); |
|
455 |
// lbls[j].setHeight(height); |
|
456 |
// } |
|
457 |
// |
|
458 |
// } else { |
|
459 |
// height = sym.getFontSize(); |
|
460 |
// lbls[j].setHeight(height); |
|
461 |
// } |
|
462 |
// Annotation_Legend vuvl = (Annotation_Legend) legend; |
|
463 |
// if (vuvl.getSymbolByValue(total) == null) { |
|
464 |
// Color color; |
|
465 |
// if (idFieldColorText != -1) { |
|
466 |
// DoubleValue c = (DoubleValue) row |
|
467 |
// .getAttribute(idFieldColorText); |
|
468 |
// color = new Color((int) c.getValue()); |
|
469 |
// } else { |
|
470 |
// color = sym.getFontColor(); |
|
471 |
// } |
|
472 |
// String typeFont; |
|
473 |
// if (idFieldTypeFontText != -1) { |
|
474 |
// StringValue tf = (StringValue) row |
|
475 |
// .getAttribute(idFieldTypeFontText); |
|
476 |
// typeFont = tf.getValue(); |
|
477 |
// } else { |
|
478 |
// typeFont = sym.getFont() |
|
479 |
// .getFontName(); |
|
480 |
// } |
|
481 |
// int style; |
|
482 |
// if (idFieldStyleFontText != -1) { |
|
483 |
// IntValue sf = (IntValue) row |
|
484 |
// .getAttribute(idFieldStyleFontText); |
|
485 |
// style = sf.getValue(); |
|
486 |
// } else { |
|
487 |
// style = sym.getFont().getStyle(); |
|
488 |
// } |
|
489 |
// symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT); |
|
490 |
// symbol.setFontSizeInPixels(isInPixels); |
|
491 |
// symbol.setFont(new Font(typeFont, style, (int) height)); |
|
492 |
// symbol.setDescription(lbls[j].getString()); |
|
493 |
// symbol.setFontColor(color); |
|
494 |
// vuvl.addSymbol(total, symbol); |
|
495 |
// } |
|
496 |
// |
|
497 |
// } |
|
498 |
// return lbls[0]; |
|
499 |
// } |
|
500 |
// return null; |
|
501 |
// } |
|
480 | 502 |
|
481 | 503 |
// public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws |
482 | 504 |
// DriverException { |
... | ... | |
738 | 760 |
// return geom; |
739 | 761 |
// |
740 | 762 |
// } |
763 |
// /** |
|
764 |
// * Is synchronized to allow thread safe access to features stored |
|
765 |
// * in files. |
|
766 |
// * |
|
767 |
// * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int) |
|
768 |
// */ |
|
769 |
// public synchronized IGeometry getShape(int index) throws DriverIOException { |
|
770 |
// IGeometry geom= super.getShape(index); |
|
771 |
// UtilFunctions.moveGeom(geom, 0, geom.getBounds2D().getHeight()); |
|
772 |
// return geom; |
|
773 |
// } |
|
741 | 774 |
} |
Also available in: Unified diff