use of gaiasky.scenegraph.SceneGraphNode in project gaiasky by langurmonkey.
the class SAMPClient method initialize.
public void initialize(final Skin skin) {
// Disable logging
java.util.logging.Logger.getLogger("org.astrogrid.samp").setLevel(Level.OFF);
// Init map
idToNode = new TwoWayHashmap<>();
idToUrl = new HashMap<>();
ClientProfile cp = DefaultClientProfile.getProfile();
conn = new GaiaSkyHubConnector(cp);
// Configure it with metadata about this application
Metadata meta = new Metadata();
meta.setName(Settings.APPLICATION_NAME);
meta.setDescriptionText("3D Universe application focused on ESA's Gaia satellite");
meta.setDocumentationUrl(Settings.DOCUMENTATION);
meta.setIconUrl(Settings.ICON_URL.replaceAll("[^\\x00-\\x7F]", "?"));
meta.put("author.name", Settings.AUTHOR_NAME_PLAIN);
meta.put("author.email", Settings.AUTHOR_EMAIL);
meta.put("author.affiliation", Settings.AUTHOR_AFFILIATION_PLAIN);
meta.put("home.page", Settings.WEBPAGE);
meta.put("gaiasky.version", Settings.settings.version.version);
conn.declareMetadata(meta);
// Load table
conn.addMessageHandler(new AbstractMessageHandler("table.load.votable") {
public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
// do stuff
String name = (String) msg.getParam("name");
String id = (String) msg.getParam("table-id");
String url = (String) msg.getParam("url");
boolean loaded = loadVOTable(url, id, name, skin);
if (!loaded) {
logger.info(I18n.txt("samp.error.votable", name));
}
return null;
}
});
// Select one row
conn.addMessageHandler(new AbstractMessageHandler("table.highlight.row") {
public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
// do stuff
long row = Parser.parseLong((String) msg.getParam("row"));
String id = (String) msg.getParam("table-id");
// First, fetch table if not here
boolean loaded = idToNode.containsKey(id);
// If table here, select
if (loaded) {
logger.info("Select row " + row + " of " + id);
if (idToNode.containsKey(id)) {
if (idToNode.getForward(id) instanceof ParticleGroup) {
// Stars or particles
ParticleGroup pg = (ParticleGroup) idToNode.getForward(id);
pg.setFocusIndex((int) row);
preventProgrammaticEvents = true;
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, pg);
preventProgrammaticEvents = false;
} else if (idToNode.getForward(id) != null) {
// Star cluster
FadeNode fn = idToNode.getForward(id);
if (fn.children != null && fn.children.size > (int) row) {
SceneGraphNode sgn = fn.children.get((int) row);
preventProgrammaticEvents = true;
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, sgn);
preventProgrammaticEvents = false;
} else {
logger.info("Star cluster to select not found: " + row);
}
}
}
}
return null;
}
});
// Select multiple rows
conn.addMessageHandler(new AbstractMessageHandler("table.select.rowList") {
public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
// do stuff
ArrayList<String> rows = (ArrayList<String>) msg.getParam("row-list");
String id = (String) msg.getParam("table-id");
// First, fetch table if not here
boolean loaded = idToNode.containsKey(id);
// If table here, select
if (loaded && rows != null && !rows.isEmpty()) {
logger.info("Select " + rows.size() + " rows of " + id + ". Gaia Sky does not support multiple selection, so only the first entry is selected.");
// We use the first one, as multiple selections are not supported in Gaia Sky
int row = Integer.parseInt(rows.get(0));
if (idToNode.containsKey(id)) {
FadeNode fn = idToNode.getForward(id);
if (fn instanceof ParticleGroup) {
ParticleGroup pg = (ParticleGroup) fn;
pg.setFocusIndex(row);
preventProgrammaticEvents = true;
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraManager.CameraMode.FOCUS_MODE);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, pg);
preventProgrammaticEvents = false;
}
}
}
return null;
}
});
// Point in sky
conn.addMessageHandler(new AbstractMessageHandler("coord.pointAt.sky") {
public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
// do stuff
double ra = Parser.parseDouble((String) msg.getParam("ra"));
double dec = Parser.parseDouble((String) msg.getParam("dec"));
logger.info("Point to coordinate (ra,dec): (" + ra + ", " + dec + ")");
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FREE_MODE);
EventManager.publish(Event.FREE_MODE_COORD_CMD, this, ra, dec);
return null;
}
});
// This step required even if no custom message handlers added.
conn.declareSubscriptions(conn.computeSubscriptions());
// Keep a look out for hubs if initial one shuts down
conn.setAutoconnect(10);
}
use of gaiasky.scenegraph.SceneGraphNode in project gaiasky by langurmonkey.
the class BookmarksComponent method initialize.
@Override
public void initialize() {
float contentWidth = ControlsWindow.getContentWidth();
searchBox = new OwnTextField("", skin);
searchBox.setName("search box");
searchBox.setWidth(contentWidth);
searchBox.setMessageText(I18n.txt("gui.objects.search"));
searchBox.addListener(event -> {
if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
if (ie.getType() == Type.keyUp && !searchBox.getText().isEmpty()) {
String text = searchBox.getText().toLowerCase().trim();
if (sg.containsNode(text)) {
SceneGraphNode node = sg.getNode(text);
if (node instanceof IFocus) {
IFocus focus = (IFocus) node;
boolean timeOverflow = focus.isCoordinatesTimeOverflow();
boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
if (!timeOverflow && ctOn) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.CAMERA_MODE_CMD, searchBox, CameraMode.FOCUS_MODE, true);
EventManager.publish(Event.FOCUS_CHANGE_CMD, searchBox, focus, true);
});
} else if (timeOverflow) {
info(I18n.txt("gui.objects.search.timerange.1", text), I18n.txt("gui.objects.search.timerange.2"));
} else {
info(I18n.txt("gui.objects.search.invisible.1", text), I18n.txt("gui.objects.search.invisible.2", focus.getCt().toString()));
}
}
} else {
info(null, null);
}
if (GaiaSky.instance.getICamera() instanceof NaturalCamera)
((NaturalCamera) GaiaSky.instance.getICamera()).getCurrentMouseKbdListener().removePressedKey(ie.getKeyCode());
if (ie.getKeyCode() == Keys.ESCAPE) {
// Lose focus
stage.setKeyboardFocus(null);
}
} else if (ie.getType() == Type.keyDown) {
if (ie.getKeyCode() == Keys.CONTROL_LEFT || ie.getKeyCode() == Keys.CONTROL_RIGHT) {
// Lose focus
stage.setKeyboardFocus(null);
}
}
return true;
}
return false;
});
// Info message
infoTable = new Table(skin);
infoCell1 = infoTable.add();
infoTable.row();
infoCell2 = infoTable.add();
infoMessage1 = new OwnLabel("", skin, "default-blue");
infoMessage2 = new OwnLabel("", skin, "default-blue");
/*
* OBJECTS
*/
bookmarksTree = new Tree<>(skin);
bookmarksTree.setName("bookmarks tree");
reloadBookmarksTree();
bookmarksTree.addListener(event -> {
if (events)
if (event instanceof ChangeEvent) {
ChangeEvent ce = (ChangeEvent) event;
Actor actor = ce.getTarget();
TreeNode selected = (TreeNode) ((Tree) actor).getSelectedNode();
if (selected != null && !selected.hasChildren()) {
String name = selected.getValue();
if (sg.containsNode(name)) {
SceneGraphNode node = sg.getNode(name);
if (node instanceof IFocus) {
IFocus focus = (IFocus) node;
boolean timeOverflow = focus.isCoordinatesTimeOverflow();
boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
if (!timeOverflow && ctOn) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.CAMERA_MODE_CMD, bookmarksTree, CameraMode.FOCUS_MODE, true);
EventManager.publish(Event.FOCUS_CHANGE_CMD, bookmarksTree, focus, true);
});
info(null, null);
} else if (timeOverflow) {
info(I18n.txt("gui.objects.search.timerange.1", name), I18n.txt("gui.objects.search.timerange.2"));
} else {
info(I18n.txt("gui.objects.search.invisible.1", name), I18n.txt("gui.objects.search.invisible.2", focus.getCt().toString()));
}
}
} else {
info(null, null);
}
}
return true;
} else if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
ie.toCoordinates(event.getListenerActor(), tmpCoords);
if (ie.getType() == Type.touchDown && ie.getButton() == Input.Buttons.RIGHT) {
TreeNode target = bookmarksTree.getNodeAt(tmpCoords.y);
// Context menu!
if (target != null) {
// selectBookmark(target.getValue(), true);
GaiaSky.postRunnable(() -> {
ContextMenu cm = new ContextMenu(skin, "default");
// New folder...
BookmarkNode parent = target.node.getFirstFolderAncestor();
String parentName = "/" + (parent == null ? "" : parent.path.toString());
MenuItem newDirectory = new MenuItem(I18n.txt("gui.bookmark.context.newfolder", parentName), skin);
newDirectory.addListener(evt -> {
if (evt instanceof ChangeEvent) {
NewBookmarkFolderDialog newBookmarkFolderDialog = new NewBookmarkFolderDialog(parent != null ? parent.path.toString() : "/", skin, stage);
newBookmarkFolderDialog.setAcceptRunnable(() -> {
String folderName = newBookmarkFolderDialog.input.getText();
EventManager.publish(Event.BOOKMARKS_ADD, newDirectory, parent != null ? parent.path.resolve(folderName).toString() : folderName, true);
reloadBookmarksTree();
});
newBookmarkFolderDialog.show(stage);
return true;
}
return false;
});
cm.addItem(newDirectory);
// Delete
MenuItem delete = new MenuItem(I18n.txt("gui.bookmark.context.delete", target.getValue()), skin);
delete.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_REMOVE, delete, target.node.path.toString());
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(delete);
cm.addSeparator();
// Move up and down
MenuItem moveUp = new MenuItem(I18n.txt("gui.bookmark.context.move.up"), skin);
moveUp.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_MOVE_UP, moveUp, target.node);
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(moveUp);
MenuItem moveDown = new MenuItem(I18n.txt("gui.bookmark.context.move.down"), skin);
moveDown.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_MOVE_DOWN, moveDown, target.node);
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(moveDown);
// Move to...
if (target.node.parent != null) {
MenuItem move = new MenuItem(I18n.txt("gui.bookmark.context.move", target.getValue(), "/"), skin);
move.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_MOVE, move, target.node, null);
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(move);
}
List<BookmarkNode> folders = GaiaSky.instance.getBookmarksManager().getFolders();
for (BookmarkNode folder : folders) {
if (!target.node.isDescendantOf(folder)) {
MenuItem mv = new MenuItem(I18n.txt("gui.bookmark.context.move", target.getValue(), "/" + folder.path.toString()), skin);
mv.addListener(evt -> {
if (evt instanceof ChangeEvent) {
EventManager.publish(Event.BOOKMARKS_MOVE, mv, target.node, folder);
reloadBookmarksTree();
return true;
}
return false;
});
cm.addItem(mv);
}
}
newMenu(cm);
cm.showMenu(stage, Gdx.input.getX(ie.getPointer()) / Settings.settings.program.ui.scale, stage.getHeight() - Gdx.input.getY(ie.getPointer()) / Settings.settings.program.ui.scale);
});
} else {
// New folder
GaiaSky.postRunnable(() -> {
ContextMenu cm = new ContextMenu(skin, "default");
// New folder...
String parentName = "/";
MenuItem newDirectory = new MenuItem(I18n.txt("gui.bookmark.context.newfolder", parentName), skin);
newDirectory.addListener(evt -> {
if (evt instanceof ChangeEvent) {
NewBookmarkFolderDialog nbfd = new NewBookmarkFolderDialog("/", skin, stage);
nbfd.setAcceptRunnable(() -> {
String folderName = nbfd.input.getText();
EventManager.publish(Event.BOOKMARKS_ADD, newDirectory, folderName, true);
reloadBookmarksTree();
});
nbfd.show(stage);
return true;
}
return false;
});
cm.addItem(newDirectory);
newMenu(cm);
cm.showMenu(stage, Gdx.input.getX(ie.getPointer()), Gdx.graphics.getHeight() - Gdx.input.getY(ie.getPointer()));
});
}
}
event.setBubbles(false);
return true;
}
return false;
});
bookmarksScrollPane = new OwnScrollPane(bookmarksTree, skin, "minimalist-nobg");
bookmarksScrollPane.setName("bookmarks scroll");
bookmarksScrollPane.setFadeScrollBars(false);
bookmarksScrollPane.setScrollingDisabled(true, false);
bookmarksScrollPane.setHeight(160f);
bookmarksScrollPane.setWidth(contentWidth);
/*
* ADD TO CONTENT
*/
VerticalGroup objectsGroup = new VerticalGroup().align(Align.left).columnAlign(Align.left).space(pad12);
objectsGroup.addActor(searchBox);
if (bookmarksScrollPane != null) {
objectsGroup.addActor(bookmarksScrollPane);
}
objectsGroup.addActor(infoTable);
component = objectsGroup;
}
use of gaiasky.scenegraph.SceneGraphNode in project gaiasky by langurmonkey.
the class ObjectsComponent method initialize.
@Override
public void initialize() {
float contentWidth = ControlsWindow.getContentWidth();
searchBox = new OwnTextField("", skin);
searchBox.setName("search box");
searchBox.setWidth(contentWidth);
searchBox.setMessageText(I18n.txt("gui.objects.search"));
searchBox.addListener(event -> {
if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
if (ie.getType() == Type.keyUp && !searchBox.getText().isEmpty()) {
String text = searchBox.getText().toLowerCase().trim();
if (sg.containsNode(text)) {
SceneGraphNode node = sg.getNode(text);
if (node instanceof IFocus) {
IFocus focus = (IFocus) node;
boolean timeOverflow = focus.isCoordinatesTimeOverflow();
boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
if (!timeOverflow && ctOn) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE, true);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, focus, true);
});
} else if (timeOverflow) {
info(I18n.txt("gui.objects.search.timerange.1", text), I18n.txt("gui.objects.search.timerange.2"));
} else {
info(I18n.txt("gui.objects.search.invisible.1", text), I18n.txt("gui.objects.search.invisible.2", focus.getCt().toString()));
}
}
} else {
info(null, null);
}
if (GaiaSky.instance.getICamera() instanceof NaturalCamera)
((NaturalCamera) GaiaSky.instance.getICamera()).getCurrentMouseKbdListener().removePressedKey(ie.getKeyCode());
if (ie.getKeyCode() == Keys.ESCAPE) {
// Lose focus
stage.setKeyboardFocus(null);
}
} else if (ie.getType() == Type.keyDown) {
if (ie.getKeyCode() == Keys.CONTROL_LEFT || ie.getKeyCode() == Keys.CONTROL_RIGHT) {
// Lose focus
stage.setKeyboardFocus(null);
}
}
return true;
}
return false;
});
// Info message
infoTable = new Table(skin);
infoCell1 = infoTable.add();
infoTable.row();
infoCell2 = infoTable.add();
infoMessage1 = new OwnLabel("", skin, "default-blue");
infoMessage2 = new OwnLabel("", skin, "default-blue");
/*
* OBJECTS
*/
final com.badlogic.gdx.scenes.scene2d.ui.List<String> focusList = new com.badlogic.gdx.scenes.scene2d.ui.List<>(skin);
focusList.setName("objects list");
Array<IFocus> focusableObjects = sg.getFocusableObjects();
Array<String> names = new Array<>(false, focusableObjects.size);
for (IFocus focus : focusableObjects) {
// Omit stars with no proper names
if (focus.getName() != null && !GlobalResources.isNumeric(focus.getName())) {
names.add(focus.getName());
}
}
names.sort();
SceneGraphNode sol = sg.getNode("Sun");
if (sol != null) {
Array<IFocus> solChildren = new Array<>();
sol.addFocusableObjects(solChildren);
solChildren.sort(new CelestialBodyComparator());
for (IFocus cb : solChildren) names.insert(0, cb.getName());
}
focusList.setItems(names);
//
focusList.pack();
focusList.addListener(event -> {
if (event instanceof ChangeEvent) {
ChangeEvent ce = (ChangeEvent) event;
Actor actor = ce.getTarget();
@SuppressWarnings("unchecked") final String text = ((com.badlogic.gdx.scenes.scene2d.ui.List<String>) actor).getSelected().toLowerCase().trim();
if (sg.containsNode(text)) {
SceneGraphNode node = sg.getNode(text);
if (node instanceof IFocus) {
IFocus focus = (IFocus) node;
boolean timeOverflow = focus.isCoordinatesTimeOverflow();
boolean ctOn = GaiaSky.instance.isOn(focus.getCt());
if (!timeOverflow && ctOn) {
GaiaSky.postRunnable(() -> {
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE, true);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, focus, true);
});
} else if (timeOverflow) {
info(I18n.txt("gui.objects.search.timerange.1", text), I18n.txt("gui.objects.search.timerange.2"));
} else {
info(I18n.txt("gui.objects.search.invisible.1", text), I18n.txt("gui.objects.search.invisible.2", focus.getCt().toString()));
}
}
} else {
info(null, null);
}
return true;
}
return false;
});
objectsList = focusList;
focusListScrollPane = new OwnScrollPane(objectsList, skin, "minimalist-nobg");
focusListScrollPane.setName("objects list scroll");
focusListScrollPane.setFadeScrollBars(false);
focusListScrollPane.setScrollingDisabled(true, false);
focusListScrollPane.setHeight(160f);
focusListScrollPane.setWidth(contentWidth);
/*
* ADD TO CONTENT
*/
VerticalGroup objectsGroup = new VerticalGroup().align(Align.left).columnAlign(Align.left).space(pad12);
objectsGroup.addActor(searchBox);
if (focusListScrollPane != null) {
objectsGroup.addActor(focusListScrollPane);
}
objectsGroup.addActor(infoTable);
component = objectsGroup;
}
use of gaiasky.scenegraph.SceneGraphNode in project gaiasky by langurmonkey.
the class ObjectsComponent method notify.
@Override
public void notify(final Event event, Object source, final Object... data) {
if (event == Event.FOCUS_CHANGED) {
// Update focus selection in focus list
SceneGraphNode sgn = null;
if (data[0] instanceof String) {
sgn = sg.getNode((String) data[0]);
} else {
sgn = (SceneGraphNode) data[0];
}
// Select only if data[1] is true
if (sgn != null) {
// Update focus selection in focus list
@SuppressWarnings("unchecked") List<String> objList = (List<String>) objectsList;
Array<String> items = objList.getItems();
SceneGraphNode node = (SceneGraphNode) data[0];
// Select without firing events, do not use set()
objList.getSelection().items().clear();
objList.getSelection().items().add(node.getName());
int itemIdx = items.indexOf(node.getName(), false);
if (itemIdx >= 0) {
objList.getSelection().setProgrammaticChangeEvents(false);
objList.setSelectedIndex(itemIdx);
objList.getSelection().setProgrammaticChangeEvents(true);
float itemHeight = objList.getItemHeight();
focusListScrollPane.setScrollY(itemIdx * itemHeight);
}
}
}
}
use of gaiasky.scenegraph.SceneGraphNode 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;
}
}
}
Aggregations