| 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.JComponent; |
| 18 | |
| 19 | import org.jdesktop.application.Action; |
| 20 | import org.jdesktop.application.Task; |
| 21 | |
| 22 | import net.sourceforge.hiveboard.WhiteBoardUserService; |
| 23 | import net.sourceforge.hiveboard.command.AbstractTask; |
| 24 | import net.sourceforge.hiveboard.command.ActionHelper; |
| 25 | import net.sourceforge.hivegui.application.ApplicationContextHolder; |
| 26 | import net.sourceforge.hivegui.application.HiveGuiApplicationMain; |
| 27 | import net.sourceforge.hiveutils.service.ObjectTools; |
| 28 | |
| 29 | /** |
| 30 | * This command is used from full screen mode by the popup menu item to set the |
| 31 | * writer of the current board. It is instantiated once for each participant of |
| 32 | * the board. |
| 33 | * |
| 34 | * @author Jean-Francois Poilpret |
| 35 | */ |
| 36 | public class DrawingActionSender |
| 37 | { |
| 38 | public DrawingActionSender(WhiteBoardUserService service, ObjectTools objectTools) |
| 39 | { |
| 40 | _service = service; |
| 41 | _objectTools = objectTools; |
| 42 | } |
| 43 | |
| 44 | public void setContextHolder(ApplicationContextHolder holder) |
| 45 | { |
| 46 | _application = holder.getApplication(); |
| 47 | _action = _application.getContext().getActionMap(this).get("sendDrawingAction"); |
| 48 | } |
| 49 | |
| 50 | public void send(DrawingAction drawAction, int where, JComponent area) |
| 51 | { |
| 52 | if (drawAction != null) |
| 53 | { |
| 54 | _drawAction = drawAction; |
| 55 | _where = where; |
| 56 | ActionHelper.execute(_action, area); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | @Action(block = Task.BlockingScope.ACTION) |
| 61 | public Task sendDrawingAction() |
| 62 | { |
| 63 | return new AbstractTask(_application) |
| 64 | { |
| 65 | @Override protected Void doInBackground() throws Exception |
| 66 | { |
| 67 | // Send the action to the server |
| 68 | _service.draw(_where, _objectTools.serialize(_drawAction)); |
| 69 | return null; |
| 70 | } |
| 71 | }; |
| 72 | } |
| 73 | |
| 74 | private final WhiteBoardUserService _service; |
| 75 | private final ObjectTools _objectTools; |
| 76 | private HiveGuiApplicationMain _application; |
| 77 | private javax.swing.Action _action; |
| 78 | private DrawingAction _drawAction; |
| 79 | private int _where; |
| 80 | } |