1 19 20 package org.netbeans.editor; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.HashSet ; 26 import java.util.Set ; 27 import java.util.logging.Level ; 28 import java.util.logging.Logger ; 29 import org.netbeans.modules.editor.lib.HighlightingDrawLayer; 30 31 39 40 41 class DrawLayerList { 42 43 private static final Logger LOG = Logger.getLogger(DrawLayerList.class.getName()); 44 45 private static final DrawLayer[] EMPTY = new DrawLayer[0]; 46 47 private DrawLayer[] layers = EMPTY; 48 49 private static final Set <String > ISSUED_WARNINGS = Collections.synchronizedSet(new HashSet <String >()); 50 51 private final ArrayList visibilityList = new ArrayList (); 52 53 60 synchronized boolean add(DrawLayer layer, int visibility) { 61 if (indexOf(layer.getName()) >= 0) { return false; 63 } 64 65 if (!(layer instanceof HighlightingDrawLayer)) { 66 String layerId = layer.getClass().getName() + layer.getName(); 67 if (!ISSUED_WARNINGS.contains(layerId)) { 68 ISSUED_WARNINGS.add(layerId); 69 LOG.log(Level.WARNING, "Using deprecated DrawLayer: " + layer.getName() + " z-order: " + visibility + " class: " + layer.getClass().getName() + " " + layer); } 73 } 74 75 int indAdd = layers.length; 76 for (int i = 0; i < layers.length; i++) { 77 if (((Integer )visibilityList.get(i)).intValue() > visibility) { 78 indAdd = i; 79 break; 80 } 81 } 82 83 ArrayList l = new ArrayList (Arrays.asList(layers)); 84 l.add(indAdd, layer); 85 layers = new DrawLayer[layers.length + 1]; 86 l.toArray(layers); 87 88 visibilityList.add(indAdd, new Integer (visibility)); 89 90 return true; 91 } 92 93 synchronized void add(DrawLayerList l) { 94 DrawLayer[] lta = l.layers; 95 for (int i = 0; i < lta.length; i++) { 96 add(lta[i], ((Integer )l.visibilityList.get(i)).intValue()); 97 } 98 } 99 100 103 synchronized DrawLayer remove(String layerName) { 104 int ind = indexOf(layerName); 105 DrawLayer removed = null; 106 107 if (ind >= 0) { 108 removed = layers[ind]; 109 ArrayList l = new ArrayList (Arrays.asList(layers)); 110 l.remove(ind); 111 layers = new DrawLayer[layers.length - 1]; 112 l.toArray(layers); 113 114 visibilityList.remove(ind); 115 } 116 117 return removed; 118 } 119 120 synchronized void remove(DrawLayerList l) { 121 DrawLayer[] lta = l.layers; 122 for (int i = 0; i < lta.length; i++) { 123 remove(lta[i].getName()); 124 } 125 } 126 127 synchronized DrawLayer findLayer(String layerName) { 128 int ind = indexOf(layerName); 129 return (ind >= 0) ? layers[ind] : null; 130 } 131 132 137 synchronized DrawLayer[] currentLayers() { 138 return (DrawLayer[])layers.clone(); 139 } 140 141 private int indexOf(String layerName) { 142 for (int i = 0; i < layers.length; i++) { 143 if (layerName.equals(layers[i].getName())) { 144 return i; 145 } 146 } 147 return -1; 148 } 149 150 public String toString() { 151 switch (layers.length) { 152 case 0: 153 return "No layers"; case 1: 155 return "Standalone " + layers[0]; default: 157 return "Layers:\n" + EditorDebug.debugArray(layers); } 159 } 160 161 } 162 | Popular Tags |