| 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.drawing; |
| 16 | |
| 17 | import javax.swing.Action; |
| 18 | import javax.swing.ActionMap; |
| 19 | |
| 20 | import net.sourceforge.hiveboard.event.EventsPriorities; |
| 21 | import net.sourceforge.hiveboard.view.DrawingAreaHolder; |
| 22 | import net.sourceforge.hiveevents.Channel; |
| 23 | import net.sourceforge.hiveevents.PersistentConsumer; |
| 24 | |
| 25 | public class ScreenModeTool extends AbstractPushButtonTool |
| 26 | { |
| 27 | public ScreenModeTool( Action switchModeCommand, |
| 28 | Channel<DrawingAreaHolder> boardImageChannel) |
| 29 | { |
| 30 | _switchModeCommand = switchModeCommand; |
| 31 | // Automatic enabling depending on existence of an open board |
| 32 | _switchModeCommand.setEnabled(false); |
| 33 | int priority = EventsPriorities.SELECTED_IMAGE_GUI_REFRESH; |
| 34 | boardImageChannel.registerPushConsumer( |
| 35 | priority, new PersistentConsumer<DrawingAreaHolder>() |
| 36 | { |
| 37 | public void push(DrawingAreaHolder holder) |
| 38 | { |
| 39 | _switchModeCommand.setEnabled(holder != null); |
| 40 | } |
| 41 | }); |
| 42 | } |
| 43 | |
| 44 | @Override protected void initActions(ActionMap map) |
| 45 | { |
| 46 | _button.putClientProperty(ToolHandler.NOT_TOOL_CLIENT_PROPERTY, ""); |
| 47 | _button.setAction(_switchModeCommand); |
| 48 | } |
| 49 | |
| 50 | private final Action _switchModeCommand; |
| 51 | } |