Skip to content

Commit

Permalink
Add some basic sanity checks around editing emitters.
Browse files Browse the repository at this point in the history
  • Loading branch information
steffen-wilke committed Dec 14, 2021
1 parent 01da7e0 commit 73d9fa1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.function.Supplier;

public abstract class Particle implements ITimeToLive {

private static final Color DEFAULT_COLOR = Color.BLACK;
private long aliveTick;
private long aliveTime;
private float angle;
Expand Down Expand Up @@ -102,7 +104,7 @@ public Collision getCollisionType() {
}

public Color getColor() {
return this.color;
return this.color == null ? DEFAULT_COLOR : this.color;
}

public float getDeltaHeight() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,28 @@ protected LayoutManager createLayout() {

private void setupChangedListeners() {
btnAdd.addActionListener(
a -> model.addRow(new Object[] {ColorHelper.encode(EmitterData.DEFAULT_COLOR.brighter())}));
a -> model.addRow(new Object[]{ColorHelper.encode(EmitterData.DEFAULT_COLOR.brighter())}));
btnRemove.addActionListener(a -> model.removeRow(table.getSelectedRow()));
btnEdit.addActionListener(
a -> {
Color previousColor =
ColorHelper.decode(
table.getValueAt(table.getSelectedRow(), table.getSelectedColumn()).toString());
if (table.getSelectedRow() == -1 || table.getSelectedColumn() == -1) {
// setting a color requires a cell selection
return;
}

Color previousColor = null;
Object value = table.getValueAt(table.getSelectedRow(), table.getSelectedColumn());
if (value != null) {
previousColor = ColorHelper.decode(value.toString());
}

final Color result =
JColorChooser.showDialog(
null, Resources.strings().get("particle_editcolor"), previousColor);
if (result == null) {
return;
}

table.setValueAt(
ColorHelper.encode(result), table.getSelectedRow(), table.getSelectedColumn());
});
Expand Down

0 comments on commit 73d9fa1

Please sign in to comment.