1 19 package org.lucane.applications.administrator.gui; 20 21 import java.util.ArrayList ; 22 23 import javax.swing.*; 24 import javax.swing.table.*; 25 26 import org.lucane.client.Plugin; 27 import org.lucane.client.Client; 28 import org.lucane.common.concepts.*; 29 30 public class ConceptTable extends JTable 31 { 32 public ConceptTable(Plugin plugin, String name, ArrayList concepts) 33 { 34 super(new ConceptTableModel(plugin, concepts)); 35 getColumnModel().getColumn(0).setMinWidth(16); 36 getColumnModel().getColumn(0).setMaxWidth(20); 37 getTableHeader().getColumnModel().getColumn(0).setHeaderValue(""); 38 getTableHeader().getColumnModel().getColumn(1).setHeaderValue(name); 39 setRowSelectionAllowed(true); 40 setShowVerticalLines(false); 41 } 42 43 public ConceptTable(Plugin plugin, String name) 44 { 45 this(plugin, name, new ArrayList ()); 46 } 47 48 public void setConcepts(ArrayList list) 49 { 50 ConceptTableModel model = (ConceptTableModel)this.getModel(); 51 model.setConcepts(list); 52 } 53 54 public void addConcept(Concept concept) 55 { 56 ConceptTableModel model = (ConceptTableModel)this.getModel(); 57 model.addConcept(concept); 58 } 59 60 public Concept getConceptAt(int row) 61 { 62 return ((ConceptTableModel)this.getModel()).getConceptAt(row); 63 } 64 } 65 66 class ConceptTableModel extends AbstractTableModel 67 { 68 private ArrayList concepts; 69 70 private ImageIcon groupIcon; 71 private ImageIcon userIcon; 72 private ImageIcon pluginIcon; 73 private ImageIcon serviceIcon; 74 75 public ConceptTableModel(Plugin plugin, ArrayList concepts) 76 { 77 this.concepts = concepts; 78 79 this.groupIcon = Client.getImageIcon("group.png"); 80 this.userIcon = Client.getImageIcon("user.png"); 81 this.pluginIcon = plugin.getImageIcon("plugin.jpg"); 82 this.serviceIcon = plugin.getImageIcon("service.jpg"); 83 } 84 85 public void setConcepts(ArrayList concepts) 86 { 87 this.concepts = concepts; 88 this.fireTableDataChanged(); 89 } 90 91 public void addConcept(Concept concept) 92 { 93 this.concepts.add(concept); 94 this.fireTableDataChanged(); 95 } 96 97 public Concept getConceptAt(int row) 98 { 99 return (Concept)concepts.get(row); 100 } 101 102 public void removeAt(int row) 103 { 104 if(row < 0) 105 return; 106 107 concepts.remove(row); 108 this.fireTableDataChanged(); 109 } 110 111 public ArrayList getConceptList() 112 { 113 return concepts; 114 } 115 116 public Object getValueAt(int x, int y) 117 { 118 Concept c = (Concept)concepts.get(x); 119 120 if(y == 1) 121 return c.getName(); 122 123 if(c instanceof PluginConcept) 124 return pluginIcon; 125 if(c instanceof GroupConcept) 126 return groupIcon; 127 if(c instanceof UserConcept) 128 return userIcon; 129 if(c instanceof ServiceConcept) 130 return serviceIcon; 131 132 return ""; 133 } 134 135 public Class getColumnClass(int c) 136 { 137 return (c==0 ? ImageIcon.class : String .class); 138 } 139 140 public int getColumnCount() 141 { 142 return 2; 143 } 144 145 public int getRowCount() 146 { 147 return concepts.size(); 148 } 149 } 150 | Popular Tags |