2 Copyright (C) 2003 Nizar N. Batada, Morten O. Alver
4 All programs in this directory and
5 subdirectories are published under the GNU General Public License as
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 Further information about the GNU GPL is available at:
24 http://www.gnu.org/copyleft/gpl.ja.html
27 package net.sf.jabref;
29 import java.util.Iterator;
30 import java.util.LinkedHashMap;
31 import java.util.LinkedList;
32 import java.util.List;
35 import javax.swing.SwingUtilities;
36 import javax.swing.event.ChangeEvent;
37 import javax.swing.event.ChangeListener;
40 * Manages visibility of SideShowComponents in a given newly constructed
43 * @version $Revision: 1.20 $ ($Date: 2006/08/30 00:04:12 $)
46 public class SidePaneManager {
54 Map components = new LinkedHashMap();
56 List visible = new LinkedList();
58 public SidePaneManager(JabRefFrame frame) {
61 * Change by Morten Alver 2005.12.04: By postponing the updating of the
62 * side pane components, we get rid of the annoying latency when
65 frame.tabbedPane.addChangeListener(new ChangeListener() {
66 public void stateChanged(ChangeEvent event) {
67 SwingUtilities.invokeLater(new Runnable() {
69 setActiveBasePanel((BasePanel) SidePaneManager.this.frame.tabbedPane
70 .getSelectedComponent());
75 sidep = new SidePane();
78 public SidePane getPanel() {
82 public synchronized boolean hasComponent(String name) {
83 return (components.get("name") != null);
86 public boolean isComponentVisible(String name) {
87 Object o = components.get(name);
89 return visible.contains(o);
95 public synchronized void toggle(String name) {
96 if (isComponentVisible(name)) {
103 public void show(String name) {
104 Object o = components.get(name);
106 show((SidePaneComponent) o);
108 System.err.println("Side pane component '" + name + "' unknown.");
111 public void hide(String name) {
112 Object o = components.get(name);
114 hideComponent((SidePaneComponent) o);
116 System.err.println("Side pane component '" + name + "' unknown.");
119 public synchronized void register(String name, SidePaneComponent comp) {
120 components.put(name, comp);
123 public synchronized void registerAndShow(String name, SidePaneComponent comp) {
124 register(name, comp);
128 private synchronized void show(SidePaneComponent component) {
129 if (!visible.contains(component)) {
130 // Put the new component at the top of the group
131 visible.add(0, component);
133 component.componentOpening();
137 public synchronized void hideComponent(SidePaneComponent comp) {
138 if (visible.contains(comp)) {
139 comp.componentClosing();
140 visible.remove(comp);
146 * Update all side pane components to show information from the given
151 public void setActiveBasePanel(BasePanel panel) {
152 for (Iterator i = components.keySet().iterator(); i.hasNext();) {
153 Object key = i.next();
154 ((SidePaneComponent) components.get(key)).setActiveBasePanel(panel);
158 public void updateView() {
159 sidep.setComponents(visible);
160 if (visible.size() > 0) {
161 boolean wasVisible = sidep.isVisible();
162 sidep.setVisible(true);
164 frame.contentPane.setDividerLocation(getPanel().getPreferredSize().width);
166 sidep.setVisible(false);
169 public void revalidate() {