Home » cxf-dosgi-ri-source-distribution-1.1 » org.apache.cxf.dosgi.samples.greeter.client » [javadoc | source]

    1   /** 
    2     * Licensed to the Apache Software Foundation (ASF) under one 
    3     * or more contributor license agreements. See the NOTICE file 
    4     * distributed with this work for additional information 
    5     * regarding copyright ownership. The ASF licenses this file 
    6     * to you under the Apache License, Version 2.0 (the 
    7     * "License"); you may not use this file except in compliance 
    8     * with the License. You may obtain a copy of the License at 
    9     * 
   10     * http://www.apache.org/licenses/LICENSE-2.0 
   11     * 
   12     * Unless required by applicable law or agreed to in writing, 
   13     * software distributed under the License is distributed on an 
   14     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 
   15     * KIND, either express or implied. See the License for the 
   16     * specific language governing permissions and limitations 
   17     * under the License. 
   18     */
   19   package org.apache.cxf.dosgi.samples.greeter.client;
   20   
   21   import java.awt.Component;
   22   import java.awt.FlowLayout;
   23   import java.awt.Frame;
   24   import java.awt.GridBagConstraints;
   25   import java.awt.GridBagLayout;
   26   import java.awt.Insets;
   27   import java.awt.event.ActionEvent;
   28   import java.awt.event.ActionListener;
   29   
   30   import javax.swing.BoxLayout;
   31   import javax.swing.ButtonGroup;
   32   import javax.swing.JButton;
   33   import javax.swing.JCheckBox;
   34   import javax.swing.JDialog;
   35   import javax.swing.JLabel;
   36   import javax.swing.JPanel;
   37   import javax.swing.JRadioButton;
   38   import javax.swing.JTextField;
   39   import javax.swing.event.ChangeEvent;
   40   import javax.swing.event.ChangeListener;
   41   
   42   public class GreeterDialog extends JDialog {
   43       private static final long serialVersionUID = 1L;
   44       
   45       Object selection;
   46   
   47       public GreeterDialog() {
   48           super((Frame) null, "Invoke Remote Greeter Service", true);
   49           
   50           JPanel panel = new JPanel();
   51           panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));     
   52           setContentPane(panel);
   53   
   54           final JRadioButton rb1 = new JRadioButton("invoke: Map<GreetingPhrase, String> greetMe(String name);");
   55           rb1.setSelected(true);
   56           rb1.setAlignmentX(Component.LEFT_ALIGNMENT);        
   57           panel.add(rb1);
   58           
   59           final JPanel simplePanel = new JPanel(new GridBagLayout());
   60           simplePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
   61           GridBagConstraints c1 = new GridBagConstraints();
   62           
   63           rb1.addChangeListener(new ChangeListener() {
   64               public void stateChanged(ChangeEvent e) {
   65                   enablePanel(simplePanel, rb1.isSelected());
   66               }
   67           });
   68           
   69           JLabel lb1 = new JLabel("Name: ");
   70           c1.weightx = 0.0;
   71           c1.gridx = 0;
   72           c1.gridy = 0;
   73           c1.insets = new Insets(0, 25, 0, 0);
   74           c1.anchor = GridBagConstraints.LINE_START;
   75           simplePanel.add(lb1, c1);
   76           
   77           final JTextField tf1 = new JTextField(20);
   78           c1.weightx = 0.2;
   79           c1.gridx = 1;
   80           c1.gridy = 0;
   81           c1.insets = new Insets(0, 10, 0, 0);
   82           c1.anchor = GridBagConstraints.LINE_START;
   83           simplePanel.add(tf1, c1);
   84           panel.add(simplePanel);
   85   
   86           panel.add(new JLabel(" ")); // add a spacer
   87           
   88           final JRadioButton rb2 = new JRadioButton("invoke: GreetingPhrase [] greetMe(GreeterData data) throws GreeterException;");
   89           rb2.setAlignmentX(Component.LEFT_ALIGNMENT);
   90           panel.add(rb2);
   91           
   92           final JPanel complexPanel = new JPanel(new GridBagLayout());
   93           complexPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
   94           GridBagConstraints c2 = new GridBagConstraints();
   95   
   96           rb2.addChangeListener(new ChangeListener() {            
   97               public void stateChanged(ChangeEvent e) {
   98                   enablePanel(complexPanel, rb2.isSelected());
   99               }
  100           });            
  101           
  102           JLabel lb2 = new JLabel("Name: ");
  103           c2.weightx = 0.0;
  104           c2.gridx = 0;
  105           c2.gridy = 0;
  106           c2.insets = new Insets(0, 25, 0, 0);
  107           c2.anchor = GridBagConstraints.LINE_START;
  108           complexPanel.add(lb2, c2);
  109           
  110           final JTextField tf2 = new JTextField(20);
  111           c2.weightx = 0.2;
  112           c2.gridx = 1;
  113           c2.gridy = 0;
  114           c2.insets = new Insets(0, 10, 0, 0);
  115           c2.anchor = GridBagConstraints.LINE_START;
  116           complexPanel.add(tf2, c2);        
  117                   
  118           JLabel lb3 = new JLabel("Age: ");
  119           c2.weightx = 0.0;
  120           c2.gridx = 0;
  121           c2.gridy = 1;
  122           c2.insets = new Insets(0, 25, 0, 0);
  123           c2.anchor = GridBagConstraints.LINE_START;
  124           complexPanel.add(lb3, c2);
  125           
  126           final JTextField tf3 = new JTextField(7);
  127           c2.weightx = 0.2;
  128           c2.gridx = 1;
  129           c2.gridy = 1;
  130           c2.insets = new Insets(0, 10, 0, 0);
  131           c2.anchor = GridBagConstraints.LINE_START;
  132           complexPanel.add(tf3, c2);
  133           
  134           final JCheckBox cb1 = new JCheckBox("Throw Exception");
  135           c2.weightx = 0.0;
  136           c2.gridx = 0;
  137           c2.gridy = 2;
  138           c2.gridwidth = 2;
  139           c2.insets = new Insets(0, 22, 0, 0);
  140           c2.anchor = GridBagConstraints.LINE_START;
  141           complexPanel.add(cb1, c2);
  142   
  143           panel.add(complexPanel);
  144           enablePanel(complexPanel, false);
  145           
  146           JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER));        
  147           buttons.setAlignmentX(Component.LEFT_ALIGNMENT);
  148           
  149           JButton b1 = new JButton("Invoke");
  150           buttons.add(b1);
  151           
  152           b1.addActionListener(new ActionListener() {            
  153               public void actionPerformed(ActionEvent e) {
  154                   if (rb1.isSelected()) {
  155                       selection = tf1.getText();
  156                   } else {
  157                       selection = new GreeterDataImpl(tf2.getText(), new Integer(tf3.getText()), cb1.isSelected());
  158                   }                
  159                   
  160                   setVisible(false);
  161               }
  162           });
  163           
  164           panel.add(buttons);
  165           
  166           ButtonGroup bg = new ButtonGroup();
  167           bg.add(rb1);
  168           bg.add(rb2);
  169           
  170           pack();
  171           setLocationRelativeTo(null); // centers frame on screen
  172       }
  173       
  174       public Object getSelection() {
  175           return selection;
  176       }
  177       
  178       private static void enablePanel(JPanel panel, boolean b) {
  179           for (Component c : panel.getComponents()) {
  180               c.setEnabled(b);
  181           }
  182       }
  183   
  184       public static void main(String ... args) {
  185           GreeterDialog gd = new GreeterDialog();
  186           gd.setVisible(true);
  187           System.exit(0);
  188       }
  189   }

Home » cxf-dosgi-ri-source-distribution-1.1 » org.apache.cxf.dosgi.samples.greeter.client » [javadoc | source]