void IView.SetViewModel(IViewModel viewModel)
        {
            this.viewModel = viewModel;

            this.resources = new Resources(viewModel, Font.Name, Font.Size, UIUtils.Dpi.ScaleUp(1, 120))
            {
                FocusedMsgSlaveVert = new LJD.Image(SequenceDiagramVisualizerControlResources.FocusedMsgSlaveVert),
                FocusedMessageImage = new LJD.Image(SequenceDiagramVisualizerControlResources.FocusedMsgSlave),
                BookmarkImage       = new LJD.Image(SequenceDiagramVisualizerControlResources.SmallBookmark),
                UserActionImage     = new LJD.Image(SequenceDiagramVisualizerControlResources.UserAction)
            };

            InitializeArrowEndShapePoints();


            this.drawingUtils = new DrawingUtils(viewModel, resources);
            this.ParentForm.VisibleChanged += (s, e) =>
            {
                if (this.ParentForm.Visible)
                {
                    viewModel.OnWindowShown();
                }
                else
                {
                    viewModel.OnWindowHidden();
                }
            };

            var notificationsIconUpdater = Updaters.Create(() => viewModel.IsNotificationsIconVisibile,
                                                           value => notificationsButton.Visible = value);

            var updateCurrentArrowControls = Updaters.Create(() => viewModel.CurrentArrowInfo,
                                                             value =>
            {
                currentArrowCaptionLabel.Text = value.Caption;
                currentArrowDescription.Text  = value.DescriptionText;
                currentArrowDescription.Links.Clear();
                foreach (var l in value.DescriptionLinks)
                {
                    currentArrowDescription.Links.Add(new LinkLabel.Link()
                    {
                        LinkData = l.Item1,
                        Start    = l.Item2,
                        Length   = l.Item3
                    });
                }
            }
                                                             );

            var collapseResponsesCheckedUpdater = Updaters.Create(() => viewModel.IsCollapseResponsesChecked,
                                                                  value => collapseResponsesCheckbox.Checked = value);

            var collapseRoleInstancesChecked = Updaters.Create(() => viewModel.IsCollapseRoleInstancesChecked,
                                                               value => collapseRoleInstancesCheckbox.Checked = value);

            var updateScrollBars = Updaters.Create(() => viewModel.ScrollInfo,
                                                   value => UpdateScrollBars(value.vMax, value.vChange, value.vValue, value.hMax, value.hChange, value.hValue));

            var invalidateViews = Updaters.Create(() => viewModel.ArrowsDrawInfo, () => viewModel.RolesDrawInfo, (_1, _2) =>
            {
                rolesCaptionsPanel.Invalidate();
                arrowsPanel.Invalidate();
                leftPanel.Invalidate();
            });

            viewModel.ChangeNotification.CreateSubscription(() =>
            {
                notificationsIconUpdater();
                updateCurrentArrowControls();
                collapseResponsesCheckedUpdater();
                collapseRoleInstancesChecked();
                updateScrollBars();
                invalidateViews();
            });
        }
        void IView.SetViewModel(IViewModel viewModel)
        {
            this.EnsureCreated();

            this.viewModel = viewModel;

            var fontSz = (NSFont.SystemFontSize + NSFont.SmallSystemFontSize) / 2f;

            this.resources = new Resources(
                viewModel,
                NSFont.SystemFontOfSize(NSFont.SystemFontSize).FamilyName,
                (float)fontSz)
            {
                BookmarkImage       = new LJD.Image(NSImage.ImageNamed("Bookmark.png")),
                FocusedMessageImage = new LJD.Image(NSImage.ImageNamed("FocusedMsgSlave.png")),
                FocusedMsgSlaveVert = new LJD.Image(NSImage.ImageNamed("FocusedMsgSlaveVert.png"))
            };

            this.drawingUtils = new DrawingUtils(viewModel, resources);

            var notificationsIconUpdater = Updaters.Create(
                () => viewModel.IsNotificationsIconVisibile,
                value => activeNotificationsButton.Hidden = !value
                );

            var updateCurrentArrowControls = Updaters.Create(
                () => viewModel.CurrentArrowInfo,
                value => {
                arrowNameTextField.StringValue = value.Caption;
                arrowDetailsLink.StringValue   = value.DescriptionText;
                arrowDetailsLink.Links         = (value.DescriptionLinks ?? Enumerable.Empty <Tuple <object, int, int> >())
                                                 .Select(l => new NSLinkLabel.Link(l.Item2, l.Item3, l.Item1)).ToArray();
            }
                );

            var updateCollapseResponsesCheckbox = Updaters.Create(
                () => viewModel.IsCollapseResponsesChecked,
                value => collapseResponsesCheckbox.State = value ? NSCellStateValue.On : NSCellStateValue.Off
                );

            var updateCollapseRoleInstancesCheckbox = Updaters.Create(
                () => viewModel.IsCollapseRoleInstancesChecked,
                value => collapseRoleInstancesCheckbox.State = value ? NSCellStateValue.On : NSCellStateValue.Off);

            var scrollBarsUpdater = Updaters.Create(
                () => viewModel.ScrollInfo,
                value => UpdateScrollBars(value.vMax, value.vChange, value.vValue,
                                          value.hMax, value.hChange, value.hValue)
                );

            var invalidateViews = Updaters.Create(
                () => viewModel.RolesDrawInfo,
                () => viewModel.ArrowsDrawInfo,
                (_1, _2) => {
                rolesCaptionsView.NeedsDisplay = true;
                arrowsView.NeedsDisplay        = true;
                leftPanelView.NeedsDisplay     = true;
            }
                );

            viewModel.ChangeNotification.CreateSubscription(() => {
                notificationsIconUpdater();
                updateCurrentArrowControls();
                updateCollapseResponsesCheckbox();
                updateCollapseRoleInstancesCheckbox();
                scrollBarsUpdater();
                invalidateViews();
            });
        }
Ejemplo n.º 3
0
 void IView.SetEventsHandler(IViewEvents eventsHandler)
 {
     this.eventsHandler = eventsHandler;
     this.drawingUtils  = new DrawingUtils(eventsHandler, resources);
 }