1 19 package org.openharmonise.him.metadata.range.swing.relatedevents; 20 21 import java.awt.*; 22 import java.beans.*; 23 import java.util.*; 24 import java.util.List ; 25 26 import javax.swing.*; 27 28 import org.openharmonise.him.metadata.range.swing.*; 29 import org.openharmonise.vfs.metadata.*; 30 import org.openharmonise.vfs.metadata.range.*; 31 import org.openharmonise.vfs.metadata.value.*; 32 33 34 39 public class RelatedEventApproxDate extends AbstractRangeDisplay implements RangeDisplay, LayoutManager { 40 41 private RelatedEventDate m_dateSpinner = null; 42 private RelatedEventCertainty m_checkbox = null; 43 private JLabel m_checkLabel = null; 44 private int m_nSpacing = 5; 45 46 private PropertyValue m_propValue = null; 47 48 49 52 public RelatedEventApproxDate(PropertyInstance propInst) { 53 super(propInst); 54 55 List vals = propInst.getValues(); 56 57 if(vals.size() > 0) { 58 m_propValue = (PropertyValue) vals.get(0); 59 } else { 60 m_propValue = (PropertyValue) propInst.getNewValueInstance(); 61 propInst.addValueWithoutFiringVirtualFileEvent(m_propValue); 62 } 63 64 setup(); 65 } 66 67 70 private void setup() { 71 this.setLayout(this); 72 73 PropertyInstance propInst = getPropertyInstance(); 74 75 76 PropertyRange range = 77 (PropertyRange) propInst 78 .getDefinition() 79 .getRange(); 80 81 List props = range.getProperties(); 82 83 List propInstances = this.m_propValue.getValue(); 84 85 ArrayList aFillingPropInstances = new ArrayList(); 86 aFillingPropInstances.addAll(propInstances); 87 88 89 Iterator iter = props.iterator(); 90 91 while (iter.hasNext()) { 92 Property tmpProp = (Property) iter.next(); 93 String sPropName = tmpProp.getName(); 94 PropertyInstance tmpPropInst = getPropertyInstance(tmpProp); 95 96 if(tmpPropInst==null) { 97 tmpPropInst = new PropertyInstance(tmpProp.getNamespace(), tmpProp.getName()); 98 aFillingPropInstances.add(tmpPropInst); 99 100 if(propInst.getVirtualFile() == null) { 101 throw new NullPointerException (); 102 } 103 104 tmpPropInst.setVirtualFile(propInst.getVirtualFile()); 105 106 PropertyValue val = (PropertyValue) propInst.getNewValueInstance(); 107 } 108 109 if(sPropName.equals("date")) { 110 m_dateSpinner = new RelatedEventDate(tmpPropInst); 111 this.add(m_dateSpinner); 112 } else if(sPropName.equals("certainty")) { 113 m_checkbox = new RelatedEventCertainty(tmpPropInst); 114 m_checkLabel = new JLabel(tmpPropInst.getName() + ":"); 115 116 this.add(m_checkLabel); 117 this.add(m_checkbox); 118 } 119 } 120 121 if(aFillingPropInstances.size()>propInstances.size()) { 122 this.m_propValue.setValue(aFillingPropInstances); 123 } 124 125 } 126 127 130 public void removeLayoutComponent(Component comp) { 131 } 132 133 136 public void layoutContainer(Container parent) { 137 int nYpos = 0; 138 int nXpos = 0; 139 140 m_dateSpinner.setLocation(nXpos, nYpos); 141 m_dateSpinner.setSize(m_dateSpinner.getPreferredSize().width, m_dateSpinner.getPreferredSize().height+3); 142 143 nYpos = nYpos + m_dateSpinner.getSize().height + m_nSpacing; 144 145 m_checkLabel.setLocation(nXpos, nYpos); 146 m_checkLabel.setSize(m_checkLabel.getPreferredSize()); 147 148 nXpos = nXpos + m_checkLabel.getSize().width + m_nSpacing; 149 150 m_checkbox.setLocation(nXpos, nYpos); 151 m_checkbox.setSize(m_checkbox.getPreferredSize()); 152 153 } 154 155 158 public void addLayoutComponent(String name, Component comp) { 159 } 160 161 164 public Dimension minimumLayoutSize(Container arg0) { 165 return this.getPreferredSize(); 166 } 167 168 169 170 173 public Dimension preferredLayoutSize(Container arg0) { 174 return this.getPreferredSize(); 175 } 176 177 180 public Dimension getPreferredSize() { 181 int nHeight = m_dateSpinner.getPreferredSize().height; 182 nHeight = nHeight + m_checkbox.getPreferredSize().height; 183 nHeight = nHeight + m_nSpacing; 184 185 int nWidth = m_dateSpinner.getPreferredSize().width; 186 187 return new Dimension(nWidth,nHeight); 188 } 189 190 191 192 195 public boolean isMetadataValid() { 196 boolean bIsValid = false; 197 198 bIsValid = (m_dateSpinner.isMetadataValid() 199 && m_checkbox.isMetadataValid()); 200 201 return bIsValid; 202 } 203 204 208 private PropertyInstance getPropertyInstance(Property prop) { 209 PropertyInstance propInst = null; 210 211 List propInstances = this.m_propValue.getValue(); 212 213 Iterator iter = propInstances.iterator(); 214 215 while(iter.hasNext()) { 216 PropertyInstance propInstTemp = (PropertyInstance)iter.next(); 217 if(prop.getName().equals(propInstTemp.getName()) && prop.getNamespace().equals(propInstTemp.getNamespaceURI())) { 218 propInst = propInstTemp; 219 } 220 } 221 222 return propInst; 223 } 224 225 228 public JPanel getPanel() { 229 230 return this; 231 } 232 233 234 237 public synchronized void addPropertyChangeListener(PropertyChangeListener listener) { 238 super.addPropertyChangeListener(listener); 239 this.m_dateSpinner.addPropertyChangeListener(listener); 240 this.m_checkbox.addPropertyChangeListener(listener); 241 } 242 243 } 244 | Popular Tags |