1 19 20 package org.netbeans.core.multiview; 21 22 import java.awt.BorderLayout ; 23 import java.io.*; 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.Map ; 29 import javax.swing.AbstractAction ; 30 import javax.swing.Action ; 31 import javax.swing.ActionMap ; 32 import javax.swing.InputMap ; 33 import javax.swing.JComponent ; 34 import javax.swing.JPanel ; 35 import javax.swing.JScrollPane ; 36 import javax.swing.KeyStroke ; 37 import org.netbeans.core.api.multiview.MultiViewHandler; 38 import org.netbeans.core.api.multiview.MultiViewPerspective; 39 import org.netbeans.core.multiview.MultiViewModel.ActionRequestObserverFactory; 40 import org.netbeans.core.multiview.MultiViewModel.ElementSelectionListener; 41 import org.netbeans.core.spi.multiview.CloseOperationHandler; 42 import org.netbeans.core.spi.multiview.CloseOperationState; 43 import org.netbeans.core.spi.multiview.MultiViewDescription; 44 import org.netbeans.core.spi.multiview.MultiViewElement; 45 import org.netbeans.core.spi.multiview.MultiViewElementCallback; 46 import org.netbeans.core.spi.multiview.MultiViewFactory; 47 import org.openide.awt.UndoRedo; 48 import org.openide.text.CloneableEditorSupport; 49 import org.openide.util.HelpCtx; 50 import org.openide.util.Lookup; 51 import org.openide.util.lookup.Lookups; 52 import org.openide.util.lookup.ProxyLookup; 53 import org.openide.windows.CloneableTopComponent; 54 import org.openide.windows.TopComponent; 55 56 57 64 65 66 public final class MultiViewTopComponent 67 extends TopComponent 68 implements ActionRequestObserverFactory { 69 70 MultiViewPeer peer; 71 72 public MultiViewTopComponent() { 73 super(); 74 peer = new MultiViewPeer(this, this); 75 peer.initComponents(); 77 associateLookup(peer.getLookup()); 79 setName(""); 80 setFocusCycleRoot(false); 81 } 82 83 84 public void setMultiViewDescriptions(MultiViewDescription[] descriptions, MultiViewDescription defaultDesc) { 85 peer.setMultiViewDescriptions(descriptions, defaultDesc); 86 } 87 88 public void setCloseOperationHandler(CloseOperationHandler handler) { 89 peer.setCloseOperationHandler(handler); 90 } 91 92 private void setDeserializedMultiViewDescriptions(MultiViewDescription[] descriptions, 93 MultiViewDescription defaultDesc, Map existingElements) { 94 peer.setDeserializedMultiViewDescriptions(descriptions, defaultDesc, existingElements); 95 } 96 97 MultiViewModel getModel() { 98 return peer.getModel(); 99 } 100 101 102 103 protected void componentClosed() { 104 super.componentClosed(); 105 peer.peerComponentClosed(); 106 } 107 108 protected void componentShowing() { 109 super.componentShowing(); 110 peer.peerComponentShowing(); 111 } 112 113 protected void componentHidden() { 114 super.componentHidden(); 115 peer.peerComponentHidden(); 116 } 117 118 protected void componentDeactivated() { 119 super.componentDeactivated(); 120 peer.peerComponentDeactivated(); 121 } 122 123 protected void componentActivated() { 124 super.componentActivated(); 125 peer.peerComponentActivated(); 126 } 127 128 protected void componentOpened() { 129 super.componentOpened(); 130 peer.peerComponentOpened(); 131 } 132 133 134 138 public Action [] getActions() { 139 Action [] superActions = super.getActions(); 141 Action [] acts = peer.peerGetActions(superActions); 142 return acts; 143 } 144 145 public MultiViewHandlerDelegate getMultiViewHandlerDelegate() { 146 return peer.getMultiViewHandlerDelegate(); 148 } 149 150 153 public int getPersistenceType() { 154 return peer.getPersistenceType(); 155 } 156 157 protected String preferredID() { 158 return peer.preferredID(); 159 } 160 161 162 163 167 public void writeExternal (ObjectOutput out) throws IOException { 168 super.writeExternal(out); 169 peer.peerWriteExternal(out); 170 } 171 172 176 public void readExternal (ObjectInput in) throws IOException, ClassNotFoundException { 177 super.readExternal(in); 178 peer.peerReadExternal(in); 179 } 180 181 182 Action [] getDefaultTCActions() { 183 return super.getActions(); 184 } 185 186 public MultiViewElementCallback createElementCallback(MultiViewDescription desc) { 187 return SpiAccessor.DEFAULT.createCallback(new ActReqObserver(desc)); 188 } 189 190 191 public HelpCtx getHelpCtx() { 192 return peer.getHelpCtx(); 193 } 194 195 public String toString() { 196 return "MultiViewTopComponent[name=" + getDisplayName() + ", peer=" + peer + "]"; } 198 199 206 public UndoRedo getUndoRedo() { 207 UndoRedo retValue; 208 retValue = peer.peerGetUndoRedo(); 209 if (retValue == null) { 210 retValue = super.getUndoRedo(); 211 } 212 return retValue; 213 } 214 215 219 public boolean canClose() { 220 return peer.canClose(); 221 } 222 223 226 public boolean requestFocusInWindow() { 227 return peer.requestFocusInWindow(); 228 } 229 230 233 public void requestFocus() { 234 peer.requestFocus(); 235 } 236 237 241 245 class ActReqObserver implements Serializable, MultiViewElementCallbackDelegate { 246 247 private static final long serialVersionUID =-3126744916624172415L; 248 private MultiViewDescription description; 249 250 ActReqObserver(MultiViewDescription desc) { 251 description = desc; 252 } 253 254 public void requestActive() { 255 boolean activated = peer.isActivated(); 256 if (!activated) { 257 MultiViewTopComponent.this.requestActive(); 258 } 259 if (peer.model.getActiveDescription() != description) { 260 if (activated) { 261 peer.model.getActiveElement().componentDeactivated(); 262 } 263 peer.tabs.changeActiveManually(description); 264 if (activated) { 265 peer.model.getActiveElement().componentActivated(); 266 } 267 } 268 } 269 270 public void requestVisible() { 271 peer.tabs.changeVisibleManually(description); 272 } 273 274 public Action [] createDefaultActions() { 275 return MultiViewTopComponent.this.getDefaultTCActions(); 276 } 277 278 public void updateTitle(String title) { 279 MultiViewTopComponent.this.setDisplayName(title); 280 } 281 282 283 public Object writeReplace() throws ObjectStreamException { 284 return null; 285 } 286 287 288 public Object readResolve() throws ObjectStreamException { 289 return null; 290 } 291 292 public boolean isSelectedElement() { 293 return (description.equals(peer.model.getActiveDescription())); 294 } 295 296 public TopComponent getTopComponent() { 297 return MultiViewTopComponent.this; 298 } 299 300 } 301 302 } | Popular Tags |