KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > amazon > amazonSimpleQueueService > AmazonSimpleQueueServiceOut


1 /*
2 * Copyright 2004,2005 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */

16 package sample.amazon.amazonSimpleQueueService;
17
18 import sample.amazon.amazonSimpleQueueService.util.QueueManager;
19
20 import javax.swing.*;
21 import java.awt.*;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.awt.event.KeyEvent JavaDoc;
25 import java.io.File JavaDoc;
26 import java.io.IOException JavaDoc;
27
28 /**
29  * GUI class which handles the OUT operations of the queue
30  *
31  * @author Saminda Abeyruwan <saminda@opensource.lk>
32  */

33 public class AmazonSimpleQueueServiceOut extends JFrame {
34     private static final String JavaDoc HELP_FILE_NAME = "/docs/AmazonSimpleWebService.html";
35     JTextField createQueue;
36     JTextField queueCode;
37     JTextField read;
38     JTextArea resuts;
39     JButton loadButton;
40     JButton deleteButton;
41
42     public AmazonSimpleQueueServiceOut() {
43         this.setBounds(200, 200, 450, 500);
44         this.setTitle("Amazon Simple Queue WS - Out");
45         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
46         this.guiInit();
47     }
48
49     private void guiInit() {
50         getContentPane().setLayout(new GridBagLayout());
51         GridBagConstraints cons = new GridBagConstraints();
52         cons.fill = GridBagConstraints.BOTH;
53         cons.insets = new Insets(5, 5, 5, 5);
54         cons.weightx = 100;
55         JLabel label0 = new JLabel("Enter Queue Name");
56         this.add(label0, cons, 0, 0, 1, 1);
57         JLabel lable1 = new JLabel("Queue Code");
58         this.add(lable1, cons, 1, 0, 1, 1);
59         createQueue = new JTextField();
60         createQueue.setEditable(false);
61         this.add(createQueue, cons, 0, 1, 1, 1);
62         queueCode = new JTextField();
63         queueCode.setEditable(false);
64         this.add(queueCode, cons, 1, 1, 1, 1);
65         JLabel lable2 = new JLabel("Read");
66         this.add(lable2, cons, 0, 2, 1, 1);
67         read = new JTextField();
68         read.setEditable(false);
69         this.add(read, cons, 0, 3, 2, 1);
70         JLabel label3 = new JLabel("Results");
71         this.add(label3, cons, 0, 4, 1, 1);
72         resuts = new JTextArea();
73         resuts.setEditable(false);
74         JScrollPane resultPane = new JScrollPane(resuts);
75         cons.weighty = 100;
76         this.add(resultPane, cons, 0, 5, 2, 1);
77         JPanel buttonPannel = new JPanel();
78         loadButton = new JButton("Load Queue");
79         loadButton.setActionCommand("1");
80         deleteButton = new JButton("Delete Queue");
81         deleteButton.setActionCommand("2");
82         buttonPannel.add(loadButton);
83         buttonPannel.add(deleteButton);
84         cons.weightx = 0;
85         cons.weighty = 0;
86         this.add(buttonPannel, cons, 0, 6, 2, 1);
87         this.createQueue.addKeyListener(new ListenersOut(this.createQueue, this.queueCode,
88                 this.read, this.resuts, this.loadButton, this.deleteButton));
89         this.loadButton.addActionListener(new ListenersOut(this.createQueue, this.queueCode,
90                 this.read, this.resuts, this.loadButton, this.deleteButton));
91         this.resuts.addMouseMotionListener(new ListenersOut(this.createQueue, this.queueCode,
92                 this.read, this.resuts, this.loadButton, this.deleteButton));
93         this.deleteButton.addActionListener(new ListenersOut(this.createQueue, this.queueCode,
94                 this.read, this.resuts, this.loadButton, this.deleteButton));
95
96         AddMenuItems();
97     }
98
99     private void add(Component c, GridBagConstraints cons, int x, int y, int w, int h) {
100         cons.gridx = x;
101         cons.gridy = y;
102         cons.gridheight = h;
103         cons.gridwidth = w;
104         this.getContentPane().add(c, cons);
105     }
106
107     private void AddMenuItems() {
108             //add the menus
109
JMenuBar menuBar = new JMenuBar();
110             JMenu settingsMenu = new JMenu("Settings");
111             settingsMenu.setMnemonic(KeyEvent.VK_S);
112             JMenuItem amazonKeyMenu = new JMenuItem("Set Amazon Key",KeyEvent.VK_G);
113             amazonKeyMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK));
114             amazonKeyMenu.addActionListener(new ActionListener JavaDoc(){
115                 public void actionPerformed(ActionEvent JavaDoc e) {
116                     setKey();
117                 }
118             });
119             settingsMenu.add(amazonKeyMenu);
120
121             JMenu helpMenu = new JMenu("Help");
122             JMenuItem mnuItemHelp = new JMenuItem("Show Help");
123             helpMenu.add(mnuItemHelp);
124
125             mnuItemHelp.addActionListener(new ActionListener JavaDoc() {
126                 public void actionPerformed(ActionEvent JavaDoc e) {
127                     showHelp();
128                 }
129             });
130
131             menuBar.add(settingsMenu);
132             menuBar.add(helpMenu);
133             setJMenuBar(menuBar);
134         }
135
136         private void setKey(){
137             String JavaDoc key = JOptionPane.showInputDialog(this,"Set the Amazon Key",QueueManager.getKey());
138             if (key!=null && !key.trim().equals("")){
139                 QueueManager.setKey(key);
140             }
141         }
142
143         /**
144          * method showHelp
145          */

146         private void showHelp() {
147
148             JFrame frame= new JFrame();
149             Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
150             frame.setLocation(screenSize.width/5,
151                     screenSize.height/5);
152             frame.setSize(screenSize.width/2,screenSize.height/2);
153
154             BorderLayout layout = new BorderLayout();
155
156             JScrollPane jsp ;
157             JEditorPane jep;
158
159             jep = new JEditorPane();
160             //jep.addHyperlinkListener(new LinkFollower());
161
jep.setEditable(false);
162             jep.setContentType("text/html");
163
164             jsp = new JScrollPane(jep);
165
166             Container contentPane = frame.getContentPane();
167             contentPane.setLayout(layout);
168             contentPane.add(jsp, BorderLayout.CENTER);
169             String JavaDoc helpDoc = System.getProperty("user.dir")+HELP_FILE_NAME;
170
171             try {
172                 jep.setPage(new File JavaDoc(helpDoc).toURL());
173             } catch (IOException JavaDoc e) {
174                 JOptionPane.showMessageDialog(this,"Help file not detected","Help file error",JOptionPane.ERROR_MESSAGE);
175                 return;
176             }
177             frame.setVisible(true);
178         }
179
180 }
181
Popular Tags