Launcher.cs :  » GUI » wx-NET » wx » SampleLauncher » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » wx NET 
wx NET » wx » SampleLauncher » Launcher.cs
//-----------------------------------------------------------------------------
// wx.NET/Samples - Launcher.cs
//
// wx.NET sample "Launcher".
//
// Written by Alexander Olk (xenomorph2@onlinehome.de)
// (C) 2004 Alexander Olk
// Licensed under the wxWidgets license, see LICENSE.txt for details.
//
// Launcher.cs,v 1.13 2004/07/02 20:53:27 t9mike Exp
//-----------------------------------------------------------------------------

using System;
using System.Drawing;
using System.Collections;
using System.Diagnostics;
using System.IO;

/** This application starts the samples.
 */
namespace wx.SampleLauncher{
  public class LauncherFrame : Frame
  {
    private MiddleHtmlWindow middleHtmlWindow = null;
    private TopHtmlWindow topHtmlWindow = null;
    private BottomHtmlWindow bottomHtmlWindow = null;
    
    //---------------------------------------------------------------------

    public LauncherFrame( string title, Point pos, Size size )
      : base(title, wxDefaultPosition, size)
    {
      Icon = new wx.Icon( "../Samples/Launcher/mondrian.png" );

      CreateStatusBar( 1 );
      StatusText = "Welcome...";  
      
      topHtmlWindow = new TopHtmlWindow( this );
      middleHtmlWindow = new MiddleHtmlWindow( this );
      bottomHtmlWindow = new BottomHtmlWindow( this );
      
      BoxSizer bs = new BoxSizer( Orientation.wxVERTICAL );
      
      bs.Add( topHtmlWindow, 0, Stretch.wxGROW );
      bs.Add( middleHtmlWindow, 1, Stretch.wxGROW );
      bs.Add( bottomHtmlWindow, 0, Stretch.wxGROW );
      
      Sizer = bs;
      
      CheckEnvironment();
    }
    
    //---------------------------------------------------------------------  
    
    private void CheckEnvironment()
    {
      // If we could determine they are running under PNET warn them
      // things probably won't work (at least as of v0.6.6)
      string clr = Environment.GetEnvironmentVariable("CLR_LAUNCHER");
      if (clr == "ilrun")
      {
        MessageDialog md = new MessageDialog(this, 
          "There is a bug in DotGNU Portable.NET as of v0.6.6 that does not allow the Launcher to work properly. Process.Start(\"ilrun example.exe\") does not work and results in a defunct process.\n\nYou may continue to use the Launcher; however, unless you have a newer version PNET samples probably won't launch when you click them.",
          "Launcher Error", Dialog.wxOK | Dialog.wxICON_WARNING);
        md.ShowModal();
      }
    }
  }   
  
  //---------------------------------------------------------------------  
  
  public class TopHtmlWindow : HtmlWindow
  {
    public TopHtmlWindow( LauncherFrame parent )
      : base( parent, -1, wxDefaultPosition, new Size( 400, 144 ) )
    {
      LoadPage( "../Samples/Launcher/launchertop.html" );
    }
  }
  
  //---------------------------------------------------------------------  
  
  public class BottomHtmlWindow : HtmlWindow
  {
    private LauncherFrame parent = null;
  
    public BottomHtmlWindow( LauncherFrame parent )
      : base( parent, -1, wxDefaultPosition, new Size( 400, 80 ) )
    {
      this.parent = parent;
      LoadPage( "../Samples/Launcher/launcherbottom.html" );
    }
    
    //---------------------------------------------------------------------  
    
    public override void OnLinkClicked(HtmlLinkInfo link)
    {
      if ( link.Href == "quit" )
      {
        parent.Close();
        return;
      }
    }
  }

  //---------------------------------------------------------------------  
  
  public class MiddleHtmlWindow : HtmlWindow
  {
    private LauncherFrame parent = null;
    
    //---------------------------------------------------------------------  
  
    public MiddleHtmlWindow( LauncherFrame parent )
      : base( parent )
    {
      this.parent = parent;
    
      LoadPage( "../Samples/Launcher/wx.NETSamplesLauncher.html" );
    }
    
    //---------------------------------------------------------------------  
    
    public override void OnLinkClicked(HtmlLinkInfo link)
    {
      string app = link.Href;
      
      if ( System.IO.File.Exists( app + ".exe" ) )
      {
        string launch_command = "";

                                // If we are on a Linux platform, use wxnet-run script to
                                // launch samples. This is not used to pick up environment
                                // as this gets inherited. The script ensures we use the
                                // .NET runtime the user has selected.
                                if ( File.Exists( "wxnet-run" ) )
                                        launch_command = "./wxnet-run " + app + ".exe";

                                // On MacOS we need to launch the appropriate bundle
                                else if ( Directory.Exists( "../MacBundles" ) )
                                        launch_command = "open ../MacBundles/" + app + ".app";

                                // Everything else (Windows for now) just execute the assembly
                                else
                                        launch_command = app + ".exe";

        try
        {
          parent.StatusText = "Executing " + launch_command;    
          Process.Start( launch_command );
        }
        catch (Exception ex)
        {
          TellError("Error running command '" + launch_command + "': " +
            ex.Message);
        }
      }
      else
      {
        TellError("The sample " + app + " could not be found in the 'Bin' directory. The sample may not be available on your operating system or it could not be built because of missing development libraries.");
      }
    }
    
    //---------------------------------------------------------------------  

    private void TellError(string msg)
    {
      MessageDialog md = new MessageDialog(this, 
        "An error occured while trying to launch your sample:\n\n" + msg,
        "Sample Launch Error", Dialog.wxOK | Dialog.wxICON_WARNING);
      md.ShowModal();
    }
  }
  
  //---------------------------------------------------------------------  

  public class LauncherApp : wx.App
  {
    public override bool OnInit()
    {
      LauncherFrame frame = new LauncherFrame( "wx.NET Samples Launcher", new Point( 10, 100 ), new Size( 600, 600 ) );
      frame.Show( true );

      return true;
    }

    //---------------------------------------------------------------------

    [STAThread]
    static void Main()
    {
      LauncherApp app = new LauncherApp();
      app.Run();
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.