| 1 | /* |
| 2 | * This file is part of lanterna (http://code.google.com/p/lanterna/). |
| 3 | * |
| 4 | * lanterna is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Lesser General Public License as published by |
| 6 | * the Free Software Foundation, either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * Copyright (C) 2010-2015 Martin |
| 18 | */ |
| 19 | package com.googlecode.lanterna.gui2; |
| 20 | |
| 21 | import com.googlecode.lanterna.input.KeyStroke; |
| 22 | import java.util.Collection; |
| 23 | |
| 24 | /** |
| 25 | * Container is a component that contains a collection of child components. The basic example of an implementation of |
| 26 | * this is the {@code Panel} class which uses a layout manager to size and position the children over its area. Note |
| 27 | * that there is no method for adding components to the container, since this depends on the implementation. In general, |
| 28 | * composites that contains one one (or zero) children, the method for specifying the child is in {@code Composite}. |
| 29 | * Multi-child containers are generally using the {@code Panel} implementation which has an {@code addComponent(..)} |
| 30 | * method. |
| 31 | * @author Martin |
| 32 | */ |
| 33 | public interface Container extends Component { |
| 34 | |
| 35 | /** |
| 36 | * Returns the number of children this container currently has |
| 37 | * @return Number of children currently in this container |
| 38 | */ |
| 39 | int getChildCount(); |
| 40 | |
| 41 | /** |
| 42 | * Returns collection that is to be considered a copy of the list of children contained inside of this object. |
| 43 | * Modifying this list will not affect any internal state. |
| 44 | * @return Child-components inside of this Container |
| 45 | */ |
| 46 | Collection<Component> getChildren(); |
| 47 | |
| 48 | /** |
| 49 | * Returns {@code true} if this container contains the supplied component either directly or indirectly through |
| 50 | * intermediate containers. |
| 51 | * @param component Component to check if it's part of this container |
| 52 | * @return {@code true} if the component is inside this Container, otherwise {@code false} |
| 53 | */ |
| 54 | boolean containsComponent(Component component); |
| 55 | |
| 56 | /** |
| 57 | * Removes the component from the container. This should remove the component from the Container's internal data |
| 58 | * structure as well as call the onRemoved(..) method on the component itself if it was found inside the container. |
| 59 | * @param component Component to remove from the Container |
| 60 | * @return {@code true} if the component existed inside the container and was removed, {@code false} otherwise |
| 61 | */ |
| 62 | boolean removeComponent(Component component); |
| 63 | |
| 64 | /** |
| 65 | * Given an interactable, find the next one in line to receive focus. If the interactable isn't inside this |
| 66 | * container, this method should return {@code null}. |
| 67 | * |
| 68 | * @param fromThis Component from which to get the next interactable, or if |
| 69 | * null, pick the first available interactable |
| 70 | * @return The next interactable component, or null if there are no more |
| 71 | * interactables in the list |
| 72 | */ |
| 73 | Interactable nextFocus(Interactable fromThis); |
| 74 | |
| 75 | /** |
| 76 | * Given an interactable, find the previous one in line to receive focus. If the interactable isn't inside this |
| 77 | * container, this method should return {@code null}. |
| 78 | * |
| 79 | * @param fromThis Component from which to get the previous interactable, |
| 80 | * or if null, pick the last interactable in the list |
| 81 | * @return The previous interactable component, or null if there are no more |
| 82 | * interactables in the list |
| 83 | */ |
| 84 | Interactable previousFocus(Interactable fromThis); |
| 85 | |
| 86 | /** |
| 87 | * If an interactable component inside this container received a keyboard event that wasn't handled, the GUI system |
| 88 | * will recursively send the event to each parent container to give each of them a chance to consume the event. |
| 89 | * Return {@code false} if the implementer doesn't care about this particular keystroke and it will be automatically |
| 90 | * sent up the hierarchy the to next container. If you return {@code true}, the event will stop here and won't be |
| 91 | * reported as unhandled. |
| 92 | * @param key Keystroke that was ignored by the interactable inside this container |
| 93 | * @return {@code true} if this event was handled by this container and shouldn't be processed anymore, |
| 94 | * {@code false} if the container didn't take any action on the event and want to pass it on |
| 95 | */ |
| 96 | boolean handleInput(KeyStroke key); |
| 97 | |
| 98 | /** |
| 99 | * Takes a lookup map and updates it with information about where all the interactables inside of this container |
| 100 | * are located. |
| 101 | * @param interactableLookupMap Interactable map to update |
| 102 | */ |
| 103 | void updateLookupMap(InteractableLookupMap interactableLookupMap); |
| 104 | } |