1 19 20 package org.objectweb.jac.aspects.gui.swing; 21 22 import org.objectweb.jac.aspects.gui.*; 23 import org.objectweb.jac.core.rtti.FieldItem; 24 import org.objectweb.jac.util.Stack; 25 import java.awt.Dimension ; 26 import java.awt.Insets ; 27 import java.awt.event.ActionEvent ; 28 import java.awt.event.ActionListener ; 29 import javax.swing.Box ; 30 import javax.swing.JButton ; 31 import javax.swing.JLabel ; 32 33 42 43 public class ReferenceView extends AbstractFieldView 44 implements FieldView, FieldUpdate, ObjectUpdate, ActionListener { 45 46 Object object; 47 JButton viewButton; 48 JLabel label = new JLabel (); 49 50 54 55 public ReferenceView(Object object, Object substance, FieldItem reference) { 56 super(substance,reference); 57 this.object = object; 58 59 add(label); 60 add(Box.createRigidArea(new Dimension (20,1))); 61 62 JButton b; 63 viewButton = new JButton (ResourceManager.getIconResource("view_icon")); 64 viewButton.setEnabled(false); 65 viewButton.setToolTipText("View"); 66 viewButton.setActionCommand("open"); 67 viewButton.addActionListener(this); 68 viewButton.setMargin(new Insets (1,1,1,1)); 69 add(viewButton); 70 71 if (GuiAC.getGraphicContext()!=null) 72 contexts.addAll(GuiAC.getGraphicContext()); 73 if (field!=null) 74 contexts.push(field); 75 refreshView(); 76 } 77 78 Stack contexts = new Stack(); 79 80 public ReferenceView() { 81 label.setFont(null); 82 add(label); 83 } 84 85 93 94 public void actionPerformed(ActionEvent evt) { 95 if (evt.getActionCommand().equals("open")) { 96 if (object!=null) { 97 EventHandler.get().onSelection(context,field,object,null,null,true); 98 } 99 } else if (evt.getActionCommand().equals("edit")) { 100 } 102 } 103 104 public void refreshView() { 105 Utils.registerObject(object,this); 106 String name; 107 if (object!=null) { 108 if (viewButton!=null) 109 viewButton.setEnabled(true); 110 name = GuiAC.toString(object,contexts); 111 } else { 112 if (viewButton!=null) 113 viewButton.setEnabled(false); 114 name = ""; 115 } 116 label.setText(name); 117 } 118 119 121 public void setValue(Object value) { 122 Utils.unregisterObject(object,this); 123 this.object = value; 124 refreshView(); 125 } 126 127 public void close(boolean validate) { 128 Utils.unregisterObject(object,this); 129 Utils.unregisterField(substance,field,this); 130 } 131 132 134 public void fieldUpdated(Object substance, FieldItem field, 135 Object value, Object param) { 136 setValue(value); 137 } 138 139 141 public void objectUpdated(Object object, Object param) { 142 refreshView(); 143 } 144 } 145 | Popular Tags |