void LuaDebuggerInterface::updateExecutionToolbar(void)
{
    _ExecuteButton->setEnabled(!TheLuaManager->isRunning());
    _StopExecutionButton->setEnabled(TheLuaManager->isRunning());
    _StepInButton->setEnabled(TheLuaManager->isStopped() && !TheLuaManager->isFinished());
    _StepOutButton->setEnabled(TheLuaManager->isStopped() && !TheLuaManager->isFinished());
    _StepOverButton->setEnabled(TheLuaManager->isStopped() && !TheLuaManager->isFinished());
}
ComponentTransitPtr createButtonedComp(Component* const LabelComp,
                                       const Button::ActionPerformedEventType::slot_type &listener)
{
    ButtonRecPtr CompRemoveButton = Button::create();
    CompRemoveButton->setText("-");
    //CompRemoveButton->setToolTipText("Remove");
    CompRemoveButton->setPreferredSize(Vec2f(17.0f,17.0f));
    CompRemoveButton->setAlignment(Vec2f(0.5f,0.5f));
    CompRemoveButton->setFont(dynamic_cast<Label*>(LabelComp)->getFont());

    //Connect
    CompRemoveButton->connectActionPerformed(listener);

    SpringLayoutRecPtr TreeCompLayout = SpringLayout::create();
    PanelRecPtr CompPanel = Panel::createEmpty();

    TreeCompLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, LabelComp, 0, SpringLayoutConstraints::NORTH_EDGE, CompPanel);
    TreeCompLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, LabelComp, 0, SpringLayoutConstraints::SOUTH_EDGE, CompPanel);
    TreeCompLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, LabelComp, 0, SpringLayoutConstraints::EAST_EDGE, CompPanel);
    TreeCompLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, LabelComp, 0, SpringLayoutConstraints::WEST_EDGE, CompPanel);

    TreeCompLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, CompRemoveButton, -5, SpringLayoutConstraints::EAST_EDGE, CompPanel);
    TreeCompLayout->putConstraint(SpringLayoutConstraints::VERTICAL_CENTER_EDGE, CompRemoveButton, 0, SpringLayoutConstraints::VERTICAL_CENTER_EDGE, CompPanel);

    CompPanel->setLayout(TreeCompLayout);
    CompPanel->pushToChildren(LabelComp);
    CompPanel->pushToChildren(CompRemoveButton);

    return ComponentTransitPtr(CompPanel);
}
/******************************************************

  Create function callbacks for TabPanel.
    Note: This tutorial uses as its 
    base 15TabPanel; for commented version
    see 15TabPanel.

 ******************************************************/
void handleAddTabAction(ActionEventDetails* const details,
                        TabPanel* const ExampleTabPanel,
                        Button* const ExampleTabContentA,
                        Button* const ExampleTabContentB)
{

    ButtonRecPtr AddedTabButton = Button::create(),
                 AddedTabContent = Button::create();
    AddedTabButton->setText("Tab7");

    AddedTabContent->setText("This is where the new Tab content hangs out");

    if( ExampleTabPanel->getMFTabs()->size() == 6) 
    {
        ExampleTabPanel->addTab(AddedTabButton, AddedTabContent);

        // Change the text on the Tabs
        ExampleTabContentA->setText("Remove Tab7 under Tab2!");

        ExampleTabContentB->setText("Remove Tab7");
    }
}
ComponentTransitPtr LuaDebuggerInterface::generateSplitOptionListComponent(List* const Parent,
                                                     const boost::any& Value,
                                                     UInt32 Index,
                                                     bool IsSelected,
                                                     bool HasFocus)
{
    ButtonRecPtr TheComponent = Button::create();
    TheComponent->setBackgrounds(NULL);
    TheComponent->setAlignment(Vec2f(0.0f,0.5f));

    std::string ValueString;
    try
    {
        ValueString = boost::any_cast<std::string>(Value);

        BoostPath IconPath;
        if(ValueString.compare("Horizontal") == 0)
        {
            IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-left-right.png"));
        }
        else if(ValueString.compare("Vertical") == 0)
        {
            IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-top-bottom.png"));
        }
        else
        {
            IconPath = BoostPath(_BaseIconDir / BoostPath("view-split-none.png"));
        }

        TheComponent->setImages(IconPath.string());
    }
    catch (boost::bad_lexical_cast &)
    {
        //Could not convert to string
    }

    TheComponent->setText(ValueString);

    if(IsSelected)
    {
        LineBorderRecPtr LabelBorder = LineBorder::create();
        LabelBorder->setWidth(1.0f);
        LabelBorder->setColor(Color4f(0.0f,0.0f,0.0f,1.0f));
        TheComponent->setBorders(LabelBorder);
    }
    else
    {
        TheComponent->setBorders(NULL);
    }

    return ComponentTransitPtr(TheComponent);
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));

        // Make Torus Node (creates Torus in background of scene)
        NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

        // Make Main Scene Node and add the Torus
        NodeRecPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(TorusGeometryNode);

        // Create the Graphics
        GraphicsRecPtr TutorialGraphics = Graphics2D::create();

        // Initialize the LookAndFeelManager to enable default settings
        LookAndFeelManager::the()->getLookAndFeel()->init();

        /******************************************************

          Create an Button Component and
          a simple Font.
          See 17Label_Font for more
          information about Fonts.

         ******************************************************/
        ButtonRecPtr ExampleButton = Button::create();

        UIFontRecPtr ExampleFont = UIFont::create();
        ExampleFont->setSize(16);

        ExampleButton->setMinSize(Vec2f(50, 25));
        ExampleButton->setMaxSize(Vec2f(200, 100));
        ExampleButton->setPreferredSize(Vec2f(100, 50));
        ExampleButton->setToolTipText("Button 1 ToolTip");

        ExampleButton->setText("Button 1");
        ExampleButton->setFont(ExampleFont);
        ExampleButton->setTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
        ExampleButton->setRolloverTextColor(Color4f(1.0, 0.0, 1.0, 1.0));
        ExampleButton->setActiveTextColor(Color4f(1.0, 0.0, 0.0, 1.0));
        ExampleButton->setAlignment(Vec2f(1.0,0.0));


        /******************************************************

          Create a ToggleButton and determine its 
          characteristics.  ToggleButton inherits
          off of Button, so all characteristsics
          used above can be used with ToggleButtons
          as well.

          The only difference is that when pressed,
          ToggleButton remains pressed until pressed 
          again.

          -setSelected(bool): Determine whether the 
          ToggleButton is Selected (true) or
          deselected (false).  

         ******************************************************/
        ToggleButtonRecPtr ExampleToggleButton = ToggleButton::create();

        ExampleToggleButton->setSelected(false);
        ExampleToggleButton->setText("ToggleMe");
        ExampleToggleButton->setToolTipText("Toggle Button ToolTip");


        // Create Background to be used with the MainInternalWindow
        ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

        // Create The Internal Window
        InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
        LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
        // Assign the Button to the MainInternalWindow so it will be displayed
        // when the view is rendered.
        MainInternalWindow->pushToChildren(ExampleButton);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setPosition(Pnt2f(50,50));
        MainInternalWindow->setPreferredSize(Vec2f(300,300));
        MainInternalWindow->setTitle(std::string("Internal Window 1"));

        // Create The Internal Window
        InternalWindowRecPtr MainInternalWindow2 = InternalWindow::create();
        LayoutRecPtr MainInternalWindowLayout2 = FlowLayout::create();
        // Assign the Button to the MainInternalWindow so it will be displayed
        // when the view is rendered.
        MainInternalWindow2->pushToChildren(ExampleToggleButton);
        MainInternalWindow2->setLayout(MainInternalWindowLayout2);
        MainInternalWindow2->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow2->setPosition(Pnt2f(150,150));
        MainInternalWindow2->setPreferredSize(Vec2f(300,300));
        MainInternalWindow2->setTitle(std::string("Allways on top window"));
        MainInternalWindow2->setIconable(false);
        MainInternalWindow2->setAllwaysOnTop(true);

        // Create the Drawing Surface
        UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);

        TutorialDrawingSurface->openWindow(MainInternalWindow);
        TutorialDrawingSurface->openWindow(MainInternalWindow2);
        // Create the UI Foreground Object
        UIForegroundRecPtr TutorialUIForeground = UIForeground::create();
        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);


        // Tell the Manager what to manage
        sceneManager.setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

        // Show the whole Scene
        sceneManager.showAll();


        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "37InternalWindow");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
void LuaDebuggerInterface::createCodeEditor(void)
{
    //Create the Breakpoint images
    BoostPath BreakpointIconPath(_BaseIconDir / BoostPath("breakpoint.png")),
              BreakpointDisabledIconPath(_BaseIconDir / BoostPath("breakpoint-disabled.png")),
              BreakpointConditionalIconPath(_BaseIconDir / BoostPath("breakpoint-conditional.png")),
              BreakpointConditionalDisabledIconPath(_BaseIconDir / BoostPath("breakpoint-conditional-disabled.png")),
              BreakpointCountIconPath(_BaseIconDir / BoostPath("breakpoint-count.png")),
              BreakpointCountDisabledIconPath(_BaseIconDir / BoostPath("breakpoint-count-disabled.png"));
    
    //Breakpoint Button prototypes
    //Regular Breakpoint
    ButtonRecPtr BreakpointProtoButton = Button::create();
    BreakpointProtoButton->setPreferredSize(Vec2f(18.0f, 18.0f));
    BreakpointProtoButton->setImages(BreakpointIconPath.string());
    BreakpointProtoButton->setDisabledImage(BreakpointDisabledIconPath.string());
    BreakpointProtoButton->setBorders(NULL);
    BreakpointProtoButton->setBackgrounds(NULL);
    BreakpointProtoButton->setForegrounds(NULL);

    //Count Breakpoint
    ButtonRecPtr BreakpointCountProtoButton = Button::create();
    BreakpointCountProtoButton->setPreferredSize(Vec2f(18.0f, 18.0f));
    BreakpointCountProtoButton->setImages(BreakpointCountIconPath.string());
    BreakpointCountProtoButton->setDisabledImage(BreakpointCountDisabledIconPath.string());
    BreakpointCountProtoButton->setBorders(NULL);
    BreakpointCountProtoButton->setBackgrounds(NULL);
    BreakpointCountProtoButton->setForegrounds(NULL);

    //Conditional breakpoint
    ButtonRecPtr BreakpointConditionalProtoButton = Button::create();
    BreakpointConditionalProtoButton->setPreferredSize(Vec2f(18.0f, 18.0f));
    BreakpointConditionalProtoButton->setImages(BreakpointConditionalIconPath.string());
    BreakpointConditionalProtoButton->setDisabledImage(BreakpointConditionalDisabledIconPath.string());
    BreakpointConditionalProtoButton->setBorders(NULL);
    BreakpointConditionalProtoButton->setBackgrounds(NULL);
    BreakpointConditionalProtoButton->setForegrounds(NULL);

    //Create the default font
    _CodeFont = UIFont::create();
    _CodeFont->setFamily("Courier New");
    _CodeFont->setSize(21);
    _CodeFont->setGlyphPixelSize(22);
    _CodeFont->setAntiAliasing(false);

    // Create a TextArea component
    _CodeTextArea = TextEditor::create();
    _CodeTextArea->setIsSplit(false);
    _CodeTextArea->setClipboardVisible(false);
    //_CodeTextArea->getTextDomArea()->setFont(_CodeFont);
    //_CodeTextArea->setGutterWidth(50.0f);
    _CodeTextArea->setText(createDefaultCodeText());

    //_CodeTextArea->connectCaretChanged(boost::bind(&LuaDebuggerInterface::codeAreaCaretChanged,this, _1));
    //_CodeTextArea->connectMouseClicked(boost::bind(&LuaDebuggerInterface::handleCodeAreaMouseClicked,this, _1));

    _MainSplitPanel = SplitPanel::create();
    _MainSplitPanel->setMinComponent(_CodeTextArea);
    _MainSplitPanel->setMaxComponent(_InfoTabPanel);
    _MainSplitPanel->setOrientation(SplitPanel::VERTICAL_ORIENTATION);
    _MainSplitPanel->setDividerPosition(0.7);
    // location from the left/top
    _MainSplitPanel->setDividerSize(4);
    _MainSplitPanel->setMaxDividerPosition(.8);
    _MainSplitPanel->setMinDividerPosition(.2);

    //Code Area Info
    LabelRefPtr LineLabel = Label::create();
    LineLabel->setText("Line:");
    LineLabel->setPreferredSize(Vec2f(40.0f, 30.0f));
    LineLabel->setAlignment(Vec2f(1.0f, 0.5f));

    _LineValueLabel = Label::create();
    _LineValueLabel->setText("");
    _LineValueLabel->setPreferredSize(Vec2f(40.0f, 30.0f));

    LabelRefPtr ColumnLabel = Label::create();
    ColumnLabel->setText("Column:");
    ColumnLabel->setPreferredSize(Vec2f(55.0f, 30.0f));
    ColumnLabel->setAlignment(Vec2f(1.0f, 0.5f));

    _ColumnValueLabel = Label::create();
    _ColumnValueLabel->setText("");
    _ColumnValueLabel->setPreferredSize(Vec2f(40.0f, 30.0f));
    //TextArea Info Panel

    _CodeAreaInfoPanel = Panel::create();

    SpringLayoutRefPtr CodeAreaInfoLayout = SpringLayout::create();

    //ColumnValueLabel
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _ColumnValueLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _ColumnValueLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _ColumnValueLabel, 0, SpringLayoutConstraints::EAST_EDGE, _CodeAreaInfoPanel);

    //ColumnLabel    
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, ColumnLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, ColumnLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, ColumnLabel, -1, SpringLayoutConstraints::WEST_EDGE, _ColumnValueLabel);

    //LineValueLabel    
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _LineValueLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _LineValueLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _LineValueLabel, -1, SpringLayoutConstraints::WEST_EDGE, ColumnLabel);

    //LineLabel    
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, LineLabel, 0, SpringLayoutConstraints::NORTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, LineLabel, 0, SpringLayoutConstraints::SOUTH_EDGE, _CodeAreaInfoPanel);
    CodeAreaInfoLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, LineLabel, -1, SpringLayoutConstraints::WEST_EDGE, _LineValueLabel);

    _CodeAreaInfoPanel->setPreferredSize(Vec2f(400.0f, 22.0f));
    _CodeAreaInfoPanel->pushToChildren(LineLabel);
    _CodeAreaInfoPanel->pushToChildren(_LineValueLabel);
    _CodeAreaInfoPanel->pushToChildren(ColumnLabel);
    _CodeAreaInfoPanel->pushToChildren(_ColumnValueLabel);
    _CodeAreaInfoPanel->setBorders(NULL);
    _CodeAreaInfoPanel->setLayout(CodeAreaInfoLayout);
}
void LuaDebuggerInterface::createExecutionToolbar(void)
{
    //Execute Button
    BoostPath ExecuteIconPath(_BaseIconDir / BoostPath("execute.png"));
    BoostPath ExecuteDisabledIconPath(_BaseIconDir / BoostPath("execute-disabled.png"));
    _ExecuteButton = Button::create();
    _ExecuteButton->setPreferredSize(_ToolButtonSize);
    _ExecuteButton->setImages(ExecuteIconPath.string());
    _ExecuteButton->setDisabledImage(ExecuteDisabledIconPath.string());
    _ExecuteButton->setAlignment(Vec2f(0.5f,0.5f));
    _ExecuteButton->setToolTipText("Execute");
    _ExecuteButton->connectActionPerformed(boost::bind(&LuaDebuggerInterface::executeScriptButtonAction,this));

    //Step Into Button
    BoostPath StepInIconPath(_BaseIconDir / BoostPath("basicstepinto.png"));
    BoostPath StepInDisabledIconPath(_BaseIconDir / BoostPath("basicstepinto-disabled.png"));
    _StepInButton = Button::create();
    _StepInButton->setPreferredSize(_ToolButtonSize);
    _StepInButton->setImages(StepInIconPath.string());
    _StepInButton->setDisabledImage(StepInDisabledIconPath.string());
    _StepInButton->setAlignment(Vec2f(0.5f,0.5f));
    _StepInButton->setToolTipText("Step In");

    //Step Out Button
    BoostPath StepOutIconPath(_BaseIconDir / BoostPath("basicstepout.png"));
    BoostPath StepOutDisabledIconPath(_BaseIconDir / BoostPath("basicstepout-disabled.png"));
    _StepOutButton = Button::create();
    _StepOutButton->setPreferredSize(_ToolButtonSize);
    _StepOutButton->setImages(StepOutIconPath.string());
    _StepOutButton->setDisabledImage(StepOutDisabledIconPath.string());
    _StepOutButton->setAlignment(Vec2f(0.5f,0.5f));
    _StepOutButton->setToolTipText("Step Out");

    //Step Over Button
    BoostPath StepOverIconPath(_BaseIconDir / BoostPath("basicstepover.png"));
    BoostPath StepOverDisabledIconPath(_BaseIconDir / BoostPath("basicstepover-disabled.png"));
    _StepOverButton = Button::create();
    _StepOverButton->setPreferredSize(_ToolButtonSize);
    _StepOverButton->setImages(StepOverIconPath.string());
    _StepOverButton->setDisabledImage(StepOverDisabledIconPath.string());
    _StepOverButton->setAlignment(Vec2f(0.5f,0.5f));
    _StepOverButton->setToolTipText("Step Over");

    //Stop Button
    BoostPath StopExecutionIconPath(_BaseIconDir / BoostPath("stop.png"));
    BoostPath StopExecutionDisabledIconPath(_BaseIconDir / BoostPath("stop-disabled.png"));
    _StopExecutionButton = Button::create();
    _StopExecutionButton->setPreferredSize(_ToolButtonSize);
    _StopExecutionButton->setImages(StopExecutionIconPath.string());
    _StopExecutionButton->setDisabledImage(StopExecutionDisabledIconPath.string());
    _StopExecutionButton->setAlignment(Vec2f(0.5f,0.5f));
    _StopExecutionButton->setToolTipText("Stop");

    //Code Execution Toolbar
    //Layout
    FlowLayoutRecPtr ToolbarLayout = FlowLayout::create();
    ToolbarLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION);
    ToolbarLayout->setHorizontalGap(3.0f);
    ToolbarLayout->setMajorAxisAlignment(0.0f);
    ToolbarLayout->setMinorAxisAlignment(0.5);

    _CodeExecutionToolbar = Panel::createEmpty();
    _CodeExecutionToolbar->setPreferredSize(Vec2f(45.0f, 45.0f));
    _CodeExecutionToolbar->setLayout(ToolbarLayout);
    _CodeExecutionToolbar->pushToChildren(_ExecuteButton);
    _CodeExecutionToolbar->pushToChildren(_StopExecutionButton);
    _CodeExecutionToolbar->pushToChildren(_StepOverButton);
    _CodeExecutionToolbar->pushToChildren(_StepInButton);
    _CodeExecutionToolbar->pushToChildren(_StepOutButton);

    updateExecutionToolbar();
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));

        // Make Torus Node (creates Torus in background of scene)
        NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

        // Make Main Scene Node and add the Torus
        NodeRecPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(TorusGeometryNode);

        // Create the Graphics
        GraphicsRecPtr TutorialGraphics = Graphics2D::create();

        // Initialize the LookAndFeelManager to enable default settings
        LookAndFeelManager::the()->getLookAndFeel()->init();

        //Create the nessicary parts for a viewport
        Matrix TransformMatrix;
        TransformMatrix.setTranslate(0.0f,0.0f, 0.0f);
        TransformRecPtr CameraBeaconTransform = Transform::create();
        CameraBeaconTransform->setMatrix(TransformMatrix);

        NodeRecPtr CameraBeaconNode = Node::create();
        CameraBeaconNode->setCore(CameraBeaconTransform);

        // Make Torus Node (creates Torus in background of scene)
        NodeRecPtr GeometryNode = makeTorus(.5, 2, 32, 32);

        //Make a light Node
        NodeRecPtr LightBeaconNode = makeCoredNode<Transform>();

        DirectionalLightRecPtr SceneLight = DirectionalLight::create();
        SceneLight->setAmbient(Color4f(0.3f,0.3f,0.3f,1.0f));
        SceneLight->setDiffuse(Color4f(0.8f,0.8f,0.8f,1.0f));
        SceneLight->setSpecular(Color4f(1.0f,1.0f,1.0f,1.0f));
        SceneLight->setOn(true);
        SceneLight->setBeacon(LightBeaconNode);

        NodeRecPtr LightNode = makeNodeFor(SceneLight);
        LightNode->addChild(GeometryNode);

        // Make Main Scene Node and add the Torus
        NodeRecPtr DefaultRootNode = Node::create();
        DefaultRootNode->setCore(Group::create());
        DefaultRootNode->addChild(LightNode);
        DefaultRootNode->addChild(LightBeaconNode);
        DefaultRootNode->addChild(CameraBeaconNode);

        //Camera
        PerspectiveCameraRecPtr DefaultCamera = PerspectiveCamera::create();
        DefaultCamera->setBeacon(CameraBeaconNode);
        DefaultCamera->setFov   (osgDegree2Rad(60.f));
        DefaultCamera->setNear  (0.1f);
        DefaultCamera->setFar   (100.f);

        //Background
        GradientBackgroundRecPtr DefaultBackground = GradientBackground::create();
        DefaultBackground->addLine(Color3f(0.0f,0.0f,0.0f), 0.0f);
        DefaultBackground->addLine(Color3f(0.0f,0.0f,1.0f), 1.0f);

        //Viewport
        ViewportRecPtr DefaultViewport = Viewport::create();
        DefaultViewport->setCamera                  (DefaultCamera);
        DefaultViewport->setRoot                    (DefaultRootNode);
        DefaultViewport->setSize                    (0.0f,0.0f, 1.0f,1.0f);
        DefaultViewport->setBackground              (DefaultBackground);

        //GL Viewport Component
        LineBorderRecPtr TheGLViewportBorder = LineBorder::create();
        TheGLViewportBorder->setColor(Color4f(1.0,0.0,0.0,1.0));
        TheGLViewportBorder->setWidth(3.0);

        GLViewportRecPtr TheGLViewport = GLViewport::create();
        TheGLViewport->setPort(DefaultViewport);
        TheGLViewport->setPreferredSize(Vec2f(400.0f,400.0f));
        TheGLViewport->setBorders(TheGLViewportBorder);
        TheGLViewport->lookAt(Pnt3f(0.0f,0.0f,10.0f), //From
                              Pnt3f(0.0f,0.0f,0.0f), //At
                              Vec3f(0.0f,1.0f,0.0f)); //Up

        ButtonRecPtr ExampleButton = Button::create();

        ExampleButton->setText("Example");

        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

        InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
        LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
        MainInternalWindow->pushToChildren(TheGLViewport);
        MainInternalWindow->pushToChildren(ExampleButton);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f));
        MainInternalWindow->setDrawTitlebar(false);
        MainInternalWindow->setResizable(false);

        // Create the Drawing Surface
        UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);

        TutorialDrawingSurface->openWindow(MainInternalWindow);

        // Create the UI Foreground Object
        UIForegroundRecPtr TutorialUIForeground = UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);


        // Tell the Manager what to manage
        sceneManager.setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

        //Create the Documentation Foreground and add it to the viewport
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // Show the whole Scene
        sceneManager.showAll();


        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "41GLViewportComponent");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));

        // Make Torus Node (creates Torus in background of scene)
        NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

        // Make Main Scene Node and add the Torus
        NodeRecPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(TorusGeometryNode);

        // Create the Graphics
        GraphicsRecPtr TutorialGraphics = Graphics2D::create();

        // Initialize the LookAndFeelManager to enable default settings
        LookAndFeelManager::the()->getLookAndFeel()->init();
        /******************************************************

          Create an Button Component and
          a simple Font.
          See 17Label_Font for more
          information about Fonts.

         ******************************************************/

        LineBorderRecPtr ChangableBorder = LineBorder::create();
        ChangableBorder->setColor(Color4f(0.0,0.0,0.0,1.0));

        ColorLayerRecPtr ChangableBackground = ColorLayer::create();
        ChangableBackground->setColor(Color4f(1.0,1.0,1.0,1.0));

        LabelRecPtr ChangableLabel = Label::create();

        ChangableLabel->setText("Changable");
        ChangableLabel->setBorders(ChangableBorder);
        ChangableLabel->setBackgrounds(ChangableBackground);

        //Command Buttons
        UndoManagerPtr TheUndoManager = UndoManager::create();

        CommandManagerPtr TheCommandManager = CommandManager::create(TheUndoManager);
        ButtonRecPtr BorderRedButton = Button::create();
        BorderRedButton->setText("Border Red");
        BorderRedButton->setPreferredSize(Vec2f(85, 20));
        BorderRedButton->connectActionPerformed(boost::bind(handleSetBorderColorAction,
                                                            _1,
                                                            TheCommandManager,
                                                            ChangableBorder.get(),
                                                            Color4f(1.0,0.0,0.0,1.0)));

        ButtonRecPtr BorderGreenButton = Button::create();
        BorderGreenButton->setText("Border Green");
        BorderGreenButton->setPreferredSize(Vec2f(85, 20));
        BorderGreenButton->connectActionPerformed(boost::bind(handleSetBorderColorAction,
                                                            _1,
                                                            TheCommandManager,
                                                            ChangableBorder.get(),
                                                            Color4f(0.0,1.0,0.0,1.0)));

        ButtonRecPtr BorderBlueButton = Button::create();
        BorderBlueButton->setText("Border Blue");
        BorderBlueButton->setPreferredSize(Vec2f(85, 20));
        BorderBlueButton->connectActionPerformed(boost::bind(handleSetBorderColorAction,
                                                            _1,
                                                            TheCommandManager,
                                                            ChangableBorder.get(),
                                                            Color4f(0.0,0.0,1.0,1.0)));

        //Background
        ButtonRecPtr BackgroundRedButton = Button::create();
        BackgroundRedButton->setText("Background Red");
        BackgroundRedButton->setPreferredSize(Vec2f(105, 20));
        BackgroundRedButton->connectActionPerformed(boost::bind(handleSetBackgroundColorAction,
                                                                _1,
                                                                TheCommandManager,
                                                                ChangableBackground.get(),
                                                                Color4f(1.0,0.0,0.0,1.0)));

        ButtonRecPtr BackgroundGreenButton = Button::create();
        BackgroundGreenButton->setText("Background Green");
        BackgroundGreenButton->setPreferredSize(Vec2f(105, 20));
        BackgroundGreenButton->connectActionPerformed(boost::bind(handleSetBackgroundColorAction,
                                                                _1,
                                                                TheCommandManager,
                                                                ChangableBackground.get(),
                                                                Color4f(0.0,1.0,0.0,1.0)));

        ButtonRecPtr BackgroundBlueButton = Button::create();
        BackgroundBlueButton->setText("Background Blue");
        BackgroundBlueButton->setPreferredSize(Vec2f(105, 20));
        BackgroundBlueButton->connectActionPerformed(boost::bind(handleSetBackgroundColorAction,
                                                                _1,
                                                                TheCommandManager,
                                                                ChangableBackground.get(),
                                                                Color4f(0.0,0.0,1.0,1.0)));

        //UndoList
        DefaultListModelRecPtr UndoRedoListModel = DefaultListModel::create();
        UndoRedoListModel->pushBack(boost::any(std::string("Top")));

        ListRecPtr UndoRedoList = List::create();
        UndoRedoList->setPreferredSize(Vec2f(200, 300));
        UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION);
        UndoRedoList->setModel(UndoRedoListModel);

        UndoRedoList->getSelectionModel()->connectSelectionChanged(boost::bind(handleUndoRedoListSelectionChanged,
                                                                               _1,
                                                                               UndoRedoList.get(),
                                                                               TheUndoManager));

        ButtonRecPtr UndoButton = Button::create();
        UndoButton->setText("Undo");
        UndoButton->setEnabled(TheUndoManager->numberOfUndos() != 0);
        UndoButton->connectActionPerformed(boost::bind(handleUndoButtonAction,
                                                       _1,
                                                       TheUndoManager));


        ButtonRecPtr RedoButton = Button::create();
        RedoButton->setText("Redo");
        RedoButton->setEnabled(TheUndoManager->numberOfRedos() != 0);
        RedoButton->connectActionPerformed(boost::bind(handleRedoButtonAction,
                                                       _1,
                                                       TheUndoManager));

        // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel)
        ScrollPanelRecPtr UndoRedoScrollPanel = ScrollPanel::create();
        UndoRedoScrollPanel->setPreferredSize(Vec2f(200,200));
        UndoRedoScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
        UndoRedoScrollPanel->setViewComponent(UndoRedoList);

        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
        InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
        LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();
        MainInternalWindow->pushToChildren(BorderRedButton);
        MainInternalWindow->pushToChildren(BorderGreenButton);
        MainInternalWindow->pushToChildren(BorderBlueButton);
        MainInternalWindow->pushToChildren(BackgroundRedButton);
        MainInternalWindow->pushToChildren(BackgroundGreenButton);
        MainInternalWindow->pushToChildren(BackgroundBlueButton);
        MainInternalWindow->pushToChildren(ChangableLabel);
        MainInternalWindow->pushToChildren(UndoRedoScrollPanel);
        MainInternalWindow->pushToChildren(UndoButton);
        MainInternalWindow->pushToChildren(RedoButton);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f));
        MainInternalWindow->setDrawTitlebar(false);
        MainInternalWindow->setResizable(false);


        TheUndoManager->connectStateChanged(boost::bind(handleUndoManagerStateChanged,
                                                        _1,
                                                        UndoRedoListModel.get(),
                                                        TheUndoManager,
                                                        UndoButton.get(),
                                                        RedoButton.get()));

        // Create the Drawing Surface
        UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);

        TutorialDrawingSurface->openWindow(MainInternalWindow);

        // Create the UI Foreground Object
        UIForegroundRecPtr TutorialUIForeground = UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);

        // Tell the Manager what to manage
        sceneManager.setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRecPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

        //Create the Documentation Foreground and add it to the viewport
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // Show the whole Scene
        sceneManager.showAll();


        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "40UndoableCommand");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);
    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        TutorialWindow->connectKeyTyped(boost::bind(keyTyped, _1));

        // Make Torus Node (creates Torus in background of scene)
        NodeRefPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

        // Make Main Scene Node and add the Torus
        NodeRefPtr scene = OSG::Node::create();
        scene->setCore(OSG::Group::create());
        scene->addChild(TorusGeometryNode);

        // Create the Graphics
        GraphicsRefPtr TutorialGraphics = OSG::Graphics2D::create();

        // Initialize the LookAndFeelManager to enable default settings
        LookAndFeelManager::the()->getLookAndFeel()->init();

        //Background
        SolidBackgroundRefPtr TutorialBackground = SolidBackground::create();
        TutorialBackground->setColor(Color3f(1.0,0.0,0.0));
    		    
        UndoManagerPtr TheUndoManager = UndoManager::create();
        CommandManagerPtr TheCommandManager = CommandManager::create(TheUndoManager);

        //UndoList
	    DefaultListModelRecPtr UndoRedoListModel = DefaultListModel::create();
        UndoRedoListModel->pushBack(boost::any(std::string("Top")));

	    ListRecPtr UndoRedoList = List::create();
        UndoRedoList->setPreferredSize(Vec2f(250, 300));
        UndoRedoList->setOrientation(List::VERTICAL_ORIENTATION);
	    UndoRedoList->setModel(UndoRedoListModel);

        UndoRedoList->getSelectionModel()->connectSelectionChanged(boost::bind(&handleUndoRedoListSelectionChanged, _1, TheUndoManager));

        ButtonRecPtr UndoButton = OSG::Button::create();
        UndoButton->setText("Undo");
	    UndoButton->setEnabled(false);
        UndoButton->connectActionPerformed(boost::bind(&handleUndoButtonAction, _1, TheUndoManager));
    	

        ButtonRecPtr RedoButton = OSG::Button::create();
        RedoButton->setText("Redo");
	    RedoButton->setEnabled(false);
        RedoButton->connectActionPerformed(boost::bind(&handleRedoButtonActionPerformed, _1, TheUndoManager));

        TheUndoManager->connectStateChanged(boost::bind(&handleUndoManagerStateChanged, _1, UndoButton.get(), RedoButton.get(), UndoRedoListModel.get(), TheUndoManager));

        // Create a ScrollPanel for easier viewing of the List (see 27ScrollPanel)
        ScrollPanelRefPtr UndoRedoScrollPanel = ScrollPanel::create();
        UndoRedoScrollPanel->setPreferredSize(Vec2f(200,200));
        UndoRedoScrollPanel->setHorizontalResizePolicy(ScrollPanel::RESIZE_TO_VIEW);
        UndoRedoScrollPanel->setViewComponent(UndoRedoList);


        //Edited Label
        LabelRecPtr EditedLabel = Label::create();
        EditedLabel->setText("Can be edited");
        EditedLabel->setPreferredSize(Vec2f(100.0f,18.0f));

        //Editor Field
        LabelRecPtr TheTextEditorLabel = Label::create();
        TheTextEditorLabel->setText("Text");
        TheTextEditorLabel->setPreferredSize(Vec2f(100.0f, 20.0f));

        FieldEditorComponentRefPtr TheTextEditor = FieldEditorFactory::the()->createDefaultEditor(EditedLabel,
                                                                                                  Label::TextFieldId,
                                                                                                  TheCommandManager);
        TheTextEditor->setPreferredSize(Vec2f(100.0f, 20.0f));

        LabelRecPtr ThePreferredSizeEditorLabel = Label::create();
        ThePreferredSizeEditorLabel->setText("PreferredSize");
        ThePreferredSizeEditorLabel->setPreferredSize(Vec2f(100.0f, 20.0f));

        FieldEditorComponentRefPtr ThePreferredSizeEditor =
            FieldEditorFactory::the()->createDefaultEditor(EditedLabel,
                                                           Label::PreferredSizeFieldId,
                                                           TheCommandManager);
        ThePreferredSizeEditor->setPreferredSize(Vec2f(150.0f, 20.0f));

        //Editing Panel
        LayoutRefPtr EditorPanelLayout = OSG::FlowLayout::create();
        PanelRecPtr EditorPanel = Panel::create();
        EditorPanel->setPreferredSize(Vec2f(200.0f,200.0f));
        EditorPanel->pushToChildren(TheTextEditorLabel);
        EditorPanel->pushToChildren(TheTextEditor);
        EditorPanel->pushToChildren(ThePreferredSizeEditorLabel);
        EditorPanel->pushToChildren(ThePreferredSizeEditor);
        EditorPanel->setLayout(EditorPanelLayout);

        //Undo Panel
        LabelRecPtr UndoPanelLabel = Label::create();
        UndoPanelLabel->setText("Undo Panel");
        UndoPanelLabel->setPreferredSize(Vec2f(100.0f, 20.0f));

        LayoutRefPtr UndoPanelLayout = OSG::FlowLayout::create();
        PanelRecPtr UndoPanel = Panel::create();
        UndoPanel->setPreferredSize(Vec2f(300.0f,300.0f));
        UndoPanel->pushToChildren(UndoPanelLabel);
        UndoPanel->pushToChildren(UndoRedoScrollPanel);
        UndoPanel->pushToChildren(UndoButton);
        UndoPanel->pushToChildren(RedoButton);
        UndoPanel->setLayout(UndoPanelLayout);

        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRefPtr MainInternalWindowBackground = OSG::ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));
        InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
        LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();
        MainInternalWindow->pushToChildren(EditedLabel);
        MainInternalWindow->pushToChildren(EditorPanel);
        MainInternalWindow->pushToChildren(UndoPanel);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.95f,0.95f));
        MainInternalWindow->setDrawTitlebar(false);
        MainInternalWindow->setResizable(false);

        // Create the Drawing Surface
        UIDrawingSurfaceRefPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);
        
	    TutorialDrawingSurface->openWindow(MainInternalWindow);
    	
	    // Create the UI Foreground Object
        UIForegroundRefPtr TutorialUIForeground = OSG::UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);
        sceneManager.setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRefPtr TutorialViewport = sceneManager.getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);
        TutorialViewport->setBackground(TutorialBackground);

        // Show the whole Scene
        sceneManager.showAll();

        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                    WinSize,
                                    "02GenericFieldEditor");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();
        TutorialWindow->initWindow();

        // Create the SimpleSceneManager helper
        SimpleSceneManagerRefPtr sceneManager = SimpleSceneManager::create();
        TutorialWindow->setDisplayCallback(boost::bind(display, sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, sceneManager));

        // Tell the Manager what to manage
        sceneManager->setWindow(TutorialWindow);

        TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1));

        // Make Torus Node (creates Torus in background of scene)
        NodeRecPtr TorusGeometryNode = makeTorus(.5, 2, 16, 16);

        // Make Main Scene Node and add the Torus
        NodeRecPtr scene = Node::create();
        scene->setCore(Group::create());
        scene->addChild(TorusGeometryNode);

        // Create the Graphics
        GraphicsRecPtr TutorialGraphics = Graphics2D::create();

        // Initialize the LookAndFeelManager to enable default settings
        LookAndFeelManager::the()->getLookAndFeel()->init();

        /******************************************************

          Create PopupMenu Components

          -MenuItem: These are items that are contained
          within a Menu; they are the things you click
          on to cause something to occur
          -SeperatorMenuItem:  These place a seperator 
          line between items in a Menu
          -Menu: These are sub-menus within another Menu;
          MenuItems and SeperatorMenuItems
          are added to a Menu

         ******************************************************/

        MenuItemRecPtr MenuItem1 = MenuItem::create();
        MenuItemRecPtr MenuItem2 = MenuItem::create();
        MenuItemRecPtr MenuItem3 = MenuItem::create();
        MenuItemRecPtr MenuItem4 = MenuItem::create();
        MenuItemRecPtr SubMenuItem1 = MenuItem::create();
        MenuItemRecPtr SubMenuItem2 = MenuItem::create();
        MenuItemRecPtr SubMenuItem3 = MenuItem::create();
        MenuRecPtr ExampleSubMenu = Menu::create();

        /******************************************************

          Edit the MenuItems

          -setText("TEXT"): Sets the text on the 
          item to be TEXT
          -setEnabled(Boolean): sets the menu item
          to be either enabled or disabled

         ******************************************************/

        MenuItem1->setText("Menu Item 1");

        MenuItem2->setText("Menu Item 2");

        MenuItem3->setText("Menu Item 3");

        MenuItem4->setText("Menu Item 4");
        MenuItem4->setEnabled(false);

        SubMenuItem1->setText("SubMenu Item 1");

        SubMenuItem2->setText("SubMenu Item 2");

        SubMenuItem3->setText("SubMenu Item 3");

        ExampleSubMenu->setText("Sub Menu");

        // This adds three MenuItems to the Menu,
        // creating a submenu.  Note this does not
        // involve begin/endEditCPs to do

        ExampleSubMenu->addItem(SubMenuItem1);
        ExampleSubMenu->addItem(SubMenuItem2);
        ExampleSubMenu->addItem(SubMenuItem3);

        /******************************************************

          Create the PopupMenu itself.

          Items are added in the order in which
          they will be displayed (top to bottom)
          via addItem(ItemToBeAdded)

          The PopupMenu is attached to a 
          Button below using 
          setPopupMenu(PopupMenuName).  

            Note: PopupMenus can be added to any
            Component.

         ******************************************************/
        PopupMenuRecPtr ExamplePopupMenu = PopupMenu::create();
        ExamplePopupMenu->setMinSize(Vec2f(100.0f, 20.0f));
        ExamplePopupMenu->setMaxSize(Vec2f(100.0f, 80.0f));
        ExamplePopupMenu->addItem(MenuItem1);
        ExamplePopupMenu->addItem(MenuItem2);
        ExamplePopupMenu->addItem(MenuItem3);
        ExamplePopupMenu->addSeparator();
        ExamplePopupMenu->addItem(ExampleSubMenu);
        ExamplePopupMenu->addItem(MenuItem4);

        // Create a Button and Font
        UIFontRecPtr PopupMenuButtonFont = UIFont::create();
        PopupMenuButtonFont->setSize(16);

        ButtonRecPtr PopupMenuButton = Button::create();
        PopupMenuButton->setText("RightClickMe!");
        // Add the PopupMenu to PopupMenuButton so that when right clicked,
        // the PopupMenu will appear
        PopupMenuButton->setPopupMenu(ExamplePopupMenu);
        PopupMenuButton->setPreferredSize(Vec2f(200,100));
        PopupMenuButton->setFont(PopupMenuButtonFont);


        // Create The Main InternalWindow
        // Create Background to be used with the Main InternalWindow
        ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
        MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

        LayoutRecPtr MainInternalWindowLayout = FlowLayout::create();

        InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
        MainInternalWindow->pushToChildren(PopupMenuButton);
        MainInternalWindow->setLayout(MainInternalWindowLayout);
        MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
        MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setScalingInDrawingSurface(Vec2f(0.5f,0.5f));
        MainInternalWindow->setDrawTitlebar(false);
        MainInternalWindow->setResizable(false);

        // Create the Drawing Surface
        UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create();
        TutorialDrawingSurface->setGraphics(TutorialGraphics);
        TutorialDrawingSurface->setEventProducer(TutorialWindow);

        TutorialDrawingSurface->openWindow(MainInternalWindow);

        // Create the UI Foreground Object
        UIForegroundRecPtr TutorialUIForeground = UIForeground::create();

        TutorialUIForeground->setDrawingSurface(TutorialDrawingSurface);


        // Tell the Manager what to manage
        sceneManager->setRoot(scene);

        // Add the UI Foreground Object to the Scene
        ViewportRecPtr TutorialViewport = sceneManager->getWindow()->getPort(0);
        TutorialViewport->addForeground(TutorialUIForeground);

        //Create the Documentation Foreground and add it to the viewport
        SimpleScreenDoc TheSimpleScreenDoc(sceneManager, TutorialWindow);

        // Show the whole Scene
        sceneManager->showAll();

        //Open Window
        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "01RubberBandCamera");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
InternalWindowTransitPtr createMainInternalWindow(void)
{
    /******************************************************

      Create Button Components to be used with 
      TabPanel and specify their characteristics.

        Note: Buttons are used for simplicity,
        any Component can be used as Tab content
        or as a Tab.  A Panel with several
        Buttons within it is also added.

     ******************************************************/

    ButtonRecPtr ExampleTabButton1 = Button::create();
    ButtonRecPtr ExampleTabButton2 = Button::create();
    ButtonRecPtr ExampleTabButton3 = Button::create();
    ButtonRecPtr ExampleTabButton4 = Button::create();
    ButtonRecPtr ExampleTabButton5 = Button::create();
    ButtonRecPtr ExampleTabButton6 = Button::create();
    ButtonRecPtr ExampleTabContentA = Button::create();
    ButtonRecPtr ExampleTabContentB = Button::create();
    ButtonRecPtr ExampleTabContentC = Button::create();
    ButtonRecPtr ExampleTabContentD = Button::create();
    ButtonRecPtr ExampleTabContentE = Button::create();
    ButtonRecPtr ExampleTabContentF = Button::create();

    ExampleTabButton1->setText("Tab1");

    ExampleTabButton2->setText("Tab2");

    ExampleTabButton3->setText("To Rotate");

    ExampleTabButton4->setText("Tab4");

    ExampleTabButton5->setText("To Zoom");

    ExampleTabButton6->setText("To Move");

    ExampleTabContentA->setText("Add another Tab");

    ExampleTabContentB->setText("Add a Tab in Tab1!");

    ExampleTabContentC->setText("Enable CapsLock, then rotate scene using left Mouse button!");

    ExampleTabContentD->setText("Enable CapsLock, then zoom in and out with right Mouse button and dragging");

    ExampleTabContentE->setText("Enable CapsLock, then move using center Mouse button");

    /******************************************************

      Create a Panel to add to the TabPanel

     ******************************************************/

    // Create and edit the Panel Buttons
    ButtonRecPtr ExampleTabPanelButton1 = Button::create();
    ButtonRecPtr ExampleTabPanelButton2 = Button::create();
    ButtonRecPtr ExampleTabPanelButton3 = Button::create();
    ButtonRecPtr ExampleTabPanelButton4 = Button::create();
    ButtonRecPtr ExampleTabPanelButton5 = Button::create();
    ButtonRecPtr ExampleTabPanelButton6 = Button::create();

    ExampleTabPanelButton1->setText("This is a");

    ExampleTabPanelButton2->setText("sample");

    ExampleTabPanelButton3->setText("UIRectangle");

    ExampleTabPanelButton4->setText("containing");

    ExampleTabPanelButton5->setText("interactive");

    ExampleTabPanelButton6->setText("components");

    // Create and edit Panel Layout
    BoxLayoutRecPtr TabPanelLayout = BoxLayout::create();
    TabPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION);

    // Create and edit Panel
    PanelRecPtr ExampleTabPanelPanel = Panel::create();
    ExampleTabPanelPanel->setPreferredSize(Vec2f(180, 500));
    ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton1);
    ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton2);
    ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton3);
    ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton4);
    ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton5);
    ExampleTabPanelPanel->pushToChildren(ExampleTabPanelButton6);
    ExampleTabPanelPanel->setLayout(TabPanelLayout);

    TabPanelRecPtr ExampleTabPanel = TabPanel::create();
    ExampleTabPanel->setPreferredSize(Vec2f(350,350));
    ExampleTabPanel->addTab(ExampleTabButton1, ExampleTabContentA);
    ExampleTabPanel->addTab(ExampleTabButton2, ExampleTabContentB);
    ExampleTabPanel->addTab(ExampleTabButton3, ExampleTabContentC);
    ExampleTabPanel->addTab(ExampleTabButton4, ExampleTabPanelPanel);
    ExampleTabPanel->addTab(ExampleTabButton5, ExampleTabContentD);
    ExampleTabPanel->addTab(ExampleTabButton6, ExampleTabContentE);
    ExampleTabPanel->setTabAlignment(0.5f);
    ExampleTabPanel->setTabPlacement(TabPanel::PLACEMENT_SOUTH);
    ExampleTabPanel->setSelectedIndex(3);

    // Create The Main InternalWindow
    // Create Background to be used with the Main InternalWindow
    ColorLayerRecPtr MainInternalWindowBackground = ColorLayer::create();
    MainInternalWindowBackground->setColor(Color4f(1.0,1.0,1.0,0.5));

    CardLayoutRecPtr MainInternalWindowLayout = CardLayout::create();

    InternalWindowRecPtr MainInternalWindow = InternalWindow::create();
    MainInternalWindow->pushToChildren(ExampleTabPanel);
    MainInternalWindow->setLayout(MainInternalWindowLayout);
    MainInternalWindow->setBackgrounds(MainInternalWindowBackground);
    MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f));
    MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f));
    MainInternalWindow->setDrawTitlebar(false);
    MainInternalWindow->setResizable(false);

    ExampleTabContentB->connectActionPerformed(boost::bind(handleRemoveTabAction, _1,
                                                           ExampleTabPanel.get(),
                                                           ExampleTabContentA.get(),
                                                           ExampleTabContentB.get()));
    ExampleTabContentA->connectActionPerformed(boost::bind(handleAddTabAction, _1,
                                                           ExampleTabPanel.get(),
                                                           ExampleTabContentA.get(),
                                                           ExampleTabContentB.get()));

    return InternalWindowTransitPtr(MainInternalWindow);
}
PanelTransitPtr VideoFieldContainerEditor::createVideoPreviewPanel(void)
{
    ChunkMaterialUnrecPtr VideoMaterial = ChunkMaterial::create();

    //Video MaterialLayer
    _VideoMaterialLayer = MaterialLayer::create();
    _VideoMaterialLayer->setMaterial(VideoMaterial);

    //Video Panel
    _VideoPanel = Panel::createEmpty();
    _VideoPanel->setBackgrounds(_VideoMaterialLayer);

    //Filename Label
    _FileNameLabel = Label::create();
    _FileNameLabel->setAlignment(Vec2f(0.5f, 0.5f));

    //Total time Label
    _TotalTimeLabel = Label::create();
    _TotalTimeLabel->setAlignment(Vec2f(0.0f, 1.0f));
    _TotalTimeLabel->setBorders(NULL);
    _TotalTimeLabel->setBackgrounds(NULL);
    _TotalTimeLabel->setPreferredSize(Vec2f(50.0f,_TotalTimeLabel->getPreferredSize().y()));

    //Playback time Label
    _PlaybackTimeLabel = Label::create();
    _PlaybackTimeLabel->setAlignment(Vec2f(1.0f, 1.0f));
    _PlaybackTimeLabel->setPreferredSize(Vec2f(50.0f,_TotalTimeLabel->getPreferredSize().y()));
    _PlaybackTimeLabel->setBorders(NULL);
    _PlaybackTimeLabel->setBackgrounds(NULL);

    LabelRecPtr TimeSeparatorLabel = Label::create();
    TimeSeparatorLabel->setAlignment(Vec2f(0.5f, 1.0f));
    TimeSeparatorLabel->setPreferredSize(Vec2f(8.0f,_TotalTimeLabel->getPreferredSize().y()));
    TimeSeparatorLabel->setBorders(NULL);
    TimeSeparatorLabel->setBackgrounds(NULL);
    TimeSeparatorLabel->setText("/");

    //PlayPause Button
    _PlayPauseButton = Button::create();
    _PlayPauseButton->setText("Play");
    _PlayPauseButton->setPreferredSize(Vec2f(40.0f,40.0f));
    _PlayPauseButton->connectActionPerformed(boost::bind(&VideoFieldContainerEditor::handlePlayPauseAction, this,   _1));

    //Stop Button
    _StopButton = Button::create();
    _StopButton->setText("Stop");
    _StopButton->setPreferredSize(Vec2f(40.0f,40.0f));
    _StopButton->connectActionPerformed(boost::bind(&VideoFieldContainerEditor::handleStopAction, this,   _1));

    //Load Button
    ButtonRecPtr LoadButton = Button::create();
    LoadButton->setText("Load");
    LoadButton->setPreferredSize(Vec2f(40.0f,40.0f));
    LoadButton->connectActionPerformed(boost::bind(&VideoFieldContainerEditor::handleLoadAction, this,   _1));

    //Playback position slider
    _LocationSlider = Slider::create();
    _LocationSlider->setOrientation(Slider::HORIZONTAL_ORIENTATION);
    _LocationSlider->setDrawLabels(false);
    _LocationSlider->setDrawMajorTicks(false);
    _LocationSlider->setDrawMinorTicks(false);
    _LocationSlider->setBorders(NULL);
    _LocationSlider->setBackgrounds(NULL);
    //_LocationSlider->getKnobButton()->setPreferredSize(Vec2f(15.0f, 8.0f));
    _LocationSlider->getRangeModel()->connectStateChanged(boost::bind(&VideoFieldContainerEditor::handlePlaybackLocationStateChanged, this,   _1));


    //Layout
    PanelRecPtr VideoPanel = Panel::createEmpty();
    SpringLayoutRecPtr MainLayout = SpringLayout::create();


    //Video Panel
    MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _VideoPanel, 0,
                              SpringLayoutConstraints::EAST_EDGE, VideoPanel);
    MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, _VideoPanel, 0,
                              SpringLayoutConstraints::WEST_EDGE, VideoPanel);
    MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _VideoPanel, 0,
                              SpringLayoutConstraints::NORTH_EDGE, VideoPanel);
    MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _VideoPanel, -1,
                              SpringLayoutConstraints::NORTH_EDGE, _PlayPauseButton);

    //Filename Label
    MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _FileNameLabel, 0,
                              SpringLayoutConstraints::EAST_EDGE, VideoPanel);
    MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, _FileNameLabel, 0,
                              SpringLayoutConstraints::WEST_EDGE, VideoPanel);
    MainLayout->putConstraint(SpringLayoutConstraints::NORTH_EDGE, _FileNameLabel, 0,
                              SpringLayoutConstraints::NORTH_EDGE, VideoPanel);

    //Play/pause Button
    MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _PlayPauseButton, -3,
                              SpringLayoutConstraints::WEST_EDGE, _StopButton);
    MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _PlayPauseButton, 0,
                              SpringLayoutConstraints::SOUTH_EDGE, VideoPanel);

    //Stop Button
    MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _StopButton, -3,
                              SpringLayoutConstraints::WEST_EDGE, _LocationSlider);
    MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _StopButton, 0,
                              SpringLayoutConstraints::SOUTH_EDGE, VideoPanel);

    //Playback Slider
    MainLayout->putConstraint(SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, _LocationSlider, 0,
                              SpringLayoutConstraints::HORIZONTAL_CENTER_EDGE, VideoPanel);
    MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _LocationSlider, 0,
                              SpringLayoutConstraints::SOUTH_EDGE, VideoPanel);

    //Total video length label
    MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _TotalTimeLabel, 0,
                              SpringLayoutConstraints::SOUTH_EDGE, LoadButton);
    MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _TotalTimeLabel, 0,
                              SpringLayoutConstraints::EAST_EDGE, _LocationSlider);

    //Separator label
    MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, TimeSeparatorLabel, 0,
                              SpringLayoutConstraints::SOUTH_EDGE, LoadButton);
    MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, TimeSeparatorLabel, -2,
                              SpringLayoutConstraints::WEST_EDGE, _TotalTimeLabel);

    //Playback time label
    MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, _PlaybackTimeLabel, 0,
                              SpringLayoutConstraints::SOUTH_EDGE, LoadButton);
    MainLayout->putConstraint(SpringLayoutConstraints::EAST_EDGE, _PlaybackTimeLabel, -2,
                              SpringLayoutConstraints::WEST_EDGE, TimeSeparatorLabel);

    //Load Button
    MainLayout->putConstraint(SpringLayoutConstraints::WEST_EDGE, LoadButton, 3,
                              SpringLayoutConstraints::EAST_EDGE, _LocationSlider);
    MainLayout->putConstraint(SpringLayoutConstraints::SOUTH_EDGE, LoadButton, 0,
                              SpringLayoutConstraints::SOUTH_EDGE, VideoPanel);

    //Main Video Panel
    VideoPanel->setLayout(MainLayout);

    VideoPanel->pushToChildren(_VideoPanel);
    VideoPanel->pushToChildren(_FileNameLabel);
    VideoPanel->pushToChildren(_PlayPauseButton);
    VideoPanel->pushToChildren(_StopButton);
    VideoPanel->pushToChildren(LoadButton);
    VideoPanel->pushToChildren(_PlaybackTimeLabel);
    VideoPanel->pushToChildren(TimeSeparatorLabel);
    VideoPanel->pushToChildren(_TotalTimeLabel);
    VideoPanel->pushToChildren(_LocationSlider);

    return PanelTransitPtr(VideoPanel);
}