Skip to content

Commit

Permalink
small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalazscs committed Jan 3, 2024
1 parent 27a1843 commit 777dd99
Show file tree
Hide file tree
Showing 43 changed files with 458 additions and 432 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/bric/math/Equations.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public static void solve(BigDecimal[][] coefficients, boolean sort) {
int row = 0;
int a, i;
BigDecimal t;
BigDecimal tolerance = new BigDecimal(0.0000000001);
BigDecimal tolerance = new BigDecimal("0.0000000001");
int errorCounter = 0;
//println(coefficients);
while (ctr < b.length) {
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/pd/AnimatedGifEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -927,21 +927,15 @@ private void alterneigh(int rad, int i, int b, int g, int r) {
a = radpower[m++];
if (j < hi) {
p = network[j++];
try {
p[0] -= (a * (p[0] - b)) / alpharadbias;
p[1] -= (a * (p[1] - g)) / alpharadbias;
p[2] -= (a * (p[2] - r)) / alpharadbias;
} catch (Exception e) {
} // prevents 1.3 miscompilation
p[0] -= (a * (p[0] - b)) / alpharadbias;
p[1] -= (a * (p[1] - g)) / alpharadbias;
p[2] -= (a * (p[2] - r)) / alpharadbias;
}
if (k > lo) {
p = network[k--];
try {
p[0] -= (a * (p[0] - b)) / alpharadbias;
p[1] -= (a * (p[1] - g)) / alpharadbias;
p[2] -= (a * (p[2] - r)) / alpharadbias;
} catch (Exception e) {
}
p[0] -= (a * (p[0] - b)) / alpharadbias;
p[1] -= (a * (p[1] - g)) / alpharadbias;
p[2] -= (a * (p[2] - r)) / alpharadbias;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/pixelitor/Composition.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Laszlo Balazs-Csiki and Contributors
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -558,7 +558,7 @@ public ImageLayer addNewEmptyImageLayer(String name, boolean bellowActive) {
getHolderForNewLayers().adder()
.withHistory("New Empty Layer")
.atPosition(bellowActive ? BELLOW_ACTIVE : ABOVE_ACTIVE)
.noRefresh()
.noUpdate()
.add(newLayer);

return newLayer;
Expand All @@ -575,7 +575,7 @@ public void addNewLayerFromComposite() {

new LayerAdder(this)
.withHistory("New Layer from Visible")
.noRefresh()
.noUpdate()
.atIndex(layerList.size())
.add(newLayer);
}
Expand Down Expand Up @@ -612,7 +612,7 @@ public void flattenImage() {
Layer flattened = new ImageLayer(this, bi, "flattened");
adder()
.atIndex(numLayers) // add to the top
.noRefresh()
.noUpdate()
.add(flattened);

for (int i = numLayers - 1; i >= 0; i--) { // delete the rest
Expand Down
88 changes: 50 additions & 38 deletions src/main/java/pixelitor/Pixelitor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Laszlo Balazs-Csiki and Contributors
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -121,28 +121,7 @@ private static void createAndShowGUI(String[] args) {

Theme theme = AppPreferences.loadTheme();
Themes.install(theme, false, true);

int uiFontSize = AppPreferences.loadUIFontSize();
String uiFontType = AppPreferences.loadUIFontType();

Font defaultFont = UIManager.getFont("defaultFont");
if (defaultFont != null) { // if null, we don't know how to set the font
if (uiFontSize != 0 || !uiFontType.isEmpty()) {
Font newFont;
if (!uiFontType.isEmpty()) {
newFont = new Font(uiFontType, Font.PLAIN, uiFontSize);
} else {
newFont = defaultFont.deriveFont((float) uiFontSize);
}

FontUIResource fontUIResource = new FontUIResource(newFont);
UIManager.put("defaultFont", fontUIResource);

if (theme.isNimbus()) {
UIManager.getLookAndFeel().getDefaults().put("defaultFont", fontUIResource);
}
}
}
loadUIFonts(theme);

var pw = PixelitorWindow.get();
Dialogs.setMainWindowInitialized(true);
Expand All @@ -167,26 +146,55 @@ private static void createAndShowGUI(String[] args) {
.exceptionally(Messages::showExceptionOnEDT);
}

private static void loadUIFonts(Theme theme) {
int uiFontSize = AppPreferences.loadUIFontSize();
String uiFontType = AppPreferences.loadUIFontType();
if (uiFontSize == 0 || uiFontType.isEmpty()) {
// no saved settings found
return;
}

Font defaultFont = UIManager.getFont("defaultFont");
if (defaultFont == null) {
// if null, we don't know how to set the font
return;
}

Font newFont;
if (!uiFontType.isEmpty()) {
newFont = new Font(uiFontType, Font.PLAIN, uiFontSize);
} else {
newFont = defaultFont.deriveFont((float) uiFontSize);
}

FontUIResource fontUIResource = new FontUIResource(newFont);
UIManager.put("defaultFont", fontUIResource);

if (theme.isNimbus()) {
UIManager.getLookAndFeel().getDefaults().put("defaultFont", fontUIResource);
}
}

/**
* Schedules the opening of the files given as command-line arguments
*/
private static CompletableFuture<Void> openCLFilesAsync(String[] args) {
List<CompletableFuture<Composition>> openedFiles = new ArrayList<>();

for (String fileName : args) {
File f = new File(fileName);
if (f.exists()) {
openedFiles.add(IO.openFileAsync(f, false));
File file = new File(fileName);
if (file.exists()) {
openedFiles.add(IO.openFileAsync(file, false));
} else {
Messages.showError("File not found",
format("The file \"%s\" doesn't exist.", f.getAbsolutePath()));
format("The file \"%s\" doesn't exist.", file.getAbsolutePath()));
}
}

return Utils.allOf(openedFiles);
}

public static void exitApp(PixelitorWindow pw) {
public static void warnAndExit(PixelitorWindow pw) {
assert calledOnEDT() : threadInfo();

var paths = IOTasks.getCurrentWritePaths();
Expand All @@ -205,27 +213,31 @@ public static void exitApp(PixelitorWindow pw) {
// can be updated while waiting
new Thread(() -> {
Utils.sleep(10, TimeUnit.SECONDS);
EventQueue.invokeLater(() -> exitApp(pw));
EventQueue.invokeLater(() -> warnAndExit(pw));
}).start();

return;
}
}

var unsavedComps = Views.getUnsavedComps();
if (!unsavedComps.isEmpty()) {
String msg = createUnsavedChangesMsg(unsavedComps);

if (Dialogs.showYesNoWarningDialog(pw, "Unsaved Changes", msg)) {
pw.setVisible(false);
AppPreferences.savePrefsAndExit();
List<Composition> unsaved = Views.getUnsavedComps();
if (!unsaved.isEmpty()) {
boolean yesClicked = Dialogs.showYesNoWarningDialog(pw,
"Unsaved Changes", createUnsavedChangesMsg(unsaved));
if (yesClicked) {
exit(pw);
}
} else {
pw.setVisible(false);
AppPreferences.savePrefsAndExit();
exit(pw);
}
}

private static void exit(PixelitorWindow pw) {
pw.setVisible(false);
AppPreferences.savePreferences();
System.exit(0);
}

private static String createUnsavedChangesMsg(List<Composition> unsavedComps) {
String msg;
if (unsavedComps.size() == 1) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pixelitor/filters/AbstractLights.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Laszlo Balazs-Csiki and Contributors
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -174,7 +174,7 @@ private List<Particle> createPoints(int width, int height, Random random, float
return points;
}

private void connectParticles(int width, int height, int numPoints, double speed, ArrayList<Particle> points) {
private void connectParticles(int width, int height, int numPoints, double speed, List<Particle> points) {
int connect = typeParam.getValue();
if (connect == TYPE_CHAOS || connect == TYPE_FRAME) {
for (int i = 0; i < numPoints; i++) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/pixelitor/filters/CommandLineFilter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Laszlo Balazs-Csiki and Contributors
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -77,4 +77,9 @@ private static List<String> parseCommands(String input) {
public FilterGUI createGUI(Filterable layer, boolean reset) {
return new CommandLineGUI(this, layer, true, reset);
}

@Override
public boolean supportsGray() {
return false;
}
}
4 changes: 2 additions & 2 deletions src/main/java/pixelitor/filters/ValueNoise.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Laszlo Balazs-Csiki and Contributors
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -174,7 +174,7 @@ private float noise(int x, int y) {
int n = x + y * 57;
n = (n << 13) ^ n;

return (1.0f - ((n * (n * n * r1 + r2) + r3) & 0x7F_FF_FF_FF) / 1.07374182E+9f);
return (1.0f - ((n * (n * n * r1 + r2) + r3) & 0x7F_FF_FF_FF) / 1.0737418E+9f);
}

private static float interpolate(float x, float y, float a, NoiseInterpolation interp) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/pixelitor/filters/gmic/GMICFilter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Laszlo Balazs-Csiki and Contributors
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -53,6 +53,11 @@ public BufferedImage doTransform(BufferedImage src, BufferedImage dest) {

public abstract List<String> getArgs();

@Override
public boolean supportsGray() {
return false;
}

public static IntChoiceParam createValueAction() {
return new IntChoiceParam("Value Action", new String[]{
"None", "Cut", "Normalize"});
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/pixelitor/filters/gui/ParamSet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Laszlo Balazs-Csiki and Contributors
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -402,7 +402,7 @@ public FilterButtonModel createReseedCachedAndNoiseAction() {
seedChangedAction = newSeed -> {
Noise.reseed(newSeed);
random.setSeed(newSeed);
CachedFloatRandom.reseedCache(random);
CachedFloatRandom.reBuildCache(random);
};

return FilterButtonModel.createReseed(() -> {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/pixelitor/gui/GlobalEvents.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Laszlo Balazs-Csiki and Contributors
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -129,6 +129,8 @@ public static void init() {
backwardKeys = new HashSet<>(backwardKeys); // make modifiable
backwardKeys.remove(Keys.CTRL_SHIFT_TAB);
keyboardFocusManager.setDefaultFocusTraversalKeys(BACKWARD_TRAVERSAL_KEYS, backwardKeys);

addBrushSizeActions();
}

private static void keyPressed(KeyEvent e) {
Expand Down Expand Up @@ -239,15 +241,15 @@ public static int getNumModalDialogs() {
return numModalDialogs;
}

public static void addBrushSizeActions() {
private static void addBrushSizeActions() {
addHotKey(']', INCREASE_ACTIVE_BRUSH_SIZE_ACTION, true);
addHotKey('[', DECREASE_ACTIVE_BRUSH_SIZE_ACTION, true);
}

public static void registerDebugMouseWatching(boolean postEvents) {
Toolkit.getDefaultToolkit().addAWTEventListener(event -> {
MouseEvent e = (MouseEvent) event;
String msg = Tools.getCurrent().getName() + ": " + Debug.debugMouseEvent(e);
String msg = Tools.getCurrent().getName() + ": " + Debug.mouseEventAsString(e);
if (postEvents) {
Events.postMouseEvent(msg);
} else {
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/pixelitor/gui/PixelitorWindow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Laszlo Balazs-Csiki and Contributors
* Copyright 2024 Laszlo Balazs-Csiki and Contributors
*
* This file is part of Pixelitor. Pixelitor is free software: you
* can redistribute it and/or modify it under the terms of the GNU
Expand Down Expand Up @@ -80,7 +80,6 @@ private PixelitorWindow() {
setupIcons();

GlobalEvents.init();
GlobalEvents.addBrushSizeActions();

AppPreferences.loadFramePosition(this, screenSize);

Expand All @@ -99,7 +98,7 @@ private void setupWindowEvents() {
new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we) {
Pixelitor.exitApp(PixelitorWindow.this);
Pixelitor.warnAndExit(PixelitorWindow.this);
}

@Override
Expand Down Expand Up @@ -129,7 +128,7 @@ private void setupMacHandlers() {
desktop.setPreferencesHandler(e -> PreferencesPanel.showInDialog());
}
if (desktop.isSupported(APP_QUIT_HANDLER)) {
desktop.setQuitHandler((e, r) -> Pixelitor.exitApp(this));
desktop.setQuitHandler((e, r) -> Pixelitor.warnAndExit(this));
}
}
}
Expand Down Expand Up @@ -173,17 +172,16 @@ private void addStatusBar() {
}

private void setupIcons() {
URL imgURL32 = getClass().getResource("/images/pixelitor_icon32.png");
URL imgURL48 = getClass().getResource("/images/pixelitor_icon48.png");
URL imgURL256 = getClass().getResource("/images/pixelitor_icon256.png");
var clazz = getClass();
URL imgURL32 = clazz.getResource("/images/pixelitor_icon32.png");
URL imgURL48 = clazz.getResource("/images/pixelitor_icon48.png");
URL imgURL256 = clazz.getResource("/images/pixelitor_icon256.png");

if (imgURL32 != null && imgURL48 != null && imgURL256 != null) {
List<Image> icons = new ArrayList<>(2);
Image img32 = new ImageIcon(imgURL32).getImage();
Image img48 = new ImageIcon(imgURL48).getImage();
icons.add(new ImageIcon(imgURL32).getImage());
icons.add(new ImageIcon(imgURL48).getImage());
Image img256 = new ImageIcon(imgURL256).getImage();
icons.add(img32);
icons.add(img48);
icons.add(img256);
setIconImages(icons);

Expand All @@ -194,8 +192,8 @@ private void setupIcons() {
}
}
} else {
String msg = "icon imgURL is null";
Dialogs.showErrorDialog(this, "Error", msg);
Dialogs.showErrorDialog(this, "Error",
"icon imgURL is null");
}
}

Expand Down
Loading

0 comments on commit 777dd99

Please sign in to comment.