Source code: com/trapezium/cdk/QuitDialog.java
1 package com.trapezium.cdk;
2
3 /*
4 A basic extension of the java.awt.Dialog class
5 */
6
7 import java.awt.*;
8 import java.awt.event.*;
9
10 public class QuitDialog extends Dialog
11 {
12 public QuitDialog(Frame parent, boolean modal)
13 {
14 super(parent, modal);
15
16 // This code is automatically generated by Visual Cafe when you add
17 // components to the visual environment. It instantiates and initializes
18 // the components. To modify the code, only use code syntax that matches
19 // what Visual Cafe can generate, or Visual Cafe may be unable to back
20 // parse your Java file into its visual environment.
21 //{{INIT_CONTROLS
22 setLayout(null);
23 setVisible(false);
24 setSize(337,135);
25 yesButton = new java.awt.Button();
26 yesButton.setLabel(" Yes ");
27 yesButton.setBounds(72,80,79,22);
28 yesButton.setFont(new Font("Dialog", Font.BOLD, 12));
29 add(yesButton);
30 noButton = new java.awt.Button();
31 noButton.setLabel(" No ");
32 noButton.setBounds(185,80,79,22);
33 noButton.setFont(new Font("Dialog", Font.BOLD, 12));
34 add(noButton);
35 label1 = new java.awt.Label("Do you really want to quit?",Label.CENTER);
36 label1.setBounds(78,33,180,23);
37 add(label1);
38 setTitle("Chisel Developer Kit - Quit");
39 //}}
40
41 //{{REGISTER_LISTENERS
42 SymWindow aSymWindow = new SymWindow();
43 this.addWindowListener(aSymWindow);
44 SymAction lSymAction = new SymAction();
45 noButton.addActionListener(lSymAction);
46 yesButton.addActionListener(lSymAction);
47 //}}
48 }
49
50 public void addNotify()
51 {
52 // Record the size of the window prior to calling parents addNotify.
53 Dimension d = getSize();
54
55 super.addNotify();
56
57 if (fComponentsAdjusted)
58 return;
59
60 // Adjust components according to the insets
61 setSize(insets().left + insets().right + d.width, insets().top + insets().bottom + d.height);
62 Component components[] = getComponents();
63 for (int i = 0; i < components.length; i++)
64 {
65 Point p = components[i].getLocation();
66 p.translate(insets().left, insets().top);
67 components[i].setLocation(p);
68 }
69 fComponentsAdjusted = true;
70 }
71
72 public QuitDialog(Frame parent, String title, boolean modal)
73 {
74 this(parent, modal);
75 setTitle(title);
76 }
77
78 /**
79 * Shows or hides the component depending on the boolean flag b.
80 * @param b if true, show the component; otherwise, hide the component.
81 * @see java.awt.Component#isVisible
82 */
83 public void setVisible(boolean b)
84 {
85 if(b)
86 {
87 Rectangle bounds = getParent().getBounds();
88 Rectangle abounds = getBounds();
89
90 setLocation(bounds.x + (bounds.width - abounds.width)/ 2,
91 bounds.y + (bounds.height - abounds.height)/2);
92 }
93 super.setVisible(b);
94 }
95
96 // Used for addNotify check.
97 boolean fComponentsAdjusted = false;
98
99 //{{DECLARE_CONTROLS
100 java.awt.Button yesButton;
101 java.awt.Button noButton;
102 java.awt.Label label1;
103 //}}
104
105 class SymWindow extends java.awt.event.WindowAdapter
106 {
107 public void windowClosing(java.awt.event.WindowEvent event)
108 {
109 Object object = event.getSource();
110 if (object == QuitDialog.this)
111 QuitDialog_WindowClosing(event);
112 }
113 }
114
115 void QuitDialog_WindowClosing(java.awt.event.WindowEvent event)
116 {
117 dispose();
118 }
119
120 class SymAction implements java.awt.event.ActionListener
121 {
122 public void actionPerformed(java.awt.event.ActionEvent event)
123 {
124 Object object = event.getSource();
125 if (object == noButton)
126 noButton_Clicked(event);
127 else if (object == yesButton)
128 yesButton_Clicked(event);
129 }
130 }
131
132 void yesButton_Clicked(java.awt.event.ActionEvent event)
133 {
134 Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(new WindowEvent((java.awt.Window)getParent(), WindowEvent.WINDOW_CLOSING));
135 }
136
137 void noButton_Clicked(java.awt.event.ActionEvent event)
138 {
139 dispose();
140 }
141
142 }