View Javadoc
1 package com.bonevich.erj.ui; 2 3 import com.bonevich.erj.model.Relation; 4 import com.bonevich.erj.diagram.FigRelation; 5 6 import org.tigris.gef.base.Editor; 7 import org.tigris.gef.base.Globals; 8 import org.tigris.gef.base.FigModifyingModeImpl; 9 import org.tigris.gef.presentation.Fig; 10 11 import java.awt.event.MouseEvent; 12 13 /*** 14 * Mode to add a new default Attribute to a Relation. 15 */ 16 public class ModeCreateAttribute extends FigModifyingModeImpl 17 { 18 //////////////////////////////////////////////////////////////// 19 // Constructor 20 public ModeCreateAttribute() { } 21 public ModeCreateAttribute(Editor editor) { super(editor); } 22 23 //////////////////////////////////////////////////////////////// 24 // Mode API 25 public String instructions() 26 { 27 return "Click on a relation to add a new attribute"; 28 } 29 30 /*** 31 * On mouseClicked, find the relation node over which we are 32 * positioned and ask that node's owner relation to add a new 33 * default attribute. 34 */ 35 public void mouseClicked(MouseEvent me) 36 { 37 //System.err.println("mouse clicked!"); 38 if (me.isConsumed()) 39 { 40 return; 41 } 42 43 int x = me.getX(), y = me.getY(); 44 Editor ce = Globals.curEditor(); 45 Fig f = ce.hit(x, y); 46 // maybe it was not a direct hit, so check a buffer region 47 if (f == null) 48 { 49 f = ce.hit(x-16, y-16, 32, 32); 50 } 51 52 if (f instanceof FigRelation) 53 { 54 FigRelation destFigNode = (FigRelation) f; 55 Relation relation = (Relation) f.getOwner(); 56 relation.createAttribute(); 57 destFigNode.damage(); 58 ce.damaged(destFigNode); 59 } 60 done(); 61 me.consume(); 62 } 63 64 } /* end class ModeCreateAttribute */

This page was automatically generated by Maven