root / branches / FMap_CAD / libraries / libFMap / src / com / iver / cit / gvsig / fmap / edition / MemoryCommandRecord.java @ 3513
History | View | Annotate | Download (3.73 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.edition; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
44 |
|
45 |
import java.io.IOException; |
46 |
|
47 |
import java.util.Stack; |
48 |
|
49 |
|
50 |
/**
|
51 |
* Clase en memoria para registrar y gestionar los comandos que vamos
|
52 |
* realizando. La forma en que ha sido implementada esta clase, en vez de una
|
53 |
* ?nica lista para albergar los comandos de deshacer(undos) y los de
|
54 |
* rehacer(redos), se ha optado por dos pilas una para deshacer(undos) y otra
|
55 |
* para rehacer(redos), de esta forma : Cuando se a?ade un nuevo comando, se
|
56 |
* inserta este a la pila de deshacer(undos) y se borra de la de
|
57 |
* rehacer(redos). Si se realiza un deshacer se desapila este comando de la
|
58 |
* pila deshacer(undos) y se apila en la de rehacer(redos). Y de la misma
|
59 |
* forma cuando se realiza un rehacer se desapila este comando de la pila de
|
60 |
* rehacer(redos) y pasa a la de deshacer(undos).
|
61 |
*
|
62 |
* @author Vicente Caballero Navarro
|
63 |
*/
|
64 |
public class MemoryCommandRecord implements CommandRecord { |
65 |
Stack undos = new Stack(); |
66 |
Stack redos = new Stack(); |
67 |
|
68 |
/**
|
69 |
* A?ade el comando a la pila de deshacer y borra todo el contenido de la
|
70 |
* pila rehacer.
|
71 |
*
|
72 |
* @param command Comando a a?adir.
|
73 |
*
|
74 |
* @throws IOException
|
75 |
* @throws DriverIOException
|
76 |
*
|
77 |
* @see com.iver.cit.gvsig.fmap.edition.CommandRecord#addCommand(com.iver.cit.gvsig.fmap.edition.Command)
|
78 |
*/
|
79 |
public void pushCommand(Command command) |
80 |
throws IOException, DriverIOException { |
81 |
undos.add(command); |
82 |
redos.clear(); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* Realiza la operaci?n del ?ltimo comando de deshacer y lo apila en los de
|
87 |
* rehacer.
|
88 |
*
|
89 |
* @throws DriverIOException
|
90 |
* @throws IOException
|
91 |
*
|
92 |
* @see com.iver.cit.gvsig.fmap.edition.CommandRecord#delCommand(com.iver.cit.gvsig.fmap.edition.Command)
|
93 |
*/
|
94 |
public void undoCommand() throws DriverIOException, IOException { |
95 |
Command command = (Command) undos.pop(); |
96 |
command.undo(); |
97 |
redos.add(command); |
98 |
} |
99 |
|
100 |
/**
|
101 |
* Realiza la operaci?n de rehacer el ?ltimo comando apilado y lo a?ade a
|
102 |
* la pila deshacer.
|
103 |
*
|
104 |
* @throws DriverIOException
|
105 |
* @throws IOException
|
106 |
*
|
107 |
* @see com.iver.cit.gvsig.fmap.edition.CommandRecord#redoCommand()
|
108 |
*/
|
109 |
public void redoCommand() throws DriverIOException, IOException { |
110 |
Command command = (Command) redos.pop(); |
111 |
command.redo(); |
112 |
undos.add(command); |
113 |
} |
114 |
|
115 |
/**
|
116 |
* @see com.iver.cit.gvsig.fmap.edition.CommandRecord#moreUndoCommands()
|
117 |
*/
|
118 |
public boolean moreUndoCommands() { |
119 |
return (!undos.isEmpty());
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* @see com.iver.cit.gvsig.fmap.edition.CommandRecord#moreRedoCommands()
|
124 |
*/
|
125 |
public boolean moreRedoCommands() { |
126 |
return (!redos.isEmpty());
|
127 |
} |
128 |
} |