KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > plaf > CompiereColorEditor


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.plaf;
15
16 import java.awt.BorderLayout JavaDoc;
17 import java.awt.Component JavaDoc;
18 import java.awt.Dialog JavaDoc;
19 import java.awt.Dimension JavaDoc;
20 import java.awt.FlowLayout JavaDoc;
21 import java.awt.Frame JavaDoc;
22 import java.awt.Graphics JavaDoc;
23 import java.awt.GridBagConstraints JavaDoc;
24 import java.awt.GridBagLayout JavaDoc;
25 import java.awt.Insets JavaDoc;
26 import java.awt.Rectangle JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29 import java.beans.PropertyChangeListener JavaDoc;
30 import java.beans.PropertyEditor JavaDoc;
31 import java.util.ResourceBundle JavaDoc;
32
33 import javax.swing.BorderFactory JavaDoc;
34 import javax.swing.JColorChooser JavaDoc;
35 import javax.swing.JDialog JavaDoc;
36
37 import org.compiere.swing.CButton;
38 import org.compiere.swing.CComboBox;
39 import org.compiere.swing.CLabel;
40 import org.compiere.swing.CPanel;
41 import org.compiere.swing.CTextField;
42 import org.compiere.util.KeyNamePair;
43 import org.compiere.util.ValueNamePair;
44
45 /**
46  * Compiere Color Editor
47  *
48  * @author Jorg Janke
49  * @version $Id: CompiereColorEditor.java,v 1.10 2003/09/27 11:08:52 jjanke Exp $
50  */

51 public class CompiereColorEditor extends JDialog JavaDoc
52     implements ActionListener JavaDoc, PropertyEditor JavaDoc
53 {
54     /**
55      * Get Background CompiereColor
56      * @param owner owner
57      * @param color optional initial color
58      * @return CompiereColor
59      */

60     public static CompiereColor showDialog (Frame JavaDoc owner, CompiereColor color)
61     {
62         CompiereColorEditor cce = new CompiereColorEditor (owner, color);
63         if (cce.isSaved())
64             return cce.getColor();
65         return color;
66     } // showDialog
67

68     /**
69      * Get Background CompiereColor
70      * @param owner owner
71      * @param color optional initial color
72      * @return CompiereColor
73      */

74     public static CompiereColor showDialog (Dialog JavaDoc owner, CompiereColor color)
75     {
76         CompiereColorEditor cce = new CompiereColorEditor (owner, color);
77         if (cce.isSaved())
78             return cce.getColor();
79         return color;
80     } // showIt
81

82     /*************************************************************************/
83
84     /**
85      * Create CompiereColor Dialog with color
86      * @param owner owner
87      * @param color Start Color
88      */

89     public CompiereColorEditor (Frame JavaDoc owner, CompiereColor color)
90     {
91         super(owner, "", true);
92         init (color);
93     } // CompiereColorEditor
94

95     /**
96      * Create CompiereColor Dialog with color
97      * @param owner owner
98      * @param color Start Color
99      */

100     public CompiereColorEditor (Dialog JavaDoc owner, CompiereColor color)
101     {
102         super(owner, "", true);
103         init (color);
104     } // CompiereColorEditor
105

106     /**
107      * Init Dialog
108      * @param color Start Color
109      */

110     private void init (CompiereColor color)
111     {
112         try
113         {
114             jbInit();
115         }
116         catch(Exception JavaDoc e)
117         {
118             e.printStackTrace();
119         }
120
121         bOK.addActionListener(this);
122         bCancel.addActionListener(this);
123         typeField.addActionListener(this);
124         flatField.addActionListener(this);
125         gradientUpper.addActionListener(this);
126         gradientLower.addActionListener(this);
127         urlField.addActionListener(this);
128         alphaField.addActionListener(this);
129         taintColor.addActionListener(this);
130         lineColor.addActionListener(this);
131         backColor.addActionListener(this);
132         widthField.addActionListener(this);
133         distanceField.addActionListener(this);
134         gradientStartField.addActionListener(this);
135         gradientDistanceField.addActionListener(this);
136
137         if (color == null)
138             setColor (m_cc);
139         else
140             setColor (new CompiereColor(color));
141         CompierePLAF.showCenterScreen(this);
142     } // init
143

144
145     private static ResourceBundle JavaDoc res = ResourceBundle.getBundle("org.compiere.plaf.PlafRes");
146     private CompiereColor m_cc = null;
147     private boolean m_saved = false;
148     private boolean m_setting = false;
149
150     //
151
private CPanel northPanel = new CPanel();
152     private CPanel southPanel = new CPanel();
153     private CButton bOK = CompierePLAF.getOKButton();
154     private CButton bCancel = CompierePLAF.getCancelButton();
155     private FlowLayout JavaDoc southLayout = new FlowLayout JavaDoc();
156     private GridBagLayout JavaDoc northLayout = new GridBagLayout JavaDoc();
157     private CLabel typeLabel = new CLabel();
158     private CComboBox typeField = new CComboBox(CompiereColor.TYPES);
159     private CButton gradientUpper = new CButton();
160     private CButton gradientLower = new CButton();
161     private CLabel urlLabel = new CLabel();
162     private CTextField urlField = new CTextField(30);
163     private CLabel alphaLabel = new CLabel();
164     private CTextField alphaField = new CTextField(10);
165     private CButton taintColor = new CButton();
166     private CButton lineColor = new CButton();
167     private CButton backColor = new CButton();
168     private CLabel widthLabel = new CLabel();
169     private CTextField widthField = new CTextField(10);
170     private CLabel distanceLabel = new CLabel();
171     private CTextField distanceField = new CTextField(10);
172     private CPanel centerPanel = new CPanel();
173     private CButton flatField = new CButton();
174     private CComboBox gradientStartField = new CComboBox(CompiereColor.GRADIENT_SP);
175     private CTextField gradientDistanceField = new CTextField(10);
176     private CLabel gradientStartLabel = new CLabel();
177     private CLabel gradientDistanceLabel = new CLabel();
178
179     /**
180      * Static Layout.
181      * <pre>
182      * - northPanel
183      * - labels & fields
184      * - centerPanel
185      * - southPanel
186      * </pre>
187      * @throws Exception
188      */

189     private void jbInit() throws Exception JavaDoc
190     {
191         this.setTitle(res.getString("CompiereColorEditor"));
192         CompiereColor.setBackground (this);
193         southPanel.setLayout(southLayout);
194         southLayout.setAlignment(FlowLayout.RIGHT);
195         northPanel.setLayout(northLayout);
196         typeLabel.setText(res.getString("CompiereType"));
197         gradientUpper.setText(res.getString("GradientUpperColor"));
198         gradientLower.setText(res.getString("GradientLowerColor"));
199         gradientStartLabel.setText(res.getString("GradientStart"));
200         gradientDistanceLabel.setText(res.getString("GradientDistance"));
201         urlLabel.setText(res.getString("TextureURL"));
202         alphaLabel.setText(res.getString("TextureAlpha"));
203         taintColor.setText(res.getString("TextureTaintColor"));
204         lineColor.setText(res.getString("LineColor"));
205         backColor.setText(res.getString("LineBackColor"));
206         widthLabel.setText(res.getString("LineWidth"));
207         distanceLabel.setText(res.getString("LineDistance"));
208         flatField.setText(res.getString("FlatColor"));
209         centerPanel.setBorder(BorderFactory.createRaisedBevelBorder());
210         centerPanel.setPreferredSize(new Dimension JavaDoc(400, 200));
211         centerPanel.setOpaque(true);
212         northPanel.setPreferredSize(new Dimension JavaDoc(400, 150));
213         southPanel.add(bCancel, null);
214         this.getContentPane().add(northPanel, BorderLayout.NORTH);
215         southPanel.add(bOK, null);
216         this.getContentPane().add(southPanel, BorderLayout.SOUTH);
217         this.getContentPane().add(centerPanel, BorderLayout.CENTER);
218         northPanel.add(typeLabel, new GridBagConstraints JavaDoc(0, 0, 1, 1, 0.0, 0.0
219             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
220         northPanel.add(typeField, new GridBagConstraints JavaDoc(1, 0, 1, 1, 0.0, 0.0
221             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 0, 5), 0, 0));
222         northPanel.add(gradientLower, new GridBagConstraints JavaDoc(1, 2, 1, 1, 0.0, 0.0
223             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
224         northPanel.add(urlField, new GridBagConstraints JavaDoc(1, 5, 2, 1, 1.0, 0.0
225             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
226         northPanel.add(alphaLabel, new GridBagConstraints JavaDoc(0, 6, 1, 1, 0.0, 0.0
227             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
228         northPanel.add(alphaField, new GridBagConstraints JavaDoc(1, 6, 1, 1, 0.0, 0.0
229             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
230         northPanel.add(taintColor, new GridBagConstraints JavaDoc(1, 7, 1, 1, 0.0, 0.0
231             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
232         northPanel.add(backColor, new GridBagConstraints JavaDoc(1, 8, 1, 1, 0.0, 0.0
233             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
234         northPanel.add(widthLabel, new GridBagConstraints JavaDoc(0, 9, 1, 1, 0.0, 0.0
235             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
236         northPanel.add(widthField, new GridBagConstraints JavaDoc(1, 9, 1, 1, 0.0, 0.0
237             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
238         northPanel.add(distanceLabel, new GridBagConstraints JavaDoc(0, 10, 1, 1, 0.0, 0.0
239             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
240         northPanel.add(distanceField, new GridBagConstraints JavaDoc(1, 10, 1, 1, 0.0, 0.0
241             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
242         northPanel.add(flatField, new GridBagConstraints JavaDoc(1, 1, 1, 1, 0.0, 0.0
243             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
244         northPanel.add(gradientStartField, new GridBagConstraints JavaDoc(1, 3, 1, 1, 0.0, 0.0
245             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
246         northPanel.add(gradientDistanceField, new GridBagConstraints JavaDoc(1, 4, 1, 1, 0.0, 0.0
247             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
248         northPanel.add(urlLabel, new GridBagConstraints JavaDoc(0, 5, 1, 1, 0.0, 0.0
249             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
250         northPanel.add(gradientStartLabel, new GridBagConstraints JavaDoc(0, 3, 1, 1, 0.0, 0.0
251             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
252         northPanel.add(gradientDistanceLabel, new GridBagConstraints JavaDoc(0, 4, 1, 1, 0.0, 0.0
253             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
254         northPanel.add(gradientUpper, new GridBagConstraints JavaDoc(0, 2, 1, 1, 0.0, 0.0
255             ,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
256         northPanel.add(lineColor, new GridBagConstraints JavaDoc(0, 8, 1, 1, 0.0, 0.0
257             ,GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, new Insets JavaDoc(5, 5, 5, 5), 0, 0));
258     } // jbInit
259

260     /**
261      * Action Listener
262      * @param e event
263      */

264     public void actionPerformed(ActionEvent JavaDoc e)
265     {
266         if (m_setting)
267             return;
268         if (e.getSource() == bOK)
269         {
270             m_saved = true;
271             dispose();
272             return;
273         }
274         else if (e.getSource() == bCancel)
275         {
276             dispose();
277             return;
278         }
279
280         /**** Field Changes ****/
281         try
282         {
283         // Type
284
if (e.getSource() == typeField)
285             cmd_type();
286         // Flat
287
else if (e.getSource() == flatField)
288             m_cc.setFlatColor(JColorChooser.showDialog
289                 (this, flatField.getText(), m_cc.getFlatColor()));
290         // Gradient
291
else if (e.getSource() == gradientUpper)
292             m_cc.setGradientUpperColor(JColorChooser.showDialog
293                 (this, gradientUpper.getText(), m_cc.getGradientUpperColor()));
294         else if (e.getSource() == gradientLower)
295             m_cc.setGradientLowerColor(JColorChooser.showDialog
296                 (this, gradientLower.getText(), m_cc.getGradientLowerColor()));
297         else if (e.getSource() == gradientStartField)
298             m_cc.setGradientStartPoint
299                 (((KeyNamePair)gradientStartField.getSelectedItem()).getKey());
300         else if (e.getSource() == gradientDistanceField)
301             m_cc.setGradientRepeatDistance(gradientDistanceField.getText());
302         // Texture
303
else if (e.getSource() == urlField)
304             m_cc.setTextureURL(urlField.getText());
305         else if (e.getSource() == alphaField)
306             m_cc.setTextureCompositeAlpha(alphaField.getText());
307         else if (e.getSource() == taintColor)
308             m_cc.setTextureTaintColor(JColorChooser.showDialog
309                 (this, taintColor.getText(), m_cc.getTextureTaintColor()));
310         // Lines
311
else if (e.getSource() == lineColor)
312             m_cc.setLineColor(JColorChooser.showDialog
313                 (this, lineColor.getText(), m_cc.getLineColor()));
314         else if (e.getSource() == backColor)
315             m_cc.setLineBackColor(JColorChooser.showDialog
316                 (this, backColor.getText(), m_cc.getLineBackColor()));
317         else if (e.getSource() == widthField)
318             m_cc.setLineWidth(widthField.getText());
319         else if (e.getSource() == distanceField)
320             m_cc.setLineDistance(distanceField.getText());
321         }
322         catch (Exception JavaDoc ee)
323         {
324         }
325         setColor (m_cc);
326     } // actionPerformed
327

328     /**
329      * Set Type with default values
330      */

331     private void cmd_type()
332     {
333         ValueNamePair vp = (ValueNamePair)typeField.getSelectedItem();
334         if (vp.getValue().equals(CompiereColor.TYPE_FLAT))
335             m_cc = new CompiereColor(CompiereColor.TYPE_FLAT);
336         else if (vp.getValue().equals(CompiereColor.TYPE_GRADIENT))
337             m_cc = new CompiereColor(CompiereColor.TYPE_GRADIENT);
338         else if (vp.getValue().equals(CompiereColor.TYPE_TEXTURE))
339             m_cc = new CompiereColor(CompiereColor.TYPE_TEXTURE);
340         else if (vp.getValue().equals(CompiereColor.TYPE_LINES))
341             m_cc = new CompiereColor(CompiereColor.TYPE_LINES);
342         setColor (m_cc);
343     } // cmd_type
344

345     /**
346      * Set Color and update UI
347      * @param color color
348      */

349     public void setColor (CompiereColor color)
350     {
351         if (color == null && m_cc != null)
352             return;
353         //
354
// System.out.println("CompiereColorEditor.setColor " + color);
355
m_cc = color;
356         if (m_cc == null)
357             m_cc = CompierePanelUI.getDefaultBackground();
358
359         // update display
360
updateFields();
361         centerPanel.setBackgroundColor(m_cc);
362         centerPanel.repaint();
363     } // setColor
364

365     /**
366      * UpdateField from CompiereColor
367      */

368     private void updateFields()
369     {
370         m_setting = true;
371         // Type
372
for (int i = 0; i < CompiereColor.TYPES.length; i++)
373         {
374             if (m_cc.getType().equals(CompiereColor.TYPE_VALUES[i]))
375             {
376                 typeField.setSelectedItem(CompiereColor.TYPES[i]);
377                 break;
378             }
379         }
380         //
381
if (m_cc.isFlat())
382         {
383             flatField.setVisible(true);
384             gradientUpper.setVisible(false);
385             gradientLower.setVisible(false);
386             gradientStartLabel.setVisible(false);
387             gradientDistanceLabel.setVisible(false);
388             gradientStartField.setVisible(false);
389             gradientDistanceField.setVisible(false);
390             urlLabel.setVisible(false);
391             urlField.setVisible(false);
392             alphaLabel.setVisible(false);
393             alphaField.setVisible(false);
394             taintColor.setVisible(false);
395             lineColor.setVisible(false);
396             backColor.setVisible(false);
397             widthLabel.setVisible(false);
398             widthField.setVisible(false);
399             distanceLabel.setVisible(false);
400             distanceField.setVisible(false);
401             //
402
flatField.setBackground(m_cc.getFlatColor());
403         }
404         else if (m_cc.isGradient())
405         {
406             flatField.setVisible(false);
407             gradientUpper.setVisible(true);
408             gradientLower.setVisible(true);
409             gradientStartLabel.setVisible(true);
410             gradientDistanceLabel.setVisible(true);
411             gradientStartField.setVisible(true);
412             gradientDistanceField.setVisible(true);
413             urlLabel.setVisible(false);
414             urlField.setVisible(false);
415             alphaLabel.setVisible(false);
416             alphaField.setVisible(false);
417             taintColor.setVisible(false);
418             lineColor.setVisible(false);
419             backColor.setVisible(false);
420             widthLabel.setVisible(false);
421             widthField.setVisible(false);
422             distanceLabel.setVisible(false);
423             distanceField.setVisible(false);
424             //
425
gradientUpper.setBackground(m_cc.getGradientUpperColor());
426             gradientLower.setBackground(m_cc.getGradientLowerColor());
427             gradientDistanceField.setText(String.valueOf(m_cc.getGradientRepeatDistance()));
428             for (int i = 0; i < CompiereColor.GRADIENT_SP.length; i++)
429             {
430                 if (m_cc.getGradientStartPoint() == CompiereColor.GRADIENT_SP_VALUES[i])
431                 {
432                     gradientStartField.setSelectedItem(CompiereColor.GRADIENT_SP[i]);
433                     break;
434                 }
435             }
436         }
437         else if (m_cc.isTexture())
438         {
439             flatField.setVisible(false);
440             gradientUpper.setVisible(false);
441             gradientLower.setVisible(false);
442             gradientStartLabel.setVisible(false);
443             gradientDistanceLabel.setVisible(false);
444             gradientStartField.setVisible(false);
445             gradientDistanceField.setVisible(false);
446             urlLabel.setVisible(true);
447             urlField.setVisible(true);
448             alphaLabel.setVisible(true);
449             alphaField.setVisible(true);
450             taintColor.setVisible(true);
451             lineColor.setVisible(false);
452             backColor.setVisible(false);
453             widthLabel.setVisible(false);
454             widthField.setVisible(false);
455             distanceLabel.setVisible(false);
456             distanceField.setVisible(false);
457             //
458
urlField.setText(m_cc.getTextureURL().toString());
459             alphaField.setText(String.valueOf(m_cc.getTextureCompositeAlpha()));
460             taintColor.setBackground(m_cc.getTextureTaintColor());
461         }
462         else if (m_cc.isLine())
463         {
464             flatField.setVisible(false);
465             gradientUpper.setVisible(false);
466             gradientLower.setVisible(false);
467             gradientStartLabel.setVisible(false);
468             gradientDistanceLabel.setVisible(false);
469             gradientStartField.setVisible(false);
470             gradientDistanceField.setVisible(false);
471             urlLabel.setVisible(false);
472             urlField.setVisible(false);
473             alphaLabel.setVisible(false);
474             alphaField.setVisible(false);
475             taintColor.setVisible(false);
476             lineColor.setVisible(true);
477             backColor.setVisible(true);
478             widthLabel.setVisible(true);
479             widthField.setVisible(true);
480             distanceLabel.setVisible(true);
481             distanceField.setVisible(true);
482             //
483
lineColor.setBackground(m_cc.getLineColor());
484             backColor.setBackground(m_cc.getLineBackColor());
485             widthField.setText(String.valueOf(m_cc.getLineWidth()));
486             distanceField.setText(String.valueOf(m_cc.getLineDistance()));
487         }
488         m_setting = false;
489     } // updateFields
490

491     /**
492      * Get Color
493      * @return Color, when saved - else null
494      */

495     public CompiereColor getColor()
496     {
497         return m_cc;
498     } // getColor
499

500     /**
501      * Was the selection saved
502      * @return true if saved
503      */

504     public boolean isSaved()
505     {
506         return m_saved;
507     } // m_saved
508

509     /*************************************************************************/
510
511     /**
512      * Set (or change) the object that is to be edited. Primitive types such
513      * as "int" must be wrapped as the corresponding object type such as
514      * "java.lang.Integer".
515      *
516      * @param value The new target object to be edited. Note that this
517      * object should not be modified by the PropertyEditor, rather
518      * the PropertyEditor should create a new object to hold any
519      * modified value.
520      */

521     public void setValue(Object JavaDoc value)
522     {
523         if (value != null && value instanceof CompiereColor)
524             setColor (new CompiereColor((CompiereColor)value));
525         else
526             throw new IllegalArgumentException JavaDoc("CompiereColorEditor.setValue requires CompiereColor");
527     } // setValue
528

529     /**
530      * Gets the property value.
531      *
532      * @return The value of the property. Primitive types such as "int" will
533      * be wrapped as the corresponding object type such as "java.lang.Integer".
534      */

535     public Object JavaDoc getValue()
536     {
537         return getColor();
538     } // getColor
539

540     /**
541      * Determines whether this property editor is paintable.
542      * @return True if the class will honor the paintValue method.
543      */

544     public boolean isPaintable()
545     {
546         return false;
547     }
548
549     /**
550      * Paint a representation of the value into a given area of screen
551      * real estate. Note that the propertyEditor is responsible for doing
552      * its own clipping so that it fits into the given rectangle.
553      * <p>
554      * If the PropertyEditor doesn't honor paint requests (see isPaintable)
555      * this method should be a silent noop.
556      * <p>
557      * The given Graphics object will have the default font, color, etc of
558      * the parent container. The PropertyEditor may change graphics attributes
559      * such as font and color and doesn't need to restore the old values.
560      *
561      * @param gfx Graphics object to paint into.
562      * @param box Rectangle within graphics object into which we should paint.
563      */

564     public void paintValue(Graphics JavaDoc gfx, Rectangle JavaDoc box)
565     {
566         /**@todo: Implement this java.beans.PropertyEditor method*/
567         throw new java.lang.UnsupportedOperationException JavaDoc("Method paintValue() not yet implemented.");
568     } // paintValue
569

570     /**
571      * This method is intended for use when generating Java code to set
572      * the value of the property. It should return a fragment of Java code
573      * that can be used to initialize a variable with the current property
574      * value.
575      * <p>
576      * Example results are "2", "new Color(127,127,34)", "Color.orange", etc.
577      *
578      * @return A fragment of Java code representing an initializer for the
579      * current value.
580      */

581     public String JavaDoc getJavaInitializationString()
582     {
583         return "new CompiereColor()";
584     } // String getJavaInitializationString
585

586     /**
587      * Gets the property value as text.
588      *
589      * @return The property value as a human editable string.
590      * <p> Returns null if the value can't be expressed as an editable string.
591      * <p> If a non-null value is returned, then the PropertyEditor should
592      * be prepared to parse that string back in setAsText().
593      */

594     public String JavaDoc getAsText()
595     {
596         return m_cc.toString();
597     } // getAsText
598

599     /**
600      * Set the property value by parsing a given String. May raise
601      * java.lang.IllegalArgumentException if either the String is
602      * badly formatted or if this kind of property can't be expressed
603      * as text.
604      * @param text The string to be parsed.
605      * @throws IllegalArgumentException
606      */

607     public void setAsText(String JavaDoc text) throws java.lang.IllegalArgumentException JavaDoc
608     {
609         throw new java.lang.IllegalArgumentException JavaDoc("CompiereColorEditor.setAsText not supported");
610     } // setAsText
611

612     /**
613      * If the property value must be one of a set of known tagged values,
614      * then this method should return an array of the tags. This can
615      * be used to represent (for example) enum values. If a PropertyEditor
616      * supports tags, then it should support the use of setAsText with
617      * a tag value as a way of setting the value and the use of getAsText
618      * to identify the current value.
619      *
620      * @return The tag values for this property. May be null if this
621      * property cannot be represented as a tagged value.
622      */

623     public String JavaDoc[] getTags()
624     {
625         return null;
626     } // getTags
627

628     /**
629      * A PropertyEditor may choose to make available a full custom Component
630      * that edits its property value. It is the responsibility of the
631      * PropertyEditor to hook itself up to its editor Component itself and
632      * to report property value changes by firing a PropertyChange event.
633      * <P>
634      * The higher-level code that calls getCustomEditor may either embed
635      * the Component in some larger property sheet, or it may put it in
636      * its own individual dialog, or ...
637      *
638      * @return A java.awt.Component that will allow a human to directly
639      * edit the current property value. May be null if this is
640      * not supported.
641      */

642     public Component JavaDoc getCustomEditor()
643     {
644         return this;
645     } // getCustomEditor
646

647     /**
648      * Determines whether this property editor supports a custom editor.
649      * @return True if the propertyEditor can provide a custom editor.
650      */

651     public boolean supportsCustomEditor()
652     {
653         return true;
654     } // supportsCustomEditor
655

656     /**
657      * Register a listener for the PropertyChange event. When a
658      * PropertyEditor changes its value it should fire a PropertyChange
659      * event on all registered PropertyChangeListeners, specifying the
660      * null value for the property name and itself as the source.
661      *
662      * @param listener An object to be invoked when a PropertyChange
663      * event is fired.
664      */

665     public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener)
666     {
667         super.addPropertyChangeListener(listener);
668     } // addPropertyChangeListener
669

670     /**
671      * Remove a listener for the PropertyChange event.
672      * @param listener The PropertyChange listener to be removed.
673      */

674     public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener)
675     {
676         super.removePropertyChangeListener(listener);
677     } // removePropertyChangeListener
678

679 } // CompiereColorEditor
680
Popular Tags