Search in sources :

Example 1 with ImageFileChooser

use of org.jwildfire.swing.ImageFileChooser in project JWildfire by thargor6.

the class FlameControlsDelegate method solidRenderingMaterialSelectReflMapBtn_clicked.

public void solidRenderingMaterialSelectReflMapBtn_clicked() {
    MaterialSettings material = getSolidRenderingSelectedMaterial();
    if (material != null) {
        JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
        if (Prefs.getPrefs().getInputImagePath() != null) {
            try {
                if (getCurrFlame().getBGImageFilename().length() > 0) {
                    chooser.setSelectedFile(new File(getCurrFlame().getBGImageFilename()));
                } else {
                    chooser.setCurrentDirectory(new File(Prefs.getPrefs().getInputImagePath()));
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if (chooser.showOpenDialog(owner.getFlamePanel()) == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            try {
                String filename = file.getAbsolutePath();
                WFImage img = RessourceManager.getImage(filename);
                if (img.getImageWidth() < 2 || img.getImageHeight() < 2 || !(img instanceof SimpleImage)) {
                    throw new Exception("Invalid image");
                }
                Prefs.getPrefs().setLastInputImageFile(file);
                owner.saveUndoPoint();
                material.setReflMapFilename(filename);
                refreshReflMapColorIndicator();
                owner.refreshFlameImage(true, false, 1, true, false);
            } catch (Throwable ex) {
                owner.errorHandler.handleError(ex);
            }
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) WFImage(org.jwildfire.image.WFImage) MaterialSettings(org.jwildfire.create.tina.base.solidrender.MaterialSettings) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) SimpleImage(org.jwildfire.image.SimpleImage) File(java.io.File)

Example 2 with ImageFileChooser

use of org.jwildfire.swing.ImageFileChooser in project JWildfire by thargor6.

the class FlamesGPURenderController method saveImageButton_clicked.

public void saveImageButton_clicked() {
    try {
        JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
        if (prefs.getOutputImagePath() != null) {
            try {
                chooser.setCurrentDirectory(new File(prefs.getOutputImagePath()));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
        if (chooser.showSaveDialog(imageRootPanel) == JFileChooser.APPROVE_OPTION) {
            File file = chooser.getSelectedFile();
            new ImageWriter().saveImage(image, file.getAbsolutePath());
            if (prefs.isTinaSaveFlamesWhenImageIsSaved()) {
                new FlameWriter().writeFlame(getCurrFlame(), file.getParentFile().getAbsolutePath() + File.separator + Tools.trimFileExt(file.getName()) + ".flame");
            }
            // if (autoLoadImageCBx.isSelected()) {
            parentCtrl.mainController.loadImage(file.getAbsolutePath(), false);
        // }
        }
    } catch (Throwable ex) {
        errorHandler.handleError(ex);
    }
}
Also used : FACLFlameWriter(org.jwildfire.create.tina.faclrender.FACLFlameWriter) FlameWriter(org.jwildfire.create.tina.io.FlameWriter) JFileChooser(javax.swing.JFileChooser) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) ImageWriter(org.jwildfire.io.ImageWriter) File(java.io.File)

Example 3 with ImageFileChooser

use of org.jwildfire.swing.ImageFileChooser in project JWildfire by thargor6.

the class TinaController method grabPaletteFromImageButton_actionPerformed.

public void grabPaletteFromImageButton_actionPerformed(ActionEvent e) {
    JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
    if (prefs.getInputImagePath() != null) {
        try {
            chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
            SimpleImage img = new ImageReader(centerPanel).loadImage(file.getAbsolutePath());
            prefs.setLastInputImageFile(file);
            RGBPalette palette = new MedianCutQuantizer().createPalette(img);
            data.paletteKeyFrames = null;
            saveUndoPoint();
            getCurrLayer().setPalette(palette);
            setLastGradient(palette);
            refreshPaletteColorsTable();
            refreshPaletteUI(palette);
            refreshFlameImage(true, false, 1, true, false);
        } catch (Throwable ex) {
            errorHandler.handleError(ex);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) RGBPalette(org.jwildfire.create.tina.palette.RGBPalette) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) SimpleImage(org.jwildfire.image.SimpleImage) ImageReader(org.jwildfire.io.ImageReader) File(java.io.File) MedianCutQuantizer(org.jwildfire.create.tina.palette.MedianCutQuantizer)

Example 4 with ImageFileChooser

use of org.jwildfire.swing.ImageFileChooser in project JWildfire by thargor6.

the class TinaController method nonlinearParamsREdChanged.

public void nonlinearParamsREdChanged(int pIdx, double pDelta) {
    if (cmbRefreshing) {
        return;
    }
    cmbRefreshing = true;
    try {
        String selected = (String) data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsCmb().getSelectedItem();
        XForm xForm = getCurrXForm();
        if (xForm != null && selected != null && selected.length() > 0) {
            saveUndoPoint();
            if (pIdx < xForm.getVariationCount()) {
                final Variation var = xForm.getVariation(pIdx);
                int idx;
                if ((idx = var.getFunc().getParameterIndex(selected)) >= 0) {
                    String valStr = data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsREd().getText();
                    if (valStr == null || valStr.length() == 0) {
                        valStr = "0";
                    }
                    // round the delta to whole numbers if the parameter is of type integer
                    if (Math.abs(pDelta) > MathLib.EPSILON) {
                        Object val = var.getFunc().getParameterValues()[idx];
                        if (val != null && val instanceof Integer) {
                            if (Math.abs(pDelta) < 1.0) {
                                pDelta = pDelta < 0 ? -1 : 1;
                            } else {
                                pDelta = Math.round(pDelta);
                            }
                        }
                    }
                    double val = Tools.stringToDouble(valStr) + pDelta;
                    var.getFunc().setParameter(selected, val);
                    if (var.getFunc().dynamicParameterExpansion(selected)) {
                        // if setting the parameter can change the total number of parameters,
                        // then refresh parameter UI (and reselect parameter that was changed)
                        this.refreshParamControls(data.TinaNonlinearControlsRows[pIdx], xForm, var, false);
                        data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsCmb().setSelectedItem(selected);
                    }
                    data.TinaNonlinearControlsRows[pIdx].getNonlinearParamsREd().setText(Tools.doubleToString(val));
                    data.TinaNonlinearControlsRows[pIdx].refreshParamWithoutRefresh(selected, val);
                } else if ((idx = var.getFunc().getRessourceIndex(selected)) >= 0) {
                    final String rName = var.getFunc().getRessourceNames()[idx];
                    RessourceType resType = var.getFunc().getRessourceType(rName);
                    switch(resType) {
                        case FONT_NAME:
                            {
                                String oldFontname = null;
                                {
                                    byte[] val = var.getFunc().getRessourceValues()[idx];
                                    if (val != null) {
                                        oldFontname = new String(val);
                                    }
                                }
                                Font oldFont = new Font(oldFontname != null ? oldFontname : "Arial", Font.PLAIN, 24);
                                Font selectedFont = JFontChooser.showDialog(centerPanel, "Choose font", oldFont);
                                if (selectedFont != null) {
                                    String valStr = selectedFont.getFontName();
                                    byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                    var.getFunc().setRessource(rName, valByteArray);
                                }
                            }
                            break;
                        case IMAGE_FILENAME:
                            {
                                String oldFilename = null;
                                {
                                    byte[] val = var.getFunc().getRessourceValues()[idx];
                                    if (val != null) {
                                        oldFilename = new String(val);
                                    }
                                }
                                JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
                                if (oldFilename != null && oldFilename.length() > 0) {
                                    try {
                                        chooser.setCurrentDirectory(new File(oldFilename).getAbsoluteFile().getParentFile());
                                        chooser.setSelectedFile(new File(oldFilename));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                } else {
                                    if (prefs.getInputImagePath() != null) {
                                        try {
                                            chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                        }
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    File file = chooser.getSelectedFile();
                                    String valStr = file.getAbsolutePath();
                                    byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                    var.getFunc().setRessource(rName, valByteArray);
                                }
                            }
                            break;
                        case FLAME_FILENAME:
                            {
                                String oldFilename = null;
                                {
                                    byte[] val = var.getFunc().getRessourceValues()[idx];
                                    if (val != null) {
                                        oldFilename = new String(val);
                                    }
                                }
                                JFileChooser chooser = new FlameFileChooser(Prefs.getPrefs());
                                if (oldFilename != null && oldFilename.length() > 0) {
                                    try {
                                        chooser.setCurrentDirectory(new File(oldFilename).getAbsoluteFile().getParentFile());
                                        chooser.setSelectedFile(new File(oldFilename));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                } else {
                                    if (prefs.getInputImagePath() != null) {
                                        try {
                                            chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                        }
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    File file = chooser.getSelectedFile();
                                    String valStr = file.getAbsolutePath();
                                    byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                    var.getFunc().setRessource(rName, valByteArray);
                                }
                            }
                            break;
                        case IMAGE_FILE:
                            {
                                JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
                                if (prefs.getInputImagePath() != null) {
                                    try {
                                        chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    try {
                                        File file = chooser.getSelectedFile();
                                        byte[] imgData = Tools.readFile(file.getAbsolutePath());
                                        var.getFunc().setRessource(rName, imgData);
                                    } catch (Exception ex) {
                                        errorHandler.handleError(ex);
                                    }
                                }
                            }
                            break;
                        case SVG_FILE:
                            {
                                JFileChooser chooser = new SvgFileChooser(prefs);
                                if (prefs.getTinaSVGPath() != null) {
                                    try {
                                        chooser.setCurrentDirectory(new File(prefs.getTinaSVGPath()));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    try {
                                        File file = chooser.getSelectedFile();
                                        String svg = Tools.readUTF8Textfile(file.getAbsolutePath());
                                        byte[] valByteArray = svg.getBytes();
                                        var.getFunc().setRessource(rName, valByteArray);
                                    } catch (Exception ex) {
                                        errorHandler.handleError(ex);
                                    }
                                }
                            }
                            break;
                        case OBJ_MESH:
                            {
                                JFileChooser chooser = new MeshFileChooser(prefs);
                                if (prefs.getTinaMeshPath() != null) {
                                    try {
                                        chooser.setCurrentDirectory(new File(prefs.getTinaMeshPath()));
                                    } catch (Exception ex) {
                                        ex.printStackTrace();
                                    }
                                }
                                if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
                                    try {
                                        File file = chooser.getSelectedFile();
                                        var.getFunc().setRessource(rName, file.getAbsolutePath().getBytes());
                                    } catch (Exception ex) {
                                        errorHandler.handleError(ex);
                                    }
                                }
                            }
                            break;
                        default:
                            {
                                final RessourceDialog dlg = new RessourceDialog(SwingUtilities.getWindowAncestor(centerPanel), prefs, errorHandler);
                                dlg.setRessourceName(rName);
                                byte[] val = var.getFunc().getRessourceValues()[idx];
                                RessourceType type = var.getFunc().getRessourceType(rName);
                                RessourceDialog.ContentType ct = type == RessourceType.JAVA_CODE ? RessourceDialog.ContentType.JAVA : RessourceDialog.ContentType.TEXT;
                                if (val != null) {
                                    dlg.setRessourceValue(ct, new String(val));
                                }
                                dlg.addValidation(new RessourceValidation() {

                                    @Override
                                    public void validate() {
                                        String valStr = dlg.getRessourceValue();
                                        byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                        byte[] oldValue = var.getFunc().getRessource(rName);
                                        try {
                                            var.getFunc().setRessource(rName, valByteArray);
                                            var.getFunc().validate();
                                        } catch (Throwable ex) {
                                            var.getFunc().setRessource(rName, oldValue);
                                            throw new RuntimeException(ex);
                                        }
                                    }
                                });
                                dlg.setModal(true);
                                dlg.setVisible(true);
                                if (dlg.isConfirmed()) {
                                    try {
                                        String valStr = dlg.getRessourceValue();
                                        byte[] valByteArray = valStr != null ? valStr.getBytes() : null;
                                        var.getFunc().setRessource(rName, valByteArray);
                                        if (var.getFunc().ressourceCanModifyParams(rName)) {
                                            // forcing refresh of params UI in case setting resource changes available params or param values
                                            this.refreshParamControls(data.TinaNonlinearControlsRows[pIdx], xForm, var, true);
                                        }
                                    } catch (Throwable ex) {
                                        errorHandler.handleError(ex);
                                    }
                                }
                            }
                    }
                }
                refreshFlameImage(true, false, 1, true, false);
            }
        }
        resizeNonlinearParamsPanel();
    } finally {
        cmbRefreshing = false;
    }
}
Also used : XForm(org.jwildfire.create.tina.base.XForm) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) Font(java.awt.Font) JFileChooser(javax.swing.JFileChooser) Variation(org.jwildfire.create.tina.variation.Variation) File(java.io.File) RessourceType(org.jwildfire.create.tina.variation.RessourceType)

Example 5 with ImageFileChooser

use of org.jwildfire.swing.ImageFileChooser in project JWildfire by thargor6.

the class TinaController method selectImageForBackgroundButton_actionPerformed.

public void selectImageForBackgroundButton_actionPerformed(ActionEvent e) {
    JFileChooser chooser = new ImageFileChooser(Tools.FILEEXT_PNG);
    if (prefs.getInputImagePath() != null) {
        try {
            if (getCurrFlame().getBGImageFilename().length() > 0) {
                chooser.setSelectedFile(new File(getCurrFlame().getBGImageFilename()));
            } else {
                chooser.setCurrentDirectory(new File(prefs.getInputImagePath()));
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
            String filename = file.getAbsolutePath();
            WFImage img = RessourceManager.getImage(filename);
            if (img.getImageWidth() < 2 || img.getImageHeight() < 2 || !(img instanceof SimpleImage)) {
                throw new Exception("Invalid background image");
            }
            prefs.setLastInputImageFile(file);
            saveUndoPoint();
            getCurrFlame().setBGImageFilename(filename);
            refreshFlameImage(true, false, 1, true, true);
        } catch (Throwable ex) {
            errorHandler.handleError(ex);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) WFImage(org.jwildfire.image.WFImage) ImageFileChooser(org.jwildfire.swing.ImageFileChooser) SimpleImage(org.jwildfire.image.SimpleImage) File(java.io.File)

Aggregations

File (java.io.File)12 JFileChooser (javax.swing.JFileChooser)12 ImageFileChooser (org.jwildfire.swing.ImageFileChooser)12 SimpleImage (org.jwildfire.image.SimpleImage)5 RenderedFlame (org.jwildfire.create.tina.render.RenderedFlame)4 WFImage (org.jwildfire.image.WFImage)4 ImageWriter (org.jwildfire.io.ImageWriter)3 Flame (org.jwildfire.create.tina.base.Flame)2 FlameWriter (org.jwildfire.create.tina.io.FlameWriter)2 RGBPalette (org.jwildfire.create.tina.palette.RGBPalette)2 Font (java.awt.Font)1 QualityProfile (org.jwildfire.base.QualityProfile)1 ResolutionProfile (org.jwildfire.base.ResolutionProfile)1 XForm (org.jwildfire.create.tina.base.XForm)1 MaterialSettings (org.jwildfire.create.tina.base.solidrender.MaterialSettings)1 FACLFlameWriter (org.jwildfire.create.tina.faclrender.FACLFlameWriter)1 MeshGenRenderThread (org.jwildfire.create.tina.meshgen.render.MeshGenRenderThread)1 RenderPointCloudThread (org.jwildfire.create.tina.meshgen.render.RenderPointCloudThread)1 RenderSlicesThread (org.jwildfire.create.tina.meshgen.render.RenderSlicesThread)1 MedianCutQuantizer (org.jwildfire.create.tina.palette.MedianCutQuantizer)1