KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > sheet > ResetButton


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * ResetButton.java
28  *
29  * Created on March 7, 2006, 4:15 PM
30  *
31  */

32
33 package it.businesslogic.ireport.gui.sheet;
34
35 import it.businesslogic.ireport.gui.event.SheetPropertyValueChangedEvent;
36 import it.businesslogic.ireport.util.I18n;
37 import it.businesslogic.ireport.util.LanguageChangedEvent;
38 import it.businesslogic.ireport.util.LanguageChangedListener;
39 import java.awt.Component JavaDoc;
40 import java.awt.Graphics JavaDoc;
41 import java.awt.event.ActionEvent JavaDoc;
42
43 /**
44  *
45  * @author gtoffoli
46  */

47 public class ResetButton extends javax.swing.JButton JavaDoc implements LanguageChangedListener {
48     
49     private SheetProperty sheetProperty = null;
50     public static final javax.swing.ImageIcon JavaDoc reset_icon = new javax.swing.ImageIcon JavaDoc( CategorySheetPanel.class.getResource("/it/businesslogic/ireport/icons/reset.png"));
51     
52             
53     /** Creates a new instance of ResetButton */
54     public ResetButton(SheetProperty sheetProperty) {
55         
56         setText("");
57         setIcon(reset_icon);
58         setMargin( new java.awt.Insets JavaDoc(0, 0, 0, 0));
59         setMaximumSize(new java.awt.Dimension JavaDoc(16, 18));
60         setMinimumSize(new java.awt.Dimension JavaDoc(16, 18));
61         setPreferredSize(new java.awt.Dimension JavaDoc(16, 18));
62         setBorder(new javax.swing.border.AbstractBorder JavaDoc() {
63             public void paintBorder(Component JavaDoc c, Graphics JavaDoc g, int x, int y, int width, int height)
64             {
65                 g.setColor( java.awt.Color.GRAY);
66                 g.drawLine(x,y,x,y+height);
67             }
68         } );
69         
70         
71         
72         setFocusPainted(false);
73         setFocusable(false);
74         setBackground(java.awt.Color.WHITE);
75         setToolTipText(it.businesslogic.ireport.util.I18n.getString("gui.elementpropertiessheet.tooltip.resetToDefault","Reset to default"));
76         
77         this.sheetProperty = sheetProperty;
78         
79         this.addActionListener( new java.awt.event.ActionListener JavaDoc() {
80             public void actionPerformed(ActionEvent JavaDoc e) {
81                 SheetProperty sp = ResetButton.this.getSheetProperty();
82                 if (sp != null && !sp.isReadOnly())
83                 {
84                     Object JavaDoc oldValue = sp.getValue();
85                     sp.setValue(null);
86                     sp.updateLabel();
87                     sp.fireSheetPropertyValueChangedListenerSheetPropertyValueChanged(
88                         new SheetPropertyValueChangedEvent(sp.getKeyName(),oldValue,null,sp) );
89                 }
90             }
91         });
92         
93         I18n.addOnLanguageChangedListener(this);
94     }
95
96     public void languageChanged(LanguageChangedEvent evt) {
97         setToolTipText(it.businesslogic.ireport.util.I18n.getString("gui.elementpropertiessheet.tooltip.resetToDefault","Reset to default"));
98     }
99
100     public SheetProperty getSheetProperty() {
101         return sheetProperty;
102     }
103
104     public void setSheetProperty(SheetProperty sheetProperty) {
105         this.sheetProperty = sheetProperty;
106     }
107     
108 }
109
Popular Tags