[CVS nano] update

Paul Hammant <paul-yCVjj/[email protected]> Mon, 17 Nov 2003 15:00:50 -0600
Newsgroups gmane.comp.java.nanocontainer.cvs
Message-ID <[email protected]>
Commit in nano/picogui/src/java/org/picoextras/gui/swing on MAIN

AddPicoComponentAction.java +72 added 1.1

update

----------

nano /picogui /src /java /org /picoextras /gui /swing

AddPicoComponentAction.java added at 1.1

diff -N AddPicoComponentAction.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AddPicoComponentAction.java 17 Nov 2003 21:00:50 -0000 1.1
@@ -0,0 +1,72 @@

+package org.picoextras.gui.swing;
+
+import javax.swing.*;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import javax.swing.event.DocumentListener;
+import javax.swing.event.DocumentEvent;
+import java.awt.event.ActionEvent;
+import java.awt.*;
+
+/**
+ * Action that adds a new component. Enables itself if a container node
+ * is selected and the current classname is a loadabe class. Otherwise
+ * disabled.
+ *
+ * @author Aslak Helles&oslash;y
+ * @version $Revision: 1.1 $
+ */
+public class AddPicoComponentAction extends AddToContainerNodeAction implements DocumentListener {
+ private final ComponentRegistrar componentRegistrar;
+
+ private Class componentImplementation = null;
+
+ public AddPicoComponentAction(
+ ComponentRegistrar componentRegistrar,
+ Component errorDialogParent,
+ JTree treeToListenTo,
+ Document documentToListenTo) {
+ super("Add PicoComponent", errorDialogParent, treeToListenTo);
+ this.componentRegistrar = componentRegistrar;
+
+ documentToListenTo.addDocumentListener(this);
+ }
+
+ public void actionPerformed(ActionEvent evt) {
+ try {
+ componentRegistrar.createComponentNodeInTree(getSelectedContainerNode(), componentImplementation, componentImplementation);
+ } catch (Exception e) {
+ showErrorDialog(e);
+ }
+ }
+
+ public void insertUpdate(DocumentEvent e) {
+ setClassName(e);
+ }
+
+ public void removeUpdate(DocumentEvent e) {
+ setClassName(e);
+ }
+
+ public void changedUpdate(DocumentEvent e) {
+ setClassName(e);
+ }
+
+ private void setClassName(DocumentEvent evt) {
+ try {
+ String currentClassName = evt.getDocument().getText(0, evt.getDocument().getLength());
+ try {
+ componentImplementation = getClass().getClassLoader().loadClass(currentClassName);
+ } catch (ClassNotFoundException e) {
+ componentImplementation = null;
+ }
+ setEnabled();
+ } catch (BadLocationException e) {
+ throw new IllegalStateException(e.getMessage());
+ }
+ }
+
+ protected void setEnabled() {
+ setEnabled(componentImplementation != null && getSelectedContainerNode() != null);
+ }
+}

\ No newline at end of file