home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / javax / swing / JProgressBar.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  6.7 KB  |  304 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Graphics;
  4. import java.io.IOException;
  5. import java.io.ObjectOutputStream;
  6. import java.text.Format;
  7. import java.text.NumberFormat;
  8. import javax.accessibility.Accessible;
  9. import javax.accessibility.AccessibleContext;
  10. import javax.accessibility.AccessibleState;
  11. import javax.swing.event.ChangeEvent;
  12. import javax.swing.event.ChangeListener;
  13. import javax.swing.plaf.ProgressBarUI;
  14.  
  15. public class JProgressBar extends JComponent implements SwingConstants, Accessible {
  16.    private static final String uiClassID = "ProgressBarUI";
  17.    protected int orientation;
  18.    protected boolean paintBorder;
  19.    protected BoundedRangeModel model;
  20.    protected String progressString;
  21.    protected boolean paintString;
  22.    private static final int defaultMinimum = 0;
  23.    private static final int defaultMaximum = 100;
  24.    private static final int defaultOrientation = 0;
  25.    protected transient ChangeEvent changeEvent;
  26.    protected ChangeListener changeListener;
  27.    private transient Format format;
  28.    private boolean indeterminate;
  29.  
  30.    public JProgressBar() {
  31.       this(0);
  32.    }
  33.  
  34.    public JProgressBar(int var1) {
  35.       this(var1, 0, 100);
  36.    }
  37.  
  38.    public JProgressBar(int var1, int var2) {
  39.       this(0, var1, var2);
  40.    }
  41.  
  42.    public JProgressBar(int var1, int var2, int var3) {
  43.       this.changeEvent = null;
  44.       this.changeListener = null;
  45.       this.setModel(new DefaultBoundedRangeModel(var2, 0, var2, var3));
  46.       this.updateUI();
  47.       this.setOrientation(var1);
  48.       this.setBorderPainted(true);
  49.       this.setStringPainted(false);
  50.       this.setString((String)null);
  51.       this.setIndeterminate(false);
  52.    }
  53.  
  54.    public JProgressBar(BoundedRangeModel var1) {
  55.       this.changeEvent = null;
  56.       this.changeListener = null;
  57.       this.setModel(var1);
  58.       this.updateUI();
  59.       this.setOrientation(0);
  60.       this.setBorderPainted(true);
  61.       this.setStringPainted(false);
  62.       this.setString((String)null);
  63.       this.setIndeterminate(false);
  64.    }
  65.  
  66.    public int getOrientation() {
  67.       return this.orientation;
  68.    }
  69.  
  70.    public void setOrientation(int var1) {
  71.       if (this.orientation != var1) {
  72.          switch (var1) {
  73.             case 0:
  74.             case 1:
  75.                int var2 = this.orientation;
  76.                this.orientation = var1;
  77.                this.firePropertyChange("orientation", var2, var1);
  78.                if (this.accessibleContext != null) {
  79.                   this.accessibleContext.firePropertyChange("AccessibleState", var2 == 1 ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL, this.orientation == 1 ? AccessibleState.VERTICAL : AccessibleState.HORIZONTAL);
  80.                }
  81.  
  82.                this.revalidate();
  83.                break;
  84.             default:
  85.                throw new IllegalArgumentException(var1 + " is not a legal orientation");
  86.          }
  87.       }
  88.  
  89.    }
  90.  
  91.    public boolean isStringPainted() {
  92.       return this.paintString;
  93.    }
  94.  
  95.    public void setStringPainted(boolean var1) {
  96.       boolean var2 = this.paintString;
  97.       this.paintString = var1;
  98.       this.firePropertyChange("stringPainted", var2, this.paintString);
  99.       if (this.paintString != var2) {
  100.          this.revalidate();
  101.          this.repaint();
  102.       }
  103.  
  104.    }
  105.  
  106.    public String getString() {
  107.       if (this.progressString != null) {
  108.          return this.progressString;
  109.       } else {
  110.          if (this.format == null) {
  111.             this.format = NumberFormat.getPercentInstance();
  112.          }
  113.  
  114.          return this.format.format(new Double(this.getPercentComplete()));
  115.       }
  116.    }
  117.  
  118.    public void setString(String var1) {
  119.       String var2 = this.progressString;
  120.       this.progressString = var1;
  121.       this.firePropertyChange("string", var2, this.progressString);
  122.       if (this.progressString == null || var2 == null || !this.progressString.equals(var2)) {
  123.          this.repaint();
  124.       }
  125.  
  126.    }
  127.  
  128.    public double getPercentComplete() {
  129.       long var1 = (long)(this.model.getMaximum() - this.model.getMinimum());
  130.       double var3 = (double)this.model.getValue();
  131.       double var5 = (var3 - (double)this.model.getMinimum()) / (double)var1;
  132.       return var5;
  133.    }
  134.  
  135.    public boolean isBorderPainted() {
  136.       return this.paintBorder;
  137.    }
  138.  
  139.    public void setBorderPainted(boolean var1) {
  140.       boolean var2 = this.paintBorder;
  141.       this.paintBorder = var1;
  142.       this.firePropertyChange("borderPainted", var2, this.paintBorder);
  143.       if (this.paintBorder != var2) {
  144.          this.repaint();
  145.       }
  146.  
  147.    }
  148.  
  149.    protected void paintBorder(Graphics var1) {
  150.       if (this.isBorderPainted()) {
  151.          super.paintBorder(var1);
  152.       }
  153.  
  154.    }
  155.  
  156.    public ProgressBarUI getUI() {
  157.       return (ProgressBarUI)this.ui;
  158.    }
  159.  
  160.    public void setUI(ProgressBarUI var1) {
  161.       super.setUI(var1);
  162.    }
  163.  
  164.    public void updateUI() {
  165.       this.setUI((ProgressBarUI)UIManager.getUI(this));
  166.    }
  167.  
  168.    public String getUIClassID() {
  169.       return "ProgressBarUI";
  170.    }
  171.  
  172.    protected ChangeListener createChangeListener() {
  173.       return new ModelListener(this, (1)null);
  174.    }
  175.  
  176.    public void addChangeListener(ChangeListener var1) {
  177.       this.listenerList.add(ChangeListener.class, var1);
  178.    }
  179.  
  180.    public void removeChangeListener(ChangeListener var1) {
  181.       this.listenerList.remove(ChangeListener.class, var1);
  182.    }
  183.  
  184.    public ChangeListener[] getChangeListeners() {
  185.       return (ChangeListener[])this.listenerList.getListeners(ChangeListener.class);
  186.    }
  187.  
  188.    protected void fireStateChanged() {
  189.       Object[] var1 = this.listenerList.getListenerList();
  190.  
  191.       for(int var2 = var1.length - 2; var2 >= 0; var2 -= 2) {
  192.          if (var1[var2] == ChangeListener.class) {
  193.             if (this.changeEvent == null) {
  194.                this.changeEvent = new ChangeEvent(this);
  195.             }
  196.  
  197.             ((ChangeListener)var1[var2 + 1]).stateChanged(this.changeEvent);
  198.          }
  199.       }
  200.  
  201.    }
  202.  
  203.    public BoundedRangeModel getModel() {
  204.       return this.model;
  205.    }
  206.  
  207.    public void setModel(BoundedRangeModel var1) {
  208.       BoundedRangeModel var2 = this.getModel();
  209.       if (var1 != var2) {
  210.          if (var2 != null) {
  211.             var2.removeChangeListener(this.changeListener);
  212.             this.changeListener = null;
  213.          }
  214.  
  215.          this.model = var1;
  216.          if (var1 != null) {
  217.             this.changeListener = this.createChangeListener();
  218.             var1.addChangeListener(this.changeListener);
  219.          }
  220.  
  221.          if (this.accessibleContext != null) {
  222.             this.accessibleContext.firePropertyChange("AccessibleValue", var2 == null ? null : new Integer(var2.getValue()), var1 == null ? null : new Integer(var1.getValue()));
  223.          }
  224.  
  225.          if (this.model != null) {
  226.             this.model.setExtent(0);
  227.          }
  228.  
  229.          this.repaint();
  230.       }
  231.  
  232.    }
  233.  
  234.    public int getValue() {
  235.       return this.getModel().getValue();
  236.    }
  237.  
  238.    public int getMinimum() {
  239.       return this.getModel().getMinimum();
  240.    }
  241.  
  242.    public int getMaximum() {
  243.       return this.getModel().getMaximum();
  244.    }
  245.  
  246.    public void setValue(int var1) {
  247.       BoundedRangeModel var2 = this.getModel();
  248.       int var3 = var2.getValue();
  249.       var2.setValue(var1);
  250.       if (this.accessibleContext != null) {
  251.          this.accessibleContext.firePropertyChange("AccessibleValue", new Integer(var3), new Integer(var2.getValue()));
  252.       }
  253.  
  254.    }
  255.  
  256.    public void setMinimum(int var1) {
  257.       this.getModel().setMinimum(var1);
  258.    }
  259.  
  260.    public void setMaximum(int var1) {
  261.       this.getModel().setMaximum(var1);
  262.    }
  263.  
  264.    public void setIndeterminate(boolean var1) {
  265.       boolean var2 = this.indeterminate;
  266.       this.indeterminate = var1;
  267.       this.firePropertyChange("indeterminate", var2, this.indeterminate);
  268.    }
  269.  
  270.    public boolean isIndeterminate() {
  271.       return this.indeterminate;
  272.    }
  273.  
  274.    private void writeObject(ObjectOutputStream var1) throws IOException {
  275.       var1.defaultWriteObject();
  276.       if (this.getUIClassID().equals("ProgressBarUI")) {
  277.          byte var2 = JComponent.getWriteObjCounter(this);
  278.          --var2;
  279.          JComponent.setWriteObjCounter(this, var2);
  280.          if (var2 == 0 && this.ui != null) {
  281.             this.ui.installUI(this);
  282.          }
  283.       }
  284.  
  285.    }
  286.  
  287.    protected String paramString() {
  288.       String var1 = this.orientation == 0 ? "HORIZONTAL" : "VERTICAL";
  289.       String var2 = this.paintBorder ? "true" : "false";
  290.       String var3 = this.progressString != null ? this.progressString : "";
  291.       String var4 = this.paintString ? "true" : "false";
  292.       String var5 = this.indeterminate ? "true" : "false";
  293.       return super.paramString() + ",orientation=" + var1 + ",paintBorder=" + var2 + ",paintString=" + var4 + ",progressString=" + var3 + ",indeterminateString=" + var5;
  294.    }
  295.  
  296.    public AccessibleContext getAccessibleContext() {
  297.       if (this.accessibleContext == null) {
  298.          this.accessibleContext = new AccessibleJProgressBar(this);
  299.       }
  300.  
  301.       return this.accessibleContext;
  302.    }
  303. }
  304.