Java tutorial
/** * Copyright (c) 2010-2015 Dangelmayr IT GmbH. All rights reserved. * * This file is part of FXL GUI API. * * FXL GUI API 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. * * FXL GUI API 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 FXL GUI API. If not, see <http://www.gnu.org/licenses/>. */ package co.fxl.gui.gwt; import co.fxl.gui.api.IAlignment; import co.fxl.gui.api.IHorizontalPanel; import com.google.gwt.user.client.ui.AbsolutePanel; import com.google.gwt.user.client.ui.HasHorizontalAlignment; import com.google.gwt.user.client.ui.HasVerticalAlignment; import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.Widget; class GWTHorizontalPanel extends GWTPanel<HorizontalPanel, IHorizontalPanel> implements IHorizontalPanel { @SuppressWarnings("unchecked") GWTHorizontalPanel(GWTContainer<?> container) { super((GWTContainer<HorizontalPanel>) container); widget().setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT); widget().setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); } @Override GWTClickHandler<IHorizontalPanel> newGWTClickHandler(IClickListener clickListener) { return new GWTClickHandler<IHorizontalPanel>(this, clickListener); } @Override public void add(Widget widget) { if (innerSpace > 0 && container.widget.getWidgetCount() > 0) addSpace(innerSpace); if (container.widget.getVerticalAlignment().equals(HorizontalPanel.ALIGN_MIDDLE) && widget instanceof HasVerticalAlignment) ((HasVerticalAlignment) widget).setVerticalAlignment(container.widget.getVerticalAlignment()); if (widget instanceof HasHorizontalAlignment) ((HasHorizontalAlignment) widget).setHorizontalAlignment(HorizontalPanel.ALIGN_LEFT); container.widget.add(widget); } @Override public IHorizontalPanel spacing(int pixel) { container.widget.setSpacing(pixel); return this; } @Override public IHorizontalPanel addSpace(int pixel) { if (pixel == 0) return this; Widget p = new AbsolutePanel(); p.setSize(pixel + "px", "1px"); container.widget.add(p); return this; } @Override public IAlignment<IHorizontalPanel> align() { return new GWTHorizontalAlignment<IHorizontalPanel>(this, container.widget); } @Override public IAlignment<IHorizontalPanel> valign() { return new GWTVerticalAlignment<IHorizontalPanel>(this, container.widget); } }