001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: StringViewMap.java,v 1.7 2005/02/16 11:28:14 jesper Exp $
023: package net.infonode.docking.util;
024:
025: import net.infonode.docking.View;
026:
027: import java.io.IOException;
028: import java.io.ObjectInputStream;
029: import java.io.ObjectOutputStream;
030:
031: /**
032: * A map of views that handles view serialization by assigning a string id to each view.
033: * The id is unique for each view in the map. To guarantee serialization compatibility a view id must remain constant.
034: *
035: * @author $Author: jesper $
036: * @version $Revision: 1.7 $
037: * @since IDW 1.1.0
038: */
039: public class StringViewMap extends AbstractViewMap {
040: /**
041: * Constructor.
042: */
043: public StringViewMap() {
044: }
045:
046: /**
047: * Utility constructor that creates a map with a number of views.
048: * A view gets it's title as id.
049: *
050: * @param views the views to add to the map
051: */
052: public StringViewMap(View[] views) {
053: for (int i = 0; i < views.length; i++)
054: addView(views[i]);
055: }
056:
057: /**
058: * Adds a view to the map.
059: * The view title is used as id.
060: *
061: * @param view the view
062: */
063: public void addView(View view) {
064: addView(view.getTitle(), view);
065: }
066:
067: /**
068: * Adds a view to the map.
069: *
070: * @param id the view id
071: * @param view the view
072: */
073: public void addView(String id, View view) {
074: addView((Object) id, view);
075: }
076:
077: /**
078: * Removes a view with a specific id from the map.
079: *
080: * @param id the view id
081: */
082: public void removeView(String id) {
083: removeView((Object) id);
084: }
085:
086: /**
087: * Returns the view with a specific id.
088: *
089: * @param id the view id
090: * @return the view with the id
091: */
092: public View getView(String id) {
093: return getView((Object) id);
094: }
095:
096: protected void writeViewId(Object id, ObjectOutputStream out)
097: throws IOException {
098: out.writeUTF((String) id);
099: }
100:
101: protected Object readViewId(ObjectInputStream in)
102: throws IOException {
103: return in.readUTF();
104: }
105: }
|