001    /*
002     * Copyright 2002 - 2007 JEuclid, http://jeuclid.sf.net
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    /* $Id: LayoutInfoImpl.java,v 88b901bf20fb 2008/06/07 14:12:27 maxberger $ */
018    
019    package net.sourceforge.jeuclid.layout;
020    
021    import java.util.ArrayList;
022    import java.util.List;
023    
024    /**
025     * @version $Revision: 88b901bf20fb $
026     */
027    public class LayoutInfoImpl implements LayoutInfo {
028    
029        private LayoutStage layoutStage;
030    
031        private float ascentHeightS1;
032    
033        private float ascentHeightS2;
034    
035        private float descentHeightS1;
036    
037        private float descentHeightS2;
038    
039        private float horizontalS1;
040    
041        private float horizontalS2;
042    
043        private float widthS1;
044    
045        private float widthS2;
046    
047        private float posXS1;
048    
049        private float posXS2;
050    
051        private float posYS1;
052    
053        private float posYS2;
054    
055        private float stretchAscent = -1.0f;
056    
057        private float stretchDescent = -1.0f;
058    
059        private float stretchWidth = -1.0f;
060    
061        private final List<GraphicsObject> graphicObjects;
062    
063        /**
064         * Default Constructor.
065         */
066        public LayoutInfoImpl() {
067            this.layoutStage = LayoutStage.NONE;
068            this.graphicObjects = new ArrayList<GraphicsObject>();
069        }
070    
071        /** {@inheritDoc} */
072        public LayoutStage getLayoutStage() {
073            return this.layoutStage;
074        }
075    
076        /** {@inheritDoc} */
077        public void setLayoutStage(final LayoutStage newStage) {
078            this.layoutStage = newStage;
079        }
080    
081        /** {@inheritDoc} */
082        public float getAscentHeight(final LayoutStage stage) {
083            if (LayoutStage.STAGE1.equals(stage)) {
084                return this.ascentHeightS1;
085            } else {
086                return this.ascentHeightS2;
087            }
088        }
089    
090        /** {@inheritDoc} */
091        public float getDescentHeight(final LayoutStage stage) {
092            if (LayoutStage.STAGE1.equals(stage)) {
093                return this.descentHeightS1;
094            } else {
095                return this.descentHeightS2;
096            }
097        }
098    
099        /** {@inheritDoc} */
100        public float getHorizontalCenterOffset(final LayoutStage stage) {
101            if (LayoutStage.STAGE1.equals(stage)) {
102                return this.horizontalS1;
103            } else {
104                return this.horizontalS2;
105            }
106        }
107    
108        /** {@inheritDoc} */
109        public float getPosX(final LayoutStage stage) {
110            if (LayoutStage.STAGE1.equals(stage)) {
111                return this.posXS1;
112            } else {
113                return this.posXS2;
114            }
115        }
116    
117        /** {@inheritDoc} */
118        public float getPosY(final LayoutStage stage) {
119            if (LayoutStage.STAGE1.equals(stage)) {
120                return this.posYS1;
121            } else {
122                return this.posYS2;
123            }
124        }
125    
126        /** {@inheritDoc} */
127        public float getWidth(final LayoutStage stage) {
128            if (LayoutStage.STAGE1.equals(stage)) {
129                return this.widthS1;
130            } else {
131                return this.widthS2;
132            }
133        }
134    
135        /** {@inheritDoc} */
136        public void moveTo(final float x, final float y, final LayoutStage stage) {
137            this.posXS2 = x;
138            this.posYS2 = y;
139            if (LayoutStage.STAGE1.equals(stage)) {
140                this.posXS1 = x;
141                this.posYS1 = y;
142            }
143    
144        }
145    
146        /** {@inheritDoc} */
147        public void setAscentHeight(final float ascentHeight,
148                final LayoutStage stage) {
149            this.ascentHeightS2 = ascentHeight;
150            if (LayoutStage.STAGE1.equals(stage)) {
151                this.ascentHeightS1 = ascentHeight;
152            }
153        }
154    
155        /** {@inheritDoc} */
156        public void setDescentHeight(final float descentHeight,
157                final LayoutStage stage) {
158            this.descentHeightS2 = descentHeight;
159            if (LayoutStage.STAGE1.equals(stage)) {
160                this.descentHeightS1 = descentHeight;
161            }
162        }
163    
164        /** {@inheritDoc} */
165        public void setHorizontalCenterOffset(final float newOffset,
166                final LayoutStage stage) {
167            this.horizontalS2 = newOffset;
168            if (LayoutStage.STAGE1.equals(stage)) {
169                this.horizontalS1 = newOffset;
170            }
171        }
172    
173        /** {@inheritDoc} */
174        public void setWidth(final float width, final LayoutStage stage) {
175            this.widthS2 = width;
176            if (LayoutStage.STAGE1.equals(stage)) {
177                this.widthS1 = width;
178            }
179        }
180    
181        /** {@inheritDoc} */
182        public void setGraphicsObject(final GraphicsObject graphicsObject) {
183            this.graphicObjects.clear();
184            this.graphicObjects.add(graphicsObject);
185        }
186    
187        /** {@inheritDoc} */
188        public List<GraphicsObject> getGraphicObjects() {
189            return this.graphicObjects;
190        }
191    
192        /** {@inheritDoc} */
193        public float getStretchWidth() {
194            return this.stretchWidth;
195        }
196    
197        /** {@inheritDoc} */
198        public void setStretchWidth(final float newStretchWidth) {
199            this.stretchWidth = newStretchWidth;
200        }
201    
202        /** {@inheritDoc} */
203        public float getStretchAscent() {
204            if (this.stretchAscent < 0.0f) {
205                return this.ascentHeightS1;
206            } else {
207                return this.stretchAscent;
208            }
209        }
210    
211        /** {@inheritDoc} */
212        public float getStretchDescent() {
213            if (this.stretchDescent < 0.0f) {
214                return this.descentHeightS1;
215            } else {
216                return this.stretchDescent;
217            }
218        }
219    
220        /** {@inheritDoc} */
221        public void setStretchAscent(final float newStretchAscent) {
222            this.stretchAscent = newStretchAscent;
223    
224        }
225    
226        /** {@inheritDoc} */
227        public void setStretchDescent(final float newStretchDescent) {
228            this.stretchDescent = newStretchDescent;
229        }
230    
231        /** {@inheritDoc} */
232        public void shiftVertically(final float offsetY, final LayoutStage stage) {
233            this.posYS2 += offsetY;
234            if (LayoutStage.STAGE1.equals(stage)) {
235                this.posYS1 += offsetY;
236            }
237        }
238    }