Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/HeuristicLab.Netron-3.0.2672.12446/NetronVisualization.cs @ 2909

Last change on this file since 2909 was 2909, checked in by mkommend, 14 years ago

added tooltips for graph visualization buttons and fixed layouting problems (ticket #867)

File size: 4.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30
31using Netron.Diagramming.Core;
32
33namespace HeuristicLab.Netron {
34  [ToolboxItem(true)]
35  public partial class NetronVisualization : DiagramControlBase {
36    private static Size INVALID_SIZE = new Size(-1, -1);
37    private Size oldSize;
38    public NetronVisualization()
39      : base() {
40      InitializeComponent();
41      this.oldSize = INVALID_SIZE;
42
43      SetStyle(ControlStyles.AllPaintingInWmPaint, true);
44      SetStyle(ControlStyles.DoubleBuffer, true);
45      SetStyle(ControlStyles.UserPaint, true);
46      SetStyle(ControlStyles.ResizeRedraw, true);
47
48      if (!DesignMode) {
49        this.Controller = new Controller(this);
50        this.Document = new Document();
51        this.Document.Model.Selection = new Selection(this.Controller, this.Document.Model);
52        this.View = new View(this);
53        this.AttachToDocument(Document);
54        this.Controller.View = View;
55        TextEditor.Init(this);
56
57        View.OnCursorChange += new EventHandler<CursorEventArgs>(mView_OnCursorChange);
58        View.OnBackColorChange += new EventHandler<ColorEventArgs>(View_OnBackColorChange);
59
60        this.SizeChanged += new EventHandler(NetronVisualization_SizeChanged);
61        this.UpdateView();
62      }
63    }
64
65    public Size PageSize {
66      get { return this.View.PageSize; }
67      set {
68        this.View.PageSize = value;
69        this.UpdateView();
70      }
71    }
72
73    private void UpdateView() {
74      //zoom in to show scrollbars - code taken from ControllerBase line 1082
75      SizeF s = this.View.Magnification;
76      float alpha = 1.1F;
77      View.Magnification = new SizeF(
78          s.Width * alpha,
79          s.Height * alpha);
80
81      float w = (float)this.AutoScrollPosition.X /
82          (float)this.AutoScrollMinSize.Width;
83
84      float h = (float)this.AutoScrollPosition.Y /
85          (float)this.AutoScrollMinSize.Height;
86
87      RectangleF pageBounds = this.Controller.Model.CurrentPage.Bounds;
88      pageBounds.Inflate(s);
89      SizeF deltaSize = new SizeF(
90          pageBounds.Width - this.ClientRectangle.Width,
91          pageBounds.Height - this.ClientRectangle.Height);
92
93      if ((deltaSize.Width > 0) && (deltaSize.Height > 0)) {
94        this.AutoScrollMinSize = Size.Round(deltaSize);
95      }
96    }
97
98    private void NetronVisualization_SizeChanged(object sender, EventArgs e) {
99      //if (this.oldSize == INVALID_SIZE) {
100      //this.View.PageSize = new Size((int)(this.Size.Width * this.Magnification.Width), (int)(this.Size.Height * this.Magnification.Height));
101      //  if (!this.DesignMode)
102      //    oldSize = this.Size;
103      //  return;
104      //}
105
106      //SizeF magnificationChanges = new SizeF();
107      //magnificationChanges.Width = ((float)this.Size.Width) / oldSize.Width;
108      //magnificationChanges.Height = ((float)this.Size.Height) / oldSize.Height;
109
110      //SizeF newMagnification = new SizeF();
111      //newMagnification.Width = this.View.Magnification.Width * magnificationChanges.Width;
112      //newMagnification.Height = this.View.Magnification.Height * magnificationChanges.Height;
113
114      //this.Magnification = newMagnification;
115      //this.oldSize = this.Size;
116    }
117
118    protected override void OnScroll(ScrollEventArgs se) {
119      //base.OnScroll(se);
120      if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll) {
121        Origin = new Point(se.NewValue, Origin.Y);
122        //System.Diagnostics.Trace.WriteLine(se.NewValue);
123      } else {
124        Origin = new Point(Origin.X, se.NewValue);
125        //System.Diagnostics.Trace.WriteLine(se.NewValue);
126      }
127    }
128
129    private void mView_OnCursorChange(object sender, CursorEventArgs e) {
130      this.Cursor = e.Cursor;
131    }
132  }
133}
Note: See TracBrowser for help on using the repository browser.