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.action;
14  
15  import java.awt.event.ActionEvent;
16  import java.awt.event.KeyEvent;
17  import java.io.File;
18  
19  import javax.swing.Action;
20  
21  import org.abstracthorizon.aequo.GlobalContext;
22  import org.abstracthorizon.aequo.util.Preferences;
23  import org.abstracthorizon.aequo.util.StringUtils;
24  import org.abstracthorizon.aequo.util.filters.Filter;
25  import org.abstracthorizon.aequo.util.prefs.RecentFileEntry;
26  
27  /**
28   * New session action.
29   *
30   * @author Daniel Sendula
31   */
32  public class PreviousSessionAction extends BaseAction {
33  
34      /** Session number in preferences file */
35      protected int sessionNo;
36  
37      /**
38       * Constructor
39       */
40      public PreviousSessionAction() {
41          setName("Previous Session");
42          setMessage("Previous Session");
43          setDescription("Previous Session");
44      }
45  
46      /**
47       * Sets the session number. Also it sets name, message and description accordingly
48       *
49       * @param sessionNo session number
50       */
51      public void setSessionNo(int sessionNo) {
52          this.sessionNo = sessionNo;
53          Preferences prefs = context.getPreferences();
54  
55          RecentFileEntry entry = RecentFileEntry.read(prefs, sessionNo);
56  
57          String sessionName = StringUtils.calculateShortestTitle(entry.left, entry.right);
58  
59          setName(sessionNo + " " + sessionName);
60          setMessage("Comparing " + sessionName);
61          setDescription("Comparing " + sessionName);
62  
63          if (sessionNo < 9) {
64              int[] keys = new int[]{KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_3, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_6, KeyEvent.VK_7, KeyEvent.VK_8, KeyEvent.VK_9};
65              putValue(Action.MNEMONIC_KEY, keys[sessionNo]);
66          }
67          autoloadIcon();
68      }
69  
70      /**
71       * Performs the action
72       * @param e event
73       */
74      public void perform(ActionEvent e) {
75          GlobalContext context = getGlobalContext();
76  
77          Preferences prefs = context.getPreferences();
78          RecentFileEntry entry = RecentFileEntry.read(prefs, sessionNo);
79  
80          if ((entry.left != null) && (entry.right != null)) {
81              CompareFilesAction compareFilesAction = new CompareFilesAction(new File(entry.left), new File(entry.right), new Filter(entry.filters), context);
82              compareFilesAction.actionPerformed(e);
83          }
84      }
85  }