Skip to content

Commit

Permalink
last changes before 4.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalazscs committed Sep 26, 2019
1 parent 6cd96b1 commit ee8a049
Show file tree
Hide file tree
Showing 36 changed files with 478 additions and 204 deletions.
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/NewImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private NewImagePanel() {
heightTF = addTextField("heightTF", "Height:",
lastSize.height, gbh);

backgroundSelector = new JComboBox(FillType.values());
backgroundSelector = new JComboBox<>(FillType.values());
gbh.addLabelWithLastControl("Fill:", backgroundSelector);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/automate/AutoPaint.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private ConfigPanel() {


colorsLabel = new JLabel("Random Colors:");
colorsCB = new JComboBox(COLOR_SETTINGS);
colorsCB = new JComboBox<>(COLOR_SETTINGS);
colorsCB.setName("colorsCB");
colorsCB.setSelectedItem(defaultColors);
gbh.addTwoComponents(colorsLabel, colorsCB);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/automate/OutputFormatSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* A combo box for selecting an output format
*/
public class OutputFormatSelector extends JComboBox {
public class OutputFormatSelector extends JComboBox<OutputFormat> {
public OutputFormatSelector() {
super(OutputFormat.values());
setSelectedItem(OutputFormat.getLastUsed());
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/pixelitor/colors/FgBgColors.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ public static void setFGColor(Color c) {
selector.setFgColor(c, true);
}

public static void setFGColor(Color c, boolean notifyListeners) {
selector.setFgColor(c, notifyListeners);
}

public static void setBGColor(Color c) {
selector.setBgColor(c, true);
}

public static void setBGColor(Color c, boolean notifyListeners) {
selector.setBgColor(c, notifyListeners);
}

public static void randomize() {
selector.randomize();
}
Expand Down
39 changes: 28 additions & 11 deletions src/main/java/pixelitor/filters/comp/Crop.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import pixelitor.tools.Tools;
import pixelitor.utils.Messages;

import java.awt.Rectangle;
import java.awt.geom.AffineTransform;
import java.awt.geom.Rectangle2D;

Expand Down Expand Up @@ -62,14 +63,13 @@ public void process(Composition comp) {
imCropRect = imCropRect.createIntersection(canvas.getImBounds());
}

if (imCropRect.isEmpty()) {
// can't do anything useful
return;
}
Rectangle roundedImCropRect = roundCropRect(imCropRect);
assert !roundedImCropRect.isEmpty();

Guides guides = comp.getGuides();
Guides newGuides = null;
if (guides != null) {
newGuides = guides.copyForCrop(imCropRect);
newGuides = guides.copyForCrop(roundedImCropRect);
comp.setGuides(newGuides);
}

Expand All @@ -85,22 +85,22 @@ public void process(Composition comp) {
} else {
// if this crop was started from the crop tool, there
// still could be a selection that needs to be cropped
comp.intersectSelection(imCropRect);
comp.intersectSelection(roundedImCropRect);
}

comp.forEachLayer(layer -> {
layer.crop(imCropRect, deleteCroppedPixels, allowGrowing);
layer.crop(roundedImCropRect, deleteCroppedPixels, allowGrowing);
if (layer.hasMask()) {
layer.getMask().crop(imCropRect, deleteCroppedPixels, allowGrowing);
layer.getMask().crop(roundedImCropRect, deleteCroppedPixels, allowGrowing);
}
});

AffineTransform tx = createTransformForCropRect(imCropRect);
AffineTransform tx = createTransformForCropRect(roundedImCropRect);
MultiLayerEdit edit = new MultiLayerEdit("Crop", comp, backup, tx);
History.addEdit(edit);

int newWidth = (int) imCropRect.getWidth();
int newHeight = (int) imCropRect.getHeight();
int newWidth = roundedImCropRect.width;
int newHeight = roundedImCropRect.height;
canvas.changeImSize(newWidth, newHeight);

// The intersected selection, tool widgets etc. have to be moved
Expand All @@ -126,6 +126,23 @@ public void process(Composition comp) {
+ newWidth + " x " + newHeight + " pixels.");
}


// in zoomed-in images fractional widths and heights can happen
private static Rectangle roundCropRect(Rectangle2D rect) {
int x = (int) Math.round(rect.getX());
int y = (int) Math.round(rect.getY());
int width = (int) Math.round(rect.getWidth());
int height = (int) Math.round(rect.getHeight());

if (width == 0) {
width = 1;
}
if (height == 0) {
height = 1;
}
return new Rectangle(x, y, width, height);
}

/**
* The returned transform describes how the image space
* coordinates for a surviving pixel change after a crop
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/filters/curves/ToneCurves.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @author Łukasz Kurzaj [email protected]
*/
public class ToneCurves {
private final EnumMap<ToneCurveType, ToneCurve> curve = new EnumMap(ToneCurveType.class);
private final EnumMap<ToneCurveType, ToneCurve> curve = new EnumMap<>(ToneCurveType.class);
private ToneCurveType activeCurveType = ToneCurveType.RGB;
private Graphics2D gr;
private final BasicStroke gridStroke = new BasicStroke(1);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/filters/gui/ResizePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private ResizePanel(Canvas canvas) {
newHeightInPercent = 100.0;

String[] items = {"pixels", "percent"};
ComboBoxModel<String> comboBoxModel = new DefaultComboBoxModel(items);
ComboBoxModel<String> comboBoxModel = new DefaultComboBoxModel<>(items);
JPanel p = new JPanel();
p.setLayout(new GridBagLayout());

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/pixelitor/gui/ImageTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@

package pixelitor.gui;

import pixelitor.Composition;
import pixelitor.gui.utils.GUIUtils;

import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.io.File;

/**
* A {@link ViewContainer} used in the tabs UI.
Expand Down Expand Up @@ -93,6 +98,23 @@ public void actionPerformed(ActionEvent e) {
});
popup.add(OpenComps.CLOSE_UNMODIFIED_ACTION);
popup.add(OpenComps.CLOSE_ALL_ACTION);

if (Desktop.isDesktopSupported()) {
Composition comp = view.getComp();
File file = comp.getFile();
if (file != null && file.exists()) {
popup.addSeparator();
popup.add(GUIUtils.createShowInFileManagerAction(file));

String fileName = file.getName();
if (!fileName.endsWith("pxc")
&& !fileName.endsWith("ora")
&& Desktop.getDesktop().isSupported(Desktop.Action.PRINT)) {
popup.add(GUIUtils.createPrintFileAction(comp, file));
}
}
}

popup.addSeparator();
popup.add(tabsUI.getTabPlacementMenu());

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/pixelitor/gui/PreferencesPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private JPanel createGeneralPanel() {

GridBagHelper gbh = new GridBagHelper(generalPanel);

JComboBox uiChooser = new JComboBox(ImageArea.Mode.values());
JComboBox<ImageArea.Mode> uiChooser = new JComboBox<>(ImageArea.Mode.values());
uiChooser.setSelectedItem(ImageArea.getMode());
uiChooser.setName("uiChooser");
gbh.addLabelWithControl("Images In: ", uiChooser);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/pixelitor/gui/TabsUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ static class TabTitleRenderer extends JPanel {
gbc.weightx = 0;
add(new CloseTabButton(tab), gbc);

addRightClickTabPopup(tab);
}

private void addRightClickTabPopup(ImageTab tab) {
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/pixelitor/gui/utils/GUIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@
package pixelitor.gui.utils;

import com.bric.util.JVM;
import pixelitor.Composition;
import pixelitor.filters.gui.FilterParam;
import pixelitor.gui.BlendingModePanel;
import pixelitor.gui.PixelitorWindow;
import pixelitor.io.OpenSave;
import pixelitor.utils.Messages;
import pixelitor.utils.Utils;

import javax.swing.*;
import java.awt.Component;
import java.awt.Container;
import java.awt.Desktop;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.EventQueue;
Expand All @@ -36,10 +39,13 @@
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Random;
import java.util.Timer;
Expand Down Expand Up @@ -302,4 +308,61 @@ public void mouseReleased(MouseEvent e) {
}
});
}

public static Action createShowInFileManagerAction(File file) {
String menuName;
if (JVM.isWindows) {
menuName = "Show in Explorer...";
} else if (JVM.isMac) {
menuName = "Show in Finder...";
} else {
menuName = "Show Folder...";
}
return new AbstractAction(menuName) {
@Override
public void actionPerformed(ActionEvent e) {
try {
// TODO in Java 9 it can be done in a platform-independent way
// see https://stackoverflow.com/questions/7357969/how-to-use-java-code-to-open-windows-file-explorer-and-highlight-the-specified-f
if (JVM.isWindows) {
Runtime.getRuntime().exec("explorer.exe /select," + file.getCanonicalPath());
} else if (JVM.isMac) {
Runtime.getRuntime().exec("open -R " + file.getCanonicalPath());
} else {
// for now (java 8 compatibility) this only
// opens the folder, but without selecting the file
File dir = file.getParentFile();
Desktop.getDesktop().open(dir);
}
} catch (IOException ex) {
Messages.showException(ex);
}
}
};
}

public static AbstractAction createPrintFileAction(Composition comp, File file) {
return new AbstractAction("Print...") {
@Override
public void actionPerformed(ActionEvent e) {
if (comp.isDirty()) {
String msg = "<html>The file <i>" + file.getName() +
"</i> contains unsaved changes.<br>" +
"Only the saved changes can be printed.<br>" +
"Do you want to save your changes now?";
boolean saveAndPrint = Dialogs.showOKCancelDialog(msg, "Unsaved Changes",
new String[]{"Save and Print", "Cancel"}, 0, JOptionPane.QUESTION_MESSAGE);
if (!saveAndPrint) {
return;
}
OpenSave.save(comp, false);
}
try {
Desktop.getDesktop().print(file);
} catch (IOException ex) {
Messages.showException(ex);
}
}
};
}
}
14 changes: 6 additions & 8 deletions src/main/java/pixelitor/guides/Guides.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import pixelitor.utils.VisibleForTesting;

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Line2D;
import java.awt.geom.Rectangle2D;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -91,14 +91,12 @@ public Guides copyForEnlargedCanvas(int north, int east, int south, int west) {
return copy;
}

public Guides copyForCrop(Rectangle2D cropRect) {
public Guides copyForCrop(Rectangle cropRect) {
Canvas canvas = comp.getCanvas();
int northMargin = (int) cropRect.getY();
int westMargin = (int) cropRect.getX();
int southMargin = (int) (canvas.getImHeight()
- cropRect.getHeight() - cropRect.getY());
int eastMargin = (int) (canvas.getImWidth()
- cropRect.getWidth() - cropRect.getX());
int northMargin = cropRect.y;
int westMargin = cropRect.x;
int southMargin = canvas.getImHeight() - cropRect.height - cropRect.y;
int eastMargin = canvas.getImWidth() - cropRect.width - cropRect.x;

// a crop is a negative enlargement
return copyForEnlargedCanvas(
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/pixelitor/history/NewSelectionEdit.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,26 @@ public class NewSelectionEdit extends PixelitorEdit {
public NewSelectionEdit(Composition comp, Shape shape) {
super("Create Selection", comp);

assert comp.getView() != null;

newShape = shape;
}

@Override
public void undo() throws CannotUndoException {
super.undo();

assert comp.getView() != null;

comp.deselect(false);
}

@Override
public void redo() throws CannotRedoException {
super.redo();

assert comp.getView() != null;

comp.createSelectionFromShape(newShape);
}
}
3 changes: 3 additions & 0 deletions src/main/java/pixelitor/layers/ImageLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,9 @@ public void resize(int canvasTargetWidth, int canvasTargetHeight) {
}
}

assert (long) imgTargetWidth * imgTargetHeight < Integer.MAX_VALUE :
"bigLayer = " + bigLayer + ", tx = " + getTX() + ", ty = " + getTY();

BufferedImage resizedImg = ImageUtils.getFasterScaledInstance(
image, imgTargetWidth, imgTargetHeight,
VALUE_INTERPOLATION_BICUBIC);
Expand Down
Loading

0 comments on commit ee8a049

Please sign in to comment.