1 | // Jomic - a viewer for comic book archives. |
2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
3 | // |
4 | // This program is free software: you can redistribute it and/or modify |
5 | // it under the terms of the GNU General Public License as published by |
6 | // the Free Software Foundation, either version 3 of the License, or |
7 | // (at your option) any later version. |
8 | // |
9 | // This program is distributed in the hope that it will be useful, |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | // GNU General Public License for more details. |
13 | // |
14 | // You should have received a copy of the GNU General Public License |
15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | package net.sf.jomic.ui; |
17 | |
18 | import java.awt.Event; |
19 | import java.awt.Toolkit; |
20 | import java.awt.event.ActionEvent; |
21 | import java.awt.event.ActionListener; |
22 | import java.awt.event.KeyEvent; |
23 | import java.util.Iterator; |
24 | import java.util.LinkedList; |
25 | import java.util.List; |
26 | |
27 | import javax.swing.ButtonGroup; |
28 | import javax.swing.JCheckBoxMenuItem; |
29 | import javax.swing.JMenu; |
30 | import javax.swing.JMenuBar; |
31 | import javax.swing.JMenuItem; |
32 | import javax.swing.JRadioButtonMenuItem; |
33 | import javax.swing.KeyStroke; |
34 | import javax.swing.text.DefaultEditorKit; |
35 | |
36 | import net.roydesign.app.AboutJMenuItem; |
37 | import net.roydesign.app.Application; |
38 | import net.roydesign.app.QuitJMenuItem; |
39 | import net.sf.jomic.common.ComicSheetRenderSettings; |
40 | import net.sf.jomic.common.PropertyConstants; |
41 | import net.sf.jomic.common.Settings; |
42 | import net.sf.jomic.tools.ActionDelegate; |
43 | import net.sf.jomic.tools.ImageRenderSettings; |
44 | import net.sf.jomic.tools.ImageTools; |
45 | import net.sf.jomic.tools.KeyValuePair; |
46 | import net.sf.jomic.tools.LocaleTools; |
47 | import net.sf.jomic.tools.SystemTools; |
48 | import net.sf.jomic.tools.UiTools; |
49 | |
50 | import org.apache.commons.logging.Log; |
51 | import org.apache.commons.logging.LogFactory; |
52 | |
53 | /** |
54 | * Menubar for all comic operations. |
55 | * |
56 | * @author Thomas Aglassinger |
57 | */ |
58 | public class JomicMenuBar extends JMenuBar implements ActionListener |
59 | { |
60 | private static Log logger = LogFactory.getLog(JomicMenuBar.class); |
61 | private AboutJMenuItem aboutItem; |
62 | private List actionListenersToRemoveList; |
63 | private JMenuItem closeItem; |
64 | private JMenuItem contactAuthorItem; |
65 | private JMenuItem convertItem; |
66 | private JMenuItem copyItem; |
67 | private JMenuItem cutItem; |
68 | private ActionDelegate delegate; |
69 | private JMenu editMenu; |
70 | private JMenuItem exportAllItem; |
71 | private JMenuItem exportItem; |
72 | private JMenu fileMenu; |
73 | private JRadioButtonMenuItem fitActualSizeItem; |
74 | private JRadioButtonMenuItem fitAllItem; |
75 | private JRadioButtonMenuItem fitHeightItem; |
76 | private JRadioButtonMenuItem fitWidthItem; |
77 | private JMenuItem fullScreenItem; |
78 | private JMenuItem goFirstItem; |
79 | private JMenuItem goLastItem; |
80 | private JMenu goMenu; |
81 | private JMenuItem goNextItem; |
82 | private JMenuItem goPageItem; |
83 | private JMenuItem goPreviousItem; |
84 | private JMenuItem helpItem; |
85 | private JMenu helpMenu; |
86 | private JMenuItem homePageItem; |
87 | private JomicApplication jomicApplication; |
88 | private LocaleTools localeTools; |
89 | private JMenuItem newItem; |
90 | private JMenuItem openItem; |
91 | private JMenuItem openNextItem; |
92 | private JMenuItem openPreviousItem; |
93 | private OpenRecentMenu openRecentMenu; |
94 | private JMenuItem pasteItem; |
95 | private QuitJMenuItem quitItem; |
96 | private JMenuItem reportBugItem; |
97 | private JMenuItem requestFeatureItem; |
98 | private JMenuItem revealItem; |
99 | private JMenuItem rotateLeftItem; |
100 | private JMenuItem rotateRightItem; |
101 | private ColorSettingMenuItem setBackgoundColorItem; |
102 | private Settings settings; |
103 | private JMenuItem systemInfoItem; |
104 | private SystemTools systemTools; |
105 | private BooleanSettingMenuItem toggleRotateOnlySinglePortraitImages; |
106 | private JCheckBoxMenuItem toggleShowInfoItem; |
107 | private BooleanSettingMenuItem toggleShowThumbsItem; |
108 | private BooleanSettingMenuItem toggleShowToolbarItem; |
109 | private BooleanSettingMenuItem toggleSwapLeftAndRightImageItem; |
110 | private BooleanSettingMenuItem toggleTwoPagesItem; |
111 | private UiTools uiTools; |
112 | private JMenu viewMenu; |
113 | |
114 | public JomicMenuBar() { |
115 | super(); |
116 | settings = Settings.instance(); |
117 | jomicApplication = JomicApplication.instance(); |
118 | localeTools = LocaleTools.instance(); |
119 | systemTools = SystemTools.instance(); |
120 | uiTools = UiTools.instance(); |
121 | |
122 | delegate = new ActionDelegate(logger); |
123 | actionListenersToRemoveList = new LinkedList(); |
124 | |
125 | // Create menus. |
126 | fileMenu = createFileMenu(); |
127 | editMenu = createEditMenu(); |
128 | viewMenu = createViewMenu(); |
129 | goMenu = createGoMenu(); |
130 | helpMenu = createHelpMenu(); |
131 | |
132 | // Build menu bar. |
133 | add(fileMenu); |
134 | //TODO: add(editMenu); |
135 | add(viewMenu); |
136 | add(goMenu); |
137 | add(helpMenu); |
138 | |
139 | uiTools.fillMnemonics(this); |
140 | updateFileOpenRecent(); |
141 | setUIState(UIStates.EMPTY); |
142 | } |
143 | |
144 | /** |
145 | * Enable/disable "Go" menu depending on page. |
146 | */ |
147 | void setEnabledGoMenu(final boolean isFirst, final boolean isLast) { |
148 | goFirstItem.setEnabled(!isFirst); |
149 | goLastItem.setEnabled(!isLast); |
150 | goNextItem.setEnabled(!isLast); |
151 | goPreviousItem.setEnabled(!isFirst); |
152 | goPageItem.setEnabled(!(isFirst && isLast)); |
153 | } |
154 | |
155 | /** |
156 | * Enable/disable "File > Open next" menu item. |
157 | */ |
158 | void setEnabledOpenPreviousAndNext(final boolean hasPreviousFile, final boolean hasNextFile) { |
159 | openPreviousItem.setEnabled(hasPreviousFile); |
160 | openNextItem.setEnabled(hasNextFile); |
161 | } |
162 | |
163 | void setUIState(String state) { |
164 | assert UIStates.isValidState(state); |
165 | if (state.equals(UIStates.EMPTY)) { |
166 | openItem.setEnabled(true); |
167 | viewMenu.setEnabled(false); |
168 | goMenu.setEnabled(false); |
169 | openRecentMenu.setEnabledUnlessEmpty(); |
170 | setEnabledOpenPreviousAndNext(false, false); |
171 | revealItem.setEnabled(false); |
172 | exportItem.setEnabled(false); |
173 | exportAllItem.setEnabled(false); |
174 | } else if (state.equals(UIStates.OPENING)) { |
175 | openItem.setEnabled(false); |
176 | openRecentMenu.setEnabled(false); |
177 | setEnabledOpenPreviousAndNext(false, false); |
178 | revealItem.setEnabled(false); |
179 | exportItem.setEnabled(false); |
180 | exportAllItem.setEnabled(false); |
181 | } else if (state.equals(UIStates.VIEWING)) { |
182 | openItem.setEnabled(true); |
183 | viewMenu.setEnabled(true); |
184 | goMenu.setEnabled(true); |
185 | openRecentMenu.setEnabledUnlessEmpty(); |
186 | revealItem.setEnabled(true); |
187 | exportItem.setEnabled(true); |
188 | exportAllItem.setEnabled(true); |
189 | // We cannot call setEnabledOpenPreviousAndNext() here because we |
190 | //do not know if a previous/next file exist. |
191 | } else { |
192 | assert false : "state = " + state; |
193 | } |
194 | } |
195 | |
196 | private void setKeyAndMask(JMenuItem item, int key, int additionalMask) { |
197 | assert item != null; |
198 | if (key != 0) { |
199 | int mask = additionalMask | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); |
200 | |
201 | item.setAccelerator(KeyStroke.getKeyStroke(key, mask)); |
202 | } |
203 | } |
204 | |
205 | public final void actionPerformed(ActionEvent event) { |
206 | assert event != null; |
207 | delegate.actionPerformed(event); |
208 | } |
209 | |
210 | public final void addActionListener(ActionListener listener) { |
211 | delegate.addActionListener(listener); |
212 | } |
213 | |
214 | public final void removeActionListener(ActionListener listener) { |
215 | delegate.removeActionListener(listener); |
216 | } |
217 | |
218 | /** |
219 | * Update <i>File > Open recent</i> menu with values currently stored in settings. |
220 | * |
221 | * @see Settings#getRecentFiles() |
222 | */ |
223 | final void updateFileOpenRecent() { |
224 | openRecentMenu.updateMenuItems(settings.getRecentFiles()); |
225 | } |
226 | |
227 | public void dispose() { |
228 | if (openRecentMenu != null) { |
229 | openRecentMenu.dispose(); |
230 | } |
231 | |
232 | // Remove all action listeners. |
233 | Iterator removeListenersRider = actionListenersToRemoveList.iterator(); |
234 | |
235 | while (removeListenersRider.hasNext()) { |
236 | KeyValuePair pair = (KeyValuePair) removeListenersRider.next(); |
237 | JMenuItem item = (JMenuItem) pair.getKey(); |
238 | ActionListener listener = (ActionListener) pair.getValue(); |
239 | |
240 | item.removeActionListener(listener); |
241 | } |
242 | actionListenersToRemoveList.clear(); |
243 | |
244 | ifNotNullRemove(helpMenu); |
245 | ifNotNullRemove(goMenu); |
246 | ifNotNullRemove(viewMenu); |
247 | //TODO: ifNotNullRemove(editMenu); |
248 | ifNotNullRemove(fileMenu); |
249 | } |
250 | |
251 | void clearFileOpenRecent() { |
252 | settings.clearRecentFiles(); |
253 | updateFileOpenRecent(); |
254 | } |
255 | |
256 | private void addGoToURIItem(JMenu menu, JMenuItem item, String uri) { |
257 | assert menu != null; |
258 | assert item != null; |
259 | assert uri != null; |
260 | |
261 | GoToURIActionListener listener = new GoToURIActionListener(uri); |
262 | |
263 | item.addActionListener(listener); |
264 | actionListenersToRemoveList.add(new KeyValuePair(item, listener)); |
265 | item.setActionCommand(Commands.DUMMY_GO_TO_URI); |
266 | menu.add(item); |
267 | } |
268 | |
269 | private void addItem(JMenuItem item, String command, int key, boolean useShift) { |
270 | assert item != null; |
271 | assert command != null; |
272 | |
273 | int additionalMask; |
274 | |
275 | if (useShift) { |
276 | additionalMask = Event.SHIFT_MASK; |
277 | } else { |
278 | additionalMask = 0; |
279 | } |
280 | assert item != null; |
281 | assert command != null; |
282 | |
283 | item.setActionCommand(command); |
284 | item.addActionListener(this); |
285 | actionListenersToRemoveList.add(new KeyValuePair(item, this)); |
286 | setKeyAndMask(item, key, additionalMask); |
287 | } |
288 | |
289 | private void addItem(JMenu menu, JMenuItem item, String command, int key) { |
290 | assert menu != null; |
291 | assert item != null; |
292 | assert command != null; |
293 | |
294 | addItem(item, command, key, false); |
295 | menu.add(item); |
296 | } |
297 | |
298 | private void addItem(JMenu menu, JMenuItem item, String command, int key, int additionalMask) { |
299 | assert menu != null; |
300 | assert item != null; |
301 | assert command != null; |
302 | |
303 | item.setActionCommand(command); |
304 | item.addActionListener(this); |
305 | actionListenersToRemoveList.add(new KeyValuePair(item, this)); |
306 | setKeyAndMask(item, key, additionalMask); |
307 | menu.add(item); |
308 | } |
309 | |
310 | private void addPropertyItem(JMenu menu, JMenuItem item) { |
311 | addPropertyItem(menu, item, 0); |
312 | } |
313 | |
314 | private void addPropertyItem(JMenu menu, JMenuItem item, int key) { |
315 | addPropertyItem(menu, item, key, 0); |
316 | } |
317 | |
318 | private void addPropertyItem(JMenu menu, JMenuItem item, int key, int additonalMask) { |
319 | assert menu != null; |
320 | assert item != null; |
321 | menu.add(item); |
322 | setKeyAndMask(item, key, additonalMask); |
323 | } |
324 | |
325 | private JMenu createEditMenu() { |
326 | JMenu result = localeTools.createMenu(LocaleTools.MENU_EDIT); |
327 | |
328 | cutItem = new JMenuItem(new DefaultEditorKit.CutAction()); |
329 | cutItem.setText(localeTools.getMenuItemLabel(LocaleTools.MENU_EDIT, "cut")); |
330 | cutItem.setMnemonic(KeyEvent.VK_T); |
331 | result.add(cutItem); |
332 | copyItem = new JMenuItem(new DefaultEditorKit.CopyAction()); |
333 | copyItem.setText(localeTools.getMenuItemLabel(LocaleTools.MENU_EDIT, "copy")); |
334 | copyItem.setMnemonic(KeyEvent.VK_C); |
335 | result.add(copyItem); |
336 | pasteItem = new JMenuItem(new DefaultEditorKit.PasteAction()); |
337 | pasteItem.setText(localeTools.getMenuItemLabel(LocaleTools.MENU_EDIT, "paste")); |
338 | pasteItem.setMnemonic(KeyEvent.VK_P); |
339 | result.add(pasteItem); |
340 | return result; |
341 | } |
342 | |
343 | private JMenu createFileMenu() { |
344 | JMenu result = localeTools.createMenu(LocaleTools.MENU_FILE); |
345 | Application application = Application.getInstance(); |
346 | |
347 | newItem = localeTools.createMenuItem(LocaleTools.MENU_FILE, "newComic"); |
348 | openItem = localeTools.createMenuItem(LocaleTools.MENU_FILE, "open"); |
349 | openRecentMenu = new OpenRecentMenu(delegate); |
350 | openRecentMenu.setText(localeTools.getMenuItemLabel(LocaleTools.MENU_FILE, "openRecent")); |
351 | openPreviousItem = localeTools.createMenuItem(LocaleTools.MENU_FILE, "openPrevious"); |
352 | openNextItem = localeTools.createMenuItem(LocaleTools.MENU_FILE, "openNext"); |
353 | closeItem = localeTools.createMenuItem(LocaleTools.MENU_FILE, "close"); |
354 | convertItem = localeTools.createMenuItem(LocaleTools.MENU_FILE, "convert"); |
355 | revealItem = localeTools.createMenuItem(LocaleTools.MENU_FILE, "reveal"); |
356 | exportItem = localeTools.createMenuItem(LocaleTools.MENU_FILE, "exportImage"); |
357 | exportAllItem = localeTools.createMenuItem(LocaleTools.MENU_FILE, "exportAllImages"); |
358 | |
359 | addItem(result, newItem, Commands.NEW_COMIC, KeyEvent.VK_N); |
360 | addItem(result, openItem, Commands.OPEN, KeyEvent.VK_O); |
361 | result.add(openRecentMenu); |
362 | addItem(result, openPreviousItem, Commands.OPEN_PREVIOUS, KeyEvent.VK_O, Event.ALT_MASK); |
363 | addItem(result, openNextItem, Commands.OPEN_NEXT, KeyEvent.VK_O, Event.SHIFT_MASK); |
364 | result.addSeparator(); |
365 | if (systemTools.isMacOSX()) { |
366 | addItem(result, closeItem, Commands.CLOSE, KeyEvent.VK_W); |
367 | } |
368 | addItem(result, convertItem, Commands.CONVERT, KeyEvent.VK_C, Event.SHIFT_MASK); |
369 | addItem(result, revealItem, Commands.REVEAL, KeyEvent.VK_R, Event.SHIFT_MASK); |
370 | addItem(result, exportItem, Commands.EXPORT, KeyEvent.VK_E, Event.SHIFT_MASK); |
371 | addItem(result, exportAllItem, Commands.EXPORT_ALL, KeyEvent.VK_E, Event.SHIFT_MASK | Event.ALT_MASK); |
372 | quitItem = application.getQuitJMenuItem(); |
373 | if (QuitJMenuItem.isAutomaticallyPresent()) { |
374 | addItem(quitItem, Commands.QUIT, KeyEvent.VK_Q, false); |
375 | } else { |
376 | result.addSeparator(); |
377 | quitItem.setText(localeTools.getMenuItemLabel(LocaleTools.MENU_FILE, "quit")); |
378 | addItem(result, quitItem, Commands.QUIT, KeyEvent.VK_Q); |
379 | } |
380 | return result; |
381 | } |
382 | |
383 | private JMenu createGoMenu() { |
384 | JMenu result = localeTools.createMenu(LocaleTools.MENU_GO); |
385 | |
386 | goFirstItem = localeTools.createMenuItem(LocaleTools.MENU_GO, "first"); |
387 | goLastItem = localeTools.createMenuItem(LocaleTools.MENU_GO, "last"); |
388 | goNextItem = localeTools.createMenuItem(LocaleTools.MENU_GO, "next"); |
389 | goPageItem = localeTools.createMenuItem(LocaleTools.MENU_GO, "toPage"); |
390 | goPreviousItem = localeTools.createMenuItem(LocaleTools.MENU_GO, "previous"); |
391 | |
392 | addItem(result, goFirstItem, Commands.FIRST_PAGE, 0); |
393 | addItem(result, goPreviousItem, Commands.GO_PREVIOUS, KeyEvent.VK_LEFT); |
394 | addItem(result, goNextItem, Commands.GO_NEXT, KeyEvent.VK_RIGHT); |
395 | addItem(result, goLastItem, Commands.LAST_PAGE, 0); |
396 | result.addSeparator(); |
397 | addItem(result, goPageItem, Commands.GO_PAGE, KeyEvent.VK_L); |
398 | return result; |
399 | } |
400 | |
401 | private JMenu createHelpMenu() { |
402 | Application application = Application.getInstance(); |
403 | |
404 | JMenu result = localeTools.createMenu(LocaleTools.MENU_HELP); |
405 | |
406 | // HACK: Prevent help menu from being converted to a standard Mac help |
407 | // menu with a with a search bar that will not find anything and a |
408 | // bunch of disabled menu items the user cannot select. |
409 | result.setText(result.getText() + " "); |
410 | helpItem = localeTools.createMenuItem(LocaleTools.MENU_HELP, "help"); |
411 | systemInfoItem = localeTools.createMenuItem(LocaleTools.MENU_HELP, "systemInformation"); |
412 | homePageItem = localeTools.createMenuItem(LocaleTools.MENU_HELP, "homepage"); |
413 | reportBugItem = localeTools.createMenuItem(LocaleTools.MENU_HELP, "reportBug"); |
414 | requestFeatureItem = localeTools.createMenuItem(LocaleTools.MENU_HELP, "requestFeature"); |
415 | contactAuthorItem = localeTools.createMenuItem(LocaleTools.MENU_HELP, "contactAuthor"); |
416 | |
417 | aboutItem = application.getAboutJMenuItem(); |
418 | if (AboutJMenuItem.isAutomaticallyPresent()) { |
419 | addItem(aboutItem, Commands.ABOUT, 0, false); |
420 | } else { |
421 | aboutItem.setText(localeTools.getMenuItemLabel(LocaleTools.MENU_HELP, "about")); |
422 | addItem(result, aboutItem, Commands.ABOUT, 0); |
423 | } |
424 | addItem(result, helpItem, Commands.HELP, 0); |
425 | systemTools.setHelpAccelerato(helpItem); |
426 | addItem(result, systemInfoItem, Commands.SYSTEM_INFO, 0); |
427 | result.addSeparator(); |
428 | addGoToURIItem(result, homePageItem, "http://jomic.sourceforge.net/"); |
429 | addGoToURIItem(result, reportBugItem, "http://sourceforge.net/tracker/?group_id=103788&atid=635943"); |
430 | addGoToURIItem( |
431 | result, |
432 | requestFeatureItem, |
433 | "http://sourceforge.net/tracker/?group_id=103788&atid=635946"); |
434 | addGoToURIItem(result, contactAuthorItem, "mailto:roskakori@users.sourceforge.net?subject=Jomic"); |
435 | return result; |
436 | } |
437 | |
438 | private JMenu createViewMenu() { |
439 | JMenu result = localeTools.createMenu(LocaleTools.MENU_VIEW); |
440 | ButtonGroup zoomGroup = new ButtonGroup(); |
441 | |
442 | fitActualSizeItem = localeTools.createRadioButtonMenuItem(LocaleTools.MENU_VIEW, zoomGroup, "actualSize"); |
443 | fitAllItem = localeTools.createRadioButtonMenuItem(LocaleTools.MENU_VIEW, zoomGroup, "zoomToFit"); |
444 | fitHeightItem = localeTools.createRadioButtonMenuItem(LocaleTools.MENU_VIEW, zoomGroup, "zoomToFitHeight"); |
445 | fitWidthItem = localeTools.createRadioButtonMenuItem(LocaleTools.MENU_VIEW, zoomGroup, "zoomToFitWidth"); |
446 | |
447 | // Select zoom mode radio button according to settings |
448 | String currentZoomState = settings.getScaleMode(); |
449 | JRadioButtonMenuItem selectedFitItem = null; |
450 | |
451 | if (currentZoomState.equals(ImageTools.SCALE_ACTUAL)) { |
452 | selectedFitItem = fitActualSizeItem; |
453 | } else if (currentZoomState.equals(ImageTools.SCALE_FIT)) { |
454 | selectedFitItem = fitAllItem; |
455 | } else if (currentZoomState.equals(ImageTools.SCALE_HEIGHT)) { |
456 | selectedFitItem = fitHeightItem; |
457 | } else if (currentZoomState.equals(ImageTools.SCALE_WIDTH)) { |
458 | selectedFitItem = fitWidthItem; |
459 | } else { |
460 | assert false : "scaleMode=" + currentZoomState; |
461 | } |
462 | selectedFitItem.setSelected(true); |
463 | |
464 | fullScreenItem = localeTools.createMenuItem(LocaleTools.MENU_VIEW, "fullScreen"); |
465 | rotateLeftItem = localeTools.createMenuItem(LocaleTools.MENU_VIEW, "rotateLeft"); |
466 | rotateRightItem = localeTools.createMenuItem(LocaleTools.MENU_VIEW, "rotateRight"); |
467 | |
468 | String rotateOnlySinglePortraitImagesLable = localeTools.getMenuItemLabel( |
469 | LocaleTools.MENU_VIEW, "rotateOnlySinglePortraitImages"); |
470 | |
471 | toggleRotateOnlySinglePortraitImages = new BooleanSettingMenuItem( |
472 | rotateOnlySinglePortraitImagesLable, ComicSheetRenderSettings.ROTATE_ONLY_SINGLE_PORTRAIT_IMAGES, |
473 | Commands.TOGGLE_ROTATE_ONLY_SINGLE_PORTRAIT_IMAGES, delegate); |
474 | |
475 | String useBlurLabel = localeTools.getMenuItemLabel(LocaleTools.MENU_VIEW, "useBlur"); |
476 | JMenuItem useBlurItem = new BooleanSettingMenuItem(useBlurLabel, PropertyConstants.USE_BLUR); |
477 | |
478 | String showThumbsLabel = localeTools.getMenuItemLabel(LocaleTools.MENU_VIEW, "showThumbs"); |
479 | |
480 | toggleShowThumbsItem = new BooleanSettingMenuItem( |
481 | showThumbsLabel, PropertyConstants.SHOW_THUMBS, Commands.TOGGLE_SHOW_THUMBS, delegate); |
482 | |
483 | String showToolbarLabel = localeTools.getMenuItemLabel(LocaleTools.MENU_VIEW, "showToolbar"); |
484 | |
485 | toggleShowToolbarItem = new BooleanSettingMenuItem( |
486 | showToolbarLabel, PropertyConstants.SHOW_TOOLBAR, Commands.TOGGLE_SHOW_TOOLBAR, delegate); |
487 | |
488 | String readFromRightToLeftLabel = localeTools.getMenuItemLabel(LocaleTools.MENU_VIEW, "readFromRightToLeft"); |
489 | |
490 | toggleSwapLeftAndRightImageItem = new BooleanSettingMenuItem( |
491 | readFromRightToLeftLabel, ComicSheetRenderSettings.SWAP_LEFT_AND_RIGHT_IMAGE, |
492 | Commands.TOGGLE_SWAP_LEFT_AND_RIGHT_IMAGE, delegate); |
493 | |
494 | String showTwoPagesLabel = localeTools.getMenuItemLabel(LocaleTools.MENU_VIEW, "showTwoPages"); |
495 | |
496 | toggleTwoPagesItem = new BooleanSettingMenuItem( |
497 | showTwoPagesLabel, ComicSheetRenderSettings.SHOW_TWO_PAGES, Commands.TOGGLE_SHOW_TWO_PAGES, delegate); |
498 | |
499 | String showInformationLabel = localeTools.getMenuItemLabel(LocaleTools.MENU_VIEW, "showInformation"); |
500 | |
501 | toggleShowInfoItem = new BooleanSettingMenuItem( |
502 | showInformationLabel, PropertyConstants.SHOW_INFO, Commands.TOGGLE_SHOW_INFO, delegate); |
503 | |
504 | JMenuItem changeBlurSettingsItem = new JMenuItem(jomicApplication.getChangeBlurSettingsAction()); |
505 | String setBackgroundColorLabel = localeTools.getMenuItemLabel(LocaleTools.MENU_VIEW, "setBackgroundColor"); |
506 | |
507 | setBackgoundColorItem = new ColorSettingMenuItem( |
508 | setBackgroundColorLabel, ImageRenderSettings.FILL_COLOR); |
509 | |
510 | addItem(result, fitActualSizeItem, Commands.FIT_ACTUAL_SIZE, KeyEvent.VK_0); |
511 | addItem(result, fitAllItem, Commands.FIT_WIDTH_AND_HEIGHT, KeyEvent.VK_1); |
512 | addItem(result, fitHeightItem, Commands.FIT_HEIGHT, KeyEvent.VK_2); |
513 | addItem(result, fitWidthItem, Commands.FIT_WIDTH, KeyEvent.VK_3); |
514 | // TODO: Use sensible shortcut key for full screen. |
515 | addItem(result, fullScreenItem, Commands.FULL_SCREEN, KeyEvent.VK_4); |
516 | result.addSeparator(); |
517 | addItem(result, rotateLeftItem, Commands.ROTATE_LEFT, KeyEvent.VK_L, Event.ALT_MASK); |
518 | addItem(result, rotateRightItem, Commands.ROTATE_RIGHT, KeyEvent.VK_R, Event.ALT_MASK); |
519 | // TODO: addPropertyItem(result, toggleRotateOnlySinglePortraitImages); |
520 | result.add(useBlurItem); |
521 | result.addSeparator(); |
522 | // TODO: Use KeyEvent.VK_T and Event.ALT_MASK |
523 | // Note: I already tried that, but the shortcuts did not show up properly in the menu |
524 | // if Jomic was launched from finder. Launched from eclipse, it worked. However, |
525 | // in both cases, the keyboard input was processed properly - even with wrong visual |
526 | // shortcuts in the menu. Maybe this is a bug in apple's swing implementation. |
527 | addPropertyItem(result, toggleTwoPagesItem, KeyEvent.VK_T); |
528 | addPropertyItem(result, toggleSwapLeftAndRightImageItem, KeyEvent.VK_J); |
529 | addPropertyItem(result, toggleShowToolbarItem, KeyEvent.VK_B); |
530 | addPropertyItem(result, toggleShowThumbsItem, KeyEvent.VK_U); |
531 | addPropertyItem(result, toggleShowInfoItem, KeyEvent.VK_I); |
532 | result.addSeparator(); |
533 | result.add(changeBlurSettingsItem); |
534 | addPropertyItem(result, setBackgoundColorItem); |
535 | return result; |
536 | } |
537 | |
538 | private void ifNotNullRemove(JMenu menu) { |
539 | if (menu != null) { |
540 | remove(menu); |
541 | } |
542 | } |
543 | } |