KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > window > DisplayManager


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (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 http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.window;
20
21 import java.awt.*;
22 import java.awt.event.*;
23
24 import javax.swing.*;
25
26 import org.openharmonise.him.configuration.*;
27 import org.openharmonise.him.context.StateHandler;
28 import org.openharmonise.him.displaycomponents.table.*;
29 import org.openharmonise.him.displaycomponents.table.title.*;
30 import org.openharmonise.him.metadata.swing.*;
31 import org.openharmonise.him.window.menus.MenuBar;
32 import org.openharmonise.him.window.outlookbar.*;
33 import org.openharmonise.him.window.swing.ExtendedSplitPane;
34 import org.openharmonise.him.window.swing.SimulacraLnF;
35 import org.openharmonise.him.window.toolbars.*;
36 import org.openharmonise.vfs.context.*;
37 import org.openharmonise.vfs.gui.*;
38
39
40 /**
41  * @author Matthew Large
42  *
43  */

44 public class DisplayManager implements Runnable JavaDoc, WindowFocusListener, ContextListener {
45
46     private static DisplayManager m_instance = null;
47
48     private ExtendedSplitPane m_splitVertBarLeft = null;
49     private TitleBarSplitPane m_splitHoriTitleBarTop = null;
50     private ExtendedSplitPane m_splitVertTableLeft = null;
51     private ExtendedSplitPane m_splitHoriMetaTopConsoleBottom = null;
52     
53     private TitleBar m_titleBar = null;
54     
55     private TableView m_table = null;
56
57     private JFrame m_mainFrame = null;
58     
59     private int m_nFrameX;
60     private int m_nFrameY;
61     private int m_nFramePosX;
62     private int m_nFramePosY;
63     
64     private FloatingBarPane m_outlookbar = null;
65     private InformationBar m_informationbar = null;
66     
67     private JScrollPane m_tableScroller = null;
68     
69     private MetadataPanel m_metadataPanel = null;
70
71     private DisplayManager() {
72         super();
73         ContextHandler.getInstance().addListener(ContextType.CONTEXT_SHUTDOWN, this);
74     }
75
76     public static DisplayManager getInstance() {
77         if (m_instance == null) {
78             m_instance = new DisplayManager();
79         }
80
81         return m_instance;
82     }
83     
84     private void setLookandFeel() {
85         SimulacraLnF.setLookAndFeel();
86     }
87     
88     public JFrame getMainWindow() {
89         return this.m_mainFrame;
90     }
91     
92     public void clearMetadataPanel() {
93         this.m_metadataPanel.clearMetadataPanel();
94     }
95
96     public void showMainWindow() {
97         this.setLookandFeel();
98         
99         this.m_mainFrame = new JFrame();
100         this.m_mainFrame.setTitle("Simulacra - Harmonise Information Manager");
101         
102         StateHandler.getInstance().setApplicationWindow(m_mainFrame);
103         
104         this.m_mainFrame.setJMenuBar( new MenuBar() );
105         
106         this.m_mainFrame.addWindowFocusListener(this);
107
108         this.m_mainFrame.setIconImage( ((ImageIcon)IconManager.getInstance().getIcon("32-sim-logo.gif")).getImage());
109         
110         DividerListener l = new DividerListener();
111         this.m_mainFrame.addComponentListener(l);
112         
113         this.m_mainFrame.setResizable(true);
114         
115         String JavaDoc sX =
116             ConfigStore.getInstance().getPropertyValue("mainFrameX");
117         int nX;
118         if (sX != null) {
119             nX = Integer.parseInt(sX);
120         } else {
121             nX=400;
122         }
123         String JavaDoc sY =
124             ConfigStore.getInstance().getPropertyValue("mainFrameY");
125         int nY;
126         if (sY != null) {
127             nY = Integer.parseInt(sY);
128         } else {
129             nY=400;
130         }
131         this.m_mainFrame.setSize(nX, nY);
132         sX =
133             ConfigStore.getInstance().getPropertyValue("mainFramePosX");
134         if (sX != null) {
135             nX = Integer.parseInt(sX);
136         } else {
137             nX=0;
138         }
139         sY =
140             ConfigStore.getInstance().getPropertyValue("mainFramePosY");
141         if (sY != null) {
142             nY = Integer.parseInt(sY);
143         } else {
144             nY=0;
145         }
146         this.m_mainFrame.setLocation(nX, nY);
147         m_mainFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
148         m_mainFrame.addWindowListener(new WindowAdapter() {
149             public void windowClosing(WindowEvent woo) {
150                 ContextEvent ce = new ContextEvent(ContextType.CONTEXT_SYNC_ALL_FILES_AND_SHUTDOWN);
151                 ContextHandler.getInstance().fireContextEvent(ce);
152             }
153         });
154
155         JPanel panel1 = new JPanel();
156         panel1.setBackground(Color.WHITE);
157         
158         m_metadataPanel = new MetadataPanel();
159         JScrollPane metadataScroller = new JScrollPane(m_metadataPanel,
160             JScrollPane.VERTICAL_SCROLLBAR_NEVER,
161             JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
162         metadataScroller.setMinimumSize(new Dimension(350,55));
163         
164         m_metadataPanel.addComponentListener(m_metadataPanel);
165         metadataScroller.addComponentListener(m_metadataPanel);
166         
167         this.m_splitVertTableLeft =
168             new ExtendedSplitPane(
169                 ExtendedSplitPane.HORIZONTAL_SPLIT,
170                 panel1,
171                 metadataScroller);
172         m_splitVertTableLeft.addComponentListener(m_metadataPanel);
173         
174         
175         m_titleBar = new TitleBar();
176         
177         this.m_splitHoriTitleBarTop =
178         new TitleBarSplitPane(
179             TitleBarSplitPane.VERTICAL_SPLIT,
180             m_titleBar,
181             m_splitVertTableLeft);
182                 
183         m_informationbar = new InformationBar();
184         this.m_splitHoriMetaTopConsoleBottom =
185             new ExtendedSplitPane(
186                 ExtendedSplitPane.VERTICAL_SPLIT,
187                 m_splitHoriTitleBarTop,
188         m_informationbar);
189
190         FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
191         fl.setHgap(0);
192         fl.setVgap(0);
193         panel1 = new JPanel(fl, true);
194         panel1.setBackground(Color.LIGHT_GRAY);
195         
196         this.m_outlookbar = new FloatingBarPane(panel1);
197         
198         panel1.add(this.m_outlookbar);
199         this.m_splitVertBarLeft =
200             new ExtendedSplitPane(
201                 ExtendedSplitPane.HORIZONTAL_SPLIT,
202                 panel1,
203                 this.m_splitHoriMetaTopConsoleBottom);
204
205         ToolBar bar = new ToolBar();
206         bar.setFloatable(false);
207         this.m_mainFrame.getContentPane().add( bar, BorderLayout.PAGE_START );
208         this.m_mainFrame.getContentPane().add( StatusBar.getInstance(), BorderLayout.PAGE_END );
209
210         this.m_mainFrame.getContentPane().add(this.m_splitVertBarLeft, BorderLayout.CENTER);
211
212         
213     }
214     
215     public void setVisible(boolean bVisible) {
216         this.m_mainFrame.setVisible(bVisible);
217         SwingUtilities.invokeLater(this);
218     }
219     
220     public void addOutlookBar(String JavaDoc sTitle, Component component) {
221         this.m_outlookbar.add(sTitle, component);
222         this.m_outlookbar.repaint();
223     }
224     
225     public void addOutlookBar(String JavaDoc sTitle, Icon icon, Component component) {
226         this.m_outlookbar.add(sTitle, icon, component);
227         this.m_outlookbar.repaint();
228     }
229     
230     public Component getOutlookBar(String JavaDoc sTitle) {
231         return this.m_outlookbar.getComponent(sTitle);
232     }
233     
234     public void setSelectedOutlookBar(String JavaDoc sTitle) {
235         Component component = this.getOutlookBar(sTitle);
236         if(component!=null) {
237             this.m_outlookbar.setSelectedComponent(component);
238         }
239     }
240     
241     public void setTable(Component table) {
242         this.m_table = (TableView) table;
243         
244         m_titleBar.setTable((TableView) table);
245         
246         m_tableScroller = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
247
248         this.m_splitVertTableLeft.setLeftComponent(m_tableScroller);
249         Dimension dim = this.m_splitVertTableLeft.getSize();
250         dim.width = dim.width-this.m_splitVertTableLeft.getDividerLocation();
251         m_tableScroller.getViewport().setSize(dim);
252         JScrollBar hBar = new JScrollBar(JScrollBar.HORIZONTAL);
253         hBar.setUnitIncrement(20);
254         m_tableScroller.setHorizontalScrollBar(hBar);
255         JScrollBar vBar = new JScrollBar(JScrollBar.VERTICAL);
256         vBar.setUnitIncrement(20);
257         m_tableScroller.setVerticalScrollBar(vBar);
258     }
259     
260     public TableView getTable() {
261         return this.m_table;
262     }
263
264     public void shutdown() {
265         ConfigStore.getInstance().setProperty("splitVertBarLeft", Double.toString(m_splitVertBarLeft.getProportionalDividerLocation()));
266         ConfigStore.getInstance().setProperty("splitVertTableLeft", Double.toString(m_splitVertTableLeft.getProportionalDividerLocation()));
267         ConfigStore.getInstance().setProperty("splitHoriMetaTopConsoleBottom", Double.toString(m_splitHoriMetaTopConsoleBottom.getProportionalDividerLocation()));
268         ConfigStore.getInstance().setProperty("mainFrameX", Integer.toString(this.m_nFrameX));
269         ConfigStore.getInstance().setProperty("mainFrameY", Integer.toString(this.m_nFrameY));
270         ConfigStore.getInstance().setProperty("mainFramePosX", Integer.toString(this.m_nFramePosX));
271         ConfigStore.getInstance().setProperty("mainFramePosY", Integer.toString(this.m_nFramePosY));
272         ConfigStore.getInstance().save();
273     }
274
275     public class DividerListener extends ComponentAdapter {
276
277         public void componentResized(ComponentEvent event) {
278             m_nFrameX = m_mainFrame.getWidth();
279             m_nFrameY = m_mainFrame.getHeight();
280         }
281         
282         public void componentMoved(ComponentEvent e) {
283             m_nFramePosX = m_mainFrame.getX();
284             m_nFramePosY = m_mainFrame.getY();
285         }
286     }
287
288     /**
289      * @return
290      */

291     public FloatingBarPane getOutlookbar() {
292         return m_outlookbar;
293     }
294     
295     public void hideMetadata() {
296         String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("AUTO_METADATA_POSITION");
297         if(sValue!=null && sValue.equals("Yes")) {
298             ((ExtendedSplitPane)this.m_splitVertTableLeft).setExtDividerLocation(this.m_splitVertTableLeft.getWidth());
299         }
300         ContextEvent ce = new ContextEvent(ContextType.CONTEXT_CLEAR_METADATA);
301         ContextHandler.getInstance().fireContextEvent(ce);
302     }
303     
304     public synchronized void openMetadata() {
305         String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("AUTO_METADATA_POSITION");
306         if(sValue!=null && sValue.equals("Yes")) {
307             this.m_splitVertTableLeft.setExtDividerLocation(200);
308         }
309         this.m_splitVertTableLeft.validate();
310     }
311     
312     public void scrollTableTo(int nPosition) {
313         String JavaDoc sValue = ConfigStore.getInstance().getPropertyValue("AUTO_METADATA_POSITION");
314         if(sValue!=null && sValue.equals("Yes")) {
315             this.m_tableScroller.getHorizontalScrollBar().setValue(nPosition);
316         }
317     }
318
319     /* (non-Javadoc)
320      * @see java.lang.Runnable#run()
321      */

322     public void run() {
323
324         String JavaDoc sSplit =
325             ConfigStore.getInstance().getPropertyValue("splitVertBarLeft");
326         if (sSplit != null) {
327             double split = Double.parseDouble(sSplit);
328             m_splitVertBarLeft.setDividerLocation(split);
329         } else {
330             double split = 0.5;
331             m_splitVertBarLeft.setDividerLocation(split);
332         }
333
334         sSplit =
335             ConfigStore.getInstance().getPropertyValue(
336                 "splitHoriMetaTopConsoleBottom");
337         if (sSplit != null) {
338             double split = Double.parseDouble(sSplit);
339             m_splitHoriMetaTopConsoleBottom.setDividerLocation(split);
340         } else {
341             double split = 0.5;
342             m_splitHoriMetaTopConsoleBottom.setDividerLocation(split);
343         }
344         m_splitVertTableLeft.setExtDividerLocation(500);
345         this.m_splitVertTableLeft.validate();
346     }
347
348     /* (non-Javadoc)
349      * @see java.awt.event.WindowFocusListener#windowGainedFocus(java.awt.event.WindowEvent)
350      */

351     public void windowGainedFocus(WindowEvent arg0) {
352         
353         ContextEvent ce = new ContextEvent(ContextType.CONTEXT_APP_FOCUS);
354         ContextHandler.getInstance().fireContextEvent(ce);
355     }
356
357     /* (non-Javadoc)
358      * @see java.awt.event.WindowFocusListener#windowLostFocus(java.awt.event.WindowEvent)
359      */

360     public void windowLostFocus(WindowEvent arg0) {
361     }
362
363     /* (non-Javadoc)
364      * @see com.simulacramedia.contentmanager.context.ContextListener#contextMessage(com.simulacramedia.contentmanager.context.ContextEvent)
365      */

366     public void contextMessage(ContextEvent ce) {
367         if(ce.CONTEXT_TYPE==ContextType.CONTEXT_SHUTDOWN) {
368             this.shutdown();
369         }
370     }
371
372 }
373
Popular Tags