1 19 20 package org.netbeans.spi.editor.highlighting; 21 22 import java.util.Collection ; 23 import java.util.List ; 24 import javax.swing.text.Document ; 25 import javax.swing.text.JTextComponent ; 26 import org.netbeans.modules.editor.lib2.highlighting.HighlightingSpiPackageAccessor; 27 import org.netbeans.modules.editor.lib2.highlighting.HighlightsLayerAccessor; 28 import org.openide.util.TopologicalSortException; 29 30 63 64 public final class HighlightsLayer { 65 66 86 public static HighlightsLayer create( 87 String layerTypeId, 88 ZOrder zOrder, 89 boolean fixedSize, 90 HighlightsContainer container 91 ) { 92 return new HighlightsLayer(layerTypeId, zOrder, fixedSize, container); 93 } 94 95 private final String layerTypeId; 96 private final ZOrder zOrder; 97 private final boolean fixedSize; 98 99 private HighlightsContainer container; 100 101 private HighlightsLayerAccessor accessor; 102 103 120 private HighlightsLayer( 121 String layerTypeId, 122 ZOrder zOrder, 123 boolean fixedSize, 124 HighlightsContainer container 125 ) { 126 assert layerTypeId != null : "The layerId parameter must not be null."; 127 assert zOrder != null : "The zOrder parameter must not be null."; 128 129 this.layerTypeId = layerTypeId; 130 this.zOrder = zOrder; 131 this.fixedSize = fixedSize; 132 this.container = container; 133 } 134 135 141 String getLayerTypeId() { 142 return layerTypeId; 143 } 144 145 153 ZOrder getZOrder() { 154 return zOrder; 155 } 156 157 172 boolean isFixedSize() { 173 return fixedSize; 174 } 175 176 HighlightsContainer getContainer() { 177 return container; 178 } 179 180 static { 181 HighlightingSpiPackageAccessor.register(new PackageAccessor()); 182 } 183 184 private static final class PackageAccessor extends HighlightingSpiPackageAccessor { 185 186 187 public PackageAccessor() { 188 } 189 190 public HighlightsLayerFactory.Context createFactoryContext(Document document, JTextComponent component) { 191 return new HighlightsLayerFactory.Context(document, component); 192 } 193 194 public List <? extends HighlightsLayer> sort(Collection <? extends HighlightsLayer> layers) throws TopologicalSortException { 195 return ZOrder.sort(layers); 196 } 197 198 public HighlightsLayerAccessor getHighlightsLayerAccessor(final HighlightsLayer layer) { 199 if (layer.accessor == null) { 200 layer.accessor = new HighlightsLayerAccessor() { 201 public String getLayerTypeId() { return layer.getLayerTypeId(); } 202 public boolean isFixedSize() { return layer.isFixedSize(); } 203 public ZOrder getZOrder() { return layer.getZOrder(); } 204 public HighlightsContainer getContainer() { return layer.getContainer(); } 205 }; 206 } 207 208 return layer.accessor; 209 } 210 } } 212 | Popular Tags |