001: /*
002: * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003: *
004: * http://izpack.org/
005: * http://izpack.codehaus.org/
006: *
007: * Copyright 2007 Dennis Reil
008: *
009: * Licensed under the Apache License, Version 2.0 (the "License");
010: * you may not use this file except in compliance with the License.
011: * You may obtain a copy of the License at
012: *
013: * http://www.apache.org/licenses/LICENSE-2.0
014: *
015: * Unless required by applicable law or agreed to in writing, software
016: * distributed under the License is distributed on an "AS IS" BASIS,
017: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018: * See the License for the specific language governing permissions and
019: * limitations under the License.
020: */
021:
022: package com.izforge.izpack.installer;
023:
024: import java.util.ArrayList;
025: import java.util.List;
026:
027: /**
028: * @author Dennis Reil, <Dennis.Reil@reddot.de>
029: * @version $Id: $
030: */
031: public class VariableHistory {
032: private String name;
033: private List<String[]> values;
034: private boolean newvariable;
035: private boolean changed;
036:
037: public VariableHistory(String variable) {
038: name = variable;
039: values = new ArrayList<String[]>();
040: }
041:
042: /**
043: * @return the name
044: */
045: public String getName() {
046: return this .name;
047: }
048:
049: /**
050: * @param name the name to set
051: */
052: public void setName(String name) {
053: this .name = name;
054: }
055:
056: public void addValue(String value, String comment) {
057: String[] valuecomment = new String[2];
058: valuecomment[0] = value;
059: valuecomment[1] = comment;
060: values.add(valuecomment);
061: if (values.size() == 1) {
062: newvariable = true;
063: changed = true;
064: } else {
065: changed = true;
066: }
067: }
068:
069: public String[] getValueComment(int index) {
070: return values.get(index);
071: }
072:
073: public int getValuesCount() {
074: return values.size();
075: }
076:
077: public String getLastValue() {
078: if (values.size() > 0) {
079: String[] valuecomment = values.get(values.size() - 1);
080: return valuecomment[0];
081: } else {
082: return "";
083: }
084: }
085:
086: /**
087: * @return the newvariable
088: */
089: public boolean isNewvariable() {
090: return this .newvariable;
091: }
092:
093: /**
094: * @return the changed
095: */
096: public boolean isChanged() {
097: return this .changed;
098: }
099:
100: /**
101: * @param changed the changed to set
102: */
103: public void setChanged(boolean changed) {
104: this .changed = changed;
105: }
106:
107: public void clearState() {
108: newvariable = false;
109: changed = false;
110: }
111:
112: public String getValueHistoryDetails() {
113: StringBuffer details = new StringBuffer();
114: details.append("<html><body>");
115: details.append("<h3>Details of <b>");
116: details.append(this .name);
117: details.append("</b></h3>");
118: for (int i = values.size() - 1; i >= 0; i--) {
119: String[] valuecomment = values.get(i);
120: details.append(i + 1);
121: details.append(". ");
122: details.append(valuecomment[0]);
123: details.append(" (");
124: details.append(valuecomment[1]);
125: details.append(")<br>");
126: }
127: details.append("</body></html>");
128: return details.toString();
129: }
130:
131: public String toString() {
132: return this.getLastValue();
133: }
134: }
|