View Javadoc

1   /*
2    * @(#)$Id: AbstractPanel.java 754 2009-08-23 18:36:45Z kurmannu $
3    *
4    * Author   : Ueli Kurmann, igesture@uelikurmann.ch
5    *                                   
6    *                                   
7    * Purpose  : 
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date       Who     Reason
14   *
15   * 23.03.2008 ukurmann  Initial Release
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  package org.ximtec.igesture.tool.view;
27  
28  import java.awt.BorderLayout;
29  import java.awt.Color;
30  
31  import javax.swing.BorderFactory;
32  import javax.swing.JComponent;
33  import javax.swing.JScrollPane;
34  import javax.swing.SwingUtilities;
35  
36  import org.ximtec.igesture.tool.core.Controller;
37  import org.ximtec.igesture.tool.explorer.DefaultExplorerTreeView;
38  import org.ximtec.igesture.tool.util.ComponentFactory;
39  
40  public abstract class AbstractPanel extends DefaultExplorerTreeView {
41  
42    private JScrollPane centerPane;
43    private Controller controller;
44  
45    public AbstractPanel(Controller controller) {
46      this.controller = controller;
47      if (controller == null) {
48        throw new RuntimeException("Controller must not be null.");
49      }
50      setLayout(new BorderLayout());
51      centerPane = new JScrollPane();
52      centerPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
53      setBackground(Color.LIGHT_GRAY);
54      setOpaque(true);
55      this.add(centerPane, BorderLayout.CENTER);
56    }
57  
58    /**
59     * Sets the title component
60     * 
61     * @param component
62     *          the title component
63     */
64    public void setTitle(JComponent component) {
65      this.add(component, BorderLayout.NORTH);
66    }
67  
68    /**
69     * Sets the content area.
70     * 
71     * @param component
72     *          the content area.
73     */
74    public void setContent(JComponent component) {
75      component.setBackground(Color.white);
76      component.setOpaque(true);
77     
78      centerPane.setViewportView(component);
79    }
80  
81    /**
82     * Sets the footer of the panel.
83     * 
84     * @param component
85     *          the footer of the panel.
86     */
87    public void setBottom(JComponent component) {
88      this.add(component, BorderLayout.SOUTH);
89    }
90  
91    /**
92     * Returns the controller
93     * 
94     * @return the controller
95     */
96    protected Controller getController() {
97      return this.controller;
98    }
99  
100   /**
101    * Returns the component factory. The Controller and it's locator is used to
102    * get the applications component factory.
103    * 
104    * @return the component factory
105    */
106   protected ComponentFactory getComponentFactory() {
107     if (controller != null) {
108       return controller.getLocator().getService(ComponentFactory.class.getName(), ComponentFactory.class);
109     }
110     return null;
111   }
112 
113   @Override
114   public final void refresh() {
115     if (SwingUtilities.isEventDispatchThread()) {
116       refreshUILogic();
117     } else {
118       SwingUtilities.invokeLater(new Runnable() {
119         @Override
120         public void run() {
121           refreshUILogic();
122         }
123       });
124     }
125   }
126 
127   /**
128    * Abstract implementations of the refreshUILogic method. This implementation
129    * is empty. Per default nothing has to be updated.
130    */
131   protected void refreshUILogic() {
132 
133   }
134 
135 }