| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| HAlign |
|
| 4.0;4 | ||||
| HAlign$1 |
|
| 4.0;4 |
| 1 | /* | |
| 2 | * Copyright 2007 - 2007 JEuclid, http://jeuclid.sf.net | |
| 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 | /* $Id: HAlign.java,v 8afef6dd0d58 2007/09/14 08:29:58 maxberger $ */ | |
| 18 | ||
| 19 | package net.sourceforge.jeuclid.elements.support.attributes; | |
| 20 | ||
| 21 | import net.sourceforge.jeuclid.layout.LayoutInfo; | |
| 22 | import net.sourceforge.jeuclid.layout.LayoutStage; | |
| 23 | ||
| 24 | /** | |
| 25 | * @version $Revision: 8afef6dd0d58 $ | |
| 26 | */ | |
| 27 | 1254 | public enum HAlign { |
| 28 | /** Left align. */ | |
| 29 | 209 | LEFT, |
| 30 | /** Center align. */ | |
| 31 | 209 | CENTER, |
| 32 | /** Right align. */ | |
| 33 | 209 | RIGHT; |
| 34 | /** constant for center align. */ | |
| 35 | public static final String ALIGN_CENTER = "center"; | |
| 36 | ||
| 37 | /** constant for right align. */ | |
| 38 | public static final String ALIGN_RIGHT = "right"; | |
| 39 | ||
| 40 | /** | |
| 41 | * Parse an Alignment String. | |
| 42 | * | |
| 43 | * @param alignString | |
| 44 | * String to parse. | |
| 45 | * @param defaultt | |
| 46 | * default value. | |
| 47 | * @return a HAlign value. | |
| 48 | */ | |
| 49 | public static HAlign parseString(final String alignString, | |
| 50 | final HAlign defaultt) { | |
| 51 | final HAlign retVal; | |
| 52 | 11286 | if (HAlign.ALIGN_CENTER.equalsIgnoreCase(alignString)) { |
| 53 | 11286 | retVal = CENTER; |
| 54 | 0 | } else if ("left".equalsIgnoreCase(alignString)) { |
| 55 | 0 | retVal = LEFT; |
| 56 | 0 | } else if (HAlign.ALIGN_RIGHT.equalsIgnoreCase(alignString)) { |
| 57 | 0 | retVal = RIGHT; |
| 58 | } else { | |
| 59 | 0 | retVal = defaultt; |
| 60 | } | |
| 61 | 11286 | return retVal; |
| 62 | } | |
| 63 | ||
| 64 | /** | |
| 65 | * Retrieve H-Align offset. | |
| 66 | * | |
| 67 | * @param stage | |
| 68 | * current Layout Stage | |
| 69 | * @param info | |
| 70 | * Info object to examine | |
| 71 | * @param width | |
| 72 | * Total width | |
| 73 | * @return Alignment offset to add to left. | |
| 74 | */ | |
| 75 | public float getHAlignOffset(final LayoutStage stage, | |
| 76 | final LayoutInfo info, final float width) { | |
| 77 | final float offset; | |
| 78 | 11286 | switch (this) { |
| 79 | case LEFT: | |
| 80 | 0 | offset = 0.0f; |
| 81 | 0 | break; |
| 82 | case RIGHT: | |
| 83 | 0 | offset = width - info.getWidth(stage); |
| 84 | 0 | break; |
| 85 | case CENTER: | |
| 86 | 11286 | offset = width / 2.0f - info.getHorizontalCenterOffset(stage); |
| 87 | 11286 | break; |
| 88 | default: | |
| 89 | 0 | assert false; |
| 90 | 627 | offset = 0.0f; |
| 91 | } | |
| 92 | 11286 | return offset; |
| 93 | } | |
| 94 | ||
| 95 | } |