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/DCPanel.java
          +++ new/usr/src/cmd/krb5/kadmin/gui/dchanger/DCPanel.java
   1    1  /*
   2    2   * CDDL HEADER START
   3    3   *
   4    4   * The contents of this file are subject to the terms of the
   5    5   * Common Development and Distribution License, Version 1.0 only
   6    6   * (the "License").  You may not use this file except in compliance
   7    7   * with the License.
   8    8   *
   9    9   * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
  10   10   * or http://www.opensolaris.org/os/licensing.
  11   11   * See the License for the specific language governing permissions
  12   12   * and limitations under the License.
  
    | 
      ↓ open down ↓ | 
    12 lines elided | 
    
      ↑ open up ↑ | 
  
  13   13   *
  14   14   * When distributing Covered Code, include this CDDL HEADER in each
  15   15   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
  23      - * ident        "%Z%%M% %I%     %E% SMI"
  24      - *
  25   23   * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
  26   24   * All rights reserved.
  27   25   */
  28   26  
  29   27      import java.awt.*;
  30   28      import java.awt.event.*;
  31   29  
  32   30      /**
  33   31       * Creates a panel with two buttons (+ and - side by side on it). The
  34   32       * panel registers a DCListener with it that gets notified whenever
  35   33       * these butons are clicked. <bold>The buttons may also be kept continously
  36   34       * pressed for faster increments/decrements.</bold>
  37   35       * <para>
  38   36       * On a single click of the button, the listener is notified to
  39   37       * increment/decrement itself by a small amount. When the button is kept
  40   38       * pressed the following notifications are sent out for larger
  41   39       * increments/decrements. (It is up to the listener to decide the
  42   40       * increment/decrement corresponding to large/small.) Moreover, these
  43   41       * notifications will be sent out much faster if the button is kept
  44      -     * pressed. 
       42 +     * pressed.
  45   43       */
  46   44  
  47   45      // The panel waits for a period of BIG_SLEEP_TIME before the faster
  48   46      // increments are sent out. They, in turn, are sent out after
  49   47      // intervals of SMALL_SLEEP_TIME. Therfore, an instance of this class
  50   48      // is associated with 2 timers - a longer one that starts off and then
  51   49      // schedules the shorter one. The shorter one keeps scheduling itself
  52   50      // every time it wakes up.
  53   51  
  54   52      public class DCPanel extends Panel {
  55      -  
       53 +
  56   54      private Button plusButton;
  57   55      private Button minusButton;
  58      -  
       56 +
  59   57      private DCListener listener = null;
  60   58  
  61   59      private Timer bigTimer;
  62   60      private Timer smallTimer;
  63   61  
  64      -    private static int BIG_SLEEP_TIME   = 1000;
       62 +    private static int BIG_SLEEP_TIME   = 1000;
  65   63      private static int SMALL_SLEEP_TIME = 100;
  66      -  
       64 +
  67   65      private boolean incrementFlag;
  68   66  
  69   67      public DCPanel() {
  70   68  
  71   69      setLayout(new GridLayout(1, 2));
  72      -    
  73      -    bigTimer     = new BigTimer();
  74      -    smallTimer   = new SmallTimer();
  75      -    
       70 +
       71 +    bigTimer     = new BigTimer();
       72 +    smallTimer   = new SmallTimer();
       73 +
  76   74      bigTimer.start();
  77   75      smallTimer.start();
  78      -    
       76 +
  79   77      plusButton = new DCButton("+");
  80   78      minusButton = new DCButton("-");
  81   79  
  82   80      add(plusButton);
  83   81      add(minusButton);
  84   82  
  85   83      }
  86   84  
  87   85      /**
  88   86       * Ensures that this component is not brought into focus by
  89   87       * tabbing. This prevents the tab focus from moving in here instead
  90   88       * of going to a text field.
  91   89       * @return false always.
  92   90       */
  93      -    public boolean isFocusTraversable() {
       91 +    public boolean isFocusable() {
  94   92      return false;
  95   93      }
  96   94  
  97   95      /**
  98   96       * Sets the listener for this tab.
  99   97       * @param listener the DCListener that needs to be notified when the
 100   98       * buttons on this panel are pressed.
 101   99       * @return the old listener
 102  100       */
 103  101      public DCListener setListener(DCListener listener) {
 104  102      DCListener oldListener = this.listener;
 105  103      this.listener = listener;
 106  104      return oldListener;
 107  105      }
 108  106  
 109  107      /**
 110  108       * Removes the listener when it no longer need to be notified.
 111  109       * @return the old listener
 112  110       */
 113  111      public DCListener removeListener() {
 114  112      return setListener(null);
 115  113      }
 116  114  
 117  115      /**
 118  116       * Kicks the times into action. Is called when a button is pressed.
 119  117       */
 120  118      private void startAction() {
 121  119      bigTimer.request();
 122  120      }
 123  121  
 124  122      /**
 125  123       * Stops the timers. Is called when a button is released.
 126  124       */
 127  125      private void stopAction() {
 128  126      smallTimer.cancel();
 129  127      bigTimer.cancel();
 130  128      }
  
    | 
      ↓ open down ↓ | 
    27 lines elided | 
    
      ↑ open up ↑ | 
  
 131  129  
 132  130      /**
 133  131       * Notifies the listener about whether to increment or decrement and
 134  132       * by how much.
 135  133       * @param bigFlag true if the listener needs to increment/decrement
 136  134       * by a large amount, false otherwise.
 137  135       */
 138  136      private void informListener(boolean bigFlag) {
 139  137      // System.out.println("DCPanel.informListener: " + bigFlag);
 140  138  
 141      -        if (listener != null) {
      139 +        if (listener != null) {
 142  140  
 143      -            if (bigFlag) {
      141 +            if (bigFlag) {
 144  142              // request a big change
 145  143              if (incrementFlag)
 146      -                listener.bigIncrement();
 147      -            else 
 148      -                listener.bigDecrement();
 149      -            } else {
      144 +                listener.bigIncrement();
      145 +            else
      146 +                listener.bigDecrement();
      147 +            } else {
 150  148              // request a small change
 151  149              if (incrementFlag)
 152      -                listener.increment();
 153      -            else 
 154      -                listener.decrement();
 155      -            }
      150 +                listener.increment();
      151 +            else
      152 +                listener.decrement();
      153 +            }
 156  154  
 157      -        }
 158      -      
      155 +        }
      156 +
 159  157      } // informListener
 160  158  
 161  159  
 162  160      // ***********************************************
 163      -    //   I N N E R    C L A S S E S   F O L L O W
      161 +    //   I N N E R    C L A S S E S   F O L L O W
 164  162      // ***********************************************
 165  163  
 166  164      /**
 167  165       * A timer class since java does not have one.
 168  166       */
 169  167      private abstract class Timer extends Thread {
 170  168      private boolean running = false;
 171  169  
 172  170      /**
 173  171       * Sleeps till the timer's services are requested using wait() and
 174  172       * notify(). Then it does its task and goes back to sleep. And
 175  173       * loops forever like this.
 176  174       */
 177  175      public void run() {
 178      -        while (true) {
      176 +        while (true) {
 179  177          try {
 180  178            synchronized (this) {
 181  179              running = false;
 182  180              // Wait till the timer is required
 183  181              wait();
 184  182              running = true;
 185  183            }
 186  184            doTask();
 187  185          } catch (InterruptedException e) {}
 188      -        } // while loop
      186 +        } // while loop
 189  187      } // run method
 190  188  
 191  189      protected void doTask() {} // bug in java workshop
 192  190  
 193  191      /**
 194  192       * Wakes up the timer.
 195  193       */
 196  194      public synchronized void request() {
 197      -        notify();
      195 +        notify();
 198  196      }
 199  197  
 200  198      /**
 201  199       * Cancels the timer if it is running.
 202  200       */
 203  201      public void cancel() {
 204      -        if (running) {
      202 +        if (running) {
 205  203          interrupt();
 206      -        }
      204 +        }
 207  205      }
 208  206  
 209  207      }// class Timer
 210  208  
 211  209      /**
 212  210       * The first stage of timer - is a longer timer. Wait to see if the
 213  211       * user really wants to amek the increments/decrements go by fast.
 214  212       */
 215  213      private class BigTimer extends Timer {
 216  214  
 217  215      /**
 218  216       * Sleep for the long amount of time. Then inform the listener
 219  217       * to have a bigIncrement/bigDecrement. After that, your job is
 220  218       * done, schedule the smaller (faster) timer from this point on.
 221  219       */
 222  220      protected void doTask() {
 223      -        try {
      221 +        try {
 224  222          sleep(BIG_SLEEP_TIME);
 225  223          informListener(true);
 226  224          smallTimer.request();
 227      -        } catch (InterruptedException e) {
      225 +        } catch (InterruptedException e) {
 228  226          informListener(false);
 229      -        }
      227 +        }
 230  228      }
 231  229  
 232  230      } // class BigTimer
 233  231  
 234  232  
 235  233      /**
 236  234       * The second stage of timers. This timer keeps rescheduling itself
 237  235       * everytime it wakes up. In between this, it sends a notification
 238  236       * to the listener to do a big Increment/Decrement.
 239  237       */
 240  238      private class SmallTimer extends Timer {
 241  239  
 242  240      protected void doTask() {
 243      -        try {
      241 +        try {
 244  242          // loop forever and keep rescheduling yourself
 245  243          while (true) {
 246  244            sleep(SMALL_SLEEP_TIME);
 247  245            informListener(true);
 248  246              }
 249      -        } catch (InterruptedException e) {}
      247 +        } catch (InterruptedException e) {}
 250  248      } // doTask method
 251  249  
 252  250      } // class SmallTimer
 253  251  
 254  252      /**
 255  253       * A mouse listener to detect when a button has been
 256  254       * pressed/released. One instance of this is bound to the plus
 257  255       * button and the other instance to the minus button.
 258  256       */
 259  257      private class DCMouseListener extends MouseAdapter {
 260  258      private boolean plusOrMinus;
 261  259  
 262  260      /**
 263  261       * Constructor for DCMouseListener.
 264  262       * @param plusOrMinus true if this is a listener for the plus
 265      -     *     button, false if it is for the minus button.
      263 +     *     button, false if it is for the minus button.
 266  264       */
 267  265      public DCMouseListener(boolean plusOrMinus) {
 268      -        this.plusOrMinus = plusOrMinus;
      266 +        this.plusOrMinus = plusOrMinus;
 269  267      }
 270  268  
 271  269      /**
 272  270       * Kicks in when the mouse is pressed.
 273  271       */
 274  272      public void mousePressed(MouseEvent e) {
 275      -        incrementFlag = plusOrMinus;
 276      -        DCPanel.this.startAction();
      273 +        incrementFlag = plusOrMinus;
      274 +        DCPanel.this.startAction();
 277  275      }
 278  276  
 279  277      /**
 280  278       * Kicks in when the mouse is released.
 281  279       */
 282  280      public void mouseReleased(MouseEvent e) {
 283      -        incrementFlag = plusOrMinus;
 284      -        DCPanel.this.stopAction();
 285      -        }
 286      -    } 
      281 +        incrementFlag = plusOrMinus;
      282 +        DCPanel.this.stopAction();
      283 +        }
      284 +    }
 287  285  
 288  286      /**
 289  287       * The button used by this DCPanel.
 290      -     */  
      288 +     */
 291  289      private class DCButton extends Button {
 292  290      public DCButton(String text) {
 293      -        super(text);
 294      -        if (text.equals("+"))
 295      -           addMouseListener(new DCMouseListener(true));
 296      -        else
 297      -        addMouseListener(new DCMouseListener(false));
      291 +        super(text);
      292 +        if (text.equals("+"))
      293 +           addMouseListener(new DCMouseListener(true));
      294 +        else
      295 +        addMouseListener(new DCMouseListener(false));
 298  296      }
 299  297  
 300  298      /**
 301  299       * Make the button non-focus traversable so that it cannot be
 302  300       * tabbed in to.
 303  301       */
 304      -    public boolean isFocusTraversable() {
 305      -        return false;
      302 +    public boolean isFocusable() {
      303 +        return false;
 306  304      }
 307  305  
 308  306      } // DCButton
 309  307  
 310  308  
 311  309      /**
 312  310       * Test method for DCPanel class to see appearance.
 313  311       */
 314  312      public static void main(String args[]) {
 315  313      Frame f = new Frame("Testing DCPanel");
 316  314      f.add(new DCPanel());
 317  315      f.setBounds(new Rectangle(100, 100, 100, 100));
 318  316      f.setVisible(true);
 319  317      }
 320      -  
      318 +
 321  319  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX