'****************************************************************************
'* Copyright (C) 2004 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: enables clients (that have a ListView instance) to be *
'* indifferent with respect to where a column is visually. *
'* The clients just use a unique identifier for each column. *
'* *
'****************************************************************************
'****************************************************************************
'* 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: listviewColumnMapper.vb *
'* TYPE: VISUAL_BASIC *
'* *
'* CREATED: PM 2005-02-28 Vrs 1.0. *
'* UPDATED: PM 2005-xx-xx *
'* *
'****************************************************************************
Option Strict On
Option Explicit On
'Changed PM_REFACTOR 2005-02-28
Public Class listviewColumnMapper
Private mSomeListView As System.Windows.Forms.ListView
Private mColumnMap As Hashtable
'Changed PM_VISUAL_COLUMNSORT 2006-02-23
Private mReverseColumnMap As Hashtable
Private mColumnIndex As Integer
Private mPixelWidth As Integer
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub New(ByRef anInListView As System.Windows.Forms.ListView)
MyBase.New()
mSomeListView = anInListView
mColumnMap = New Hashtable
mReverseColumnMap = New Hashtable
mColumnIndex = 0
mPixelWidth = 0
End Sub 'New
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Function columnCount() As Integer
Return mColumnMap.Count
End Function 'columnCount
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Function effectivePixelWidth() As Integer
Return mPixelWidth + 14
End Function 'columnCount
'Changed PM_TRIPLEDISPLAY 2003-06-17
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub newColumn( _
ByVal aColumnHeader As String, _
ByVal aWidth As Integer, _
ByVal aIdentifier As Integer, _
ByVal anAlignment As HorizontalAlignment)
'Old parameters:
' ByRef aColumnIndex As Integer
' ByVal aColumnColour As Color)
'Changed PM_COLUMNALIGNMENT 2008-04-16
'Dim aligment As HorizontalAlignment = HorizontalAlignment.Left
Dim aligment As HorizontalAlignment = anAlignment
Dim newItem As System.Windows.Forms.ColumnHeader = _
mSomeListView.Columns.Add( _
aColumnHeader, aWidth, aligment)
Dim existsAlready As Boolean = mColumnMap.ContainsKey(aIdentifier)
If existsAlready Then
Dim peter2 As Integer = 2
End If
Trace.Assert(existsAlready = False, _
"PIL ASSERT. Could not add key to mColumnMap. " & _
"Probably re-init of listview columns - this is currently not allowed. " & _
"Or this function is called twice (by mistake) with the same key. " & _
"Move the initialisation from Init() to New() or " & _
"check for uniqueness of keys.")
mColumnMap.Add(aIdentifier, mColumnIndex)
'Changed PM_VISUAL_COLUMNSORT 2006-02-23
mReverseColumnMap.Add(mColumnIndex, aIdentifier)
mColumnIndex += 1
mPixelWidth += aWidth
mPixelWidth += 1
End Sub 'newColumn
'Changed PM_TRIPLEDISPLAY 2003-06-17
'****************************************************************************
'* Translates from our identifier for a column to the index in *
'* the (visual) structure, a column in the list. *
'****************************************************************************
Public Function item2ColumnIndex( _
ByVal anColumnIdentifier As Integer) As Integer
'old parameter type: quantPeptTbItmColEnum2
Dim toReturn As Integer = -1
If mColumnMap.ContainsKey(anColumnIdentifier) Then
toReturn = CInt(mColumnMap.Item(anColumnIdentifier))
End If
Return toReturn
End Function 'item2ColumnIndex
'****************************************************************************
'* Translates from an index in *
'* the (visual) structure to our identifier for a column *
'****************************************************************************
Public Function columnIndex2itemID( _
ByVal anColumnIndex As Integer) As Integer
Dim toReturn As Integer = -1
If mReverseColumnMap.ContainsKey(anColumnIndex) Then
toReturn = CInt(mReverseColumnMap.Item(anColumnIndex))
End If
Return toReturn
End Function 'item2ColumnIndex
'Changed PM_TRIPLEDISPLAY 2003-06-18
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Function readOffListItem( _
ByRef aRowToRead As ListViewItem, _
ByVal anColumnIdentifier As Integer) _
As String
Dim toReturn As String = Nothing
Dim realIndex As Integer = Me.item2ColumnIndex(anColumnIdentifier)
If realIndex <> -1 Then
toReturn = aRowToRead.SubItems(realIndex).Text
Else
toReturn = "117" 'It is difficult to find a neutral value
' if the client depend on the value...
End If
Return toReturn
End Function 'readOffListItem
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub itemBackColour( _
ByRef aRowToUpdate As ListViewItem, _
ByVal anColumnIdentifier As Integer, ByVal aValue As Color)
Dim realIndex As Integer = Me.item2ColumnIndex(anColumnIdentifier)
aRowToUpdate.SubItems(realIndex).BackColor = aValue
End Sub 'itemBackColour
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub listItemForeColour( _
ByRef aRowToUpdate As ListViewItem, _
ByVal anColumnIdentifier As Integer, _
ByVal aValue As Color)
Dim realIndex As Integer = Me.item2ColumnIndex(anColumnIdentifier)
If realIndex <> -1 Then 'If e.g. the triple encoding columns do not
' exist then we can't set the colour...
aRowToUpdate.SubItems(realIndex).ForeColor = aValue
End If
End Sub 'listItemForeColour
'Changed PM_TRIPLEDISPLAY 2003-06-17
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub updateListItem( _
ByRef aRowToUpdate As ListViewItem, _
ByVal anColumnIdentifier As Integer, _
ByVal aValue As String)
Dim realIndex As Integer = Me.item2ColumnIndex(anColumnIdentifier)
If realIndex <> -1 Then 'We ignore the request for a
' change if the column does not exist, e.g. the
' columns for triple encoding has not been added
' because the quantitation mode is not triple
' encoding.
aRowToUpdate.SubItems(realIndex).Text = aValue
End If
End Sub 'updateListItem
End Class 'listviewColumnMapper
Generated by script codePublish.pl at 2008-09-23T11:59:18.