Title: Group Description: A Group is an element that is made of other elements. The group's position, size, visibility and transformation do affect the elements in the group. The group's style doesn't, though. @author Francisco Esquembre @version March 2005 @see Style
| 26 | * @see Style |
| 27 | */ |
| 28 | public class Group extends Element implements org.opensourcephysics.display3d.core.Group { |
| 29 | // Implementation variables |
| 30 | private ArrayList<org.opensourcephysics.display3d.simple3d.Element> elementList = new ArrayList<org.opensourcephysics.display3d.simple3d.Element>(); |
| 31 | private ArrayList<Object3D> list3D = new ArrayList<Object3D>(); // The list of Objects3D |
| 32 | private Object3D[] minimalObjects = new Object3D[1]; // The array of Objects3D |
| 33 | |
| 34 | // ---------------------------------------------------- |
| 35 | // Implementation of core.Group |
| 36 | // ---------------------------------------------------- |
| 37 | @Override |
| 38 | public void addElement(org.opensourcephysics.display3d.core.Element element) { |
| 39 | if(!(element instanceof Element)) { |
| 40 | throw new UnsupportedOperationException("Can't add element to group (incorrect implementation)"); //$NON-NLS-1$ |
| 41 | } |
| 42 | if(!elementList.contains(element)) { |
| 43 | elementList.add((org.opensourcephysics.display3d.simple3d.Element) element); |
| 44 | } |
| 45 | ((Element) element).setGroup(this); |
| 46 | } |
| 47 | |
| 48 | public void addElements(java.util.Collection<org.opensourcephysics.display3d.core.Element> elements) { |
| 49 | if(elements!=null) { |
| 50 | Iterator<?> it = elements.iterator(); |
| 51 | while(it.hasNext()) { |
| 52 | Object obj = it.next(); |
| 53 | if(obj instanceof Element) { |
| 54 | addElement((Element) obj); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public void removeElement(org.opensourcephysics.display3d.core.Element element) { |
| 62 | elementList.remove(element); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public void removeAllElements() { |
| 67 | elementList.clear(); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public synchronized List<org.opensourcephysics.display3d.core.Element> getElements() { |
| 72 | return new ArrayList<org.opensourcephysics.display3d.core.Element>(elementList); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public org.opensourcephysics.display3d.core.Element getElement(int index) { |
| 77 | try { |
| 78 | return elementList.get(index); |
| 79 | } catch(IndexOutOfBoundsException exc) { |
| 80 | return null; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // ---------------------------------------------------- |
| 85 | // Abstract part of Element |