Changeset 706


Ignore:
Timestamp:
Oct 10, 2009, 4:32:02 PM (12 years ago)
Author:
Arno Wacker
Message:

Cosmetic changes to frequency test Presentation

  • Replaced the StackPanel with Grid to gain more control over placing elements
  • Added ChartHeight-settings, in case Autozoom is not used
  • Headline is now dynamically adapted depending on gram-length used.
  • In autozoom mode the chart now also adapts if the number of character changes during play (see e.g. the enigma-analyzer samples)
  • Added a slider to the settings for scaling - currently duplicates the slider in the presentation; maybe the in-presentations slider can be removed later (open: when moving the in-presentation-slider, the settings-slider does not move yet - not implemented)
  • Resize bug still open, no solution found yet, see #97
  • Updated the sample to avoid loading-warnings
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/FrequencyTest/FrequencyTest.cs

    r700 r706  
    3232        private IDictionary<string, double[]> grams = new SortedDictionary<string, double[]>();
    3333        private DataSource data = new DataSource();
    34         private double presentationScaler = 1.0;
    35         private double presentationOffset = 55.0;
     34        private double presentationScaler = 1.0; // the slider-value
     35        private double presentationOffset = 60.0; // top-offest in presentation, must skip height of headline-text
    3636
    3737        // TODO: this shall be an algorithm setting or an optional word
     
    124124
    125125            presentation.SizeChanged += new System.Windows.SizeChangedEventHandler(presentation_SizeChanged);
    126         }
    127 
     126
     127            settings.PropertyChanged += new PropertyChangedEventHandler(settings_PropertyChanged);
     128        }
     129
     130       
     131
     132       
    128133        public UserControl Presentation { get; private set; }
    129134
     
    237242
    238243                data.ValueCollection.Clear();
     244                double chartheight = (double) settings.ChartHeight;
     245                if (settings.Autozoom)
     246                {
     247                    chartheight = presentation.ActualHeight - presentation.sli.ActualHeight - (presentation.chartHeadline.ActualHeight + presentationOffset) * presentationScaler;
     248                    presentationScaler = presentation.ActualWidth / (presentation.chart.ActualWidth);
     249                    presentation.SetScaler(presentationScaler);
     250                }
    239251
    240252                // calculate presentation bars height
    241253                foreach (KeyValuePair<string, double[]> item in grams)
    242254                {
    243 
    244                     int height = (int)(item.Value[PERCENTAGED] * ((presentation.ActualHeight - presentation.sli.ActualHeight - (presentationOffset * presentationScaler)) / (max * presentationScaler)));
     255                    int height = (int)(item.Value[PERCENTAGED] * (chartheight / (max * presentationScaler)));
     256                    //int height = (int)(item.Value[PERCENTAGED] * ((presentation.ActualHeight - presentation.sli.ActualHeight - (presentationOffset * presentationScaler)) / (max * presentationScaler)));
     257
    245258                    CollectionElement row = new CollectionElement(height, Math.Round(item.Value[PERCENTAGED] * 100, 2), item.Key);
    246259                    data.ValueCollection.Add(row);
    247260                }
     261
     262                switch (settings.GrammLength)
     263                {
     264                    case 1:
     265                        presentation.SetHeadline("Character (unigram) frequency (in %)");
     266                        break;
     267                    case 2:
     268                        presentation.SetHeadline("Bigram frequency (in %)");
     269                        break;
     270                    case 3:
     271                        presentation.SetHeadline("Trigram frequency (in %)");
     272                        break;
     273                    default:
     274                        presentation.SetHeadline(settings.GrammLength + "-gram frequency (in %)");
     275                        break;
     276                }
     277               
    248278
    249279                presentation.ShowData(data);
     
    256286            //if (e.HeightChanged)
    257287            //{
    258             //    GuiLogMessage("Height changed from "+e.PreviousSize.Height +" to " + e.NewSize.Height, NotificationLevel.Info);               
     288            //    GuiLogMessage("Height changed from " + e.PreviousSize.Height + " to " + e.NewSize.Height, NotificationLevel.Info);
    259289            //}
    260290
     
    263293            //    GuiLogMessage("Width changed from " + e.PreviousSize.Width + " to " + e.NewSize.Width, NotificationLevel.Info);
    264294            //}
    265             //GuiLogMessage("Chart size: H=" + presentation.chart.ActualHeight + ", W=" + presentation.chart.ActualWidth, NotificationLevel.Info);
    266 
    267             if (settings.Autozoom)
    268             {
    269                 presentationScaler = e.NewSize.Width / presentation.chart.ActualWidth;
    270                 presentation.sli.Value = presentationScaler;
    271             }
     295            //GuiLogMessage("Chart size: AH=" + presentation.chart.ActualHeight + ", AW=" + presentation.chart.ActualWidth + "; H-slider=" + (presentation.ActualHeight - presentation.sli.ActualHeight), NotificationLevel.Info);
    272296
    273297            updatePresentation();
     298        }
     299
     300        private void settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
     301        {
     302            switch (e.PropertyName)
     303            {
     304                case "Autozoom":
     305                case "ChartHeight":
     306                    updatePresentation();
     307                    break;
     308
     309                case "Scale":
     310                    presentation.SetScaler( (double)settings.Scale / 1000.0);
     311                    break;
     312            }
    274313        }
    275314
  • trunk/CrypPlugins/FrequencyTest/FrequencyTestPresentation.xaml

    r700 r706  
    6161   
    6262   
    63     <StackPanel VerticalAlignment="Bottom" Orientation="Vertical"  Width="Auto">
    64             <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto"  ScrollViewer.HorizontalScrollBarVisibility="Auto" x:Name="sw">
     63    <Grid VerticalAlignment="Stretch">
     64        <Grid.RowDefinitions>
     65            <RowDefinition />
     66            <RowDefinition Height="Auto" />
     67        </Grid.RowDefinitions>
    6568       
    66             <Grid VerticalAlignment="Bottom" >
    67             <Grid.LayoutTransform>
    68                 <ScaleTransform   ScaleX="{Binding ElementName=sli,Path=Value}" ScaleY="{Binding
    69                          ElementName=sli, Path=Value}"/>
    70             </Grid.LayoutTransform>
     69        <ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto"  ScrollViewer.HorizontalScrollBarVisibility="Auto">
     70            <Grid x:Name="chart" Grid.Row="0" VerticalAlignment="Stretch" >
     71                <Grid.RowDefinitions>
     72                    <RowDefinition Height="Auto" />
     73                    <RowDefinition Height="1*" />
     74                </Grid.RowDefinitions>
     75               
     76                <Grid.LayoutTransform>
     77                    <ScaleTransform   ScaleX="{Binding ElementName=sli,Path=Value}" ScaleY="{Binding ElementName=sli, Path=Value}"/>
     78                </Grid.LayoutTransform>
     79             
     80               <TextBlock x:Name="chartHeadline" TextAlignment="Center" Grid.Row="0" FontSize="20" Foreground="DarkBlue"  FontFamily="Academy" OpacityMask="Turquoise" Text="No data available yet!" ></TextBlock>
    7181
    72             <StackPanel VerticalAlignment="Bottom" x:Name="chart">
    73                
    74                <TextBlock TextAlignment="Center" FontSize="20" Foreground="DarkBlue"  FontFamily="Academy" OpacityMask="Turquoise" Text="Character Frequencies (in %)" ></TextBlock>
     82               <ItemsControl Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"           
     83                 ItemsSource="{Binding Source={StaticResource source},Path=ValueCollection}"
     84                 ItemTemplate="{StaticResource template}" ItemsPanel="{StaticResource panelTemplate}" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
     85               </ItemsControl>
    7586
    76                <ItemsControl HorizontalAlignment="Center" VerticalAlignment="Bottom"           
    77                  ItemsSource="{Binding Source={StaticResource source},Path=ValueCollection}"
    78                  ItemTemplate="{StaticResource template}" ItemsPanel="{StaticResource panelTemplate}">
    79                </ItemsControl>
    80              
    81             </StackPanel>
    82            
    83           </Grid>
    84 
     87            </Grid>
    8588        </ScrollViewer>
    86         <Slider x:Name="sli" Width="100" HorizontalAlignment="Center" Minimum="0.2" VerticalAlignment="Bottom"
    87                 Maximum="2" Value="1"/>
    88     </StackPanel>
     89       
     90        <Slider x:Name="sli" Grid.Row="1" Width="100" HorizontalAlignment="Center" Minimum="0.05" VerticalAlignment="Bottom" Maximum="2" Value="1"/>
     91       
     92    </Grid>
    8993   
    9094   
  • trunk/CrypPlugins/FrequencyTest/FrequencyTestPresentation.xaml.cs

    r700 r706  
    4343            }, null);
    4444        }
     45
     46
     47        public void SetHeadline(string text)
     48        {
     49            Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     50            {
     51                chartHeadline.Text = text;
     52            }, null);
     53        }
     54
     55        public void SetScaler(double value)
     56        {
     57            Dispatcher.Invoke(DispatcherPriority.Normal, (SendOrPostCallback)delegate
     58            {
     59                sli.Value = value;
     60            }, null);
     61        }
     62
    4563    }
    4664}
  • trunk/CrypPlugins/FrequencyTest/FrequencyTestSettings.cs

    r700 r706  
    55using Cryptool.PluginBase;
    66using System.ComponentModel;
     7using System.Windows;
    78
    89namespace Cryptool.FrequencyTest
     
    2021
    2122        #endregion
     23
     24        #region INotifyPropertyChanged Members
     25
     26        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
     27
     28        protected void OnPropertyChanged(string name)
     29        {
     30            if (PropertyChanged != null)
     31            {
     32                PropertyChanged(this, new PropertyChangedEventArgs(name));
     33            }
     34        }
     35
     36        #endregion
     37
     38
     39
     40        #region Private variables
    2241
    2342        private int unknownSymbolHandling = 0;
     
    2746        private int boundaryFragments = 0;
    2847        private bool autozoom = true;
     48        private int chartHeight = 160;
     49        private int scale = 1000; // = 1 , factor of 1000
     50
     51        #endregion
     52
     53        #region Private helper methods
     54
     55        private void showSettingsElement(string element)
     56        {
     57            if (TaskPaneAttributeChanged != null)
     58            {
     59                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer(element, Visibility.Visible)));
     60            }
     61        }
     62
     63        private void hideSettingsElement(string element)
     64        {
     65            if (TaskPaneAttributeChanged != null)
     66            {
     67                TaskPaneAttributeChanged(this, new TaskPaneAttributeChangedEventArgs(new TaskPaneAttribteContainer(element, Visibility.Collapsed)));
     68            }
     69        }
     70
     71        #endregion
     72
     73        #region Public events and methods
     74
     75        /// <summary>
     76        /// This event is needed in order to render settings elements visible/invisible
     77        /// </summary>
     78        public event TaskPaneAttributeChangedHandler TaskPaneAttributeChanged;
     79
     80        #endregion
     81
     82        #region Visible settings
    2983       
    3084        /// <summary>
     
    50104
    51105        [PropertySaveOrder(2)]
    52         [TaskPane("Enter the gramLength of the gramms to be investigated.", "Groups of how many characters should be checked?", "", 1, false, DisplayLevel.Expert, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, 100)]
     106        [TaskPane("Enter the length of the gramms to be investigated.", "Groups of how many characters should be checked?", "", 1, false, DisplayLevel.Expert, ControlType.NumericUpDown, ValidationType.RangeInteger, 0, 100)]
    53107        public int GrammLength
    54108        {
     
    65119
    66120        [PropertySaveOrder(3)]
    67         [ContextMenu("Handling of unknown characters", "What should be done with encountered characters at the word which are not in the alphabet?", 4, DisplayLevel.Expert, ContextMenuControlType.ComboBox, null, new string[] { "Don't count", "Count" })]
    68         [TaskPane("Handling of unknown characters", "What should be done with encountered characters at the word which are not in the alphabet?", null, 4, false, DisplayLevel.Expert, ControlType.ComboBox, new string[] { "Don't count", "Count" })]
     121        [ContextMenu("Handling of unknown characters", "What should be done with encountered characters in the word which are not in the alphabet?", 4, DisplayLevel.Expert, ContextMenuControlType.ComboBox, null, new string[] { "Don't count", "Count" })]
     122        [TaskPane("Handling of unknown characters", "What should be done with encountered characters in the word which are not in the alphabet?", null, 4, false, DisplayLevel.Expert, ControlType.ComboBox, new string[] { "Don't count", "Count" })]
    69123        public int ProcessUnknownSymbols
    70124        {
     
    97151        /// </summary>
    98152        [PropertySaveOrder(4)]
    99         [TaskPane("Word boundary fragments", "Include additional fragments with whitespaces at word boundary? Only relevant for gramLength >= 2.", "", 10, false, DisplayLevel.Expert, ControlType.ComboBox, new string[] { "No fragments at boundary", "Include fragments" })]
     153        [TaskPane("Word boundary fragments", "Include additional fragments with whitespaces at word boundary? Only relevant for gramlength >= 2.", "", 10, false, DisplayLevel.Expert, ControlType.ComboBox, new string[] { "No fragments at boundary", "Include fragments" })]
    100154        public int BoundaryFragments
    101155        {
     
    114168
    115169        [PropertySaveOrder(5)]
    116         [TaskPane("Autozoom", "Should the chart perfrom autozoom?", "Presentation", 20, true, DisplayLevel.Beginner, ControlType.CheckBox)]
     170        [TaskPane("Autozoom", "Should the chart perform autozoom?", "Presentation", 20, true, DisplayLevel.Beginner, ControlType.CheckBox)]
    117171        public bool Autozoom
    118172        {
     
    126180                }
    127181
     182                if (autozoom)
     183                    hideSettingsElement("ChartHeight");
     184                else
     185                    showSettingsElement("ChartHeight");
     186               
     187
    128188                OnPropertyChanged("Autozoom");
    129189            }
     
    131191
    132192
    133         #region INotifyPropertyChanged Members
    134 
    135         public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
    136 
    137         protected void OnPropertyChanged(string name)
    138         {
    139             if (PropertyChanged != null)
    140             {
    141                 PropertyChanged(this, new PropertyChangedEventArgs(name));
    142             }
    143         }
    144 
    145         #endregion
     193        [PropertySaveOrder(6)]
     194        [TaskPane("Chart height", "This is the chart height, if autozoom is disabled", "Presentation", 21, true, DisplayLevel.Beginner, ControlType.NumericUpDown, ValidationType.RangeInteger, 10, 1000)]
     195        public int ChartHeight
     196        {
     197            get { return this.chartHeight; }
     198            set
     199            {
     200                if (value != chartHeight)
     201                {
     202                    HasChanges = true;
     203                    chartHeight = value;
     204                }
     205
     206                OnPropertyChanged("ChartHeight");
     207            }
     208        }
     209
     210
     211        [PropertySaveOrder(7)]
     212        [TaskPane("Scale", "Scale the chart", "Presentation", 22, true, DisplayLevel.Beginner, ControlType.Slider, 5, 2000)]
     213        public int Scale
     214        {
     215            get { return scale; }
     216            set
     217            {
     218                scale = value;
     219                HasChanges = true;
     220                OnPropertyChanged("Scale");
     221            }
     222        }
     223
     224        #endregion
     225       
    146226    }
    147227}
Note: See TracChangeset for help on using the changeset viewer.