|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions are met: |
|
7 * |
|
8 * - Redistributions of source code must retain the above copyright notice, |
|
9 * this list of conditions and the following disclaimer. |
|
10 * - Redistributions in binary form must reproduce the above copyright notice, |
|
11 * this list of conditions and the following disclaimer in the documentation |
|
12 * and/or other materials provided with the distribution. |
|
13 * - Neither the name of Nokia Corporation nor the names of its contributors |
|
14 * may be used to endorse or promote products derived from this software |
|
15 * without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 * POSSIBILITY OF SUCH DAMAGE. |
|
28 * |
|
29 * Initial Contributors: |
|
30 * Nokia Corporation - initial contribution. |
|
31 * |
|
32 * Contributors: |
|
33 * |
|
34 * Description: |
|
35 * |
|
36 */ |
|
37 |
|
38 using System; |
|
39 using System.Drawing; |
|
40 using System.Collections; |
|
41 using System.Collections.Generic; |
|
42 using HeapCtrlLib.Interfaces; |
|
43 using HeapCtrlLib.Popups.Managers; |
|
44 using HeapCtrlLib.Renderers.Headers; |
|
45 using HeapCtrlLib.Renderers.SelectionBorders; |
|
46 using HeapCtrlLib.Renderers.Contents; |
|
47 using HeapCtrlLib.Renderers.ContentBorders; |
|
48 using HeapCtrlLib.Utilities; |
|
49 using HeapLib.Reconstructor; |
|
50 using HeapLib.Statistics.Tracking.Base; |
|
51 using SymbianUtils.Colour; |
|
52 |
|
53 namespace HeapCtrlLib.Factories |
|
54 { |
|
55 internal class FactoryByObject : Factory |
|
56 { |
|
57 #region Constructors & destructor |
|
58 public FactoryByObject() |
|
59 { |
|
60 base.Renderers.Header = new HeapCellRendererRowHeader(); |
|
61 base.Renderers.SelectionBorder = new HeapCellRendererSelectionBorder(); |
|
62 base.Renderers.Content = new HeapCellRendererColourByObject(); |
|
63 base.Renderers.ContentBorder = new HeapCellRendererContentBorder3d(); |
|
64 // |
|
65 PopupManager = new PopupManagerByAge(); |
|
66 } |
|
67 #endregion |
|
68 |
|
69 #region API |
|
70 internal void PrepareColourHashes( HeapReconstructor aReconstructor, List<KnownColor> aStandardColours ) |
|
71 { |
|
72 if ( iColourHashes.Count == 0 ) |
|
73 { |
|
74 // Pick colours at random from the standard colours until we have used them all |
|
75 System.Random random = new Random( 0 ); |
|
76 |
|
77 // How many objects do we have to colourise? |
|
78 int count = aReconstructor.Statistics.StatsAllocated.TrackerObjects.Count; |
|
79 for ( int i = 0; i < count; i++ ) |
|
80 { |
|
81 // Get associated symbol item |
|
82 TrackingInfo item = aReconstructor.Statistics.StatsAllocated.TrackerObjects[ i ]; |
|
83 |
|
84 // Get object name |
|
85 string caption = item.Symbol.ObjectWithoutSection; |
|
86 |
|
87 // If we still have some system colours left, then we'll |
|
88 // try to use them up. Otherwise, we'll resort to generating |
|
89 // random colors. |
|
90 Color col = Color.Black; |
|
91 // |
|
92 if ( aStandardColours.Count > 0 ) |
|
93 { |
|
94 // Get system colour index |
|
95 int colIndex = random.Next( 0, aStandardColours.Count - 1 ); |
|
96 |
|
97 // Link colour with symbol |
|
98 KnownColor knownCol = (KnownColor) aStandardColours[ colIndex ]; |
|
99 col = Color.FromKnownColor( knownCol ); |
|
100 |
|
101 // Remove known colour so we don't use it again |
|
102 aStandardColours.RemoveAt( colIndex ); |
|
103 } |
|
104 else |
|
105 { |
|
106 // Get random known colour |
|
107 col = iColorUtil.GenerateRandomColour( random ); |
|
108 } |
|
109 |
|
110 // Associate object with colour |
|
111 iColourHashes.Add( item.Symbol.ObjectWithoutSection, caption, col, item ); |
|
112 } |
|
113 } |
|
114 } |
|
115 #endregion |
|
116 |
|
117 #region Properties |
|
118 internal HeapCellFilterTripletDictionary ColourHashes |
|
119 { |
|
120 get { return iColourHashes; } |
|
121 set { iColourHashes = value; } |
|
122 } |
|
123 #endregion |
|
124 |
|
125 #region Data members |
|
126 private HeapCellFilterTripletDictionary iColourHashes = new HeapCellFilterTripletDictionary(); |
|
127 private ColourGenerationUtil iColorUtil = new ColourGenerationUtil(); |
|
128 #endregion |
|
129 } |
|
130 } |