Revision 18621 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/SymbologyFactory.java
SymbologyFactory.java | ||
---|---|---|
104 | 104 |
*/ |
105 | 105 |
package com.iver.cit.gvsig.fmap.core; |
106 | 106 |
|
107 |
import java.awt.BasicStroke; |
|
107 | 108 |
import java.awt.Color; |
108 | 109 |
import java.awt.Font; |
110 |
import java.awt.Graphics; |
|
111 |
import java.awt.Graphics2D; |
|
112 |
import java.awt.Rectangle; |
|
113 |
import java.awt.geom.AffineTransform; |
|
109 | 114 |
import java.io.File; |
110 |
import java.io.IOException; |
|
111 | 115 |
|
116 |
import javax.print.attribute.PrintRequestAttributeSet; |
|
117 |
import javax.swing.JFrame; |
|
118 |
import javax.swing.JPanel; |
|
119 |
|
|
112 | 120 |
import org.apache.log4j.Logger; |
113 | 121 |
|
122 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
114 | 123 |
import com.iver.cit.gvsig.fmap.Messages; |
124 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
115 | 125 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
116 |
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle; |
|
117 |
import com.iver.cit.gvsig.fmap.core.symbols.AbstractSymbol; |
|
118 | 126 |
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
119 | 127 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
120 | 128 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
121 | 129 |
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol; |
122 | 130 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
123 | 131 |
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol; |
124 |
import com.iver.cit.gvsig.fmap.core.symbols.LineFillSymbol; |
|
125 | 132 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerFillSymbol; |
126 | 133 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerLineSymbol; |
127 | 134 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerMarkerSymbol; |
128 | 135 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol; |
129 |
import com.iver.cit.gvsig.fmap.core.symbols.PictureMarkerSymbol; |
|
130 | 136 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
131 | 137 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
132 | 138 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol; |
133 | 139 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol; |
134 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
|
|
140 |
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException;
|
|
135 | 141 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
136 | 142 |
import com.iver.utiles.IPersistence; |
137 | 143 |
import com.iver.utiles.NotExistInXMLEntity; |
138 | 144 |
import com.iver.utiles.XMLEntity; |
145 |
import com.iver.utiles.swing.threads.Cancellable; |
|
139 | 146 |
|
140 | 147 |
/** |
141 | 148 |
* Factory for obtaining symbology of any kind from several sources like. |
... | ... | |
149 | 156 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
150 | 157 |
*/ |
151 | 158 |
public class SymbologyFactory { |
152 |
public static int DefaultSymbolUnit = -1; // pixel |
|
153 |
public static int DefaultSymbolReferenceSystem = CartographicSupport.WORLD; |
|
154 |
public static Color DefaultSymbolColor = Color.DARK_GRAY; |
|
155 |
public static Color DefaultFillSymbolColor = new Color(60, 235, 235); |
|
156 |
public static Font DefaultTextFont = new Font("SansSerif", Font.PLAIN, 9); |
|
159 |
|
|
160 |
/** |
|
161 |
* This Constants are only used in SymbologyPage (preferences page for symbology), |
|
162 |
* do not use in other context. |
|
163 |
*/ |
|
164 |
public static final Color FactoryDefaultSymbolColor = Color.GRAY; |
|
165 |
public static final Color FactoryDefaultFillSymbolColor = new Color(60, 235, 235); |
|
166 |
public static final Font FactoryDefaultTextFont = new Font("Serif", Font.PLAIN, 8); |
|
167 |
public static final String FactorySymbolLibraryPath = |
|
168 |
System.getProperty("user.home") + |
|
169 |
File.separator + |
|
170 |
"gvSIG" + |
|
171 |
File.separator + |
|
172 |
"Symbols"; |
|
173 |
|
|
174 |
|
|
175 |
public static Color DefaultSymbolColor = FactoryDefaultSymbolColor; |
|
176 |
public static Color DefaultFillSymbolColor = FactoryDefaultFillSymbolColor; |
|
177 |
public static Font DefaultTextFont = FactoryDefaultTextFont; |
|
178 |
public static String SymbolLibraryPath = FactorySymbolLibraryPath; |
|
179 |
|
|
157 | 180 |
private static Logger logger = Logger.getLogger(SymbologyFactory.class.getName()); |
158 |
// private static WarningSymbol warningSymbol;
|
|
181 |
private static WarningSymbol warningSymbol; |
|
159 | 182 |
|
160 | 183 |
/** |
161 | 184 |
* Factory that allows to create <b>ISymbol</b>'s from an ISymbol xml |
... | ... | |
269 | 292 |
* @return IMultiLayerSymbol |
270 | 293 |
*/ |
271 | 294 |
public static IMultiLayerSymbol createEmptyMultiLayerSymbol(int shapeType) { |
272 |
|
|
273 |
IMultiLayerSymbol sym = null; |
|
274 |
|
|
275 |
switch (shapeType % FShape.Z) { |
|
295 |
IMultiLayerSymbol mSym; |
|
296 |
switch (shapeType) { |
|
276 | 297 |
case FShape.POINT: |
277 |
|
|
278 |
sym = new MultiLayerMarkerSymbol(); |
|
298 |
mSym = new MultiLayerMarkerSymbol(); |
|
279 | 299 |
break; |
280 |
|
|
281 | 300 |
case FShape.LINE: |
282 |
|
|
283 |
sym = new MultiLayerLineSymbol(); |
|
301 |
mSym = new MultiLayerLineSymbol(); |
|
284 | 302 |
break; |
285 |
|
|
286 | 303 |
case FShape.POLYGON: |
287 |
|
|
288 |
sym = new MultiLayerFillSymbol(); |
|
304 |
mSym =new MultiLayerFillSymbol(); |
|
289 | 305 |
break; |
290 |
|
|
291 | 306 |
default: |
292 | 307 |
throw new Error("Shape type not yet supported for multilayer symbols"); |
293 | 308 |
} |
294 |
|
|
295 | 309 |
|
296 |
if (sym instanceof CartographicSupport) {
|
|
297 |
CartographicSupport csSym = (CartographicSupport) sym;
|
|
298 |
csSym.setUnit(DefaultSymbolUnit);
|
|
299 |
csSym.setReferenceSystem(DefaultSymbolReferenceSystem);
|
|
310 |
if (mSym instanceof CartographicSupport) {
|
|
311 |
CartographicSupport cs = (CartographicSupport) mSym;
|
|
312 |
cs.setUnit(CartographicSupportToolkit.DefaultMeasureUnit);
|
|
313 |
cs.setReferenceSystem(CartographicSupportToolkit.DefaultReferenceSystem);
|
|
300 | 314 |
} |
301 |
|
|
302 |
return sym; |
|
303 |
|
|
315 |
return mSym; |
|
304 | 316 |
} |
305 | 317 |
|
306 | 318 |
/** |
... | ... | |
311 | 323 |
SimpleMarkerSymbol sms = new SimpleMarkerSymbol(); |
312 | 324 |
sms.setColor(DefaultSymbolColor); |
313 | 325 |
sms.setSize(4); |
326 |
toDefaultCartographicProperties(sms); |
|
314 | 327 |
return sms; |
315 | 328 |
} |
316 | 329 |
|
317 | 330 |
/** |
318 |
* Returns a new instance of an <b>ILineSymbol</b>. |
|
331 |
* Returns a new instance of an <b>ILineSymbol</b>. A black line.
|
|
319 | 332 |
* @return ILineSymbol, the default symbol for lines. |
320 | 333 |
*/ |
321 | 334 |
public static ILineSymbol createDefaultLineSymbol() { |
322 | 335 |
SimpleLineSymbol sls = new SimpleLineSymbol(); |
323 | 336 |
sls.setLineColor(DefaultSymbolColor); |
324 | 337 |
sls.setLineWidth(1); |
338 |
toDefaultCartographicProperties(sls); |
|
325 | 339 |
return sls; |
326 | 340 |
} |
327 |
// |
|
328 |
// private static void toDefaultCartographicProperties(CartographicSupport cs) {
|
|
329 |
// cs.setUnit(CartographicSupportToolkit.DefaultMeasureUnit);
|
|
330 |
// cs.setReferenceSystem(CartographicSupportToolkit.DefaultReferenceSystem);
|
|
331 |
// }
|
|
341 |
|
|
342 |
private static void toDefaultCartographicProperties(CartographicSupport cs) { |
|
343 |
cs.setUnit(CartographicSupportToolkit.DefaultMeasureUnit); |
|
344 |
cs.setReferenceSystem(CartographicSupportToolkit.DefaultReferenceSystem); |
|
345 |
} |
|
332 | 346 |
|
333 | 347 |
/** |
334 | 348 |
* Returns a new instance of an <b>IFillSymbol</b>. Black outline, |
... | ... | |
342 | 356 |
// Default symbol for polygons |
343 | 357 |
sfs.setOutline(createDefaultLineSymbol()); |
344 | 358 |
sfs.setFillColor(DefaultFillSymbolColor); // transparent fill |
345 |
// toDefaultCartographicProperties(sfs);
|
|
359 |
toDefaultCartographicProperties(sfs); |
|
346 | 360 |
return sfs; |
347 | 361 |
} |
348 | 362 |
|
... | ... | |
355 | 369 |
|
356 | 370 |
sts.setFont(DefaultTextFont); |
357 | 371 |
sts.setTextColor(DefaultSymbolColor); |
358 |
// toDefaultCartographicProperties(sts);
|
|
372 |
toDefaultCartographicProperties(sts); |
|
359 | 373 |
|
360 | 374 |
return sts; |
361 | 375 |
} |
... | ... | |
368 | 382 |
* @return ISymbol, the default symbol for the shape type defined by <b>shapeType</b> |
369 | 383 |
*/ |
370 | 384 |
public static ISymbol createDefaultSymbolByShapeType(int shapeType) { |
371 |
switch (shapeType % FShape.Z) {
|
|
385 |
switch (shapeType) { |
|
372 | 386 |
case FShape.POINT: |
373 | 387 |
return createDefaultMarkerSymbol(); |
374 | 388 |
case FShape.LINE: |
... | ... | |
419 | 433 |
return sym; |
420 | 434 |
} |
421 | 435 |
|
422 |
public static ISymbol deriveFSymbol(FSymbol fSymbol) { |
|
423 |
ISymbol derivedSymbol; |
|
424 |
|
|
425 |
int symbolType = fSymbol.getSymbolType(); |
|
426 |
Color color = fSymbol.getColor(); |
|
427 |
double size = fSymbol.getSize(); |
|
428 |
int unit = fSymbol.isSizeInPixels() ? -1 : 1; // only meters or pixels |
|
429 |
// were supported in |
|
430 |
// FSymbol |
|
431 |
if (symbolType == FShape.LINE) { |
|
432 |
ILineSymbol line = createDefaultLineSymbol(); |
|
433 |
line.setLineColor(color); |
|
436 |
|
|
434 | 437 |
|
435 |
SimpleLineStyle lineStyle = new SimpleLineStyle(); |
|
436 |
lineStyle.setUnit(unit); |
|
437 |
lineStyle.setStroke(fSymbol.getStroke()); |
|
438 |
lineStyle.setOffset(0); |
|
439 |
lineStyle.setReferenceSystem(CartographicSupport.WORLD); |
|
440 |
lineStyle.setLineWidth((float) size); |
|
441 |
line.setLineStyle(lineStyle); |
|
442 |
derivedSymbol = line; |
|
443 |
|
|
444 |
} else if (symbolType == FShape.POINT) { |
|
445 |
int style = fSymbol.getStyle(); |
|
446 |
IMarkerSymbol marker; |
|
447 |
if (style == FConstant.SYMBOL_STYLE_MARKER_IMAGEN) { |
|
448 |
marker = new PictureMarkerSymbol(); |
|
449 |
PictureMarkerSymbol pic = (PictureMarkerSymbol) marker; |
|
450 |
try { |
|
451 |
pic.setImage(new File(fSymbol.getIconURI().getPath())); |
|
452 |
} catch (IOException e) { |
|
453 |
// image could not be restored, |
|
454 |
// will use a regular point as symbol |
|
455 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
|
456 |
return deriveFSymbol(fSymbol); |
|
457 |
} |
|
458 |
} else { |
|
459 |
marker = new SimpleMarkerSymbol(); |
|
460 |
SimpleMarkerSymbol sms = (SimpleMarkerSymbol) marker; |
|
461 |
if (style == FConstant.SYMBOL_STYLE_MARKER_CIRCLE) { |
|
462 |
sms.setStyle(SimpleMarkerSymbol.CIRCLE_STYLE); |
|
463 |
} else if (style == FConstant.SYMBOL_STYLE_MARKER_CROSS) { |
|
464 |
sms.setStyle(SimpleMarkerSymbol.CROSS_STYLE); |
|
465 |
} else if (style == FConstant.SYMBOL_STYLE_MARKER_SQUARE) { |
|
466 |
sms.setStyle(SimpleMarkerSymbol.SQUARE_STYLE); |
|
467 |
} else if (style == FConstant.SYMBOL_STYLE_MARKER_TRIANGLE) { |
|
468 |
sms.setStyle(SimpleMarkerSymbol.TRIANGLE_STYLE); |
|
469 |
} |
|
470 |
Color outlineColor = fSymbol.getOutlineColor(); |
|
471 |
if (outlineColor != null) { |
|
472 |
sms.setOutlined(true); |
|
473 |
sms.setOutlineColor(outlineColor); |
|
474 |
} |
|
475 |
} |
|
476 |
marker.setColor(color); |
|
477 |
marker.setSize(size); |
|
478 |
marker.setRotation(fSymbol.getRotation()); |
|
479 |
derivedSymbol = marker; |
|
480 |
|
|
481 |
} else if (symbolType == FShape.POLYGON) { |
|
482 |
IFillSymbol fill; |
|
483 |
int fSymbolStyle = fSymbol.getStyle(); |
|
484 |
color = null; |
|
485 |
if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_SOLID) { |
|
486 |
fill = createDefaultFillSymbol(); |
|
487 |
color = fSymbol.getColor(); |
|
488 |
} else if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_TRANSPARENT || |
|
489 |
fSymbolStyle == FConstant.SYMBOL_STYLE_DGNSPECIAL) { |
|
490 |
fill = createDefaultFillSymbol(); |
|
491 |
} else { |
|
492 |
// lets see how to derive FSymbol with fill patterns |
|
493 |
if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_CROSS) { |
|
494 |
// the cross will be substituted by two line fill symbols |
|
495 |
// with |
|
496 |
// perpendicular line angles mixed into a multilayer symbol |
|
497 |
IMultiLayerSymbol mfs = createEmptyMultiLayerSymbol(FShape.POLYGON); |
|
498 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_VERTICAL); |
|
499 |
LineFillSymbol firstLayer = (LineFillSymbol) deriveFSymbol(fSymbol); |
|
500 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_HORIZONTAL); |
|
501 |
LineFillSymbol secondLayer = (LineFillSymbol) deriveFSymbol(fSymbol); |
|
502 |
mfs.addLayer(firstLayer); |
|
503 |
mfs.addLayer(secondLayer); |
|
504 |
fill = (IFillSymbol) mfs; |
|
505 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_CROSS); // restore |
|
506 |
// old |
|
507 |
// style |
|
508 |
// (just |
|
509 |
// in |
|
510 |
// case) |
|
511 |
} else if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL ) { |
|
512 |
// the cross will be substituted by two line fill symbols |
|
513 |
// with |
|
514 |
// perpendicular line angles mixed into a multilayer symbol |
|
515 |
IMultiLayerSymbol mfs = createEmptyMultiLayerSymbol(FShape.POLYGON); |
|
516 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL); |
|
517 |
LineFillSymbol firstLayer = (LineFillSymbol) deriveFSymbol(fSymbol); |
|
518 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL); |
|
519 |
LineFillSymbol secondLayer = (LineFillSymbol) deriveFSymbol(fSymbol); |
|
520 |
mfs.addLayer(firstLayer); |
|
521 |
mfs.addLayer(secondLayer); |
|
522 |
fill = (IFillSymbol) mfs; |
|
523 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL); // restore |
|
524 |
// old |
|
525 |
// style |
|
526 |
// (just |
|
527 |
// in |
|
528 |
// case) |
|
529 |
} else { |
|
530 |
LineFillSymbol lfs = new LineFillSymbol(); |
|
531 |
// Let's create the filling line symbol |
|
532 |
fSymbol.setSymbolType(FShape.LINE); |
|
533 |
ILineSymbol lineSymbol = (ILineSymbol) deriveFSymbol(fSymbol); |
|
534 |
SimpleLineStyle lineStyle = new SimpleLineStyle(); |
|
535 |
lineStyle.setLineWidth(1f); |
|
536 |
lineSymbol.setLineStyle(lineStyle); |
|
537 |
|
|
538 |
// restore the old value for symbol type (should be always |
|
539 |
// FShape.POLYGON) |
|
540 |
assert symbolType == FShape.POLYGON; |
|
541 |
fSymbol.setSymbolType(symbolType); |
|
542 |
double angle = 0; |
|
543 |
switch (fSymbolStyle) { |
|
544 |
case FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL: |
|
545 |
angle = 45; |
|
546 |
break; |
|
547 |
case FConstant.SYMBOL_STYLE_FILL_VERTICAL: |
|
548 |
angle = 90; |
|
549 |
break; |
|
550 |
case FConstant.SYMBOL_STYLE_FILL_HORIZONTAL: |
|
551 |
angle = 0; |
|
552 |
break; |
|
553 |
case FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL: |
|
554 |
angle = -45; |
|
555 |
break; |
|
556 |
} |
|
557 |
lfs.setSeparation(10); |
|
558 |
lfs.setAngle(angle*FConstant.DEGREE_TO_RADIANS); |
|
559 |
lfs.setLineSymbol(lineSymbol); |
|
560 |
fill = lfs; |
|
561 |
} |
|
562 |
} |
|
563 |
|
|
564 |
fill.setFillColor(color); |
|
565 |
|
|
566 |
if (fSymbol.isOutlined()) { |
|
567 |
// Let's create the outline line symbol |
|
568 |
fSymbol.setSymbolType(FShape.LINE); |
|
569 |
ILineSymbol outline = (ILineSymbol) deriveFSymbol(fSymbol); |
|
570 |
|
|
571 |
// restore the old value for symbol type (should be always |
|
572 |
// FShape.POLYGON) |
|
573 |
assert symbolType == FShape.POLYGON; |
|
574 |
fSymbol.setSymbolType(symbolType); |
|
575 |
outline.setLineColor(fSymbol.getOutlineColor()); |
|
576 |
fill.setOutline(outline); |
|
577 |
} |
|
578 |
derivedSymbol = fill; |
|
579 |
} else if (symbolType == FShape.MULTI) { |
|
580 |
fSymbol.setSymbolType(FShape.LINE); |
|
581 |
ILineSymbol line = (ILineSymbol) deriveFSymbol(fSymbol); |
|
582 |
fSymbol.setSymbolType(FShape.POINT); |
|
583 |
IMarkerSymbol marker = (IMarkerSymbol) deriveFSymbol(fSymbol); |
|
584 |
fSymbol.setSymbolType(FShape.POLYGON); |
|
585 |
IFillSymbol fill = (IFillSymbol) deriveFSymbol(fSymbol); |
|
586 |
assert symbolType == FShape.MULTI; |
|
587 |
fSymbol.setSymbolType(symbolType); |
|
588 |
MultiShapeSymbol multiShapeSymbol = new MultiShapeSymbol(); |
|
589 |
multiShapeSymbol.setMarkerSymbol(marker); |
|
590 |
multiShapeSymbol.setLineSymbol(line); |
|
591 |
multiShapeSymbol.setFillSymbol(fill); |
|
592 |
|
|
593 |
derivedSymbol = multiShapeSymbol; |
|
594 |
} else if (symbolType == FShape.TEXT) { |
|
595 |
ITextSymbol textSym = createDefaultTextSymbol(); |
|
596 |
textSym.setTextColor(color); |
|
597 |
derivedSymbol = textSym; |
|
598 |
} else { |
|
599 |
throw new Error("FSymbol of type "+symbolType+" cannot be imported yet!"); |
|
600 |
} |
|
601 |
|
|
602 |
// establish the general description; |
|
603 |
if (derivedSymbol instanceof AbstractSymbol) { |
|
604 |
AbstractSymbol symbol = (AbstractSymbol) derivedSymbol; |
|
605 |
symbol.setIsShapeVisible(true); |
|
606 |
symbol.setDescription(fSymbol.getDescription()); |
|
607 |
} |
|
608 |
|
|
609 |
|
|
610 |
|
|
611 |
if (derivedSymbol instanceof CartographicSupport) { |
|
612 |
CartographicSupport cs = (CartographicSupport) derivedSymbol; |
|
613 |
// the only options allowed by the old FSymbol class |
|
614 |
cs.setUnit(unit); |
|
615 |
cs.setReferenceSystem(CartographicSupport.WORLD); |
|
616 |
} |
|
617 |
|
|
618 |
return derivedSymbol; |
|
619 |
} |
|
620 |
|
|
621 |
/* public static ISymbol getWarningSymbol(String message, String symbolDesc, int symbolDrawExceptionType) { |
|
438 |
public static ISymbol getWarningSymbol(String message, String symbolDesc, int symbolDrawExceptionType) { |
|
622 | 439 |
if (warningSymbol == null) { |
623 | 440 |
warningSymbol = new WarningSymbol(); |
624 | 441 |
} |
... | ... | |
724 | 541 |
} |
725 | 542 |
|
726 | 543 |
|
727 |
};*/
|
|
544 |
}; |
|
728 | 545 |
} |
Also available in: Unified diff