// Copyright 2012 Georg-August-Universität Göttingen, Germany // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package de.ugoe.cs.autoquest.eventcore.guimodel; import java.util.Collections; import java.util.LinkedList; import java.util.List; /** *

* This class is a dummy GUI element to represent groups of GUI elements. A group of GUI elements * can be integrated in any GUI model using the method * {@link GUIModel#groupGUIElements(java.util.List, String)}. A group has the same behavior as * any other parent GUI element. *

* * @author Patrick Harms */ public class GUIElementGroup extends AbstractDefaultGUIElement { /** *

* default serial version UID *

*/ private static final long serialVersionUID = 1L; /** * the list of grouped GUIElements */ private List groupedGUIElements = new LinkedList(); /** *

* instantiates a GUI element group with a name and its optional parent GUI element *

* * @param groupName the name of the GUI element group * @param parent the optional parent GUI element of the group * @param guiModel the GUI model to which the group will belong */ public GUIElementGroup(String groupName, IGUIElement parent, GUIModel guiModel) { super(new GroupSpecification(groupName), parent); super.setGUIModel(guiModel); } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(IGUIElementSpec) */ @Override public final void updateSpecification(IGUIElementSpec furtherSpec) { // do nothing } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform() */ @Override public String getPlatform() { return "none"; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier() */ @Override public String getStringIdentifier() { return ((GroupSpecification) super.getSpecification()).name; } /* (non-Javadoc) * @see java.lang.Object#toString() */ @Override public String toString() { return getStringIdentifier(); } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getView() */ @Override public IGUIView getView() { return null; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement) */ @Override public double getDistanceTo(IGUIElement otherElement) { if (equals(otherElement)) { return 0.0; } else if (super.getParent() != null) { return super.getParent().getDistanceTo(otherElement); } else { return 1.0; } } /** *

* returns the list of GUI elements belonging to this group. *

* * @return the GUI elements belonging to this group * */ public List getGroupedElements() { return Collections.unmodifiableList(groupedGUIElements); } /** *

* allows adding a new GUI element to the group *

* * @param guiElement the new member of the group */ void addToGroup(IGUIElement guiElement) { this.groupedGUIElements.add(guiElement); } /** *

* internally required GUI element specification for a GUI element group. This is just a wrapper * for a name of a GUI element group *

* * @author Patrick Harms */ private static class GroupSpecification implements IGUIElementSpec { /** *

* default serial version UID *

*/ private static final long serialVersionUID = 1L; /** *

* the name of the GUI element group represented by this specification *

*/ private String name; /** *

* instantiates the group specification with the given name. Two group specifications * are only similar, if their names match. *

* * @param name the name of the group */ private GroupSpecification(String name) { super(); this.name = name; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType() */ @Override public String getType() { return "GUI element group"; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy() */ @Override public String[] getTypeHierarchy() { return new String[] { getType() }; } /* (non-Javadoc) * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getSimilarity(IGUIElementSpec) */ @Override public boolean getSimilarity(IGUIElementSpec other) { return (other instanceof GroupSpecification) && name.equals(((GroupSpecification) other).name); } } }