umbrello API Documentation

toolbarstatefactory.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2004-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 #include "toolbarstatefactory.h"
00012 
00013 #include "toolbarstate.h"
00014 #include "toolbarstatepool.h"
00015 #include "toolbarstateother.h"
00016 #include "toolbarstatearrow.h"
00017 #include "toolbarstatemessages.h"
00018 #include "toolbarstateassociation.h"
00019 
00020 #include "umlview.h"
00021 
00022 ToolBarStateFactory::ToolBarStateFactory(UMLView *umlView)
00023 {
00024     m_pUMLView = umlView;
00025 
00026     for (int i = 0; i < NR_OF_TOOLBAR_STATES; i++)
00027     {
00028         states[i] = NULL;
00029     }
00030 }
00031 
00032 ToolBarStateFactory::~ToolBarStateFactory()
00033 {
00034     for (int i = 0; i < NR_OF_TOOLBAR_STATES; i++)
00035     {
00036         if (states[i] != NULL) delete states[i];
00037     }
00038 }
00039 
00040 
00041 ToolBarState* ToolBarStateFactory::getState(const WorkToolBar::ToolBar_Buttons &toolbarButton)
00042 {
00043     int key = getKey(toolbarButton);
00044 
00045     if (states[key] == NULL)
00046     {
00047         switch (key)
00048         {
00049             // When you add a new state, make sure you also increase the
00050             // NR_OF_TOOLBAR_STATES
00051         case 0: states[0] = new ToolBarStateOther(m_pUMLView); break;
00052         case 1: states[1] = new ToolBarStateAssociation(m_pUMLView); break;
00053         case 2: states[2] = new ToolBarStateMessages(m_pUMLView); break;
00054 
00055             // This case has no pool.
00056         case 3: states[3] = new ToolBarStateArrow(m_pUMLView); break;
00057         }
00058     }
00059 
00060     // Make explicit the selected button. This is only necessary for states with a pool.
00061     if (key <= 2) ((ToolBarStatePool *) states[key])->setButton(toolbarButton);
00062 
00063     return states[key];
00064 }
00065 
00066 
00067 int ToolBarStateFactory::getKey(const WorkToolBar::ToolBar_Buttons &toolbarButton) const
00068 {
00069     switch (toolbarButton)
00070     {
00071         // Associations
00072     case WorkToolBar::tbb_Dependency:          return 1;
00073     case WorkToolBar::tbb_Aggregation:         return 1;
00074     case WorkToolBar::tbb_Relationship:        return 1;
00075     case WorkToolBar::tbb_Generalization:      return 1;
00076     case WorkToolBar::tbb_Association:         return 1;
00077     case WorkToolBar::tbb_UniAssociation:      return 1;
00078     case WorkToolBar::tbb_Composition:         return 1;
00079     case WorkToolBar::tbb_Containment:         return 1;
00080     case WorkToolBar::tbb_Anchor:              return 1;
00081     case WorkToolBar::tbb_Coll_Message:        return 1;
00082     case WorkToolBar::tbb_State_Transition:    return 1;
00083     case WorkToolBar::tbb_Activity_Transition: return 1;
00084 
00085         // Messages
00086     case WorkToolBar::tbb_Seq_Message_Synchronous:  return 2;
00087     case WorkToolBar::tbb_Seq_Message_Asynchronous: return 2;
00088 
00089         // Arrow pointer
00090     case WorkToolBar::tbb_Arrow: return 3;
00091 
00092         // Other.
00093     default: return 0;
00094     }
00095 
00096 }
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:08:00 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003