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.BorderFactory;
022: import javax.swing.JSpinner;
023: import javax.swing.SpinnerNumberModel;
024:
025: import com.jeta.forms.store.properties.BorderProperty;
026: import com.jeta.forms.store.properties.LineBorderProperty;
027:
028: /**
029: * View that is used to create and edit bevel borders
030: *
031: * @author Jeff Tassin
032: */
033: public class LineBorderView extends AbstractBorderView {
034:
035: /**
036: * ctor
037: */
038: public LineBorderView() {
039: this (null);
040: }
041:
042: /**
043: * ctor
044: */
045: public LineBorderView(LineBorderProperty bp) {
046: super ("com/jeta/swingbuilder/gui/border/lineBorder.frm");
047: if (bp == null) {
048: setBorderProperty(new LineBorderProperty());
049: } else {
050: setBorderProperty(bp);
051: }
052: setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
053: JSpinner sp = (JSpinner) getView().getComponentByName(
054: LineBorderNames.ID_LINE_THICKNESS);
055: sp.setModel(new SpinnerNumberModel(1, 1, 100, 1));
056: }
057:
058: /**
059: * Creates a border property based on the view inputs
060: */
061: public BorderProperty createBorderProperty() {
062: LineBorderProperty bp = new LineBorderProperty();
063: bp.setLineThickness(getLineThickness());
064: bp
065: .setLineColorProperty(getColorProperty(LineBorderNames.ID_LINE_COLOR_SELECTOR));
066: bp.setCurved(getView().getBoolean(
067: LineBorderNames.ID_ROUNDED_BORDER));
068: bp.setTopPainted(getBoolean(BorderNames.ID_BORDER_TOP));
069: bp.setLeftPainted(getBoolean(BorderNames.ID_BORDER_LEFT));
070: bp.setBottomPainted(getBoolean(BorderNames.ID_BORDER_BOTTOM));
071: bp.setRightPainted(getBoolean(BorderNames.ID_BORDER_RIGHT));
072: setTitle(bp);
073: return bp;
074: }
075:
076: /**
077: * @return a description for this view. Typically used for a title in a
078: * dialog
079: */
080: public String getDescription() {
081: return "Line Border";
082: }
083:
084: /**
085: * @return the line thickness
086: */
087: public int getLineThickness() {
088: JSpinner sp = (JSpinner) getView().getComponentByName(
089: LineBorderNames.ID_LINE_THICKNESS);
090: Integer ival = (Integer) sp.getValue();
091: return ival.intValue();
092: }
093:
094: /**
095: * Sets the line thickness in the view
096: */
097: public void setLineThickness(int thickness) {
098: JSpinner sp = (JSpinner) getView().getComponentByName(
099: LineBorderNames.ID_LINE_THICKNESS);
100: sp.setValue(new Integer(thickness));
101: }
102:
103: /**
104: * Updates this view based on the given border settings
105: */
106: public void setBorderProperty(BorderProperty border) {
107: super .setBorderProperty(border);
108: if (border instanceof LineBorderProperty) {
109: LineBorderProperty bb = (LineBorderProperty) border;
110: setColorProperty(LineBorderNames.ID_LINE_COLOR_SELECTOR, bb
111: .getLineColorProperty());
112: setLineThickness(bb.getLineThickness());
113: getView().setSelected(LineBorderNames.ID_ROUNDED_BORDER,
114: bb.isCurved());
115: getView().setSelected(LineBorderNames.ID_SQUARE_BORDER,
116: !bb.isCurved());
117:
118: setSelected(BorderNames.ID_BORDER_TOP, border
119: .isTopPainted());
120: setSelected(BorderNames.ID_BORDER_LEFT, border
121: .isLeftPainted());
122: setSelected(BorderNames.ID_BORDER_RIGHT, border
123: .isRightPainted());
124: setSelected(BorderNames.ID_BORDER_BOTTOM, border
125: .isBottomPainted());
126: } else {
127: assert (false);
128: }
129: }
130: }
|