001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.common.filters;
042:
043: import java.util.Map;
044: import java.util.Vector;
045:
046: /**
047: *
048: * @author Tomas Hurka
049: * @author Jiri Sedlacek
050: */
051: public final class DefinedFilterSets {
052: //~ Instance fields ----------------------------------------------------------------------------------------------------------
053:
054: private final Vector definedFilterSets;
055:
056: //~ Constructors -------------------------------------------------------------------------------------------------------------
057:
058: /** Creates a new instance of DefinedFilterSets */
059: public DefinedFilterSets() {
060: definedFilterSets = new Vector();
061: }
062:
063: public DefinedFilterSets(final DefinedFilterSets filterSets) {
064: this ();
065: setValuesFrom(filterSets);
066: }
067:
068: //~ Methods ------------------------------------------------------------------------------------------------------------------
069:
070: public FilterSet getFilterSet(final String filterSetName) {
071: final int filterSetIndex = getFilterSetIndex(filterSetName);
072:
073: if (filterSetIndex == -1) {
074: return null;
075: }
076:
077: return getFilterSetAt(filterSetIndex);
078: }
079:
080: public FilterSet getFilterSetAt(final int index) {
081: return (FilterSet) definedFilterSets.get(index);
082: }
083:
084: public int getFilterSetIndex(final String filterSetName) {
085: for (int i = 0; i < definedFilterSets.size(); i++) {
086: if (getFilterSetAt(i).getFilterSetName().equals(
087: filterSetName)) {
088: return i;
089: }
090: }
091:
092: return -1;
093: }
094:
095: public int getFilterSetsCount() {
096: return definedFilterSets.size();
097: }
098:
099: public void setValuesFrom(final DefinedFilterSets filterSets) {
100: definedFilterSets.clear();
101:
102: for (int i = 0; i < filterSets.getFilterSetsCount(); i++) {
103: definedFilterSets.add(new FilterSet(filterSets
104: .getFilterSetAt(i)));
105: }
106: }
107:
108: public void addFilterSet(final FilterSet filterSet) {
109: if (filterSet == null) {
110: return;
111: }
112:
113: definedFilterSets.add(filterSet);
114: }
115:
116: public void clear() {
117: definedFilterSets.clear();
118: }
119:
120: public String debug() {
121: final StringBuffer sb = new StringBuffer();
122:
123: sb.append("DefinedFilterSets:"); //NOI18N
124: sb.append("\n"); //NOI18N
125:
126: for (int i = 0; i < definedFilterSets.size(); i++) {
127: sb.append(((FilterSet) definedFilterSets.get(i)).debug());
128: sb.append("\n"); //NOI18N
129: }
130:
131: return sb.toString();
132: }
133:
134: public DefinedFilterSets load(final Map props) {
135: clear();
136:
137: int index = 0;
138:
139: while (props.get("FilterSet-" + index + "-name") != null) { //NOI18N
140: addFilterSet(new FilterSet().load(props, index));
141: index++;
142: }
143:
144: return this ;
145: }
146:
147: public void moveFilterSetDown(final int index) {
148: if (index > (definedFilterSets.size() - 2)) {
149: return;
150: }
151:
152: final FilterSet filterSet = (FilterSet) definedFilterSets
153: .remove(index);
154: definedFilterSets.add(index + 1, filterSet);
155: }
156:
157: public void moveFilterSetUp(final int index) {
158: if (index < 1) {
159: return;
160: }
161:
162: final FilterSet filterSet = (FilterSet) definedFilterSets
163: .remove(index);
164: definedFilterSets.add(index - 1, filterSet);
165: }
166:
167: public void removeFilterSet(final FilterSet filterSet) {
168: if (filterSet == null) {
169: return;
170: }
171:
172: definedFilterSets.remove(filterSet);
173: }
174:
175: public void removeFilterSet(final int index) {
176: definedFilterSets.remove(index);
177: }
178:
179: public void store(final Map props) {
180: for (int i = 0; i < definedFilterSets.size(); i++) {
181: ((FilterSet) definedFilterSets.get(i)).store(props, i);
182: }
183: }
184: }
|