<!-- Copyright © Northwoods Software Corporation, 2008-2026. All Rights Reserved. -->

<UserControl x:Class="Navigator.Navigator"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:go="http://schemas.nwoods.com/GoXam"
    xmlns:local="clr-namespace:Navigator">

  <UserControl.Resources>
    <!-- These custom converters will be bound to a part data's Highlight property. -->
    <local:ThicknessConverter x:Key="theThicknessConverter" />
    <local:PartTextConverter x:Key="thePartDataTextConverter" />
    
    <local:ColorList x:Key="theColorList">
      <local:ColorInfo Index="0" Brush="Black" Description="Not related" />
      <local:ColorInfo Index="1" Brush="Blue" Description="Directly related" />
      <local:ColorInfo Index="2" Brush="Green" Description="2 relationships apart" />
      <local:ColorInfo Index="3" Brush="Orange" Description="3 relationships apart" />
      <local:ColorInfo Index="4" Brush="Red" Description="4 relationships apart" />
      <local:ColorInfo Index="5" Brush="Purple" Description="Very indirectly related" />
    </local:ColorList>
    <!-- This converter chooses the appropriate brush from the ColorList above,
         given a Highlight value from zero to 5 or more -->
    <local:ColorConverter x:Key="theColorConverter" Objects="{StaticResource theColorList}" />

    <!-- The node DataTemplate; for each node data,
         a Node with the following elements will be generated. -->
    <DataTemplate x:Key="NodeTemplate">
      <!-- "Data" corresponds to the NavModelNodeData that forms the data for a given Node.
           In "Data.*" the * is the property of the NavModelNodeData type
           that you wish the Node's attribute to be bound to. -->
      <go:NodePanel go:Node.Location="{Binding Path=Data.InitPosition, Mode=OneTime}"
                    go:Part.SelectionAdorned="True"
                    Width="30" Height="30">
        <ToolTipService.ToolTip>
          <TextBlock Text="{Binding Path=Node,
                            Converter={StaticResource thePartDataTextConverter}}" />
        </ToolTipService.ToolTip>
        <go:NodeShape go:NodePanel.Figure="Rectangle" Fill="White"
                      Stroke="{Binding Path=Data.Highlight,
                               Converter={StaticResource theColorConverter}}" 
                      StrokeThickness="{Binding Path=Data.Highlight,
                                        Converter={StaticResource theThicknessConverter}}" />
        <TextBlock Text="{Binding Path=Data.Key}"
                   TextAlignment="Center"
                   HorizontalAlignment="Center" VerticalAlignment="Center" 
                   Foreground="{Binding Path=Data.Highlight,
                                Converter={StaticResource theColorConverter}}" />
      </go:NodePanel>
    </DataTemplate>

    <DataTemplate x:Key="GroupTemplate">
      <Border x:Name="myBorder" Background="#1FFF0000"
              BorderBrush="{Binding Path=Data.Highlight,
                            Converter={StaticResource theColorConverter}}" 
              BorderThickness="{Binding Path=Data.Highlight,
                                Converter={StaticResource theThicknessConverter}}"
              go:Node.Location="{Binding Path=Data.InitPosition, Mode=OneTime}"
              go:Node.LocationElementName="myGroupPanel"
              go:Part.SelectionAdorned="True"
              go:Node.ToSpot="TopSide">
        <ToolTipService.ToolTip>
          <TextBlock Text="{Binding Path=Group,
                            Converter={StaticResource thePartDataTextConverter}}" />
        </ToolTipService.ToolTip>
        <StackPanel>
          <TextBlock Name="TextBlock" Text="{Binding Path=Data.Key}"
                     FontSize="12" FontWeight="Bold" Margin="5 0 5 0"
                     Foreground="{Binding Path=Data.Highlight,
                                  Converter={StaticResource theColorConverter}}" />
          <go:GroupPanel x:Name="myGroupPanel" Padding="5" />
        </StackPanel>
      </Border>
    </DataTemplate>

    <DataTemplate x:Key="LinkTemplate">
      <go:LinkPanel go:Link.SelectionElementName="Path" go:Link.SelectionAdorned="True">
        <go:Link.Route>
          <go:Route Curve="Bezier" />
        </go:Link.Route>
        <ToolTipService.ToolTip>
          <TextBlock Text="{Binding Path=Link,
                            Converter={StaticResource thePartDataTextConverter}}" />
        </ToolTipService.ToolTip>
        <go:LinkShape x:Name="Path"
                      Stroke="{Binding Path=Data.Highlight,
                               Converter={StaticResource theColorConverter}}"
                      StrokeThickness="{Binding Path=Data.Highlight,
                                        Converter={StaticResource theThicknessConverter}}" />
        <Path Fill="{Binding Path=Data.Highlight, Converter={StaticResource theColorConverter}}"
              go:LinkPanel.ToArrow="Standard" />
      </go:LinkPanel>
    </DataTemplate>
  </UserControl.Resources>

  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>
    <go:Diagram Grid.Column="0" x:Name="myDiagram"
                Padding="10"
                HorizontalContentAlignment="Center"
                VerticalContentAlignment="Center"  
                NodeTemplate="{StaticResource NodeTemplate}"
                GroupTemplate="{StaticResource GroupTemplate}"
                LinkTemplate="{StaticResource LinkTemplate}" 
                MouseLeftButtonUp="Update"
                MaximumSelectionCount="1" />
    <ScrollViewer Grid.Column="1">
      <StackPanel>
        <!-- RadioButtons for choosing what parts to highlight relative to the selected part -->
        <Border BorderBrush="Black" BorderThickness="1" Background="WhiteSmoke"
                CornerRadius="5" Padding="3" Margin="5">
          <StackPanel>
            <TextBlock Text="Related Parts Highlighted" HorizontalAlignment="Center"
                       FontWeight="Bold" TextWrapping="Wrap"
                       FontSize="11" TextAlignment="Center" />
            <RadioButton Name="DeselectButton" Content="Unhighlight All"
                         HorizontalAlignment="Left" Checked="Update" IsChecked="True" />
            <RadioButton Name="LinksIntoButton" Content="Links Into"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="LinksOutOfButton" Content="Links Out Of"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="LinksConnectedButton" Content="Links Connected"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="NodesIntoButton" Content="Nodes Into"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="NodesOutOfButton" Content="Nodes Out Of"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="NodesReachableButton" Content="Nodes Reachable"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="NodesConnectedButton" Content="Nodes Connected"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="ContainingGroupParentButton" Content="Containing Group (Parent)"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="ContainingGroupAllButton" Content="Containing Groups (All)"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="MemberNodesChildrenButton" Content="Member Nodes (Children)"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="MemberNodesAllButton" Content="Member Nodes (All)"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="MemberLinksChildrenButton" Content="Member Links (Children)"
                         HorizontalAlignment="Left" Checked="Update" />
            <RadioButton Name="MemberLinksAllButton" Content="Member Links (All)"
                         HorizontalAlignment="Left" Checked="Update" />
          </StackPanel>
        </Border>

        <!-- the key associating colors with relationship distances -->
        <Border BorderBrush="Black" BorderThickness="1" Background="WhiteSmoke"
                CornerRadius="5" Padding="3" Margin="5">
          <StackPanel>
            <TextBlock Text="Relationship Colors" FontWeight="Bold" HorizontalAlignment="Center" />
            <ListBox Background="WhiteSmoke" BorderBrush="Transparent" BorderThickness="0"
                     ItemsSource="{StaticResource theColorList}" IsHitTestVisible="False">
              <ListBox.ItemTemplate>
                <DataTemplate>
                  <StackPanel Orientation="Horizontal">
                    <Rectangle Fill="{Binding Path=Brush}" Width="20" Height="20" Margin="3" />
                    <TextBlock Text="{Binding Path=Description}" VerticalAlignment="Center" />
                  </StackPanel>
                </DataTemplate>
              </ListBox.ItemTemplate>
            </ListBox>
          </StackPanel>
        </Border>
      </StackPanel>
    </ScrollViewer>
  </Grid>
</UserControl>