Example usage for com.badlogic.gdx.scenes.scene2d.ui Container setBackground

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui Container setBackground

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui Container setBackground.

Prototype

public void setBackground(Drawable background) 

Source Link

Document

Sets the background drawable and adjusts the container's padding to match the background.

Usage

From source file:com.mbrlabs.mundus.ui.modules.menu.MundusMenuBar.java

License:Apache License

@Override
public Table getTable() {
    VisTable root = new VisTable();
    root.setBackground("menu-bg");
    Table menuTable = super.getTable();

    VisImage icon = new VisImage(new Texture(Gdx.files.internal("ui/menu_icon.png")));
    root.add(icon).center().left().pad(5);
    root.add(menuTable).expand().fill().left().center().row();
    Container sep = new Container();
    sep.setBackground(VisUI.getSkin().getDrawable("separator-green"));
    root.add(sep).expandX().fillX().height(1).colspan(2).row();

    return root;/*w  w w  . j  a va  2  s . c  o m*/
}

From source file:com.ray3k.skincomposer.dialog.DialogColorPicker.java

License:Open Source License

public void populate() {
    content.clear();//from  w ww. j  a v a 2 s  . c o m
    content.defaults().padLeft(10.0f);

    Image cursor = new Image(skin.getDrawable("color-picker"));
    cursor.setTouchable(Touchable.enabled);
    Image hueKnob = new Image(skin, "color-scale");
    hueKnob.setTouchable(Touchable.enabled);
    Image hueKnob2 = new Image(skin, "color-scale-flipped");
    hueKnob2.setTouchable(Touchable.enabled);
    Image alphaKnob = new Image(skin, "color-scale");
    alphaKnob.setTouchable(Touchable.enabled);
    Image alphaKnob2 = new Image(skin, "color-scale-flipped");
    alphaKnob2.setTouchable(Touchable.enabled);

    Container selectedColorCont = new Container();
    selectedColorCont.setBackground(skin.getDrawable("white"));
    selectedColorCont.setColor(selectedColor);

    Vector3 v = rgbToHsb(selectedColor.r, selectedColor.g, selectedColor.b);

    Spinner greenSpinner, blueSpinner, alphaSpinner, hueSpinner, saturationSpinner, brightnessSpinner;

    hueSpinner = new Spinner(v.x * 359.0f, 1.0, true, Orientation.HORIZONTAL, spinnerStyle);
    hueSpinner.setMinimum(0.0);
    hueSpinner.setMaximum(359.0);
    hueSpinner.getTextField().addListener(main.getIbeamListener());
    hueSpinner.getButtonMinus().addListener(main.getHandListener());
    hueSpinner.getButtonPlus().addListener(main.getHandListener());

    saturationSpinner = new Spinner(v.y * 100.0f, 1.0, true, Orientation.HORIZONTAL, spinnerStyle);
    saturationSpinner.setMinimum(0.0);
    saturationSpinner.setMaximum(100.0);
    saturationSpinner.getTextField().addListener(main.getIbeamListener());
    saturationSpinner.getButtonMinus().addListener(main.getHandListener());
    saturationSpinner.getButtonPlus().addListener(main.getHandListener());

    brightnessSpinner = new Spinner(v.z * 100.0f, 1.0, true, Orientation.HORIZONTAL, spinnerStyle);
    brightnessSpinner.setMinimum(0.0);
    brightnessSpinner.setMaximum(100.0);
    brightnessSpinner.getTextField().addListener(main.getIbeamListener());
    brightnessSpinner.getButtonMinus().addListener(main.getHandListener());
    brightnessSpinner.getButtonPlus().addListener(main.getHandListener());

    redSpinner = new Spinner(selectedColor.r * 255.0f, 1.0, true, Orientation.HORIZONTAL, spinnerStyle);
    redSpinner.setMinimum(0.0);
    redSpinner.setMaximum(255.0);
    redSpinner.getTextField().addListener(main.getIbeamListener());
    redSpinner.getButtonMinus().addListener(main.getHandListener());
    redSpinner.getButtonPlus().addListener(main.getHandListener());

    greenSpinner = new Spinner(selectedColor.g * 255.0f, 1.0, true, Orientation.HORIZONTAL, spinnerStyle);
    greenSpinner.setMinimum(0.0);
    greenSpinner.setMaximum(255.0);
    greenSpinner.getTextField().addListener(main.getIbeamListener());
    greenSpinner.getButtonMinus().addListener(main.getHandListener());
    greenSpinner.getButtonPlus().addListener(main.getHandListener());

    blueSpinner = new Spinner(selectedColor.b * 255.0f, 1.0, true, Orientation.HORIZONTAL, spinnerStyle);
    blueSpinner.setMinimum(0.0);
    blueSpinner.setMaximum(255.0);
    blueSpinner.getTextField().addListener(main.getIbeamListener());
    blueSpinner.getButtonMinus().addListener(main.getHandListener());
    blueSpinner.getButtonPlus().addListener(main.getHandListener());

    alphaSpinner = new Spinner(selectedColor.a * 255.0f, 1.0, true, Orientation.HORIZONTAL, spinnerStyle);
    alphaSpinner.setMinimum(0.0);
    alphaSpinner.setMaximum(255.0);
    alphaSpinner.getTextField().addListener(main.getIbeamListener());
    alphaSpinner.getButtonMinus().addListener(main.getHandListener());
    alphaSpinner.getButtonPlus().addListener(main.getHandListener());

    redSpinner.setTransversalNext(greenSpinner.getTextField());
    greenSpinner.setTransversalNext(blueSpinner.getTextField());
    blueSpinner.setTransversalNext(alphaSpinner.getTextField());
    alphaSpinner.setTransversalNext(hueSpinner.getTextField());
    hueSpinner.setTransversalNext(saturationSpinner.getTextField());
    saturationSpinner.setTransversalNext(brightnessSpinner.getTextField());
    brightnessSpinner.setTransversalNext(redSpinner.getTextField());

    redSpinner.setTransversalPrevious(brightnessSpinner.getTextField());
    greenSpinner.setTransversalPrevious(redSpinner.getTextField());
    blueSpinner.setTransversalPrevious(greenSpinner.getTextField());
    alphaSpinner.setTransversalPrevious(blueSpinner.getTextField());
    hueSpinner.setTransversalPrevious(alphaSpinner.getTextField());
    saturationSpinner.setTransversalPrevious(hueSpinner.getTextField());
    brightnessSpinner.setTransversalPrevious(saturationSpinner.getTextField());

    ChangeListener rgbListener = new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            selectedColor.set((float) redSpinner.getValue() / 255.0f, (float) greenSpinner.getValue() / 255.0f,
                    (float) blueSpinner.getValue() / 255.0f, (float) alphaSpinner.getValue() / 255.0f);
            Vector3 v = rgbToHsb(selectedColor.r, selectedColor.g, selectedColor.b);
            hueSpinner.setValue(v.x * 359.0f);
            saturationSpinner.setValue(v.y * 100.0f);
            brightnessSpinner.setValue(v.z * 100.0f);
            selectedColorCont.setColor(selectedColor);

            Color color = hsbToRgb((float) hueSpinner.getValue(), 1.0f, 1.0f);
            gradientS.setCol2(color);
            gradientS.setCol3(color);
            gradientAlpha.setCol3(color);
            gradientAlpha.setCol4(color);
            color = new Color(color);
            color.a = 0.0f;
            gradientAlpha.setCol1(color);
            gradientAlpha.setCol2(color);

            cursor.setX(v.y * SIZE - cursor.getWidth() / 2.0f);
            cursor.setY(v.z * SIZE - cursor.getHeight() / 2.0f);
            hueKnob.setY(v.x * SIZE - hueKnob.getHeight() / 2.0f);
            hueKnob2.setY(hueKnob.getY());
        }
    };
    redSpinner.addListener(rgbListener);
    greenSpinner.addListener(rgbListener);
    blueSpinner.addListener(rgbListener);

    ChangeListener hsbListener = new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            Color color = hsbToRgb((float) hueSpinner.getValue(), (float) saturationSpinner.getValue() / 100.0f,
                    (float) brightnessSpinner.getValue() / 100.0f);
            color.a = (float) alphaSpinner.getValue() / 255.0f;
            redSpinner.setValue(color.r * 255.0f);
            greenSpinner.setValue(color.g * 255.0f);
            blueSpinner.setValue(color.b * 255.0f);
            selectedColor.set(color);
            selectedColorCont.setColor(selectedColor);

            color = hsbToRgb((float) hueSpinner.getValue(), 1.0f, 1.0f);
            gradientS.setCol2(color);
            gradientS.setCol3(color);
            gradientAlpha.setCol3(color);
            gradientAlpha.setCol4(color);
            color = new Color(color);
            color.a = 0.0f;
            gradientAlpha.setCol1(color);
            gradientAlpha.setCol2(color);

            cursor.setX((float) saturationSpinner.getValue() / 100.0f * SIZE - cursor.getWidth() / 2.0f);
            cursor.setY((float) brightnessSpinner.getValue() / 100.0f * SIZE - cursor.getHeight() / 2.0f);
            hueKnob.setY((float) hueSpinner.getValue() / 359.0f * SIZE - hueKnob.getHeight() / 2.0f);
            hueKnob2.setY(hueKnob.getY());
        }
    };
    hueSpinner.addListener(hsbListener);
    saturationSpinner.addListener(hsbListener);
    brightnessSpinner.addListener(hsbListener);

    alphaSpinner.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            selectedColor.set((float) redSpinner.getValue() / 255.0f, (float) greenSpinner.getValue() / 255.0f,
                    (float) blueSpinner.getValue() / 255.0f, (float) alphaSpinner.getValue() / 255.0f);
            selectedColorCont.setColor(selectedColor);

            alphaKnob.setY(selectedColor.a * SIZE - alphaKnob.getHeight() / 2.0f);
            alphaKnob2.setY(alphaKnob.getY());
        }
    });

    Table panel = new Table(skin);
    panel.setBackground("color-box");
    Table t = new Table(skin);
    t.setClip(true);
    t.setBackground(gradientSB);
    t.setTouchable(Touchable.enabled);
    cursor.setPosition(v.y * SIZE - cursor.getWidth() / 2.0f, v.z * SIZE - cursor.getHeight() / 2.0f);
    t.addActor(cursor);
    DragListener dragListener = new DragListener() {
        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            saturationSpinner.setValue(MathUtils.clamp(x / SIZE * 100.0f, 0, 100));
            brightnessSpinner.setValue(MathUtils.clamp(y / SIZE * 100.0f, 0, 100));
            saturationSpinner.fire(new ChangeListener.ChangeEvent());
        }
    };
    dragListener.setTapSquareSize(1.0f);
    t.addListener(dragListener);

    t.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            saturationSpinner.setValue(MathUtils.clamp(x / SIZE * 100.0f, 0, 100));
            brightnessSpinner.setValue(MathUtils.clamp(y / SIZE * 100.0f, 0, 100));
            saturationSpinner.fire(new ChangeListener.ChangeEvent());

            return false;
        }
    });
    panel.add(t).size(SIZE, SIZE);
    content.add(panel);

    panel = new Table(skin);
    panel.setBackground("color-box");
    t = new Table(skin);
    t.setTouchable(Touchable.enabled);
    t.setClip(true);
    for (GradientDrawable gradient : hueGradient) {
        Container container = new Container();
        container.background(gradient);
        t.add(container).growX().height(50.0f);
        t.row();
    }
    t.addActor(hueKnob);
    t.addActor(hueKnob2);
    hueKnob.setY(v.x * SIZE - hueKnob.getHeight() / 2.0f);
    hueKnob2.setX(30.0f - hueKnob2.getWidth());
    hueKnob2.setY(v.x * SIZE - hueKnob2.getHeight() / 2.0f);
    dragListener = new DragListener() {
        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            hueSpinner.setValue(MathUtils.clamp(y / SIZE * 359.0f, 0.0f, 359.0f));

            hueSpinner.fire(new ChangeListener.ChangeEvent());
        }
    };
    dragListener.setTapSquareSize(1.0f);
    t.addListener(dragListener);
    t.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            hueSpinner.setValue(MathUtils.clamp(y / SIZE * 359.0f, 0.0f, 359.0f));

            hueSpinner.fire(new ChangeListener.ChangeEvent());
            return false;
        }

    });
    panel.add(t).minWidth(30.0f).height(SIZE);
    content.add(panel);

    panel = new Table(skin);
    panel.setBackground("color-box");
    t = new Table();
    t.setTouchable(Touchable.enabled);
    t.setBackground(alphaStack);
    t.setClip(true);
    t.addActor(alphaKnob);
    t.addActor(alphaKnob2);
    alphaKnob.setY(selectedColor.a * SIZE - alphaKnob.getHeight() / 2.0f);
    alphaKnob2.setX(30.0f - alphaKnob2.getWidth());
    alphaKnob2.setY(selectedColor.a * SIZE - alphaKnob2.getHeight() / 2.0f);
    dragListener = new DragListener() {
        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            alphaSpinner.setValue(MathUtils.clamp(y / SIZE * 255.0f, 0.0f, 255.0f));

            alphaSpinner.fire(new ChangeListener.ChangeEvent());
        }
    };
    dragListener.setTapSquareSize(1.0f);
    t.addListener(dragListener);
    t.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            alphaSpinner.setValue(MathUtils.clamp(y / SIZE * 255.0f, 0.0f, 255.0f));

            alphaSpinner.fire(new ChangeListener.ChangeEvent());
            return false;
        }

    });
    panel.add(t).minWidth(30.0f).height(SIZE);
    content.add(panel);

    t = new Table();
    t.defaults().pad(10.0f);

    Table table = new Table(skin);
    Label label = new Label("new", skin);
    label.setAlignment(Align.center);
    table.add(label).growX();
    table.row();
    Container bg = new Container();
    bg.setBackground(checker);
    Stack stack = new Stack(bg, selectedColorCont);
    panel = new Table(skin);
    panel.setBackground("color-box");
    panel.add(stack).grow();
    table.add(panel).grow();
    if (previousColor != null) {
        Container cont = new Container();
        cont.setBackground(skin.getDrawable("white"));
        cont.setColor(previousColor);
        bg = new Container();
        bg.setBackground(checker);
        stack = new Stack(bg, cont);
        panel.row();
        panel.add(stack).grow();
        table.row();
        label = new Label("current", skin);
        label.setAlignment(Align.center);
        table.add(label).growX();
        t.add(table).minWidth(80.0f).minHeight(150.0f);
    } else {
        t.add(table).minWidth(80.0f).minHeight(100.0f);
    }

    table = new Table();
    TextButton textButton = new TextButton("OK", skin);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            if (listener != null) {
                listener.handle(new ColorListener.ColorEvent(selectedColor));
            }
            hide();
        }
    });
    table.add(textButton).growX();
    table.row();
    textButton = new TextButton("Cancel", skin);
    textButton.addListener(main.getHandListener());
    textButton.addListener(new ChangeListener() {
        @Override
        public void changed(ChangeListener.ChangeEvent event, Actor actor) {
            if (listener != null) {
                listener.handle(new ColorListener.ColorEvent(null));
            }
            hide();
        }
    });
    table.add(textButton).growX().padTop(10.0f);
    t.add(table);

    t.row();
    table = new Table();
    label = new Label("R", skin, "required");
    table.add(label);
    table.add(redSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);

    table = new Table();
    label = new Label("H", skin, "required");
    table.add(label);
    table.add(hueSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);

    t.row();
    table = new Table();
    label = new Label("G", skin, "required");
    table.add(label);
    table.add(greenSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);

    table = new Table();
    label = new Label("S", skin, "required");
    table.add(label);
    table.add(saturationSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);

    t.row();
    table = new Table();
    label = new Label("B", skin, "required");
    table.add(label);
    table.add(blueSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);

    table = new Table();
    label = new Label("B", skin, "required");
    table.add(label);
    table.add(brightnessSpinner).padLeft(10.0f).minWidth(90.0f);
    t.add(table);

    t.row();
    table = new Table();
    label = new Label("A", skin, "required");
    table.add(label);
    t.add(table);
    table.add(alphaSpinner).padLeft(10.0f).minWidth(90.0f);
    content.add(t).growY();
}

From source file:com.ray3k.skincomposer.dialog.DialogDrawables.java

License:Open Source License

private void refreshDrawableDisplay() {
    contentGroup.clear();/*from w w  w .  j  a v a2  s .c  o  m*/

    TooltipManager manager = new TooltipManager();
    manager.animations = false;
    manager.initialTime = .4f;
    manager.resetTime = 0.0f;
    manager.subsequentTime = 0.0f;
    manager.hideAll();
    manager.instant();

    if (drawables.size == 0) {
        Label label = new Label("No drawables have been added!", getSkin());
        contentGroup.addActor(label);
    }

    for (DrawableData drawable : drawables) {
        Button drawableButton;

        if (property != null) {
            drawableButton = new Button(getSkin(), "color-base");
            drawableButton.addListener(new ChangeListener() {
                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    result(drawable);
                    hide();
                }
            });
            drawableButton.addListener(main.getHandListener());
        } else {
            drawableButton = new Button(getSkin(), "color-base-static");
        }
        contentGroup.addActor(drawableButton);

        Table table = new Table();
        drawableButton.add(table).width(sizes[MathUtils.floor(zoomSlider.getValue())])
                .height(sizes[MathUtils.floor(zoomSlider.getValue())]);

        ClickListener fixDuplicateTouchListener = new ClickListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                event.setBubbles(false);
                return super.touchDown(event, x, y, pointer, button);
            }
        };

        //color wheel
        Button button = new Button(getSkin(), "colorwheel");
        button.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                newTintedDrawable(drawable);
                event.setBubbles(false);
            }
        });
        button.addListener(fixDuplicateTouchListener);
        if (property == null) {
            button.addListener(main.getHandListener());
        }
        table.add(button);

        //swatches
        button = new Button(getSkin(), "swatches");
        button.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                colorSwatchesDialog(drawable);
                event.setBubbles(false);
            }
        });
        button.addListener(fixDuplicateTouchListener);
        if (property == null) {
            button.addListener(main.getHandListener());
        }
        table.add(button);

        //rename (ONLY FOR TINTS)
        if (drawable.tint != null || drawable.tintName != null) {
            button = new Button(getSkin(), "settings-small");
            button.addListener(new ChangeListener() {
                @Override
                public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                    renameDrawableDialog(drawable);
                    event.setBubbles(false);
                }
            });
            button.addListener(fixDuplicateTouchListener);
            if (property == null) {
                button.addListener(main.getHandListener());
            }
            table.add(button);
        } else {
            table.add();
        }

        //delete
        button = new Button(getSkin(), "delete-small");
        button.addListener(new ChangeListener() {
            @Override
            public void changed(ChangeListener.ChangeEvent event, Actor actor) {
                deleteDrawable(drawable);
                event.setBubbles(false);
            }
        });
        button.addListener(fixDuplicateTouchListener);
        if (property == null) {
            button.addListener(main.getHandListener());
        }
        table.add(button).expandX().right();

        //preview
        table.row();
        Container bg = new Container();
        bg.setClip(true);
        bg.setBackground(getSkin().getDrawable("white"));
        bg.setColor(drawable.bgColor);
        Image image = new Image(drawablePairs.get(drawable));
        if (MathUtils.isZero(zoomSlider.getValue())) {
            image.setScaling(Scaling.fit);
            bg.fill(false);
        } else {
            image.setScaling(Scaling.stretch);
            bg.fill();
        }
        bg.setActor(image);
        table.add(bg).colspan(4).grow();

        //name
        table.row();
        Label label = new Label(drawable.name, getSkin());
        label.setEllipsis("...");
        label.setEllipsis(true);
        label.setAlignment(Align.center);
        table.add(label).colspan(4).growX().width(sizes[MathUtils.floor(zoomSlider.getValue())]);

        //Tooltip
        TextTooltip toolTip = new TextTooltip(drawable.name, manager, getSkin());
        label.addListener(toolTip);
    }
}

From source file:com.vlaaad.dice.ui.windows.DieSettingsWindow.java

License:Open Source License

@Override
protected void doShow(final Params params) {
    Table content = new Table(Config.skin);
    content.setBackground("ui-store-window-background");
    content.defaults().pad(4);//w ww  . j  a  v a  2 s. c om
    content.setTouchable(Touchable.enabled);

    final LocLabel infoLabel = new LocLabel(
            "ui-renames-left", Thesaurus.params().with("count", String.valueOf(params.die.renames))
                    .with("free-renames", "free-renames." + Thesaurus.Util.countForm(params.die.renames)),
            StoreWindow.INACTIVE);
    infoLabel.setWrap(true);
    infoLabel.setAlignment(Align.center);

    final StringSpin nameSpin = new StringSpin(4, 10, Config.thesaurus.localize(params.die.nameLocKey()));
    Container inner = new Container(nameSpin);
    inner.padTop(3);
    final Container nameContainer = new Container(inner);
    nameContainer.setBackground(Config.skin.getDrawable("ui/button/name-change-background"));
    final Button changeNameButton = new Button(Config.skin);
    final Thesaurus thesaurus = Config.assetManager.get("names.yml", Thesaurus.class);
    final Array<ThesaurusData> values = thesaurus.values();
    final Item coin = Config.items.get("coin");
    updateChangeNameButton(changeNameButton, params);
    changeNameButton.addListener(new ChangeListener() {
        @SuppressWarnings("unchecked")
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            ObjectSet<ThesaurusData> existingNames = Pools.obtain(ObjectSet.class);
            for (Die die : params.userData.dice()) {
                existingNames.add(thesaurus.getData(die.name.toLowerCase()));
            }
            ThesaurusData newName = values.random();
            while (existingNames.contains(newName)) {
                newName = values.random();
            }
            existingNames.clear();
            Pools.free(existingNames);
            final ThesaurusData chosenName = newName;
            changeNameButton.setDisabled(true);
            nameSpin.setText(Config.thesaurus.localize(newName.key), new Runnable() {
                @Override
                public void run() {
                    params.die.name = chosenName.key;
                    if (params.die.renames > 0) {
                        params.die.renames -= 1;
                        infoLabel.setParams(Thesaurus.params().with("count", String.valueOf(params.die.renames))
                                .with("free-renames",
                                        "free-renames." + Thesaurus.Util.countForm(params.die.renames)));
                    } else {
                        params.userData.incrementItemCount(coin, -1);
                    }
                    updateChangeNameButton(changeNameButton, params);
                    fire(RefreshEvent.INSTANCE);
                }
            });
        }
    });

    content.add(new LocLabel("ui-select-die-name")).row();
    content.add(new Tile("ui-creature-info-line")).width(80).padTop(0).row();
    content.add(nameContainer).size(70, 21).row();
    content.add(changeNameButton).size(100, 21).padBottom(0).row();
    content.add(infoLabel).width(110).row();

    table.add(content);
}

From source file:de.bitbrain.craft.ui.widgets.TabWidget.java

License:Open Source License

private void generateLeft() {
    Container<Actor> c = new Container<Actor>();
    c.setBackground(new NinePatchDrawable(
            GraphicsFactory.createNinePatch(Assets.TEX_PANEL_9patch, Sizes.panelRadius())));
    left = add(c);//from   w w w . j  av  a  2 s  .  co  m

}

From source file:es.eucm.ead.editor.view.widgets.TextEditor.java

License:Open Source License

public TextEditor(Skin skin, TextEditorStyle style, I18N i18n, Preferences prefs) {

    float pad = WidgetBuilder.dpToPixels(8);
    pad(pad);//  w  w w .  j a v a2  s. c om

    setBackground(style.background);

    this.i18n = i18n;

    final IconButton editLabel = new IconButton(SkinConstants.IC_EDIT, skin);
    text = " ";
    label = new Label(text, skin, SkinConstants.STYLE_TOOLBAR);
    label.setEllipsis(true);
    Container<Label> textContainer = new Container<Label>();
    Color color = skin.getColor(SkinConstants.COLOR_SEMI_BLACK);
    textContainer.setBackground(skin.getDrawable(SkinConstants.DRAWABLE_TEXT_FIELD));
    textContainer.setColor(color);
    textContainer.setActor(label);
    textContainer.fillX().width(0);

    colorPicker = new ColorPickerPanel(skin, style.colorPickerStyle, prefs);
    colorPicker.addListener(new ColorListener() {
        @Override
        public void colorChanged(ColorEvent event) {
            label.setColor(event.getColor());
        }
    });

    top = new Table();
    top.add(editLabel).pad(pad);
    top.add(textContainer).pad(pad).expandX().fillX();

    selectTypo = new SelectBox<String>(skin);
    selectTypo.getSelection().setProgrammaticChangeEvents(false);
    Array<String> typo = new Array<String>();
    typo.add("roboto");
    typo.add("comfortaa");
    typo.add("rabanera");
    selectTypo.setItems(typo);

    selectSize = new SelectBox<String>(skin);
    selectSize.getSelection().setProgrammaticChangeEvents(false);
    Array<String> size = new Array<String>();
    size.add(i18n.m("small"));
    size.add(i18n.m("big"));
    selectSize.setItems(size);

    LinearLayout fontOptions = new LinearLayout(true);
    fontOptions.add(selectTypo).marginRight(pad);
    fontOptions.add(selectSize).marginRight(pad);

    add(top).expandX().fillX();
    row();
    add(fontOptions).padBottom(pad);
    row();
    add(colorPicker).padBottom(pad);
    colorPicker.completeRowsIfPossible(this);
}

From source file:gaia.cu9.ari.gaiaorbit.interfce.AboutWindow.java

License:Open Source License

public AboutWindow(Stage stg, Skin sk) {
    super(txt("gui.help.help") + " - " + GlobalConf.APPLICATION_NAME + " v" + GlobalConf.version.version, sk);

    this.stage = stg;
    this.skin = sk;
    this.me = this;
    this.linkStyle = skin.get("link", LabelStyle.class);

    float tawidth = 440 * GlobalConf.SCALE_FACTOR;
    float taheight = 250 * GlobalConf.SCALE_FACTOR;
    float taheight_s = 60 * GlobalConf.SCALE_FACTOR;
    float tabwidth = 60 * GlobalConf.SCALE_FACTOR;
    float pad = 5 * GlobalConf.SCALE_FACTOR;

    scrolls = new ArrayList<OwnScrollPane>(5);
    textareas = new ArrayList<Actor>();

    /** TABLE and SCROLL **/
    table = new Table(skin);

    // Create the tab buttons
    HorizontalGroup group = new HorizontalGroup();
    group.align(Align.left);//  www  .  j a va 2  s. c  o m

    final Button tab1 = new OwnTextButton(txt("gui.help.help"), skin, "toggle-big");
    tab1.pad(pad);
    tab1.setWidth(tabwidth);
    final Button tab2 = new OwnTextButton(txt("gui.help.about"), skin, "toggle-big");
    tab2.pad(pad);
    tab2.setWidth(tabwidth);
    final Button tab3 = new OwnTextButton(txt("gui.help.system"), skin, "toggle-big");
    tab3.pad(pad);
    tab3.setWidth(tabwidth);

    group.addActor(tab1);
    group.addActor(tab2);
    group.addActor(tab3);
    table.add(group).align(Align.left).padLeft(pad);
    table.row();

    // Create the tab content. Just using images here for simplicity.
    Stack content = new Stack();

    /** CONTENT 1 - HELP **/
    final Table content1 = new Table(skin);
    content1.align(Align.top);
    Image gaiasky = new Image(getSpriteDrawable(Gdx.files.internal("img/gaiaskylogo.png")));

    // User manual
    Label usermantitle = new OwnLabel(txt("gui.help.usermanual"), skin, "ui-12");
    Label usermantxt = new OwnLabel(txt("gui.help.help1"), skin, "ui-11");
    Link usermanlink = new Link(GlobalConf.WEBPAGE, linkStyle, GlobalConf.WEBPAGE);

    // Wiki
    Label wikititle = new OwnLabel("Docs", skin, "ui-12");
    Label wikitxt = new OwnLabel(txt("gui.help.help2"), skin, "ui-11");
    Link wikilink = new Link(GlobalConf.DOCUMENTATION, linkStyle, GlobalConf.DOCUMENTATION);

    // Readme
    Label readmetitle = new OwnLabel(txt("gui.help.readme"), skin, "ui-12");
    FileHandle readmefile = Gdx.files.internal("README.md");
    if (!readmefile.exists()) {
        readmefile = Gdx.files.internal("../README.md");
    }
    String readmestr = readmefile.readString();
    int lines = GlobalResources.countOccurrences(readmestr, '\n');
    TextArea readme = new TextArea(readmestr, skin);
    readme.setDisabled(true);
    readme.setPrefRows(lines);
    textareas.add(readme);

    OwnScrollPane readmescroll = new OwnScrollPane(readme, skin, "default-nobg");
    readmescroll.setWidth(tawidth);
    readmescroll.setHeight(taheight);
    readmescroll.setForceScroll(false, true);
    readmescroll.setSmoothScrolling(true);
    readmescroll.setFadeScrollBars(false);

    scrolls.add(readmescroll);

    // Add all to content
    content1.add(gaiasky).colspan(2);
    content1.row();
    content1.add(usermantitle).align(Align.left).padRight(pad * 2);
    content1.add(usermantxt).align(Align.left);
    content1.row();
    content1.add(new OwnLabel("", skin, "ui-11"));
    content1.add(usermanlink).align(Align.left);
    content1.row();
    content1.add(wikititle).align(Align.left).padRight(pad * 2);
    content1.add(wikitxt).align(Align.left);
    content1.row();
    content1.add(new OwnLabel("", skin, "ui-11"));
    content1.add(wikilink).align(Align.left);
    content1.row();
    content1.add(readmetitle).colspan(2).align(Align.left);
    content1.row();
    content1.add(readmescroll).colspan(2).expand().pad(pad * 2, 0, pad * 2, 0).align(Align.center);

    /** CONTENT 2 - ABOUT **/
    final Table content2 = new Table(skin);
    content2.align(Align.top);

    // Intro
    TextArea intro = new OwnTextArea(txt("gui.help.gscredits", GlobalConf.version.version),
            skin.get("msg-11", TextFieldStyle.class));
    intro.setDisabled(true);
    intro.setPrefRows(3);
    intro.setWidth(tawidth);
    textareas.add(intro);

    // Home page
    Label homepagetitle = new OwnLabel(txt("gui.help.homepage"), skin, "ui-12");
    Link homepage = new Link(GlobalConf.WEBPAGE, linkStyle, GlobalConf.WEBPAGE);

    // Author
    Label authortitle = new OwnLabel(txt("gui.help.author"), skin, "ui-12");

    VerticalGroup author = new VerticalGroup();
    author.align(Align.left);
    Label authorname = new OwnLabel("Toni Sagrist Sells", skin, "ui-11");
    Link authormail = new Link("tsagrista@ari.uni-heidelberg.de", linkStyle,
            "mailto:tsagrista@ari.uni-heidelberg.de");
    Link authorpage = new Link("www.tonisagrista.com", linkStyle, "http://tonisagrista.com");
    author.addActor(authorname);
    author.addActor(authormail);
    author.addActor(authorpage);

    // Contributor
    Label contribtitle = new OwnLabel(txt("gui.help.contributors"), skin, "ui-12");

    VerticalGroup contrib = new VerticalGroup();
    contrib.align(Align.left);
    Label contribname = new OwnLabel("Apl. Prof. Dr. Stefan Jordan", skin, "ui-11");
    Link contribmail = new Link("jordan@ari.uni-heidelberg.de", linkStyle,
            "mailto:jordan@ari.uni-heidelberg.de");
    contrib.addActor(contribname);
    contrib.addActor(contribmail);

    // License
    HorizontalGroup licenseh = new HorizontalGroup();
    licenseh.space(pad * 2);
    Image license = new Image(getSpriteDrawable(Gdx.files.internal("img/license.png")));

    VerticalGroup licensev = new VerticalGroup();
    TextArea licensetext = new OwnTextArea(txt("gui.help.license"), skin.get("msg-11", TextFieldStyle.class));
    licensetext.setDisabled(true);
    licensetext.setPrefRows(3);
    licensetext.setWidth(tawidth / 2f);
    Link licenselink = new Link("https://www.gnu.org/licenses/gpl.html", linkStyle,
            "https://www.gnu.org/licenses/gpl.html");

    licensev.addActor(licensetext);
    licensev.addActor(licenselink);

    licenseh.addActor(license);
    licenseh.addActor(licensev);

    // Thanks

    HorizontalGroup thanks = new HorizontalGroup();
    thanks.space(pad * 2);
    Container thanksc = new Container(thanks);
    thanksc.setBackground(skin.getDrawable("bg-clear"));

    Image zah = new Image(getSpriteDrawable(Gdx.files.internal("img/zah.png")));
    Image dlr = new Image(getSpriteDrawable(Gdx.files.internal("img/dlr.png")));
    Image bwt = new Image(getSpriteDrawable(Gdx.files.internal("img/bwt.png")));
    Image dpac = new Image(getSpriteDrawable(Gdx.files.internal("img/dpac.png")));

    thanks.addActor(zah);
    thanks.addActor(dlr);
    thanks.addActor(bwt);
    thanks.addActor(dpac);

    content2.add(intro).colspan(2).align(Align.left).padTop(pad * 2);
    content2.row();
    content2.add(homepagetitle).align(Align.topLeft).padRight(pad * 2);
    content2.add(homepage).align(Align.left);
    content2.row();
    content2.add(authortitle).align(Align.topLeft).padRight(pad * 2).padTop(pad);
    content2.add(author).align(Align.left).padTop(pad);
    content2.row();
    content2.add(contribtitle).align(Align.topLeft).padRight(pad * 2).padTop(pad);
    content2.add(contrib).align(Align.left).padTop(pad);
    content2.row();
    content2.add(licenseh).colspan(2).align(Align.center).padTop(pad * 4);
    content2.row();
    content2.add(thanksc).colspan(2).align(Align.center).padTop(pad * 8);

    /** CONTENT 3 - SYSTEM **/
    final Table content3 = new Table(skin);
    content3.align(Align.top);

    // Build info
    Label buildinfo = new OwnLabel(txt("gui.help.buildinfo"), skin, "help-title");

    Label versiontitle = new OwnLabel(txt("gui.help.version", GlobalConf.APPLICATION_NAME), skin, "ui-12");
    Label version = new OwnLabel(GlobalConf.version.version, skin, "ui-11");

    Label revisiontitle = new OwnLabel(txt("gui.help.buildnumber"), skin, "ui-12");
    Label revision = new OwnLabel(GlobalConf.version.build, skin, "ui-11");

    Label timetitle = new OwnLabel(txt("gui.help.buildtime"), skin, "ui-12");
    Label time = new OwnLabel(GlobalConf.version.buildtime, skin, "ui-11");

    Label systemtitle = new OwnLabel(txt("gui.help.buildsys"), skin, "ui-12");
    TextArea system = new OwnTextArea(GlobalConf.version.system, skin.get("msg-11", TextFieldStyle.class));
    system.setDisabled(true);
    system.setPrefRows(3);
    system.setWidth(tawidth * 2f / 3f);
    textareas.add(system);

    Label buildertitle = new OwnLabel(txt("gui.help.builder"), skin, "ui-12");
    Label builder = new OwnLabel(GlobalConf.version.builder, skin, "ui-11");

    // Java info
    Label javainfo = new OwnLabel(txt("gui.help.javainfo"), skin, "help-title");

    Label javaversiontitle = new OwnLabel(txt("gui.help.javaversion"), skin, "ui-12");
    Label javaversion = new OwnLabel(System.getProperty("java.version"), skin, "ui-11");

    Label javaruntimetitle = new OwnLabel(txt("gui.help.javaname"), skin, "ui-12");
    Label javaruntime = new OwnLabel(System.getProperty("java.runtime.name"), skin, "ui-11");

    Label javavmnametitle = new OwnLabel(txt("gui.help.javavmname"), skin, "ui-12");
    Label javavmname = new OwnLabel(System.getProperty("java.vm.name"), skin, "ui-11");

    Label javavmversiontitle = new OwnLabel(txt("gui.help.javavmversion"), skin, "ui-12");
    Label javavmversion = new OwnLabel(System.getProperty("java.vm.version"), skin, "ui-11");

    Label javavmvendortitle = new OwnLabel(txt("gui.help.javavmvendor"), skin, "ui-12");
    Label javavmvendor = new OwnLabel(System.getProperty("java.vm.vendor"), skin, "ui-11");

    TextButton memoryinfobutton = new OwnTextButton(txt("gui.help.meminfo"), skin, "default");
    memoryinfobutton.setName("memoryinfo");
    memoryinfobutton.setSize(150 * GlobalConf.SCALE_FACTOR, 20 * GlobalConf.SCALE_FACTOR);
    memoryinfobutton.addListener(new EventListener() {
        @Override
        public boolean handle(Event event) {
            if (event instanceof ChangeEvent) {
                EventManager.instance.post(Events.DISPLAY_MEM_INFO_WINDOW, stage, skin);
                return true;
            }

            return false;
        }

    });

    // OpenGL info
    Label glinfo = new OwnLabel(txt("gui.help.openglinfo"), skin, "help-title");

    Label glversiontitle = new OwnLabel(txt("gui.help.openglversion"), skin, "ui-12");
    Label glversion = new OwnLabel(Gdx.gl.glGetString(GL20.GL_VERSION), skin, "ui-11");

    Label glslversiontitle = new OwnLabel(txt("gui.help.glslversion"), skin, "ui-12");
    Label glslversion = new OwnLabel(Gdx.gl.glGetString(GL20.GL_SHADING_LANGUAGE_VERSION), skin, "ui-11");

    Label glextensionstitle = new OwnLabel(txt("gui.help.glextensions"), skin, "ui-12");
    String glextensionsstr = Gdx.gl.glGetString(GL20.GL_EXTENSIONS).replace(' ', '\r');
    lines = GlobalResources.countOccurrences(glextensionsstr, '\r') + 1;
    IntBuffer buf = BufferUtils.newIntBuffer(16);
    Gdx.gl.glGetIntegerv(Gdx.graphics.getGL20().GL_MAX_TEXTURE_SIZE, buf);
    int maxSize = buf.get(0);
    TextArea glextensions = new TextArea("Max texture size: " + maxSize + "\r" + glextensionsstr, skin);
    glextensions.setDisabled(true);
    glextensions.setPrefRows(lines);

    textareas.add(glextensions);

    OwnScrollPane glextensionsscroll = new OwnScrollPane(glextensions, skin, "default-nobg");
    glextensionsscroll.setWidth(tawidth / 1.7f);
    glextensionsscroll.setHeight(taheight_s);
    glextensionsscroll.setForceScroll(false, true);
    glextensionsscroll.setSmoothScrolling(true);
    glextensionsscroll.setFadeScrollBars(false);
    scrolls.add(glextensionsscroll);

    content3.add(buildinfo).colspan(2).align(Align.left).padTop(pad * 3);
    content3.row();
    content3.add(versiontitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(version).align(Align.left);
    content3.row();
    content3.add(revisiontitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(revision).align(Align.left);
    content3.row();
    content3.add(timetitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(time).align(Align.left);
    content3.row();
    content3.add(buildertitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(builder).align(Align.left).padBottom(pad * 3);
    content3.row();
    content3.add(systemtitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(system).align(Align.left);
    content3.row();

    content3.add(javainfo).colspan(2).align(Align.left).padTop(pad * 2);
    content3.row();
    content3.add(javaversiontitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(javaversion).align(Align.left);
    content3.row();
    content3.add(javaruntimetitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(javaruntime).align(Align.left);
    content3.row();
    content3.add(javavmnametitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(javavmname).align(Align.left);
    content3.row();
    content3.add(javavmversiontitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(javavmversion).align(Align.left);
    content3.row();
    content3.add(javavmvendortitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(javavmvendor).align(Align.left).padBottom(pad * 2);
    content3.row();
    content3.add(memoryinfobutton).colspan(2).align(Align.left).padBottom(pad * 3);
    content3.row();
    content3.add(glinfo).colspan(2).align(Align.left).padTop(pad * 2);
    content3.row();
    content3.add(glversiontitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(glversion).align(Align.left);
    content3.row();
    content3.add(glslversiontitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(glslversion).align(Align.left);
    content3.row();
    content3.add(glextensionstitle).align(Align.topLeft).padRight(pad * 2);
    content3.add(glextensionsscroll).align(Align.left);

    /** ADD ALL CONTENT **/
    content.addActor(content1);
    content.addActor(content2);
    content.addActor(content3);

    table.add(content).expand().fill();

    // Listen to changes in the tab button checked states
    // Set visibility of the tab content to match the checked state
    ChangeListener tab_listener = new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            content1.setVisible(tab1.isChecked());
            content2.setVisible(tab2.isChecked());
            content3.setVisible(tab3.isChecked());
        }
    };
    tab1.addListener(tab_listener);
    tab2.addListener(tab_listener);
    tab3.addListener(tab_listener);

    // Let only one tab button be checked at a time
    ButtonGroup tabs = new ButtonGroup();
    tabs.setMinCheckCount(1);
    tabs.setMaxCheckCount(1);
    tabs.add(tab1);
    tabs.add(tab2);
    tabs.add(tab3);

    /** BUTTONS **/
    HorizontalGroup buttonGroup = new HorizontalGroup();
    TextButton close = new OwnTextButton(txt("gui.close"), skin, "default");
    close.setName("close");
    close.setSize(70 * GlobalConf.SCALE_FACTOR, 20 * GlobalConf.SCALE_FACTOR);
    close.addListener(new EventListener() {
        @Override
        public boolean handle(Event event) {
            if (event instanceof ChangeEvent) {
                me.hide();
                return true;
            }

            return false;
        }

    });
    buttonGroup.addActor(close);

    add(table).pad(pad);
    row();
    add(buttonGroup).pad(pad).bottom().right();
    getTitleTable().align(Align.left);

    pack();

    this.setPosition(Math.round(stage.getWidth() / 2f - this.getWidth() / 2f),
            Math.round(stage.getHeight() / 2f - this.getHeight() / 2f));

    /** CAPTURE SCROLL FOCUS **/
    stage.addListener(new EventListener() {

        @Override
        public boolean handle(Event event) {
            if (event instanceof InputEvent) {
                InputEvent ie = (InputEvent) event;

                if (ie.getType() == Type.mouseMoved) {
                    for (OwnScrollPane scroll : scrolls) {
                        if (ie.getTarget().isDescendantOf(scroll)) {
                            stage.setScrollFocus(scroll);
                        }
                    }
                    return true;
                }
            }
            return false;
        }
    });

}