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.effects;
020:
021: import java.awt.Container;
022:
023: import javax.swing.JComboBox;
024: import javax.swing.JLabel;
025:
026: import com.jeta.forms.components.panel.FormPanel;
027: import com.jeta.forms.gui.effects.ImagePainter;
028: import com.jeta.forms.gui.form.GridView;
029: import com.jeta.forms.store.properties.ImageProperty;
030: import com.jeta.forms.store.properties.effects.PaintProperty;
031: import com.jeta.swingbuilder.gui.images.ImagePropertiesView;
032: import com.jgoodies.forms.layout.CellConstraints;
033: import com.jgoodies.forms.layout.FormLayout;
034: import com.jgoodies.forms.layout.RowSpec;
035:
036: /**
037: * @author Jeff Tassin
038: */
039: public class ImageFillView extends ImagePropertiesView implements
040: PaintView {
041: /**
042: * The preview for the gradient settings
043: */
044: private GridView m_preview;
045:
046: /**
047: * The texture property
048: */
049: private ImageProperty m_image_prop = new ImageProperty();
050: private ImagePainter m_painter = new ImagePainter();
051:
052: /**
053: * ctor
054: */
055: public ImageFillView(GridView preview) {
056: this (preview, null);
057: }
058:
059: /**
060: * ctor
061: */
062: public ImageFillView(GridView preview, PaintProperty pp) {
063: super ("com/jeta/swingbuilder/gui/images/imageProperties.frm",
064: null);
065: FormPanel view = getView();
066: Container form = view.getFormContainer();
067: FormLayout layout = (FormLayout) form.getLayout();
068: layout.appendRow(new RowSpec("2dlu"));
069: layout.appendRow(new RowSpec("pref"));
070: CellConstraints cc = new CellConstraints();
071:
072: JComboBox hbox = new JComboBox(new Object[] { "LEFT", "CENTER",
073: "RIGHT" });
074: hbox.setName(ImageFillNames.ID_HORIZONTAL_ALIGNMENT);
075: form.add(new JLabel("Horizontal Alignment"), cc.xy(1, layout
076: .getRowCount()));
077: form.add(hbox, cc.xy(3, layout.getRowCount()));
078:
079: layout.appendRow(new RowSpec("2dlu"));
080: layout.appendRow(new RowSpec("pref"));
081:
082: JComboBox vbox = new JComboBox(new Object[] { "TOP", "CENTER",
083: "BOTTOM" });
084: vbox.setName(ImageFillNames.ID_VERTICAL_ALIGNMENT);
085: form.add(new JLabel("Vertical Alignment"), cc.xy(1, layout
086: .getRowCount()));
087: form.add(vbox, cc.xy(3, layout.getRowCount()));
088:
089: m_preview = preview;
090: setController(new ImageFillController(this ));
091: if (pp != null) {
092: setPaintProperty(pp);
093: }
094: }
095:
096: /**
097: * @return the property for this view
098: */
099: public PaintProperty getPaintProperty() {
100: return new PaintProperty(getImageProperty());
101: }
102:
103: public ImageProperty getImageProperty() {
104: m_image_prop.setValue(getIconProperty());
105: m_image_prop.setVerticalAlignment(getVerticalAlignment());
106: m_image_prop.setHorizontalAlignment(getHorizontalAlignment());
107: return m_image_prop;
108: }
109:
110: public int getHorizontalAlignment() {
111: String item = (String) getSelectedItem(ImageFillNames.ID_HORIZONTAL_ALIGNMENT);
112: if ("CENTER".equals(item))
113: return ImageProperty.CENTER;
114: else if ("RIGHT".equals(item))
115: return ImageProperty.RIGHT;
116: else
117: return ImageProperty.LEFT;
118: }
119:
120: public int getVerticalAlignment() {
121: String item = (String) getSelectedItem(ImageFillNames.ID_VERTICAL_ALIGNMENT);
122: System.out.println("ImageFillView.getVerticalAlignment: "
123: + item);
124: if ("CENTER".equals(item))
125: return ImageProperty.CENTER;
126: else if ("BOTTOM".equals(item))
127: return ImageProperty.BOTTOM;
128: else
129: return ImageProperty.TOP;
130: }
131:
132: /**
133: * Sets the property for the view
134: */
135: public void setPaintProperty(PaintProperty pp) {
136: try {
137: getController().enableEvents(false);
138: if (pp.getPaintDelegate() instanceof ImageProperty) {
139: ImageProperty tp = (ImageProperty) pp
140: .getPaintDelegate();
141: m_image_prop.setValue(tp);
142: setIconProperty(tp);
143: updatePreview();
144: }
145: } finally {
146: getController().enableEvents(true);
147: }
148: }
149:
150: public void updatePreview() {
151: ImageProperty iprop = getImageProperty();
152: m_painter.setIcon(iprop);
153: m_painter
154: .setHorizontalAlignment(iprop.getHorizontalAlignment());
155: m_painter.setVerticalAlignment(iprop.getVerticalAlignment());
156: m_preview.setBackgroundPainter(m_painter);
157: }
158:
159: }
|