| 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 | import javax.swing.JViewport; | 
| 22 |   | 
| 23 | public class DrawingAreaPanel extends JPanel implements DrawingAreaHolder | 
| 24 | { | 
| 25 |         // This constructor is used only for the fake empty area view | 
| 26 |         public DrawingAreaPanel() | 
| 27 |         { | 
| 28 |                 _area = null; | 
| 29 |                 _scroller = null; | 
| 30 |         } | 
| 31 |          | 
| 32 |         public DrawingAreaPanel(DrawingArea area) | 
| 33 |         { | 
| 34 |                 super(new BorderLayout()); | 
| 35 |                 _area = area; | 
| 36 |                 _scroller = new JScrollPane(_area); | 
| 37 |                 // Improve scrolling performance | 
| 38 |                 _scroller.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); | 
| 39 |                 _scroller.getViewport().setName("drawing-area-viewport"); | 
| 40 |             add(_scroller, BorderLayout.CENTER); | 
| 41 |         } | 
| 42 |          | 
| 43 |         public DrawingArea getDrawingArea() | 
| 44 |         { | 
| 45 |                 return _area; | 
| 46 |         } | 
| 47 |          | 
| 48 |         public void        attachArea() | 
| 49 |         { | 
| 50 |                 _scroller.setViewportView(_area); | 
| 51 |         } | 
| 52 |          | 
| 53 |         public void        detachArea() | 
| 54 |         { | 
| 55 |                 _scroller.setViewportView(null); | 
| 56 |         } | 
| 57 |          | 
| 58 |         private final DrawingArea        _area; | 
| 59 |         private final JScrollPane        _scroller; | 
| 60 |   | 
| 61 | } |