| 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.view; | 
| 16 |   | 
| 17 | import java.awt.BorderLayout; | 
| 18 |   | 
| 19 | import javax.swing.JPanel; | 
| 20 | import javax.swing.JScrollPane; | 
| 21 |   | 
| 22 | import net.sourceforge.hiveboard.Board; | 
| 23 | import net.sourceforge.hiveboard.docking.Views; | 
| 24 | import net.sourceforge.hiveboard.event.EventsPriorities; | 
| 25 | import net.sourceforge.hiveevents.Channel; | 
| 26 | import net.sourceforge.hiveevents.PersistentConsumer; | 
| 27 | import net.sourceforge.hivegui.table.BeanTable; | 
| 28 |   | 
| 29 | public class BoardListPanel extends JPanel | 
| 30 | { | 
| 31 |         public BoardListPanel(        BeanTable<Board>                                        tblBoards, | 
| 32 |                                                         final Channel<DrawingAreaHolder>        selectedBoardImageChannel) | 
| 33 |         { | 
| 34 |                 setLayout(new BorderLayout()); | 
| 35 |                 _tblBoards = tblBoards; | 
| 36 |                 _tblBoards.setName(Views.BOARDS_LIST.id() + "-table"); | 
| 37 |                 _boardsModel = (BoardListModel) _tblBoards.getDataListModel(); | 
| 38 |   | 
| 39 |                 // Listen to changes in list of board image areas | 
| 40 |                 int priority = EventsPriorities.SELECTED_IMAGE_GUI_REFRESH; | 
| 41 |                 selectedBoardImageChannel.registerPushConsumer( | 
| 42 |                                                                 priority, new PersistentConsumer<DrawingAreaHolder>() | 
| 43 |                 { | 
| 44 |                         public void        push(DrawingAreaHolder holder) | 
| 45 |                         { | 
| 46 |                                 if (holder != null) | 
| 47 |                                 { | 
| 48 |                                         int id = holder.getDrawingArea().getBoardImageModel().getBoard().getId(); | 
| 49 |                                         // Find board with this id | 
| 50 |                                         int index = _boardsModel.findBoard(id); | 
| 51 |                                         if (index >= 0) | 
| 52 |                                         { | 
| 53 |                                                 _tblBoards.setRowSelectionInterval(index, index); | 
| 54 |                                         } | 
| 55 |                                 } | 
| 56 |                         } | 
| 57 |                 }); | 
| 58 |   | 
| 59 |             add(new JScrollPane(_tblBoards), BorderLayout.CENTER); | 
| 60 |         } | 
| 61 |   | 
| 62 |         final private BeanTable<Board>        _tblBoards; | 
| 63 |         final private BoardListModel        _boardsModel; | 
| 64 | } |