Free cookie consent management tool by TermsFeed Policy Generator

source: stable/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/Netron.Diagramming.Core-3.0.2672.12446/Utils/NetronClipboard.cs

Last change on this file was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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