use of gaiasky.util.scene2d.OwnTextField 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.util.scene2d.OwnTextField in project gaiasky by langurmonkey.
the class SearchDialog method build.
public void build() {
candidates = new Table(skin);
candidates.setBackground("table-bg");
candidates.setFillParent(false);
// Info message
searchInput = new OwnTextField("", skin);
searchInput.setWidth(480f);
searchInput.setMessageText(I18n.txt("gui.objects.search"));
searchInput.addListener(event -> {
if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
int matchingSize = matching.size();
int code = ie.getKeyCode();
if (ie.getType() == Type.keyUp) {
if (code == Keys.ESCAPE || code == Keys.ENTER) {
if (cIdx >= 0) {
checkString(searchInput.getText(), sg);
}
removeCandidates();
me.remove();
return true;
} else if (code == Keys.UP && matchingSize > 0) {
cIdx = cIdx - 1 < 0 ? matchingSize - 1 : cIdx - 1;
selectMatch();
} else if (code == Keys.DOWN && matchingSize > 0) {
cIdx = (cIdx + 1) % matchingSize;
selectMatch();
} else if (!searchInput.getText().equals(currentInputText) && !searchInput.getText().isBlank()) {
// Process only if text changed
if (suggestions) {
currentInputText = searchInput.getText();
String name = currentInputText.toLowerCase().trim();
// New task
Task task = new Task() {
public void run() {
synchronized (matching) {
matchingNodes(name, sg);
if (!matching.isEmpty()) {
cIdx = -1;
candidates.clear();
int n = matching.size();
matching.stream().forEach(match -> {
OwnLabel m = new OwnLabel(match, skin);
m.addListener((evt) -> {
if (evt instanceof InputEvent) {
InputEvent iEvt = (InputEvent) evt;
if (iEvt.getType() == Type.touchDown) {
checkString(match, sg);
searchInput.setText(match);
accept();
return true;
}
}
return false;
});
matchingLabels.add(m);
m.setWidth(searchInput.getWidth());
Cell<?> c = candidates.add(m).left().padBottom(pad5);
c.row();
});
candidates.pack();
searchInput.localToStageCoordinates(aux.set(0, 0));
candidates.setPosition(aux.x, aux.y, Align.topLeft);
stage.addActor(candidates);
} else {
removeCandidates();
}
}
}
};
// Cancel others
cancelTasks();
tasks.add(task);
// Schedule with delay
Timer.schedule(task, 0.5f);
// Actually check and select
if (!checkString(name, sg)) {
if (name.matches("[0-9]+")) {
// Check with 'HIP '
if (checkString("hip " + name, sg)) {
cancelTasks();
removeCandidates();
}
} else if (name.matches("hip [0-9]+") || name.matches("HIP [0-9]+")) {
// Check without 'HIP '
if (checkString(name.substring(4), sg)) {
cancelTasks();
removeCandidates();
}
}
} else {
cancelTasks();
removeCandidates();
}
}
} else {
removeCandidates();
}
if (GaiaSky.instance.getICamera() instanceof NaturalCamera)
((NaturalCamera) GaiaSky.instance.getICamera()).getCurrentMouseKbdListener().removePressedKey(ie.getKeyCode());
}
}
return false;
});
// Info message
infoMessage = new OwnLabel("", skin, "default-blue");
content.add(searchInput).top().left().expand().row();
infoCell = content.add();
infoCell.top().left().padTop(pad5).expand().row();
}
use of gaiasky.util.scene2d.OwnTextField 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());
}
use of gaiasky.util.scene2d.OwnTextField in project gaiasky by langurmonkey.
the class NewBookmarkFolderDialog method build.
public void build() {
// Info message
IValidator val = new FolderValidator();
input = new OwnTextField("", skin, val);
input.setWidth(480f);
input.setMessageText("New folder");
content.add(input).top().left().expand().row();
}
use of gaiasky.util.scene2d.OwnTextField in project gaiasky by langurmonkey.
the class FileNameWindow method build.
@Override
protected void build() {
OwnLabel label = new OwnLabel(I18n.txt("gui.filename.filename") + ": ", skin);
LengthValidator lengthValidator = new LengthValidator(3, 40);
RegexpValidator nameValidator = new RegexpValidator(lengthValidator, "^[^*&%\\s\\+\\=\\\\\\/@#\\$&\\*()~]+$");
fileName = new OwnTextField(defaultName, skin, nameValidator);
fileName.setWidth(400f);
content.add(label).padRight(pad10).padBottom(pad10);
content.add(fileName).padBottom(pad10);
}
Aggregations