001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.gui.border;
020:
021: import javax.swing.JSpinner;
022: import javax.swing.SpinnerNumberModel;
023:
024: import com.jeta.forms.store.properties.BorderProperty;
025: import com.jeta.forms.store.properties.ColorProperty;
026: import com.jeta.forms.store.properties.ShadowBorderProperty;
027: import com.jeta.open.i18n.I18N;
028:
029: /**
030: * A view for creating and editing shadow border.s
031: *
032: * @author Jeff Tassin
033: */
034: public class ShadowBorderView extends AbstractBorderView {
035:
036: public ShadowBorderView() {
037: super ("com/jeta/swingbuilder/gui/border/shadowBorder.frm");
038:
039: JSpinner sp = getSpinner(ShadowBorderNames.ID_THICKNESS_SPINNER);
040: sp.setModel(new SpinnerNumberModel(1, 1, 100, 1));
041: sp.setValue(new Integer(1));
042: setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10,
043: 10, 10));
044: }
045:
046: /**
047: * Creates a border property based on the view inputs
048: */
049: public BorderProperty createBorderProperty() {
050: return new ShadowBorderProperty(getType(), getThickness(),
051: getStartColor(), getEndColor(), getSymmetric());
052: }
053:
054: /**
055: * @return a description for this view. Typically used for a title in a
056: * dialog
057: */
058: public String getDescription() {
059: return I18N.getLocalizedMessage("Shadow Border");
060: }
061:
062: public ColorProperty getStartColor() {
063: return getColorProperty(ShadowBorderNames.ID_START_COLOR);
064: }
065:
066: public ColorProperty getEndColor() {
067: return getColorProperty(ShadowBorderNames.ID_END_COLOR);
068: }
069:
070: public boolean getSymmetric() {
071: return getBoolean(ShadowBorderNames.ID_SYMMETRIC);
072: }
073:
074: /**
075: * @return the type of border selected (ShadowBorderProperty.SOLID or
076: * GRADIENT)
077: */
078: public int getType() {
079: return isSelected(ShadowBorderNames.ID_SOLID_RADIO) ? ShadowBorderProperty.SOLID
080: : ShadowBorderProperty.GRADIENT;
081: }
082:
083: /**
084: * @return the thickness of the border
085: */
086: public int getThickness() {
087: SpinnerNumberModel model = (SpinnerNumberModel) getSpinner(
088: ShadowBorderNames.ID_THICKNESS_SPINNER).getModel();
089: Integer value = (Integer) model.getValue();
090: return value.intValue();
091: }
092:
093: /**
094: * Updates this view based on the given border settings
095: */
096: public void setBorderProperty(BorderProperty border) {
097: if (border instanceof ShadowBorderProperty) {
098: ShadowBorderProperty sp = (ShadowBorderProperty) border;
099: setColorProperty(ShadowBorderNames.ID_START_COLOR, sp
100: .getStartColor());
101: setColorProperty(ShadowBorderNames.ID_END_COLOR, sp
102: .getEndColor());
103: SpinnerNumberModel model = (SpinnerNumberModel) getSpinner(
104: ShadowBorderNames.ID_THICKNESS_SPINNER).getModel();
105: model.setValue(new Integer(sp.getThickness()));
106: setSelected(ShadowBorderNames.ID_SOLID_RADIO,
107: (sp.getType() == ShadowBorderProperty.SOLID));
108: setSelected(ShadowBorderNames.ID_GRADIENT_RADIO, (sp
109: .getType() == ShadowBorderProperty.GRADIENT));
110: setSelected(ShadowBorderNames.ID_SYMMETRIC, sp
111: .isSymmetric());
112: } else {
113: assert (false);
114: }
115: }
116:
117: }
|