Changeset 1101

Show
Ignore:
Timestamp:
12/08/06 01:56:37 (2 years ago)
Author:
arjanmol
Message:

added editor for objectNode

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/branches/new-canvas/gaphor/actions/tests/test_placementactions.py

    r1100 r1101  
    104104        self.do_test_placement(placementactions.FlowFinalNodePlacementAction()) 
    105105 
     106    def test_objectnode_placement(self): 
     107        self.do_test_placement(placementactions.ObjectNodePlacementAction()) 
     108 
    106109    def test_flow_placement(self): 
    107110        self.do_test_placement(placementactions.FlowPlacementAction()) 
  • gaphor/branches/new-canvas/gaphor/adapters/editors.py

    r1098 r1101  
    6666 
    6767component.provideAdapter(NamedItemEditor) 
     68 
     69 
     70class ObjectNodeItemEditor(NamedItemEditor): 
     71    component.adapts(items.ObjectNodeItem) 
     72 
     73    def is_editable(self, x, y): 
     74        self.edit_tag = (x, y) in self._item.tag_bounds 
     75        return True 
     76 
     77    def get_text(self): 
     78        if self.edit_tag: 
     79            return self._item.subject.upperBound.value 
     80        else: 
     81            return super(ObjectNodeItemEditor, self).get_text() 
     82 
     83    def update_text(self, text): 
     84        if self.edit_tag: 
     85            self._item.subject.upperBound.value = text 
     86        else: 
     87            return super(ObjectNodeItemEditor, self).update_text(text) 
     88        self._item.request_update() 
     89 
     90component.provideAdapter(ObjectNodeItemEditor) 
    6891 
    6992 
  • gaphor/branches/new-canvas/gaphor/diagram/items.py

    r1100 r1101  
    3737from gaphor.diagram.activitynodes import ForkNodeItem 
    3838from gaphor.diagram.flow import FlowItem 
     39from gaphor.diagram.objectnode import ObjectNodeItem 
    3940 
    4041# Use Cases: 
  • gaphor/branches/new-canvas/gaphor/diagram/objectnode.py

    r1100 r1101  
    1111#from gaphor.diagram.groupable import GroupBase 
    1212from gaphor.diagram.nameditem import NamedItem 
     13from gaphas.util import text_extents, text_multiline 
     14from gaphas.geometry import Rectangle, distance_rectangle_point 
    1315 
    1416 
     
    2123    """ 
    2224 
    23     __uml__      = UML.ObjectNode 
     25    __uml__ = UML.ObjectNode 
    2426 
    2527    __style__ = { 
     
    4244        self._tag = '' #TextElement('value', '{ upperBound = %s }', '*') 
    4345        self._tag_bounds = None 
    44         #self.add(self._upper_bound) 
    45  
    46         #self._ordering = diacanvas.shape.Text() 
    47         #self._ordering.set_font_description(pango.FontDescription(font.FONT)) 
    48         #self._ordering.set_alignment(pango.ALIGN_CENTER) 
    49         #self._ordering.set_markup(False) 
    5046 
    5147        self._show_ordering = False 
     
    5955 
    6056    ordering = property(lambda s: s.subject.ordering, _set_ordering) 
     57 
     58    tag_bounds = property(lambda s: s._tag_bounds) 
    6159 
    6260    def _set_show_ordering(self, value): 
     
    10098        # TODO: format tag properly: 
    10199        if self.subject.upperBound: 
    102             self._tag = '{ upperBound = %s }' % self.subject.upperBound.value 
     100            self._tag = '{ upperBound = %s }\n' % self.subject.upperBound.value 
    103101 
    104102        self._tag += '{ ordering = %s }' % self.subject.ordering 
    105103 
    106         w, h = text_extents(self._tag
     104        w, h = text_extents(context.cairo, self._tag, multiline=True
    107105        x = (self.width - w) / 2 
    108         y = self.height + self.style.margin[0
     106        y = self.height + self.style.margin[2
    109107        self._tag_bounds = Rectangle(x, y, width=w, height=h) 
     108 
     109    def point(self, x, y): 
     110        """ 
     111        Return the distance from (x, y) to the item. 
     112        """ 
     113        d1 = super(ObjectNodeItem, self).point(x, y) 
     114        d2 = distance_rectangle_point(self._tag_bounds, (x, y)) 
     115        return min(d1, d2) 
    110116 
    111117    def draw(self, context):