Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Utils/NetronClipboard.cs @ 3757

Last change on this file since 3757 was 2768, checked in by mkommend, 14 years ago

added solution folders and sources for the netron library (ticket #867)

File size: 4.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Collections;
5using System.Diagnostics;
6using System.IO;
7
8namespace Netron.Diagramming.Core
9{
10    // ----------------------------------------------------------------------
11    /// <summary>
12    /// Our custom "clipboard" for copying diagram elements (or anything else
13    /// for that matter) to.
14    /// </summary>
15    // ----------------------------------------------------------------------
16    public static class NetronClipboard
17    {
18        // ------------------------------------------------------------------
19        /// <summary>
20        /// The items on the clipboard.
21        /// </summary>
22        // ------------------------------------------------------------------
23        static ArrayList items = new ArrayList();
24
25        // ------------------------------------------------------------------
26        /// <summary>
27        /// Gets the collection of all items.
28        /// </summary>
29        // ------------------------------------------------------------------
30        public static ArrayList Items
31        {
32            get
33            {
34                return items;
35            }
36        }
37
38        // ------------------------------------------------------------------
39        /// <summary>
40        /// Adds the item to the collection.
41        /// </summary>
42        /// <param name="item">object</param>
43        /// <returns>int</returns>
44        // ------------------------------------------------------------------
45        public static int Add(object item)
46        {
47            return items.Add(item);
48        }
49
50        public static int AddStream(MemoryStream stream)
51        {
52            return items.Add(stream);
53        }
54
55        // ------------------------------------------------------------------
56        /// <summary>
57        /// Clears the collection.
58        /// </summary>
59        // ------------------------------------------------------------------
60        public static void Clear()
61        {
62            items.Clear();
63        }
64
65        // ------------------------------------------------------------------
66        /// <summary>
67        /// Returns if we have any items of the type specified.
68        /// </summary>
69        /// <param name="type">Type</param>
70        /// <returns>bool</returns>
71        // ------------------------------------------------------------------
72        public static bool ContainsData(Type type)
73        {
74            foreach (Object obj in items)
75            {
76                if (obj.GetType() == type)
77                {
78                    return true;
79                }
80            }
81            return false;
82        }
83
84        // ------------------------------------------------------------------
85        /// <summary>
86        /// Gets all items of the type specified.
87        /// </summary>
88        /// <param name="type"></param>
89        /// <returns></returns>
90        // ------------------------------------------------------------------
91        public static ArrayList GetAll(Type type)
92        {
93            ArrayList subitems = new ArrayList();
94            foreach (Object obj in items)
95            {
96                if (obj.GetType() == type)
97                {
98                    subitems.Add(obj);
99                }
100            }
101            return subitems;
102        }
103
104        // ------------------------------------------------------------------
105        /// <summary>
106        /// Returns the FIRST item found that has the type specified.
107        /// </summary>
108        /// <param name="type">Type</param>
109        /// <returns>object</returns>
110        // ------------------------------------------------------------------
111        public static object Get(Type type)
112        {
113            foreach (Object obj in items)
114            {
115                if (obj.GetType() == type)
116                {
117                    return obj;
118                }
119            }
120            return null;
121        }
122
123        public static MemoryStream GetMemoryStream()
124        {
125            foreach (object obj in items)
126            {
127                if (obj is MemoryStream)
128                {
129                    return obj as MemoryStream;
130                }
131            }
132
133            return null;
134        }
135    }
136}
Note: See TracBrowser for help on using the repository browser.