Java tutorial
/* * Copyright (c) 2010 Zhihua (Dennis) Jiang * * 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 com.gwtm.ui.client.widgets; import com.gwtm.ui.client.core.Utils; import com.gwtm.ui.client.themes.ThemeConfig; import com.gwtm.ui.client.themes.ThemeConfig.Constants; import com.gwtm.ui.client.themes.ThemeConstants; import com.gwtm.ui.client.themes.ThemeConstants.BackgroundVariant; import com.gwtm.ui.client.themes.ThemeConstants.LabelVariant; import com.gwtm.ui.client.themes.ThemeManager; public class Label extends com.google.gwt.user.client.ui.Label { public LabelVariant labelTemplate = LabelVariant.none; public BackgroundVariant labelBackgroundVariant = BackgroundVariant.none; // 6 attributes very common to change and tryout within gwtdesigner // especially to accomodate widgets into panels for multiple layouts // on some panels, we might want to block users from playing with this, but // this brings more flexibility and if we don't have private boolean horizontalPadding = false; private boolean verticalPadding = false; private boolean horizontalMargin = false; private boolean verticalMargin = false; private boolean fullWidth = false; private boolean fullHeight = false; private boolean inlineStyle = true; public Label() { Utils.Widgets.setPrimaryCssClass(this, ThemeManager.getTheme().label()); setLabelTemplate(labelTemplate); setLabelBackgroundVariant(labelBackgroundVariant); updateUi(this); } public Label(String text) { this(); setText(text); } public LabelVariant getLabelTemplate() { return labelTemplate; } public void setLabelTemplate(LabelVariant labelTemplate) { removeStyleName(this.labelTemplate.toString()); this.labelTemplate = labelTemplate; if (labelTemplate != LabelVariant.none) addStyleName(labelTemplate.toString()); } public BackgroundVariant getLabelBackgroundVariant() { return labelBackgroundVariant; } public void setLabelBackgroundVariant(BackgroundVariant labelBackgroundVariant) { removeStyleName(this.labelBackgroundVariant.toString()); this.labelBackgroundVariant = labelBackgroundVariant; if (labelBackgroundVariant != BackgroundVariant.none) addStyleName(labelBackgroundVariant.toString()); } public boolean isInlineStyle() { return inlineStyle; } public void setInlineStyle(boolean inlineStyle) { this.inlineStyle = inlineStyle; updateUi(this); } public boolean isHorizontalPadding() { return horizontalPadding; } public void setHorizontalPadding(boolean horizontalPadding) { this.horizontalPadding = horizontalPadding; updateUi(this); } public boolean isVerticalPadding() { return verticalPadding; } public void setVerticalPadding(boolean verticalPadding) { this.verticalPadding = verticalPadding; updateUi(this); } public boolean isFullWidth() { return fullWidth; } public void setFullWidth(boolean fullWidth) { this.fullWidth = fullWidth; updateUi(this); } public boolean isHorizontalMargin() { return horizontalMargin; } public void setHorizontalMargin(boolean horizontalMargin) { this.horizontalMargin = horizontalMargin; updateUi(this); } public boolean isVerticalMargin() { return verticalMargin; } public void setVerticalMargin(boolean verticalMargin) { this.verticalMargin = verticalMargin; updateUi(this); } public boolean isFullHeight() { return fullHeight; } public void setFullHeight(boolean fullHeight) { this.fullHeight = fullHeight; updateUi(this); } @Override public void setWordWrap(boolean wrap) { super.setWordWrap(wrap); if (wrap) { Utils.Widgets.setExtensionCssClass(this, ThemeConstants.Extension.wordwrap); } else { Utils.Widgets.removeExtensionCssClass(this, ThemeConstants.Extension.wordwrap); } } private static void updateUi(Label label) { if (label.isInlineStyle()) { label.getElement().setAttribute("style", (label.isHorizontalPadding() ? ThemeConfig.get().getConstant(Constants.CSS_HORIZONTAL_PADDING) : "") + (label.isVerticalPadding() ? ThemeConfig.get().getConstant(Constants.CSS_VERTICAL_PADDING) : "") + (label.isHorizontalMargin() ? ThemeConfig.get().getConstant(Constants.CSS_HORIZONTAL_MARGIN) : "") + (label.isVerticalMargin() ? ThemeConfig.get().getConstant(Constants.CSS_VERTICAL_MARGIN) : "") + (label.isFullHeight() ? ThemeConfig.get().getConstant(Constants.CSS_FULL_HEIGHT) : "") + (label.isFullWidth() ? ThemeConfig.get().getConstant(Constants.CSS_FULL_WIDTH) : "")); } else { label.getElement().setAttribute("style", ""); } } }