001: /*
002: * uDig - User Friendly Desktop Internet GIS client http://udig.refractions.net (C) 2004,
003: * Refractions Research Inc. This library is free software; you can redistribute it and/or modify it
004: * under the terms of the GNU Lesser General Public License as published by the Free Software
005: * Foundation; version 2.1 of the License. This library is distributed in the hope that it will be
006: * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
007: * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
008: */
009: package net.refractions.udig.project.internal.render;
010:
011: import java.io.IOException;
012:
013: import net.refractions.udig.project.ILayer;
014: import net.refractions.udig.project.internal.Layer;
015: import net.refractions.udig.project.internal.LayerDecorator;
016: import net.refractions.udig.project.internal.Map;
017: import net.refractions.udig.project.internal.ProjectFactory;
018: import net.refractions.udig.project.internal.ProjectPackage;
019: import net.refractions.udig.project.internal.ProjectPlugin;
020: import net.refractions.udig.project.internal.StyleBlackboard;
021: import net.refractions.udig.project.internal.impl.LayerImpl;
022:
023: import org.eclipse.emf.common.notify.Notification;
024: import org.eclipse.emf.ecore.impl.ENotificationImpl;
025: import org.geotools.data.FeatureSource;
026: import org.geotools.filter.Filter;
027: import org.geotools.styling.Style;
028:
029: /**
030: * TODO Purpose of net.refractions.udig.project.internal.render
031: * <p>
032: * </p>
033: *
034: * @author Jesse
035: * @since 1.0.0
036: */
037: public class SelectionLayer extends LayerDecorator {
038:
039: private StyleBlackboard styleBlackboard = ProjectFactory.eINSTANCE
040: .createStyleBlackboard();
041:
042: private String message;
043:
044: /**
045: * Construct <code>SelectionLayer</code>.
046: *
047: * @param layer
048: */
049: public SelectionLayer(Layer layer) {
050: super (layer);
051: }
052:
053: /**
054: * @see net.refractions.udig.project.internal.Layer#isVisible()
055: */
056: public boolean isVisible() {
057: return layer.isVisible() && !Filter.ALL.equals(getFilter());
058: }
059:
060: /**
061: * @see net.refractions.udig.project.internal.Layer#getStyleBlackboard()
062: * @uml.property name="styleBlackboard"
063: */
064: public StyleBlackboard getStyleBlackboard() {
065: try {
066: if (styleBlackboard == null)
067: styleBlackboard = ProjectFactory.eINSTANCE
068: .createStyleBlackboard();
069:
070: styleBlackboard.clear();
071: Style style = SelectionStyleContent
072: .createDefaultStyle(layer);
073: if (style == null)
074: return styleBlackboard;
075: style.getFeatureTypeStyles()[0].setFeatureTypeName(layer
076: .getResource(FeatureSource.class, null).getSchema()
077: .getTypeName());
078: styleBlackboard.put(SelectionStyleContent.ID, style);
079: } catch (IOException e) {
080: ProjectPlugin.log(null, e);
081: }
082: return styleBlackboard;
083: }
084:
085: /**
086: * @see net.refractions.udig.project.internal.Layer#setStyleBlackboard(net.refractions.udig.project.StyleBlackboard)
087: * @uml.property name="styleBlackboard"
088: */
089: public void setStyleBlackboard(StyleBlackboard value) {
090: styleBlackboard = value;
091: if (eNotificationRequired())
092: eNotify(new ENotificationImpl(this , Notification.SET,
093: ProjectPackage.LAYER__STYLE_BLACKBOARD, value,
094: value));
095: }
096:
097: /**
098: * @see net.refractions.udig.project.internal.LayerDecorator#getZorder()
099: */
100: @Override
101: public int getZorder() {
102: Map mapInternal = getMapInternal();
103: if (mapInternal == null)
104: return Integer.MAX_VALUE;
105: return super .getZorder()
106: + mapInternal.getLayersInternal().size();
107: }
108:
109: /**
110: * Required because delegating to layer won't get this objects z-order
111: */
112: public int compareTo(ILayer layer2) {
113: return LayerImpl.doComparison(this , layer2);
114: }
115:
116: /**
117: * @see net.refractions.udig.project.internal.Layer#setStatus(int)
118: */
119: public void setStatus(int status) {
120: // FIXME: Selection layer is always setting wait on us
121: if (status == WAIT)
122: return; // not
123: layer.setStatus(status);
124: }
125:
126: /**
127: * @see net.refractions.udig.project.internal.LayerDecorator#setStatusMessage(java.lang.String)
128: */
129: public void setStatusMessage(String message) {
130: this .message = message;
131: }
132:
133: /**
134: * @see net.refractions.udig.project.internal.LayerDecorator#getStatusMessage()
135: */
136: public String getStatusMessage() {
137: return message;
138: }
139: }
|