01: /*
02: * Copyright (C) 2004 NNL Technology AB
03: * Visit www.infonode.net for information about InfoNode(R)
04: * products and how to contact NNL Technology AB.
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
19: * MA 02111-1307, USA.
20: */
21:
22: // $Id: AbstractWindowLocation.java,v 1.15 2005/03/17 16:19:37 jesper Exp $
23: package net.infonode.docking.location;
24:
25: import net.infonode.docking.DockingWindow;
26: import net.infonode.docking.RootWindow;
27: import net.infonode.docking.internalutil.InternalDockingUtil;
28: import net.infonode.util.IntList;
29:
30: import java.io.IOException;
31: import java.io.ObjectInputStream;
32: import java.io.ObjectOutputStream;
33: import java.lang.ref.WeakReference;
34:
35: /**
36: * @author $Author: jesper $
37: * @version $Revision: 1.15 $
38: */
39: abstract public class AbstractWindowLocation implements WindowLocation {
40: private WindowLocation parentLocation;
41: private WeakReference window;
42:
43: abstract protected boolean set(DockingWindow parent,
44: DockingWindow child);
45:
46: protected AbstractWindowLocation(DockingWindow window,
47: WindowLocation parentLocation) {
48: this .window = new WeakReference(window);
49: this .parentLocation = parentLocation;
50: }
51:
52: protected AbstractWindowLocation() {
53: }
54:
55: public boolean set(DockingWindow window) {
56: DockingWindow w = getWindow();
57:
58: if (w != null)
59: set(w, window);
60: else if (parentLocation != null)
61: parentLocation.set(window);
62:
63: return true;
64: }
65:
66: private DockingWindow getWindow() {
67: if (window == null)
68: return null;
69:
70: DockingWindow w = (DockingWindow) window.get();
71: return w != null && w.getRootWindow() != null
72: && !w.isMinimized() ? w : null;
73: }
74:
75: public void write(ObjectOutputStream out) throws IOException {
76: out.writeBoolean(parentLocation != null);
77:
78: if (parentLocation != null)
79: parentLocation.write(out);
80:
81: DockingWindow w = getWindow();
82: out.writeBoolean(w != null);
83:
84: if (w != null) {
85: InternalDockingUtil.getWindowPath(w).write(out);
86: }
87: }
88:
89: protected void read(ObjectInputStream in, RootWindow rootWindow)
90: throws IOException {
91: parentLocation = in.readBoolean() ? LocationDecoder.decode(in,
92: rootWindow) : null;
93: window = in.readBoolean() ? new WeakReference(
94: InternalDockingUtil.getWindow(rootWindow, IntList
95: .decode(in))) : null;
96: }
97:
98: }
|