2 * Command Buffer for the cluster window of the spider GUI.
4 * @version 1.00 - 20010418.
6 * Copyright (C) 2001 Ian Norton.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public Licence as published by
10 * the Free Software Foundation; either version 2 of the Licence, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public Licence for more details.
18 * You should have received a copy of the GNU General Public Licence
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Contacting the author :
24 * i.norton@lancaster.ac.uk
25 * http://www.lancs.ac.uk/~norton/ **/
27 import java.util.Vector ;
31 private int top, bottom, pointer, size ;
32 private Vector buffer ;
33 private boolean rolled ;
36 * main - testing purposes only.
38 public static void main(String[] args)
40 CommandBuffer c = new CommandBuffer(5) ;
42 System.out.println(c.getPreviousCommand()) ;
43 System.out.println(c.getNextCommand()) ;
48 * @param int - Number of lines of buffer.
50 public CommandBuffer(int i)
52 // Size of the buffer.
61 // Vector that does that actual storage.
62 buffer = new Vector(size) ;
67 * @param String - command to add to the buffer
69 public void addCommand(String s)
71 // Is it an empty string
72 if(s.length() == 0) return ;
74 // Add the command to the buffer
75 buffer.addElement(s) ;
77 // Check the buffer remains the correct size.
78 while(buffer.size() > size) buffer.removeElementAt(0) ;
80 // Pointer to the last command
81 pointer = buffer.indexOf(s) ;
85 * getPreviousCommand - get the previous command (recursive)
86 * @returns String - previous command
88 public String getPreviousCommand()
90 String output = (String)buffer.elementAt(pointer) ;
91 if(pointer != 0) pointer-- ;
96 * getNextCommand - get the next command (recursive)
97 * @returns String - next command
99 public String getNextCommand()
102 if(pointer == buffer.size())
107 String output = (String)buffer.elementAt(pointer) ;