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: SplitWindowItem.java,v 1.12 2007/01/28 21:25:10 jesper Exp $
023: package net.infonode.docking.model;
024:
025: import net.infonode.docking.DockingWindow;
026: import net.infonode.docking.internal.ReadContext;
027: import net.infonode.docking.internal.WriteContext;
028: import net.infonode.docking.properties.SplitWindowProperties;
029: import net.infonode.properties.propertymap.PropertyMap;
030:
031: import java.io.IOException;
032: import java.io.ObjectInputStream;
033: import java.io.ObjectOutputStream;
034: import java.util.ArrayList;
035:
036: /**
037: * @author $Author: jesper $
038: * @version $Revision: 1.12 $
039: */
040: public class SplitWindowItem extends WindowItem {
041: public static final SplitWindowProperties emptyProperties = new SplitWindowProperties();
042:
043: private boolean isHorizontal;
044: private float dividerLocation;
045: private SplitWindowProperties splitWindowProperties;
046: private SplitWindowProperties parentProperties = emptyProperties;
047:
048: public SplitWindowItem() {
049: splitWindowProperties = new SplitWindowProperties(
050: emptyProperties);
051: }
052:
053: public SplitWindowItem(SplitWindowItem windowItem) {
054: super (windowItem);
055: splitWindowProperties = new SplitWindowProperties(windowItem
056: .getSplitWindowProperties().getMap().copy(true, true));
057: splitWindowProperties.getMap().replaceSuperMap(
058: windowItem.getParentSplitWindowProperties().getMap(),
059: emptyProperties.getMap());
060: }
061:
062: public SplitWindowItem(WindowItem leftWindow,
063: WindowItem rightWindow, boolean horizontal,
064: float dividerLocation) {
065: addWindow(leftWindow);
066: addWindow(rightWindow);
067: isHorizontal = horizontal;
068: this .dividerLocation = dividerLocation;
069: }
070:
071: protected DockingWindow createWindow(ViewReader viewReader,
072: ArrayList childWindows) {
073: return childWindows.size() == 0 ? null
074: : childWindows.size() == 1 ? (DockingWindow) childWindows
075: .get(0)
076: : viewReader.createSplitWindow(
077: (DockingWindow) childWindows.get(0),
078: (DockingWindow) childWindows.get(1),
079: this );
080: }
081:
082: public boolean isHorizontal() {
083: return isHorizontal;
084: }
085:
086: public float getDividerLocation() {
087: return dividerLocation;
088: }
089:
090: public void setHorizontal(boolean horizontal) {
091: isHorizontal = horizontal;
092: }
093:
094: public void setDividerLocation(float dividerLocation) {
095: this .dividerLocation = dividerLocation;
096: }
097:
098: public SplitWindowProperties getSplitWindowProperties() {
099: return splitWindowProperties;
100: }
101:
102: public SplitWindowProperties getParentSplitWindowProperties() {
103: return parentProperties;
104: }
105:
106: public void setParentSplitWindowProperties(
107: SplitWindowProperties parentProperties) {
108: splitWindowProperties.getMap().replaceSuperMap(
109: this .parentProperties.getMap(),
110: parentProperties.getMap());
111: this .parentProperties = parentProperties;
112: }
113:
114: public WindowItem copy() {
115: return new SplitWindowItem(this );
116: }
117:
118: public void write(ObjectOutputStream out, WriteContext context,
119: ViewWriter viewWriter) throws IOException {
120: out.writeInt(WindowItemDecoder.SPLIT);
121: super .write(out, context, viewWriter);
122: }
123:
124: public void writeSettings(ObjectOutputStream out,
125: WriteContext context) throws IOException {
126: out.writeBoolean(isHorizontal);
127: out.writeFloat(dividerLocation);
128: super .writeSettings(out, context);
129: }
130:
131: public void readSettings(ObjectInputStream in, ReadContext context)
132: throws IOException {
133: if (context.getVersion() >= 3) {
134: isHorizontal = in.readBoolean();
135: dividerLocation = in.readFloat();
136: }
137:
138: super .readSettings(in, context);
139: }
140:
141: protected PropertyMap getPropertyObject() {
142: return getSplitWindowProperties().getMap();
143: }
144:
145: public String toString() {
146: return "SplitWindow: " + super.toString();
147: }
148:
149: }
|