| 1 19 package org.openharmonise.him.metadata.range.swing.resourcehandling; 20 21 import java.awt.*; 22 import java.util.*; 23 import java.util.List ; 24 25 import javax.swing.*; 26 27 import org.openharmonise.vfs.*; 28 import org.openharmonise.vfs.metadata.value.*; 29 30 31 37 public class ResourceSelectionList extends JPanel implements LayoutManager { 38 39 private ResourceRangeDisplay m_display = null; 40 41 private ArrayList m_aReasons = new ArrayList(); 42 43 private JPanel m_panel = null; 44 45 48 public ResourceSelectionList(ResourceRangeDisplay display) { 49 super(); 50 this.m_display = display; 51 this.setup(); 52 } 53 54 private void setup() { 55 m_panel = new JPanel(); 56 m_panel.setLayout(this); 57 this.setBackground(Color.WHITE); 58 this.m_panel.setBackground(Color.WHITE); 59 60 JScrollPane scroller = new JScrollPane(m_panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 61 scroller.setBorder(BorderFactory.createEmptyBorder()); 62 this.setLayout(new BorderLayout()); 63 this.add(scroller); 64 } 65 66 public void addReason(Reason reason) { 67 this.m_aReasons.add(reason); 68 69 List values = reason.getPropertyInstance().getValues(); 70 Iterator itor = values.iterator(); 71 while (itor.hasNext()) { 72 ResourceValue value = (ResourceValue) itor.next(); 73 ResourceSelectionCell cell = new ResourceSelectionCell(value, reason, this); 74 m_panel.add(cell); 75 int nHeight = 0; 76 for(int i=0; i<this.m_panel.getComponentCount(); i++) { 77 Component comp = this.m_panel.getComponent(i); 78 if(comp instanceof ResourceSelectionCell) { 79 nHeight = nHeight + 20; 80 } 81 } 82 this.m_panel.setPreferredSize(new Dimension(270, nHeight)); 83 } 84 this.refreshReasons(); 85 } 86 87 public void refreshReasons() { 88 for(int i=0; i<this.m_panel.getComponentCount(); i++) { 89 Component comp = this.m_panel.getComponent(i); 90 if(comp instanceof ResourceSelectionCell) { 91 ((ResourceSelectionCell)comp).refreshReasons(); 92 } 93 } 94 } 95 96 public void addResource(VirtualFile vfFile) { 97 ResourceSelectionCell cell = new ResourceSelectionCell(this, vfFile); 98 m_panel.add(cell); 99 } 100 101 public boolean isValid() { 102 boolean bValid = true; 103 104 Iterator itor = this.m_aReasons.iterator(); 105 while (itor.hasNext()) { 106 Reason reason = (Reason) itor.next(); 107 if(!reason.isValid()) { 108 bValid = false; 109 } 110 } 111 112 return bValid; 113 } 114 115 118 public void layoutContainer(Container arg0) { 119 int nHeight = 0; 120 121 for(int i=0; i<this.m_panel.getComponentCount(); i++) { 122 Component comp = this.m_panel.getComponent(i); 123 if(comp instanceof ResourceSelectionCell) { 124 ResourceSelectionCell cell = (ResourceSelectionCell) comp; 125 cell.setSize(cell.getPreferredSize()); 126 cell.setLocation(0, nHeight); 127 nHeight = nHeight + cell.getSize().height; 128 } 129 } 130 } 131 132 private ResourceSelectionCell getSelectedCell() { 133 ResourceSelectionCell cell = null; 134 for(int i=0; i<this.m_panel.getComponentCount(); i++) { 135 Component comp = this.m_panel.getComponent(i); 136 if(comp instanceof ResourceSelectionCell && ((ResourceSelectionCell)comp).isSelected() ) { 137 cell = (ResourceSelectionCell) comp; 138 } 139 } 140 return cell; 141 } 142 143 public void cellSelected(ResourceSelectionCell cell) { 144 for(int i=0; i<this.m_panel.getComponentCount(); i++) { 145 Component comp = this.m_panel.getComponent(i); 146 if(comp instanceof ResourceSelectionCell) { 147 ((ResourceSelectionCell)comp).setCellSelected(false); 148 } 149 } 150 cell.setCellSelected(true); 151 this.validateTree(); 152 this.repaint(); 153 } 154 155 public void removeSelectedCell() { 156 ResourceSelectionCell cell = this.getSelectedCell(); 157 158 if(cell!=null) { 159 cell.prepareToRemove(); 160 this.m_panel.remove(cell); 161 } 162 } 163 164 167 public Dimension getPreferredSize() { 168 return new Dimension(300,300); 169 } 170 171 protected List getReasons() { 172 return (List ) this.m_aReasons.clone(); 173 } 174 175 178 private ResourceSelectionList(boolean arg0) { 179 super(arg0); 180 } 181 182 185 private ResourceSelectionList(LayoutManager arg0) { 186 super(arg0); 187 } 188 189 193 private ResourceSelectionList(LayoutManager arg0, boolean arg1) { 194 super(arg0, arg1); 195 } 196 197 200 public Dimension minimumLayoutSize(Container arg0) { 201 return this.getPreferredSize(); 202 } 203 204 207 public Dimension preferredLayoutSize(Container arg0) { 208 return this.getPreferredSize(); 209 } 210 211 214 public void removeLayoutComponent(Component arg0) { 215 } 216 217 220 public void addLayoutComponent(String arg0, Component arg1) { 221 } 222 223 } 224 | Popular Tags |