home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161a.iso / handson / files / copyjava.exe / com / sun / java / swing / plaf / basic / Spinner.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-02-26  |  6.8 KB  |  352 lines

  1. package com.sun.java.swing.plaf.basic;
  2.  
  3. import com.sun.java.swing.JComponent;
  4. import com.sun.java.swing.UIManager;
  5. import com.sun.java.swing.plaf.SpinnerUI;
  6. import java.awt.Adjustable;
  7. import java.awt.Color;
  8. import java.awt.Component;
  9. import java.awt.Container;
  10. import java.awt.Dimension;
  11. import java.awt.Font;
  12. import java.awt.FontMetrics;
  13. import java.awt.Graphics;
  14. import java.awt.event.AdjustmentEvent;
  15. import java.awt.event.AdjustmentListener;
  16. import java.awt.event.FocusEvent;
  17. import java.awt.event.FocusListener;
  18. import java.awt.event.KeyEvent;
  19. import java.awt.event.KeyListener;
  20. import java.awt.event.MouseEvent;
  21. import java.awt.event.MouseListener;
  22.  
  23. public class Spinner extends JComponent implements Adjustable, AdjustmentListener, FocusListener, KeyListener, MouseListener {
  24.    protected String txt;
  25.    // $FF: renamed from: d java.awt.Dimension
  26.    protected Dimension field_0;
  27.    protected int ascent;
  28.    protected int value;
  29.    protected boolean haveFocus = false;
  30.    protected int minValue;
  31.    protected int maxValue = 8388607;
  32.    // $FF: renamed from: fm java.awt.FontMetrics
  33.    protected FontMetrics field_1;
  34.    protected int nDigits = 4;
  35.    protected int digitsTyped;
  36.    protected boolean wraps = false;
  37.    protected boolean borderPainted = false;
  38.    protected Color backgroundColor;
  39.    protected int leadingPad;
  40.    public boolean wrapped;
  41.    // $FF: synthetic field
  42.    static Class class$java$awt$event$AdjustmentListener;
  43.  
  44.    public Spinner(int var1, String var2) {
  45.       this.backgroundColor = Color.white;
  46.       this.leadingPad = -1;
  47.       this.wrapped = false;
  48.       this.init(var1, var2);
  49.    }
  50.  
  51.    public Spinner(int var1) {
  52.       this.backgroundColor = Color.white;
  53.       this.leadingPad = -1;
  54.       this.wrapped = false;
  55.       this.init(var1, (String)null);
  56.    }
  57.  
  58.    private void init(int var1, String var2) {
  59.       this.txt = var2;
  60.       this.value = var1;
  61.       ((Component)this).addFocusListener(this);
  62.       ((Component)this).addMouseListener(this);
  63.       ((Component)this).addKeyListener(this);
  64.       this.updateUI();
  65.    }
  66.  
  67.    public int getValue() {
  68.       return this.value;
  69.    }
  70.  
  71.    public void setValue(int var1) {
  72.       if (this.wraps) {
  73.          if (var1 >= this.minValue && var1 <= this.maxValue) {
  74.             this.wrapped = false;
  75.          } else {
  76.             this.wrapped = true;
  77.          }
  78.       }
  79.  
  80.       while(var1 < this.minValue) {
  81.          if (this.wraps) {
  82.             var1 += this.maxValue + 1 - this.minValue;
  83.          } else {
  84.             var1 = this.minValue;
  85.          }
  86.       }
  87.  
  88.       while(var1 > this.maxValue) {
  89.          if (this.wraps) {
  90.             var1 = this.minValue - 1 + var1 - this.maxValue;
  91.          } else {
  92.             var1 = this.maxValue;
  93.          }
  94.       }
  95.  
  96.       if (this.value != var1) {
  97.          this.value = var1;
  98.          if (((Component)this).isShowing()) {
  99.             ((Component)this).repaint(20L);
  100.          }
  101.  
  102.          this.fireAdjustmentValueChanged(new AdjustmentEvent(this, 0, 601, var1));
  103.       }
  104.  
  105.    }
  106.  
  107.    public void setWrap(boolean var1) {
  108.       this.wraps = var1;
  109.    }
  110.  
  111.    public boolean getWrap() {
  112.       return this.wraps;
  113.    }
  114.  
  115.    public void setText(String var1) {
  116.       this.txt = var1;
  117.       if (((Component)this).isShowing()) {
  118.          ((Component)this).repaint(20L);
  119.       }
  120.  
  121.    }
  122.  
  123.    public String getText() {
  124.       return this.txt;
  125.    }
  126.  
  127.    public void setFont(Font var1) {
  128.       if (var1 != ((Component)this).getFont()) {
  129.          super.setFont(var1);
  130.          this.field_0 = null;
  131.          ((Container)this).invalidate();
  132.       }
  133.  
  134.    }
  135.  
  136.    public void setDigits(int var1) {
  137.       this.nDigits = var1;
  138.    }
  139.  
  140.    public int getDigits() {
  141.       return this.nDigits;
  142.    }
  143.  
  144.    public void setLeadingPad(int var1) {
  145.       this.leadingPad = var1;
  146.    }
  147.  
  148.    public int getLeadingPad() {
  149.       return this.leadingPad;
  150.    }
  151.  
  152.    public void setBackgroundColor(Color var1) {
  153.       this.backgroundColor = var1;
  154.    }
  155.  
  156.    public Color getBackgroundColor() {
  157.       return this.backgroundColor;
  158.    }
  159.  
  160.    public boolean isFocusTraversable() {
  161.       return true;
  162.    }
  163.  
  164.    public boolean hasFocus() {
  165.       return this.haveFocus;
  166.    }
  167.  
  168.    public boolean isBorderPainted() {
  169.       return this.borderPainted;
  170.    }
  171.  
  172.    public void setBorderPainted(boolean var1) {
  173.       this.borderPainted = var1;
  174.       ((Container)this).invalidate();
  175.    }
  176.  
  177.    protected void paintBorder(Graphics var1) {
  178.       if (this.isBorderPainted()) {
  179.          super.paintBorder(var1);
  180.       }
  181.  
  182.    }
  183.  
  184.    public void adjustmentValueChanged(AdjustmentEvent var1) {
  185.       this.setValue(var1.getValue());
  186.    }
  187.  
  188.    public void setMinimum(int var1) {
  189.       this.minValue = var1;
  190.       this.setValue(this.value);
  191.    }
  192.  
  193.    public int getMinimum() {
  194.       return this.minValue;
  195.    }
  196.  
  197.    public void setMaximum(int var1) {
  198.       this.maxValue = var1;
  199.       this.setValue(this.value);
  200.    }
  201.  
  202.    public int getMaximum() {
  203.       return this.maxValue;
  204.    }
  205.  
  206.    public void addAdjustmentListener(AdjustmentListener var1) {
  207.       super.listenerList.add(class$java$awt$event$AdjustmentListener != null ? class$java$awt$event$AdjustmentListener : (class$java$awt$event$AdjustmentListener = class$("java.awt.event.AdjustmentListener")), var1);
  208.    }
  209.  
  210.    public void removeAdjustmentListener(AdjustmentListener var1) {
  211.       super.listenerList.remove(class$java$awt$event$AdjustmentListener != null ? class$java$awt$event$AdjustmentListener : (class$java$awt$event$AdjustmentListener = class$("java.awt.event.AdjustmentListener")), var1);
  212.    }
  213.  
  214.    protected void fireAdjustmentValueChanged(AdjustmentEvent var1) {
  215.       Object[] var2 = super.listenerList.getListenerList();
  216.  
  217.       for(int var3 = var2.length - 2; var3 >= 0; var3 -= 2) {
  218.          if (var2[var3] == (class$java$awt$event$AdjustmentListener != null ? class$java$awt$event$AdjustmentListener : (class$java$awt$event$AdjustmentListener = class$("java.awt.event.AdjustmentListener")))) {
  219.             ((AdjustmentListener)var2[var3 + 1]).adjustmentValueChanged(var1);
  220.          }
  221.       }
  222.  
  223.    }
  224.  
  225.    public void setUnitIncrement(int var1) {
  226.    }
  227.  
  228.    public int getUnitIncrement() {
  229.       return 1;
  230.    }
  231.  
  232.    public void setBlockIncrement(int var1) {
  233.    }
  234.  
  235.    public int getBlockIncrement() {
  236.       return 1;
  237.    }
  238.  
  239.    public void setVisibleAmount(int var1) {
  240.    }
  241.  
  242.    public int getVisibleAmount() {
  243.       return 1;
  244.    }
  245.  
  246.    public int getOrientation() {
  247.       return 0;
  248.    }
  249.  
  250.    public void keyTyped(KeyEvent var1) {
  251.    }
  252.  
  253.    public void keyPressed(KeyEvent var1) {
  254.       if (var1.isActionKey()) {
  255.          switch (var1.getKeyCode()) {
  256.             case 38:
  257.                this.setValue(this.value + 1);
  258.                return;
  259.             case 39:
  260.             default:
  261.                break;
  262.             case 40:
  263.                this.setValue(this.value - 1);
  264.                return;
  265.          }
  266.       } else {
  267.          char var2 = var1.getKeyChar();
  268.          if (var2 >= '0' && var2 <= '9') {
  269.             if (this.digitsTyped < this.nDigits) {
  270.                if (this.digitsTyped == 0) {
  271.                   this.value = 0;
  272.                }
  273.  
  274.                int var3 = this.value * 10 + var2 - 48;
  275.                if (var3 <= this.maxValue && var3 >= this.minValue) {
  276.                   this.setValue(var3);
  277.                   ++this.digitsTyped;
  278.                   return;
  279.                }
  280.             }
  281.          } else {
  282.             switch (var2) {
  283.                case '\b':
  284.                case '\u007f':
  285.                   this.setValue(this.value / 10);
  286.                   --this.digitsTyped;
  287.                   return;
  288.                case '-':
  289.                   this.setValue(-this.value);
  290.                   return;
  291.             }
  292.          }
  293.       }
  294.  
  295.    }
  296.  
  297.    public void keyReleased(KeyEvent var1) {
  298.    }
  299.  
  300.    public void mouseClicked(MouseEvent var1) {
  301.    }
  302.  
  303.    public void mousePressed(MouseEvent var1) {
  304.       ((JComponent)this).requestFocus();
  305.    }
  306.  
  307.    public void mouseReleased(MouseEvent var1) {
  308.    }
  309.  
  310.    public void mouseEntered(MouseEvent var1) {
  311.    }
  312.  
  313.    public void mouseExited(MouseEvent var1) {
  314.    }
  315.  
  316.    public void focusGained(FocusEvent var1) {
  317.       this.haveFocus = true;
  318.       this.digitsTyped = 0;
  319.       ((Component)this).repaint();
  320.    }
  321.  
  322.    public void focusLost(FocusEvent var1) {
  323.       this.haveFocus = false;
  324.       ((Component)this).repaint();
  325.    }
  326.  
  327.    public SpinnerUI getUI() {
  328.       return (SpinnerUI)super.ui;
  329.    }
  330.  
  331.    public void setUI(SpinnerUI var1) {
  332.       super.setUI(var1);
  333.    }
  334.  
  335.    public void updateUI() {
  336.       this.setUI((SpinnerUI)UIManager.getUI(this));
  337.    }
  338.  
  339.    public String getUIClassID() {
  340.       return "SpinnerUI";
  341.    }
  342.  
  343.    // $FF: synthetic method
  344.    static Class class$(String var0) {
  345.       try {
  346.          return Class.forName(var0);
  347.       } catch (ClassNotFoundException var2) {
  348.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  349.       }
  350.    }
  351. }
  352.