| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AbstractElementWithDelegates |
|
| 1.4;1,4 |
| 1 | /* | |
| 2 | * Copyright 2002 - 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: AbstractElementWithDelegates.java,v bc1d5fde7b73 2009/06/01 14:40:54 maxberger $ */ | |
| 18 | ||
| 19 | package net.sourceforge.jeuclid.elements; | |
| 20 | ||
| 21 | import java.util.List; | |
| 22 | ||
| 23 | import net.sourceforge.jeuclid.elements.presentation.AbstractContainer; | |
| 24 | import net.sourceforge.jeuclid.layout.LayoutableNode; | |
| 25 | ||
| 26 | import org.apache.batik.dom.AbstractDocument; | |
| 27 | ||
| 28 | /** | |
| 29 | * Generic class for all mathobjects that can be represented using other Math | |
| 30 | * objects. These math objects use a delegates for the actual display and | |
| 31 | * calculations. | |
| 32 | * <p> | |
| 33 | * To use this class, overwrite {@link #createDelegates()} to create the | |
| 34 | * delegate objects. | |
| 35 | * | |
| 36 | * @version $Revision: bc1d5fde7b73 $ | |
| 37 | */ | |
| 38 | public abstract class AbstractElementWithDelegates extends AbstractContainer { | |
| 39 | ||
| 40 | // TODO: Re-Enable resetting delegates on changeHook! | |
| 41 | private List<LayoutableNode> delegates; | |
| 42 | ||
| 43 | /** | |
| 44 | * Default constructor. Sets MathML Namespace. | |
| 45 | * | |
| 46 | * @param qname | |
| 47 | * Qualified name. | |
| 48 | * @param odoc | |
| 49 | * Owner Document. | |
| 50 | */ | |
| 51 | public AbstractElementWithDelegates(final String qname, | |
| 52 | final AbstractDocument odoc) { | |
| 53 | 2299 | super(qname, odoc); |
| 54 | 2299 | } |
| 55 | ||
| 56 | /** | |
| 57 | * Overwrite this function in your implementation. | |
| 58 | * | |
| 59 | * @return a MathObject representing the real contents. | |
| 60 | */ | |
| 61 | protected abstract List<LayoutableNode> createDelegates(); | |
| 62 | ||
| 63 | private void prepareDelegates() { | |
| 64 | 1045 | if (this.delegates == null) { |
| 65 | 209 | this.delegates = this.createDelegates(); |
| 66 | 209 | for (final LayoutableNode element : this.delegates) { |
| 67 | 627 | ((JEuclidElement) element).setFakeParent(this); |
| 68 | } | |
| 69 | } | |
| 70 | 1045 | } |
| 71 | ||
| 72 | /** {@inheritDoc} */ | |
| 73 | @Override | |
| 74 | public List<LayoutableNode> getChildrenToLayout() { | |
| 75 | 836 | this.prepareDelegates(); |
| 76 | 836 | return this.delegates; |
| 77 | } | |
| 78 | ||
| 79 | /** {@inheritDoc} */ | |
| 80 | @Override | |
| 81 | public List<LayoutableNode> getChildrenToDraw() { | |
| 82 | 209 | this.prepareDelegates(); |
| 83 | 209 | return this.delegates; |
| 84 | } | |
| 85 | ||
| 86 | } |