KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > hssf > model > ConvertAnchor


1 /* ====================================================================
2    Copyright 2004 Apache Software Foundation
3
4    Licensed under the Apache License, Version 2.0 (the "License");
5    you may not use this file except in compliance with the License.
6    You may obtain a copy of the License at
7
8        http://www.apache.org/licenses/LICENSE-2.0
9
10    Unless required by applicable law or agreed to in writing, software
11    distributed under the License is distributed on an "AS IS" BASIS,
12    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13    See the License for the specific language governing permissions and
14    limitations under the License.
15 ==================================================================== */

16
17 package org.apache.poi.hssf.model;
18
19 import org.apache.poi.ddf.EscherRecord;
20 import org.apache.poi.ddf.EscherClientAnchorRecord;
21 import org.apache.poi.ddf.EscherChildAnchorRecord;
22 import org.apache.poi.hssf.usermodel.HSSFAnchor;
23 import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
24 import org.apache.poi.hssf.usermodel.HSSFChildAnchor;
25
26 /**
27  * $Id: ConvertAnchor.java,v 1.3 2004/08/23 08:52:28 glens Exp $
28  */

29 public class ConvertAnchor
30 {
31     public static EscherRecord createAnchor( HSSFAnchor userAnchor )
32     {
33         if (userAnchor instanceof HSSFClientAnchor)
34         {
35             HSSFClientAnchor a = (HSSFClientAnchor) userAnchor;
36
37             EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
38             anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID );
39             anchor.setOptions( (short) 0x0000 );
40             anchor.setFlag( (short) 0 );
41             anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) );
42             anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
43             anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) );
44             anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );
45
46             anchor.setCol2( (short) Math.max(a.getCol1(), a.getCol2()) );
47             anchor.setDx2( (short) Math.max(a.getDx1(), a.getDx2()) );
48             anchor.setRow2( (short) Math.max(a.getRow1(), a.getRow2()) );
49             anchor.setDy2( (short) Math.max(a.getDy1(), a.getDy2() ) );
50             return anchor;
51         }
52         else
53         {
54             HSSFChildAnchor a = (HSSFChildAnchor) userAnchor;
55             EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
56             anchor.setRecordId( EscherChildAnchorRecord.RECORD_ID );
57             anchor.setOptions( (short) 0x0000 );
58             anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
59             anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );
60             anchor.setDx2( (short) Math.max(a.getDx2(), a.getDx1()) );
61             anchor.setDy2( (short) Math.max(a.getDy2(), a.getDy1()) );
62             return anchor;
63         }
64     }
65
66 }
67
Popular Tags