Clover coverage report - Graph - 1.0.0
Coverage timestamp: ven. déc. 26 2003 02:14:20 CET
file stats: LOC: 155   Methods: 5
NCLOC: 99   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
SelectGraphDialog.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * EJTools, the Enterprise Java Tools
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at www.gnu.org.
 6   
  */
 7   
 package org.ejtools.graph.dialog;
 8   
 
 9   
 import java.awt.Component;
 10   
 import java.awt.GridBagConstraints;
 11   
 import java.awt.GridBagLayout;
 12   
 import java.awt.GridLayout;
 13   
 import java.awt.Insets;
 14   
 import java.awt.event.ActionEvent;
 15   
 import java.awt.event.ActionListener;
 16   
 import java.util.ResourceBundle;
 17   
 
 18   
 import javax.swing.JButton;
 19   
 import javax.swing.JComboBox;
 20   
 import javax.swing.JDialog;
 21   
 import javax.swing.JLabel;
 22   
 import javax.swing.JPanel;
 23   
 
 24   
 /**
 25   
  * @author    Laurent Etiemble
 26   
  * @version   $Revision: 1.5 $
 27   
  */
 28   
 public class SelectGraphDialog extends JDialog
 29   
 {
 30   
    /** Description of the Field */
 31   
    protected JComboBox choices;
 32   
    /** Description of the Field */
 33   
    protected Object initialSelectionValue;
 34   
    /** Description of the Field */
 35   
    protected Object selectedValue = null;
 36   
    /** Description of the Field */
 37   
    private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.graph.GraphService");
 38   
 
 39   
 
 40   
    /**
 41   
     *Constructor for the CustomJOptionPane object
 42   
     *
 43   
     * @param parentComponent        Description of the Parameter
 44   
     * @param selectionValues        Description of the Parameter
 45   
     * @param initialSelectionValue  Description of the Parameter
 46   
     */
 47  0
    public SelectGraphDialog(Component parentComponent, Object[] selectionValues, Object initialSelectionValue)
 48   
    {
 49  0
       super();
 50  0
       this.setModal(true);
 51  0
       this.setTitle(resources.getString("graph.dialog.title"));
 52   
 
 53  0
       JPanel main = new JPanel(new GridBagLayout());
 54  0
       GridBagConstraints constraints = new GridBagConstraints();
 55  0
       constraints.insets = new Insets(5, 5, 5, 5);
 56   
 
 57  0
       constraints.gridwidth = GridBagConstraints.REMAINDER;
 58  0
       constraints.weightx = 1.0;
 59  0
       constraints.fill = GridBagConstraints.HORIZONTAL;
 60  0
       constraints.anchor = GridBagConstraints.WEST;
 61  0
       JLabel messageLabel = new JLabel(resources.getString("graph.dialog.text.description"));
 62  0
       main.add(messageLabel, constraints);
 63   
 
 64  0
       this.initialSelectionValue = initialSelectionValue;
 65   
 
 66  0
       this.choices = new JComboBox(selectionValues);
 67  0
       this.choices.setSelectedItem(this.initialSelectionValue);
 68  0
       this.choices.setEditable(true);
 69  0
       if (selectionValues.length == 0)
 70   
       {
 71  0
          choices.getEditor().setItem(this.initialSelectionValue);
 72   
       }
 73   
 
 74  0
       main.add(choices, constraints);
 75   
 
 76  0
       JPanel buttons = new JPanel(new GridLayout(1, 2, 2, 2));
 77   
 
 78  0
       JButton buttonSelect = new JButton(resources.getString("graph.dialog.button.select"));
 79  0
       buttons.add(buttonSelect);
 80  0
       buttonSelect.addActionListener(
 81   
          new ActionListener()
 82   
          {
 83   
             /**
 84   
              * @param e  Description of the Parameter
 85   
              */
 86  0
             public void actionPerformed(ActionEvent e)
 87   
             {
 88  0
                select();
 89  0
                dispose();
 90   
             }
 91   
          });
 92   
 
 93  0
       JButton buttonCancel = new JButton(resources.getString("graph.dialog.button.cancel"));
 94  0
       buttons.add(buttonCancel);
 95  0
       buttonCancel.addActionListener(
 96   
          new ActionListener()
 97   
          {
 98   
             /**
 99   
              * @param e  Description of the Parameter
 100   
              */
 101  0
             public void actionPerformed(ActionEvent e)
 102   
             {
 103  0
                selectedValue = null;
 104  0
                dispose();
 105   
             }
 106   
          });
 107   
 
 108  0
       constraints.fill = GridBagConstraints.NONE;
 109  0
       constraints.anchor = GridBagConstraints.SOUTH;
 110  0
       main.add(buttons, constraints);
 111   
 
 112  0
       this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
 113  0
       this.getContentPane().add(main);
 114  0
       this.pack();
 115  0
       this.setLocationRelativeTo(parentComponent);
 116   
    }
 117   
 
 118   
 
 119   
    /**
 120   
     * Returns the selectedValue.
 121   
     *
 122   
     * @return   Object
 123   
     */
 124  0
    public Object getSelectedValue()
 125   
    {
 126  0
       return selectedValue;
 127   
    }
 128   
 
 129   
 
 130   
    /** Description of the Method */
 131  0
    private void select()
 132   
    {
 133  0
       boolean found = false;
 134   
 
 135  0
       Object choice = this.choices.getSelectedItem();
 136  0
       Object text = this.choices.getEditor().getItem();
 137   
 
 138  0
       for (int i = 0; i < this.choices.getModel().getSize(); i++)
 139   
       {
 140  0
          choice = this.choices.getModel().getElementAt(i);
 141  0
          if (choice.toString().equals(text.toString()))
 142   
          {
 143  0
             found = true;
 144  0
             break;
 145   
          }
 146   
       }
 147  0
       if (!found)
 148   
       {
 149  0
          choice = text;
 150   
       }
 151   
 
 152  0
       this.selectedValue = choice;
 153   
    }
 154   
 }
 155