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: WindowDecoder.java,v 1.19 2007/01/28 21:25:10 jesper Exp $
023: package net.infonode.docking;
024:
025: import net.infonode.docking.internal.ReadContext;
026: import net.infonode.docking.model.SplitWindowItem;
027: import net.infonode.docking.model.TabWindowItem;
028: import net.infonode.docking.model.ViewReader;
029: import net.infonode.docking.model.WindowItem;
030:
031: import java.io.IOException;
032: import java.io.ObjectInputStream;
033:
034: /**
035: * @author $Author: jesper $
036: * @version $Revision: 1.19 $
037: */
038: class WindowDecoder {
039: private WindowDecoder() {
040: }
041:
042: static DockingWindow decodeWindow(ObjectInputStream in,
043: ReadContext context) throws IOException {
044: int id = in.readInt();
045:
046: switch (id) {
047: case WindowIds.VIEW:
048: return View.read(in, context);
049:
050: case WindowIds.SPLIT: {
051: SplitWindow w = new SplitWindow(true);
052: return w.oldRead(in, context);
053: }
054:
055: case WindowIds.TAB: {
056: TabWindow w = new TabWindow();
057: return w.oldRead(in, context);
058: }
059:
060: default:
061: throw new IOException("Invalid window ID: " + id + '!');
062: }
063: }
064:
065: static DockingWindow decodeWindow(ObjectInputStream in,
066: ReadContext context, ViewReader viewReader)
067: throws IOException {
068: int id = in.readInt();
069:
070: if (id == WindowIds.VIEW) {
071: return viewReader.readView(in, context);
072: } else {
073: WindowItem windowItem = viewReader.readWindowItem(in,
074: context);
075:
076: switch (id) {
077: case WindowIds.SPLIT: {
078: SplitWindowItem item = (SplitWindowItem) windowItem;
079:
080: if (item == null) {
081: item = new SplitWindowItem();
082: item.readSettings(in, context);
083: }
084:
085: SplitWindow w = new SplitWindow(item.isHorizontal(),
086: item.getDividerLocation(), null, null, item);
087: return w.newRead(in, context, viewReader);
088: }
089:
090: case WindowIds.TAB: {
091: TabWindowItem item = (TabWindowItem) windowItem;
092:
093: if (item == null) {
094: item = new TabWindowItem();
095: item.readSettings(in, context);
096: }
097:
098: TabWindow w = new TabWindow(null, item);
099: return w.newRead(in, context, viewReader);
100: }
101:
102: default:
103: throw new IOException("Invalid window ID: " + id + '!');
104: }
105: }
106: }
107: }
|