001package kiwi.ui.propeditor; 002 003import java.util.*; 004import javax.swing.Icon; 005 006import kiwi.util.KiwiUtils; 007 008/** 009 */ 010 011public class Property 012 { 013 private PropertyType type; 014 private Object value; 015 private String name; 016 private ArrayList children = null; 017 private Icon icon; 018 private boolean editable = true; 019 private static final Icon PROPERTY_ICON = KiwiUtils.getResourceManager() 020 .getIcon("option.gif"); 021 022 023 public Property(String name, PropertyType type) 024 { 025 this(name, PROPERTY_ICON, type, null); 026 } 027 028 public Property(String name, Icon icon, PropertyType type) 029 { 030 this(name, icon, type, null); 031 } 032 033 public Property(String name, Icon icon, PropertyType type, Object value) 034 { 035 this.name = name; 036 this.icon = icon; 037 this.type = type; 038 this.value = value; 039 } 040 041 public boolean isEditable() 042 { 043 return(editable); 044 } 045 046 public boolean hasValue() 047 { 048 return(value != null); 049 } 050 051 public void setEditable(boolean editable) 052 { 053 this.editable = editable; 054 } 055 056 public Icon getIcon() 057 { 058 return(icon); 059 } 060 061 public String getName() 062 { 063 return(name); 064 } 065 066 public PropertyType getType() 067 { 068 return(type); 069 } 070 071 public Object getValue() 072 { 073 return(value); 074 } 075 076 public void setValue(Object value) 077 { 078 this.value = value; 079 } 080 081 public boolean hasChildren() 082 { 083 return(children != null); 084 } 085 086 public void addChild(Property property) 087 { 088 if(children == null) 089 children = new ArrayList(); 090 091 children.add(property); 092 } 093 094 public void removeChild(Property property) 095 { 096 if(children != null) 097 children.remove(property); 098 } 099 100 public void removeChildren() 101 { 102 children = null; 103 } 104 105 public Iterator getChildren() 106 { 107 return(children == null ? null : children.iterator()); 108 } 109 110 public String toString() 111 { 112 if(value != null) 113 return(name + ": " + type.formatValue(value)); 114 else 115 return(name); 116 } 117 }