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.event.ActionEvent;
022: import java.awt.event.ActionListener;
023:
024: import com.jeta.forms.gui.effects.TexturePainter;
025: import com.jeta.forms.gui.form.GridView;
026: import com.jeta.forms.store.properties.effects.PaintProperty;
027: import com.jeta.forms.store.properties.effects.TextureProperty;
028: import com.jeta.swingbuilder.gui.images.ImagePropertiesController;
029: import com.jeta.swingbuilder.gui.images.ImagePropertiesNames;
030: import com.jeta.swingbuilder.gui.images.ImagePropertiesView;
031:
032: /**
033: * @author Jeff Tassin
034: */
035: public class TextureView extends ImagePropertiesView implements
036: PaintView {
037: /**
038: * The preview for the gradient settings
039: */
040: private GridView m_preview;
041:
042: /**
043: * The texture property
044: */
045: private TextureProperty m_texture_prop = new TextureProperty();
046: private TexturePainter m_painter = new TexturePainter();
047:
048: /**
049: * ctor
050: */
051: public TextureView(GridView preview) {
052: this (preview, null);
053: }
054:
055: /**
056: * ctor
057: */
058: public TextureView(GridView preview, PaintProperty pp) {
059: super ("com/jeta/swingbuilder/gui/images/imageProperties.frm",
060: null);
061: m_preview = preview;
062: setController(new TextureViewController());
063: if (pp != null) {
064: initialize((TextureProperty) pp.getPaintDelegate());
065: }
066: }
067:
068: /**
069: * @return the property for this view
070: */
071: public PaintProperty getPaintProperty() {
072: return new PaintProperty(getTextureProperty());
073: }
074:
075: public TextureProperty getTextureProperty() {
076: m_texture_prop.setIconProperty(getIconProperty());
077: return m_texture_prop;
078: }
079:
080: /**
081: * Initializes the view
082: */
083: public void initialize(TextureProperty tp) {
084: if (tp != null) {
085: setIconProperty(tp.getIconProperty());
086: updatePreview();
087: }
088: }
089:
090: /**
091: * Sets the property for the view
092: */
093: public void setPaintProperty(PaintProperty pp) {
094: if (pp.getPaintDelegate() instanceof TextureProperty) {
095: TextureProperty tp = (TextureProperty) pp
096: .getPaintDelegate();
097: m_texture_prop.setValue(tp);
098: initialize(m_texture_prop);
099: updatePreview();
100: }
101: }
102:
103: public void updatePreview() {
104: m_painter.setTextureProperty(getTextureProperty());
105: m_preview.setBackgroundPainter(m_painter);
106: }
107:
108: public class TextureViewController extends
109: ImagePropertiesController {
110: private ActionListener m_delegate;
111:
112: public TextureViewController() {
113: super (TextureView.this );
114: m_delegate = getAction(ImagePropertiesNames.ID_FILE_BUTTON);
115: assignAction(ImagePropertiesNames.ID_FILE_BUTTON,
116: new FileAction());
117: }
118:
119: public class FileAction implements ActionListener {
120: public void actionPerformed(ActionEvent evt) {
121: if (m_delegate != null)
122: m_delegate.actionPerformed(evt);
123: updatePreview();
124: }
125: }
126: }
127:
128: }
|