Added clampMaxImageSize so an image will be a max of that size, but

still maintain it's aspect ratio.
This commit is contained in:
nathan 2017-09-17 16:29:46 +02:00
parent ce758c4c17
commit cc035c7898
3 changed files with 34 additions and 4 deletions

View File

@ -76,7 +76,7 @@ Maven Info
<dependency>
<groupId>com.dorkbox</groupId>
<artifactId>Notify</artifactId>
<version>3.5</version>
<version>3.6</version>
</dependency>
</dependencies>
```

View File

@ -93,7 +93,7 @@ class Notify {
*/
public static
String getVersion() {
return "3.5";
return "3.6";
}
/**
@ -245,6 +245,12 @@ class Notify {
bufferedImage = ImageUtil.resizeImage(bufferedImage, -1, 48);
}
// we have to now clamp to a max dimension of 48
bufferedImage = ImageUtil.clampMaxImageSize(bufferedImage, 48);
// now we want to center the image
bufferedImage = ImageUtil.getSquareBufferedImage(bufferedImage);
this.icon = new ImageIcon(bufferedImage);
return this;
}

View File

@ -14,7 +14,11 @@
* limitations under the License.
*/
import java.awt.FlowLayout;
import java.awt.Image;
import java.io.IOException;
import java.io.InputStream;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@ -23,6 +27,8 @@ import javax.swing.JPanel;
import dorkbox.notify.Notify;
import dorkbox.notify.Pos;
import dorkbox.util.ActionHandler;
import dorkbox.util.ImageUtil;
import dorkbox.util.LocationResolver;
import dorkbox.util.ScreenUtil;
public
@ -142,7 +148,7 @@ class NotifyTest {
System.err.println("Notification " + finalI + " clicked on!");
}
});
notify.showConfirm();
notify.show();
try {
Thread.sleep(1000);
@ -151,6 +157,17 @@ class NotifyTest {
}
}
InputStream resourceAsStream = LocationResolver.getResourceAsStream("notify-dark.png");
Image image = null;
try {
image = ImageUtil.getImageImmediate(ImageIO.read(resourceAsStream));
// image = image.getScaledInstance(144, 104, Image.SCALE_SMOOTH);
image = image.getScaledInstance(104, 144, Image.SCALE_SMOOTH);
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < count; i++) {
final int finalI = i;
notify = Notify.create()
@ -171,7 +188,14 @@ class NotifyTest {
System.err.println("Notification " + finalI + " clicked on!");
}
});
notify.show();
if (i == 0) {
notify.image(image);
notify.show();
}
else {
notify.showConfirm();
}
try {
Thread.sleep(1000);