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.MenuBar;
18 import java.awt.print.PrinterException;
19 import java.awt.print.PrinterJob;
20 import java.util.logging.Logger;
21 import javax.swing.JFrame;
22 import javax.swing.JMenuBar;
23
24 import net.curre.prefcount.PrefCountRegistry;
25 import net.curre.prefcount.gui.HelpFrame;
26 import net.curre.prefcount.gui.MainWindow;
27 import net.curre.prefcount.gui.Template;
28 import net.curre.prefcount.gui.menu.AwtMenuBar;
29 import net.curre.prefcount.gui.menu.PrefCountMenuBar;
30 import net.curre.prefcount.gui.menu.SwingMenuBar;
31 import net.curre.prefcount.gui.theme.skin.PrefSkin;
32 import net.curre.prefcount.gui.type.WindowComponent;
33 import net.curre.prefcount.util.Utilities;
34
35
36
37
38
39
40
41
42
43 public class MainService {
44
45
46 private static Logger log = Logger.getLogger(MainService.class.toString());
47
48
49 private static HelpFrame helpFrame;
50
51
52 private MainService() {
53 }
54
55
56
57
58
59
60 public static synchronized void doShowHelp(WindowComponent itemEnum) {
61
62 if (helpFrame == null) {
63 helpFrame = new HelpFrame();
64 }
65
66 helpFrame.refreshText(itemEnum);
67 }
68
69
70 public static void doPrint() {
71 MainWindow window = PrefCountRegistry.getInstance().getMainWindow();
72 PrinterJob printJob = PrinterJob.getPrinterJob();
73 printJob.setPrintable(window);
74 if (printJob.printDialog()) {
75 try {
76 printJob.print();
77 } catch (PrinterException e) {
78 log.severe("Error printing: " + e);
79 }
80 }
81 }
82
83
84
85
86
87
88 public static void doPrintTemplate(int numberOfPlayers) {
89 Template template = new Template(numberOfPlayers);
90 PrinterJob printJob = PrinterJob.getPrinterJob();
91 printJob.setPrintable(template);
92 if (printJob.printDialog()) {
93 try {
94 printJob.print();
95 } catch (PrinterException e) {
96 log.severe("Error printing: " + e);
97 }
98 }
99 }
100
101
102 public static void doQuit() {
103
104 if (helpFrame != null) {
105 helpFrame.setVisible(false);
106 helpFrame.dispose();
107 }
108
109 MainWindow window = PrefCountRegistry.getInstance().getMainWindow();
110 window.setVisible(false);
111
112
113 PrefSkin skin = LafThemeService.getInstance().getPendingSkin();
114 if (skin != null) {
115 SettingsService.updateSkin(skin);
116 try {
117 SettingsService.persistSettings();
118 } catch (ServiceException e) {
119 log.warning("Error while saving the settings: " + e);
120 }
121 }
122
123 if (window.playerDialogFrame != null) {
124 window.playerDialogFrame.setVisible(false);
125 window.playerDialogFrame.dispose();
126 }
127 window.dispose();
128
129 System.exit(0);
130 }
131
132
133
134
135
136
137
138
139
140
141
142 public static PrefCountMenuBar addPlayerDialogMenuBar(JFrame frame) {
143 PrefCountMenuBar menuBar = null;
144 if (Utilities.isMacOs()) {
145 menuBar = new AwtMenuBar(PrefCountMenuBar.MenuBarType.PLAYER_DIALOG);
146 frame.setMenuBar((MenuBar) menuBar);
147 }
148 return menuBar;
149 }
150
151
152
153
154
155
156
157
158
159
160
161 public static PrefCountMenuBar addMainWindowMenuBar(JFrame frame) {
162 PrefCountMenuBar menuBar;
163 if (Utilities.isMacOs()) {
164 menuBar = new AwtMenuBar(PrefCountMenuBar.MenuBarType.MAIN_WINDOW);
165 frame.setMenuBar((MenuBar) menuBar);
166 } else {
167 menuBar = new SwingMenuBar();
168 frame.setJMenuBar((JMenuBar) menuBar);
169 }
170 return menuBar;
171 }
172
173
174 }