| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.main; |
| 16 | |
| 17 | import java.awt.BorderLayout; |
| 18 | |
| 19 | import javax.swing.Action; |
| 20 | import javax.swing.JComponent; |
| 21 | import javax.swing.JFrame; |
| 22 | import javax.swing.JScrollPane; |
| 23 | import javax.swing.JToolBar; |
| 24 | import javax.swing.JViewport; |
| 25 | import javax.swing.KeyStroke; |
| 26 | |
| 27 | import org.apache.commons.logging.Log; |
| 28 | |
| 29 | import net.sourceforge.hiveboard.Board; |
| 30 | import net.sourceforge.hiveboard.drawing.ToolHandler; |
| 31 | import net.sourceforge.hiveboard.event.EventsPriorities; |
| 32 | import net.sourceforge.hiveboard.view.DrawingArea; |
| 33 | import net.sourceforge.hiveboard.view.DrawingAreaHolder; |
| 34 | import net.sourceforge.hiveboard.view.FullScreenPanel; |
| 35 | import net.sourceforge.hiveevents.Channel; |
| 36 | import net.sourceforge.hiveevents.PersistentConsumer; |
| 37 | import net.sourceforge.hivegui.component.IconTools; |
| 38 | import net.sourceforge.hivegui.menu.MenuFactory; |
| 39 | import net.sourceforge.hivegui.util.ScreenTools; |
| 40 | |
| 41 | /** |
| 42 | * Special Frame used to cover the full screen. It always exists but is visible |
| 43 | * only in full-screen mode. |
| 44 | * <p> |
| 45 | * It can also display comments/notifications. |
| 46 | * |
| 47 | * @author jean-Francois Poilpret |
| 48 | */ |
| 49 | public class FullScreenShell extends JFrame implements PersistentConsumer<DrawingAreaHolder> |
| 50 | { |
| 51 | public FullScreenShell( Log logger, |
| 52 | Channel<DrawingAreaHolder> boardChannel, |
| 53 | ToolHandler toolHandler, |
| 54 | MenuFactory menuFactory, |
| 55 | Action switchMode, |
| 56 | Channel<Object> fullScreenMode, |
| 57 | Channel<Object> windowMode, |
| 58 | FullScreenPanel screenPane) |
| 59 | { |
| 60 | super(); |
| 61 | setName("fullscreen-shell"); |
| 62 | |
| 63 | _logger = logger; |
| 64 | _area = null; |
| 65 | _toolbar = toolHandler.getToolBar(); |
| 66 | int priority = EventsPriorities.SELECTED_IMAGE_FULLSCREEN_UPDATE; |
| 67 | boardChannel.registerPushConsumer(priority, this); |
| 68 | |
| 69 | final JComponent content = (JComponent) getContentPane(); |
| 70 | |
| 71 | // Set command for switching screen mode |
| 72 | KeyStroke shortcut = findShortcut(switchMode); |
| 73 | if (shortcut != null) |
| 74 | { |
| 75 | content.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(shortcut, "switch-mode"); |
| 76 | content.getActionMap().put("switch-mode", switchMode); |
| 77 | } |
| 78 | |
| 79 | content.setLayout(new BorderLayout()); |
| 80 | setIconImage(IconTools.loadIcon("image/hiveboard.gif").getImage()); |
| 81 | setUndecorated(true); |
| 82 | |
| 83 | // Improve scrolling performance |
| 84 | _scroller.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); |
| 85 | |
| 86 | _content = screenPane; |
| 87 | _content.setAreaScroller(_scroller); |
| 88 | |
| 89 | content.add(_content, BorderLayout.CENTER); |
| 90 | |
| 91 | setBounds(ScreenTools.getMainScreenBounds()); |
| 92 | |
| 93 | // Register consumer for screen mode switching channels |
| 94 | priority = EventsPriorities.FULLSCREENSHELL_FULL_SWITCH; |
| 95 | fullScreenMode.registerPushConsumer(priority, new PersistentConsumer<Object>() |
| 96 | { |
| 97 | public void push(Object event) |
| 98 | { |
| 99 | _scroller.setViewportView(_area); |
| 100 | Board board = _area.getBoardImageModel().getBoard(); |
| 101 | _content.setBoard(board); |
| 102 | setTitle("HiveBoard - " + board.getName()); |
| 103 | content.add(_toolbar, BorderLayout.NORTH); |
| 104 | setVisible(true); |
| 105 | } |
| 106 | }); |
| 107 | priority = EventsPriorities.FULLSCREENSHELL_WINDOW_SWITCH; |
| 108 | windowMode.registerPushConsumer(priority, new PersistentConsumer<Object>() |
| 109 | { |
| 110 | public void push(Object event) |
| 111 | { |
| 112 | setVisible(false); |
| 113 | _scroller.setViewportView(null); |
| 114 | _content.setBoard(null); |
| 115 | content.remove(_toolbar); |
| 116 | } |
| 117 | }); |
| 118 | } |
| 119 | |
| 120 | private KeyStroke findShortcut(Action command) |
| 121 | { |
| 122 | return (KeyStroke) command.getValue(Action.ACCELERATOR_KEY); |
| 123 | } |
| 124 | |
| 125 | public void push(DrawingAreaHolder holder) |
| 126 | { |
| 127 | // Update current area |
| 128 | if (holder == null) |
| 129 | { |
| 130 | _area = null; |
| 131 | } |
| 132 | else |
| 133 | { |
| 134 | _area = holder.getDrawingArea(); |
| 135 | } |
| 136 | _logger.debug("push() _area=" + _area); |
| 137 | } |
| 138 | |
| 139 | private DrawingArea _area; |
| 140 | final private Log _logger; |
| 141 | final private FullScreenPanel _content; |
| 142 | final private JScrollPane _scroller = new JScrollPane(); |
| 143 | final private JToolBar _toolbar; |
| 144 | } |