View Javadoc

1   /*
2    * Copyright (c) 2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.aequo.text;
14  
15  import java.io.File;
16  import java.io.IOException;
17  
18  import org.abstracthorizon.aequo.GlobalContext;
19  import org.abstracthorizon.aequo.file.BaseFileCompareWindow;
20  import org.abstracthorizon.aequo.file.FileCompareEntry;
21  
22  /**
23   * Text compare window.
24   *
25   * @author Daniel Sendula
26   */
27  public class TextCompareWindow extends BaseFileCompareWindow {
28  
29      /** Model */
30      protected TextModel model;
31      
32      /**
33       * Constructor
34       * @param context global context
35       * @param leftFilet left file
36       * @param rightFile right file
37       * @throws IOException thrown in problem reading file
38       */
39      public TextCompareWindow(GlobalContext context, File leftFile, File rightFile) throws IOException {
40          super(context);
41  
42          model = new TextModel(leftFile, rightFile);
43          model.load();
44      }
45  
46      /**
47       * Returns window id.
48       * @return window id
49       */
50      protected String getWindowId() {
51          return "window.text";
52      }
53  
54      /**
55       * Creates components for this window
56       */
57      public void initialise() {
58          super.initialise();
59      }
60      
61      /**
62       * Creates compare panel
63       */
64      protected void createComparePanel() {
65          comparePanel = new TextComparePanel(context, model);
66          comparePanel.initialise();
67      }
68      
69      /**
70       * Constructor
71       * @param context global context
72       * @param fileEntry file entry
73       * @throws IOException thrown if there are problems loading files
74       */
75      public TextCompareWindow(GlobalContext context, FileCompareEntry fileEntry) throws IOException {
76          super(context);
77          
78          model = new TextModel(fileEntry);
79          model.load();
80      }
81  
82      /**
83       * Returns left file name (for title)
84       * @return left file name (for title)
85       */
86      protected String getLeftFileName() {
87          return model.getLeftFile().getAbsolutePath();
88      }
89  
90      /**
91       * Returns right file name (for title)
92       * @return right file name (for title)
93       */
94      protected String getRightFileName() {
95          return model.getRightFile().getAbsolutePath();
96      }
97  
98      /**
99       * Sets window title
100      * @param title title
101      */
102     public void setTitle(String title) {
103         if (getLeftFileName().equals(getRightFileName())) {
104             super.setTitle(getLeftFileName() + ": " + title);
105         } else {
106             super.setTitle(title);
107         }
108     }
109 }