Source code: org/dma/ihm/gui/message/FrameMessage.java
1 package org.dma.ihm.gui.message;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.util.*;
6
7 import javax.swing.*;
8
9 import org.dma.ihm.controller.*;
10 import org.dma.ihm.controller.data.*;
11 import org.dma.ihm.game.*;
12 import org.dma.ihm.game.calendar.*;
13 import org.dma.ihm.game.calendar.events.*;
14 import org.dma.ihm.game.match.*;
15 import org.dma.ihm.game.team.*;
16 import org.dma.ihm.gui.*;
17 import org.dma.ihm.gui.lib.*;
18
19 /**
20 * The FrameMessage contains: A frame that just shows a message, and and fires
21 * an action event to all listeners when button is pressed.
22 *
23 * @author Bernhard von Gunten
24 * @created December 29, 2001
25 */
26 public class FrameMessage extends JIhmInternalFrame {
27
28 // Gui controls
29 JButton cmdNext = new JButton();
30 BorderLayout borderLayout1 = new BorderLayout();
31 JLabel lblMsg = new JLabel();
32
33 private transient Vector actionListeners;
34
35
36 /**
37 * Conscructs the frame, sets the user (=null) and desktop of this frame
38 *
39 * @param user User to show this frame for
40 * @param title Title of the message
41 * @param message Message to show
42 * @param showMoveOn Indicates if moveOn button is shown
43 */
44 public FrameMessage(User user, String title, String message, boolean showMoveOn) {
45 super(user);
46 try {
47 jbInit();
48 ihmInit(title, message, showMoveOn);
49 } catch (Exception e) {
50 e.printStackTrace();
51 }
52 }
53
54
55 /** Empty Constructor for the FrameMessage object (for the jbuilder designer) */
56 public FrameMessage() { }
57
58
59 /**
60 * JBuilder stuff
61 *
62 * @exception Exception Exception
63 */
64 private void jbInit() throws Exception {
65 this.setSize(500, 90);
66 cmdNext.setText(Controller.getTranslation("general.moveOn"));
67 cmdNext.addActionListener(
68 new java.awt.event.ActionListener() {
69 public void actionPerformed(ActionEvent e) {
70 cmdNext_actionPerformed(e);
71 }
72 });
73 this.getContentPane().setLayout(borderLayout1);
74 lblMsg.setFont(new java.awt.Font("Dialog", 1, 16));
75 lblMsg.setHorizontalAlignment(SwingConstants.CENTER);
76 lblMsg.setHorizontalTextPosition(SwingConstants.CENTER);
77 lblMsg.setText("noMsg");
78 this.setResizable(true);
79 this.setTitle("");
80 this.getContentPane().add(lblMsg, BorderLayout.CENTER);
81 }
82
83
84 /**
85 * Display a text message on the frame
86 *
87 * @param title Title of message
88 * @param msg Message to show
89 * @param showMoveOn Indicates if moveOn button is shown
90 */
91 public void ihmInit(String title, String msg, boolean showMoveOn) {
92 this.setTitle(title);
93 this.lblMsg.setText(msg);
94
95 if (showMoveOn) {
96 this.getContentPane().add(cmdNext, BorderLayout.SOUTH);
97 }
98
99 this.repaint();
100 }
101
102
103 /**
104 * Shows a short message
105 *
106 * @param title Title of message
107 * @param msg Message to show
108 */
109 public void displayShortMessage(String title, String msg) {
110 this.setTitle(title);
111 this.lblMsg.setText(msg);
112 this.repaint();
113 }
114
115
116 /**
117 * Fire action event that button moveOn is pressed
118 *
119 * @param e Source event
120 */
121 void cmdNext_actionPerformed(ActionEvent e) {
122 this.fireActionPerformed(e);
123 this.doDefaultCloseAction();
124 }
125
126
127 // Event handling
128
129 /**
130 * Description of the Method
131 *
132 * @param l Description of the Parameter
133 */
134 public synchronized void removeActionListener(ActionListener l) {
135 if (actionListeners != null && actionListeners.contains(l)) {
136 Vector v = (Vector) actionListeners.clone();
137 v.removeElement(l);
138 actionListeners = v;
139 }
140 }
141
142
143 /**
144 * Adds a feature to the ActionListener attribute of the FrameMessage object
145 *
146 * @param l The feature to be added to the ActionListener attribute
147 */
148 public synchronized void addActionListener(ActionListener l) {
149 Vector v = actionListeners == null ? new Vector(2) : (Vector) actionListeners.clone();
150 if (!v.contains(l)) {
151 v.addElement(l);
152 actionListeners = v;
153 }
154 }
155
156
157 /**
158 * Description of the Method
159 *
160 * @param e Description of the Parameter
161 */
162 protected void fireActionPerformed(ActionEvent e) {
163 if (actionListeners != null) {
164 Vector listeners = actionListeners;
165 int count = listeners.size();
166 for (int i = 0; i < count; i++) {
167 ((ActionListener) listeners.elementAt(i)).actionPerformed(e);
168 }
169 }
170 }
171
172 }