Java tutorial
/* * Copyright (C) 2016 Glauco Knihs. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * * Please contact Glauco Knihs, Rua 10 de Junho, N469, Centro, * Guabiruba-SC, CEP 88360-000, BRAZIL, eglauko@hotmail.com, * if you need additional information or have any questions. */ package org.balisunrise.vaadin.components; import com.vaadin.ui.AbstractComponent; /** * Tamanhos enumerados para componentes. * @author Glauco */ public enum Sizes { /** * Tamanho Mximo */ FULL, /** * Tamanho no definido. */ UNDEFINED, /** * 80% */ BIG, /** * 60% */ MEDIUM, /** * 50% */ HALF, /** * 40% */ SMALL, /** * 25% */ QUARTER, /** * 20% */ VERY_SMALL, /** * 15% */ SIXTH, /** * 10% */ TENTH, /** * 5% */ SMALLEST; public String toSize() { switch (this) { case FULL: return "100%"; case BIG: return "80%"; case MEDIUM: return "60%"; case HALF: return "50%"; case SMALL: return "40%"; case QUARTER: return "25%"; case VERY_SMALL: return "20%"; case SIXTH: return "15%"; case TENTH: return "10%"; case SMALLEST: return "5%"; case UNDEFINED: return ""; default: throw new AssertionError(); } } public int toGridColumns() { switch (this) { case FULL: return 20; case BIG: return 16; case MEDIUM: return 12; case HALF: return 10; case SMALL: return 8; case QUARTER: return 5; case VERY_SMALL: return 4; case SIXTH: return 3; case TENTH: return 2; case SMALLEST: return 1; default: return 1; } } public void applyWidth(AbstractComponent component) { switch (this) { case UNDEFINED: component.setWidthUndefined(); break; default: component.setWidth(this.toSize()); } } }