716f49b54b2015dc87e1d82cf63bc8a895b9e6d4
[debian/jabref.git] / src / main / java / net / sf / jabref / SidePaneComponent.java
1 /*  Copyright (C) 2003-2011 JabRef contributors.
2     This program is free software; you can redistribute it and/or modify
3     it under the terms of the GNU General Public License as published by
4     the Free Software Foundation; either version 2 of the License, or
5     (at your option) any later version.
6
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10     GNU General Public License for more details.
11
12     You should have received a copy of the GNU General Public License along
13     with this program; if not, write to the Free Software Foundation, Inc.,
14     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 */
16 package net.sf.jabref;
17
18 import java.awt.Dimension;
19 import java.awt.Insets;
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
22 import java.net.URL;
23
24 import javax.swing.BorderFactory;
25 import javax.swing.ImageIcon;
26 import javax.swing.JButton;
27 import javax.swing.JToolBar;
28
29 import com.jgoodies.uif_lite.panel.SimpleInternalFrame;
30
31 public abstract class SidePaneComponent extends SimpleInternalFrame {
32
33         protected JButton close = new JButton(GUIGlobals.getImage("close"));
34
35         protected boolean visible = false;
36
37         protected SidePaneManager manager;
38
39         protected BasePanel panel = null;
40
41         public SidePaneComponent(SidePaneManager manager, URL icon, String title) {
42                 super(new ImageIcon(icon), title);
43                 this.manager = manager;
44                 setSelected(true);
45                 JToolBar tlb = new JToolBar();
46                 close.setMargin(new Insets(0, 0, 0, 0));
47                 // tlb.setOpaque(false);
48                 close.setBorder(null);
49         tlb.setFloatable(false);
50                 tlb.add(close);
51                 close.addActionListener(new CloseButtonListener());
52                 setToolBar(tlb);
53                 // setBorder(BorderFactory.createEtchedBorder());
54                 setBorder(BorderFactory.createEmptyBorder());
55                 // setBorder(BorderFactory.createMatteBorder(1,1,1,1,java.awt.Color.green));
56                 // setPreferredSize(new java.awt.Dimension
57                 // (GUIGlobals.SPLIT_PANE_DIVIDER_LOCATION, 200));
58                 // Util.pr(""+GUIGlobals.SPLIT_PANE_DIVIDER_LOCATION);
59         }
60
61         public void hideAway() {
62                 manager.hideComponent(this);
63         }
64
65         /**
66          * Used by SidePaneManager only, to keep track of visibility.
67          * 
68          */
69         void setVisibility(boolean vis) {
70                 visible = vis;
71         }
72
73         /**
74          * Used by SidePaneManager only, to keep track of visibility.
75          * 
76          */
77         boolean hasVisibility() {
78                 return visible;
79         }
80
81         public void setActiveBasePanel(BasePanel panel) {
82                 this.panel = panel;
83         }
84
85         public BasePanel getActiveBasePanel() {
86                 return panel;
87         }
88
89         /**
90          * Override this method if the component needs to make any changes before it
91          * can close.
92          */
93         public void componentClosing() {
94
95         }
96
97         /**
98          * Override this method if the component needs to do any actions when
99          * opening.
100          */
101         public void componentOpening() {
102
103         }
104
105         public Dimension getMinimumSize() {
106                 return getPreferredSize();
107         }
108
109         class CloseButtonListener implements ActionListener {
110                 public void actionPerformed(ActionEvent e) {
111                         hideAway();
112                 }
113         }
114 }