001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hslf.record;
019:
020: import java.io.IOException;
021: import java.io.OutputStream;
022:
023: import org.apache.poi.util.LittleEndian;
024:
025: /**
026: * Master container for Slides. There is one of these for every slide,
027: * and they have certain specific children
028: *
029: * @author Nick Burch
030: */
031:
032: public class Slide extends SheetContainer {
033: private byte[] _header;
034: private static long _type = 1006l;
035:
036: // Links to our more interesting children
037: private SlideAtom slideAtom;
038: private PPDrawing ppDrawing;
039: private ColorSchemeAtom _colorScheme;
040:
041: /**
042: * Returns the SlideAtom of this Slide
043: */
044: public SlideAtom getSlideAtom() {
045: return slideAtom;
046: }
047:
048: /**
049: * Returns the PPDrawing of this Slide, which has all the
050: * interesting data in it
051: */
052: public PPDrawing getPPDrawing() {
053: return ppDrawing;
054: }
055:
056: /**
057: * Set things up, and find our more interesting children
058: */
059: protected Slide(byte[] source, int start, int len) {
060: // Grab the header
061: _header = new byte[8];
062: System.arraycopy(source, start, _header, 0, 8);
063:
064: // Find our children
065: _children = Record.findChildRecords(source, start + 8, len - 8);
066:
067: // Find the interesting ones in there
068: for (int i = 0; i < _children.length; i++) {
069: if (_children[i] instanceof SlideAtom) {
070: slideAtom = (SlideAtom) _children[i];
071: } else if (_children[i] instanceof PPDrawing) {
072: ppDrawing = (PPDrawing) _children[i];
073: }
074:
075: if (ppDrawing != null
076: && _children[i] instanceof ColorSchemeAtom) {
077: _colorScheme = (ColorSchemeAtom) _children[i];
078: }
079: }
080: }
081:
082: /**
083: * Create a new, empty, Slide, along with its required
084: * child records.
085: */
086: public Slide() {
087: _header = new byte[8];
088: LittleEndian.putUShort(_header, 0, 15);
089: LittleEndian.putUShort(_header, 2, (int) _type);
090: LittleEndian.putInt(_header, 4, 0);
091:
092: slideAtom = new SlideAtom();
093: ppDrawing = new PPDrawing();
094:
095: ColorSchemeAtom colorAtom = new ColorSchemeAtom();
096:
097: _children = new Record[] { slideAtom, ppDrawing, colorAtom };
098: }
099:
100: /**
101: * We are of type 1006
102: */
103: public long getRecordType() {
104: return _type;
105: }
106:
107: /**
108: * Write the contents of the record back, so it can be written
109: * to disk
110: */
111: public void writeOut(OutputStream out) throws IOException {
112: writeOut(_header[0], _header[1], _type, _children, out);
113: }
114:
115: public ColorSchemeAtom getColorScheme() {
116: return _colorScheme;
117: }
118: }
|