001: /*
002: * $RCSfile: RequiredTextField.java,v $
003: * @modification $Date: 2001/09/28 19:35:30 $
004: * @version $Id: RequiredTextField.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
005: *
006: */
007:
008: package com.memoire.vainstall.builder.gui;
009:
010: import com.memoire.vainstall.builder.VAIProductModel;
011:
012: import java.awt.Color;
013:
014: import javax.swing.BorderFactory;
015: import javax.swing.JTextField;
016: import javax.swing.border.Border;
017: import javax.swing.event.DocumentEvent;
018: import javax.swing.event.DocumentListener;
019:
020: /**
021: *
022: *
023: * @see
024: *
025: * @author Henrik Falk
026: * @version $Id: RequiredTextField.java,v 1.1 2001/09/28 19:35:30 hfalk Exp $
027: */
028: public class RequiredTextField extends JTextField implements
029: DocumentListener {
030:
031: private VAIProductModel productModel;
032: private String requirementName;
033:
034: private Border oldBorder;
035:
036: private Border greenBorder = BorderFactory.createMatteBorder(1, 1,
037: 1, 1, Color.green);
038: private Border redBorder = BorderFactory.createMatteBorder(1, 1, 1,
039: 1, Color.red);
040:
041: private boolean hasChanged = false;
042:
043: public RequiredTextField() {
044:
045: oldBorder = getBorder();
046:
047: setBorder(redBorder);
048:
049: getDocument().addDocumentListener(this );
050:
051: }
052:
053: /**
054: * initialize the textfield
055: */
056: public void initialize(VAIProductModel model, String requirementName) {
057: this .productModel = model;
058: this .requirementName = requirementName;
059: }
060:
061: public void changedUpdate(DocumentEvent e) {
062: }
063:
064: public void insertUpdate(DocumentEvent e) {
065:
066: if (productModel == null) {
067: return;
068: }
069:
070: if (getText().length() > 0) {
071: productModel.removeRequirement(requirementName);
072: setBorder(greenBorder);
073: } else {
074: productModel.addRequirement(requirementName);
075: setBorder(redBorder);
076: }
077: hasChanged = true;
078: }
079:
080: public void removeUpdate(DocumentEvent e) {
081:
082: if (productModel == null) {
083: return;
084: }
085:
086: if (getText().length() > 0) {
087: productModel.removeRequirement(requirementName);
088: setBorder(greenBorder);
089: } else {
090: productModel.addRequirement(requirementName);
091: setBorder(redBorder);
092: }
093: hasChanged = true;
094: }
095:
096: public boolean hasChanged() {
097: return hasChanged;
098: }
099:
100: public void setChanged(boolean change) {
101: hasChanged = change;
102: }
103: }
|