001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * ResetButton.java
028: *
029: * Created on March 7, 2006, 4:15 PM
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.sheet;
034:
035: import it.businesslogic.ireport.gui.event.SheetPropertyValueChangedEvent;
036: import it.businesslogic.ireport.util.I18n;
037: import it.businesslogic.ireport.util.LanguageChangedEvent;
038: import it.businesslogic.ireport.util.LanguageChangedListener;
039: import java.awt.Component;
040: import java.awt.Graphics;
041: import java.awt.event.ActionEvent;
042:
043: /**
044: *
045: * @author gtoffoli
046: */
047: public class ResetButton extends javax.swing.JButton implements
048: LanguageChangedListener {
049:
050: private SheetProperty sheetProperty = null;
051: public static final javax.swing.ImageIcon reset_icon = new javax.swing.ImageIcon(
052: CategorySheetPanel.class
053: .getResource("/it/businesslogic/ireport/icons/reset.png"));
054:
055: /** Creates a new instance of ResetButton */
056: public ResetButton(SheetProperty sheetProperty) {
057:
058: setText("");
059: setIcon(reset_icon);
060: setMargin(new java.awt.Insets(0, 0, 0, 0));
061: setMaximumSize(new java.awt.Dimension(16, 18));
062: setMinimumSize(new java.awt.Dimension(16, 18));
063: setPreferredSize(new java.awt.Dimension(16, 18));
064: setBorder(new javax.swing.border.AbstractBorder() {
065: public void paintBorder(Component c, Graphics g, int x,
066: int y, int width, int height) {
067: g.setColor(java.awt.Color.GRAY);
068: g.drawLine(x, y, x, y + height);
069: }
070: });
071:
072: setFocusPainted(false);
073: setFocusable(false);
074: setBackground(java.awt.Color.WHITE);
075: setToolTipText(it.businesslogic.ireport.util.I18n.getString(
076: "gui.elementpropertiessheet.tooltip.resetToDefault",
077: "Reset to default"));
078:
079: this .sheetProperty = sheetProperty;
080:
081: this .addActionListener(new java.awt.event.ActionListener() {
082: public void actionPerformed(ActionEvent e) {
083: SheetProperty sp = ResetButton.this .getSheetProperty();
084: if (sp != null && !sp.isReadOnly()) {
085: Object oldValue = sp.getValue();
086: sp.setValue(null);
087: sp.updateLabel();
088: sp
089: .fireSheetPropertyValueChangedListenerSheetPropertyValueChanged(new SheetPropertyValueChangedEvent(
090: sp.getKeyName(), oldValue, null, sp));
091: }
092: }
093: });
094:
095: I18n.addOnLanguageChangedListener(this );
096: }
097:
098: public void languageChanged(LanguageChangedEvent evt) {
099: setToolTipText(it.businesslogic.ireport.util.I18n.getString(
100: "gui.elementpropertiessheet.tooltip.resetToDefault",
101: "Reset to default"));
102: }
103:
104: public SheetProperty getSheetProperty() {
105: return sheetProperty;
106: }
107:
108: public void setSheetProperty(SheetProperty sheetProperty) {
109: this.sheetProperty = sheetProperty;
110: }
111:
112: }
|