| 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 | /** |
| 22 | * Utility class for quickly bunching up components in a panel, arranged in a particular pattern |
| 23 | * @author Martin |
| 24 | */ |
| 25 | public class Panels { |
| 26 | |
| 27 | /** |
| 28 | * Creates a new {@code Panel} with a {@code LinearLayout} layout manager in horizontal mode and adds all the |
| 29 | * components passed in |
| 30 | * @param components Components to be added to the new {@code Panel}, in order |
| 31 | * @return The new {@code Panel} |
| 32 | */ |
| 33 | public static Panel horizontal(Component... components) { |
| 34 | Panel panel = new Panel(); |
| 35 | panel.setLayoutManager(new LinearLayout(Direction.HORIZONTAL)); |
| 36 | for(Component component: components) { |
| 37 | panel.addComponent(component); |
| 38 | } |
| 39 | return panel; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Creates a new {@code Panel} with a {@code LinearLayout} layout manager in vertical mode and adds all the |
| 44 | * components passed in |
| 45 | * @param components Components to be added to the new {@code Panel}, in order |
| 46 | * @return The new {@code Panel} |
| 47 | */ |
| 48 | public static Panel vertical(Component... components) { |
| 49 | Panel panel = new Panel(); |
| 50 | panel.setLayoutManager(new LinearLayout(Direction.VERTICAL)); |
| 51 | for(Component component: components) { |
| 52 | panel.addComponent(component); |
| 53 | } |
| 54 | return panel; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Creates a new {@code Panel} with a {@code GridLayout} layout manager and adds all the components passed in |
| 59 | * @param columns Number of columns in the grid |
| 60 | * @param components Components to be added to the new {@code Panel}, in order |
| 61 | * @return The new {@code Panel} |
| 62 | */ |
| 63 | public static Panel grid(int columns, Component... components) { |
| 64 | Panel panel = new Panel(); |
| 65 | panel.setLayoutManager(new GridLayout(columns)); |
| 66 | for(Component component: components) { |
| 67 | panel.addComponent(component); |
| 68 | } |
| 69 | return panel; |
| 70 | } |
| 71 | |
| 72 | //Cannot instantiate |
| 73 | private Panels() {} |
| 74 | } |