'****************************************************************************
'* 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
Imports System.Collections.Generic 'For Dictionary and List.
'Changed PM_COLUMNSORT_BY_KEYBOARD 2008-11-06
Public Structure listViewColumnInfoStruct
Dim columnHeader As String
Dim width As Integer
Dim identifier As Integer
Dim alignment As HorizontalAlignment
End Structure 'listViewColumnInfoStruct
'Changed PM_REFACTOR 2005-02-28
Public Class listviewColumnMapper
Private mSomeListView As System.Windows.Forms.ListView
'Changed PM_TYPESAFE_HASH 2008-11-06
'Private mColumnMap As Hashtable
''Changed PM_VISUAL_COLUMNSORT 2006-02-23
'Private mReverseColumnMap As Hashtable
Private mColumnMap2 As Dictionary(Of Integer, Integer)
' Key is XYZ. Value is ABC.
Private mReverseColumnMap2 As Dictionary(Of Integer, Integer)
' Key is XYZ. Value is ABC.
'Changed PM_COLUMNSORT_BY_KEYBOARD 2008-11-06
Private mListViewColumnInfo As _
Dictionary(Of Integer, listViewColumnInfoStruct)
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
mColumnMap2 = New Dictionary(Of Integer, Integer)
mReverseColumnMap2 = New Dictionary(Of Integer, Integer)
mColumnIndex = 0
mPixelWidth = 0
'Changed PM_COLUMNSORT_BY_KEYBOARD 2008-11-06
mListViewColumnInfo = _
New Dictionary(Of Integer, listViewColumnInfoStruct)
End Sub 'Constructor
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Function columnCount() _
As Integer
Return mColumnMap2.Count
End Function 'columnCount()
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Function effectivePixelWidth() _
As Integer
Return mPixelWidth + 14
End Function 'columnCount()
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Sub newColumn( _
ByVal aColumnHeader As String, _
ByVal aWidth As Integer, _
ByVal aIdentifier As Integer, _
ByVal anAlignment As HorizontalAlignment, _
ByVal aHideIt As Boolean)
'Old parameters:
' ByRef aColumnIndex As Integer
' ByVal aColumnColour As Color)
If True Then 'Block. Run-time error detection (for client error).
Dim existsAlready As Boolean = mColumnMap2.ContainsKey(aIdentifier)
'For breakpoints.
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.")
End If
'Save for use later. E.g. clients asking for information (e.g. to
'create menu items for keyboard-only sorting of columns)
Dim someInfo As listViewColumnInfoStruct
someInfo.alignment = anAlignment
someInfo.columnHeader = aColumnHeader
someInfo.identifier = aIdentifier
someInfo.width = aWidth
mListViewColumnInfo(aIdentifier) = someInfo
'Changed PM_COLUMNALIGNMENT 2008-04-16
'Dim aligment As HorizontalAlignment = HorizontalAlignment.Left
Dim aligment As HorizontalAlignment = anAlignment
If Not aHideIt Then
Dim newItem2 As System.Windows.Forms.ColumnHeader = _
mSomeListView.Columns.Add( _
aColumnHeader, aWidth, aligment)
mColumnMap2.Add(aIdentifier, mColumnIndex)
'Changed PM_VISUAL_COLUMNSORT 2006-02-23
mReverseColumnMap2.Add(mColumnIndex, aIdentifier)
mColumnIndex += 1
mPixelWidth += aWidth
mPixelWidth += 1
Else
'Changed PM_SORT_BY_SELECTION_AND_CHECKED 2008-12-09
'No actual add to the GUI. This is for special cases, e.g. sorted
'by selected or by checked.
Dim peter2 As Integer = 2
End If
End Sub 'newColumn()
'Changed PM_COLUMNSORT_BY_KEYBOARD 2008-11-06
'****************************************************************************
'* <placeholder for header> *
'****************************************************************************
Public Function getColumnInfo( _
ByVal anID As Integer, ByRef anOutExists As Boolean) _
As listViewColumnInfoStruct
'Changed PM_LEFTOUT_GUICOLUMNS_BUG 2008-12-05.
'Return mListViewColumnInfo(anID)
anOutExists = False
Dim toReturn As listViewColumnInfoStruct
toReturn.columnHeader = Nothing 'Keep compiler happy.
If mListViewColumnInfo.TryGetValue(anID, toReturn) Then
anOutExists = True
Else
'Defined, but left out of the actual GUI. In that case the
'client should not e.g. list it as a menu item to sort by...
Dim peter2 As Integer = 2
End If
Return toReturn
End Function 'getColumnInfo()
'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 mColumnMap2.ContainsKey(anColumnIdentifier) Then
'Changed PM_TYPESAFE_HASH 2008-11-06
'toReturn = CInt(mColumnMap.Item(anColumnIdentifier))
toReturn = mColumnMap2(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 mReverseColumnMap2.ContainsKey(anColumnIndex) Then
'Changed PM_TYPESAFE_HASH 2008-11-06
'toReturn = CInt(mReverseColumnMap.Item(anColumnIndex))
toReturn = mReverseColumnMap2(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 2009-01-05T15:20:59.