summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/toolbarstatefactory.cpp
blob: 66cf89bb97f689fdce70fc31cacdb4bf6fe8f1dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   copyright (C) 2004-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/
#include "toolbarstatefactory.h"

#include "toolbarstate.h"
#include "toolbarstatepool.h"
#include "toolbarstateother.h"
#include "toolbarstatearrow.h"
#include "toolbarstatemessages.h"
#include "toolbarstateassociation.h"

#include "umlview.h"

ToolBarStateFactory::ToolBarStateFactory(UMLView *umlView)
{
    m_pUMLView = umlView;

    for (int i = 0; i < NR_OF_TOOLBAR_STATES; i++)
    {
        states[i] = NULL;
    }
}

ToolBarStateFactory::~ToolBarStateFactory()
{
    for (int i = 0; i < NR_OF_TOOLBAR_STATES; i++)
    {
        if (states[i] != NULL) delete states[i];
    }
}


ToolBarState* ToolBarStateFactory::getState(const WorkToolBar::ToolBar_Buttons &toolbarButton)
{
    int key = getKey(toolbarButton);

    if (states[key] == NULL)
    {
        switch (key)
        {
            // When you add a new state, make sure you also increase the
            // NR_OF_TOOLBAR_STATES
        case 0: states[0] = new ToolBarStateOther(m_pUMLView); break;
        case 1: states[1] = new ToolBarStateAssociation(m_pUMLView); break;
        case 2: states[2] = new ToolBarStateMessages(m_pUMLView); break;

            // This case has no pool.
        case 3: states[3] = new ToolBarStateArrow(m_pUMLView); break;
        }
    }

    // Make explicit the selected button. This is only necessary for states with a pool.
    if (key <= 2) ((ToolBarStatePool *) states[key])->setButton(toolbarButton);

    return states[key];
}


int ToolBarStateFactory::getKey(const WorkToolBar::ToolBar_Buttons &toolbarButton) const
{
    switch (toolbarButton)
    {
        // Associations
    case WorkToolBar::tbb_Dependency:          return 1;
    case WorkToolBar::tbb_Aggregation:         return 1;
    case WorkToolBar::tbb_Relationship:        return 1;
    case WorkToolBar::tbb_Generalization:      return 1;
    case WorkToolBar::tbb_Association:         return 1;
    case WorkToolBar::tbb_UniAssociation:      return 1;
    case WorkToolBar::tbb_Composition:         return 1;
    case WorkToolBar::tbb_Containment:         return 1;
    case WorkToolBar::tbb_Anchor:              return 1;
    case WorkToolBar::tbb_Coll_Message:        return 1;
    case WorkToolBar::tbb_State_Transition:    return 1;
    case WorkToolBar::tbb_Activity_Transition: return 1;

        // Messages
    case WorkToolBar::tbb_Seq_Message_Synchronous:  return 2;
    case WorkToolBar::tbb_Seq_Message_Asynchronous: return 2;

        // Arrow pointer
    case WorkToolBar::tbb_Arrow: return 3;

        // Other.
    default: return 0;
    }

}