001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.action;
019:
020: import java.awt.BorderLayout;
021: import java.awt.Color;
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import java.awt.event.FocusAdapter;
025: import java.awt.event.FocusEvent;
026: import java.util.logging.Logger;
027:
028: import javax.swing.JLabel;
029: import javax.swing.JTextField;
030:
031: import de.finix.contelligent.client.base.ContelligentComponent;
032: import de.finix.contelligent.client.event.ContelligentEvent;
033: import de.finix.contelligent.client.gui.AbstractComponentEditor;
034: import de.finix.contelligent.client.i18n.Resources;
035:
036: public class ParameterEditor extends AbstractComponentEditor {
037:
038: private static Logger logger = Logger
039: .getLogger(ParameterEditor.class.getName());
040:
041: private JTextField valueField;
042:
043: private JLabel requiredLabel;
044:
045: public void init() {
046: valueField = new JTextField(15);
047: requiredLabel = new JLabel();
048:
049: update();
050:
051: valueField.setEditable(isEditable());
052: valueField.setBackground(Color.white);
053: valueField.setBorder(null);
054:
055: requiredLabel.setOpaque(true);
056:
057: add(valueField, BorderLayout.CENTER);
058: add(requiredLabel, BorderLayout.EAST);
059:
060: addFocusListener(new FocusAdapter() {
061: public void focusGained(FocusEvent e) {
062: getView().setActions(getActions());
063: }
064: });
065:
066: valueField.addActionListener(new ActionListener() {
067: public void actionPerformed(ActionEvent e) {
068: updateComponent();
069: notifyListeners();
070: }
071: });
072: }
073:
074: public void update() {
075: valueField.setText(getComponent().getPropertyValue(
076: ContelligentComponent.DEFAULT));
077:
078: if (Boolean.valueOf(
079: getComponent().getPropertyValue(
080: ContelligentComponent.REQUIRED)).booleanValue()) {
081: requiredLabel.setBackground(new Color(255, 194, 155));
082: requiredLabel.setText(Resources.getLocalString("required"));
083: } else {
084: requiredLabel.setBackground(new Color(155, 255, 155));
085: requiredLabel.setText(Resources.getLocalString("optional"));
086: }
087: }
088:
089: protected void componentChanged(ContelligentEvent event) {
090: update();
091: }
092:
093: protected void childComponentAdded(ContelligentEvent event) {
094: }
095:
096: protected void childComponentRemoved(ContelligentEvent event) {
097: }
098:
099: protected void childComponentChanged(ContelligentEvent event) {
100: }
101:
102: protected void descendentComponentChanged(ContelligentEvent event) {
103: }
104:
105: protected void updateComponent() {
106: getComponent().setPropertyValue(ContelligentComponent.DEFAULT,
107: valueField.getText());
108: }
109:
110: public void setEditable(boolean editable) {
111: super.setEditable(editable);
112: if (valueField != null) {
113: valueField.setEditable(isEditable());
114: }
115: }
116: }
|