Skip to content

Commit

Permalink
last changes before 4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalazscs committed Mar 12, 2016
1 parent a28a077 commit a6184ed
Show file tree
Hide file tree
Showing 34 changed files with 360 additions and 170 deletions.
14 changes: 12 additions & 2 deletions src/main/java/pixelitor/Build.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,20 @@
* menus and runtime checks.
*/
public enum Build {
DEVELOPMENT {
}, FINAL {
DEVELOPMENT(true) {
}, FINAL(false) {
};

private final boolean development;

Build(boolean development) {
this.development = development;
}

public boolean isDevelopment() {
return development;
}

public static final boolean enableAdjLayers = false;

public static Build CURRENT = FINAL;
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/pixelitor/ConsistencyChecks.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
import java.awt.image.BufferedImage;
import java.util.Optional;

import static pixelitor.gui.ImageComponents.getActiveComp;

/**
* Consistency checks that run only in developer mode.
* They are enabled by the Build setting or by the assertions
Expand All @@ -44,11 +42,11 @@ public static void checkAll(Composition comp, boolean checkImageCoversCanvas) {
assert comp != null;

selectionCheck(comp);
fadeCheck(comp);
assert fadeCheck(comp);
if (checkImageCoversCanvas) {
imageCoversCanvasCheck(comp);
assert imageCoversCanvasCheck(comp);
}
layerDeleteActionEnabledCheck();
assert layerDeleteActionEnabledCheck();
}

public static boolean fadeCheck(Composition comp) {
Expand Down Expand Up @@ -87,15 +85,18 @@ public static boolean fadeCheck(ImageLayer layer) {
Utils.debugImage(previous, "previous");
String lastFadeableOp = History.getLastEditName();
Composition comp = layer.getComp();

String historyCompName = fadeableEdit.getComp().getName();
String activeCompName = ImageComponents.getActiveCompOrNull().getName();
throw new IllegalStateException("'Fade " + lastFadeableOp + "' would not work now:"
+ "\nFadeableEdit class = " + fadeableEdit.getClass().getName() + ", and name = " + fadeableEdit.getName()
+ "\n current selected dimensions: " + current.getWidth() + "x" + current.getHeight() + ", "
+ "history dimensions: " + previous.getWidth() + "x" + previous.getHeight()
+ "\nchecked composition = " + comp.getName() + "(hasSelection = " + comp.hasSelection()
+ (comp.hasSelection() ? ", selection bounds = " + comp.getSelectionOrNull().getShapeBounds() : "") + ")"
+ "\nchecked composition canvas = " + comp.getCanvas().getBounds()
+ "\nhistory composition = " + fadeableEdit.getComp().getName()
+ "\nactive composition = " + ImageComponents.getActiveCompOrNull().getName()
+ "\nhistory composition = " + historyCompName
+ "\nactive composition = " + activeCompName
+ "\n"


Expand Down Expand Up @@ -193,22 +194,21 @@ public static boolean layerDeleteActionEnabledCheck() {
return true;
}

Optional<Composition> optComp = getActiveComp();
if (!optComp.isPresent()) {
Composition comp = ImageComponents.getActiveCompOrNull();
if (comp == null) {
return true;
}
Composition comp = optComp.get();

boolean enabled = action.isEnabled();

int nrLayers = comp.getNrLayers();
if (enabled) {
if (nrLayers <= 1) {
throw new IllegalStateException("enabled, but nrLayers = " + nrLayers);
throw new IllegalStateException("delete layer enabled for " + comp.getName() + ", but nrLayers = " + nrLayers);
}
} else { // disabled
if (nrLayers >= 2) {
throw new IllegalStateException("disabled, but nrLayers = " + nrLayers);
throw new IllegalStateException("delete layer disabled for " + comp.getName() + ", but nrLayers = " + nrLayers);
}
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/filters/ParamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ParamTest() {

@Override
public BufferedImage doTransform(BufferedImage src, BufferedImage dest) {
if ((Build.CURRENT == Build.DEVELOPMENT) && (!RandomGUITest.isRunning())) {
if ((Build.CURRENT.isDevelopment()) && (!RandomGUITest.isRunning())) {
System.out.println("ParamTest.doTransform CALLED");
}

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/pixelitor/gui/FgBgColorSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public class FgBgColorSelector extends JLayeredPane {

private boolean layerMaskEditing = false;

public FgBgColorSelector() {
public static FgBgColorSelector INSTANCE = new FgBgColorSelector();

private FgBgColorSelector() {
setLayout(null);

initFGButton();
Expand Down Expand Up @@ -237,4 +239,10 @@ public void setLayerMaskEditing(boolean layerMaskEditing) {
}
}
}

public void dumpState() {
System.out.println("FgBgColorSelector::dumpState: layerMaskEditing = " + layerMaskEditing);
System.out.println("FgBgColorSelector::dumpState: fgColor = " + fgColor + ", bgColor = " + bgColor);
System.out.println("FgBgColorSelector::dumpState: maskFgColor = " + maskFgColor + ", maskBgColor = " + maskBgColor);
}
}
61 changes: 54 additions & 7 deletions src/main/java/pixelitor/gui/ImageComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import pixelitor.layers.ImageLayer;
import pixelitor.layers.Layer;
import pixelitor.layers.MaskViewMode;
import pixelitor.layers.TextLayer;
import pixelitor.menus.view.ZoomLevel;
import pixelitor.menus.view.ZoomMenu;
import pixelitor.selection.Selection;
Expand All @@ -45,7 +46,9 @@
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;

/**
* Static methods for maintaining the list of open ImageComponent objects
Expand Down Expand Up @@ -163,8 +166,7 @@ public static BufferedImage getActiveCompositeImageOrNull() {
*/
public static void toolCropActiveImage(boolean allowGrowing) {
try {
Optional<Composition> opt = getActiveComp();
opt.ifPresent(comp -> {
onActiveComp(comp -> {
Rectangle2D cropRect = Tools.CROP.getCropRect(comp.getIC());
new Crop(cropRect, false, allowGrowing).process(comp);
});
Expand Down Expand Up @@ -211,7 +213,7 @@ public static void setActiveIC(ImageComponent ic, boolean activate) {
/**
* When a new tool is activated, the cursor has to be changed for each image
*/
public static void setToolCursor(Cursor cursor) {
public static void setCursorForAll(Cursor cursor) {
for (ImageComponent ic : icList) {
ic.setCursor(cursor);
}
Expand All @@ -238,7 +240,6 @@ private static void onAllImagesClosed() {
* Another image became active
*/
public static void activeImageHasChanged(ImageComponent ic) {
// not called in unit tests
ImageComponent oldIC = activeIC;

setActiveIC(ic, false);
Expand Down Expand Up @@ -329,17 +330,63 @@ public static void reloadActiveFromFile() {
}

public static void onActiveIC(Consumer<ImageComponent> action) {
if(activeIC != null) {
if (activeIC != null) {
action.accept(activeIC);
}
}

public static void onActiveICAndComp(BiConsumer<ImageComponent, Composition> action) {
if (activeIC != null) {
Composition comp = activeIC.getComp();
action.accept(activeIC, comp);
}
}

public static <T> T fromActiveIC(Function<ImageComponent, T> function) {
return function.apply(activeIC);
}

public static void onAllImages(Consumer<ImageComponent> action) {
//noinspection Convert2streamapi
for (ImageComponent ic : icList) {
action.accept(ic);
}
}

public static void onActiveComp(Consumer<Composition> action) {
if (activeIC != null) {
Composition comp = activeIC.getComp();
action.accept(comp);
}
}

public static void onActiveSelection(Consumer<Selection> action) {
if(activeIC != null) {
if (activeIC != null) {
Selection selection = activeIC.getComp().getSelectionOrNull();
if(selection != null) {
if (selection != null) {
action.accept(selection);
}
}
}

public static void onActiveLayer(Consumer<Layer> action) {
if (activeIC != null) {
Layer activeLayer = activeIC.getComp().getActiveLayer();
action.accept(activeLayer);
}
}

public static void onActiveImageLayer(Consumer<ImageLayer> action) {
if (activeIC != null) {
ImageLayer activeLayer = (ImageLayer) activeIC.getComp().getActiveLayer();
action.accept(activeLayer);
}
}

public static void onActiveTextLayer(Consumer<TextLayer> action) {
if (activeIC != null) {
TextLayer activeLayer = (TextLayer) activeIC.getComp().getActiveLayer();
action.accept(activeLayer);
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/pixelitor/gui/PixelitorWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void addToolsPanel() {
verticalBoxWest = Box.createVerticalBox();
toolsPanel = new ToolsPanel();

FgBgColors.setGUI(new FgBgColorSelector());
FgBgColors.setGUI(FgBgColorSelector.INSTANCE);
if (AppPreferences.WorkSpace.getToolsVisibility()) {
verticalBoxWest.add(toolsPanel);
verticalBoxWest.add(FgBgColors.getGUI());
Expand Down Expand Up @@ -164,7 +164,7 @@ public void setHistogramsVisibility(boolean v, boolean revalidate) {
if (v) {
verticalBoxEast.add(histogramsPanel);

ImageComponents.getActiveComp().ifPresent(histogramsPanel::updateFromCompIfShown);
ImageComponents.onActiveComp(histogramsPanel::updateFromCompIfShown);
} else {
verticalBoxEast.remove(histogramsPanel);
}
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/pixelitor/gui/utils/Dialogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ public static void showExceptionDialog(Throwable e, Thread thread) {
}

if (RandomGUITest.isRunning()) {
Events.dump();
Events.dumpAll();
History.showHistory();
Toolkit.getDefaultToolkit().beep();

playWarningSound();
} else if(Build.CURRENT == Build.DEVELOPMENT) {
Events.dump();

RandomGUITest.stop();
} else if(Build.CURRENT.isDevelopment()) {
Events.dumpActive();
}

Frame parent = getParentForDialogs();
Expand Down Expand Up @@ -189,7 +190,7 @@ private static void playWarningSound() {
}

public static void showOutOfMemoryDialog(OutOfMemoryError e) {
if (Build.CURRENT == Build.DEVELOPMENT) {
if (Build.CURRENT.isDevelopment()) {
e.printStackTrace();
}
String message = "<html><b>Out of memory error.</b> You can try <ul>" +
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/pixelitor/gui/utils/ImagePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ protected void paintComponent(Graphics g) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());

if (image == null) {
return;
}

try {
if (drawCheckerBoard) {
Graphics2D g2 = (Graphics2D) g;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/pixelitor/layers/Layer.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ public void addMask(LayerMaskAddType addType) {
editName = "Layer Mask from Selection";
}

addImageAsMask(bwMask, deselect, editName);
addImageAsMask(bwMask, deselect, editName, false);
}

public void addImageAsMask(BufferedImage bwMask, boolean deselect, String editName) {
public void addImageAsMask(BufferedImage bwMask, boolean deselect, String editName, boolean inheritTranslation) {
assert mask == null;

mask = new LayerMask(comp, bwMask, this);
mask = new LayerMask(comp, bwMask, this, inheritTranslation);
maskEnabled = true;

// needs to be added first, because the inherited layer
Expand Down Expand Up @@ -336,7 +336,7 @@ public void addOrReplaceMaskImage(BufferedImage bwMask, String editName) {
if (hasMask()) {
mask.replaceImage(bwMask, editName);
} else {
addImageAsMask(bwMask, false, editName);
addImageAsMask(bwMask, false, editName, true);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/pixelitor/layers/LayerBlendingModePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import pixelitor.utils.ImageSwitchListener;
import pixelitor.utils.UpdateGUI;

import static pixelitor.gui.ImageComponents.getActiveLayer;
import static pixelitor.gui.ImageComponents.onActiveLayer;

/**
* The GUI selector for the opacity and blending mode of the layers
Expand Down Expand Up @@ -58,14 +58,14 @@ private LayerBlendingModePanel() {
}

private void opacityChanged() {
getActiveLayer().ifPresent(layer -> {
onActiveLayer(layer -> {
float floatValue = getOpacity();
layer.setOpacity(floatValue, UpdateGUI.NO, AddToHistory.YES, true);
});
}

private void blendingModeChanged() {
getActiveLayer().ifPresent(layer -> {
onActiveLayer(layer -> {
BlendingMode blendingMode = getBlendingMode();
layer.setBlendingMode(blendingMode, UpdateGUI.NO, AddToHistory.YES, true);
});
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/pixelitor/layers/LayerMask.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ public class LayerMask extends ImageLayer {

public static final Composite RUBYLITH_COMPOSITE = AlphaComposite.SrcOver.derive(0.5f);

public LayerMask(Composition comp, BufferedImage bwImage, Layer layer) {
public LayerMask(Composition comp, BufferedImage bwImage, Layer layer, boolean inheritTranslation) {
super(comp, bwImage, layer.getName() + " MASK", layer);

if (inheritTranslation && layer instanceof ContentLayer) {
ContentLayer contentLayer = (ContentLayer) layer;
translationX = contentLayer.getTX();
translationY = contentLayer.getTY();
}

assert bwImage.getType() == BufferedImage.TYPE_BYTE_GRAY;
}

Expand Down Expand Up @@ -139,8 +145,9 @@ public void updateIconImage() {
* to the given layer
*/
public LayerMask duplicate(Layer master) {
LayerMask d = new LayerMask(comp, ImageUtils.copyImage(image), master);
BufferedImage maskImageCopy = ImageUtils.copyImage(image);

LayerMask d = new LayerMask(comp, maskImageCopy, master, false);
d.setTranslation(getTX(), getTY());

return d;
Expand Down
Loading

0 comments on commit a6184ed

Please sign in to comment.