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:
023: import com.jeta.forms.store.properties.BorderProperty;
024: import com.jeta.forms.store.properties.EmptyBorderProperty;
025: import com.jeta.swingbuilder.gui.components.IntegerDocument;
026:
027: /**
028: * View that is used to create and edit bevel borders
029: *
030: * @author Jeff Tassin
031: */
032: public class EmptyBorderView extends AbstractBorderView {
033:
034: /**
035: * ctor
036: */
037: public EmptyBorderView() {
038: this (null);
039: }
040:
041: /**
042: * ctor
043: */
044: public EmptyBorderView(EmptyBorderProperty bp) {
045: super ("com/jeta/swingbuilder/gui/border/emptyBorder.frm");
046: if (bp == null) {
047: setBorderProperty(new EmptyBorderProperty());
048: } else {
049: setBorderProperty(bp);
050: }
051: setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
052: getTextField(EmptyBorderNames.ID_EMPTY_BORDER_TOP).setDocument(
053: new IntegerDocument(false));
054: getTextField(EmptyBorderNames.ID_EMPTY_BORDER_LEFT)
055: .setDocument(new IntegerDocument(false));
056: getTextField(EmptyBorderNames.ID_EMPTY_BORDER_BOTTOM)
057: .setDocument(new IntegerDocument(false));
058: getTextField(EmptyBorderNames.ID_EMPTY_BORDER_RIGHT)
059: .setDocument(new IntegerDocument(false));
060: }
061:
062: /**
063: * Creates a border property based on the view inputs
064: */
065: public BorderProperty createBorderProperty() {
066: EmptyBorderProperty bp = new EmptyBorderProperty(
067: getInteger(EmptyBorderNames.ID_EMPTY_BORDER_TOP),
068: getInteger(EmptyBorderNames.ID_EMPTY_BORDER_LEFT),
069: getInteger(EmptyBorderNames.ID_EMPTY_BORDER_BOTTOM),
070: getInteger(EmptyBorderNames.ID_EMPTY_BORDER_RIGHT));
071: setTitle(bp);
072: return bp;
073: }
074:
075: /**
076: * @return a description for this view. Typically used for a title in a
077: * dialog
078: */
079: public String getDescription() {
080: return "Empty Border";
081: }
082:
083: public int getInteger(String compId) {
084: try {
085: return Integer.parseInt(getView().getText(compId));
086: } catch (Exception e) {
087: return 0;
088: }
089: }
090:
091: /**
092: * Updates this view based on the given border settings
093: */
094: public void setBorderProperty(BorderProperty border) {
095: super .setBorderProperty(border);
096: if (border instanceof EmptyBorderProperty) {
097: EmptyBorderProperty bb = (EmptyBorderProperty) border;
098: getView().setText(EmptyBorderNames.ID_EMPTY_BORDER_TOP,
099: String.valueOf(bb.getTop()));
100: getView().setText(EmptyBorderNames.ID_EMPTY_BORDER_LEFT,
101: String.valueOf(bb.getLeft()));
102: getView().setText(EmptyBorderNames.ID_EMPTY_BORDER_BOTTOM,
103: String.valueOf(bb.getBottom()));
104: getView().setText(EmptyBorderNames.ID_EMPTY_BORDER_RIGHT,
105: String.valueOf(bb.getRight()));
106: } else {
107: assert (false);
108: }
109: }
110:
111: }
|