1 /*
2  * NPlot - A charting library for .NET
3  *
4  * MenuForm.cs
5  * Copyright (C) 2003-2006 Matt Howlett and others.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice, this
12  *    list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  *    this list of conditions and the following disclaimer in the documentation
15  *    and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26  * OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 using System;
30 using System.Drawing;
31 using System.Collections;
32 using System.ComponentModel;
33 using System.Windows.Forms;
34 using System.Threading;
35 
36 namespace NPlotDemo
37 {
38 	/// <summary>
39 	/// Summary description for MenuForm.
40 	/// </summary>
41 	public class MenuForm : System.Windows.Forms.Form
42 	{
43 		private System.Windows.Forms.Button multiPlotDemoButton;
44 		private System.Windows.Forms.Button plotSurface2DDemoButton;
45 		private System.Windows.Forms.Button quitButton;
46 		private System.Windows.Forms.Label DemosLabel;
47 		private System.Windows.Forms.Label TestsLabel;
48 		private System.Windows.Forms.ComboBox TestSelectComboBox;
49 
50 		private ArrayList testItems;
51 		private System.Windows.Forms.Button RunTestButton;
52 
53 		public class TestItem
54 		{
55 
56 			/// <summary>
57 			/// Constructor
58 			/// </summary>
59 			/// <param name="name">The name of the test</param>
60 			/// <param name="form">The form that contains the test</param>
TestItem( string name, Form form )61 			public TestItem( string name, Form form )
62 			{
63 				form_ = form;
64 				name_ = name;
65 			}
66 
67 			/// <summary>
68 			/// Name of the test.
69 			/// </summary>
70 			public string Name
71 			{
72 				get
73 				{
74 					return name_;
75 				}
76 			}
77 			private string name_;
78 
79 			/// <summary>
80 			/// The form that contains the test.
81 			/// </summary>
82 			public Form Form
83 			{
84 				get
85 				{
86 					return form_;
87 				}
88 			}
89 			private Form form_;
90 
91 		}
92 
93 		/// <summary>
94 		/// Required designer variable.
95 		/// </summary>
96 		private System.ComponentModel.Container components = null;
97 
MenuForm()98 		public MenuForm()
99 		{
100 			//
101 			// Required for Windows Form Designer support
102 			//
103 			InitializeComponent();
104 
105 			testItems = new ArrayList();
106 			testItems.Add( new TestItem( "Axis Test", new AxisTestsForm() ) );
107 
108 			this.TestSelectComboBox.DataSource = testItems;
109 			this.TestSelectComboBox.DisplayMember = "Name";
110 		}
111 
112 		/// <summary>
113 		/// Clean up any resources being used.
114 		/// </summary>
Dispose( bool disposing )115 		protected override void Dispose( bool disposing )
116 		{
117 			if( disposing )
118 			{
119 				if(components != null)
120 				{
121 					components.Dispose();
122 				}
123 			}
124 			base.Dispose( disposing );
125 		}
126 
127 		#region Windows Form Designer generated code
128 		/// <summary>
129 		/// Required method for Designer support - do not modify
130 		/// the contents of this method with the code editor.
131 		/// </summary>
InitializeComponent()132 		private void InitializeComponent()
133 		{
134 			this.multiPlotDemoButton = new System.Windows.Forms.Button();
135 			this.plotSurface2DDemoButton = new System.Windows.Forms.Button();
136 			this.quitButton = new System.Windows.Forms.Button();
137 			this.DemosLabel = new System.Windows.Forms.Label();
138 			this.TestsLabel = new System.Windows.Forms.Label();
139 			this.TestSelectComboBox = new System.Windows.Forms.ComboBox();
140 			this.RunTestButton = new System.Windows.Forms.Button();
141 			this.SuspendLayout();
142 			//
143 			// multiPlotDemoButton
144 			//
145 			this.multiPlotDemoButton.Location = new System.Drawing.Point(8, 56);
146 			this.multiPlotDemoButton.Name = "multiPlotDemoButton";
147 			this.multiPlotDemoButton.Size = new System.Drawing.Size(136, 23);
148 			this.multiPlotDemoButton.TabIndex = 2;
149 			this.multiPlotDemoButton.Text = "Multi Plot Demo";
150 			this.multiPlotDemoButton.Click += new System.EventHandler(this.runDemoButton_Click);
151 			//
152 			// plotSurface2DDemoButton
153 			//
154 			this.plotSurface2DDemoButton.Location = new System.Drawing.Point(8, 32);
155 			this.plotSurface2DDemoButton.Name = "plotSurface2DDemoButton";
156 			this.plotSurface2DDemoButton.Size = new System.Drawing.Size(136, 23);
157 			this.plotSurface2DDemoButton.TabIndex = 3;
158 			this.plotSurface2DDemoButton.Text = "PlotSurface2D Demo";
159 			this.plotSurface2DDemoButton.Click += new System.EventHandler(this.plotSurface2DDemoButton_Click);
160 			//
161 			// quitButton
162 			//
163 			this.quitButton.Location = new System.Drawing.Point(40, 200);
164 			this.quitButton.Name = "quitButton";
165 			this.quitButton.TabIndex = 8;
166 			this.quitButton.Text = "Quit";
167 			this.quitButton.Click += new System.EventHandler(this.quitButton_Click);
168 			//
169 			// DemosLabel
170 			//
171 			this.DemosLabel.Location = new System.Drawing.Point(8, 8);
172 			this.DemosLabel.Name = "DemosLabel";
173 			this.DemosLabel.TabIndex = 9;
174 			this.DemosLabel.Text = "Demos";
175 			//
176 			// TestsLabel
177 			//
178 			this.TestsLabel.Location = new System.Drawing.Point(8, 96);
179 			this.TestsLabel.Name = "TestsLabel";
180 			this.TestsLabel.TabIndex = 10;
181 			this.TestsLabel.Text = "Tests";
182 			//
183 			// TestSelectComboBox
184 			//
185 			this.TestSelectComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
186 			this.TestSelectComboBox.Location = new System.Drawing.Point(8, 120);
187 			this.TestSelectComboBox.Name = "TestSelectComboBox";
188 			this.TestSelectComboBox.Size = new System.Drawing.Size(136, 21);
189 			this.TestSelectComboBox.TabIndex = 11;
190 			//
191 			// RunTestButton
192 			//
193 			this.RunTestButton.Location = new System.Drawing.Point(8, 152);
194 			this.RunTestButton.Name = "RunTestButton";
195 			this.RunTestButton.Size = new System.Drawing.Size(136, 23);
196 			this.RunTestButton.TabIndex = 12;
197 			this.RunTestButton.Text = "Run Selected Test";
198 			this.RunTestButton.Click += new System.EventHandler(this.RunTestButton_Click);
199 			//
200 			// MenuForm
201 			//
202 			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
203 			this.ClientSize = new System.Drawing.Size(152, 238);
204 			this.Controls.Add(this.RunTestButton);
205 			this.Controls.Add(this.TestSelectComboBox);
206 			this.Controls.Add(this.TestsLabel);
207 			this.Controls.Add(this.DemosLabel);
208 			this.Controls.Add(this.quitButton);
209 			this.Controls.Add(this.plotSurface2DDemoButton);
210 			this.Controls.Add(this.multiPlotDemoButton);
211 			this.Name = "MenuForm";
212 			this.Text = "NPlot Demo";
213 			this.ResumeLayout(false);
214 
215 		}
216 		#endregion
217 
218         [STAThread]
Main()219 		static void Main()
220 		{
221 			Application.Run(new MenuForm());
222 		}
223 
224 		private System.Windows.Forms.Form displayForm_ = null;
WindowThread()225 		private void WindowThread()
226 		{
227 			displayForm_.ShowDialog();
228 		}
229 
runDemoButton_Click(object sender, System.EventArgs e)230 		private void runDemoButton_Click(object sender, System.EventArgs e)
231 		{
232 
233 			displayForm_ = new FinancialDemo();
234 			System.Threading.Thread t = new Thread( new ThreadStart(WindowThread) );
235             t.ApartmentState = ApartmentState.STA;
236             //t.SetApartmentState(ApartmentState.STA);
237             t.Start();
238 
239         }
240 
plotSurface2DDemoButton_Click(object sender, System.EventArgs e)241         private void plotSurface2DDemoButton_Click(object sender, System.EventArgs e)
242 		{
243 			displayForm_ = new PlotSurface2DDemo();
244 			displayForm_.ShowDialog();
245 			/*
246 			System.Threading.Thread t = new Thread( new ThreadStart(WindowThread) );
247             //t.SetApartmentState( ApartmentState.STA ); // necessary for copy to clipboard to work.
248             t.ApartmentState = ApartmentState.STA;
249             t.Start();
250 			*/
251 		}
252 
253 
quitButton_Click(object sender, System.EventArgs e)254 		private void quitButton_Click(object sender, System.EventArgs e)
255 		{
256 			Application.Exit();
257 		}
258 
RunTestButton_Click(object sender, System.EventArgs e)259 		private void RunTestButton_Click(object sender, System.EventArgs e)
260 		{
261 			TestItem ti = (TestItem)this.TestSelectComboBox.SelectedItem;
262 
263 			displayForm_ = ti.Form;
264 			System.Threading.Thread t = new Thread( new ThreadStart(WindowThread) );
265 			//t.SetApartmentState( ApartmentState.STA ); // necessary for copy to clipboard to work.
266 			t.ApartmentState = ApartmentState.STA;
267 			t.Start();
268 		}
269 
270 
271 	}
272 }
273