KickJava   Java API By Example, From Geeks To Geeks.

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


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 which handles the IN operations of the queue
30  * @author Saminda Abeyruwan <saminda@opensource.lk>
31  *
32  */

33 public class AmazonSimpleQueueServiceIn extends JFrame{
34     private static final String JavaDoc HELP_FILE_NAME = "/docs/AmazonSimpleWebService.html";
35     JTextField createQueue;
36     JTextField queueCode;
37     JTextField enqueue;
38     JTextArea resuts;
39
40     public AmazonSimpleQueueServiceIn(){
41         this.setBounds(200,200,450,500);
42         this.setTitle("Amazon Simple Queue WS - In");
43         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
44         this.guiInit();
45     }
46     private void guiInit(){
47         getContentPane().setLayout(new GridBagLayout());
48         GridBagConstraints cons = new GridBagConstraints();
49         cons.fill = GridBagConstraints.BOTH;
50         JLabel lable1 = new JLabel("Create Queue");
51         cons.insets = new Insets(5,5,5,5);
52         this.add(lable1,cons,0,0,1,1);
53         JLabel lable2 = new JLabel("Queue Code");
54         this.add(lable2, cons, 1,0,1,1);
55         cons.weightx = 100;
56         createQueue = new JTextField("Test Queue LSF2");
57         this.add(createQueue,cons,0,1,1,1);
58         queueCode = new JTextField();
59         queueCode.setEditable(false);
60         this.add(queueCode,cons,1,1,1,1);
61         JLabel lable3 = new JLabel("Enqueue");
62         this.add(lable3,cons,0,2,1,1);
63         enqueue = new JTextField();
64         enqueue.setEditable(false);
65         this.add(enqueue,cons,0,3,2,1);
66         JLabel label4 = new JLabel("Results");
67         this.add(label4,cons,0,5,1,1);
68         cons.weighty = 100;
69         resuts = new JTextArea();
70         resuts.setEditable(false);
71         resuts.setLineWrap(true);
72         resuts.setWrapStyleWord(true);
73         JScrollPane resultpane = new JScrollPane(resuts);
74         this.add(resultpane,cons,0,6,2,2);
75         createQueue.addKeyListener(new ListenersIn(createQueue,queueCode,enqueue,resuts));
76         enqueue.addKeyListener(new ListenersIn(createQueue,queueCode,enqueue,resuts));
77
78         AddMenuItems();
79
80     }
81
82     private void AddMenuItems() {
83         //add the menus
84
JMenuBar menuBar = new JMenuBar();
85         JMenu settingsMenu = new JMenu("Settings");
86         settingsMenu.setMnemonic(KeyEvent.VK_S);
87         JMenuItem amazonKeyMenu = new JMenuItem("Set Amazon Key",KeyEvent.VK_G);
88         amazonKeyMenu.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK));
89         amazonKeyMenu.addActionListener(new ActionListener JavaDoc(){
90             public void actionPerformed(ActionEvent JavaDoc e) {
91                 setKey();
92             }
93         });
94         settingsMenu.add(amazonKeyMenu);
95
96         JMenu helpMenu = new JMenu("Help");
97         JMenuItem mnuItemHelp = new JMenuItem("Show Help");
98         helpMenu.add(mnuItemHelp);
99
100         mnuItemHelp.addActionListener(new ActionListener JavaDoc() {
101             public void actionPerformed(ActionEvent JavaDoc e) {
102                 showHelp();
103             }
104         });
105
106         menuBar.add(settingsMenu);
107         menuBar.add(helpMenu);
108         setJMenuBar(menuBar);
109     }
110
111     private void setKey(){
112         String JavaDoc key = JOptionPane.showInputDialog(this,"Set the Amazon Key",QueueManager.getKey());
113         if (key!=null && !key.trim().equals("")){
114             QueueManager.setKey(key);
115         }
116     }
117
118     /**
119      * method showHelp
120      */

121     private void showHelp() {
122
123         JFrame frame= new JFrame();
124         Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
125         frame.setLocation(screenSize.width/5,
126                 screenSize.height/5);
127         frame.setSize(screenSize.width/2,screenSize.height/2);
128
129         BorderLayout layout = new BorderLayout();
130
131         JScrollPane jsp ;
132         JEditorPane jep;
133
134         jep = new JEditorPane();
135         //jep.addHyperlinkListener(new LinkFollower());
136
jep.setEditable(false);
137         jep.setContentType("text/html");
138
139         jsp = new JScrollPane(jep);
140
141         Container contentPane = frame.getContentPane();
142         contentPane.setLayout(layout);
143         contentPane.add(jsp, BorderLayout.CENTER);
144         String JavaDoc helpDoc = System.getProperty("user.dir")+HELP_FILE_NAME;
145
146         try {
147             jep.setPage(new File JavaDoc(helpDoc).toURL());
148         } catch (IOException JavaDoc e) {
149             JOptionPane.showMessageDialog(this,"Help file not detected","Help file error",JOptionPane.ERROR_MESSAGE);
150             return;
151         }
152         frame.setVisible(true);
153     }
154
155
156     private void add(Component c, GridBagConstraints cons, int x, int y, int w, int h){
157         cons.gridx = x;
158         cons.gridy = y;
159         cons.gridheight = h;
160         cons.gridwidth = w;
161         this.getContentPane().add(c,cons);
162     }
163
164 }
165
Popular Tags