Search in sources :

Example 16 with ShortcutDTO

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());
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URI(java.net.URI) BufferedImage(java.awt.image.BufferedImage) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO)

Example 17 with ShortcutDTO

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);
}
Also used : TabPane(javafx.scene.control.TabPane) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) Observable(javafx.beans.Observable)

Example 18 with ShortcutDTO

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);
    });
}
Also used : TextArea(javafx.scene.control.TextArea) Label(javafx.scene.control.Label) IOException(java.io.IOException) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) Button(javafx.scene.control.Button) FileChooser(javafx.stage.FileChooser) TextField(javafx.scene.control.TextField) File(java.io.File) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 19 with ShortcutDTO

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());
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URI(java.net.URI) BufferedImage(java.awt.image.BufferedImage) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO)

Example 20 with ShortcutDTO

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);
}
Also used : Logger(org.slf4j.Logger) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) ScriptInterpreter(org.phoenicis.scripts.interpreter.ScriptInterpreter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) File(java.io.File) ShortcutInfoDTO(org.phoenicis.library.dto.ShortcutInfoDTO) Consumer(java.util.function.Consumer) Safe(org.phoenicis.configuration.security.Safe) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) URI(java.net.URI) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession) ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) InteractiveScriptSession(org.phoenicis.scripts.interpreter.InteractiveScriptSession)

Aggregations

ShortcutDTO (org.phoenicis.library.dto.ShortcutDTO)30 File (java.io.File)18 IOException (java.io.IOException)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 URI (java.net.URI)12 ShortcutCategoryDTO (org.phoenicis.library.dto.ShortcutCategoryDTO)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Consumer (java.util.function.Consumer)8 List (java.util.List)7 ScriptInterpreter (org.phoenicis.scripts.interpreter.ScriptInterpreter)7 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)6 Observable (javafx.beans.Observable)6 ScriptObjectMirror (jdk.nashorn.api.scripting.ScriptObjectMirror)6 Safe (org.phoenicis.configuration.security.Safe)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 Collections (java.util.Collections)5 Collectors (java.util.stream.Collectors)5 ContainerCategoryDTO (org.phoenicis.containers.dto.ContainerCategoryDTO)5 ContainerDTO (org.phoenicis.containers.dto.ContainerDTO)5