~fredericp/zaluum/wip-ide

« back to all changes in this revision

Viewing changes to org.zaluum.model/src/org/zaluum/model/FSMBox.java

  • Committer: Frederic Perez Ordeig
  • Date: 2009-12-17 16:27:19 UTC
  • Revision ID: frederic@zaluum.com-20091217162719-wplg8lm7zbr1jfgu
Refactored box cloning
Port name acts as an id and cannot be duplicated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
                setName("fsm");
44
44
                states = Sets.newHashSet();
45
45
        }
46
 
        public void addState(State s){
47
 
                Preconditions.checkNotNull(s);
48
 
                states.add(s);
49
 
                observable.notifyObservers();
50
 
        }
51
 
        public ImmutableSet<State> getStates() {
52
 
                return ImmutableSet.copyOf(states);
53
 
        }
54
 
        public void removeState(State stateModel) {
55
 
                stateModel.disconnectAll();
56
 
                states.remove(stateModel);
57
 
                observable.notifyObservers();
58
 
        }
59
 
        @Override
60
 
        public BoxCopyResult deepCopy(){
61
 
                FSMBox newBox = new FSMBox();
62
 
                newBox.setName(getName());
63
 
                newBox.setBounds(new Rectangle(getBounds()));
 
46
        public FSMBox(FSMBox toCopy){
 
47
                super(toCopy);
 
48
                states = Sets.newHashSet();
64
49
                HashBiMap<State, State> oldToNew = HashBiMap.create();
65
 
                for (State s : states){
66
 
                        State newState = new State(s.getName(),s.getPosition().getCopy(),newBox);
67
 
                        newState.setEntryActions(s.getEntryActions());
68
 
                        newState.setExitActions(s.getExitActions());
69
 
                        newState.setInitial(s.isInitial());
 
50
                for (State s : toCopy.states){
 
51
                        State newState = new State(s, this);
70
52
                        oldToNew.put(s, newState);
71
 
                        newBox.addState(newState);
72
53
                }
73
54
                for (Entry<State, State> e : oldToNew.entrySet()){
74
55
                        State oldfrom = e.getKey();
78
59
                                State newTo = oldToNew.get(oldTo);
79
60
                                Transition transition = Transition.create(newfrom, newTo);
80
61
                                transition.setCondition(trans.getCondition());
81
 
                                
82
62
                        }
83
63
                }
84
 
                return copyPorts(newBox);
 
64
 
 
65
        }
 
66
 
 
67
        protected void addStateInternal(State s){
 
68
                states.add(s);
 
69
                observable.notifyObservers();
 
70
        }
 
71
        public void restoreState(State s){
 
72
                Preconditions.checkArgument(s.getBox()==this);
 
73
                addStateInternal(s);
 
74
        }
 
75
        public ImmutableSet<State> getStates() {
 
76
                return ImmutableSet.copyOf(states);
 
77
        }
 
78
        public void removeState(State stateModel) {
 
79
                stateModel.disconnectAll();
 
80
                states.remove(stateModel);
 
81
                observable.notifyObservers();
 
82
        }
 
83
        @Override
 
84
        public Box deepCopy(){
 
85
                return  new FSMBox(this);
85
86
        }
86
87
        @Override
87
88
        public BoxDescriptor getDescriptor() {