1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package net.curre.prefcount.service;
16
17 import java.awt.*;
18 import java.util.logging.Level;
19 import java.util.logging.Logger;
20 import javax.swing.*;
21
22 import net.curre.prefcount.gui.theme.skin.*;
23 import net.curre.prefcount.util.Utilities;
24
25 import org.jvnet.substance.SubstanceLookAndFeel;
26
27
28
29
30
31
32
33
34
35 public class LafThemeService {
36
37
38 private static Logger log = Logger.getLogger(LafThemeService.class.toString());
39
40
41 private static LafThemeService instance;
42
43
44 private static SubstanceLookAndFeel substanceLaf;
45
46
47 private static PrefSkin currentSkin;
48
49
50 public static final PrefSkin[] AVAILABLE_SKINS = {
51 new DefaultSkin(), new BusinessSkin(), new ModerateSkin(),
52 new NebulaSkin(), new OfficeBlue2007Skin(), new GreenMagicSkin(),
53 new MangoSkin(), new CremeSkin(), new FieldOfWheatSkin(),
54 new FindingNemoSkin()
55 };
56
57 static {
58 instance = new LafThemeService();
59 substanceLaf = new SubstanceLookAndFeel();
60
61 currentSkin = AVAILABLE_SKINS[0];
62 }
63
64
65 private LafThemeService() {
66 }
67
68
69
70
71
72
73 public static LafThemeService getInstance() {
74 return instance;
75 }
76
77
78
79
80
81
82 public PrefSkin getCurrentSkin() {
83 return currentSkin;
84 }
85
86
87
88
89
90
91
92
93 public void setLookAndFeel(final String skinId, boolean isFirstRun) {
94
95
96 try {
97 currentSkin = findSkinById(skinId);
98 if (isFirstRun) {
99 UIManager.setLookAndFeel(substanceLaf);
100
101
102 for (Frame frame : Frame.getFrames()) {
103 frame.setBackground(currentSkin.getMainBackgroundColor());
104 }
105 }
106 if (!isFirstRun && DefaultSkin.NAME_KEY.equals(skinId)) {
107 Utilities.displayMessageInFrame("pref.settings.skin.needsRestart");
108 } else {
109 SubstanceLookAndFeel.setSkin(currentSkin.getSubstanceSkinClassName());
110 }
111
112 } catch (Exception e) {
113 log.log(Level.WARNING, "Unable to set LAF", e);
114 }
115 }
116
117
118
119
120
121
122
123
124 public PrefSkin findSkinById(String skinId) throws ServiceException {
125 for (PrefSkin skin : AVAILABLE_SKINS) {
126 if (skin.getNameResourceKey().equals(skinId)) {
127 return skin;
128 }
129 }
130 throw new ServiceException("Skin with id \"" + skinId + "\" was not found!");
131 }
132
133 }