home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / CFJava.cab / CFJavaRuntime.cab / netscape / application / ListItem.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-10-01  |  7.1 KB  |  312 lines

  1. package netscape.application;
  2.  
  3. import netscape.util.ClassInfo;
  4. import netscape.util.Codable;
  5. import netscape.util.CodingException;
  6. import netscape.util.Decoder;
  7. import netscape.util.Encoder;
  8. import netscape.util.InconsistencyException;
  9.  
  10. public class ListItem implements Cloneable, Codable {
  11.    ListView listView;
  12.    String command;
  13.    String title;
  14.    Font font;
  15.    Color selectedColor;
  16.    Color textColor;
  17.    Image image;
  18.    Image selectedImage;
  19.    boolean selected;
  20.    boolean enabled = true;
  21.    Object data;
  22.    static final String LISTVIEW_KEY = "listView";
  23.    static final String COMMAND_KEY = "command";
  24.    static final String TITLE_KEY = "title";
  25.    static final String FONT_KEY = "font";
  26.    static final String SELECTEDCOLOR_KEY = "selectedColor";
  27.    static final String TEXTCOLOR_KEY = "textColor";
  28.    static final String IMAGE_KEY = "image";
  29.    static final String SELECTEDIMAGE_KEY = "selectedImage";
  30.    static final String SELECTED_KEY = "selected";
  31.    static final String ENABLED_KEY = "enabled";
  32.    static final String DATA_KEY = "data";
  33.    static final String VER_2_TEXTCOLOR_KEY = "foregroundColor";
  34.  
  35.    public ListItem() {
  36.       this.selectedColor = Color.white;
  37.       this.textColor = Color.black;
  38.    }
  39.  
  40.    public Object clone() {
  41.       try {
  42.          return super.clone();
  43.       } catch (CloneNotSupportedException var2) {
  44.          throw new InconsistencyException(this + ": clone() not supported :" + var2);
  45.       }
  46.    }
  47.  
  48.    void setListView(ListView var1) {
  49.       this.listView = var1;
  50.    }
  51.  
  52.    public ListView listView() {
  53.       return this.listView;
  54.    }
  55.  
  56.    public boolean isTransparent() {
  57.       return !this.selected;
  58.    }
  59.  
  60.    public void setCommand(String var1) {
  61.       this.command = var1;
  62.    }
  63.  
  64.    public String command() {
  65.       return this.command;
  66.    }
  67.  
  68.    public void setTitle(String var1) {
  69.       this.title = var1;
  70.    }
  71.  
  72.    public String title() {
  73.       return this.title;
  74.    }
  75.  
  76.    public void setSelected(boolean var1) {
  77.       if (!this.enabled) {
  78.          var1 = false;
  79.       }
  80.  
  81.       this.selected = var1;
  82.    }
  83.  
  84.    public boolean isSelected() {
  85.       return this.selected;
  86.    }
  87.  
  88.    public void setEnabled(boolean var1) {
  89.       this.enabled = var1;
  90.       if (!this.enabled) {
  91.          this.selected = false;
  92.       }
  93.  
  94.    }
  95.  
  96.    public boolean isEnabled() {
  97.       return this.enabled;
  98.    }
  99.  
  100.    public void setImage(Image var1) {
  101.       this.image = var1;
  102.    }
  103.  
  104.    public Image image() {
  105.       return this.image;
  106.    }
  107.  
  108.    public void setSelectedImage(Image var1) {
  109.       this.selectedImage = var1;
  110.    }
  111.  
  112.    public Image selectedImage() {
  113.       return this.selectedImage;
  114.    }
  115.  
  116.    public void setFont(Font var1) {
  117.       this.font = var1;
  118.    }
  119.  
  120.    public Font font() {
  121.       if (this.font == null) {
  122.          this.font = Font.defaultFont();
  123.       }
  124.  
  125.       return this.font;
  126.    }
  127.  
  128.    public void setSelectedColor(Color var1) {
  129.       this.selectedColor = var1;
  130.    }
  131.  
  132.    public Color selectedColor() {
  133.       return this.selectedColor;
  134.    }
  135.  
  136.    public void setTextColor(Color var1) {
  137.       this.textColor = var1;
  138.    }
  139.  
  140.    public Color textColor() {
  141.       return this.textColor;
  142.    }
  143.  
  144.    public void setData(Object var1) {
  145.       this.data = var1;
  146.    }
  147.  
  148.    public Object data() {
  149.       return this.data;
  150.    }
  151.  
  152.    public int minWidth() {
  153.       int var2 = 0;
  154.       if (this.image != null) {
  155.          var2 = this.image.width();
  156.       }
  157.  
  158.       if (this.selectedImage != null && this.selectedImage.width() > var2) {
  159.          var2 = this.selectedImage.width();
  160.       }
  161.  
  162.       Font var1 = this.font();
  163.       if (var1 != null) {
  164.          var2 += var1.fontMetrics().stringWidth(this.title);
  165.       }
  166.  
  167.       if (var2 > 0) {
  168.          var2 += 3;
  169.       }
  170.  
  171.       return var2;
  172.    }
  173.  
  174.    public int minHeight() {
  175.       int var2 = 0;
  176.       int var3 = 0;
  177.       if (this.image != null) {
  178.          var2 = this.image.height();
  179.       }
  180.  
  181.       if (this.selectedImage != null && this.selectedImage.height() > var2) {
  182.          var2 = this.selectedImage.height();
  183.       }
  184.  
  185.       Font var1 = this.font();
  186.       if (var1 != null) {
  187.          var3 = var1.fontMetrics().stringHeight();
  188.       }
  189.  
  190.       if (var3 > var2) {
  191.          var2 = var3;
  192.       }
  193.  
  194.       return var2;
  195.    }
  196.  
  197.    protected void drawBackground(Graphics var1, Rect var2) {
  198.       if (this.selected) {
  199.          var1.setColor(this.selectedColor);
  200.          var1.fillRect(var2);
  201.       }
  202.  
  203.    }
  204.  
  205.    protected void drawStringInRect(Graphics var1, String var2, Font var3, Rect var4, int var5) {
  206.       if (this.listView().isEnabled() && this.enabled) {
  207.          var1.setColor(this.textColor);
  208.       } else {
  209.          var1.setColor(Color.gray);
  210.       }
  211.  
  212.       var1.setFont(var3);
  213.       var1.drawStringInRect(var2, var4, var5);
  214.    }
  215.  
  216.    public void drawInRect(Graphics var1, Rect var2) {
  217.       this.drawBackground(var1, var2);
  218.       Image var3;
  219.       if (this.selected) {
  220.          var3 = this.selectedImage;
  221.       } else {
  222.          var3 = this.image;
  223.       }
  224.  
  225.       int var6 = 0;
  226.       int var5 = 0;
  227.       if (this.image != null) {
  228.          var5 = this.image.width();
  229.          var6 = this.image.height();
  230.       }
  231.  
  232.       if (this.selectedImage != null) {
  233.          if (this.selectedImage.width() > var5) {
  234.             var5 = this.selectedImage.width();
  235.          }
  236.  
  237.          if (this.selectedImage.height() > var6) {
  238.             var6 = this.selectedImage.height();
  239.          }
  240.       }
  241.  
  242.       if (var3 != null) {
  243.          var3.drawAt(var1, var2.x, var2.y + (var2.height - var6) / 2);
  244.       }
  245.  
  246.       if (this.title != null && this.title.length() > 0) {
  247.          Rect var4 = Rect.newRect(var2.x + 2 + var5, var2.y, var2.width - 2 - var5, var2.height);
  248.          this.drawStringInRect(var1, this.title, this.font(), var4, 0);
  249.          Rect.returnRect(var4);
  250.       }
  251.  
  252.    }
  253.  
  254.    public void describeClassInfo(ClassInfo var1) {
  255.       var1.addClass("netscape.application.ListItem", 3);
  256.       var1.addField("listView", (byte)18);
  257.       var1.addField("command", (byte)16);
  258.       var1.addField("title", (byte)16);
  259.       var1.addField("font", (byte)18);
  260.       var1.addField("selectedColor", (byte)18);
  261.       var1.addField("image", (byte)18);
  262.       var1.addField("selectedImage", (byte)18);
  263.       var1.addField("selected", (byte)0);
  264.       var1.addField("enabled", (byte)0);
  265.       var1.addField("data", (byte)18);
  266.       var1.addField("textColor", (byte)18);
  267.    }
  268.  
  269.    public void encode(Encoder var1) throws CodingException {
  270.       var1.encodeObject("listView", this.listView);
  271.       var1.encodeString("command", this.command);
  272.       var1.encodeString("title", this.title);
  273.       var1.encodeObject("font", this.font);
  274.       var1.encodeObject("selectedColor", this.selectedColor);
  275.       var1.encodeObject("image", this.image);
  276.       var1.encodeObject("selectedImage", this.selectedImage);
  277.       var1.encodeBoolean("selected", this.selected);
  278.       var1.encodeBoolean("enabled", this.enabled);
  279.       if (this.data != null && this.data instanceof Codable) {
  280.          var1.encodeObject("data", this.data);
  281.       } else {
  282.          var1.encodeObject("data", (Object)null);
  283.       }
  284.  
  285.       var1.encodeObject("textColor", this.textColor);
  286.    }
  287.  
  288.    public void decode(Decoder var1) throws CodingException {
  289.       this.listView = (ListView)var1.decodeObject("listView");
  290.       this.command = var1.decodeString("command");
  291.       this.title = var1.decodeString("title");
  292.       this.font = (Font)var1.decodeObject("font");
  293.       this.selectedColor = (Color)var1.decodeObject("selectedColor");
  294.       this.image = (Image)var1.decodeObject("image");
  295.       this.selectedImage = (Image)var1.decodeObject("selectedImage");
  296.       this.selected = var1.decodeBoolean("selected");
  297.       this.enabled = var1.decodeBoolean("enabled");
  298.       this.data = var1.decodeObject("data");
  299.       if (var1.versionForClassName("netscape.application.ListItem") == 2) {
  300.          this.textColor = (Color)var1.decodeObject("foregroundColor");
  301.       } else {
  302.          if (var1.versionForClassName("netscape.application.ListItem") > 2) {
  303.             this.textColor = (Color)var1.decodeObject("textColor");
  304.          }
  305.  
  306.       }
  307.    }
  308.  
  309.    public void finishDecoding() throws CodingException {
  310.    }
  311. }
  312.