1 19 20 package org.openharmonise.him.metadata.swing; 21 22 import java.awt.*; 23 24 import javax.swing.*; 25 import javax.swing.border.*; 26 27 import org.openharmonise.commons.xml.namespace.*; 28 import org.openharmonise.him.metadata.range.swing.*; 29 import org.openharmonise.vfs.metadata.*; 30 31 32 36 public class PropertyPanel extends JPanel implements LayoutManager { 37 38 private PropertyInstance m_propertyInstance = null; 39 private String m_sName = null; 40 41 private boolean m_bResizeWidth = true; 42 43 private HelpIcon m_helpIcon = null; 44 45 private JLabel m_titleLabel = null; 46 47 50 public PropertyPanel(PropertyInstance propertyInstance, boolean bResizeWidth) { 51 super(); 52 this.m_propertyInstance = propertyInstance; 53 this.m_bResizeWidth = bResizeWidth; 54 this.setup(); 55 } 56 59 public PropertyPanel(String sName, boolean bResizeWidth) { 60 super(); 61 this.m_sName = sName; 62 this.m_bResizeWidth = bResizeWidth; 63 this.setup(); 64 } 65 66 public Property getProperty() { 67 Property prop = null; 68 69 if(this.m_propertyInstance!=null && this.m_propertyInstance.getDefinition()!=null) { 70 prop = this.m_propertyInstance.getDefinition(); 71 } 72 73 return prop; 74 } 75 76 79 private PropertyPanel(boolean arg0) { 80 super(arg0); 81 } 82 83 86 private PropertyPanel(LayoutManager arg0) { 87 super(arg0); 88 } 89 90 94 private PropertyPanel(LayoutManager arg0, boolean arg1) { 95 super(arg0, arg1); 96 } 97 98 private void setup() { 99 this.setLayout(this); 100 101 TitledBorder border = null; 102 103 if(this.m_propertyInstance!=null) { 104 if(this.m_propertyInstance.getNamespaceURI().equals(NamespaceType.OHRM.getURI()) && this.m_propertyInstance.getName().equals("title")) { 105 this.m_titleLabel = new JLabel("Title"); 106 } else { 107 this.m_titleLabel = new JLabel(this.m_propertyInstance.getDefinition().getDisplayName()); 108 } 109 } else if(this.m_sName!=null) { 110 this.m_titleLabel = new JLabel(this.m_sName); 111 } 112 String fontName = "Dialog"; 113 int fontSize = 13; 114 Font font = new Font(fontName, Font.BOLD, fontSize); 115 this.m_titleLabel.setFont(font); 116 this.add(m_titleLabel); 117 118 if(this.m_propertyInstance!=null && this.m_propertyInstance.getDefinition()!=null) { 119 if(this.m_propertyInstance.getName().equals("domain")) { 120 this.m_helpIcon = new HelpIcon("Domain", "Domain is used to restrict a Property's use (and occurrence) to a particular set of Collections or Resources, for example you could restrict the Property \"Location\" to the Resources within the Collection \"Case Study\" and restrict the number of locations to \"one\". This would mean that when tagging a Case Study document the vocabularies within Location (e.g. South East, Midlands etc.) would be available to the user and that they need to define one Location."); 121 this.add(m_helpIcon); 122 } else if(this.m_propertyInstance.getName().equals("range")) { 123 this.m_helpIcon = new HelpIcon("Range", "The Range of a Property is description of its allowable Values."); 124 this.add(m_helpIcon); 125 } else { 126 this.m_helpIcon = new HelpIcon(this.m_propertyInstance.getDefinition()); 127 this.add(m_helpIcon); 128 } 129 } 130 } 131 132 133 134 137 public Dimension getPreferredSize() { 138 int nHeight = 0; 139 int nCount = this.getComponentCount(); 140 int nWidth = 0; 141 for(int i=0; i<nCount; i++) { 142 Component comp = this.getComponent(i); 143 int nDepth = comp.getLocation().y + comp.getPreferredSize().height; 144 int nCurrWidth = comp.getLocation().x + comp.getPreferredSize().width; 145 if(nDepth > nHeight) { 146 nHeight = nDepth; 147 } 148 if(nCurrWidth > nWidth) { 149 nWidth = nCurrWidth; 150 } 151 } 152 153 if(this.m_bResizeWidth) { 154 return new Dimension( this.getParent().getWidth()-20, nHeight+5); 155 } else { 156 return new Dimension( nWidth, nHeight+5); 157 } 158 } 159 160 163 public void setEnabled(boolean bEnabled) { 164 for (int i = 0; i < this.getComponentCount(); i++) { 165 Component comp = this.getComponent(i); 166 comp.setEnabled(bEnabled); 167 } 168 super.setEnabled(bEnabled); 169 } 170 171 public AbstractRangeDisplay getRangeDisplay() { 172 for (int i = 0; i < this.getComponentCount(); i++) { 173 Component comp = this.getComponent(i); 174 if(comp instanceof AbstractRangeDisplay) { 175 return (AbstractRangeDisplay) comp; 176 } 177 } 178 return null; 179 } 180 183 public void layoutContainer(Container arg0) { 184 int nHeight = 35; 185 for (int i = 0; i < this.getComponentCount(); i++) { 186 Component comp = this.getComponent(i); 187 if(comp instanceof AbstractRangeDisplay) { 188 comp.setSize(comp.getPreferredSize()); 189 comp.setLocation(5, nHeight); 190 } else if(comp instanceof HelpIcon) { 191 comp.setSize(20, 20); 192 comp.setLocation(this.m_titleLabel.getPreferredSize().width+15, 10); 193 } else if(comp==this.m_titleLabel) { 194 comp.setSize(this.m_titleLabel.getPreferredSize().width, 30); 195 comp.setLocation(5, 5); 196 } 197 } 198 } 199 200 203 public void removeLayoutComponent(Component arg0) { 204 } 205 206 209 public void addLayoutComponent(String arg0, Component arg1) { 210 } 211 212 215 public Dimension minimumLayoutSize(Container arg0) { 216 return this.getPreferredSize(); 217 } 218 219 222 public Dimension preferredLayoutSize(Container arg0) { 223 return this.getPreferredSize(); 224 } 225 } 226 | Popular Tags |