1 package net.logAnalyzer.gui;
2
3 import java.awt.GridLayout;
4
5 import javax.swing.JInternalFrame;
6 import javax.swing.event.InternalFrameEvent;
7 import javax.swing.event.InternalFrameListener;
8
9 /***
10 * This class is a {@link net.logAnalyzer.gui.LAViewContainer}implementation as
11 * a {@link javax.swing.JInternalFrame}.
12 *
13 * @author Karim REFEYTON
14 * @version 0.1
15 */
16 public class InternalFrameViewContainer extends JInternalFrame implements
17 LAViewContainer, InternalFrameListener {
18 private static final long serialVersionUID = 1L;
19
20 public InternalFrameViewContainer() {
21 super("", true, true, true, true);
22 getContentPane().setLayout(new GridLayout(1, 0));
23 addInternalFrameListener(this);
24 }
25
26 /***
27 * Parent frame.
28 */
29 private LAFrame frame;
30
31 /***
32 * Returns the parent frame.
33 *
34 * @return Parent frame.
35 */
36 public LAFrame getFrame() {
37 return this.frame;
38 }
39
40 /***
41 * Sets the parent frame.
42 *
43 * @param frame
44 * Parent frame.
45 */
46 public void setFrame(LAFrame frame) {
47 this.frame = frame;
48 }
49
50 /***
51 * Contained view.
52 */
53 private LAView view;
54
55 /***
56 * Sets the contained view.
57 *
58 * @param newView
59 * NEw view to contain.
60 * @return Previous contained view if exists; <tt>null</tt> otherwise.
61 */
62 public LAView setView(LAView newView) {
63 LAView oldView = this.view;
64 if (oldView != null) {
65 getContentPane().remove(oldView);
66 }
67 this.view = (LAView) newView;
68 getContentPane().add(this.view);
69 view.setViewContainer(this);
70 return oldView;
71 }
72
73 /***
74 * Called by the contained view when its content is modified.
75 */
76 public void viewModified() {
77 setTitle(view.getTitle());
78 setFrameIcon(view.getIcon());
79 }
80
81 /***
82 * Called by the contained view when the current messages selection has
83 * changed.
84 *
85 * @param firstIndex
86 * First messageLabel index.
87 * @param lastIndex
88 * Last messageLabel index.
89 */
90 public void messageChanged(int firstIndex, int lastIndex) {
91 this.frame.messageChanged(this, firstIndex, lastIndex);
92 }
93
94 /***
95 * Changes the current messages selection.
96 *
97 * @param firstIndex
98 * First messageLabel index.
99 * @param lastIndex
100 * Last messageLabel index.
101 */
102 public void setCurrentMessage(int firstIndex, int lastIndex) {
103 view.setCurrentMessage(firstIndex, lastIndex);
104 }
105
106 /***
107 * Modification to the inherited behavior.
108 *
109 * @see javax.swing.event.InternalFrameListener#internalFrameActivated(javax.swing.event.InternalFrameEvent)
110 */
111 public void internalFrameActivated(InternalFrameEvent e) {
112 frame.activatedView(this.view);
113 }
114
115 /***
116 * Modification to the inherited behavior.
117 *
118 * @see javax.swing.event.InternalFrameListener#internalFrameClosed(javax.swing.event.InternalFrameEvent)
119 */
120 public void internalFrameClosed(InternalFrameEvent e) {
121
122
123 }
124
125 /***
126 * Modification to the inherited behavior.
127 *
128 * @see javax.swing.event.InternalFrameListener#internalFrameClosing(javax.swing.event.InternalFrameEvent)
129 */
130 public void internalFrameClosing(InternalFrameEvent e) {
131 frame.deactivatedView(this.view);
132 frame.closeView(this);
133 }
134
135 /***
136 * Modification to the inherited behavior.
137 *
138 * @see javax.swing.event.InternalFrameListener#internalFrameDeactivated(javax.swing.event.InternalFrameEvent)
139 */
140 public void internalFrameDeactivated(InternalFrameEvent e) {
141 frame.deactivatedView(this.view);
142 }
143
144 /***
145 * Modification to the inherited behavior.
146 *
147 * @see javax.swing.event.InternalFrameListener#internalFrameDeiconified(javax.swing.event.InternalFrameEvent)
148 */
149 public void internalFrameDeiconified(InternalFrameEvent e) {
150 frame.activatedView(this.view);
151 }
152
153 /***
154 * Modification to the inherited behavior.
155 *
156 * @see javax.swing.event.InternalFrameListener#internalFrameIconified(javax.swing.event.InternalFrameEvent)
157 */
158 public void internalFrameIconified(InternalFrameEvent e) {
159 frame.deactivatedView(this.view);
160 }
161
162 /***
163 * Modification to the inherited behavior.
164 *
165 * @see javax.swing.event.InternalFrameListener#internalFrameOpened(javax.swing.event.InternalFrameEvent)
166 */
167 public void internalFrameOpened(InternalFrameEvent e) {
168 frame.activatedView(this.view);
169 }
170 }