Source code for MSQuant: frmDimensions.vb, MSQuant/msquant/src/GUI/forms/frmDimensions.vb.

Table of contents page.

Home page for MSQuant.

'****************************************************************************
'* Copyright (C) 2008 Peter Mortensen and Matthias Mann                     *
'* This file is part of MSQuant.                                            *
'*                                                                          *
'* MSQuant is distributed under the terms of                                *
'* the GNU General Public License. See src/COPYING.TXT or                   *
'* <http://www.gnu.org/licenses/gpl.txt> for details.                       *
'*                                                                          *
'* MSQuant is free software; you can redistribute it                        *
'* and/or modify it under the terms of the GNU                              *
'* General Public License as published by the Free                          *
'* Software Foundation; either version 2 of the                             *
'* License, or (at your option) any later version.                          *
'*                                                                          *
'* MSQuant is distributed in the hope that it will be                       *
'* useful, but WITHOUT ANY WARRANTY; without even the                       *
'* implied warranty of MERCHANTABILITY or FITNESS FOR                       *
'* A PARTICULAR PURPOSE.  See the GNU General Public                        *
'* License for more details.                                                *
'*                                                                          *
'* You should have received a copy of the GNU General                       *
'* Public License along with MSQuant; if not, write to                      *
'* the Free Software Foundation, Inc., 59 Temple                            *
'* Place, Suite 330, Boston, MA  02111-1307  USA                            *
'*                                                                          *
'* Purpose: Holds Class frmDimensions, see below for                        *
'*          documentation.                                                  *
'*                                                                          *
'****************************************************************************

'****************************************************************************
'*                               CEBI                                       *
'*                    Software Development Group                            *
'*                         Peter Mortensen                                  *
'*                E-mail: NUKESPAMMERSdrmortensen@get2netZZZZZZ.dk          *
'*                 WWW: http://www.cebi.sdu.dk/                             *
'*                                                                          *
'*  Program for post-processing of result from search in mass               *
'*    spectrometric data.                                                   *
'*                                                                          *
'*    FILENAME:   frmDimensions.vb                                          *
'*    TYPE:  VISUAL_BASIC                                                   *
'*                                                                          *
'* CREATED: PM 2008-07-29   Vrs 1.0.                                        *
'* UPDATED: PM 2008-xx-xx                                                   *
'*                                                                          *
'****************************************************************************

Option Strict On
Option Explicit On

Imports System.Collections.Generic 'List.


Imports SDUPutility 'For CEBIspaces.


'****************************************************************************
'*    <placeholder for header>                                              *
'****************************************************************************
Public Class frmDimensions


    Private Const LABELMARKER As String = "dimTextLabel"

    Private Structure oneDimensionGUIstructure
        Dim txtName As System.Windows.Forms.TextBox
        Dim txtShortName As System.Windows.Forms.TextBox
        Dim txtDimSize2 As System.Windows.Forms.TextBox

        Dim txtStartNumber As System.Windows.Forms.TextBox
    End Structure 'oneDimensionGUIstructure


    Private mDimensionGUIlist As List(Of oneDimensionGUIstructure)

    Private mWorkingList As List(Of CEBIdimension)

    'Private mSpaces As CEBIspaces  not used...

    'Changed PM_HIGHER_LEVEL_PROCESSING 2008-09-02
    Public Event dimensionsDismissed( _
      ByVal aSender As Object, _
      ByVal anEvent As dimensionsEventArgs)


    'Changed PM_HIGHER_LEVEL_PROCESSING 2008-08-24
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Sub New(ByRef anInSettings As CEBIspaces)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        mDimensionGUIlist = Nothing 'Marker that it is the first time.

        'mSpaces = anInSettings  not used...

        Me.Init(anInSettings)
    End Sub 'Constructor.


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub changeYlevel2( _
      ByRef anInOut As System.Windows.Forms.Control, _
      ByVal anYlevel As Integer)

        Dim somePosition As System.Drawing.Point = anInOut.Location

        Trace.Assert(somePosition.X > 0, _
          "PIL ASSERT. X position is defined. Was about to set Y to: " & _
          anYlevel.ToString & " .")

        somePosition.Y = anYlevel
        anInOut.Location = somePosition
    End Sub 'changeYlevel2


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub changeYlevel_L( _
      ByRef anInOut As System.Windows.Forms.Label, _
      ByVal anYlevel As Integer)

        changeYlevel2( _
          DirectCast(anInOut, System.Windows.Forms.Control), anYlevel)
    End Sub 'changeYlevel_L


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub changeYlevel_T( _
      ByRef anInOut As System.Windows.Forms.TextBox, _
      ByVal anYlevel As Integer)

        changeYlevel2( _
          DirectCast(anInOut, System.Windows.Forms.Control), anYlevel)
    End Sub 'changeYlevel_T


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub changeYlevel_B( _
      ByRef anInOut As System.Windows.Forms.Button, _
      ByVal anYlevel As Integer)

        changeYlevel2( _
          DirectCast(anInOut, System.Windows.Forms.Control), anYlevel)
    End Sub 'changeYlevel_B


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub setupTextBox( _
      ByRef anOutSomeTextBox As System.Windows.Forms.TextBox, _
      ByRef anInTextBoxTemplate As System.Windows.Forms.TextBox, _
      ByRef anInTextToSet As String, _
      ByVal anYlevel As Integer)

        'anOutSomeTextBox = anInTextBoxTemplate 'Nope, does not 
        '  work... Or does it? That was before Me.Controls.Add()...
        anOutSomeTextBox = New System.Windows.Forms.TextBox

        'What do we need to set/copy?
        anOutSomeTextBox.Name = "txtXYZ" & "_" & anYlevel.ToString 'Good name??
        anOutSomeTextBox.Size = anInTextBoxTemplate.Size
        anOutSomeTextBox.TabIndex = anYlevel

        'anOutSomeTextBox.Width = anInTextBoxTemplate.Width
        anOutSomeTextBox.Text = anInTextToSet

        'Dim somePosition As System.Drawing.Point = anInTextBoxTemplate.Location
        'somePosition.Y = anYlevel
        'anOutSomeTextBox.Location = somePosition
        anOutSomeTextBox.Location = anInTextBoxTemplate.Location
        changeYlevel_T(anOutSomeTextBox, anYlevel)

        anOutSomeTextBox.Visible = True

        'Changed PM_READVALUES_DIMENSION_DIALOG 2008-09-15
        'anOutSomeTextBox.Enabled = False 'For now, as we are not reading back values...

        Me.Controls.Add(anOutSomeTextBox)
    End Sub 'setupTextBox


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub addTextLabel( _
      ByRef anInLabel As System.Windows.Forms.Label, _
      ByVal anYlevel As Integer)

        'Probably OK to share some reference members...
        'Dim newLabel As System.Windows.Forms.Label = anInLabel
        Dim newLabel As System.Windows.Forms.Label = _
          New System.Windows.Forms.Label

        newLabel.AutoSize = True
        newLabel.Name = "lblXYZ" & anYlevel.ToString
        newLabel.Size = anInLabel.Size
        newLabel.TabIndex = anYlevel
        newLabel.Text = anInLabel.Text

        newLabel.Tag = LABELMARKER

        'Dim somePosition As System.Drawing.Point = anInLabel.Location
        'somePosition.Y = anYlevel
        'newLabel.Location = somePosition
        newLabel.Location = anInLabel.Location
        changeYlevel_L(newLabel, anYlevel)

        newLabel.Visible = True

        Me.Controls.Add(newLabel)
    End Sub 'addTextLabel


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Function deepCopy( _
      ByRef anInList As List(Of CEBIdimension)) _
      As List(Of CEBIdimension)

        Dim toReturn As List(Of CEBIdimension) = New List(Of CEBIdimension)

        Dim someItem As CEBIdimension
        For Each someItem In anInList
            toReturn.Add(someItem)
        Next
        Return toReturn
    End Function 'deepCopy()


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub Init(ByRef anInSettings As CEBIspaces)

        Me.dimensionsSetup(anInSettings.getDimensionDefinitions())
    End Sub 'Init


    'Changed PM_HIGHER_LEVEL_PROCESSING 2008-08-24
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub dimensionsSetup(ByRef anInDimensions As List(Of CEBIdimension))

        'Changed PM_NO_BYVAL 2008-09-29
        '  Old parameter:
        '    ByVal anInDimensions As List(Of CEBIdimension)

        mWorkingList = Me.deepCopy(anInDimensions)
        Dim len As Integer = mWorkingList.Count()

        Dim newDimensions As Boolean = Not mDimensionGUIlist Is Nothing

        If newDimensions Then
            'me.ControlCollection.
            'For Each someGUIline In Me.Controls

            'Note: we don't bother removing old controls. We just make
            '      them invisible. This garbage will be cleaned up when
            '      the dialog is closed. Should we also move them off-screen?
            Dim someGUIline As oneDimensionGUIstructure
            For Each someGUIline In mDimensionGUIlist
                someGUIline.txtName.Visible = False
                someGUIline.txtShortName.Visible = False
                someGUIline.txtDimSize2.Visible = False

                'Changed PM_HIGHER_LEVEL_PROCESSING 2008-09-26
                someGUIline.txtStartNumber.Visible = False
            Next

            'Hide all the text labels for dimensions.
            If True Then
                Dim someControl As Control
                Dim done As Boolean = False
                While Not done
                    Dim removedSomething As Boolean = False
                    For Each someControl In Me.Controls
                        'If someControl.Name.StartsWith(LABELMARKER) Then

                        If someControl.Visible Then
                            Dim tag As String = CStr(someControl.Tag)

                            'Note: depends on shortcircuit boolean. Otherwise
                            '      an exception is thrown.
                            If Not tag Is Nothing AndAlso _
                               tag.StartsWith(LABELMARKER) Then
                                'Make invisible instead of really deleting.
                                'As we are not removing anything we can be done 
                                'with all the labels in one go.
                                'someControl.Location = farOff_DeletedPosition
                                someControl.Visible = False
                            End If
                        End If
                    Next 'Through all controls in this form.
                    If Not removedSomething Then
                        done = True
                    End If
                End While
            End If
        End If 'New dimensions.

        mDimensionGUIlist = New List(Of oneDimensionGUIstructure)(len) 'This will 
        '  remove references to any old controls...

        'We only use these as pixel position templates... 
        txtName.Visible = False
        txtShortName.Visible = False
        txtDimSize.Visible = False
        txtStartNumber.Visible = False
        lblName.Visible = False
        lblShortName.Visible = False
        lblSize.Visible = False
        lblStartNumber.Visible = False

        Dim GUIline As oneDimensionGUIstructure
        GUIline.txtName = Nothing 'Keep compiler happy.
        GUIline.txtShortName = Nothing 'Keep compiler happy.
        GUIline.txtDimSize2 = Nothing 'Keep compiler happy.
        GUIline.txtStartNumber = Nothing 'Keep compiler happy.

        Dim yLevel As Integer = txtName.Location.Y

        'Dim lastIndex As Integer = len - 1
        Dim j As Integer
        For j = 1 To len
            Dim someD As CEBIdimension = mWorkingList(j - 1)

            setupTextBox(GUIline.txtName, txtName, _
              someD.getBaseName(), yLevel)
            setupTextBox(GUIline.txtShortName, txtShortName, _
              someD.getBaseShortName(), yLevel)
            setupTextBox(GUIline.txtDimSize2, txtDimSize, _
              someD.getSize2().ToString, yLevel)

            'Changed PM_HIGHER_LEVEL_PROCESSING 2008-09-26
            setupTextBox(GUIline.txtStartNumber, txtStartNumber, _
              someD.startNumber().ToString, yLevel)

            'Note: some reference types, e.g. strings, may be shared 
            '      between items in the list...
            mDimensionGUIlist.Add(GUIline)

            'We don't need to store these as we are not going to read
            'anything back.
            addTextLabel(lblName, yLevel)
            addTextLabel(lblShortName, yLevel)
            addTextLabel(lblSize, yLevel)

            'Changed PM_HIGHER_LEVEL_PROCESSING 2008-09-26
            addTextLabel(lblStartNumber, yLevel)

            yLevel += 30
        Next j

        changeYlevel_B(btnFewer, yLevel)
        changeYlevel_B(btnMore, yLevel)

        'Button "Fewer" should not be active if there is only one dimension.
        If anInDimensions.Count() <= 1 Then
            btnFewer.Enabled = False 'Note: is enabled again in
            '  the 'More' handler.
        End If
    End Sub 'dimensionsSetup()



    'Changed PM_REFACTOR 2008-12-18
    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Function readOffGUI() _
      As List(Of CEBIdimension)

        Dim newLen As Integer = mDimensionGUIlist.Count

        Dim toReturn As List(Of CEBIdimension) = _
          New List(Of CEBIdimension)(newLen)

        'No validation for now....
        Try
            Dim someItem As oneDimensionGUIstructure
            For Each someItem In mDimensionGUIlist
                Dim baseName As String = someItem.txtName.Text
                Dim baseShortName As String = someItem.txtShortName.Text
                Dim dsize2 As Integer = CInt(someItem.txtDimSize2.Text)

                'Changed PM_HIGHER_LEVEL_PROCESSING 2008-09-26
                Dim startNumber As Integer = _
                  CInt(someItem.txtStartNumber.Text)


                Dim someDimension As CEBIdimension = _
                  New CEBIdimension( _
                    baseName, baseShortName, dsize2, startNumber)
                toReturn.Add(someDimension)
            Next 'Through mDimensionGUIlist

        Catch exceptionObject As Exception
            AppCommon2.displayStandardExceptionInfo( _
              exceptionObject, _
              "Could not read values in dialog. " & _
              "Some numeric fields may hold letters, etc.")
        End Try

        Return toReturn
    End Function 'readOffGUI()


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnOK_Click( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles btnOK.Click

        'Changed PM_REFACTOR 2008-12-18
        mWorkingList = readOffGUI()

        RaiseEvent dimensionsDismissed( _
          aSender, New dimensionsEventArgs(mWorkingList))

        Me.Close()
    End Sub 'btnOK_Click()


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnCancel_Click( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles btnCancel.Click

        Me.Close()
    End Sub 'btnCancel_Click()


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnMore_Click( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles btnMore.Click

        'Changed PM_DIMENSIONDLG_BUG 2008-12-18
        mWorkingList = readOffGUI() 'We need to store any changes the
        '  user has made before building up new GUI elements... Otherwise
        '  the user changes are lost.


        Dim newList As List(Of CEBIdimension) = _
          Me.deepCopy(mWorkingList)

        Dim newLen As Integer = newList.Count() + 1
        Dim defaultContent As String = "Dim " & newLen.ToString() 'For
        '  now: just numbered.

        'Changed PM_HIGHER_LEVEL_PROCESSING 2008-09-26
        Dim startNum As Integer = 1

        Dim newItem2 As CEBIdimension = _
          New CEBIdimension(defaultContent, defaultContent, newLen, startNum)

        newList.Add(newItem2)
        Me.dimensionsSetup(newList)

        btnFewer.Enabled = True 'Unconditinal. There are now at least two...
    End Sub 'btnMore_Click()


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Private Sub btnFewer_Click( _
      ByVal aSender As System.Object, ByVal anEvent As System.EventArgs) _
      Handles btnFewer.Click

        mWorkingList = readOffGUI() 'We need to store any changes the
        '  user has made before building up new GUI elements... Otherwise
        '  the user changes are lost.

        'Make temporary copy so we can use the same function as at startup time.
        Dim newList As List(Of CEBIdimension) = _
          Me.deepCopy(mWorkingList)

        Dim oldLastIndex As Integer = newList.Count() - 1
        newList.RemoveAt(oldLastIndex)
        Me.dimensionsSetup(newList)
    End Sub 'btnFewer_Click()


End Class 'frmDimensions


'Helper class for rawFileMappingDismissed event.
'****************************************************************************
'*    <placeholder for header>                                              *
'****************************************************************************
Public Class dimensionsEventArgs
    Inherits System.EventArgs

    Private mDimensions As List(Of CEBIdimension)


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Sub New( _
      ByVal aSomeValue As List(Of CEBIdimension))

        mDimensions = aSomeValue
    End Sub 'Constructor.


    '****************************************************************************
    '*    <placeholder for header>                                              *
    '****************************************************************************
    Public Function getDimensions() _
      As List(Of CEBIdimension)

        Return mDimensions 'What about deep copy???
    End Function 'getDimensions()


End Class 'dimensionsEventArgs


    

    

Generated by script codePublish.pl at 2009-01-05T15:20:59.