use of gaiasky.util.validator.RegexpValidator in project gaiasky by langurmonkey.
the class KeyframesWindow method build.
@Override
protected void build() {
/*
* Right and left tables
*/
Table left = new Table(skin);
left.align(Align.top | Align.left);
Table right = new Table(skin);
right.align(Align.top | Align.left);
/* LEFT - CONTROLS */
// ADD
OwnTextIconButton addKeyframe = new OwnTextIconButton(I18n.txt("gui.keyframes.add.end"), skin, "add");
addKeyframe.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.add.end"), skin));
addKeyframe.pad(pad5);
left.add(addKeyframe).left().colspan(2).padBottom(pad5).row();
addKeyframe.addListener(event -> {
if (event instanceof ChangeEvent) {
// Add at end
return addKeyframe(-1);
}
return false;
});
// SECONDS
FloatValidator secondsValidator = new FloatValidator(0.0001f, 9999.0f);
secondsValidator.setIsValidCallback(() -> {
// Enable add button
addKeyframe.setDisabled(false);
});
secondsValidator.setIsInvalidCallback(() -> {
// Disable add button
addKeyframe.setDisabled(true);
});
secondsInput = new OwnTextField("1.0", skin, secondsValidator);
secondsInput.setWidth(96f);
OwnLabel secondsLabel = new OwnLabel(I18n.txt("gui.keyframes.secsafter") + ":", skin);
left.add(secondsLabel).center().left().padRight(pad10).padBottom(pad10);
left.add(secondsInput).center().left().padBottom(pad10).row();
// NAME
LengthValidator lengthValidator = new LengthValidator(0, 15);
RegexpValidator nameValidator = new RegexpValidator(lengthValidator, "^[^*&%\\s\\+\\=\\\\\\/@#\\$&\\*()~]*$");
nameInput = new OwnTextField("", skin, nameValidator);
nameInput.setWidth(96f);
OwnLabel nameLabel = new OwnLabel(I18n.txt("gui.keyframes.name") + ":", skin);
left.add(nameLabel).center().left().padRight(pad10).padBottom(pad10);
left.add(nameInput).center().left().padBottom(pad10).row();
left.pack();
/* RIGHT - KEYFRAMES */
OwnLabel keyframesTitle = new OwnLabel(I18n.txt("gui.keyframes.list"), skin, "hud-header");
// KEYFRAMES TABLE
keyframesTable = buildKeyframesTable();
// ADD SCROLL
rightScroll = new OwnScrollPane(keyframesTable, skin, "minimalist-nobg");
rightScroll.setExpand(true);
rightScroll.setScrollingDisabled(true, false);
rightScroll.setHeight(160f);
rightScroll.setWidth(540f);
rightScroll.setFadeScrollBars(true);
right.add(keyframesTitle).top().left().padBottom(pad10).row();
right.add(rightScroll).center().left();
right.pack();
/* RE-NORMALIZE TIME */
OwnTextButton normalizeTime = new OwnTextButton(I18n.txt("gui.keyframes.normalize"), skin);
normalizeTime.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.normalize"), skin));
normalizeTime.pad(pad10);
normalizeTime.addListener((event) -> {
if (event instanceof ChangeEvent) {
if (keyframes != null && keyframes.size > 2) {
Vector3d aux = new Vector3d();
int n = keyframes.size;
double totalTime = 0;
double totalDist = 0;
for (int i = 1; i < n; i++) {
Keyframe kf0 = keyframes.get(i - 1);
Keyframe kf1 = keyframes.get(i);
totalTime += kf1.seconds;
totalDist += aux.set(kf1.pos).sub(kf0.pos).len();
}
// Loop over keyframes and assign new times
for (int i = 1; i < n; i++) {
Keyframe kf0 = keyframes.get(i - 1);
Keyframe kf1 = keyframes.get(i);
double dist = aux.set(kf1.pos).sub(kf0.pos).len();
kf1.seconds = totalTime * dist / totalDist;
}
// Reload window contents
reinitialiseKeyframes(keyframes, null);
keyframesPathObject.unselect();
logger.info(I18n.txt("gui.keyframes.normalize.done"));
}
return true;
}
return false;
});
/* ACTION BUTTONS */
HorizontalGroup buttons = new HorizontalGroup();
buttons.space(pad10);
// Open keyframes
OwnTextIconButton open = new OwnTextIconButton(I18n.txt("gui.keyframes.load"), skin, "open");
open.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.load"), skin));
open.pad(pad5);
open.addListener((event) -> {
if (event instanceof ChangeEvent) {
FileChooser fc = new FileChooser(I18n.txt("gui.download.pickloc"), skin, stage, SysUtils.getDefaultCameraDir(), FileChooser.FileChooserTarget.FILES);
fc.setShowHidden(Settings.settings.program.fileChooser.showHidden);
fc.setShowHiddenConsumer((showHidden) -> Settings.settings.program.fileChooser.showHidden = showHidden);
fc.setFileFilter(pathname -> pathname.getFileName().toString().endsWith(".gkf"));
fc.setAcceptedFiles("*.gkf");
fc.setResultListener((success, result) -> {
if (success) {
if (Files.exists(result) && Files.isRegularFile(result)) {
// Load selected file
try {
Array<Keyframe> kfs = CameraKeyframeManager.instance.loadKeyframesFile(result);
// Update current instance
reinitialiseKeyframes(kfs, null);
keyframesPathObject.unselect();
lastKeyframeFileName = result.getFileName().toString();
logger.info(I18n.txt("gui.keyframes.load.success", keyframes.size, result.getFileName()));
} catch (RuntimeException e) {
logger.error(I18n.txt("gui.keyframes.load.error", result.getFileName()), e);
Label warn = new OwnLabel(I18n.txt("error.loading.format", result.getFileName()), skin);
warn.setColor(1f, .4f, .4f, 1f);
notice.setActor(warn);
return false;
}
} else {
logger.error(I18n.txt("error.loading.notexistent", result.getFileName()));
Label warn = new OwnLabel(I18n.txt("error.loading.notexistent", result.getFileName()), skin);
warn.setColor(1f, .4f, .4f, 1f);
notice.setActor(warn);
return false;
}
}
notice.clearActor();
return true;
});
fc.show(stage);
return true;
}
return false;
});
// Save keyframes
OwnTextIconButton save = new OwnTextIconButton(I18n.txt("gui.keyframes.save"), skin, "save");
save.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.save"), skin));
save.pad(pad5);
save.addListener((event) -> {
if (event instanceof ChangeEvent) {
String suggestedName = lastKeyframeFileName == null ? df.format(new Date()) + "_keyframes.gkf" : lastKeyframeFileName;
FileNameWindow fnw = new FileNameWindow(suggestedName, stage, skin);
OwnTextField textField = fnw.getFileNameField();
fnw.setAcceptRunnable(() -> {
if (textField.isValid()) {
EventManager.publish(Event.KEYFRAMES_FILE_SAVE, fnw, keyframes, textField.getText());
lastKeyframeFileName = textField.getText();
notice.clearActor();
} else {
Label warn = new OwnLabel(I18n.txt("error.file.name.notvalid", textField.getText()), skin);
warn.setColor(1f, .4f, .4f, 1f);
notice.setActor(warn);
}
});
fnw.show(stage);
return true;
}
return false;
});
// Export to camera path
OwnTextIconButton export = new OwnTextIconButton(I18n.txt("gui.keyframes.export"), skin, "export");
export.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.export"), skin));
export.pad(pad5);
export.addListener((event) -> {
if (event instanceof ChangeEvent) {
String suggestedName = df.format(new Date()) + ".gsc";
FileNameWindow fnw = new FileNameWindow(suggestedName, stage, skin);
OwnTextField textField = fnw.getFileNameField();
fnw.setAcceptRunnable(() -> {
if (textField.isValid()) {
EventManager.publish(Event.KEYFRAMES_EXPORT, fnw, keyframes, textField.getText());
notice.clearActor();
} else {
Label warn = new OwnLabel(I18n.txt("error.file.name.notvalid", textField.getText()), skin);
warn.setColor(1f, .4f, .4f, 1f);
notice.setActor(warn);
}
});
fnw.show(stage);
return true;
}
return false;
});
// Keyframe preferences
Button preferences = new OwnTextIconButton(I18n.txt("gui.preferences"), skin, "preferences");
preferences.setName("keyframe preferences");
preferences.pad(pad5);
preferences.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.editprefs"), skin));
preferences.addListener((event) -> {
if (event instanceof ChangeEvent) {
KeyframePreferencesWindow kpw = new KeyframePreferencesWindow(stage, skin);
kpw.setAcceptRunnable(() -> {
// Resample
GaiaSky.postRunnable(() -> {
keyframesPathObject.resamplePath();
});
});
kpw.setCancelRunnable(() -> {
});
kpw.show(stage, me.getWidth(), 0);
return true;
}
return false;
});
buttons.addActor(open);
buttons.addActor(save);
buttons.addActor(export);
buttons.addActor(preferences);
/* FINAL LAYOUT */
content.add(left).top().left().padRight(pad10 * 2f).padBottom(pad10 * 3f);
content.add(right).width(592f).top().left().padBottom(pad10).row();
notice = content.add();
notice.padBottom(pad10 * 2f).expandY().center().colspan(2).row();
content.add(normalizeTime).colspan(2).bottom().center().padBottom(pad10).row();
content.add(buttons).colspan(2).bottom().right().row();
// CLEAR
OwnTextButton clear = new OwnTextButton(I18n.txt("gui.clear"), skin);
clear.setName("clear");
clear.addListener((event) -> {
if (event instanceof ChangeEvent) {
GaiaSky.postRunnable(this::clean);
return true;
}
return false;
});
buttonGroup.addActorAt(0, clear);
// HIDE
OwnTextButton hide = new OwnTextButton(I18n.txt("gui.hide"), skin);
hide.setName("hide");
hide.addListener((event) -> {
if (event instanceof ChangeEvent) {
hide();
return true;
}
return false;
});
buttonGroup.addActorAt(1, hide);
recalculateButtonSize();
}
use of gaiasky.util.validator.RegexpValidator 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);
}
use of gaiasky.util.validator.RegexpValidator in project gaiasky by langurmonkey.
the class KeyframesWindow method addFrameName.
private void addFrameName(Keyframe kf, int index, Table table) {
// Seconds
OwnLabel nameL = new OwnLabel((index + 1) + ": " + kf.name, skin);
nameL.setWidth(160f);
Cell<?> nameCell;
if (namesCells.containsKey(kf))
nameCell = namesCells.get(kf);
else {
nameCell = table.add();
namesCells.put(kf, nameCell);
}
nameCell.clearActor();
nameCell.setActor(nameL).left().padRight(pad10 / 2f).padBottom(pad5);
keyframeNames.put(kf, nameL);
nameL.addListener(new OwnTextTooltip(I18n.txt("gui.tooltip.kf.name"), skin));
nameL.addListener((event) -> {
if (event instanceof InputEvent) {
InputEvent ie = (InputEvent) event;
if (ie.getType() == InputEvent.Type.touchDown) {
if (editing.notEmpty()) {
// Remove current
editing.revert();
editing.unset();
}
String valText = nameL.getText().toString();
valText = valText.substring(valText.indexOf(":") + 2);
nameL.clear();
keyframeNames.remove(kf);
namesCells.get(kf).clearActor();
LengthValidator lengthValidator = new LengthValidator(0, 15);
RegexpValidator nameValidator = new RegexpValidator(lengthValidator, "^[^*&%\\+\\=\\\\\\/@#\\$&\\*()~]*$");
OwnTextField nameInput = new OwnTextField(valText, skin, nameValidator);
nameInput.setWidth(160f);
nameInput.selectAll();
stage.setKeyboardFocus(nameInput);
editing.setName(kf, index, nameInput);
nameInput.addListener((evt) -> {
if (nameInput.isValid() && evt instanceof InputEvent && System.currentTimeMillis() - lastMs > 1500) {
InputEvent ievt = (InputEvent) evt;
if (ievt.getType() == InputEvent.Type.keyDown && (ievt.getKeyCode() == Input.Keys.ENTER || ievt.getKeyCode() == Input.Keys.ESCAPE)) {
kf.name = nameInput.getText();
addFrameName(kf, index, table);
editing.unset();
}
}
evt.setBubbles(false);
return true;
});
namesCells.get(kf).setActor(nameInput);
lastMs = System.currentTimeMillis();
}
}
return true;
});
addHighlightListener(nameL, kf);
}
Aggregations