Print this page
    
4719 update gate build environment to [open]jdk7 4742 update manifests for javadoc7 4743 Fix deprecated /usr/j2se usage in slp and remove from filesystem(5) manpage 4744 remove traces of /var/sadm/system/admin/default_java Reviewed by: Dan McDonald <danmcd@omniti.com> Reviewed by: Richard Lowe <richlowe@richlowe.net>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/cmd/krb5/kadmin/gui/dchanger/EncListDialog.java
          +++ new/usr/src/cmd/krb5/kadmin/gui/dchanger/EncListDialog.java
   1    1  /*
   2    2   * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
   3    3   * Use is subject to license terms.
   4      - *
   5      - * ident        "%Z%%M% %I%     %E% SMI"
   6    4   */
   7    5  
   8    6  import java.awt.*;
   9    7  import java.awt.event.*;
  10    8  import java.text.*;
  11    9  import java.util.*;
  12   10  
  13   11  /*
  14   12   * This class creates a dialog box that helps the user select encryption types
  15   13   * with some mouse clicks.  The dialog box need only be created
  16   14   * once. The Ok and Cancel buttons merely call setVisible with an
  17   15   * argument of false.
  18   16   */
  19   17  
  20   18  // The layout will consist of 2 panels:
  21   19  // topPanel contains the dynamic list of encryption type check boxes.
  22   20  // bottomPanel contains the buttons ok, clear, cancel, and help.
  23   21  // The two panels are separated by a LineSeparator.
  24   22  
  25   23  public class EncListDialog extends Dialog {
  26   24  
  27   25          private boolean save;
  28   26  
  29   27          private int i;
  30   28  
  31   29          private Frame parent;
  32   30  
  33   31          private Button ok;
  34   32          private Button clear;
  35   33          private Button cancel;
  36   34          private Button help;
  37   35  
  38   36          private HelpDialog hd = null;
  39   37  
  40   38          private Panel topPanel;
  41   39          private Panel bottomPanel;
  
    | 
      ↓ open down ↓ | 
    26 lines elided | 
    
      ↑ open up ↑ | 
  
  42   40  
  43   41          private static Toolkit toolkit = Toolkit.getDefaultToolkit();
  44   42  
  45   43          private Kadmin kadmin;
  46   44          private Checkbox cb[];
  47   45          private Integer grp_num[];
  48   46          private String encList = "";
  49   47  
  50   48          // For I18N
  51   49          private static ResourceBundle rb =
  52      -            ResourceBundle.getBundle("GuiResource" /* NOI18N */); 
       50 +            ResourceBundle.getBundle("GuiResource" /* NOI18N */);
  53   51          private static ResourceBundle hrb =
  54      -            ResourceBundle.getBundle("HelpData" /* NOI18N */); 
       52 +            ResourceBundle.getBundle("HelpData" /* NOI18N */);
  55   53  
  56   54          /*
  57   55           * Constructor that lays out the components and sets the different
  58      -         * event handlers. 
       56 +         * event handlers.
  59   57           */
  60   58          public EncListDialog(Frame parent, Color background, Color foreground,
  61   59              Kadmin session) {
  62   60                  super(parent, getString("SEAM Encryption Type List Helper"),
  63   61                      true);
  64   62  
  65   63                  this.parent = parent;
  66   64  
  67   65                  this.kadmin = session;
  68   66  
  69   67                  setLayout(new GridBagLayout());
  70   68                  addCheckboxes();
  71   69  
  72   70                  addButtons();
  73   71                  setSize(250, 300);
  74   72                  setResizable(true);
  75   73  
  76   74                  addWindowListener(new DCWindowListener());
  77   75          }
  78   76  
  79   77          /*
  80   78           * Adds the check boxes only
  81   79           */
  82   80          private void addCheckboxes() {
  83   81  
  84   82                  GridBagConstraints gbc = new GridBagConstraints();
  85   83  
  86   84                  gbc.weighty = 1;
  87   85  
  88   86                  topPanel = new Panel();
  89   87                  topPanel.setLayout(new GridBagLayout());
  90   88                  gbc.gridwidth = GridBagConstraints.REMAINDER;
  91   89                  gbc.fill = GridBagConstraints.BOTH;
  92   90                  gbc.anchor = GridBagConstraints.CENTER;
  93   91                  gbc.gridx = 0;
  94   92                  gbc.gridy = 0;
  95   93                  add(topPanel, gbc);
  96   94  
  97   95                  gbc.fill = GridBagConstraints.NONE;
  98   96                  gbc.anchor = GridBagConstraints.WEST;
  99   97                  gbc.gridx = 0;
 100   98                  gbc.gridwidth = 1;
 101   99  
 102  100                  String et[] = kadmin.getEncList();
 103  101  
 104  102                  cb = new Checkbox[et.length];
 105  103                  grp_num = new Integer[et.length];
 106  104  
 107  105                  for (int i = 0; i < et.length; i++) {
 108  106                          String[] grp_enc = et[i].split(" ");
 109  107                          cb[i] = new Checkbox(grp_enc[1]);
 110  108                          CBListener cbl = new CBListener();
 111  109                          cb[i].addItemListener(cbl);
 112  110                          grp_num[i] = new Integer(grp_enc[0]);
 113  111                          gbc.gridy = i;
 114  112                          topPanel.add(cb[i], gbc);
 115  113                  }
 116  114          }
 117  115  
 118  116          // Adds all the buttons
 119  117          private void addButtons() {
 120  118  
 121  119                  GridBagConstraints gbc = new GridBagConstraints();
 122  120                  gbc.weighty = 1;
 123  121  
 124  122                  gbc.gridwidth = GridBagConstraints.REMAINDER;
 125  123                  gbc.gridheight = 1;
 126  124                  gbc.fill = GridBagConstraints.BOTH;
 127  125                  gbc.gridx = 0;
 128  126                  gbc.gridy = 2;
 129  127                  add(new LineSeparator(), gbc);
 130  128  
 131  129                  bottomPanel = new Panel();
 132  130                  ok = new Button(getString("OK"));
 133  131                  clear = new Button(getString("Clear"));
 134  132                  cancel = new Button(getString("Cancel"));
 135  133                  help = new Button(getString("Help"));
 136  134                  bottomPanel.add(ok);
 137  135                  bottomPanel.add(clear);
 138  136                  bottomPanel.add(cancel);
 139  137                  bottomPanel.add(help);
 140  138                  gbc.fill = GridBagConstraints.HORIZONTAL;
 141  139                  gbc.gridwidth = GridBagConstraints.REMAINDER;
 142  140                  gbc.gridx = 0;
 143  141                  gbc.gridy = 3;
 144  142                  add(bottomPanel, gbc);
 145  143  
 146  144                  DCButtonListener bl = new DCButtonListener();
  
    | 
      ↓ open down ↓ | 
    78 lines elided | 
    
      ↑ open up ↑ | 
  
 147  145                  ok.addActionListener(bl);
 148  146                  clear.addActionListener(bl);
 149  147                  cancel.addActionListener(bl);
 150  148                  help.addActionListener(bl);
 151  149          }
 152  150  
 153  151          /*
 154  152           * Closes (hides) the dialog box when the user is done
 155  153           * @param save true if the box is being dismissed by clicking on
 156  154           * "ok" and the user wants to retain the modified value, false
 157      -         * otherwise. 
      155 +         * otherwise.
 158  156           */
 159  157          private void encListDialogClose(boolean save) {
 160  158                  this.save = save;
 161  159                  setVisible(false);
 162  160          }
 163  161  
 164  162          /*
 165  163           * Checks if the user requested that the value in this
 166  164           * EncListDialog be used e.g., by clicking on "Ok" instead of
 167  165           * "Cancel."
 168  166           * @return true if the user wants to save the value in the
 169  167           * EncListDialog, false otherwise.
 170  168           */
 171  169  
 172  170          public boolean isSaved() {
 173  171                  return save;
 174  172          }
 175  173          /*
 176  174           * Sets the current enc list for the principal during modification.
 177  175           * @param enc types of current principal.
 178  176           */
 179  177          public void setEncTypes(String e_str) {
 180  178  
 181  179                  if (e_str.compareTo("") == 0)
 182  180                          return;
 183  181  
 184  182                  String[] e_list = e_str.split(" ");
 185  183  
 186  184                  for (int i = 0; i < e_list.length; i++) {
 187  185                          for (int j = 0; j < cb.length; j++) {
  
    | 
      ↓ open down ↓ | 
    20 lines elided | 
    
      ↑ open up ↑ | 
  
 188  186                                  if (cb[j].getLabel().compareTo(e_list[i])
 189  187                                      == 0) {
 190  188                                          cb[j].setState(true);
 191  189                                          break;
 192  190                                  }
 193  191                          }
 194  192                  }
 195  193          }
 196  194  
 197  195          // ***********************************************
 198      -        //       I N N E R    C L A S S E S   F O L L O W
      196 +        //       I N N E R    C L A S S E S   F O L L O W
 199  197          // ***********************************************
 200  198  
 201  199          /*
 202  200           * Listener for an annoying work around in deselection of a check box
 203  201           * in case the user doesn't want any items in a grouped list.
 204  202           */
 205  203          private class CBListener implements ItemListener {
 206  204  
 207  205                  public void itemStateChanged(ItemEvent e) {
 208  206                          Checkbox c = (Checkbox) e.getItemSelectable();
 209  207  
 210  208                          if (e.getStateChange() == e.DESELECTED) {
 211  209                                  c.setState(false);
 212  210                          } else if (e.getStateChange() == e.SELECTED) {
 213  211                                  for (int i = 0; i < cb.length; i++) {
 214  212                                      if (c == cb[i]) {
 215  213                                          for (int j = 0; j < cb.length; j++) {
 216  214                                              if (grp_num[j].equals(grp_num[i])
 217  215                                                  == true) {
 218  216                                                  cb[j].setState(false);
 219  217                                              }
 220  218                                          }
 221  219                                          break;
 222  220                                      }
 223  221                                  }
 224  222                                  c.setState(true);
 225  223                          // else what else is there
 226  224                          }
 227  225                  }
 228  226          }
 229  227  
 230  228          /*
 231  229           * Listener for closing the dialog box through the window close
 232  230           * menu.
 233  231           */
 234  232          private class DCWindowListener extends WindowAdapter {
 235  233  
 236  234                  public void windowClosing(WindowEvent e) {
 237  235                          encListDialogClose(false);
 238  236                  }
 239  237          }
 240  238  
 241  239          /*
 242  240           * Listener for all the buttons. The listener is shared for the sake
 243  241           * of reducing the number of overall listeners.
 244  242           * TBD: I18N the help
 245  243           */
 246  244          private class DCButtonListener implements ActionListener {
 247  245  
 248  246                  public void actionPerformed(ActionEvent e) {
  
    | 
      ↓ open down ↓ | 
    40 lines elided | 
    
      ↑ open up ↑ | 
  
 249  247                          if (e.getSource() == ok) {
 250  248                                  EncListDialog.this.encListDialogClose(true);
 251  249                          } else if (e.getSource() == cancel) {
 252  250                                  EncListDialog.this.encListDialogClose(false);
 253  251                          } else if (e.getSource() == clear) {
 254  252                                  for (int i = 0; i < cb.length; i++) {
 255  253                                          cb[i].setState(false);
 256  254                                  }
 257  255                          } else if (e.getSource() == help) {
 258  256                                  if (hd != null)
 259      -                                        hd.show();
      257 +                                        hd.setVisible(true);
 260  258                                  else {
 261  259                                          hd = new HelpDialog(
 262  260                                              EncListDialog.this.parent,
 263      -                                            getString(
      261 +                                            getString(
 264  262                                              "Help for Encryption Type Dialog"),
 265      -                                            false);
      263 +                                            false);
 266  264                                          hd.setVisible(true);
 267  265                                          hd.setText(getString(hrb,
 268      -                                             "EncryptionTypeDialogHelp"));
      266 +                                            "EncryptionTypeDialogHelp"));
 269  267                                  }
 270  268                          }
 271  269                  } // actionPerformed
 272  270          }
 273  271  
 274  272          /*
 275  273           * The string representation of the dialog box.
 276  274           * @return a String which contians the encryption type list
 277  275           */
 278  276          public String toString() {
 279  277  
 280  278                  for (int i = 0; i < cb.length; i++) {
 281  279                          if (cb[i].getState() == true)
 282  280                                  encList = encList.concat(cb[i].getLabel() +
 283  281                                      " ");
 284  282                  }
 285  283                  return encList;
 286  284          }
 287  285  
 288  286          /*
 289  287           * Call rb.getString(), but catch exception and return English
 290  288           * key so that small spelling errors don't cripple the GUI
 291  289           */
 292  290          private static final String getString(String key) {
 293  291                  return (getString(rb, key));
 294  292          }
 295  293  
 296  294          private static final String getString(ResourceBundle rb, String key) {
 297  295                  try {
 298  296                          String res = rb.getString(key);
 299  297                          return res;
 300  298                  } catch (MissingResourceException e) {
 301  299                          System.out.println("Missing resource "+key+
 302  300                              ", using English.");
 303  301                          return key;
 304  302                  }
 305  303          }
 306  304  }
  
    | 
      ↓ open down ↓ | 
    28 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX