| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package net.sourceforge.jeuclid.elements.support; |
| 20 | |
|
| 21 | |
import java.awt.Color; |
| 22 | |
import java.awt.geom.Dimension2D; |
| 23 | |
import java.util.ArrayList; |
| 24 | |
import java.util.List; |
| 25 | |
|
| 26 | |
import net.sourceforge.jeuclid.layout.FillRectObject; |
| 27 | |
import net.sourceforge.jeuclid.layout.GraphicsObject; |
| 28 | |
import net.sourceforge.jeuclid.layout.LayoutInfo; |
| 29 | |
import net.sourceforge.jeuclid.layout.LayoutStage; |
| 30 | |
import net.sourceforge.jeuclid.layout.LayoutView; |
| 31 | |
import net.sourceforge.jeuclid.layout.LayoutableNode; |
| 32 | |
|
| 33 | |
import org.w3c.dom.Node; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
public final class ElementListSupport { |
| 44 | |
|
| 45 | 0 | private ElementListSupport() { |
| 46 | |
|
| 47 | 0 | } |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
public static List<Node> createListOfChildren(final Node parent) { |
| 57 | 7185382 | final org.w3c.dom.NodeList childList = parent.getChildNodes(); |
| 58 | 7185382 | final int len = childList.getLength(); |
| 59 | 7185382 | final List<Node> children = new ArrayList<Node>(len); |
| 60 | 47013438 | for (int i = 0; i < len; i++) { |
| 61 | 39828056 | final Node child = childList.item(i); |
| 62 | 39828056 | children.add(child); |
| 63 | |
} |
| 64 | 7185382 | return children; |
| 65 | |
|
| 66 | |
} |
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
public static List<LayoutableNode> createListOfLayoutChildren( |
| 76 | |
final Node parent) { |
| 77 | 204860 | final org.w3c.dom.NodeList childList = parent.getChildNodes(); |
| 78 | 204860 | final int len = childList.getLength(); |
| 79 | 204860 | final List<LayoutableNode> children = new ArrayList<LayoutableNode>(len); |
| 80 | 874110 | for (int i = 0; i < len; i++) { |
| 81 | 669250 | final Node child = childList.item(i); |
| 82 | 669250 | if (child instanceof LayoutableNode) { |
| 83 | 313950 | children.add((LayoutableNode) child); |
| 84 | |
} |
| 85 | |
} |
| 86 | 204860 | return children; |
| 87 | |
|
| 88 | |
} |
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
public static void fillInfoFromChildren(final LayoutView view, |
| 105 | |
final LayoutInfo info, final Node parent, final LayoutStage stage, |
| 106 | |
final Dimension2D borderLeftTop, final Dimension2D borderRightBottom) { |
| 107 | 14421 | float ascentHeight = (float) borderLeftTop.getHeight(); |
| 108 | 14421 | float descentHeight = (float) borderRightBottom.getHeight(); |
| 109 | 14421 | final float startX = (float) borderLeftTop.getWidth(); |
| 110 | 14421 | float width = startX; |
| 111 | 14421 | for (final LayoutableNode child : ElementListSupport |
| 112 | |
.createListOfLayoutChildren(parent)) { |
| 113 | 33858 | final LayoutInfo childInfo = view.getInfo(child); |
| 114 | 33858 | ascentHeight = Math.max(ascentHeight, -childInfo.getPosY(stage) |
| 115 | |
+ childInfo.getAscentHeight(stage)); |
| 116 | 33858 | descentHeight = Math.max(descentHeight, childInfo.getPosY(stage) |
| 117 | |
+ childInfo.getDescentHeight(stage)); |
| 118 | 33858 | width = Math.max(width, childInfo.getPosX(stage) |
| 119 | |
+ childInfo.getWidth(stage)); |
| 120 | 33858 | } |
| 121 | 14421 | info.setAscentHeight(ascentHeight + (float) borderLeftTop.getHeight(), |
| 122 | |
stage); |
| 123 | 14421 | info.setDescentHeight(descentHeight |
| 124 | |
+ (float) borderRightBottom.getHeight(), stage); |
| 125 | 14421 | info.setHorizontalCenterOffset((width + startX) / 2.0f, stage); |
| 126 | 14421 | info.setWidth(width + (float) borderRightBottom.getWidth(), stage); |
| 127 | 14421 | } |
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 139 | |
public static void layoutSequential(final LayoutView view, |
| 140 | |
final LayoutInfo info, final List<LayoutableNode> children, |
| 141 | |
final LayoutStage stage) { |
| 142 | 48090 | float ascentHeight = 0.0f; |
| 143 | 48090 | float descentHeight = 0.0f; |
| 144 | 48090 | float posX = 0.0f; |
| 145 | 48090 | float stretchAscent = 0.0f; |
| 146 | 48090 | float stretchDescent = 0.0f; |
| 147 | |
|
| 148 | 48090 | for (final LayoutableNode child : children) { |
| 149 | 84243 | final LayoutInfo childInfo = view.getInfo(child); |
| 150 | 84243 | ascentHeight = Math.max(ascentHeight, childInfo |
| 151 | |
.getAscentHeight(stage)); |
| 152 | 84243 | descentHeight = Math.max(descentHeight, childInfo |
| 153 | |
.getDescentHeight(stage)); |
| 154 | 84243 | stretchAscent = Math.max(stretchAscent, childInfo |
| 155 | |
.getStretchAscent()); |
| 156 | 84243 | stretchDescent = Math.max(stretchDescent, childInfo |
| 157 | |
.getStretchDescent()); |
| 158 | 84243 | childInfo.moveTo(posX, 0.0f, stage); |
| 159 | 84243 | posX += childInfo.getWidth(stage); |
| 160 | 84243 | } |
| 161 | 48090 | info.setAscentHeight(ascentHeight, stage); |
| 162 | 48090 | info.setDescentHeight(descentHeight, stage); |
| 163 | 48090 | info.setStretchAscent(stretchAscent); |
| 164 | 48090 | info.setStretchDescent(stretchDescent); |
| 165 | 48090 | info.setHorizontalCenterOffset(posX / 2.0f, stage); |
| 166 | 48090 | info.setWidth(posX, stage); |
| 167 | 48090 | } |
| 168 | |
|
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
public static void addBackground(final Color backgroundColor, |
| 182 | |
final LayoutInfo info, final boolean useCeil) { |
| 183 | 21736 | if (backgroundColor != null) { |
| 184 | |
final GraphicsObject fillObject; |
| 185 | 0 | if (useCeil) { |
| 186 | 0 | fillObject = new FillRectObject(backgroundColor, (float) Math |
| 187 | |
.ceil(info.getAscentHeight(LayoutStage.STAGE2)), |
| 188 | |
(float) Math.ceil(info |
| 189 | |
.getDescentHeight(LayoutStage.STAGE2)), |
| 190 | |
(float) Math.ceil(info.getWidth(LayoutStage.STAGE2))); |
| 191 | |
} else { |
| 192 | 0 | fillObject = new FillRectObject(backgroundColor, info |
| 193 | |
.getAscentHeight(LayoutStage.STAGE2), info |
| 194 | |
.getDescentHeight(LayoutStage.STAGE2), info |
| 195 | |
.getWidth(LayoutStage.STAGE2)); |
| 196 | |
|
| 197 | |
} |
| 198 | |
|
| 199 | 0 | info.getGraphicObjects().add(0, fillObject); |
| 200 | |
} |
| 201 | |
|
| 202 | 21736 | } |
| 203 | |
} |