001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: ElementPropertyEditor.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.gui.old;
009:
010: import java.awt.*;
011: import java.awt.event.ActionEvent;
012: import java.awt.event.ActionListener;
013: import java.awt.event.KeyEvent;
014: import java.awt.event.KeyListener;
015: import javax.swing.*;
016:
017: import com.uwyn.rife.gui.Rife;
018: import com.uwyn.rife.swing.JDialogError;
019: import com.uwyn.rife.swing.MouseMotionEventTranslator;
020: import com.uwyn.rife.swing.documents.CharFilterDocument;
021: import com.uwyn.rife.tools.Localization;
022:
023: class ElementPropertyEditor extends JTextField implements KeyListener,
024: ActionListener {
025: private ElementProperty mElementProperty = null;
026: private Rectangle mEditRectangle = null;
027:
028: ElementPropertyEditor(ElementProperty elementProperty,
029: Point referencePoint) {
030: super (new CharFilterDocument(ElementProperty.VALID_CHARS,
031: CharFilterDocument.VALID,
032: ElementStyle.MAX_PROPERTY_STRING_LENGTH),
033: elementProperty.getName(), 0);
034:
035: mElementProperty = elementProperty;
036: mEditRectangle = mElementProperty
037: .getEditRectangle(referencePoint);
038:
039: mElementProperty.getElement().add(ElementPropertyEditor.this );
040: mElementProperty.getElement().getStructurePanel()
041: .elementPropertyHighlighted(mElementProperty);
042: setBorder(null);
043: setFont(mElementProperty.getEditFont());
044: setHorizontalAlignment(mElementProperty.getEditAlignment());
045:
046: setBounds((int) mEditRectangle.getX(), (int) mEditRectangle
047: .getY(), (int) mEditRectangle.getWidth(),
048: (int) mEditRectangle.getHeight());
049:
050: setVisible(true);
051: requestFocus();
052:
053: addActionListener(this );
054: addKeyListener(this );
055: addMouseMotionListener(new MouseMotionEventTranslator(
056: getElementProperty().getElement()));
057: }
058:
059: ElementProperty getElementProperty() {
060: return mElementProperty;
061: }
062:
063: void destroy() {
064: removeKeyListener(this );
065: removeActionListener(this );
066: Element element = mElementProperty.getElement();
067: element.remove(this );
068: if (mElementProperty.getName().length() == 0) {
069: element.removeProperty(mElementProperty);
070: }
071: element.repaint();
072: }
073:
074: public void keyTyped(KeyEvent e) {
075: }
076:
077: public void keyPressed(KeyEvent e) {
078: }
079:
080: public void keyReleased(KeyEvent e) {
081: if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
082: Element element = mElementProperty.getElement();
083: element.getStructurePanel().removeElementPropertyEditor();
084: }
085: }
086:
087: public void actionPerformed(ActionEvent e) {
088: Object source = e.getSource();
089:
090: if (source == this ) {
091: if (getText().length() == 0) {
092: JDialogError dialog = new JDialogError(
093: Rife.getMainFrame(),
094: "rife.dialog.emptyelementproperty.title",
095: Localization
096: .getString("rife.dialog.emptyelementproperty.message"));
097: dialog.setVisible(true);
098: } else {
099: Element element = mElementProperty.getElement();
100: if (element.renameProperty(mElementProperty, getText())) {
101: element.getStructurePanel()
102: .removeElementPropertyEditor();
103: element.resetPrecalculatedAreas();
104: } else {
105: JDialogError dialog = mElementProperty
106: .getUnicityErrorDialog();
107: dialog.setVisible(true);
108: }
109: }
110: }
111: }
112: }
|