Changeset 1063

Show
Ignore:
Timestamp:
11/04/06 10:18:24 (2 years ago)
Author:
wrobell
Message:

- started updating fork/join node item

Files:

Legend:

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

    r1061 r1063  
    275275 
    276276 
    277 #class ForkNodePlacementAction(PlacementAction): 
    278 #    id = 'InsertForkNode' 
    279 #    label = 'Fork/Join Node' 
    280 #    tooltip = 'Create a new fork/join node' 
    281 #    stock_id = 'gaphor-fork-node' 
    282 #    name = 'ForkNode' 
    283 #    type = diagram.ForkNodeItem 
     277class ForkNodePlacementAction(PlacementAction): 
     278    id = 'InsertForkNode' 
     279    label = 'Fork/Join Node' 
     280    tooltip = 'Create a new fork/join node' 
     281    stock_id = 'gaphor-fork-node' 
     282    name = 'ForkNode' 
     283    type = items.ForkNodeItem 
    284284#    subject_type = UML.ForkNode 
    285 
    286 #register_action(ForkNodePlacementAction) 
     285    subject_type = UML.JoinNode 
     286 
     287register_action(ForkNodePlacementAction) 
    287288 
    288289 
  • gaphor/branches/new-canvas/gaphor/adapters/editors.py

    r1062 r1063  
    159159     
    160160 
     161 
     162class ForkNodeItemEditor(object): 
     163    """Text edit support for fork node join specification. 
     164    """ 
     165    interface.implements(IEditor) 
     166    component.adapts(items.ForkNodeItem) 
     167 
     168    def __init__(self, item): 
     169        self._item = item 
     170 
     171    def is_editable(self, x, y): 
     172        return True 
     173 
     174    def get_text(self): 
     175        """ 
     176        Get join specification text. 
     177        """ 
     178        if self._item.subject.joinSpec: 
     179            return self._item.subject.joinSpec.value 
     180        else: 
     181            return '' 
     182 
     183    def get_bounds(self): 
     184        return None 
     185 
     186    def update_text(self, text): 
     187        """ 
     188        Set join specification text. 
     189        """ 
     190        spec = self._item.subject.joinSpec 
     191        if not spec: 
     192            from gaphor import resource 
     193            factory = resource(UML.ElementFactory) 
     194            spec = self._item.subject.joinSpec = factory.create(UML.LiteralSpecification) 
     195            spec.value = text 
     196 
     197    def key_pressed(self, pos, key): 
     198        pass 
     199 
     200component.provideAdapter(ForkNodeItemEditor) 
     201 
    161202# vim:sw=4:et:ai 
  • gaphor/branches/new-canvas/gaphor/diagram/activitynodes.py

    r1061 r1063  
    1212from gaphor.diagram.style import ALIGN_LEFT, ALIGN_CENTER, ALIGN_TOP, \ 
    1313        ALIGN_RIGHT, ALIGN_BOTTOM 
     14from gaphor.diagram.style import get_text_point 
     15from gaphas.util import text_extents 
    1416 
    1517 
     
    188190class ForkNodeItem(FDNode): 
    189191    """ 
    190     Representation of fork or join node. 
    191     """ 
    192     __uml__   = UML.ForkNode 
     192    Representation of fork and join node. 
     193    """ 
     194    __uml__   = UML.JoinNode 
     195    #__uml__   = UML.ForkNode 
    193196    __style__ = { 
    194197        'name-align': (ALIGN_CENTER, ALIGN_BOTTOM), 
    195198    } 
    196199 
    197     WIDTH  =  6.0 
    198     HEIGHT = 45.0 
    199     MARGIN = 10 
    200  
    201     def __init__(self, id=None): 
    202         GroupBase.__init__(self) 
    203         FDNode.__init__(self, id) 
    204  
    205         self._join_spec = TextElement('value', '{ joinSpec = %s }', 'and') 
    206         self.add(self._join_spec) 
    207  
    208         for h in self.handles: 
    209             h.props.movable = False 
    210             h.props.visible = False 
    211         self.handles[diacanvas.HANDLE_N].props.visible = True 
    212         self.handles[diacanvas.HANDLE_S].props.visible = True 
    213         self.handles[diacanvas.HANDLE_N].props.movable = True 
    214         self.handles[diacanvas.HANDLE_S].props.movable = True 
    215  
    216  
    217     def create_border(self): 
    218         line = diacanvas.shape.Path() 
    219         line.set_line_width(self.WIDTH) 
    220  
    221         self.set(width = self.WIDTH, height = self.HEIGHT) 
    222         return line 
    223  
    224  
    225     def draw_border(self): 
    226         """ 
    227         Draw line between central handles. 
    228         """ 
    229         p1 = self.handles[diacanvas.HANDLE_N].get_pos_i() 
    230         p2 = self.handles[diacanvas.HANDLE_S].get_pos_i() 
    231         self._border.line((p1, p2)) 
    232  
    233  
    234     def on_update(self, affine): 
    235         """ 
    236         Update fork/join node. 
    237  
    238         If node is join node then update also join specification. 
    239         """ 
    240         FDNode.on_update(self, affine) 
    241  
    242         w, h = self._join_spec.get_size() 
    243         self._join_spec.update_label((self.width - w) / 2,  
    244             -h - self.MARGIN) 
    245  
    246         GroupBase.on_update(self, affine) 
    247  
    248  
    249     def on_subject_notify(self, pspec, notifiers = ()): 
    250         """ 
    251         Detect changes of subject. 
    252  
    253         If subject is join node, then set subject of join specification 
    254         text element. 
    255         """ 
    256         FDNode.on_subject_notify(self, pspec, notifiers) 
    257         if self.subject and isinstance(self.subject, UML.JoinNode): 
    258             factory = resource(UML.ElementFactory) 
    259             if not self.subject.joinSpec: 
    260                 self.subject.joinSpec = factory.create(UML.LiteralSpecification) 
    261                 self.subject.joinSpec.value = 'and' 
    262             self._join_spec.subject = self.subject.joinSpec 
    263         else: 
    264             self._join_spec.subject = None 
    265         self.request_update() 
     200    def __init__(self, id = None, width = 6.0, height = 45.0): 
     201#        GroupBase.__init__(self) 
     202        FDNode.__init__(self, id, width, height) 
     203 
     204        self._join_spec = 'join spec test' 
     205        self._join_spec_x = 0 
     206        self._join_spec_y = 0 
     207 
     208#        for h in self.handles: 
     209#            h.props.movable = False 
     210#            h.props.visible = False 
     211#        self.handles[diacanvas.HANDLE_N].props.visible = True 
     212#        self.handles[diacanvas.HANDLE_S].props.visible = True 
     213#        self.handles[diacanvas.HANDLE_N].props.movable = True 
     214#        self.handles[diacanvas.HANDLE_S].props.movable = True 
     215 
     216    def update(self, context): 
     217        """ 
     218        Update join specification position. 
     219        """ 
     220        self._join_spec_x, self._join_spec_y = get_text_point( 
     221                text_extents(context.cairo, self._join_spec), 
     222                self.width, self.height, 
     223                (ALIGN_CENTER, ALIGN_TOP), 
     224                (10, 0, 0, 0), 
     225                True) 
     226 
     227 
     228    def draw(self, context): 
     229        """ 
     230        Draw vertical line - symbol of fork and join nodes. Join 
     231        specification is also drawn above the item. 
     232        """ 
     233        cr = context.cairo 
     234        cr.set_line_width(self.width) 
     235        cr.move_to(0, 0) 
     236        cr.line_to(0, self.height) 
     237        cr.move_to(self.name_x, self.name_y) 
     238 
     239        cr.move_to(self._join_spec_x, self._join_spec_y) 
     240        cr.show_text(self._join_spec) 
     241 
     242        cr.stroke() 
     243        super(ForkNodeItem, self).draw(context) 
     244 
     245 
     246###    def on_update(self, affine): 
     247###        """ 
     248###        Update fork/join node. 
     249### 
     250###        If node is join node then update also join specification. 
     251###        """ 
     252###        FDNode.on_update(self, affine) 
     253### 
     254###        w, h = self._join_spec.get_size() 
     255###        self._join_spec.update_label((self.width - w) / 2,  
     256###            -h - self.MARGIN) 
     257### 
     258###        GroupBase.on_update(self, affine) 
     259### 
     260### 
     261###    def on_subject_notify(self, pspec, notifiers = ()): 
     262###        """ 
     263###        Detect changes of subject. 
     264### 
     265###        If subject is join node, then set subject of join specification 
     266###        text element. 
     267###        """ 
     268###        FDNode.on_subject_notify(self, pspec, notifiers) 
     269###        if self.subject and isinstance(self.subject, UML.JoinNode): 
     270###            factory = resource(UML.ElementFactory) 
     271###            if not self.subject.joinSpec: 
     272###                self.subject.joinSpec = factory.create(UML.LiteralSpecification) 
     273###                self.subject.joinSpec.value = 'and' 
     274###            self._join_spec.subject = self.subject.joinSpec 
     275###        else: 
     276###            self._join_spec.subject = None 
     277###        self.request_update() 
    266278 
    267279# vim:sw=4:et 
  • gaphor/branches/new-canvas/gaphor/diagram/items.py

    r1061 r1063  
    3333from gaphor.diagram.activitynodes import FlowFinalNodeItem 
    3434from gaphor.diagram.activitynodes import DecisionNodeItem 
     35from gaphor.diagram.activitynodes import ForkNodeItem 
    3536 
    3637# Use Cases: