Skip to content

Commit 817d3d2

Browse files
committed
small improvements
1 parent 30a927a commit 817d3d2

114 files changed

Lines changed: 1591 additions & 1935 deletions

File tree

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: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@
6767
import static pixelitor.io.FileUtils.removeExtension;
6868
import static pixelitor.layers.LayerAdder.Position.ABOVE_ACTIVE;
6969
import static pixelitor.layers.LayerAdder.Position.BELOW_ACTIVE;
70+
import static pixelitor.utils.Threads.callInfo;
7071
import static pixelitor.utils.Threads.calledOnEDT;
7172
import static pixelitor.utils.Threads.onEDT;
7273
import static pixelitor.utils.Threads.onIOThread;
73-
import static pixelitor.utils.Threads.threadInfo;
7474
import static pixelitor.utils.Utils.createCopyName;
7575
import static pixelitor.utils.debug.DebugNodes.createBufferedImageNode;
7676

@@ -88,7 +88,7 @@ public class Composition implements Serializable, ImageSource, LayerHolder {
8888

8989
private final List<Layer> layerList = new ArrayList<>();
9090

91-
// The currently selected layer, potentially nested within groups or smart objects.
91+
// the currently selected layer, potentially nested within groups or smart objects
9292
private Layer activeLayer;
9393

9494
// The top-level ancestor layer of the activeLayer.
@@ -131,8 +131,8 @@ public class Composition implements Serializable, ImageSource, LayerHolder {
131131

132132
private transient Selection selection;
133133

134-
// A temporary selection that is currently being created
135-
// by dragging, but it's not finalized yet.
134+
// a temporary selection that is currently being created
135+
// by dragging, but it's not finalized yet
136136
private transient Selection draftSelection;
137137

138138
/**
@@ -208,7 +208,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
208208

209209
activeTopLevelLayer = activeLayer.getTopLevelLayer();
210210

211-
// Perform actions that need a full canvas and also
211+
// perform actions that need a full canvas and also
212212
// (re)load the contents of linked smart objects
213213
forEachNestedLayerOfType(CompositeLayer.class, CompositeLayer::afterDeserialization);
214214

@@ -375,8 +375,8 @@ public void addOwner(SmartObject newOwner) {
375375
* Checks if this {@link Composition} is the content of any {@link SmartObject}.
376376
*/
377377
public boolean isSmartObjectContent() {
378-
// If a content file is opened independently of its parent,
379-
// then this will return false, even for PXC files!
378+
// if a content file is opened independently of its parent,
379+
// then this will return false, even for PXC files
380380
return owners != null;
381381
}
382382

@@ -509,8 +509,7 @@ public void setName(String name) {
509509
}
510510

511511
/**
512-
* Create a file name that will be suggested as the default
513-
* file name in the save dialog.
512+
* Creates a file name to suggest in the save dialog.
514513
*/
515514
public String suggestFileName(String extension) {
516515
if (file == null) {
@@ -546,7 +545,7 @@ public void rename(String oldName, String newName) {
546545
return;
547546
}
548547
setName(newName);
549-
History.add(new CompositionRenamedEdit(this, oldName, newName));
548+
History.add(new CompositionRenameEdit(this, oldName, newName));
550549
}
551550

552551
public String getDebugName() {
@@ -660,6 +659,7 @@ public void flattenImage() {
660659
return;
661660
}
662661

662+
// create the new flattened layer from the composite of visible layers
663663
BufferedImage flattenedImg = getCompositeImage();
664664
Layer flattenedLayer = new ImageLayer(this, flattenedImg, "flattened");
665665

@@ -865,8 +865,8 @@ public void setActiveLayer(Layer layer, boolean addToHistory, String editName) {
865865
Layer prevActiveLayer = this.activeLayer;
866866
this.activeLayer = layer;
867867

868-
// After ungrouping a group with a single active layer,
869-
// the active layer could change without a change in the target.
868+
// after ungrouping a group with a single active layer,
869+
// the active layer could change without a change in the target
870870
setActiveTopLevelLayer(layer.getTopLevelLayer());
871871

872872
if (this.activeLayer == prevActiveLayer) {
@@ -1015,8 +1015,7 @@ public void forEachNestedLayerAndMask(Consumer<Layer> action) {
10151015
}
10161016

10171017
/**
1018-
* Applies an action to all nested layers.
1019-
* Traverses both layer group hierarchy and smart object content hierarchy.
1018+
* Applies an action to all nested layers, traversing groups and smart objects.
10201019
*/
10211020
public void forEachNestedLayer(Consumer<Layer> action, boolean includeMasks) {
10221021
for (Layer layer : layerList) {
@@ -1054,7 +1053,7 @@ public Layer findLayerAtPoint(Point2D p) {
10541053

10551054
Point pixelLoc = new Point((int) p.getX(), (int) p.getY());
10561055

1057-
// iterate in reverse order (we need to search layers from top to bottom)
1056+
// iterate in reverse order to search layers from top to bottom
10581057
ListIterator<Layer> li = layerList.listIterator(layerList.size());
10591058
while (li.hasPrevious()) {
10601059
Layer layer = li.previous();
@@ -1099,7 +1098,7 @@ private Layer getActiveTarget() {
10991098
}
11001099

11011100
/**
1102-
* Returns the active mask or image layer or null
1101+
* Returns the active {@link Drawable} (layer or mask), or null if none is active.
11031102
*/
11041103
public Drawable getActiveDrawable() {
11051104
assert checkInvariants();
@@ -1112,6 +1111,9 @@ public Drawable getActiveDrawable() {
11121111
}
11131112
}
11141113

1114+
/**
1115+
* Returns the active {@link Filterable} (layer or mask), or null if none is active.
1116+
*/
11151117
public Filterable getActiveFilterable() {
11161118
assert checkInvariants();
11171119
if (activeLayer.isMaskEditing()) {
@@ -1124,8 +1126,7 @@ public Filterable getActiveFilterable() {
11241126
}
11251127

11261128
/**
1127-
* Returns the active mask or image layer.
1128-
* Calling this method assumes that the active layer is a {@link Drawable}.
1129+
* Returns the active {@link Drawable} (layer or mask), or throws an exception if none is active.
11291130
*/
11301131
public Drawable getActiveDrawableOrThrow() {
11311132
Drawable dr = getActiveDrawable();
@@ -1503,15 +1504,13 @@ public void intersectSelectionWith(Rectangle2D rect) {
15031504
* might not be open in a view.
15041505
*/
15051506
public void imCoordsChanged(AffineTransform at, boolean isUndoRedo, View view) {
1506-
// The selection is explicitly reset to a backup shape
1507-
// when something is undone/redone.
1507+
// the selection is explicitly reset to a backup shape
1508+
// when something is undone/redone
15081509
if (selection != null && !isUndoRedo) {
15091510
selection.transform(at);
15101511
}
1511-
// The paths and the tool widgets are transformed even for undo/redo.
1512-
// The advantage is simpler code, the disadvantage is that
1513-
// rounding errors could accumulate if the same operation is
1514-
// undone/redone many times.
1512+
1513+
// the paths and the tool widgets are transformed even for undo/redo
15151514
if (paths != null) {
15161515
paths.imCoordsChanged(at);
15171516
}
@@ -1616,9 +1615,7 @@ public void activeLayerToCanvasSize() {
16161615
}
16171616

16181617
/**
1619-
* Fits the canvas to the combined bounds of all content layers.
1620-
* If any content layer is larger than the current canvas, the
1621-
* canvas will be enlarged to fully contain all content layers.
1618+
* Enlarges the canvas to fit the content of all layers.
16221619
*/
16231620
public void fitCanvasToLayers() {
16241621
Outsets enlargement = Outsets.createZero();
@@ -1747,7 +1744,7 @@ public boolean checkInvariants() {
17471744
*/
17481745
public CompletableFuture<Void> saveAsync(SaveSettings saveSettings,
17491746
boolean addToRecentFiles) {
1750-
assert calledOnEDT() : threadInfo();
1747+
assert calledOnEDT() : callInfo();
17511748

17521749
// prevent concurrent processing of the same file path
17531750
File targetFile = saveSettings.file();
@@ -1759,7 +1756,7 @@ public CompletableFuture<Void> saveAsync(SaveSettings saveSettings,
17591756
}
17601757
IOTasks.markPathForWriting(filePath);
17611758

1762-
// Set to not dirty already at the beginning of the saving process,
1759+
// set to not dirty already at the beginning of the saving process,
17631760
// so that subsequent closing doesn't trigger another save.
17641761
boolean wasDirty = isDirty();
17651762
clearDirtyFlagsRecursively();
@@ -1786,7 +1783,7 @@ public CompletableFuture<Void> saveAsync(SaveSettings saveSettings,
17861783
* Actions to perform on the EDT after a successful save.
17871784
*/
17881785
public void handleSuccessfulSave(File file, boolean addToRecentFiles) {
1789-
assert calledOnEDT() : threadInfo();
1786+
assert calledOnEDT() : callInfo();
17901787

17911788
setFile(file);
17921789
if (addToRecentFiles) {
@@ -1796,8 +1793,8 @@ public void handleSuccessfulSave(File file, boolean addToRecentFiles) {
17961793
Messages.showFileSavedMessage(file);
17971794

17981795
if (isSmartObjectContent()) {
1799-
// Otherwise the changes might not be propagated when deactivating,
1800-
// because this isn't dirty after saving even if it's changed.
1796+
// otherwise the changes might not be propagated when deactivating,
1797+
// because this isn't dirty after saving even if it's changed
18011798
for (SmartObject owner : owners) {
18021799
owner.propagateContentChanges(this, true);
18031800

@@ -1914,7 +1911,7 @@ public ImageMode getMode() {
19141911
* need to be reloaded due to external file modifications.
19151912
*/
19161913
public CompletableFuture<Composition> checkForExternalModifications() {
1917-
// check only the open compositions here - hidden
1914+
// check only the open compositions here; hidden
19181915
// smart object contents will be checked later
19191916
if (file != null && isOpen()) {
19201917
long currentFileTimestamp = file.lastModified();

src/main/java/pixelitor/ConsistencyChecks.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import pixelitor.selection.SelectionActions;
2424
import pixelitor.utils.Threads;
2525
import pixelitor.utils.debug.Debug;
26-
import pixelitor.utils.test.Events;
2726

2827
import java.awt.Rectangle;
2928
import java.awt.image.BufferedImage;
@@ -95,8 +94,6 @@ private static boolean isSizeDifferent(BufferedImage a, BufferedImage b) {
9594
}
9695

9796
private static void differentSizeForFade(BufferedImage currentImg, BufferedImage previousImg, Composition comp) {
98-
Events.postProgramError("fade would not work", comp, null);
99-
10097
Debug.debugImage(currentImg, "current");
10198
Debug.debugImage(previousImg, "previous");
10299

src/main/java/pixelitor/Pixelitor.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
import java.util.concurrent.TimeUnit;
4848

4949
import static java.lang.String.format;
50+
import static pixelitor.utils.Threads.callInfo;
5051
import static pixelitor.utils.Threads.calledOnEDT;
5152
import static pixelitor.utils.Threads.onEDT;
5253
import static pixelitor.utils.Threads.onIOThread;
53-
import static pixelitor.utils.Threads.threadInfo;
5454

5555
/**
5656
* The main enty point for the app.
@@ -128,7 +128,7 @@ private static void launchGUI(String[] args) {
128128
}
129129

130130
private static void createAndShowGUI(String[] args) {
131-
assert calledOnEDT() : threadInfo();
131+
assert calledOnEDT() : callInfo();
132132

133133
Messages.setHandler(new GUIMessageHandler());
134134

@@ -141,8 +141,8 @@ private static void createAndShowGUI(String[] args) {
141141
PixelitorWindow mainWindow = PixelitorWindow.get();
142142
Dialogs.setMainWindowInitialized(true);
143143

144-
// ensure the main window has focus after GUI initialization
145-
// so that keyboard shortcuts work properly
144+
// ensure that after GUI initialization the focus isn't grabbed
145+
// by a textfield, and keyboard shortcuts work properly
146146
FgBgColors.getGUI().requestFocus();
147147

148148
TipsOfTheDay.showTips(mainWindow, false);
@@ -158,12 +158,11 @@ private static void createAndShowGUI(String[] args) {
158158
.exceptionally(Messages::showExceptionOnEDT);
159159
}
160160

161-
// less urgent initializations on the main thread
161+
// less urgent initializations on the main thread after starting the GUI on the EDT
162162
private static void mainThreadInit() {
163163
MeasurementOverlay.initializeFont();
164164

165-
// force look-up table initialization now
166-
// to prevent unexpected delays later
165+
// force look-up table initialization now to prevent unexpected delays later
167166
FastMath.initTables();
168167
}
169168

@@ -218,7 +217,7 @@ private static CompletableFuture<Void> openCommandLineFilesAsync(String[] args)
218217
}
219218

220219
public static void exitApp(PixelitorWindow mainWindow) {
221-
assert calledOnEDT() : threadInfo();
220+
assert calledOnEDT() : callInfo();
222221

223222
if (isExitBlockedByOngoingWrites(mainWindow)) {
224223
return;

src/main/java/pixelitor/automate/AutoPaint.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import pixelitor.utils.Lazy;
3131
import pixelitor.utils.Messages;
3232
import pixelitor.utils.ProgressHandler;
33-
import pixelitor.utils.Rnd;
3433

3534
import java.awt.Color;
3635
import java.awt.geom.Path2D;
@@ -47,20 +46,20 @@
4746
import static pixelitor.tools.Tools.ERASER;
4847
import static pixelitor.tools.Tools.SMUDGE;
4948
import static pixelitor.utils.Texts.i18n;
49+
import static pixelitor.utils.Threads.callInfo;
5050
import static pixelitor.utils.Threads.calledOnEDT;
51-
import static pixelitor.utils.Threads.threadInfo;
5251

5352
/**
5453
* The "Auto Paint" functionality.
5554
*/
5655
public class AutoPaint {
57-
public static final Tool[] SUPPORTED_TOOLS = {SMUDGE, BRUSH, CLONE, ERASER};
56+
public static final AbstractBrushTool[] SUPPORTED_TOOLS = {SMUDGE, BRUSH, CLONE, ERASER};
5857
private static Color origFg;
5958
private static Color origBg;
6059
private static final Lazy<AutoPaintPanel> CONFIG_PANEL_FACTORY = Lazy.of(AutoPaintPanel::new);
6160

6261
private AutoPaint() {
63-
// Utility class, no instantiation
62+
// utility class, no instantiation
6463
}
6564

6665
public static void showDialog(Drawable dr) {
@@ -74,7 +73,7 @@ public static void showDialog(Drawable dr) {
7473
}
7574

7675
private static void autoPaint(Drawable dr, AutoPaintSettings settings) {
77-
assert calledOnEDT() : threadInfo();
76+
assert calledOnEDT() : callInfo();
7877

7978
BufferedImage backupImage = dr.getSelectedSubImage(true);
8079
String statusBarMessage = "Auto Paint with " + settings.getTool().getName();
@@ -102,7 +101,7 @@ private static void autoPaint(Drawable dr, AutoPaintSettings settings) {
102101
private static void generateStrokes(AutoPaintSettings settings,
103102
Drawable dr,
104103
ProgressHandler progressHandler) {
105-
assert calledOnEDT() : threadInfo();
104+
assert calledOnEDT() : callInfo();
106105

107106
var random = new SplittableRandom();
108107
var comp = dr.getComp();
@@ -120,19 +119,14 @@ private static void generateSingleStroke(Drawable dr,
120119
AutoPaintSettings settings,
121120
Composition comp,
122121
SplittableRandom rand) {
123-
assert calledOnEDT() : threadInfo();
122+
assert calledOnEDT() : callInfo();
124123

125124
setColors(settings, rand);
126125
PPoint start = comp.genRandomPointInCanvas();
127126
PPoint end = settings.genRandomEndPoint(start, comp, rand);
127+
Path2D strokePath = createStrokePath(start, end, settings, rand);
128128

129-
Tool tool = settings.getTool();
130-
if (tool instanceof AbstractBrushTool abt) {
131-
Path2D strokePath = createStrokePath(start, end, settings);
132-
abt.trace(dr, strokePath);
133-
} else {
134-
throw new IllegalStateException("tool = " + tool.getClass().getName());
135-
}
129+
settings.getTool().trace(dr, strokePath);
136130
}
137131

138132
private static void setColors(AutoPaintSettings settings, SplittableRandom rand) {
@@ -143,24 +137,28 @@ private static void setColors(AutoPaintSettings settings, SplittableRandom rand)
143137
}
144138
}
145139

146-
private static Path2D createStrokePath(PPoint start, PPoint end, AutoPaintSettings settings) {
140+
private static Path2D createStrokePath(PPoint start, PPoint end, AutoPaintSettings settings, SplittableRandom rand) {
147141
Path2D path = new Path2D.Double();
148142
path.moveTo(start.getImX(), start.getImY());
149143

150144
double controlX = (start.getImX() + end.getImX()) / 2.0;
151145
double controlY = (start.getImY() + end.getImY()) / 2.0;
152146

153-
double curvature = settings.getMaxCurvature();
154-
if (curvature > 0) {
155-
double maxShift = start.imDist(end) * curvature;
156-
controlX += (Rnd.nextDouble() - 0.5) * maxShift;
157-
controlY += (Rnd.nextDouble() - 0.5) * maxShift;
147+
double maxCurvature = settings.getMaxCurvature();
148+
if (maxCurvature > 0) {
149+
double maxShift = start.imDist(end) * maxCurvature;
150+
controlX += (rand.nextDouble() - 0.5) * maxShift;
151+
controlY += (rand.nextDouble() - 0.5) * maxShift;
158152
}
159153

160154
path.quadTo(controlX, controlY, end.getImX(), end.getImY());
161155
return path;
162156
}
163157

158+
static boolean useColors(Tool selectedTool) {
159+
return selectedTool == BRUSH;
160+
}
161+
164162
private static void rememberOriginalColors() {
165163
origFg = getFGColor();
166164
origBg = getBGColor();

0 commit comments

Comments
 (0)