1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.page;
14 import java.io.IOException;
15 import java.io.Serializable;
16 import java.io.StreamCorruptedException;
18 import org.simantics.utils.page.PageCentering;
19 import org.simantics.utils.page.PageDesc;
20 import org.simantics.utils.page.PageOrientation;
23 * A serializable wrapper for {@link PageDesc}.
25 public class SerializablePageDesc implements Serializable {
27 private static final long serialVersionUID = -1992775876802871858L;
29 private transient PageDesc desc;
31 public SerializablePageDesc(PageDesc desc) {
35 public PageDesc getDesc() {
40 public String toString() {
41 return String.format("%s [%s]", getClass().getSimpleName(), desc.toString());
44 private void writeObject(java.io.ObjectOutputStream out) throws IOException {
45 out.defaultWriteObject();
46 out.writeUTF(desc.getText());
47 out.writeDouble(desc.getWidth());
48 out.writeDouble(desc.getHeight());
49 out.writeByte(desc.getOrientation().ordinal());
50 out.writeByte(desc.getCentering().ordinal());
53 private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
54 in.defaultReadObject();
55 String text = in.readUTF();
56 double widthInMM = in.readDouble();
57 double heightInMM = in.readDouble();
58 byte o = in.readByte();
59 byte c = in.readByte();
60 PageOrientation[] orientations = PageOrientation.values();
61 if (o < 0 || o >= orientations.length)
62 throw new StreamCorruptedException("invalid orientation: " + o);
63 PageOrientation orientation = orientations[o];
64 PageCentering[] centerings = PageCentering.values();
65 if (c < 0 || c >= centerings.length)
66 throw new StreamCorruptedException("invalid centering: " + c);
67 PageCentering centering = centerings[c];
69 desc = new PageDesc(text, orientation, centering, widthInMM, heightInMM);