home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import netscape.util.ClassInfo;
- import netscape.util.Codable;
- import netscape.util.CodingException;
- import netscape.util.Decoder;
- import netscape.util.Encoder;
- import netscape.util.InconsistencyException;
-
- public class ListItem implements Cloneable, Codable {
- ListView listView;
- String command;
- String title;
- Font font;
- Color selectedColor;
- Color textColor;
- Image image;
- Image selectedImage;
- boolean selected;
- boolean enabled = true;
- Object data;
- static final String LISTVIEW_KEY = "listView";
- static final String COMMAND_KEY = "command";
- static final String TITLE_KEY = "title";
- static final String FONT_KEY = "font";
- static final String SELECTEDCOLOR_KEY = "selectedColor";
- static final String TEXTCOLOR_KEY = "textColor";
- static final String IMAGE_KEY = "image";
- static final String SELECTEDIMAGE_KEY = "selectedImage";
- static final String SELECTED_KEY = "selected";
- static final String ENABLED_KEY = "enabled";
- static final String DATA_KEY = "data";
- static final String VER_2_TEXTCOLOR_KEY = "foregroundColor";
-
- public ListItem() {
- this.selectedColor = Color.white;
- this.textColor = Color.black;
- }
-
- public Object clone() {
- try {
- return super.clone();
- } catch (CloneNotSupportedException var2) {
- throw new InconsistencyException(this + ": clone() not supported :" + var2);
- }
- }
-
- void setListView(ListView var1) {
- this.listView = var1;
- }
-
- public ListView listView() {
- return this.listView;
- }
-
- public boolean isTransparent() {
- return !this.selected;
- }
-
- public void setCommand(String var1) {
- this.command = var1;
- }
-
- public String command() {
- return this.command;
- }
-
- public void setTitle(String var1) {
- this.title = var1;
- }
-
- public String title() {
- return this.title;
- }
-
- public void setSelected(boolean var1) {
- if (!this.enabled) {
- var1 = false;
- }
-
- this.selected = var1;
- }
-
- public boolean isSelected() {
- return this.selected;
- }
-
- public void setEnabled(boolean var1) {
- this.enabled = var1;
- if (!this.enabled) {
- this.selected = false;
- }
-
- }
-
- public boolean isEnabled() {
- return this.enabled;
- }
-
- public void setImage(Image var1) {
- this.image = var1;
- }
-
- public Image image() {
- return this.image;
- }
-
- public void setSelectedImage(Image var1) {
- this.selectedImage = var1;
- }
-
- public Image selectedImage() {
- return this.selectedImage;
- }
-
- public void setFont(Font var1) {
- this.font = var1;
- }
-
- public Font font() {
- if (this.font == null) {
- this.font = Font.defaultFont();
- }
-
- return this.font;
- }
-
- public void setSelectedColor(Color var1) {
- this.selectedColor = var1;
- }
-
- public Color selectedColor() {
- return this.selectedColor;
- }
-
- public void setTextColor(Color var1) {
- this.textColor = var1;
- }
-
- public Color textColor() {
- return this.textColor;
- }
-
- public void setData(Object var1) {
- this.data = var1;
- }
-
- public Object data() {
- return this.data;
- }
-
- public int minWidth() {
- int var2 = 0;
- if (this.image != null) {
- var2 = this.image.width();
- }
-
- if (this.selectedImage != null && this.selectedImage.width() > var2) {
- var2 = this.selectedImage.width();
- }
-
- Font var1 = this.font();
- if (var1 != null) {
- var2 += var1.fontMetrics().stringWidth(this.title);
- }
-
- if (var2 > 0) {
- var2 += 3;
- }
-
- return var2;
- }
-
- public int minHeight() {
- int var2 = 0;
- int var3 = 0;
- if (this.image != null) {
- var2 = this.image.height();
- }
-
- if (this.selectedImage != null && this.selectedImage.height() > var2) {
- var2 = this.selectedImage.height();
- }
-
- Font var1 = this.font();
- if (var1 != null) {
- var3 = var1.fontMetrics().stringHeight();
- }
-
- if (var3 > var2) {
- var2 = var3;
- }
-
- return var2;
- }
-
- protected void drawBackground(Graphics var1, Rect var2) {
- if (this.selected) {
- var1.setColor(this.selectedColor);
- var1.fillRect(var2);
- }
-
- }
-
- protected void drawStringInRect(Graphics var1, String var2, Font var3, Rect var4, int var5) {
- if (this.listView().isEnabled() && this.enabled) {
- var1.setColor(this.textColor);
- } else {
- var1.setColor(Color.gray);
- }
-
- var1.setFont(var3);
- var1.drawStringInRect(var2, var4, var5);
- }
-
- public void drawInRect(Graphics var1, Rect var2) {
- this.drawBackground(var1, var2);
- Image var3;
- if (this.selected) {
- var3 = this.selectedImage;
- } else {
- var3 = this.image;
- }
-
- int var6 = 0;
- int var5 = 0;
- if (this.image != null) {
- var5 = this.image.width();
- var6 = this.image.height();
- }
-
- if (this.selectedImage != null) {
- if (this.selectedImage.width() > var5) {
- var5 = this.selectedImage.width();
- }
-
- if (this.selectedImage.height() > var6) {
- var6 = this.selectedImage.height();
- }
- }
-
- if (var3 != null) {
- var3.drawAt(var1, var2.x, var2.y + (var2.height - var6) / 2);
- }
-
- if (this.title != null && this.title.length() > 0) {
- Rect var4 = Rect.newRect(var2.x + 2 + var5, var2.y, var2.width - 2 - var5, var2.height);
- this.drawStringInRect(var1, this.title, this.font(), var4, 0);
- Rect.returnRect(var4);
- }
-
- }
-
- public void describeClassInfo(ClassInfo var1) {
- var1.addClass("netscape.application.ListItem", 3);
- var1.addField("listView", (byte)18);
- var1.addField("command", (byte)16);
- var1.addField("title", (byte)16);
- var1.addField("font", (byte)18);
- var1.addField("selectedColor", (byte)18);
- var1.addField("image", (byte)18);
- var1.addField("selectedImage", (byte)18);
- var1.addField("selected", (byte)0);
- var1.addField("enabled", (byte)0);
- var1.addField("data", (byte)18);
- var1.addField("textColor", (byte)18);
- }
-
- public void encode(Encoder var1) throws CodingException {
- var1.encodeObject("listView", this.listView);
- var1.encodeString("command", this.command);
- var1.encodeString("title", this.title);
- var1.encodeObject("font", this.font);
- var1.encodeObject("selectedColor", this.selectedColor);
- var1.encodeObject("image", this.image);
- var1.encodeObject("selectedImage", this.selectedImage);
- var1.encodeBoolean("selected", this.selected);
- var1.encodeBoolean("enabled", this.enabled);
- if (this.data != null && this.data instanceof Codable) {
- var1.encodeObject("data", this.data);
- } else {
- var1.encodeObject("data", (Object)null);
- }
-
- var1.encodeObject("textColor", this.textColor);
- }
-
- public void decode(Decoder var1) throws CodingException {
- this.listView = (ListView)var1.decodeObject("listView");
- this.command = var1.decodeString("command");
- this.title = var1.decodeString("title");
- this.font = (Font)var1.decodeObject("font");
- this.selectedColor = (Color)var1.decodeObject("selectedColor");
- this.image = (Image)var1.decodeObject("image");
- this.selectedImage = (Image)var1.decodeObject("selectedImage");
- this.selected = var1.decodeBoolean("selected");
- this.enabled = var1.decodeBoolean("enabled");
- this.data = var1.decodeObject("data");
- if (var1.versionForClassName("netscape.application.ListItem") == 2) {
- this.textColor = (Color)var1.decodeObject("foregroundColor");
- } else {
- if (var1.versionForClassName("netscape.application.ListItem") > 2) {
- this.textColor = (Color)var1.decodeObject("textColor");
- }
-
- }
- }
-
- public void finishDecoding() throws CodingException {
- }
- }
-