1:/* 2: * Programmins graphical user interfaces 3: * Example: Diagram.h 4: * Jarkko Leponiemi 2003 5: */ 6:#pragma once 7: 8:#include <string> 9:#include <list> 10:#include "Observable.h" 11: 12:#define NODETYPE 0 13:#define CONNECTORTYPE 1 14: 15:using namespace std; 16: 17:// the diagram node class 18:class Node 19:{ 20:public: 21: Node(string title, int x, int y); 22: Node(const Node ©); 23: 24: const Node& operator=(const Node ©); 25: 26: const string& GetTitle() { return title; } 27: int GetX() { return x; } 28: int GetY() { return y; } 29: 30: void Move(int x, int y); 31: 32:private: 33: string title; 34: int x; 35: int y; 36:}; 37: 38:// the diagram connector class 39:class Connector 40:{ 41:public: 42: Connector(Node *n1, Node *n2); 43: Connector(const Connector ©); 44: 45: const Connector& operator=(const Connector ©); 46: 47: Node *GetNode1() { return n1; } 48: Node *GetNode2() { return n2; } 49: 50:private: 51: Node *n1, *n2; 52:}; 53: 54:typedef list<Node*> NodeList; 55:typedef list<Connector*> ConnectorList; 56: 57:// the diagram data model 58:class Diagram : public Observable 59:{ 60:public: 61: Diagram() { nextid = 0; } 62: 63: const NodeList& GetNodes() { return nodes; } 64: const ConnectorList& GetConnectors() { return connectors; } 65: 66: int GetNextID() { return ++nextid; } 67: 68: Node* CreateNode(string title, int x, int y); 69: Connector* CreateConnector(Node *n1, Node *n2); 70: 71: void MoveNode(Node * n, int x, int y); 72: 73:private: 74: NodeList nodes; 75: ConnectorList connectors; 76: int nextid; 77:}; 78: