ComponentTransitPtr DefaultTableCellEditor::getTableCellEditorComponent(Table* const table, const boost::any& value, bool isSelected, UInt32 row, UInt32 column)
{
    if(value.empty()){
        return ComponentTransitPtr(NULL);
    }
    TextFieldRefPtr TheTextField = TextField::create();
    std::string tempString;
    try
    {
        tempString = lexical_cast(value);
    }
    catch (boost::bad_lexical_cast &)
    {
        //Could not convert to string
    }
    TheTextField->setText(tempString);
    TheTextField->setPreferredSize(Vec2f(100,30));
    TheTextField->setAlignment(Vec2f(0.5,0.5));
    TheTextField->selectAll();
    TheTextField->setCaretPosition(TheTextField->getText().size());
    ColorLayerRefPtr tempBackground;
    tempBackground = ColorLayer::create();

    TheTextField->setBackground(tempBackground);

    //if(isSelected){
    //	tempBackground->setColor(Color4f(0.4, 0.4, 1.0, 1.0));
    //}
    //else{
    tempBackground->setColor(Color4f(1.0, 1.0, 1.0, 1.0));
    //}

    LineBorderRefPtr tempBorder;

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

    TheTextField->setBorder(tempBorder);

    setDefaultStringEditor(TheTextField);
    _EditorActionConnection = getDefaultStringEditor()->connectActionPerformed(boost::bind(&DefaultTableCellEditor::handleEditorAction, this, _1));
    _EditorFocusLostConnection = getDefaultStringEditor()->connectFocusLost(boost::bind(&DefaultTableCellEditor::handleEditorFocusLost, this, _1));
    _EditorKeyPressedConnection = getDefaultStringEditor()->connectKeyPressed(boost::bind(&DefaultTableCellEditor::handleEditorKeyPressed, this, _1));
    return ComponentTransitPtr(getDefaultStringEditor());
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

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

    TutorialWindow->setDisplayCallback(display);
    TutorialWindow->setReshapeCallback(reshape);

    TutorialKeyListener TheKeyListener;
    TutorialWindow->addKeyListener(&TheKeyListener);

    // 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();

    // Create a simple Font to be used with the TextField
    UIFontRefPtr sampleFont = OSG::UIFont::create();
    sampleFont->setSize(16);

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


        Create and edit the TextField.  A TextField is
    	a Component which allows a single line of text
    	to be displayed.  Text can be entered via the
    	keyboard, and selected with arrow keys or
    	the Mouse.

        -setTextColor(Color4f): Determine the
    		Text Color.
        setSelectionBoxColor(Color4f): Determine
    		the Color of highlighting around
    		selected Text.
        -setSelectionTextColor(Color4f): Determine
    		the Color of selected Text.
        -setText("TextToBeDisplayed"): Determine
    	    initial Text within TextField.
        -setFont(FontName): Determine the Font
            used within TextField.
        -setSelectionStart(StartCharacterNumber):
            Determine the character with which
    		the selection will initially start.
        -setSelectionEnd(EndCharacterNumber):
            Determine the character which the
    		selection ends before.
        -setAlignment(float): Determine
    		the alignment of the text.
    		The float is a percentage is from the
    		top of the text [0.0-1.0].  Note: be
    		sure to visually verify this, as due
            to font size and line size this does
            not always place it exactly
            at the percentage point.

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

    // Create a TextField component
    TextFieldRefPtr ExampleTextField = OSG::TextField::create();

    ExampleTextField->setPreferredSize(Vec2f(100, 50));
    ExampleTextField->setTextColor(Color4f(0.0, 0.0, 0.0, 1.0));
    ExampleTextField->setSelectionBoxColor(Color4f(0.0, 0.0, 1.0, 1.0));
    ExampleTextField->setSelectionTextColor(Color4f(1.0, 1.0, 1.0, 1.0));
    ExampleTextField->setText("What");
    ExampleTextField->setFont(sampleFont);
    // The next two functions will select the "a" from above
    ExampleTextField->setSelectionStart(2);
    ExampleTextField->setSelectionEnd(3);
    ExampleTextField->setAlignment(Vec2f(0.0,0.5));

    // Create another TextField Component
    TextFieldRefPtr ExampleTextField2 = OSG::TextField::create();
    ExampleTextField2->setText("");
    ExampleTextField2->setEmptyDescText("Write in me, please");
    ExampleTextField2->setPreferredSize(Vec2f(200.0f,ExampleTextField2->getPreferredSize().y()));


    // 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));

    LayoutRefPtr MainInternalWindowLayout = OSG::FlowLayout::create();

    InternalWindowRefPtr MainInternalWindow = OSG::InternalWindow::create();
    MainInternalWindow->pushToChildren(ExampleTextField);
    MainInternalWindow->pushToChildren(ExampleTextField2);
    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
    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);

    // Create the SimpleSceneManager helper
    mgr = new SimpleSceneManager;

    // Tell the Manager what to manage
    mgr->setWindow(TutorialWindow);
    mgr->setRoot(scene);

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

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


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

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

    osgExit();

    return 0;
}
ComponentRefPtr createLeftPanelRadioTextPanel(void)
{

    // Create the RadioButton group
    RadioButtonRefPtr RadioButton1 = OSG::RadioButton::create();
    RadioButtonRefPtr RadioButton2 = OSG::RadioButton::create();
    RadioButtonRefPtr RadioButton3 = OSG::RadioButton::create();
    RadioButtonRefPtr RadioButton4 = OSG::RadioButton::create();

        RadioButton1->setAlignment(Vec2f(0.0,0.5));
        RadioButton1->setPreferredSize(Vec2f(100, 40));
        RadioButton1->setText("Black Text");
        RadioButton1->setToolTipText("Set TextArea text black");
    RadioButton1->addButtonSelectedListener(&RadioButton1Listener);

        RadioButton2->setAlignment(Vec2f(0.0,0.5));
        RadioButton2->setPreferredSize(Vec2f(100, 40));
        RadioButton2->setText("Red Text");
        RadioButton2->setToolTipText("Set TextArea text red");
    RadioButton2->addButtonSelectedListener(&RadioButton2Listener);

        RadioButton3->setAlignment(Vec2f(0.0,0.5));
        RadioButton3->setPreferredSize(Vec2f(100, 40));
        RadioButton3->setText("Green Text");
        RadioButton3->setToolTipText("Set TextArea text green");
    RadioButton3->addButtonSelectedListener(&RadioButton3Listener);

        RadioButton4->setAlignment(Vec2f(0.0,0.5));
        RadioButton4->setPreferredSize(Vec2f(100, 40));
        RadioButton4->setText("Blue Text");
        RadioButton4->setToolTipText("Set TextArea text blue");
    RadioButton4->addButtonSelectedListener(&RadioButton4Listener);

    buttonGroup = RadioButtonGroup::create();
    buttonGroup->addButton(RadioButton1);
    buttonGroup->addButton(RadioButton2);
    buttonGroup->addButton(RadioButton3);
    buttonGroup->addButton(RadioButton4);


    // Create TextArea
    LeftPanelTextArea = OSG::TextArea::create();
        LeftPanelTextArea->setPreferredSize(Vec2f(125, 200));

    // Create Panel and its Background/Border to label TextField
    LabelRefPtr LeftPanelTextFieldLabel = OSG::Label::create();
    EmptyLayerRefPtr LeftPanelTextFieldLabelBackground = OSG::EmptyLayer::create();
    EmptyBorderRefPtr LeftPanelTextFieldLabelBorder = OSG::EmptyBorder::create();
        LeftPanelTextFieldLabel->setPreferredSize(Vec2f(100, 25));
        LeftPanelTextFieldLabel->setBorders(LeftPanelTextFieldLabelBorder);
        LeftPanelTextFieldLabel->setBackgrounds(LeftPanelTextFieldLabelBackground);
        LeftPanelTextFieldLabel->setText("Text Field");

    // Create TextField
    TextFieldRefPtr LeftPanelTextField = OSG::TextField::create();
        LeftPanelTextField->setPreferredSize(Vec2f(125.0f, 22.0f));

    
    // Create an edit Panel Background
    ColorLayerRefPtr LeftPanelRadioTextPanelBackground = OSG::ColorLayer::create();
        LeftPanelRadioTextPanelBackground->setColor(Color4f(0.93f,0.93f,0.93f,1.0f));

    // Create and edit Panel layouts
    FlowLayoutRefPtr LeftPanelRadioTextPanelLayout = OSG::FlowLayout::create();
    FlowLayoutRefPtr LeftPanelRadioTextPanelRadioPanelLayout = OSG::FlowLayout::create();
    FlowLayoutRefPtr LeftPanelRadioTextPanelTextPanelLayout = OSG::FlowLayout::create();
        LeftPanelRadioTextPanelLayout->setMinorAxisAlignment(0.0f);

    // Create two Panels for this Panel
    PanelRefPtr LeftPanelRadioTextPanelRadioPanel = OSG::Panel::create();
    PanelRefPtr LeftPanelRadioTextPanelTextPanel = OSG::Panel::create();

    // Create some Borders
    EmptyBorderRefPtr LeftPanelRadioTextPanelRadioPanelBorder = OSG::EmptyBorder::create();

        LeftPanelRadioTextPanelRadioPanel->setBorders(LeftPanelRadioTextPanelRadioPanelBorder);
        LeftPanelRadioTextPanelRadioPanel->setPreferredSize(Vec2f(125, 200));
        LeftPanelRadioTextPanelRadioPanel->setLayout(LeftPanelRadioTextPanelRadioPanelLayout);
        LeftPanelRadioTextPanelRadioPanel->setBackgrounds(LeftPanelRadioTextPanelBackground);
        LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton1);
        LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton2);
        LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton3);
        LeftPanelRadioTextPanelRadioPanel->pushToChildren(RadioButton4);

    // Create Panel Border
    LineBorderRefPtr PanelBorder1 = OSG::LineBorder::create();
        PanelBorder1->setColor(Color4f(0.0,0.0,0.0,1.0));
        PanelBorder1->setWidth(1);

    // Create and edit Panel
    PanelRefPtr LeftPanelRadioTextPanel = OSG::Panel::create();
        LeftPanelRadioTextPanel->setPreferredSize(Vec2f(180, 500));
        LeftPanelRadioTextPanel->pushToChildren(LeftPanelRadioTextPanelRadioPanel);
        LeftPanelRadioTextPanel->pushToChildren(LeftPanelTextArea);
        LeftPanelRadioTextPanel->pushToChildren(LeftPanelTextFieldLabel);
        LeftPanelRadioTextPanel->pushToChildren(LeftPanelTextField);
        LeftPanelRadioTextPanel->setLayout(LeftPanelRadioTextPanelLayout);
        LeftPanelRadioTextPanel->setBackgrounds(LeftPanelRadioTextPanelBackground);
        LeftPanelRadioTextPanel->setBorders(PanelBorder1);

    return LeftPanelRadioTextPanel;
}
ComponentTransitPtr PanelListComponentGenerator::getListComponent(List* const Parent, const boost::any& Value, UInt32 Index, bool IsSelected, bool HasFocus)
{
	if(Value.empty()){
		return ComponentTransitPtr(NULL);
	}

	std::string ValueString;

    try
    {
        ValueString = lexical_cast(Value);
		PanelRefPtr theComponent = Panel::create();
	
		GridLayoutRefPtr PanelLayout = OSG::GridLayout::create();
		PanelLayout->setRows(3);
		PanelLayout->setColumns(1);
		PanelLayout->setHorizontalGap(0);
		PanelLayout->setVerticalGap(2);

		

		std::stringstream is;
		is<<Index;
		std::string iss;
		is>>iss;
		TextFieldRefPtr theName = TextField::create();
		theName->setText("Group"+iss);
		theName->setPreferredSize(Vec2f(146,20));
		

		PanelRefPtr rangePanel = Panel::create();
		
		GridLayoutRefPtr rangePanelLayout = OSG::GridLayout::create();
		rangePanelLayout->setRows(1);
		rangePanelLayout->setColumns(4);
		rangePanelLayout->setHorizontalGap(2);
		rangePanelLayout->setVerticalGap(0);

		
		LabelRefPtr rangeLabel = Label::create();
		rangeLabel->setText("Range:");
		rangeLabel->setPreferredSize(Vec2f(35,20));

		TextFieldRefPtr from = TextField::create();
		from->setEmptyDescText("From");
		from->setPreferredSize(Vec2f(35,20));

		LabelRefPtr hiphenLabel = Label::create();
		hiphenLabel->setText(" - ");
		hiphenLabel->setPreferredSize(Vec2f(35,20));

		TextFieldRefPtr to = TextField::create();
		to->setPreferredSize(Vec2f(35,20));
		to->setEmptyDescText("To");

		rangePanel->pushToChildren(rangeLabel);
		rangePanel->pushToChildren(from);
		rangePanel->pushToChildren(hiphenLabel);
		rangePanel->pushToChildren(to);
		rangePanel->setLayout(rangePanelLayout);
		rangePanel->setPreferredSize(Vec2f(146,20));

		DefaultMutableComboBoxModelRefPtr TheComboBoxModel = DefaultMutableComboBoxModel::create();
		TheComboBoxModel->addElement(boost::any(Color4f(1.0,0.0,0.0,1.0)));
		TheComboBoxModel->addElement(boost::any(Color4f(0.0,1.0,0.0,1.0)));
		TheComboBoxModel->addElement(boost::any(Color4f(0.0,0.0,1.0,1.0)));
		TheComboBoxModel->addElement(boost::any(Color4f(0.0,0.0,0.0,1.0)));
		TheComboBoxModel->addElement(boost::any(Color4f(1.0,1.0,1.0,1.0)));
		TheComboBoxModel->addElement(boost::any(std::string("More Colors")));

		ColorChooserComboBoxComponentGeneratorRefPtr TheColorChooserComboBoxComponentGenerator = ColorChooserComboBoxComponentGenerator::create();
		
		//Create the ComboBox
		ComboBoxRefPtr TheComboBox = ComboBox::create();
		TheComboBox->setModel(TheComboBoxModel);
		TheComboBox->setCellGenerator(TheColorChooserComboBoxComponentGenerator);
		TheComboBox->setEditable(false);
		TheComboBox->setSelectedIndex(0);
		TheComboBox->setPreferredSize(Vec2f(146,20));

		theComponent->pushToChildren(theName);
		theComponent->pushToChildren(rangePanel);
		theComponent->pushToChildren(TheComboBox);
		theComponent->setLayout(PanelLayout);
		theComponent->setPreferredSize(Vec2f(146,66));

		Parent->setCellMajorAxisLength(66);

		return ComponentTransitPtr(theComponent.get());

    }
    catch (boost::bad_lexical_cast &)
    {
        return ComponentTransitPtr(NULL);
    }

}