|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
CurrentObjectsStackManager.java | 100% | 100% | 100% | 100% |
|
1 |
/**
|
|
2 |
* Java Gui Builder - A library to build GUIs using an XML file.
|
|
3 |
* Copyright 2002, 2003 (C) François Beausoleil
|
|
4 |
*
|
|
5 |
* This library is free software; you can redistribute it and/or
|
|
6 |
* modify it under the terms of the GNU Lesser General Public
|
|
7 |
* License as published by the Free Software Foundation; either
|
|
8 |
* version 2.1 of the License, or (at your option) any later version.
|
|
9 |
*
|
|
10 |
* This library 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 GNU
|
|
13 |
* Lesser General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU Lesser General Public
|
|
16 |
* License along with this library; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
18 |
*/
|
|
19 |
|
|
20 |
package jgb.builder.utils;
|
|
21 |
|
|
22 |
import java.util.Stack;
|
|
23 |
|
|
24 |
/**
|
|
25 |
* @since 0.2.1a
|
|
26 |
* @author Francois Beausoleil, <a href="mailto:fbos@users.sourceforge.net">fbos@users.sourceforge.net</a>
|
|
27 |
*/
|
|
28 |
public class CurrentObjectsStackManager { |
|
29 |
private Stack stack = new Stack(); |
|
30 |
|
|
31 | 180 |
public void pushCurrentObject(Object o) { |
32 | 180 |
pushCurrentObject(o, null);
|
33 |
} |
|
34 |
|
|
35 | 324 |
public void pushCurrentObject(Object o, String id) { |
36 | 324 |
CurrentObject co = new CurrentObject(o, id);
|
37 | 324 |
stack.push(co); |
38 |
} |
|
39 |
|
|
40 | 66 |
public void popCurrentObject() { |
41 | 66 |
stack.pop(); |
42 |
} |
|
43 |
|
|
44 | 383 |
public Object getCurrentObject() {
|
45 | 383 |
if (isCurrentObjectValid()) {
|
46 | 382 |
return ((CurrentObject)stack.peek()).getObject();
|
47 |
} else {
|
|
48 | 1 |
return null; |
49 |
} |
|
50 |
} |
|
51 |
|
|
52 | 198 |
public String getCurrentObjectId() {
|
53 | 198 |
if (isCurrentObjectValid()) {
|
54 | 197 |
return ((CurrentObject)stack.peek()).getObjectId();
|
55 |
} else {
|
|
56 | 1 |
return null; |
57 |
} |
|
58 |
} |
|
59 |
|
|
60 | 858 |
public boolean isCurrentObjectValid() { |
61 | 858 |
return !stack.isEmpty();
|
62 |
} |
|
63 |
|
|
64 | 40 |
public int size() { |
65 | 40 |
return stack.size();
|
66 |
} |
|
67 |
|
|
68 | 3 |
public String toString() {
|
69 | 3 |
return this.getClass().getName() + " [" + stack.toString() + "]"; |
70 |
} |
|
71 |
|
|
72 |
private static class CurrentObject { |
|
73 |
private Object object;
|
|
74 |
private String objectId;
|
|
75 |
|
|
76 | 324 |
public CurrentObject(Object object, String objectId) {
|
77 | 324 |
this.object = object;
|
78 | 324 |
this.objectId = objectId;
|
79 |
} |
|
80 |
|
|
81 | 382 |
public Object getObject() {
|
82 | 382 |
return object;
|
83 |
} |
|
84 |
|
|
85 | 197 |
public String getObjectId() {
|
86 | 197 |
return objectId;
|
87 |
} |
|
88 |
} |
|
89 |
} |
|
90 |
|
|