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.Color; |
18 | import java.awt.Graphics; |
19 | import java.awt.Graphics2D; |
20 | import java.awt.event.ContainerEvent; |
21 | import java.awt.event.ContainerListener; |
22 | import java.awt.event.MouseAdapter; |
23 | import java.awt.event.MouseEvent; |
24 | import java.awt.event.MouseListener; |
25 | |
26 | import javax.swing.JPanel; |
27 | import javax.swing.JPopupMenu; |
28 | import javax.swing.JScrollPane; |
29 | import javax.swing.JViewport; |
30 | |
31 | import org.jdesktop.animation.timing.Animator; |
32 | |
33 | import net.sourceforge.hiveboard.Board; |
34 | import net.sourceforge.hivegui.component.CenterLayout; |
35 | |
36 | public class FullScreenPanel extends JPanel implements MatteCommentAcceptor |
37 | { |
38 | public FullScreenPanel( FullScreenPrefs prefs, |
39 | FullScreenPopupHandler popupHandler, |
40 | FullScreenMatteHandler matteHandler) |
41 | { |
42 | super(new CenterLayout()); |
43 | setName("fullscreen-pane"); |
44 | setOpaque(true); |
45 | setBackground(Color.WHITE); |
46 | |
47 | // Initialize fields |
48 | _painter = new MattePainterManager(this); |
49 | _prefs = prefs; |
50 | _popup = popupHandler.getPopup(); |
51 | _matteHandler = matteHandler; |
52 | |
53 | // Setup listeners |
54 | addMouseListener(_listener); |
55 | _matteHandler.setCommentAcceptor(this); |
56 | } |
57 | |
58 | public void setAreaScroller(JScrollPane scroller) |
59 | { |
60 | // The only component that can be put in this pane is a scrollpane |
61 | JViewport view = scroller.getViewport(); |
62 | view.addContainerListener(new ContainerListener() |
63 | { |
64 | public void componentAdded(ContainerEvent e) |
65 | { |
66 | e.getChild().addMouseListener(_listener); |
67 | } |
68 | public void componentRemoved(ContainerEvent e) |
69 | { |
70 | e.getChild().removeMouseListener(_listener); |
71 | } |
72 | }); |
73 | add(scroller); |
74 | } |
75 | |
76 | public void setBoard(Board board) |
77 | { |
78 | _matteHandler.setBoard(board); |
79 | } |
80 | |
81 | public void setMatteComment(String comment) |
82 | { |
83 | if (_animator != null && _animator.isRunning()) |
84 | { |
85 | _animator.stop(); |
86 | } |
87 | _animator = _painter.createAnimator(_prefs, comment); |
88 | _animator.start(); |
89 | } |
90 | |
91 | @Override protected void paintChildren(Graphics g) |
92 | { |
93 | super.paintChildren(g); |
94 | if (_animator != null && _animator.isRunning()) |
95 | { |
96 | _painter.paint((Graphics2D) g); |
97 | } |
98 | } |
99 | |
100 | private void managePopupTrigger(MouseEvent e) |
101 | { |
102 | if (e.isPopupTrigger()) |
103 | { |
104 | // Popup is directly managed, never passed further |
105 | _popup.show(e.getComponent(), e.getX(), e.getY()); |
106 | } |
107 | } |
108 | |
109 | private class PopupMouseListener extends MouseAdapter |
110 | { |
111 | @Override public void mousePressed(MouseEvent e) |
112 | { |
113 | managePopupTrigger(e); |
114 | } |
115 | |
116 | @Override public void mouseReleased(MouseEvent e) |
117 | { |
118 | managePopupTrigger(e); |
119 | } |
120 | } |
121 | |
122 | private final MattePainterManager _painter; |
123 | private Animator _animator; |
124 | private final FullScreenPrefs _prefs; |
125 | |
126 | private final FullScreenMatteHandler _matteHandler; |
127 | private final JPopupMenu _popup; |
128 | private final MouseListener _listener = new PopupMouseListener(); |
129 | } |