1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package de.aikiit.fotorenamer.util;
16
17 import lombok.AccessLevel;
18 import lombok.NoArgsConstructor;
19 import org.apache.logging.log4j.Logger;
20 import org.apache.logging.log4j.LogManager;
21
22 import javax.swing.ImageIcon;
23 import java.awt.Component;
24 import java.awt.Dimension;
25 import java.awt.Toolkit;
26
27
28
29
30
31
32
33 @NoArgsConstructor(access = AccessLevel.PRIVATE)
34 public final class ComponentGaugeUtil {
35
36
37
38 private static final Logger LOG =
39 LogManager.getLogger(ComponentGaugeUtil.class);
40
41
42
43
44
45
46 public static void makeCentered(final Component component) {
47 Toolkit toolkit = Toolkit.getDefaultToolkit();
48 Dimension dim = toolkit.getScreenSize();
49 int screenWidth = dim.width;
50 int screenHeight = dim.height;
51 component.setLocation((screenWidth - component.getSize().width) / 2,
52 (screenHeight - component.getSize().height) / 2);
53 }
54
55
56
57
58
59
60
61
62 public static ImageIcon createImageIcon(final String path) {
63 assert path != null : "Path for image icon needs to be set.";
64 LOG.debug("Creating image icon from path " + path);
65 java.net.URL imgURL = ComponentGaugeUtil.class.getResource(path);
66 LOG.debug("extracted URL is: " + imgURL);
67
68 if (imgURL != null) {
69 return new ImageIcon(imgURL);
70 } else {
71 LOG.error("Could not generate a valid URL from the given path: "
72 + path);
73 return null;
74 }
75 }
76 }