Skip to content

Commit 3ff2237

Browse files
committed
small improvements
1 parent 5bdfd97 commit 3ff2237

13 files changed

Lines changed: 283 additions & 105 deletions

File tree

src/main/java/pixelitor/filters/ColorThreshold.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public BufferedImage transform(BufferedImage src, BufferedImage dest) {
7070
int greenTh = greenThreshold.getValue();
7171
int blueTh = blueThreshold.getValue();
7272

73-
boolean dither = diffusionStrengthParam.getValue() != 0;
73+
boolean dither = diffusionStrengthParam.isNotZero();
7474
double diffusionStrength = diffusionStrengthParam.getPercentage();
7575
int ditheringMethod = ditheringMethodParam.getValue();
7676

src/main/java/pixelitor/filters/ColorWheel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ int toRGB(double angle, double sat, double bri) {
9191
public ColorWheel() {
9292
super(false);
9393

94+
helpURL = "https://en.wikipedia.org/wiki/Color_wheel";
95+
9496
initParams(type, center,
9597
hueRotParam, brgLumParam, satParam, spiralParam);
9698
}

src/main/java/pixelitor/filters/Posterize.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import pixelitor.filters.gui.RangeParam;
2424
import pixelitor.filters.lookup.RGBLookup;
2525
import pixelitor.filters.util.ColorSpace;
26+
import pixelitor.gui.GUIText;
2627
import pixelitor.utils.ColorSpaces;
2728
import pixelitor.utils.Dithering;
2829
import pixelitor.utils.ImageUtils;
@@ -81,14 +82,15 @@ private void updateSliders() {
8182
levels3.setName(i18n("blue"));
8283
}
8384
case OKLAB -> {
84-
levels1.setName("Green-Red (a)");
85-
levels2.setName("Blue-Yellow (b)");
86-
levels3.setName("Lightness");
85+
levels1.setName(GUIText.RED_GREEN_A);
86+
levels2.setName(GUIText.BLUE_YELLOW_B);
87+
levels3.setName(GUIText.LIGHTNESS);
8788
}
8889
}
8990
levelsParam.updateGUIAppearance();
9091
}
9192

93+
9294
@Override
9395
public BufferedImage transform(BufferedImage src, BufferedImage dest) {
9496
return switch (colorSpace.getSelected()) {

src/main/java/pixelitor/filters/Threshold.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import pixelitor.filters.gui.IntChoiceParam;
2222
import pixelitor.filters.gui.RangeParam;
2323
import pixelitor.filters.util.Channel;
24+
import pixelitor.filters.util.ColorSpace;
2425
import pixelitor.utils.Dithering;
2526
import pixelitor.utils.ImageUtils;
2627

@@ -47,7 +48,7 @@ public class Threshold extends ParametrizedFilter {
4748
@Serial
4849
private static final long serialVersionUID = 3739055511694844941L;
4950

50-
private final EnumParam<Channel> channelParam = Channel.asParam();
51+
private final EnumParam<Channel> channelParam = Channel.asParam(ColorSpace.SRGB);
5152
private final RangeParam thresholdParam = new RangeParam(THRESHOLD, 0, 128, 255);
5253
private final RangeParam diffusionStrengthParam = new RangeParam("Dithering Amount (%)", 0, 0, 100);
5354
private final IntChoiceParam ditheringMethodParam = Dithering.createDitheringChoices();
@@ -68,7 +69,7 @@ public Threshold() {
6869

6970
@Override
7071
public BufferedImage transform(BufferedImage src, BufferedImage dest) {
71-
boolean dither = diffusionStrengthParam.getValue() != 0;
72+
boolean dither = diffusionStrengthParam.isNotZero();
7273
double diffusionStrength = diffusionStrengthParam.getPercentage();
7374

7475
// a copy of the input is needed because error diffusion modifies the pixel data

src/main/java/pixelitor/filters/curves/ToneCurvesFilter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ public ToneCurvesGUI createGUI(Filterable layer, boolean reset) {
6060
return lastGUI;
6161
}
6262

63-
public ToneCurves getCurves() {
64-
return curves;
65-
}
66-
6763
@Override
6864
public BufferedImage transform(BufferedImage src, BufferedImage dest) {
6965
if (filter == null) {
@@ -86,6 +82,12 @@ public void randomize() {
8682
stateChanged();
8783
}
8884

85+
private void stateChanged() {
86+
if (lastGUI != null) { // it's null when loading a smart filter
87+
lastGUI.stateChanged();
88+
}
89+
}
90+
8991
@Override
9092
public void saveStateTo(UserPreset preset) {
9193
for (Channel channel : Channel.values()) {
@@ -104,9 +106,7 @@ public void loadUserPreset(UserPreset preset) {
104106
stateChanged();
105107
}
106108

107-
private void stateChanged() {
108-
if (lastGUI != null) { // it's null when loading a smart filter
109-
lastGUI.stateChanged();
110-
}
109+
public ToneCurves getCurves() {
110+
return curves;
111111
}
112112
}

src/main/java/pixelitor/filters/curves/ToneCurvesGUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private JPanel createChannelPanel(Channel activeChannel) {
6565
}
6666

6767
private JComboBox<Channel> createChannelsCombo(Channel activeChannel) {
68-
var channelCB = GUIUtils.createComboBox(Channel.values());
68+
var channelCB = GUIUtils.createComboBox(Channel.getRGBValues());
6969
channelCB.setSelectedItem(activeChannel);
7070
channelCB.addActionListener(e -> curvesPanel.setActiveCurve(
7171
(Channel) channelCB.getSelectedItem()));

src/main/java/pixelitor/filters/gui/ChoiceParam.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ public void setSelectedItem(E item, boolean trigger) {
106106
}
107107
}
108108

109+
public void setChoices(List<E> newChoices, boolean keepSelection) {
110+
if (newChoices == null || newChoices.isEmpty()) {
111+
throw new IllegalArgumentException();
112+
}
113+
E oldSelection = selectedValue;
114+
this.choices = List.copyOf(newChoices);
115+
116+
if (keepSelection && oldSelection != null && choices.contains(oldSelection)) {
117+
selectedValue = oldSelection;
118+
} else {
119+
selectedValue = choices.getFirst();
120+
}
121+
122+
fireContentsChanged(this, 0, getSize() - 1);
123+
124+
if (adjustmentListener != null) {
125+
adjustmentListener.paramAdjusted();
126+
}
127+
}
128+
109129
@Override
110130
public Object getSelectedItem() {
111131
return selectedValue;

src/main/java/pixelitor/filters/gui/EnumParam.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package pixelitor.filters.gui;
1919

20+
import java.util.List;
21+
2022
/**
2123
* A {@link ChoiceParam} for choosing a value from an enum.
2224
*/
@@ -25,6 +27,10 @@ public EnumParam(String name, Class<E> enumClass) {
2527
super(name, enumClass.getEnumConstants(), RandomizeMode.ALLOW_RANDOMIZE);
2628
}
2729

30+
public EnumParam(String name, List<E> choices) {
31+
super(name, choices, choices.getFirst(), RandomizeMode.ALLOW_RANDOMIZE);
32+
}
33+
2834
public EnumParam<E> withDefault(E item) {
2935
defaultValue = item;
3036
setSelectedItem(item, false);

src/main/java/pixelitor/filters/levels/LevelsGUI.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
package pixelitor.filters.levels;
1919

20-
import org.jdesktop.swingx.combobox.EnumComboBoxModel;
2120
import pixelitor.filters.Filter;
21+
import pixelitor.filters.gui.EnumParam;
2222
import pixelitor.filters.gui.FilterGUI;
2323
import pixelitor.filters.util.Channel;
24+
import pixelitor.filters.util.ColorSpace;
2425
import pixelitor.gui.utils.GUIUtils;
2526
import pixelitor.layers.Filterable;
2627

@@ -38,8 +39,7 @@
3839
* The {@link FilterGUI} for the {@link Levels} filter.
3940
*/
4041
public class LevelsGUI extends FilterGUI {
41-
private final EnumComboBoxModel<Channel> channelsModel
42-
= new EnumComboBoxModel<>(Channel.class);
42+
private final EnumParam<Channel> channelsModel = Channel.asParam(ColorSpace.SRGB);
4343

4444
private final JPanel cardPanel;
4545
private JCheckBox showOriginalCB;
@@ -61,7 +61,6 @@ public LevelsGUI(Filter filter, Filterable layer, LevelsModel model) {
6161
model.updateFilterLookup();
6262
}
6363

64-
@SuppressWarnings("unchecked")
6564
private JPanel createNorthPanel(LevelsModel model) {
6665
var northPanel = new JPanel(new FlowLayout());
6766
northPanel.add(new JLabel("Channel:"));
@@ -76,7 +75,7 @@ private JPanel createNorthPanel(LevelsModel model) {
7675
northPanel.add(selector);
7776

7877
JButton resetChannelButton = GUIUtils.createResetChannelButton(
79-
e -> model.resetChannelToDefault(channelsModel.getSelectedItem()));
78+
e -> model.resetChannelToDefault(channelsModel.getSelected()));
8079
northPanel.add(resetChannelButton);
8180

8281
return northPanel;

src/main/java/pixelitor/filters/lookup/ColorBalance.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import pixelitor.filters.gui.IntChoiceParam.Item;
2727
import pixelitor.filters.gui.RangeWithColorsParam;
2828
import pixelitor.filters.util.ColorSpace;
29+
import pixelitor.gui.GUIText;
2930
import pixelitor.utils.ColorSpaces;
3031

3132
import java.awt.image.BufferedImage;
@@ -120,11 +121,11 @@ private void updateSlidersForSRGB() {
120121
}
121122

122123
private void updateSlidersForOKLAB() {
123-
range1.setName("Green-Red (a)");
124+
range1.setName(GUIText.RED_GREEN_A);
124125
range1.setLeftColor(GREEN);
125126
range1.setRightColor(RED);
126127

127-
range2.setName("Blue-Yellow (b)");
128+
range2.setName(GUIText.BLUE_YELLOW_B);
128129
range2.setLeftColor(BLUE);
129130
range2.setRightColor(YELLOW);
130131

0 commit comments

Comments
 (0)