View Javadoc
1   package net.logAnalyzer.gui;
2   
3   import java.awt.BorderLayout;
4   import java.awt.Color;
5   import java.awt.Dimension;
6   import java.awt.Point;
7   import java.awt.event.WindowEvent;
8   import java.awt.event.WindowListener;
9   import java.util.Vector;
10  
11  import javax.swing.JFrame;
12  
13  import net.logAnalyzer.LogAnalyzerGUI;
14  import net.logAnalyzer.config.ConfigurationManager;
15  import net.logAnalyzer.gui.quickbar.actions.QuickMainPanel;
16  import net.logAnalyzer.gui.quickbar.actions.QuickViewsPanel;
17  import net.logAnalyzer.patternParser.PatternParsingException;
18  import net.logAnalyzer.resources.LAResourceBundle;
19  import net.logAnalyzer.utils.gui.JScrollDesktopPane;
20  import net.logAnalyzer.utils.gui.quickbar.QuickBar;
21  import net.logAnalyzer.utils.gui.quickbar.QuickPanel;
22  
23  /***
24   * This class implements the main window of the LogAnalyzer GUI. It manages
25   * views declared in the LogAnalyzer.xml file via a Windows XP like side bar
26   * called {@link QuickBar}.
27   * 
28   * @author KKI
29   * 
30   */
31  public class LAFrame extends JFrame implements WindowListener {
32      /***
33       * Used for Swing serialization.
34       */
35      private static final long serialVersionUID = 1L;
36      /***
37       * Default window dimension.
38       */
39      private static final Dimension DIMENSION = new Dimension(800, 600);
40  
41      /***
42       * Desktop pane used to manage {@link javax.swing.JInternalFrame}.
43       */
44      private JScrollDesktopPane desktopPane;
45  
46      /***
47       * QuickBar used to manage {@link QuickPanel}.
48       */
49      private QuickBar quickbar;
50  
51      /***
52       * Views containers.
53       */
54      private Vector viewsContainers = new Vector();
55  
56      /***
57       * Constructs a new LAFrame.
58       * 
59       * @param title
60       *            frame title.
61       * @see JFrame#JFrame(java.lang.String)
62       */
63      public LAFrame(String title) {
64          super(title);
65          addComponents();
66          addWindowListener(this);
67          setSize(DIMENSION);
68      }
69  
70      /***
71       * Adds the components.
72       */
73      private void addComponents() {
74  
75          // Sets frame icon
76          this.setIconImage(LAResourceBundle.getIcon("LAFrame.icon").getImage());
77  
78          // Adds QuickBar
79          quickbar = new QuickBar(200);
80          getContentPane().add(quickbar, BorderLayout.WEST);
81          QuickPanel qmainPanel = new QuickMainPanel();
82          qmainPanel.setFrame(this);
83          quickbar.addPanel(qmainPanel);
84          QuickPanel qviewsPanel = new QuickViewsPanel();
85          qviewsPanel.setFrame(this);
86          quickbar.addPanel(qviewsPanel);
87          // Sets desktop pane
88          desktopPane = new JScrollDesktopPane();
89          desktopPane.setBackground(Color.LIGHT_GRAY);
90          getContentPane().add(desktopPane, BorderLayout.CENTER);
91      }
92  
93      /***
94       * X offset location for new view.
95       */
96      private int xOffset = 30;
97  
98      /***
99       * Y offset location for new view.
100      */
101     private int yOffset = 30;
102 
103     /***
104      * XY factor for new view. If the new view location is outside the visible
105      * rectangle, xyFactor is set to <tt>0</tt>.
106      */
107     private int xyFactor = 0;
108 
109     /***
110      * Creates a new view of the specified name form its definition.
111      * 
112      * @param name
113      *            Name of the view.
114      * @return The created view.
115      */
116     public LAView createView(String name) {
117         LAView view = null;
118         try {
119             view = ConfigurationManager.getInstance().createView(name);
120             displayView(view);
121         } catch (PatternParsingException ppe) {
122             return view;
123         }
124         return view;
125     }
126     
127     public void displayView(LAView view){
128 
129         // Create the view container and its view
130         InternalFrameViewContainer container = new InternalFrameViewContainer();
131         viewsContainers.add(container);
132         container.setFrame(this);
133         container.setView(view);
134         container.setSize(300, 300);
135         // Set the standard position of a new internal frame
136         Point newLocation = new Point(xOffset * xyFactor, yOffset * xyFactor);
137         if (!desktopPane.getVisibleRect().contains(newLocation)) {
138             xyFactor = 0;
139             newLocation = new Point(xOffset * xyFactor, yOffset * xyFactor);
140         }
141         xyFactor++;
142         container.setLocation(newLocation);
143         // Add and show the new internal frame
144         container.setVisible(true);
145         desktopPane.add(container);
146         try {
147             container.setSelected(true);
148         } catch (java.beans.PropertyVetoException e) {
149             // NOP
150         }
151     }
152 
153     /***
154      * Removes the specified closing view.
155      * 
156      * @param view
157      *            Closing view.
158      */
159     public void closeView(LAViewContainer view) {
160         viewsContainers.remove(view);
161     }
162     
163     public void deactivatedView(LAView view) {
164         if(view.getQuickBarComponent() != null){
165             quickbar.removePanel(view.getQuickBarComponent());
166         }
167     }
168     
169     public void activatedView(LAView view) {
170         if(view.getQuickBarComponent() != null){
171             quickbar.addPanel(view.getQuickBarComponent());
172         }
173         
174     }
175 
176     /***
177      * Called by a view when the current messages selection has changed.
178      * 
179      * @param viewContainer
180      *            View container in which the current messageLabel has changed.
181      * @param firstIndex
182      *            First messageLabel index.
183      * @param lastIndex
184      *            Last messageLabel index.
185      */
186     public void messageChanged(LAViewContainer viewContainer, int firstIndex,
187             int lastIndex) {
188         for (int i = 0; i < viewsContainers.size(); i++) {
189             LAViewContainer container = (LAViewContainer) viewsContainers
190                     .get(i);
191             if (!container.equals(viewContainer)) {
192                 container.setCurrentMessage(firstIndex, lastIndex);
193             }
194         }
195     }
196 
197     /***
198      * Modification to the inherited behavior.
199      * 
200      * @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
201      */
202     public void windowActivated(WindowEvent e) {
203         // NOP
204     }
205 
206     /***
207      * Modification to the inherited behavior.
208      * 
209      * @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
210      */
211     public void windowClosed(WindowEvent e) {
212         // NOP
213     }
214 
215     /***
216      * Modification to the inherited behavior.
217      * 
218      * @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
219      */
220     public void windowClosing(WindowEvent e) {
221         LogAnalyzerGUI.closeGUI(this);
222     }
223 
224     /***
225      * Modification to the inherited behavior.
226      * 
227      * @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
228      */
229     public void windowDeactivated(WindowEvent e) {
230         // NOP
231     }
232 
233     /***
234      * Modification to the inherited behavior.
235      * 
236      * @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
237      */
238     public void windowDeiconified(WindowEvent e) {
239         // NOP
240     }
241 
242     /***
243      * Modification to the inherited behavior.
244      * 
245      * @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
246      */
247     public void windowIconified(WindowEvent e) {
248         // NOP
249     }
250 
251     /***
252      * Modification to the inherited behavior.
253      * 
254      * @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
255      */
256     public void windowOpened(WindowEvent e) {
257         // NOP
258     }
259 
260 }