' D. de Haas
' Amsterdam, Netherlands
' 29 October 2002
' ddhadam@yahoo.com

Option Explicit On 
Option Strict On

Imports System
Imports System.Drawing

Namespace Graphics

    Public Class LineCollection
        ' Specialized Collection for storing DdH.Graphics.Line
        ' It's is actually an Array, that acts like an collection
        ' so it's possible to place lines at any index

        Private mLines() As Graphics.Line
        Private mCount As Integer

        '==== Events

        '==== Constructors

        '==== Private Methods/Functions

        '==== Public Functions

        Public Overridable Function Add(ByVal line As Graphics.Line) As Integer
            ' Add a line the collection

            ' Set the upper bound of the inner array
            If mLines Is Nothing Then
                ReDim mLines(0)
            Else
                ReDim Preserve mLines(mLines.Length)
            End If

            Dim index As Integer
            index = mLines.Length - 1

            ' Add line to the inner array
            mLines(index) = line

            Return index
        End Function

        '==== Public Methodes

        Public Overridable Sub Clear()
            mLines = Nothing
        End Sub

        Public Overridable Sub Insert(ByVal index As Integer, ByVal line As Graphics.Line)
            ' Add a line the collection on the (index) location

            ' Set the upper bound of the inner array
            If index >= Me.Count Then
                ReDim Preserve mLines(index)
            End If

            ' Add line to the inner array
            mLines(index) = line
        End Sub

        Public Overridable Sub Remove(ByVal index As Integer)
            ' Remove block from the collection

            Try
                mLines(index) = Nothing
            Catch
                ' nothing
            End Try
        End Sub

        '==== Properties

        Public ReadOnly Property Item(ByVal index As Integer) As Graphics.Line
            Get
                Try
                    Return mLines(index)
                Catch
                    Return Nothing
                End Try
            End Get
        End Property

        Public ReadOnly Property Count() As Integer
            Get
                If mLines Is Nothing Then
                    Return 0
                Else
                    Return mLines.Length
                End If
            End Get
        End Property

    End Class

End Namespace
