use of org.jwildfire.create.tina.variation.RessourceType 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.create.tina.variation.RessourceType in project JWildfire by thargor6.
the class IFlamesFunc method getRessourceType.
@Override
public RessourceType getRessourceType(String pName) {
RessourceType res;
res = imageParams.getRessourceType(pName);
if (res != null) {
return res;
}
res = motionParams.getRessourceType(pName);
if (res != null) {
return res;
}
res = flameParams.getRessourceType(pName);
if (res != null) {
return res;
}
throw new IllegalArgumentException(pName);
}
Aggregations