Search in sources :

Example 1 with OwnTextButton

use of gaiasky.util.scene2d.OwnTextButton in project gaiasky by langurmonkey.

the class TipGenerator method addTip.

private void addTip(WidgetGroup g, String[] tip) {
    float pad5 = 8f;
    float pad2 = 3.2f;
    g.clear();
    for (String part : tip) {
        boolean def = true;
        String style = "main-title-s";
        String text = part;
        if (part.startsWith("%%")) {
            int idx = text.indexOf(" ");
            text = part.substring(idx + 1);
            style = part.substring(2, idx);
            def = false;
        }
        if (skin.has(style, Label.LabelStyle.class)) {
            OwnLabel label = new OwnLabel(text, skin, style);
            if (def) {
                label.setColor(0.5f, 0.5f, 0.5f, 1f);
                g.addActor(label);
            }
            g.addActor(label);
        } else if (skin.has(style, TextButton.TextButtonStyle.class)) {
            String[] keys = text.split("\\+");
            int n = keys.length;
            for (int i = 0; i < n; i++) {
                OwnTextButton button = new OwnTextButton(keys[i], skin, style);
                button.pad(pad2, pad5, pad2, pad5);
                g.addActor(button);
                if (i < n - 1) {
                    OwnLabel plus = new OwnLabel("+", skin, "main-title-s");
                    plus.setColor(0.5f, 0.5f, 0.5f, 1f);
                    g.addActor(plus);
                }
            }
        }
    }
}
Also used : OwnTextButton(gaiasky.util.scene2d.OwnTextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) OwnLabel(gaiasky.util.scene2d.OwnLabel) OwnLabel(gaiasky.util.scene2d.OwnLabel)

Example 2 with OwnTextButton

use of gaiasky.util.scene2d.OwnTextButton in project gaiasky by langurmonkey.

the class GuiRegistry method notify.

@Override
public void notify(final Event event, Object source, final Object... data) {
    if (current != null) {
        Stage ui = current.getGuiStage();
        // Treats windows that can appear in any GUI
        switch(event) {
            case SHOW_SEARCH_ACTION:
                if (searchDialog == null) {
                    searchDialog = new SearchDialog(skin, ui, sceneGraph, true);
                } else {
                    searchDialog.clearText();
                }
                if (!searchDialog.isVisible() | !searchDialog.hasParent())
                    searchDialog.show(ui);
                break;
            case SHOW_QUIT_ACTION:
                if (!removeModeChangePopup() && !removeControllerGui()) {
                    if (GLFW.glfwGetInputMode(((Lwjgl3Graphics) Gdx.graphics).getWindow().getWindowHandle(), GLFW.GLFW_CURSOR) == GLFW.GLFW_CURSOR_DISABLED) {
                        // Release mouse if captured
                        GLFW.glfwSetInputMode(((Lwjgl3Graphics) Gdx.graphics).getWindow().getWindowHandle(), GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
                    } else {
                        Runnable quitRunnable = data.length > 0 ? (Runnable) data[0] : null;
                        if (Settings.settings.program.exitConfirmation) {
                            QuitWindow quit = new QuitWindow(ui, skin);
                            if (data.length > 0) {
                                quit.setAcceptRunnable(quitRunnable);
                            }
                            quit.show(ui);
                        } else {
                            if (quitRunnable != null)
                                quitRunnable.run();
                            GaiaSky.postRunnable(() -> Gdx.app.exit());
                        }
                    }
                }
                break;
            case CAMERA_MODE_CMD:
                removeModeChangePopup();
                break;
            case SHOW_ABOUT_ACTION:
                if (aboutWindow == null)
                    aboutWindow = new AboutWindow(ui, skin);
                if (!aboutWindow.isVisible() || !aboutWindow.hasParent())
                    aboutWindow.show(ui);
                break;
            case SHOW_PREFERENCES_ACTION:
                Array<Actor> prefs = getElementsOfType(PreferencesWindow.class);
                if (prefs.isEmpty()) {
                    if (preferencesWindow == null) {
                        preferencesWindow = new PreferencesWindow(ui, skin, GaiaSky.instance.getGlobalResources());
                    }
                    if (!preferencesWindow.isVisible() || !preferencesWindow.hasParent())
                        preferencesWindow.show(ui);
                } else {
                    // Close current windows
                    for (Actor pref : prefs) {
                        if (pref instanceof PreferencesWindow) {
                            ((PreferencesWindow) pref).cancel();
                            ((PreferencesWindow) pref).hide();
                        }
                    }
                }
                break;
            case SHOW_PER_OBJECT_VISIBILITY_ACTION:
                if (indVisWindow == null) {
                    final ISceneGraph sg = GaiaSky.instance.sceneGraph;
                    indVisWindow = new IndividualVisibilityWindow(sg, ui, skin);
                }
                if (!indVisWindow.isVisible() || !indVisWindow.hasParent())
                    indVisWindow.show(ui);
                break;
            case SHOW_SLAVE_CONFIG_ACTION:
                if (MasterManager.hasSlaves()) {
                    if (slaveConfigWindow == null)
                        slaveConfigWindow = new SlaveConfigWindow(ui, skin);
                    if (!slaveConfigWindow.isVisible() || !slaveConfigWindow.hasParent())
                        slaveConfigWindow.show(ui);
                }
                break;
            case SHOW_LOAD_CATALOG_ACTION:
                if (lastOpenLocation == null && Settings.settings.program.fileChooser.lastLocation != null && !Settings.settings.program.fileChooser.lastLocation.isEmpty()) {
                    try {
                        lastOpenLocation = Paths.get(Settings.settings.program.fileChooser.lastLocation);
                    } catch (Exception e) {
                        lastOpenLocation = null;
                    }
                }
                if (lastOpenLocation == null) {
                    lastOpenLocation = SysUtils.getUserHome();
                } else if (!Files.exists(lastOpenLocation) || !Files.isDirectory(lastOpenLocation)) {
                    lastOpenLocation = SysUtils.getHomeDir();
                }
                FileChooser fc = new FileChooser(I18n.txt("gui.loadcatalog"), skin, ui, lastOpenLocation, FileChooser.FileChooserTarget.FILES);
                fc.setShowHidden(Settings.settings.program.fileChooser.showHidden);
                fc.setShowHiddenConsumer((showHidden) -> Settings.settings.program.fileChooser.showHidden = showHidden);
                fc.setAcceptText(I18n.txt("gui.loadcatalog"));
                fc.setFileFilter(pathname -> pathname.getFileName().toString().endsWith(".vot") || pathname.getFileName().toString().endsWith(".csv") || pathname.getFileName().toString().endsWith(".fits") || pathname.getFileName().toString().endsWith(".json"));
                fc.setAcceptedFiles("*.vot, *.csv, *.fits, *.json");
                fc.setResultListener((success, result) -> {
                    if (success) {
                        if (Files.exists(result) && Files.exists(result)) {
                            // Load selected file
                            try {
                                String fileName = result.getFileName().toString();
                                if (fileName.endsWith(".json")) {
                                    // Load internal JSON catalog file
                                    GaiaSky.instance.getExecutorService().execute(() -> {
                                        try {
                                            logger.info(I18n.txt("notif.catalog.loading", fileName));
                                            final Array<SceneGraphNode> objects = SceneGraphJsonLoader.loadJsonFile(Gdx.files.absolute(result.toAbsolutePath().toString()));
                                            logger.info(I18n.txt("notif.catalog.loaded", objects.size, I18n.txt("gui.objects")));
                                            GaiaSky.postRunnable(() -> {
                                                // THIS WILL BLOCK
                                                for (SceneGraphNode node : objects) {
                                                    node.initialize();
                                                }
                                                for (SceneGraphNode node : objects) {
                                                    EventManager.publish(Event.SCENE_GRAPH_ADD_OBJECT_NO_POST_CMD, this, node, true);
                                                }
                                                while (!GaiaSky.instance.assetManager.isFinished()) {
                                                    // Busy wait
                                                    try {
                                                        Thread.sleep(100);
                                                    } catch (InterruptedException e) {
                                                        logger.error(e);
                                                    }
                                                }
                                                for (SceneGraphNode node : objects) {
                                                    node.doneLoading(GaiaSky.instance.assetManager);
                                                }
                                                GaiaSky.postRunnable(GaiaSky.instance::touchSceneGraph);
                                            });
                                        } catch (Exception e) {
                                            logger.error(I18n.txt("notif.error", fileName), e);
                                        }
                                    });
                                } else {
                                    final DatasetLoadDialog dld = new DatasetLoadDialog(I18n.txt("gui.dsload.title") + ": " + fileName, fileName, skin, ui);
                                    Runnable doLoad = () -> {
                                        GaiaSky.instance.getExecutorService().execute(() -> {
                                            DatasetOptions datasetOptions = dld.generateDatasetOptions();
                                            // Load dataset
                                            GaiaSky.instance.scripting().loadDataset(datasetOptions.catalogName, result.toAbsolutePath().toString(), CatalogInfoSource.UI, datasetOptions, true);
                                            // Select first
                                            CatalogInfo ci = this.catalogManager.get(datasetOptions.catalogName);
                                            if (datasetOptions.type.isSelectable() && ci != null && ci.object != null) {
                                                if (ci.object instanceof ParticleGroup) {
                                                    ParticleGroup pg = (ParticleGroup) ci.object;
                                                    if (pg.data() != null && !pg.data().isEmpty() && pg.isVisibilityOn()) {
                                                        EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraManager.CameraMode.FOCUS_MODE);
                                                        EventManager.publish(Event.FOCUS_CHANGE_CMD, this, pg.getRandomParticleName());
                                                    }
                                                } else if (ci.object.children != null && !ci.object.children.isEmpty() && ci.object.children.get(0).isVisibilityOn()) {
                                                    EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraManager.CameraMode.FOCUS_MODE);
                                                    EventManager.publish(Event.FOCUS_CHANGE_CMD, this, ci.object.children.get(0));
                                                }
                                                // Open UI datasets
                                                GaiaSky.instance.scripting().maximizeInterfaceWindow();
                                                GaiaSky.instance.scripting().expandGuiComponent("DatasetsComponent");
                                            } else {
                                                logger.info("No data loaded (did the load crash?)");
                                            }
                                        });
                                    };
                                    dld.setAcceptRunnable(doLoad);
                                    dld.show(ui);
                                }
                                lastOpenLocation = result.getParent();
                                Settings.settings.program.fileChooser.lastLocation = lastOpenLocation.toAbsolutePath().toString();
                                return true;
                            } catch (Exception e) {
                                logger.error(I18n.txt("notif.error", result.getFileName()), e);
                                return false;
                            }
                        } else {
                            logger.error("Selection must be a file: " + result.toAbsolutePath());
                            return false;
                        }
                    } else {
                        // Still, update last location
                        if (!Files.isDirectory(result)) {
                            lastOpenLocation = result.getParent();
                        } else {
                            lastOpenLocation = result;
                        }
                        Settings.settings.program.fileChooser.lastLocation = lastOpenLocation.toAbsolutePath().toString();
                    }
                    return false;
                });
                fc.show(ui);
                break;
            case SHOW_KEYFRAMES_WINDOW_ACTION:
                if (keyframesWindow == null) {
                    keyframesWindow = new KeyframesWindow(ui, skin);
                }
                if (!keyframesWindow.isVisible() || !keyframesWindow.hasParent())
                    keyframesWindow.show(ui, 0, 0);
                break;
            case UI_THEME_RELOAD_INFO:
                if (keyframesWindow != null) {
                    keyframesWindow.dispose();
                    keyframesWindow = null;
                }
                this.skin = (Skin) data[0];
                break;
            case MODE_POPUP_CMD:
                if (Settings.settings.runtime.displayGui) {
                    ModePopupInfo mpi = (ModePopupInfo) data[0];
                    String name = (String) data[1];
                    if (mpi != null) {
                        // Add
                        Float seconds = (Float) data[2];
                        float pad10 = 16f;
                        float pad5 = 8f;
                        float pad3 = 4.8f;
                        if (modeChangeTable != null) {
                            modeChangeTable.remove();
                        }
                        modeChangeTable = new Table(skin);
                        modeChangeTable.setName("mct-" + name);
                        modeChangeTable.setBackground("table-bg");
                        modeChangeTable.pad(pad10);
                        // Fill up table
                        OwnLabel ttl = new OwnLabel(mpi.title, skin, "hud-header");
                        modeChangeTable.add(ttl).left().padBottom(pad10).row();
                        OwnLabel dsc = new OwnLabel(mpi.header, skin);
                        modeChangeTable.add(dsc).left().padBottom(pad5 * 3f).row();
                        Table keysTable = new Table(skin);
                        for (Pair<String[], String> m : mpi.mappings) {
                            HorizontalGroup keysGroup = new HorizontalGroup();
                            keysGroup.space(pad3);
                            String[] keys = m.getFirst();
                            String action = m.getSecond();
                            for (int i = 0; i < keys.length; i++) {
                                TextButton key = new TextButton(keys[i], skin, "key");
                                key.pad(0, pad3, 0, pad3);
                                key.pad(pad5);
                                keysGroup.addActor(key);
                                if (i < keys.length - 1) {
                                    keysGroup.addActor(new OwnLabel("+", skin));
                                }
                            }
                            keysTable.add(keysGroup).right().padBottom(pad5).padRight(pad10 * 2f);
                            keysTable.add(new OwnLabel(action, skin)).left().padBottom(pad5).row();
                        }
                        modeChangeTable.add(keysTable).center().row();
                        if (mpi.warn != null && !mpi.warn.isEmpty()) {
                            modeChangeTable.add(new OwnLabel(mpi.warn, skin, "mono-pink")).left().padTop(pad10).padBottom(pad5).row();
                        }
                        OwnTextButton closeButton = new OwnTextButton(I18n.txt("gui.ok") + " [esc]", skin);
                        closeButton.pad(pad3, pad10, pad3, pad10);
                        closeButton.addListener(event1 -> {
                            if (event1 instanceof ChangeEvent) {
                                removeModeChangePopup();
                                return true;
                            }
                            return false;
                        });
                        modeChangeTable.add(closeButton).right().padTop(pad10 * 2f);
                        modeChangeTable.pack();
                        // Add table to UI
                        Container mct = new Container<>(modeChangeTable);
                        mct.setFillParent(true);
                        mct.top();
                        mct.pad(pad10 * 2, 0, 0, 0);
                        ui.addActor(mct);
                        startModePopupInfoThread(modeChangeTable, seconds);
                    } else {
                        // Remove
                        if (modeChangeTable != null && modeChangeTable.hasParent() && modeChangeTable.getName().equals("mct-" + name)) {
                            modeChangeTable.remove();
                            modeChangeTable = null;
                        }
                    }
                }
                break;
            case DISPLAY_GUI_CMD:
                boolean displayGui = (Boolean) data[0];
                if (!displayGui) {
                    // Remove processor
                    inputMultiplexer.removeProcessor(current.getGuiStage());
                } else {
                    // Add processor
                    inputMultiplexer.addProcessor(0, current.getGuiStage());
                }
                break;
            case SHOW_RESTART_ACTION:
                String text;
                if (data.length > 0) {
                    text = (String) data[0];
                } else {
                    text = I18n.txt("gui.restart.default");
                }
                GenericDialog restart = new GenericDialog(I18n.txt("gui.restart.title"), skin, ui) {

                    @Override
                    protected void build() {
                        content.clear();
                        content.add(new OwnLabel(text, skin)).left().padBottom(pad10 * 2f).row();
                    }

                    @Override
                    protected void accept() {
                        // Shut down
                        GaiaSky.postRunnable(() -> {
                            Gdx.app.exit();
                            // Attempt restart
                            Path workingDir = Path.of(System.getProperty("user.dir"));
                            Path[] scripts;
                            if (SysUtils.isWindows()) {
                                scripts = new Path[] { workingDir.resolve("gaiasky.exe"), workingDir.resolve("gaiasky.bat"), workingDir.resolve("gradlew.bat") };
                            } else {
                                scripts = new Path[] { workingDir.resolve("gaiasky"), workingDir.resolve("gradlew") };
                            }
                            for (Path file : scripts) {
                                if (Files.exists(file) && Files.isRegularFile(file) && Files.isExecutable(file)) {
                                    try {
                                        if (file.getFileName().toString().contains("gaiasky")) {
                                            // Just use the script
                                            final ArrayList<String> command = new ArrayList<>();
                                            command.add(file.toString());
                                            final ProcessBuilder builder = new ProcessBuilder(command);
                                            builder.start();
                                        } else if (file.getFileName().toString().contains("gradlew")) {
                                            // Gradle script
                                            final ArrayList<String> command = new ArrayList<>();
                                            command.add(file.toString());
                                            command.add("core:run");
                                            final ProcessBuilder builder = new ProcessBuilder(command);
                                            builder.start();
                                        }
                                        break;
                                    } catch (IOException e) {
                                        logger.error(e, "Error running Gaia Sky");
                                    }
                                }
                            }
                        });
                    }

                    @Override
                    protected void cancel() {
                    // Nothing
                    }

                    @Override
                    public void dispose() {
                    // Nothing
                    }
                };
                restart.setAcceptText(I18n.txt("gui.yes"));
                restart.setCancelText(I18n.txt("gui.no"));
                restart.buildSuper();
                restart.show(ui);
                break;
            case UI_RELOAD_CMD:
                reloadUI((GlobalResources) data[0]);
                break;
            default:
                break;
        }
    }
}
Also used : OwnTextButton(gaiasky.util.scene2d.OwnTextButton) SceneGraphNode(gaiasky.scenegraph.SceneGraphNode) ArrayList(java.util.ArrayList) Lwjgl3Graphics(com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics) Actor(com.badlogic.gdx.scenes.scene2d.Actor) FileChooser(gaiasky.util.scene2d.FileChooser) Stage(com.badlogic.gdx.scenes.scene2d.Stage) DatasetOptions(gaiasky.data.group.DatasetOptions) OwnTextButton(gaiasky.util.scene2d.OwnTextButton) Path(java.nio.file.Path) ParticleGroup(gaiasky.scenegraph.ParticleGroup) IOException(java.io.IOException) IOException(java.io.IOException) ISceneGraph(gaiasky.scenegraph.ISceneGraph) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) OwnLabel(gaiasky.util.scene2d.OwnLabel)

Example 3 with OwnTextButton

use of gaiasky.util.scene2d.OwnTextButton in project gaiasky by langurmonkey.

the class SlaveConfigWindow method build.

@Override
protected void build() {
    FloatValidator angleVal = new FloatValidator(-1000f, 1000f);
    FloatValidator fovVal = new FloatValidator(Constants.MIN_FOV, 170f);
    float tw = 96f;
    // Send button (does not close dialog)
    OwnTextButton sendButton = new OwnTextButton(I18n.txt("gui.send"), skin, "default");
    sendButton.setName("send");
    sendButton.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            accept();
            return true;
        }
        return false;
    });
    buttonGroup.addActor(sendButton);
    recalculateButtonSize();
    // Get slaves
    List<String> slaves = MasterManager.instance.getSlaves();
    // Status
    slaveStatuses = new OwnLabel[slaves.size()];
    OwnLabel statusLabel = new OwnLabel(I18n.txt("gui.slave.config.status") + ":", skin);
    Table statusTable = new Table(skin);
    for (int i = 0; i < slaves.size(); i++) {
        OwnLabel slaveMarker = new OwnLabel("[" + (i + 1) + "]", skin);
        if (MasterManager.instance.isSlaveConnected(slaves.get(i))) {
            slaveMarker.setColor(Color.GREEN);
        } else {
            slaveMarker.setColor(Color.RED);
        }
        slaveStatuses[i] = slaveMarker;
        statusTable.add(slaveMarker).left().padRight(pad10);
    }
    content.add(statusLabel).center().left().padRight(pad10).padBottom(pad10 * 2f);
    content.add(statusTable).center().left().padBottom(pad10 * 2f).row();
    // Instance
    Array<String> slaveList = getSlaveBeans();
    slaveSelect = new OwnSelectBox<>(skin);
    slaveSelect.setWidth(tw * 4f);
    slaveSelect.setItems(slaveList);
    slaveSelect.addListener((event) -> {
        if (event instanceof ChangeEvent) {
            String newSlave = slaveSelect.getSelected();
            pullParameters(newSlave);
            updateSlaveStatusText(newSlave);
            return true;
        }
        return false;
    });
    OwnLabel slaveLabel = new OwnLabel(I18n.txt("gui.slave.config.instance") + ":", skin);
    content.add(slaveLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(slaveSelect).center().left().padBottom(pad10).row();
    // Slave status label
    slaveStatusLabel = new OwnLabel("", skin);
    content.add(slaveStatusLabel).colspan(2).center().padBottom(pad10 * 2f).row();
    if (slaves.size() > 0)
        updateSlaveStatusText(slaves.get(0));
    // Yaw
    yaw = new OwnTextField("", skin, angleVal);
    yaw.setWidth(tw);
    OwnLabel yawLabel = new OwnLabel(I18n.txt("gui.slave.config.yaw") + ":", skin);
    content.add(yawLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(yaw).center().left().padBottom(pad10).row();
    // Pitch
    pitch = new OwnTextField("", skin, angleVal);
    pitch.setWidth(tw);
    OwnLabel pitchLabel = new OwnLabel(I18n.txt("gui.slave.config.pitch") + ":", skin);
    content.add(pitchLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(pitch).center().left().padBottom(pad10).row();
    // Roll
    roll = new OwnTextField("", skin, angleVal);
    roll.setWidth(tw);
    OwnLabel rollLabel = new OwnLabel(I18n.txt("gui.slave.config.roll") + ":", skin);
    content.add(rollLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(roll).center().left().padBottom(pad10).row();
    // FOV
    fov = new OwnTextField("", skin, fovVal);
    fov.setWidth(tw);
    OwnLabel fovLabel = new OwnLabel(I18n.txt("gui.slave.config.fov") + ":", skin);
    content.add(fovLabel).center().left().padRight(pad10).padBottom(pad10);
    content.add(fov).center().left().padBottom(pad10).row();
    if (slaveSelect.getSelected() != null)
        pullParameters(slaveSelect.getSelected());
}
Also used : OwnTextButton(gaiasky.util.scene2d.OwnTextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) OwnTextField(gaiasky.util.scene2d.OwnTextField) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) OwnLabel(gaiasky.util.scene2d.OwnLabel) FloatValidator(gaiasky.util.validator.FloatValidator)

Example 4 with OwnTextButton

use of gaiasky.util.scene2d.OwnTextButton in project gaiasky by langurmonkey.

the class ExternalInformationUpdater method update.

public void update(final IFocus focus) {
    GaiaSky.postRunnable(() -> {
        if (focus != null) {
            logger.debug("Looking up network resources for '" + focus.getName() + "'");
            infoCell = table.add().left();
            gaiaCell = table.add().left();
            simbadCell = table.add().left();
            // Add table
            if (focus instanceof IStarFocus) {
                EventManager.publish(Event.UPDATE_ARCHIVE_VIEW_ACTION, this, focus);
                if (gaiaButton != null)
                    gaiaButton.remove();
                gaiaButton = new OwnTextButton(I18n.txt("gui.focusinfo.archive"), skin);
                gaiaButton.pad(pad / 3f, pad, pad / 3f, pad);
                gaiaButton.addListener(new GaiaButtonListener((IStarFocus) focus));
                gaiaButton.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.gaiaarchive"), skin));
                gaiaCell.setActor(gaiaButton).padRight(pad);
            } else {
                gaiaCell.padRight(0);
            }
            String wikiname = focus.getName().replace(' ', '_');
            setWikiLink(wikiname, focus, new LinkListener() {

                @Override
                public void ok(String link) {
                    if (infoCell != null) {
                        try {
                            String actualWikiname = link.substring(Constants.URL_WIKIPEDIA.length());
                            EventManager.publish(Event.UPDATE_WIKI_INFO_ACTION, this, actualWikiname);
                            if (infoButton != null)
                                infoButton.remove();
                            infoButton = new OwnTextButton(I18n.txt("gui.focusinfo.moreinfo"), skin);
                            infoButton.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.wiki"), skin));
                            infoButton.pad(pad / 3f, pad, pad / 3f, pad);
                            infoButton.addListener((event) -> {
                                if (event instanceof ChangeEvent) {
                                    EventManager.publish(Event.SHOW_WIKI_INFO_ACTION, this, actualWikiname);
                                    return true;
                                }
                                return false;
                            });
                            infoCell.setActor(infoButton).padRight(pad);
                        } catch (Exception ignored) {
                        }
                    }
                }

                @Override
                public void ko(String link) {
                    if (infoCell != null)
                        infoCell.padRight(0);
                }
            });
            setSimbadLink(focus, new LinkListener() {

                @Override
                public void ok(String link) {
                    if (simbadCell != null) {
                        try {
                            if (simbadLink != null) {
                                simbadLink.remove();
                            }
                            simbadLink = new Link(I18n.txt("gui.focusinfo.simbad"), linkStyle, "");
                            simbadLink.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.simbad"), skin));
                            simbadLink.setLinkURL(link);
                            simbadCell.setActor(simbadLink);
                        } catch (Exception ignored) {
                        }
                    }
                }

                @Override
                public void ko(String link) {
                }
            });
        }
    });
}
Also used : HttpRequest(com.badlogic.gdx.Net.HttpRequest) GaiaSky(gaiasky.GaiaSky) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Constants(gaiasky.util.Constants) Logger(gaiasky.util.Logger) HttpStatus(com.badlogic.gdx.net.HttpStatus) Event(gaiasky.event.Event) Gdx(com.badlogic.gdx.Gdx) HttpResponse(com.badlogic.gdx.Net.HttpResponse) gaiasky.scenegraph(gaiasky.scenegraph) Link(gaiasky.util.scene2d.Link) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) I18n(gaiasky.util.I18n) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Cell(com.badlogic.gdx.scenes.scene2d.ui.Cell) OwnTextTooltip(gaiasky.util.scene2d.OwnTextTooltip) Log(gaiasky.util.Logger.Log) OwnTextButton(gaiasky.util.scene2d.OwnTextButton) EventManager(gaiasky.event.EventManager) HttpMethods(com.badlogic.gdx.Net.HttpMethods) LabelStyle(com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle) HttpResponseListener(com.badlogic.gdx.Net.HttpResponseListener) EventListener(com.badlogic.gdx.scenes.scene2d.EventListener) OwnTextButton(gaiasky.util.scene2d.OwnTextButton) OwnTextTooltip(gaiasky.util.scene2d.OwnTextTooltip) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) Link(gaiasky.util.scene2d.Link)

Example 5 with OwnTextButton

use of gaiasky.util.scene2d.OwnTextButton in project gaiasky by langurmonkey.

the class GenericDialog method buildSuper.

public void buildSuper() {
    // BUTTONS
    buttonGroup = new HorizontalGroup();
    buttonGroup.space(pad5);
    if (acceptText != null) {
        acceptButton = new OwnTextButton(acceptText, skin, "default");
        acceptButton.setName("accept");
        acceptButton.addListener((event) -> {
            if (event instanceof ChangeEvent) {
                accept();
                if (acceptRunnable != null)
                    acceptRunnable.run();
                me.hide();
                return true;
            }
            return false;
        });
        buttonGroup.addActor(acceptButton);
    }
    if (cancelText != null) {
        cancelButton = new OwnTextButton(cancelText, skin, "default");
        cancelButton.setName("cancel");
        cancelButton.addListener((event) -> {
            if (event instanceof ChangeEvent) {
                cancel();
                if (cancelRunnable != null)
                    cancelRunnable.run();
                me.hide();
                return true;
            }
            return false;
        });
        buttonGroup.addActor(cancelButton);
    }
    recalculateButtonSize();
    add(content).left().pad(pad10).row();
    add(bottom).expandY().bottom().right().padRight(pad10).row();
    add(buttonGroup).pad(pad10).bottom().right();
    getTitleTable().align(Align.left);
    // Align top left
    align(Align.top | Align.left);
    pack();
    // Add keys for ESC, ENTER and TAB
    me.addListener(event -> {
        if (event instanceof InputEvent) {
            InputEvent ievent = (InputEvent) event;
            if (ievent.getType() == Type.keyUp) {
                int key = ievent.getKeyCode();
                switch(key) {
                    case Keys.ESCAPE:
                        if (escExit) {
                            // Exit
                            cancel();
                            if (cancelRunnable != null)
                                cancelRunnable.run();
                            me.hide();
                        }
                        // Do not propagate to parents
                        event.stop();
                        return true;
                    case Keys.ENTER:
                        if (enterExit) {
                            // Exit
                            accept();
                            if (acceptRunnable != null)
                                acceptRunnable.run();
                            me.hide();
                        }
                        // Do not propagate to parents
                        event.stop();
                        return true;
                    case Keys.TAB:
                        return true;
                    default:
                        // Nothing
                        break;
                }
            }
        }
        return false;
    });
    // CAPTURE SCROLL FOCUS
    stage.addListener(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 false;
    });
    // Build actual content
    build();
    // Modal
    setModal(this.modal);
}
Also used : OwnScrollPane(gaiasky.util.scene2d.OwnScrollPane) OwnTextButton(gaiasky.util.scene2d.OwnTextButton) ChangeEvent(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup)

Aggregations

OwnTextButton (gaiasky.util.scene2d.OwnTextButton)5 ChangeEvent (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent)4 OwnLabel (gaiasky.util.scene2d.OwnLabel)3 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)2 Gdx (com.badlogic.gdx.Gdx)1 HttpMethods (com.badlogic.gdx.Net.HttpMethods)1 HttpRequest (com.badlogic.gdx.Net.HttpRequest)1 HttpResponse (com.badlogic.gdx.Net.HttpResponse)1 HttpResponseListener (com.badlogic.gdx.Net.HttpResponseListener)1 Lwjgl3Graphics (com.badlogic.gdx.backends.lwjgl3.Lwjgl3Graphics)1 HttpStatus (com.badlogic.gdx.net.HttpStatus)1 Actor (com.badlogic.gdx.scenes.scene2d.Actor)1 EventListener (com.badlogic.gdx.scenes.scene2d.EventListener)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Cell (com.badlogic.gdx.scenes.scene2d.ui.Cell)1 HorizontalGroup (com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 LabelStyle (com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 GaiaSky (gaiasky.GaiaSky)1