You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NavigationHistoryModel.java 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.ajde.ui.internal;
  14. import java.util.Stack;
  15. import org.aspectj.asm.IProgramElement;
  16. /**
  17. * @author Mik Kersten
  18. */
  19. public class NavigationHistoryModel {
  20. private IProgramElement currNode = null;
  21. private Stack backHistory = new Stack();
  22. private Stack forwardHistory = new Stack();
  23. /**
  24. * @return null if the history is empty
  25. */
  26. public IProgramElement navigateBack() {
  27. if (backHistory.isEmpty() || currNode == null) return null;
  28. forwardHistory.push(currNode);
  29. currNode = (IProgramElement)backHistory.pop();
  30. return currNode;
  31. }
  32. /**
  33. * @return null if the history is empty
  34. */
  35. public IProgramElement navigateForward() {
  36. if (forwardHistory.isEmpty() || currNode == null) return null;
  37. backHistory.push(currNode);
  38. currNode = (IProgramElement)forwardHistory.pop();
  39. return currNode;
  40. }
  41. public void navigateToNode(IProgramElement toNode) {
  42. if (currNode != null) backHistory.push(currNode);
  43. currNode = toNode;
  44. }
  45. }