|
|
@@ -10,6 +10,7 @@ import javax.imageio.ImageIO;
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
import lombok.Getter;
|
|
|
+import lombok.NonNull;
|
|
|
import lombok.Synchronized;
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
|
@@ -23,15 +24,26 @@ public class ImagePanel extends JPanel {
|
|
|
setPreferredSize(new Dimension(200, 200));
|
|
|
}
|
|
|
|
|
|
- public ImagePanel(String imagePath) {
|
|
|
- try {
|
|
|
- image = ImageIO.read(new File(imagePath));
|
|
|
- } catch (IOException ex) {
|
|
|
- image = getPlaceholder();
|
|
|
- }
|
|
|
- setMinimumSize(new Dimension(200, 200));
|
|
|
- setPreferredSize(new Dimension(200, 200));
|
|
|
- }
|
|
|
+ public ImagePanel(final @NonNull String path) {
|
|
|
+ setImage(path);
|
|
|
+ setMinimumSize(new Dimension(200, 200));
|
|
|
+ setPreferredSize(new Dimension(200, 200));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setImage(final String path) {
|
|
|
+ if (path == null || !setImageImpl(path)) {
|
|
|
+ image = getPlaceholder();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean setImageImpl(final @NonNull String path) {
|
|
|
+ try {
|
|
|
+ image = ImageIO.read(new File(path));
|
|
|
+ return true;
|
|
|
+ } catch (IOException ex) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Synchronized
|
|
|
private static BufferedImage getDefaultImage() {
|