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.BorderLayout;
022: import java.awt.Dimension;
023: import java.util.HashMap;
024:
025: import com.jeta.forms.components.panel.FormPanel;
026: import com.jeta.forms.gui.form.FormAccessor;
027: import com.jeta.forms.gui.form.GridView;
028: import com.jeta.forms.store.properties.ImageProperty;
029: import com.jeta.forms.store.properties.JETAProperty;
030: import com.jeta.forms.store.properties.effects.GradientProperty;
031: import com.jeta.forms.store.properties.effects.PaintProperty;
032: import com.jeta.forms.store.properties.effects.RadialGradientProperty;
033: import com.jeta.forms.store.properties.effects.SolidProperty;
034: import com.jeta.forms.store.properties.effects.TextureProperty;
035: import com.jeta.open.gui.framework.JETAController;
036: import com.jeta.open.gui.framework.JETAPanel;
037: import com.jeta.open.rules.JETARule;
038: import com.jeta.open.rules.RuleResult;
039: import com.jeta.swingbuilder.gui.images.ImagePropertiesValidator;
040: import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
041: import com.jgoodies.forms.layout.CellConstraints;
042:
043: /**
044: * Displays the fill effects view. Currently we support solid, gradient, and
045: * texture fills for panels and cells.
046: *
047: * @author Jeff Tassin
048: */
049: public class PaintAssignmentView extends JETAPanel {
050: /**
051: * The fillProperties form.
052: */
053: private FormPanel m_view;
054:
055: /**
056: * The current fill type view: Solid, Gradient, Texture
057: */
058: private PaintViewProxy m_current_view;
059:
060: /**
061: * A map of PaintViews keyed on their class. m_views<Class,PaintView>
062: */
063: private HashMap m_views = new HashMap();
064:
065: /**
066: * The preview panel
067: */
068: private GridView m_preview;
069:
070: /**
071: * ctor
072: */
073: public PaintAssignmentView() {
074: this (null);
075: }
076:
077: /**
078: * ctor
079: */
080: public PaintAssignmentView(PaintProperty fp) {
081: setLayout(new BorderLayout());
082: m_view = new FormPanel(
083: "com/jeta/swingbuilder/gui/effects/paintProperties.frm");
084: add(m_view, BorderLayout.CENTER);
085: setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10,
086: 10, 10));
087:
088: setController(new PaintAssignmentController(this ));
089:
090: m_preview = (GridView) m_view
091: .getComponentByName(PaintNames.ID_PREVIEW_PANEL);
092: if (fp == null || fp.getPaintDelegate() == null) {
093: loadView(NoFillView.class);
094: } else {
095: JETAProperty pp = fp.getPaintDelegate();
096: if (pp instanceof TextureProperty) {
097: loadView(TextureView.class);
098: } else if (pp instanceof GradientProperty) {
099: loadView(GradientView.class);
100: } else if (pp instanceof RadialGradientProperty) {
101: loadView(RadialView.class);
102: } else if (pp instanceof SolidProperty) {
103: loadView(SolidView.class);
104: } else if (pp instanceof ImageProperty) {
105: loadView(ImageFillView.class);
106: } else {
107: loadView(NoFillView.class);
108: }
109: m_current_view.setPaintProperty(fp);
110: }
111: }
112:
113: /**
114: * @return the preferred size for this panel
115: */
116: public Dimension getPreferredSize() {
117: return FormDesignerUtils.getWindowDimension(this , 350, 200);
118: }
119:
120: /**
121: * @return the property for this view
122: */
123: public PaintProperty getPaintProperty() {
124: return m_current_view.getPaintProperty();
125: }
126:
127: /**
128: * Loads the GradientView into this view
129: */
130: void loadView(Class viewClass) {
131: JETAController controller = getController();
132:
133: try {
134: controller.enableEvents(false);
135: FormAccessor form_access = m_view
136: .getFormAccessor(PaintNames.ID_SETTINGS_PANEL);
137: form_access.removeBean(PaintNames.ID_MAIN_VIEW);
138:
139: /*
140: * if ( m_current_view != null ) { FormPanel.removeFromParent(
141: * (java.awt.Component)m_current_view.getView() ); }
142: */
143:
144: PaintViewProxy fillview = (PaintViewProxy) m_views
145: .get(viewClass);
146: if (fillview == null) {
147: if (viewClass == GradientView.class) {
148: fillview = new PaintViewProxy(new GradientView(
149: m_preview), null);
150: m_view.setSelected(
151: PaintNames.ID_LINEAR_GRADIENT_FILL, true);
152:
153: } else if (viewClass == TextureView.class) {
154: fillview = new PaintViewProxy(new TextureView(
155: m_preview), new ImagePropertiesValidator());
156: m_view
157: .setSelected(PaintNames.ID_TEXTURE_FILL,
158: true);
159: } else if (viewClass == SolidView.class) {
160: fillview = new PaintViewProxy(new SolidView(
161: m_preview), null);
162: m_view.setSelected(PaintNames.ID_SOLID_FILL, true);
163: } else if (viewClass == RadialView.class) {
164: fillview = new PaintViewProxy(new RadialView(
165: m_preview), null);
166: m_view.setSelected(
167: PaintNames.ID_RADIAL_GRADIENT_FILL, true);
168: } else if (viewClass == ImageFillView.class) {
169: fillview = new PaintViewProxy(new ImageFillView(
170: m_preview), null);
171: m_view.setSelected(PaintNames.ID_IMAGE_FILL, true);
172: } else {
173: fillview = new PaintViewProxy(new NoFillView(
174: m_preview), null);
175: m_view.setSelected(PaintNames.ID_NO_FILL, true);
176: }
177: m_views.put(viewClass, fillview);
178: }
179:
180: m_current_view = fillview;
181: java.awt.Component comp = (java.awt.Component) fillview
182: .getView();
183: comp.setName(PaintNames.ID_MAIN_VIEW);
184: form_access.addBean(comp, new CellConstraints(2, 2));
185: m_view.revalidate();
186:
187: revalidate();
188: repaint();
189: } catch (Exception e) {
190: e.printStackTrace();
191: } finally {
192: controller.enableEvents(true);
193: }
194:
195: }
196:
197: /**
198: * This class associates a nested paint view with its validator.
199: *
200: */
201: private static class PaintViewProxy implements PaintView, JETARule {
202: private PaintView m_view;
203: private JETARule m_validator;
204:
205: /**
206: * ctor
207: */
208: public PaintViewProxy(PaintView view, JETARule viewValidator) {
209: m_view = view;
210: m_validator = viewValidator;
211: }
212:
213: public PaintView getView() {
214: return m_view;
215: }
216:
217: /**
218: * PaintView implementation
219: */
220: public PaintProperty getPaintProperty() {
221: return m_view.getPaintProperty();
222: }
223:
224: /**
225: * PaintView implementation
226: */
227: public void setPaintProperty(PaintProperty pp) {
228: m_view.setPaintProperty(pp);
229: }
230:
231: /**
232: * JETARule implementation
233: */
234: public RuleResult check(Object[] params) {
235: if (m_validator == null)
236: return RuleResult.SUCCESS;
237: else {
238: params = new Object[] { m_view };
239: return m_validator.check(params);
240: }
241: }
242: }
243:
244: }
|