01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hssf.model;
19:
20: import org.apache.poi.ddf.EscherRecord;
21: import org.apache.poi.ddf.EscherClientAnchorRecord;
22: import org.apache.poi.ddf.EscherChildAnchorRecord;
23: import org.apache.poi.hssf.usermodel.HSSFAnchor;
24: import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
25: import org.apache.poi.hssf.usermodel.HSSFChildAnchor;
26:
27: /**
28: * $Id: ConvertAnchor.java 562536 2007-08-03 18:09:41Z yegor $
29: */
30: public class ConvertAnchor {
31: public static EscherRecord createAnchor(HSSFAnchor userAnchor) {
32: if (userAnchor instanceof HSSFClientAnchor) {
33: HSSFClientAnchor a = (HSSFClientAnchor) userAnchor;
34:
35: EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
36: anchor.setRecordId(EscherClientAnchorRecord.RECORD_ID);
37: anchor.setOptions((short) 0x0000);
38: anchor.setFlag((short) a.getAnchorType());
39: anchor.setCol1((short) Math.min(a.getCol1(), a.getCol2()));
40: anchor.setDx1((short) a.getDx1());
41: anchor.setRow1((short) Math.min(a.getRow1(), a.getRow2()));
42: anchor.setDy1((short) a.getDy1());
43:
44: anchor.setCol2((short) Math.max(a.getCol1(), a.getCol2()));
45: anchor.setDx2((short) a.getDx2());
46: anchor.setRow2((short) Math.max(a.getRow1(), a.getRow2()));
47: anchor.setDy2((short) a.getDy2());
48: return anchor;
49: } else {
50: HSSFChildAnchor a = (HSSFChildAnchor) userAnchor;
51: EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
52: anchor.setRecordId(EscherChildAnchorRecord.RECORD_ID);
53: anchor.setOptions((short) 0x0000);
54: anchor.setDx1((short) Math.min(a.getDx1(), a.getDx2()));
55: anchor.setDy1((short) Math.min(a.getDy1(), a.getDy2()));
56: anchor.setDx2((short) Math.max(a.getDx2(), a.getDx1()));
57: anchor.setDy2((short) Math.max(a.getDy2(), a.getDy1()));
58: return anchor;
59: }
60: }
61:
62: }
|