PageRenderTime 79ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/components/forks/poi/src/loci/poi/hssf/model/ConvertAnchor.java

http://github.com/openmicroscopy/bioformats
Java | 90 lines | 42 code | 7 blank | 41 comment | 1 complexity | 4a104008df6507ccad1c60c8d405747e MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, BSD-2-Clause, MPL-2.0-no-copyleft-exception
  1. /*
  2. * #%L
  3. * Fork of Apache Jakarta POI.
  4. * %%
  5. * Copyright (C) 2008 - 2013 Open Microscopy Environment:
  6. * - Board of Regents of the University of Wisconsin-Madison
  7. * - Glencoe Software, Inc.
  8. * - University of Dundee
  9. * %%
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * #L%
  22. */
  23. /* ====================================================================
  24. Licensed to the Apache Software Foundation (ASF) under one or more
  25. contributor license agreements. See the NOTICE file distributed with
  26. this work for additional information regarding copyright ownership.
  27. The ASF licenses this file to You under the Apache License, Version 2.0
  28. (the "License"); you may not use this file except in compliance with
  29. the License. You may obtain a copy of the License at
  30. http://www.apache.org/licenses/LICENSE-2.0
  31. Unless required by applicable law or agreed to in writing, software
  32. distributed under the License is distributed on an "AS IS" BASIS,
  33. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. See the License for the specific language governing permissions and
  35. limitations under the License.
  36. ==================================================================== */
  37. package loci.poi.hssf.model;
  38. import loci.poi.ddf.EscherRecord;
  39. import loci.poi.ddf.EscherClientAnchorRecord;
  40. import loci.poi.ddf.EscherChildAnchorRecord;
  41. import loci.poi.hssf.usermodel.HSSFAnchor;
  42. import loci.poi.hssf.usermodel.HSSFClientAnchor;
  43. import loci.poi.hssf.usermodel.HSSFChildAnchor;
  44. /**
  45. * $Id: ConvertAnchor.java 562536 2007-08-03 18:09:41Z yegor $
  46. */
  47. public class ConvertAnchor
  48. {
  49. public static EscherRecord createAnchor( HSSFAnchor userAnchor )
  50. {
  51. if (userAnchor instanceof HSSFClientAnchor)
  52. {
  53. HSSFClientAnchor a = (HSSFClientAnchor) userAnchor;
  54. EscherClientAnchorRecord anchor = new EscherClientAnchorRecord();
  55. anchor.setRecordId( EscherClientAnchorRecord.RECORD_ID );
  56. anchor.setOptions( (short) 0x0000 );
  57. anchor.setFlag( (short) a.getAnchorType() );
  58. anchor.setCol1( (short) Math.min(a.getCol1(), a.getCol2()) );
  59. anchor.setDx1( (short) a.getDx1() );
  60. anchor.setRow1( (short) Math.min(a.getRow1(), a.getRow2()) );
  61. anchor.setDy1( (short) a.getDy1() );
  62. anchor.setCol2( (short) Math.max(a.getCol1(), a.getCol2()) );
  63. anchor.setDx2( (short) a.getDx2() );
  64. anchor.setRow2( (short) Math.max(a.getRow1(), a.getRow2()) );
  65. anchor.setDy2( (short) a.getDy2() );
  66. return anchor;
  67. }
  68. else
  69. {
  70. HSSFChildAnchor a = (HSSFChildAnchor) userAnchor;
  71. EscherChildAnchorRecord anchor = new EscherChildAnchorRecord();
  72. anchor.setRecordId( EscherChildAnchorRecord.RECORD_ID );
  73. anchor.setOptions( (short) 0x0000 );
  74. anchor.setDx1( (short) Math.min(a.getDx1(), a.getDx2()) );
  75. anchor.setDy1( (short) Math.min(a.getDy1(), a.getDy2()) );
  76. anchor.setDx2( (short) Math.max(a.getDx2(), a.getDx1()) );
  77. anchor.setDy2( (short) Math.max(a.getDy2(), a.getDy1()) );
  78. return anchor;
  79. }
  80. }
  81. }