1 19 20 package org.netbeans.editor; 21 22 import java.lang.ref.WeakReference ; 23 import javax.swing.text.Position ; 24 25 31 32 public class MarkFactory { 33 34 private MarkFactory() { 35 } 37 38 46 public static class SyntaxMark extends Mark { 47 48 49 private Syntax.StateInfo stateInfo; 50 51 private TokenItem tokenItem; 52 53 54 public Syntax.StateInfo getStateInfo() { 55 return stateInfo; 56 } 57 58 public void updateStateInfo(Syntax syntax) { 59 if (stateInfo == null) { 60 stateInfo = syntax.createStateInfo(); 61 } 62 syntax.storeState(stateInfo); 63 } 64 65 void setStateInfo(Syntax.StateInfo stateInfo) { 66 this.stateInfo = stateInfo; 67 } 68 69 public TokenItem getTokenItem() { 70 return tokenItem; 71 } 72 73 void setTokenItem(TokenItem tokenItem) { 74 this.tokenItem = tokenItem; 75 } 76 77 78 protected void removeUpdateAction(int pos, int len) { 79 try { 80 remove(); 81 } catch (InvalidMarkException e) { 82 } 84 } 85 86 } 87 88 89 public static class ContextMark extends Mark { 90 91 public ContextMark(boolean stayBOL) { 92 this(false, stayBOL); 93 } 94 95 public ContextMark(boolean insertAfter, boolean stayBOL) { 96 this(insertAfter ? Position.Bias.Backward : Position.Bias.Forward, stayBOL); 97 } 98 99 public ContextMark(Position.Bias bias, boolean stayBOL) { 100 super(bias); 101 } 102 103 } 104 105 108 public static class DrawMark extends ContextMark { 109 110 111 protected boolean activateLayer; 112 113 114 String layerName; 115 116 119 WeakReference editorUIRef; 120 121 public DrawMark(String layerName, EditorUI editorUI) { 122 this(layerName, editorUI, Position.Bias.Forward); 123 } 124 125 public DrawMark(String layerName, EditorUI editorUI, Position.Bias bias) { 126 super(bias, false); 127 this.layerName = layerName; 128 setEditorUI(editorUI); 129 } 130 131 public boolean isDocumentMark() { 132 return (editorUIRef == null); 133 } 134 135 public EditorUI getEditorUI() { 136 if (editorUIRef != null) { 137 return (EditorUI)editorUIRef.get(); 138 } 139 return null; 140 } 141 142 public void setEditorUI(EditorUI editorUI) { 143 this.editorUIRef = (editorUI != null) ? new WeakReference (editorUI) : null; 144 } 145 146 public boolean isValidUI() { 147 return !(editorUIRef != null && editorUIRef.get() == null); 148 } 149 150 public void setActivateLayer(boolean activateLayer) { 151 this.activateLayer = activateLayer; 152 } 153 154 public boolean getActivateLayer() { 155 return activateLayer; 156 } 157 158 public boolean removeInvalid() { 159 if (!isValidUI() && isValid()) { 160 try { 161 this.remove(); 162 } catch (InvalidMarkException e) { 163 throw new IllegalStateException (e.toString()); 164 } 165 return true; } 167 return false; } 169 170 public String toString() { 171 try { 172 return "pos=" + getOffset() + ", line=" + getLine(); } catch (InvalidMarkException e) { 174 return "mark not valid"; } 176 } 177 178 } 179 180 181 public static class ChainDrawMark extends DrawMark { 182 183 184 protected ChainDrawMark next; 185 186 187 protected ChainDrawMark prev; 188 189 public ChainDrawMark(String layerName, EditorUI editorUI) { 190 this(layerName, editorUI, Position.Bias.Forward); 191 } 192 193 public ChainDrawMark(String layerName, EditorUI editorUI, Position.Bias bias) { 194 super(layerName, editorUI, bias); 195 } 196 197 public final ChainDrawMark getNext() { 198 return next; 199 } 200 201 public final void setNext(ChainDrawMark mark) { 202 next = mark; 203 } 204 205 206 public void setNextChain(ChainDrawMark mark) { 207 this.next = mark; 208 if (mark != null) { 209 mark.prev = this; 210 } 211 } 212 213 public final ChainDrawMark getPrev() { 214 return prev; 215 } 216 217 public final void setPrev(ChainDrawMark mark) { 218 prev = mark; 219 } 220 221 222 public void setPrevChain(ChainDrawMark mark) { 223 this.prev = mark; 224 if (mark != null) { 225 mark.next = this; 226 } 227 } 228 229 232 public ChainDrawMark insertChain(ChainDrawMark mark) { 233 ChainDrawMark thisPrev = this.prev; 234 mark.prev = thisPrev; 235 mark.next = this; 236 if (thisPrev != null) { 237 thisPrev.next = mark; 238 } 239 this.prev = mark; 240 return mark; 241 } 242 243 246 public ChainDrawMark removeChain() { 247 ChainDrawMark thisNext = this.next; 248 ChainDrawMark thisPrev = this.prev; 249 if (thisPrev != null) { thisPrev.next = thisNext; 251 this.prev = null; 252 } 253 if (thisNext != null) { thisNext.prev = thisPrev; 255 this.next = null; 256 } 257 try { 258 this.remove(); } catch (InvalidMarkException e) { 260 } 262 return thisNext; 263 } 264 265 public String toStringChain() { 266 return toString() + (next != null ? "\n" + next.toStringChain() : ""); } 268 269 public String toString() { 270 return super.toString() + ", " + ((prev != null) ? ((next != null) ? "chain member" : "last member") : ((next != null) ? "first member" : "standalone member")); } 275 276 } 277 } 278 | Popular Tags |