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.JCheckBox;
022:
023: import com.jeta.forms.components.colors.ColorSelector;
024: import com.jeta.forms.components.panel.FormPanel;
025: import com.jeta.forms.store.properties.BorderProperty;
026: import com.jeta.forms.store.properties.ListItemProperty;
027: import com.jeta.swingbuilder.gui.components.panel.SwingBuilderPanel;
028:
029: /**
030: * Base view that is used to create and edit border properties
031: *
032: * @author Jeff Tassin
033: */
034: public abstract class AbstractBorderView extends SwingBuilderPanel {
035:
036: /**
037: * ctor
038: */
039: public AbstractBorderView(String formPath) {
040: super (formPath);
041: }
042:
043: public FormPanel getView() {
044: return this ;
045: }
046:
047: /**
048: * Creates a border property based on the view inputs
049: */
050: public abstract BorderProperty createBorderProperty();
051:
052: /**
053: * @return a description for this view. Typically used for a title in a
054: * dialog
055: */
056: public abstract String getDescription();
057:
058: /**
059: * Adds a custom 'default' color to the colorselectivew with the given name.
060: * This is needed because the BevelBorder can defines its colors based on
061: * the component associated with the border.
062: */
063: public void addCustomColor(String controlName, String key) {
064: ColorSelector cv = (ColorSelector) getComponentByName(controlName);
065: if (cv != null) {
066: cv.prependColor(key, null);
067: cv.setSelectedColor(key);
068: }
069: }
070:
071: /**
072: * Updates this view based on the given border settings
073: */
074: public void setBorderProperty(BorderProperty border) {
075: JCheckBox cbox = getCheckBox(BorderNames.ID_TITLE_INCLUDE);
076: if (cbox != null)
077: cbox.setSelected(border.isIncludeTitle());
078:
079: setText(BorderNames.ID_TITLE_TEXT_FIELD, border.getTitle());
080:
081: getComboBox(BorderNames.ID_TITLE_POSITION_COMBO)
082: .setSelectedItem(
083: new ListItemProperty(BorderProperty
084: .toPositionString(border.getPosition())));
085: getComboBox(BorderNames.ID_TITLE_JUSTIFICATION_COMBO)
086: .setSelectedItem(
087: new ListItemProperty(BorderProperty
088: .toJustificationString(border
089: .getJustification())));
090:
091: setColorProperty(BorderNames.ID_TITLE_COLOR_SELECTOR, border
092: .getTextColorProperty());
093: }
094:
095: /**
096: * Sets the BorderProperty title settings based on the form inputs
097: */
098: protected void setTitle(BorderProperty border) {
099: border
100: .setIncludeTitle(getBoolean(BorderNames.ID_TITLE_INCLUDE));
101: border.setTitle(getText(BorderNames.ID_TITLE_TEXT_FIELD));
102:
103: Object sel_item = getComboBox(
104: BorderNames.ID_TITLE_JUSTIFICATION_COMBO)
105: .getSelectedItem();
106: if (sel_item != null)
107: sel_item = sel_item.toString();
108:
109: border.setJustification(BorderProperty
110: .fromJustificationString((String) sel_item));
111:
112: sel_item = getComboBox(BorderNames.ID_TITLE_POSITION_COMBO)
113: .getSelectedItem();
114: if (sel_item != null)
115: sel_item = sel_item.toString();
116:
117: border.setPosition(BorderProperty
118: .fromPositionString((String) sel_item));
119:
120: border
121: .setTextColorProperty(getColorProperty(BorderNames.ID_TITLE_COLOR_SELECTOR));
122: }
123:
124: }
|