home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / javax / swing / AbstractButton$AccessibleAbstractButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  7.6 KB  |  428 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Graphics;
  4. import java.awt.Insets;
  5. import java.awt.Point;
  6. import java.awt.Rectangle;
  7. import java.awt.Shape;
  8. import java.awt.geom.Rectangle2D;
  9. import java.text.BreakIterator;
  10. import java.util.Enumeration;
  11. import javax.accessibility.AccessibleAction;
  12. import javax.accessibility.AccessibleIcon;
  13. import javax.accessibility.AccessibleRelation;
  14. import javax.accessibility.AccessibleRelationSet;
  15. import javax.accessibility.AccessibleState;
  16. import javax.accessibility.AccessibleStateSet;
  17. import javax.accessibility.AccessibleText;
  18. import javax.accessibility.AccessibleValue;
  19. import javax.swing.text.AttributeSet;
  20. import javax.swing.text.BadLocationException;
  21. import javax.swing.text.Document;
  22. import javax.swing.text.Element;
  23. import javax.swing.text.Position;
  24. import javax.swing.text.StyledDocument;
  25. import javax.swing.text.View;
  26. import javax.swing.text.Position.Bias;
  27.  
  28. public abstract class AbstractButton$AccessibleAbstractButton extends JComponent.AccessibleJComponent implements AccessibleAction, AccessibleValue, AccessibleText {
  29.    // $FF: synthetic field
  30.    private final AbstractButton this$0;
  31.  
  32.    protected AbstractButton$AccessibleAbstractButton(AbstractButton var1) {
  33.       super(var1);
  34.       this.this$0 = var1;
  35.    }
  36.  
  37.    public String getAccessibleName() {
  38.       if (super.accessibleName != null) {
  39.          return super.accessibleName;
  40.       } else {
  41.          return this.this$0.getText() == null ? super.getAccessibleName() : this.this$0.getText();
  42.       }
  43.    }
  44.  
  45.    public AccessibleIcon[] getAccessibleIcon() {
  46.       if (AbstractButton.access$200(this.this$0) == null) {
  47.          return null;
  48.       } else {
  49.          AccessibleIcon[] var1 = new AccessibleIcon[]{AbstractButton.access$200(this.this$0)};
  50.          return var1;
  51.       }
  52.    }
  53.  
  54.    public AccessibleStateSet getAccessibleStateSet() {
  55.       AccessibleStateSet var1 = super.getAccessibleStateSet();
  56.       if (this.this$0.getModel().isArmed()) {
  57.          var1.add(AccessibleState.ARMED);
  58.       }
  59.  
  60.       if (this.this$0.hasFocus()) {
  61.          var1.add(AccessibleState.FOCUSED);
  62.       }
  63.  
  64.       if (this.this$0.getModel().isPressed()) {
  65.          var1.add(AccessibleState.PRESSED);
  66.       }
  67.  
  68.       if (this.this$0.isSelected()) {
  69.          var1.add(AccessibleState.CHECKED);
  70.       }
  71.  
  72.       return var1;
  73.    }
  74.  
  75.    public AccessibleRelationSet getAccessibleRelationSet() {
  76.       AccessibleRelationSet var1 = super.getAccessibleRelationSet();
  77.       if (!var1.contains(AccessibleRelation.MEMBER_OF)) {
  78.          ButtonModel var2 = this.this$0.getModel();
  79.          if (var2 != null && var2 instanceof DefaultButtonModel) {
  80.             ButtonGroup var3 = ((DefaultButtonModel)var2).getGroup();
  81.             if (var3 != null) {
  82.                int var4 = var3.getButtonCount();
  83.                Object[] var5 = new Object[var4];
  84.                Enumeration var6 = var3.getElements();
  85.  
  86.                for(int var7 = 0; var7 < var4; ++var7) {
  87.                   if (var6.hasMoreElements()) {
  88.                      var5[var7] = var6.nextElement();
  89.                   }
  90.                }
  91.  
  92.                AccessibleRelation var8 = new AccessibleRelation(AccessibleRelation.MEMBER_OF);
  93.                var8.setTarget(var5);
  94.                var1.add(var8);
  95.             }
  96.          }
  97.       }
  98.  
  99.       return var1;
  100.    }
  101.  
  102.    public AccessibleAction getAccessibleAction() {
  103.       return this;
  104.    }
  105.  
  106.    public AccessibleValue getAccessibleValue() {
  107.       return this;
  108.    }
  109.  
  110.    public int getAccessibleActionCount() {
  111.       return 1;
  112.    }
  113.  
  114.    public String getAccessibleActionDescription(int var1) {
  115.       return var1 == 0 ? new String("click") : null;
  116.    }
  117.  
  118.    public boolean doAccessibleAction(int var1) {
  119.       if (var1 == 0) {
  120.          this.this$0.doClick();
  121.          return true;
  122.       } else {
  123.          return false;
  124.       }
  125.    }
  126.  
  127.    public Number getCurrentAccessibleValue() {
  128.       return this.this$0.isSelected() ? new Integer(1) : new Integer(0);
  129.    }
  130.  
  131.    public boolean setCurrentAccessibleValue(Number var1) {
  132.       if (var1 instanceof Integer) {
  133.          int var2 = var1.intValue();
  134.          if (var2 == 0) {
  135.             this.this$0.setSelected(false);
  136.          } else {
  137.             this.this$0.setSelected(true);
  138.          }
  139.  
  140.          return true;
  141.       } else {
  142.          return false;
  143.       }
  144.    }
  145.  
  146.    public Number getMinimumAccessibleValue() {
  147.       return new Integer(0);
  148.    }
  149.  
  150.    public Number getMaximumAccessibleValue() {
  151.       return new Integer(1);
  152.    }
  153.  
  154.    public AccessibleText getAccessibleText() {
  155.       View var1 = (View)this.this$0.getClientProperty("html");
  156.       return var1 != null ? this : null;
  157.    }
  158.  
  159.    public int getIndexAtPoint(Point var1) {
  160.       View var2 = (View)this.this$0.getClientProperty("html");
  161.       if (var2 != null) {
  162.          Rectangle var3 = this.getTextRectangle();
  163.          if (var3 == null) {
  164.             return -1;
  165.          } else {
  166.             Rectangle2D.Float var4 = new Rectangle2D.Float((float)var3.x, (float)var3.y, (float)var3.width, (float)var3.height);
  167.             Position.Bias[] var5 = new Position.Bias[1];
  168.             return var2.viewToModel((float)var1.x, (float)var1.y, var4, var5);
  169.          }
  170.       } else {
  171.          return -1;
  172.       }
  173.    }
  174.  
  175.    public Rectangle getCharacterBounds(int var1) {
  176.       View var2 = (View)this.this$0.getClientProperty("html");
  177.       if (var2 != null) {
  178.          Rectangle var3 = this.getTextRectangle();
  179.          if (var3 == null) {
  180.             return null;
  181.          } else {
  182.             Rectangle2D.Float var4 = new Rectangle2D.Float((float)var3.x, (float)var3.y, (float)var3.width, (float)var3.height);
  183.  
  184.             try {
  185.                Shape var5 = var2.modelToView(var1, var4, Bias.Forward);
  186.                return var5.getBounds();
  187.             } catch (BadLocationException var6) {
  188.                return null;
  189.             }
  190.          }
  191.       } else {
  192.          return null;
  193.       }
  194.    }
  195.  
  196.    public int getCharCount() {
  197.       View var1 = (View)this.this$0.getClientProperty("html");
  198.       if (var1 != null) {
  199.          Document var2 = var1.getDocument();
  200.          if (var2 instanceof StyledDocument) {
  201.             StyledDocument var3 = (StyledDocument)var2;
  202.             return var3.getLength();
  203.          }
  204.       }
  205.  
  206.       return this.this$0.accessibleContext.getAccessibleName().length();
  207.    }
  208.  
  209.    public int getCaretPosition() {
  210.       return -1;
  211.    }
  212.  
  213.    public String getAtIndex(int var1, int var2) {
  214.       if (var2 >= 0 && var2 < this.getCharCount()) {
  215.          switch (var1) {
  216.             case 1:
  217.                try {
  218.                   return this.getText(var2, 1);
  219.                } catch (BadLocationException var8) {
  220.                   return null;
  221.                }
  222.             case 2:
  223.                try {
  224.                   String var9 = this.getText(0, this.getCharCount());
  225.                   BreakIterator var10 = BreakIterator.getWordInstance();
  226.                   var10.setText(var9);
  227.                   int var11 = var10.following(var2);
  228.                   return var9.substring(var10.previous(), var11);
  229.                } catch (BadLocationException var7) {
  230.                   return null;
  231.                }
  232.             case 3:
  233.                try {
  234.                   String var3 = this.getText(0, this.getCharCount());
  235.                   BreakIterator var4 = BreakIterator.getSentenceInstance();
  236.                   var4.setText(var3);
  237.                   int var5 = var4.following(var2);
  238.                   return var3.substring(var4.previous(), var5);
  239.                } catch (BadLocationException var6) {
  240.                   return null;
  241.                }
  242.             default:
  243.                return null;
  244.          }
  245.       } else {
  246.          return null;
  247.       }
  248.    }
  249.  
  250.    public String getAfterIndex(int var1, int var2) {
  251.       if (var2 >= 0 && var2 < this.getCharCount()) {
  252.          switch (var1) {
  253.             case 1:
  254.                if (var2 + 1 >= this.getCharCount()) {
  255.                   return null;
  256.                } else {
  257.                   try {
  258.                      return this.getText(var2 + 1, 1);
  259.                   } catch (BadLocationException var9) {
  260.                      return null;
  261.                   }
  262.                }
  263.             case 2:
  264.                try {
  265.                   String var10 = this.getText(0, this.getCharCount());
  266.                   BreakIterator var11 = BreakIterator.getWordInstance();
  267.                   var11.setText(var10);
  268.                   int var12 = var11.following(var2);
  269.                   if (var12 != -1 && var12 < var10.length()) {
  270.                      int var13 = var11.following(var12);
  271.                      if (var13 != -1 && var13 < var10.length()) {
  272.                         return var10.substring(var12, var13);
  273.                      }
  274.  
  275.                      return null;
  276.                   }
  277.  
  278.                   return null;
  279.                } catch (BadLocationException var8) {
  280.                   return null;
  281.                }
  282.             case 3:
  283.                try {
  284.                   String var3 = this.getText(0, this.getCharCount());
  285.                   BreakIterator var4 = BreakIterator.getSentenceInstance();
  286.                   var4.setText(var3);
  287.                   int var5 = var4.following(var2);
  288.                   if (var5 != -1 && var5 < var3.length()) {
  289.                      int var6 = var4.following(var5);
  290.                      if (var6 != -1 && var6 < var3.length()) {
  291.                         return var3.substring(var5, var6);
  292.                      }
  293.  
  294.                      return null;
  295.                   }
  296.  
  297.                   return null;
  298.                } catch (BadLocationException var7) {
  299.                   return null;
  300.                }
  301.             default:
  302.                return null;
  303.          }
  304.       } else {
  305.          return null;
  306.       }
  307.    }
  308.  
  309.    public String getBeforeIndex(int var1, int var2) {
  310.       if (var2 >= 0 && var2 <= this.getCharCount() - 1) {
  311.          switch (var1) {
  312.             case 1:
  313.                if (var2 == 0) {
  314.                   return null;
  315.                } else {
  316.                   try {
  317.                      return this.getText(var2 - 1, 1);
  318.                   } catch (BadLocationException var9) {
  319.                      return null;
  320.                   }
  321.                }
  322.             case 2:
  323.                try {
  324.                   String var10 = this.getText(0, this.getCharCount());
  325.                   BreakIterator var11 = BreakIterator.getWordInstance();
  326.                   var11.setText(var10);
  327.                   var11.following(var2);
  328.                   int var12 = var11.previous();
  329.                   int var13 = var11.previous();
  330.                   if (var13 == -1) {
  331.                      return null;
  332.                   }
  333.  
  334.                   return var10.substring(var13, var12);
  335.                } catch (BadLocationException var8) {
  336.                   return null;
  337.                }
  338.             case 3:
  339.                try {
  340.                   String var3 = this.getText(0, this.getCharCount());
  341.                   BreakIterator var4 = BreakIterator.getSentenceInstance();
  342.                   var4.setText(var3);
  343.                   var4.following(var2);
  344.                   int var5 = var4.previous();
  345.                   int var6 = var4.previous();
  346.                   if (var6 == -1) {
  347.                      return null;
  348.                   }
  349.  
  350.                   return var3.substring(var6, var5);
  351.                } catch (BadLocationException var7) {
  352.                   return null;
  353.                }
  354.             default:
  355.                return null;
  356.          }
  357.       } else {
  358.          return null;
  359.       }
  360.    }
  361.  
  362.    public AttributeSet getCharacterAttribute(int var1) {
  363.       View var2 = (View)this.this$0.getClientProperty("html");
  364.       if (var2 != null) {
  365.          Document var3 = var2.getDocument();
  366.          if (var3 instanceof StyledDocument) {
  367.             StyledDocument var4 = (StyledDocument)var3;
  368.             Element var5 = var4.getCharacterElement(var1);
  369.             if (var5 != null) {
  370.                return var5.getAttributes();
  371.             }
  372.          }
  373.       }
  374.  
  375.       return null;
  376.    }
  377.  
  378.    public int getSelectionStart() {
  379.       return -1;
  380.    }
  381.  
  382.    public int getSelectionEnd() {
  383.       return -1;
  384.    }
  385.  
  386.    public String getSelectedText() {
  387.       return null;
  388.    }
  389.  
  390.    private String getText(int var1, int var2) throws BadLocationException {
  391.       View var3 = (View)this.this$0.getClientProperty("html");
  392.       if (var3 != null) {
  393.          Document var4 = var3.getDocument();
  394.          if (var4 instanceof StyledDocument) {
  395.             StyledDocument var5 = (StyledDocument)var4;
  396.             return var5.getText(var1, var2);
  397.          }
  398.       }
  399.  
  400.       return null;
  401.    }
  402.  
  403.    private Rectangle getTextRectangle() {
  404.       String var1 = this.this$0.getText();
  405.       Icon var2 = this.this$0.isEnabled() ? this.this$0.getIcon() : this.this$0.getDisabledIcon();
  406.       if (var2 == null && var1 == null) {
  407.          return null;
  408.       } else {
  409.          Rectangle var3 = new Rectangle();
  410.          Rectangle var4 = new Rectangle();
  411.          Rectangle var5 = new Rectangle();
  412.          Insets var6 = new Insets(0, 0, 0, 0);
  413.          var6 = this.this$0.getInsets(var6);
  414.          var5.x = var6.left;
  415.          var5.y = var6.top;
  416.          var5.width = this.this$0.getWidth() - (var6.left + var6.right);
  417.          var5.height = this.this$0.getHeight() - (var6.top + var6.bottom);
  418.          Graphics var7 = this.this$0.getGraphics();
  419.          if (var7 == null) {
  420.             return null;
  421.          } else {
  422.             SwingUtilities.layoutCompoundLabel(this.this$0, var7.getFontMetrics(), var1, var2, this.this$0.getVerticalAlignment(), this.this$0.getHorizontalAlignment(), this.this$0.getVerticalTextPosition(), this.this$0.getHorizontalTextPosition(), var5, var3, var4, 0);
  423.             return var4;
  424.          }
  425.       }
  426.    }
  427. }
  428.