use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class ListWidgetElement method create.
public static ListWidgetElement<ContainerDTO> create(ContainerDTO container) {
final List<BufferedImage> miniatures = new ArrayList<>();
// do not use too many segments (cannot recognize the miniature if the segment is too small)
final int maxSegments = 4;
int currentSegment = 0;
for (ShortcutDTO shortcutDTO : container.getInstalledShortcuts()) {
if (currentSegment >= maxSegments) {
break;
}
try {
miniatures.add(ImageIO.read(shortcutDTO.getMiniature().toURL()));
currentSegment++;
} catch (IOException e) {
LOGGER.warn(String.format("Could not read miniature for shortcut \"%s\"", shortcutDTO.getInfo().getName()), e);
}
}
final BufferedImage segmentedMiniature = createSegmentedMiniature(miniatures);
final Optional<URI> shortcutMiniature = saveBufferedImage(segmentedMiniature, container.getName());
return new ListWidgetElement<>(container, shortcutMiniature, CONTAINER_MINIATURE, container.getName(), Collections.emptyList(), Collections.emptyList());
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class LibraryFeaturePanelSkin method createContent.
/**
* {@inheritDoc}
*/
@Override
public ObjectExpression<Node> createContent() {
final CombinedListWidget<ShortcutDTO> combinedListWidget = createCombinedListWidget();
final Tab installedApplicationsTab = new Tab(tr("My applications"), combinedListWidget);
installedApplicationsTab.setClosable(false);
final TabPane container = new TabPane();
container.getStyleClass().add("rightPane");
getControl().selectedTabProperty().addListener((Observable invalidation) -> {
final Tab selectedTab = getControl().getSelectedTab();
if (selectedTab != null) {
container.getSelectionModel().select(selectedTab);
} else {
container.getSelectionModel().selectFirst();
}
});
container.getSelectionModel().selectedItemProperty().addListener((Observable invalidation) -> getControl().setSelectedTab(container.getSelectionModel().getSelectedItem()));
Bindings.bindContentBidirectional(container.getTabs(), getControl().getTabs());
container.getTabs().add(installedApplicationsTab);
return new SimpleObjectProperty<>(container);
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class EditShortcutPanel method setShortcutDTO.
/**
* sets the shortcut which can be edited in this view
* @param shortcutDTO
*/
public void setShortcutDTO(ShortcutDTO shortcutDTO) {
this.editedShortcut = shortcutDTO;
this.setTitle(this.editedShortcut.getInfo().getName());
this.description.setText(this.editedShortcut.getInfo().getDescription());
this.gridPane.getChildren().clear();
// miniature
Label miniatureLabel = new Label(tr("Miniature:"));
miniatureLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(miniatureLabel, VPos.TOP);
this.gridPane.add(miniatureLabel, 0, 0);
TextField miniaturePathField = new TextField(this.editedShortcut.getMiniature().getPath());
Button openBrowser = new Button(tr("Choose"));
openBrowser.setOnAction(event -> {
FileChooser chooser = new FileChooser();
chooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter(tr("Images"), "*.miniature, *.png"));
File defaultFile = new File(this.editedShortcut.getMiniature());
chooser.setInitialDirectory(defaultFile.getParentFile());
File newMiniature = chooser.showOpenDialog(null);
miniaturePathField.setText(newMiniature.toString());
this.editedShortcut = new ShortcutDTO.Builder(this.editedShortcut).withMiniature(newMiniature.toURI()).build();
});
HBox content = new HBox(miniaturePathField, openBrowser);
HBox.setHgrow(miniaturePathField, Priority.ALWAYS);
this.gridPane.add(content, 1, 0);
// shortcut script
try {
LOGGER.info("Reading shortcut: {}", this.editedShortcut.getScript());
final Map<String, Object> shortcutProperties = objectMapper.readValue(this.editedShortcut.getScript(), new TypeReference<Map<String, Object>>() {
});
int row = 1;
for (Map.Entry<String, Object> entry : shortcutProperties.entrySet()) {
final Label keyLabel = new Label(tr(unCamelize(entry.getKey())) + ":");
keyLabel.getStyleClass().add(CAPTION_TITLE_CSS_CLASS);
GridPane.setValignment(keyLabel, VPos.TOP);
this.gridPane.add(keyLabel, 0, row);
final TextArea valueLabel = new TextArea(entry.getValue().toString());
valueLabel.setWrapText(true);
valueLabel.setPrefRowCount(entry.getValue().toString().length() / 25);
valueLabel.focusedProperty().addListener((observable, oldValue, newValue) -> {
// update shortcut if TextArea looses focus (doesn't save yet)
if (!newValue) {
shortcutProperties.replace(entry.getKey(), valueLabel.getText());
try {
String json = new ObjectMapper().writeValueAsString(shortcutProperties);
this.editedShortcut = new ShortcutDTO.Builder(this.editedShortcut).withScript(json).build();
} catch (JsonProcessingException e) {
LOGGER.error("Creating new shortcut String failed.", e);
}
}
});
this.gridPane.add(valueLabel, 1, row);
row++;
}
} catch (IOException e) {
LOGGER.warn("Could not parse shortcut script JSON", e);
}
this.saveButton.setOnMouseClicked(event -> {
this.onShortcutChanged.accept(this.editedShortcut);
});
}
use of org.phoenicis.library.dto.ShortcutDTO in project POL-POM-5 by PhoenicisOrg.
the class ListWidgetEntry method create.
public static ListWidgetEntry<ContainerDTO> create(ContainerDTO container) {
final List<BufferedImage> miniatures = new ArrayList<>();
// do not use too many segments (cannot recognize the miniature if the segment is too small)
final int maxSegments = 4;
int currentSegment = 0;
for (ShortcutDTO shortcutDTO : container.getInstalledShortcuts()) {
if (currentSegment >= maxSegments) {
break;
}
try {
miniatures.add(ImageIO.read(shortcutDTO.getMiniature().toURL()));
currentSegment++;
} catch (IOException e) {
LOGGER.warn(String.format("Could not read miniature for shortcut \"%s\"", shortcutDTO.getInfo().getName()), e);
}
}
final BufferedImage segmentedMiniature = createSegmentedMiniature(miniatures);
final Optional<URI> shortcutMiniature = saveBufferedImage(segmentedMiniature, container.getName());
return new ListWidgetEntry<>(container, shortcutMiniature, CONTAINER_MINIATURE, container.getName(), Optional.empty(), Optional.empty());
}
use of org.phoenicis.library.dto.ShortcutDTO in project phoenicis by PhoenicisOrg.
the class ShortcutManager method uninstallFromShortcut.
public void uninstallFromShortcut(ShortcutDTO shortcutDTO, Consumer<Exception> errorCallback) {
final InteractiveScriptSession interactiveScriptSession = scriptInterpreter.createInteractiveSession();
interactiveScriptSession.eval("include([\"Engines\", \"Wine\", \"Shortcuts\", \"Reader\"]);", ignored -> interactiveScriptSession.eval("new ShortcutReader()", output -> {
final ScriptObjectMirror shortcutReader = (ScriptObjectMirror) output;
shortcutReader.callMember("of", shortcutDTO);
shortcutReader.callMember("uninstall");
}, errorCallback), errorCallback);
}
Aggregations