1 19 package org.openide.text; 20 21 import java.lang.ref.Reference ; 22 import java.util.*; 23 24 import javax.swing.event.*; 25 import javax.swing.text.Position ; 26 import javax.swing.text.StyledDocument ; 27 28 29 33 final class EditorSupportLineSet extends DocumentLine.Set { 34 35 private CloneableEditorSupport support; 36 37 41 public EditorSupportLineSet(CloneableEditorSupport support, StyledDocument doc) { 42 super(doc, support); 43 this.support = support; 44 } 45 46 48 Map<Line,Reference <Line>> findWeakHashMap() { 49 return support.findWeakHashMap(); 50 } 51 52 56 public Line createLine(int offset) { 57 PositionRef ref = new PositionRef(support.getPositionManager(), offset, Position.Bias.Forward); 58 59 return new SupportLine(support.getLookup(), ref, support); 60 } 61 62 64 private static final class SupportLine extends DocumentLine { 65 static final long serialVersionUID = 7282223299866986051L; 66 67 69 public SupportLine(org.openide.util.Lookup obj, PositionRef ref, CloneableEditorSupport support) { 70 super(obj, ref); 71 } 72 73 77 public void show(int kind, int column) { 78 CloneableEditorSupport support = pos.getCloneableEditorSupport(); 79 80 if ((kind == SHOW_TRY_SHOW) && !support.isDocumentLoaded()) { 81 return; 82 } 83 84 CloneableEditorSupport.Pane editor; 85 86 if (kind == SHOW_REUSE || kind == SHOW_REUSE_NEW) { 87 editor = support.openReuse(pos, column, kind); 88 } else { 89 editor = support.openAt(pos, column); 90 if (kind == SHOW_TOFRONT) editor.getComponent().toFront(); 91 } 92 editor.getComponent().requestActive(); 93 } 94 95 96 public Line.Part createPart(int column, int length) { 97 DocumentLine.Part part = new DocumentLine.Part( 98 this, 99 new PositionRef( 100 pos.getCloneableEditorSupport().getPositionManager(), pos.getOffset() + column, 101 Position.Bias.Forward 102 ), length 103 ); 104 addLinePart(part); 105 106 return part; 107 } 108 109 110 public String getDisplayName() { 111 CloneableEditorSupport support = pos.getCloneableEditorSupport(); 112 113 return support.messageLine(this); 114 } 115 116 public String toString() { 117 return "SupportLine@" + Integer.toHexString(System.identityHashCode(this)) + " at line: " + 118 getLineNumber(); } 120 } 121 122 126 static class Closed extends Line.Set implements ChangeListener { 127 128 private CloneableEditorSupport support; 129 130 133 private Line.Set delegate; 134 135 139 public Closed(CloneableEditorSupport support) { 140 this.support = support; 141 support.addChangeListener(org.openide.util.WeakListeners.change(this, support)); 142 } 143 144 146 Map<Line,Reference <Line>> findWeakHashMap() { 147 return support.findWeakHashMap(); 148 } 149 150 156 public List<? extends Line> getLines() { 157 if (delegate != null) { 158 return delegate.getLines(); 159 } 160 161 return new ArrayList<Line>(); 163 } 164 165 173 public Line getOriginal(int line) throws IndexOutOfBoundsException { 174 if (delegate != null) { 175 return delegate.getOriginal(line); 176 } 177 178 return getCurrent(line); 179 } 180 181 187 public Line getCurrent(int line) throws IndexOutOfBoundsException { 188 PositionRef ref = new PositionRef(support.getPositionManager(), line, 0, Position.Bias.Forward); 189 190 org.openide.util.Lookup obj = support.getLookup(); 192 193 return this.registerLine(new SupportLine(obj, ref, support)); 194 } 195 196 198 public synchronized void stateChanged(ChangeEvent ev) { 199 if (delegate == null) { 200 StyledDocument doc = support.getDocument(); 201 202 if (doc != null) { 203 delegate = new EditorSupportLineSet(support, doc); 204 } 205 } else { 206 if (support.getDocument() == null) { 207 delegate = null; 208 } 209 } 210 } 211 } 212 } 213 | Popular Tags |