use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.
the class EnvelopeDialog method findProperty.
private String findProperty(Object pObject, Object pProperty, String pPath) {
if (pObject == pProperty) {
return pPath;
}
Class<?> cls = pObject.getClass();
for (Field field : cls.getDeclaredFields()) {
field.setAccessible(true);
Object fieldValue;
try {
fieldValue = field.get(pObject);
} catch (Exception ex) {
fieldValue = null;
}
if (fieldValue != null) {
if (fieldValue == pProperty) {
String pathExt = field.getName();
return pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
}
if (fieldValue instanceof List) {
List<?> list = (List<?>) fieldValue;
for (int i = 0; i < list.size(); i++) {
String pathExt = field.getName() + "[" + i + "]";
String subPath = pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
String subResult = findProperty(list.get(i), pProperty, subPath);
if (subResult != null) {
return subResult;
}
}
} else if (fieldValue instanceof Map) {
Map<?, ?> map = (Map<?, ?>) fieldValue;
Set<?> entrySet = map.entrySet();
for (Object obj : entrySet) {
Entry<?, ?> entry = (Entry<?, ?>) obj;
String pathExt = field.getName() + "[" + entry.getKey().toString() + "]";
String subPath = pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
String subResult = findProperty(entry.getValue(), pProperty, subPath);
if (subResult != null) {
return subResult;
}
}
} else if (fieldValue instanceof RGBPalette) {
RGBPalette palette = (RGBPalette) fieldValue;
String pathExt = field.getName();
String subPath = pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
String subResult = findProperty(palette, pProperty, subPath);
if (subResult != null) {
return subResult;
}
} else if (fieldValue instanceof SolidRenderSettings) {
SolidRenderSettings settings = (SolidRenderSettings) fieldValue;
String pathExt = field.getName();
String subPath = pPath == null ? pathExt : pPath + PATH_SEPARATOR + pathExt;
String subResult = findProperty(settings, pProperty, subPath);
if (subResult != null) {
return subResult;
}
}
}
}
return null;
}
use of org.jwildfire.create.tina.palette.RGBPalette 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.create.tina.palette.RGBPalette in project JWildfire by thargor6.
the class TinaController method grabPaletteFromFlameButton_actionPerformed.
public void grabPaletteFromFlameButton_actionPerformed(ActionEvent e) {
JFileChooser chooser = new FlameFileChooser(prefs);
if (prefs.getInputFlamePath() != null) {
try {
chooser.setCurrentDirectory(new File(prefs.getInputFlamePath()));
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (chooser.showOpenDialog(centerPanel) == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
List<Flame> flames = new FlameReader(prefs).readFlames(file.getAbsolutePath());
Flame flame = flames.get(0);
prefs.setLastInputFlameFile(file);
RGBPalette palette = flame.getFirstLayer().getPalette();
data.paletteKeyFrames = null;
saveUndoPoint();
getCurrLayer().setPalette(palette);
setLastGradient(palette);
refreshPaletteColorsTable();
refreshPaletteUI(palette);
refreshFlameImage(true, false, 1, true, false);
}
}
use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.
the class TinaController method refreshPaletteColorsTable.
private void refreshPaletteColorsTable() {
final int COL_COLOR = 0;
final int COL_RED = 1;
final int COL_GREEN = 2;
final int COL_BLUE = 3;
data.createPaletteColorsTable.setDefaultRenderer(Object.class, new PaletteTableCustomRenderer());
data.createPaletteColorsTable.setModel(new DefaultTableModel() {
private static final long serialVersionUID = 1L;
@Override
public int getRowCount() {
return Integer.parseInt(data.paletteRandomPointsREd.getText());
}
@Override
public int getColumnCount() {
return 4;
}
@Override
public String getColumnName(int columnIndex) {
switch(columnIndex) {
case COL_COLOR:
return "Color";
case COL_RED:
return "Red";
case COL_GREEN:
return "Green";
case COL_BLUE:
return "Blue";
}
return null;
}
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
if (data.paletteKeyFrames != null && data.paletteKeyFrames.size() > rowIndex) {
switch(columnIndex) {
case COL_COLOR:
return String.valueOf(rowIndex + 1);
case COL_RED:
return String.valueOf(data.paletteKeyFrames.get(rowIndex).getRed());
case COL_GREEN:
return String.valueOf(data.paletteKeyFrames.get(rowIndex).getGreen());
case COL_BLUE:
return String.valueOf(data.paletteKeyFrames.get(rowIndex).getBlue());
}
}
return null;
}
@Override
public boolean isCellEditable(int row, int column) {
return column == COL_RED || column == COL_GREEN || column == COL_BLUE;
}
@Override
public void setValueAt(Object aValue, int row, int column) {
if (getCurrFlame() != null && data.paletteKeyFrames != null && data.paletteKeyFrames.size() > row) {
String valStr = (String) aValue;
if (valStr == null || valStr.length() == 0) {
valStr = "0";
}
switch(column) {
case COL_RED:
data.paletteKeyFrames.get(row).setRed(Tools.limitColor(Tools.stringToInt(valStr)));
break;
case COL_GREEN:
data.paletteKeyFrames.get(row).setGreen(Tools.limitColor(Tools.stringToInt(valStr)));
break;
case COL_BLUE:
data.paletteKeyFrames.get(row).setBlue(Tools.limitColor(Tools.stringToInt(valStr)));
break;
default:
// nothing to do
break;
}
refreshPaletteColorsTable();
RGBPalette palette = RandomGradientGenerator.generatePalette(data.paletteKeyFrames, data.paletteFadeColorsCBx.isSelected(), data.paletteUniformWidthCBx.isSelected());
saveUndoPoint();
getCurrLayer().setPalette(palette);
setLastGradient(palette);
refreshPaletteUI(palette);
refreshFlameImage(true, false, 1, true, false);
}
super.setValueAt(aValue, row, column);
}
});
data.createPaletteColorsTable.getTableHeader().setFont(data.transformationsTable.getFont());
data.createPaletteColorsTable.getColumnModel().getColumn(COL_COLOR).setWidth(20);
data.createPaletteColorsTable.getColumnModel().getColumn(COL_RED).setPreferredWidth(60);
data.createPaletteColorsTable.getColumnModel().getColumn(COL_GREEN).setPreferredWidth(60);
data.createPaletteColorsTable.getColumnModel().getColumn(COL_BLUE).setPreferredWidth(60);
}
use of org.jwildfire.create.tina.palette.RGBPalette in project JWildfire by thargor6.
the class TinaController method addLayerBtn_clicked.
public void addLayerBtn_clicked() {
Flame flame = getCurrFlame();
Layer layer = new Layer();
RGBPalette palette = RandomGradientGeneratorList.getRandomGradientGeneratorInstance((String) data.paletteRandomGeneratorCmb.getSelectedItem()).generatePalette(Integer.parseInt(data.paletteRandomPointsREd.getText()), data.paletteFadeColorsCBx.isSelected(), data.paletteUniformWidthCBx.isSelected());
layer.setPalette(palette);
setLastGradient(palette);
saveUndoPoint();
flame.getLayers().add(layer);
gridRefreshing = true;
try {
refreshLayersTable();
} finally {
gridRefreshing = false;
}
int row = getCurrFlame().getLayers().size() - 1;
data.layersTable.getSelectionModel().setSelectionInterval(row, row);
}
Aggregations