1 19 20 package org.netbeans.modules.diff.builtin.visualizer; 21 22 import java.awt.event.*; 23 import java.beans.*; 24 import java.io.*; 25 import java.util.*; 26 27 import javax.swing.text.*; 28 29 import org.openide.actions.*; 30 import org.openide.cookies.EditorCookie; 31 import org.openide.cookies.OpenCookie; 32 import org.openide.cookies.CloseCookie; 33 import org.openide.cookies.PrintCookie; 34 import org.openide.filesystems.*; 35 import org.openide.loaders.*; 36 import org.openide.text.CloneableEditor; 37 import org.openide.text.CloneableEditorSupport; 38 import org.openide.windows.*; 39 import org.openide.util.HelpCtx; 42 import org.openide.util.NbBundle; 43 44 49 public class TextDiffEditorSupport extends CloneableEditorSupport implements EditorCookie.Observable, OpenCookie, PrintCookie, CloseCookie { 50 51 52 private final TextDiffVisualizer.TextDiffInfo diff; 54 55 130 131 132 137 TextDiffEditorSupport(TextDiffVisualizer.TextDiffInfo diff) { super (new TextDiffEditorSupport.Env(diff)); 139 this.diff = diff; 140 } 141 142 145 public final FileObject getFileObject () { 146 return null; 147 } 148 149 152 protected String messageOpening () { 153 return NbBundle.getMessage (TextDiffEditorSupport.class , "CTL_ObjectOpen", diff.getName() 155 ); 156 } 157 158 159 162 protected String messageOpened () { 163 return NbBundle.getMessage (TextDiffEditorSupport.class, "CTL_ObjectOpened", diff.getName() 165 ); 166 } 167 168 173 protected String messageSave () { 174 return ""; 179 } 180 181 185 protected String messageName () { 186 return diff.getName(); 187 } 188 189 193 protected String messageToolTip () { 194 return diff.getTitle(); 196 } 197 198 207 protected void initializeCloneableEditor (CloneableEditor editor) { 208 editor.setIcon(org.openide.util.Utilities.loadImage("org/netbeans/modules/diff/diffSettingsIcon.gif", true)); 209 } 213 214 protected CloneableEditor createCloneableEditor() { 215 return new DiffCloneableEditor(this); 216 } 217 218 224 protected StyledDocument createStyledDocument (EditorKit kit) { 225 StyledDocument doc = super.createStyledDocument (kit); 226 227 doc.putProperty(javax.swing.text.Document.TitleProperty, 229 diff.getName() 230 ); 231 236 return doc; 237 } 238 239 CloneableTopComponent createCloneableTopComponentForMe() { 240 return createCloneableTopComponent(); 241 } 242 243 250 251 253 public static class Env extends Object implements CloneableOpenSupport.Env, CloneableEditorSupport.Env, java.io.Serializable 254 { 255 256 static final long serialVersionUID = -2945098431098324441L; 257 258 259 private transient TextDiffVisualizer.TextDiffInfo diff; 260 261 264 public Env (TextDiffVisualizer.TextDiffInfo diff) { this.diff = diff; 266 } 267 268 272 274 277 public InputStream inputStream() throws IOException { 278 if (diff.isContextMode()) { 279 return TextDiffVisualizer.differenceToContextDiffText(diff); 280 } else { 281 return TextDiffVisualizer.differenceToLineDiffText(diff.getDifferences()); 282 } 283 } 284 285 288 public OutputStream outputStream() throws IOException { 289 throw new IOException("No output to a file diff supported."); 290 } 292 293 296 public String getMimeType() { 297 return "text/plain"; } 299 300 307 public void markModified() throws java.io.IOException { 308 throw new IOException("The file revision can not be modified."); 309 316 } 317 318 321 public void unmarkModified() { 322 } 324 325 338 339 public void removePropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) { 340 } 341 342 public boolean isModified() { 343 return false; 344 } 345 346 public java.util.Date getTime() { 347 return new java.util.Date (System.currentTimeMillis()); 348 } 349 350 public void removeVetoableChangeListener(java.beans.VetoableChangeListener vetoableChangeListener) { 351 } 352 353 public boolean isValid() { 354 return true; 355 } 356 357 public void addVetoableChangeListener(java.beans.VetoableChangeListener vetoableChangeListener) { 358 } 359 360 public void addPropertyChangeListener(java.beans.PropertyChangeListener propertyChangeListener) { 361 } 362 363 public CloneableOpenSupport findCloneableOpenSupport() { 364 return diff.getOpenSupport(); 366 } 367 368 } 370 public static class DiffCloneableEditor extends CloneableEditor { 371 372 DiffCloneableEditor(CloneableEditorSupport support) { 373 super(support); 374 } 375 376 381 public void addNotify() { 382 componentShowing(); 383 super.addNotify(); 384 } 385 386 private boolean componentShowingCalled = false; 387 392 protected void componentShowing() { 393 if (!componentShowingCalled) { 394 super.componentShowing(); 395 componentShowingCalled = true; 396 } 397 } 398 399 public HelpCtx getHelpCtx() { 400 return new HelpCtx(TextDiffEditorSupport.class); 401 } 402 } 403 404 459 460 } 461 | Popular Tags |