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);
}
}
}
}
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);
}
}
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);
}
}
}
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;
}
}
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);
}
}
}
Aggregations