Imports System.Windows.Forms

Public Class Mediator
  Private cpButton As CpyButton
  Private clrButton As clrButton
  Private txkids As TextBox
  Private pkList As ListBox
  Private klist As KidsListBox
  Private kds As Kids
  '-----
  Public Overloads Sub register(ByVal cpb As CpyButton)
    cpButton = cpb
  End Sub
  '-----
  Public Overloads Sub register(ByVal clr As clrButton)
    clrButton = clr
  End Sub
  '-----
  Public Overloads Sub register(ByVal kd As KidsListBox)
    klist = kd
  End Sub
  '-----
  Public Overloads Sub register(ByVal pick As ListBox)
    pkList = pick
  End Sub
  '-----
  Public Overloads Sub register(ByVal tx As TextBox)
    txkids = tx
  End Sub
  '-----
  Public Sub kidPicked()
    'Skopiuj tekst z listy do pola tekstowego
    txkids.Text = klist.Text
    'Aktywuj przycisk copy 
    cpButton.Enabled = True
  End Sub
  '-----
  Public Sub copyClicked()
    'Skopiuj nazwisko na drugą listę
    pkList.Items.Add(txkids.Text)
    'Atywuj przycisk clear 
    clrButton.Enabled = True
    klist.SelectedIndex = -1
  End Sub
  '-----
  Public Sub clearClicked()
    'Dezaktywuj przyciski i wyczyść listę
    cpButton.Enabled = False
    clrButton.Enabled = False
    pkList.Items.Clear()
  End Sub
  '-----
  Public Sub init()
    'inicjuje mediatora
    Dim kd As Kid
    clearClicked()                'Ustaw stan wyjściowy
    'Wczytaj plik i załaduj listy
    kds = New Kids(Application.StartupPath & "\50free.txt")
    Dim iter As Iterator = kds.getIterator

    While (iter.hasMoreElements)
      kd = CType(iter.nextElement, Kid)
      klist.Items.Add(kd.getFrname + " " + kd.getLname)
    End While
  End Sub
End Class
