Skip to content

Commit 9d43b4b

Browse files
committed
last changes before 4.2.3
1 parent 732d539 commit 9d43b4b

58 files changed

Lines changed: 1305 additions & 506 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/pixelitor/Composition.java

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@
7070
import java.util.Optional;
7171
import java.util.concurrent.CompletableFuture;
7272
import java.util.function.Consumer;
73+
import java.util.function.Predicate;
7374

7475
import static java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE;
7576
import static java.lang.String.format;
77+
import static java.util.stream.Collectors.toList;
7678
import static pixelitor.Composition.ImageChangeActions.FULL;
7779
import static pixelitor.Composition.LayerAdder.Position.ABOVE_ACTIVE;
7880
import static pixelitor.Composition.LayerAdder.Position.BELLOW_ACTIVE;
@@ -384,21 +386,17 @@ public void mergeDown(Layer layer, boolean updateGUI) {
384386
BufferedImage bellowImage = bellowLayer.getImage();
385387
Graphics2D g = bellowImage.createGraphics();
386388
g.translate(-bellowLayer.getTX(), -bellowLayer.getTY());
387-
BufferedImage result = activeLayer.applyLayer(g, bellowImage, false);
389+
BufferedImage result = layer.applyLayer(g, bellowImage, false);
388390
if (result != null) { // this was an adjustment
389391
bellowLayer.setImage(result);
390392
}
391393
g.dispose();
392394

393395
bellowLayer.updateIconImage();
394396

395-
// keep the reference because after deleting the
396-
// active merged layer, another layer will become active
397-
Layer mergedLayer = activeLayer;
397+
deleteLayer(layer, false, updateGUI);
398398

399-
deleteActiveLayer(updateGUI, false);
400-
401-
History.addEdit(new MergeDownEdit(this, mergedLayer,
399+
History.addEdit(new MergeDownEdit(this, layer,
402400
bellowLayer, imageBefore, maskViewModeBefore, layerIndex));
403401
}
404402

@@ -471,9 +469,10 @@ public void setActiveLayer(Layer newActiveLayer, boolean updateGUI, boolean addT
471469
if (addToHistory) {
472470
History.addEdit(new LayerSelectionChangeEdit(
473471
editName, this, oldLayer, newActiveLayer));
472+
}
474473

475-
// shouldn't run in initialization code
476-
Tools.imageChanged(activeLayer);
474+
if(view != null) { // shouldn't run while loading the composition
475+
Tools.editedObjectChanged(activeLayer);
477476
}
478477

479478
assert checkInvariant();
@@ -507,6 +506,20 @@ public int getNumLayers() {
507506
return layerList.size();
508507
}
509508

509+
public int getNumLayers(Predicate<Layer> condition) {
510+
return (int) layerList.stream()
511+
.filter(condition)
512+
.count();
513+
}
514+
515+
public int getNumImageLayers() {
516+
return getNumLayers(layer -> layer instanceof ImageLayer);
517+
}
518+
519+
public int getNumTextLayers() {
520+
return getNumLayers(layer -> layer instanceof TextLayer);
521+
}
522+
510523
public void forEachLayer(Consumer<Layer> action) {
511524
layerList.forEach(action);
512525
}
@@ -535,6 +548,21 @@ public void updateAllIconImages() {
535548
forEachDrawable(Drawable::updateIconImage);
536549
}
537550

551+
public void rasterizeAllTextLayers() {
552+
assert view == null;
553+
554+
// create a separate copy to avoid modification
555+
// of the original list while iterating
556+
List<TextLayer> textLayers = layerList.stream()
557+
.filter(layer -> layer instanceof TextLayer)
558+
.map(layer -> (TextLayer) layer)
559+
.collect(toList());
560+
561+
for (TextLayer textLayer : textLayers) {
562+
textLayer.replaceWithRasterized(false, false);
563+
}
564+
}
565+
538566
public boolean activeIsDrawable() {
539567
if (activeLayer instanceof ImageLayer) {
540568
return true;
@@ -1071,9 +1099,14 @@ public void invertSelection() {
10711099
if (selection != null) {
10721100
Shape backupShape = selection.getShape();
10731101
Shape inverted = canvas.invertShape(backupShape);
1074-
selection.setShape(inverted);
1075-
History.addEdit(new SelectionShapeChangeEdit(
1076-
"Invert Selection", this, backupShape));
1102+
if(inverted.getBounds2D().isEmpty()) {
1103+
// presumably everything was selected, and now nothing is
1104+
deselect(true);
1105+
} else {
1106+
selection.setShape(inverted);
1107+
History.addEdit(new SelectionShapeChangeEdit(
1108+
"Invert Selection", this, backupShape));
1109+
}
10771110
}
10781111
}
10791112

@@ -1266,16 +1299,6 @@ public boolean checkInvariant() {
12661299
return true;
12671300
}
12681301

1269-
public int getNumImageLayers() {
1270-
int count = 0;
1271-
for (Layer layer : layerList) {
1272-
if (layer instanceof ImageLayer) {
1273-
count++;
1274-
}
1275-
}
1276-
return count;
1277-
}
1278-
12791302
public int calcNumImages() {
12801303
int count = 0;
12811304
for (Layer layer : layerList) {

src/main/java/pixelitor/ConsistencyChecks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void checkAll(Composition comp, boolean checkImageCoversCanvas) {
4747

4848
selectionActionsEnabledCheck(comp);
4949

50-
assert selectionShapeIsNotEmpty(comp) : "empty selection in " + comp.getName();
50+
assert selectionShapeIsNotEmpty(comp) : "empty selection shape in " + comp.getName();
5151
assert selectionIsInsideCanvas(comp) : "selection outside the canvas in " + comp.getName();
5252
assert fadeWouldWorkOn(comp);
5353

src/main/java/pixelitor/automate/Automate.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ public Void doInBackground() {
8282

8383
File file = inputFiles[i];
8484
progressMonitor.setProgress((int) ((float) i * 100 / nrOfFiles));
85-
progressMonitor.setNote("Processing " + file.getName());
86-
System.out.println("Processing " + file.getName());
85+
86+
String msg = "Processing " + (i + 1) + " of " + nrOfFiles;
87+
progressMonitor.setNote(msg);
88+
System.out.println(msg);
8789

8890
processFile(file, action, saveDir);
8991

src/main/java/pixelitor/automate/SingleDirChooser.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 Laszlo Balazs-Csiki and Contributors
2+
* Copyright 2019 Laszlo Balazs-Csiki and Contributors
33
*
44
* This file is part of Pixelitor. Pixelitor is free software: you
55
* can redistribute it and/or modify it under the terms of the GNU
@@ -42,13 +42,12 @@ public class SingleDirChooser extends ValidatedPanel {
4242

4343
private SingleDirChooser(String label, String initialPath,
4444
String fileChooserTitle,
45-
boolean addOutputChooser, OutputFormat outputFormat) {
46-
assert addOutputChooser == (outputFormat != null);
47-
45+
OutputFormat outputFormat) {
4846
dirChooser = new BrowseFilesSupport(initialPath, fileChooserTitle, DIRECTORY);
4947
JTextField dirTF = dirChooser.getNameTF();
5048
JButton browseButton = dirChooser.getBrowseButton();
5149

50+
boolean addOutputChooser = (outputFormat != null);
5251
if (addOutputChooser) {
5352
setLayout(new GridBagLayout());
5453
GridBagHelper gbh = new GridBagHelper(this);
@@ -95,15 +94,18 @@ public ValidationResult checkValidity() {
9594
}
9695
}
9796

97+
public static boolean selectOutputDir() {
98+
return selectOutputDir(null);
99+
}
100+
98101
/**
99102
* Lets the user select the output directory property of the application.
100103
* Returns true if a selection was made, false if the operation was cancelled.
101104
*/
102-
public static boolean selectOutputDir(boolean addOutputChooser,
103-
OutputFormat defaultFormat) {
105+
public static boolean selectOutputDir(OutputFormat defaultFormat) {
104106
SingleDirChooser chooserPanel = new SingleDirChooser("Output Folder:",
105107
Dirs.getLastSave().getAbsolutePath(),
106-
"Select Output Folder", addOutputChooser, defaultFormat);
108+
"Select Output Folder", defaultFormat);
107109

108110
boolean[] selectionWasMade = {false};
109111
new DialogBuilder()
@@ -116,7 +118,7 @@ public static boolean selectOutputDir(boolean addOutputChooser,
116118
})
117119
.show();
118120

119-
if (addOutputChooser) {
121+
if (defaultFormat != null) {
120122
OutputFormat selectedFormat = chooserPanel.getSelectedFormat();
121123
OutputFormat.setLastUsed(selectedFormat);
122124
}

src/main/java/pixelitor/colors/FgBgColorSelector.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
* the foreground and background colors
4242
*/
4343
public class FgBgColorSelector extends JLayeredPane {
44+
public static final String RANDOMIZE_COLORS_BUTTON_NAME = "randomizeColorsButton";
45+
public static final String FG_BUTTON_NAME = "fgButton";
46+
public static final String BG_BUTTON_NAME = "bgButton";
47+
public static final String RESET_DEF_COLORS_BUTTON_NAME = "resetDefColorsButton";
48+
public static final String SWAP_COLORS_BUTTON_NAME = "swapColorsButton";
4449
private final PixelitorWindow pw;
4550
private JButton fgButton;
4651
private JButton bgButton;
@@ -80,15 +85,17 @@ public FgBgColorSelector(PixelitorWindow pw) {
8085
}
8186

8287
private void initFGButton() {
83-
fgButton = initButton("Set Foreground Color", BIG_BUTTON_SIZE, 2);
88+
fgButton = initButton("Set Foreground Color",
89+
BIG_BUTTON_SIZE, 2, FG_BUTTON_NAME);
8490
fgButton.addActionListener(e -> fgButtonPressed());
8591
fgButton.setLocation(0, SMALL_BUTTON_VERTICAL_SPACE);
8692

8793
fgButton.setComponentPopupMenu(createPopupMenu(true));
8894
}
8995

9096
private void initBGButton() {
91-
bgButton = initButton("Set Background Color", BIG_BUTTON_SIZE, 1);
97+
bgButton = initButton("Set Background Color",
98+
BIG_BUTTON_SIZE, 1, BG_BUTTON_NAME);
9299
bgButton.addActionListener(e -> bgButtonPressed());
93100
bgButton.setLocation(BIG_BUTTON_SIZE / 2, SMALL_BUTTON_VERTICAL_SPACE + BIG_BUTTON_SIZE / 2);
94101

@@ -113,8 +120,8 @@ public void onClick() {
113120
});
114121

115122
String mixTitle = fg
116-
? "HSB Mix with Background Variations..."
117-
: "HSB Mix with Foreground Variations...";
123+
? "HSB Mix with Background..."
124+
: "HSB Mix with Foreground...";
118125
menu.add(new MenuAction(mixTitle) {
119126
@Override
120127
public void onClick() {
@@ -123,8 +130,8 @@ public void onClick() {
123130
});
124131

125132
String rgbMixTitle = fg
126-
? "RGB Mix with Background Variations..."
127-
: "RGB Mix with Foreground Variations...";
133+
? "RGB Mix with Background..."
134+
: "RGB Mix with Foreground...";
128135
menu.add(new MenuAction(rgbMixTitle) {
129136
@Override
130137
public void onClick() {
@@ -164,7 +171,8 @@ public void onClick() {
164171
}
165172

166173
private void initResetDefaultsButton() {
167-
JButton defaultsButton = initButton("Reset Default Colors (D)", SMALL_BUTTON_SIZE, 1);
174+
JButton defaultsButton = initButton("Reset Default Colors (D)",
175+
SMALL_BUTTON_SIZE, 1, RESET_DEF_COLORS_BUTTON_NAME);
168176
defaultsButton.setLocation(0, 0);
169177
resetToDefaultAction = new AbstractAction() {
170178
@Override
@@ -181,7 +189,8 @@ public void setDefaultColors() {
181189
}
182190

183191
private void initSwapColorsButton() {
184-
JButton swapButton = initButton("Swap Colors (X)", SMALL_BUTTON_SIZE, 1);
192+
JButton swapButton = initButton("Swap Colors (X)",
193+
SMALL_BUTTON_SIZE, 1, SWAP_COLORS_BUTTON_NAME);
185194
swapButton.setLocation(SMALL_BUTTON_SIZE, 0);
186195
swapColorsAction = new AbstractAction() {
187196
@Override
@@ -205,7 +214,8 @@ public void swapColors() {
205214
}
206215

207216
private void initRandomizeButton() {
208-
JButton randomizeButton = initButton("Randomize Colors (R)", SMALL_BUTTON_SIZE, 1);
217+
JButton randomizeButton = initButton("Randomize Colors (R)",
218+
SMALL_BUTTON_SIZE, 1, RANDOMIZE_COLORS_BUTTON_NAME);
209219
randomizeButton.setLocation(2 * SMALL_BUTTON_SIZE, 0);
210220
randomizeColorsAction = new AbstractAction() {
211221
@Override
@@ -228,10 +238,11 @@ private void setupSize() {
228238
setMaximumSize(dim);
229239
}
230240

231-
private JButton initButton(String toolTip, int size, int layer) {
241+
private JButton initButton(String toolTip, int size, int layer, String name) {
232242
JButton button = new JButton();
233243
button.setToolTipText(toolTip);
234244
button.setSize(size, size);
245+
button.setName(name);
235246
add(button, Integer.valueOf(layer));
236247
return button;
237248
}

src/main/java/pixelitor/filters/ChaosGame.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import pixelitor.filters.gui.IntChoiceParam;
2222
import pixelitor.filters.gui.IntChoiceParam.Value;
2323
import pixelitor.filters.gui.RangeParam;
24+
import pixelitor.filters.gui.ReseedNoiseFilterAction;
2425
import pixelitor.filters.gui.ShowOriginal;
2526
import pixelitor.utils.ImageUtils;
2627
import pixelitor.utils.ProgressTracker;
@@ -83,7 +84,7 @@ public ChaosGame() {
8384
centerJump,
8485
midpointJump,
8586
restrict,
86-
showPoly);
87+
showPoly).withAction(ReseedNoiseFilterAction.noOpReseed());
8788
}
8889

8990
@Override
@@ -285,6 +286,14 @@ private static void drawPolygon(BufferedImage dest, List<Point> points, int numV
285286
g.dispose();
286287
}
287288

289+
@Override
290+
public boolean supportsGray() {
291+
return false;
292+
}
293+
294+
/**
295+
* A point with double precision and an associated color
296+
*/
288297
private static final class Point {
289298
double x;
290299
double y;

src/main/java/pixelitor/filters/comp/Crop.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,9 @@ public CompletableFuture<Composition> process(Composition comp) {
136136
view.ensurePositiveLocation();
137137

138138
assert comp != newComp;
139+
String editName = addHidingMask ? "Crop and Hide" : "Crop";
139140
History.addEdit(new CompositionReplacedEdit(
140-
"Crop", false, view, comp, newComp, canvasTx));
141+
editName, false, view, comp, newComp, canvasTx));
141142
view.replaceComp(newComp);
142143
SelectionActions.setEnabled(newComp.hasSelection(), newComp);
143144

src/main/java/pixelitor/filters/comp/EnlargeCanvas.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ private EnlargeCanvasPanel() {
148148

149149
private void addSliderSpinner(RangeParam range, String sliderName) {
150150
SliderSpinner s = new SliderSpinner(range, BORDER, false);
151-
s.setSliderName(sliderName);
151+
s.setName(sliderName);
152152
add(s);
153153
}
154154

src/main/java/pixelitor/filters/comp/Resize.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ public CompletableFuture<Composition> process(Composition comp) {
100100
}
101101

102102
private static Composition afterResizeActions(Composition comp, Composition newComp, Dimension targetSize, ProgressHandler progressHandler) {
103+
assert EventQueue.isDispatchThread(): "called on " + Thread.currentThread().getName();
104+
103105
int canvasTargetWidth = targetSize.width;
104106
int canvasTargetHeight = targetSize.height;
105107

@@ -117,7 +119,12 @@ private static Composition afterResizeActions(Composition comp, Composition newC
117119
History.addEdit(new CompositionReplacedEdit(
118120
"Resize", false, view, comp, newComp, canvasTx));
119121
view.replaceComp(newComp);
120-
SelectionActions.setEnabled(newComp.hasSelection(), newComp);
122+
123+
// the view was active when the resize started, but since the
124+
// resize was asynchronous, this could have changed
125+
if(view.isActive()) {
126+
SelectionActions.setEnabled(newComp.hasSelection(), newComp);
127+
}
121128

122129
Guides guides = comp.getGuides();
123130
if (guides != null) {

0 commit comments

Comments
 (0)