1 | /** |
---|
2 | * |
---|
3 | */ |
---|
4 | package com.framsticks.gui; |
---|
5 | |
---|
6 | import org.apache.logging.log4j.Logger; |
---|
7 | import org.apache.logging.log4j.LogManager; |
---|
8 | |
---|
9 | import javax.swing.*; |
---|
10 | |
---|
11 | import java.util.HashMap; |
---|
12 | import java.util.Map; |
---|
13 | |
---|
14 | /** |
---|
15 | * Class provides icons images. |
---|
16 | */ |
---|
17 | public class ImageProvider { |
---|
18 | |
---|
19 | private final static Logger log = LogManager.getLogger(ImageProvider.class.getName()); |
---|
20 | |
---|
21 | |
---|
22 | /** |
---|
23 | * HashMap stores icons. Key is icon path, Value is icon. |
---|
24 | */ |
---|
25 | private static Map<String, ImageIcon> icons = new HashMap<String, ImageIcon>(); |
---|
26 | |
---|
27 | public static final String IMAGE = "image.png"; |
---|
28 | public static final String LOGO = "logo.png"; |
---|
29 | |
---|
30 | public static final String FOLDER_OPEN = "folder_open.png"; |
---|
31 | public static final String FOLDER_CLOSED = "folder_close.png"; |
---|
32 | public static final String NODE = "node.png"; |
---|
33 | |
---|
34 | public static final String SERVER = "server.png"; |
---|
35 | |
---|
36 | public static final String CLI = "cli.png"; |
---|
37 | public static final String EVENT = "event.png"; |
---|
38 | public static final String SIMULATOR = "simulator.png"; |
---|
39 | |
---|
40 | public static final String WORLD = "World.png"; |
---|
41 | public static final String GENEPOOLS = "genepools.png"; |
---|
42 | public static final String GENEPOOLS_GROUP = "genepoolsgroup.png"; |
---|
43 | public static final String POPULATIONS = "populations.png"; |
---|
44 | public static final String POPULATION_GROUP = "populationgroup.png"; |
---|
45 | public static final String STATISTIC = "statistic.png"; |
---|
46 | public static final String EXPERIMENT = "experiment.png"; |
---|
47 | |
---|
48 | public static final String CREATURES_GROUP = "CreaturesGroup.png"; |
---|
49 | public static final String CREATURE = "Creature.png"; |
---|
50 | |
---|
51 | public static final String GENOTYPES_GROUP = "GenotypeGroup.png"; |
---|
52 | public static final String GENOTYPES = "Genotype.png"; |
---|
53 | |
---|
54 | public static final String JOINT_GROUP = "l_Joint.png"; |
---|
55 | public static final String JOINT = "Joint.png"; |
---|
56 | public static final String MECH_JOINT_GROUP = "l_MechJoint.png"; |
---|
57 | public static final String MECH_JOINT = "MechJoint.png"; |
---|
58 | public static final String PART_GROUP = "l_Part.png"; |
---|
59 | public static final String PART = "Part.png"; |
---|
60 | public static final String MECH_PART_GROUP = "l_MechPart.png"; |
---|
61 | public static final String MECH_PART = "MechPart.png"; |
---|
62 | public static final String NEURON_GROUP = "l_Neuro.png"; |
---|
63 | public static final String NEURON = "Neuro.png"; |
---|
64 | public static final String NEURON_DEF_GROUP = "l_NeuroDef.png"; |
---|
65 | public static final String NEURON_DEF = "NeuroDef.png"; |
---|
66 | |
---|
67 | public static final String FAVORITES = "stats.png"; |
---|
68 | public static final String FAVORITE_FIELDS = "FavouriteFields.png"; |
---|
69 | |
---|
70 | public static final String SIM_START = "sim_start.png"; |
---|
71 | public static final String SIM_STEP = "sim_step.png"; |
---|
72 | public static final String SIM_STOP = "sim_stop.png"; |
---|
73 | |
---|
74 | /** |
---|
75 | * Loads image icon with the given getName(path). |
---|
76 | * |
---|
77 | * @param imageName Name of the image(including extension) which will be loaded. |
---|
78 | * @return Loaded image. |
---|
79 | */ |
---|
80 | public static ImageIcon loadImage(final String imageName) { |
---|
81 | if (icons.containsKey(imageName)) { |
---|
82 | return icons.get(imageName); |
---|
83 | } |
---|
84 | String resourceName = "/shared/res/network/" + imageName; |
---|
85 | try { |
---|
86 | ImageIcon icon = new ImageIcon(ImageProvider.class.getResource(resourceName)); |
---|
87 | icons.put(imageName, icon); |
---|
88 | return icon; |
---|
89 | } catch (Exception ignored) { |
---|
90 | log.error("failed to read icon: {}", resourceName); |
---|
91 | } |
---|
92 | return null; |
---|
93 | } |
---|
94 | } |
---|