1 19 package org.openharmonise.him.swing.resourcetree.formresourcetree; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.util.*; 24 import java.util.List ; 25 26 import javax.swing.*; 27 28 import org.openharmonise.swing.FontManager; 29 import org.openharmonise.vfs.*; 30 import org.openharmonise.vfs.metadata.*; 31 import org.openharmonise.vfs.metadata.range.*; 32 import org.openharmonise.vfs.metadata.value.*; 33 34 35 42 public class FormTreeCell extends JPanel implements MouseListener, LayoutManager { 43 44 47 protected Icon m_icon = null; 48 49 52 protected String m_sText = null; 53 54 57 protected JLabel m_iconLabel = new JLabel(); 58 59 62 protected JLabel m_textLabel = new JLabel(); 63 64 67 private JToggleButton m_checkBox = null; 68 69 72 private FormResourceTree m_tree = null; 73 74 77 private String m_sFullPath = null; 78 79 82 private boolean m_bIsLeaf = false; 83 84 87 private boolean m_bIsChildrenPopulated = false; 88 89 93 public FormTreeCell() { 94 super(); 95 } 96 97 108 public FormTreeCell(FormResourceTree tree, String sFullPath, Icon icon, String sText, JToggleButton checkBox, boolean bIsLeaf, boolean bIsChildrenPopulated) { 109 super(); 110 this.m_sFullPath = sFullPath; 111 this.m_tree = tree; 112 this.m_icon = icon; 113 this.m_sText = sText; 114 this.m_checkBox = checkBox; 115 this.m_bIsLeaf = bIsLeaf; 116 this.m_bIsChildrenPopulated = bIsChildrenPopulated; 117 this.setup(); 118 } 119 120 123 private FormTreeCell(boolean arg0) { 124 super(arg0); 125 } 126 127 130 private FormTreeCell(LayoutManager arg0) { 131 super(arg0); 132 } 133 134 138 private FormTreeCell(LayoutManager arg0, boolean arg1) { 139 super(arg0, arg1); 140 } 141 142 146 protected void setup() { 147 148 VirtualFile vfFile = this.m_tree.getVFS().getVirtualFile(m_sFullPath).getResource(); 149 if(vfFile.isVirtualDirectory() && !this.m_tree.isAllowVirtualDirectorySelect()) { 150 this.m_checkBox=null; 151 } 152 153 boolean bBoldText = false; 154 155 if(this.m_bIsLeaf || !this.m_tree.isShowLeafNodes()) { 156 if(this.m_tree.getPathValues().contains(this.m_sFullPath)) { 157 this.m_checkBox.setSelected(true); 158 bBoldText = true; 159 } 160 } 161 162 if(!this.m_bIsLeaf) { 163 Iterator itor = this.m_tree.getPathValues().iterator(); 164 while (itor.hasNext()) { 165 String sPath = (String ) itor.next(); 166 if(sPath.startsWith(this.m_sFullPath) && sPath.replaceFirst(this.m_sFullPath, "").indexOf("/")==0) { 167 bBoldText=true; 168 break; 169 } 170 } 171 } 172 173 boolean bChecked = false; 174 175 if(this.m_checkBox!=null) { 176 this.addMouseListener(this); 177 } 178 179 this.m_tree.addCell(this); 180 181 this.setLayout(this); 182 this.setBackground(Color.WHITE); 183 184 if(bBoldText) { 185 this.m_textLabel.setFont( FontManager.getInstance().getFont( FontManager.FONT_RESOURCE_TITLE_BOLD ) ); 188 } else { 189 this.m_textLabel.setFont( FontManager.getInstance().getFont( FontManager.FONT_RESOURCE_TITLE ) ); 191 } 192 193 this.m_textLabel.setEnabled(this.m_tree.isEnabled()); 194 195 this.m_iconLabel.setIcon(this.m_icon); 196 this.m_iconLabel.setPreferredSize(new Dimension(20,20)); 197 this.add(this.m_iconLabel); 198 this.m_textLabel.setText(this.m_sText); 199 this.m_textLabel.setPreferredSize(new Dimension(this.m_textLabel.getPreferredSize().width,20)); 200 this.add(this.m_textLabel); 201 if(this.m_checkBox!=null) { 202 this.m_checkBox.setPreferredSize(new Dimension(17,20)); 203 204 this.m_checkBox.setBackground(Color.WHITE); 205 this.add(this.m_checkBox); 206 } 207 } 208 209 212 public void removeLayoutComponent(Component arg0) { 213 } 214 215 218 public void layoutContainer(Container arg0) { 219 220 this.m_iconLabel.setSize( this.m_iconLabel.getPreferredSize() ); 221 this.m_iconLabel.setLocation(0,0); 222 223 int xPos = 18; 224 if(this.m_checkBox!=null) { 225 this.m_checkBox.setSize( 20,20 ); 226 this.m_checkBox.setLocation(16,0); 227 xPos = 38; 228 } 229 230 this.m_textLabel.setSize( this.m_textLabel.getPreferredSize() ); 231 this.m_textLabel.setLocation(xPos,0); 232 } 233 234 237 public void addLayoutComponent(String arg0, Component arg1) { 238 } 239 240 243 public Dimension minimumLayoutSize(Container arg0) { 244 return this.getPreferredSize(); 245 } 246 247 250 public Dimension preferredLayoutSize(Container arg0) { 251 return this.getPreferredSize(); 252 } 253 254 257 public Dimension getPreferredSize() { 258 int nWidth = 3; 259 if(this.m_checkBox!=null) { 260 nWidth = nWidth + this.m_checkBox.getPreferredSize().width; 261 } 262 nWidth = nWidth + this.m_iconLabel.getPreferredSize().width + this.m_textLabel.getPreferredSize().width; 263 return new Dimension(nWidth, 20); 264 } 265 266 269 public void mouseClicked(MouseEvent me) { 270 if(this.m_checkBox!=null) { 271 VirtualFile vfFile = this.m_tree.getVFS().getVirtualFile(m_sFullPath).getResource(); 272 if(this.m_tree.isAllowVirtualDirectorySelect() || !vfFile.isVirtualDirectory()) { 273 if(this.m_checkBox.isSelected()) { 274 this.m_checkBox.setSelected(false); 275 this.m_tree.cellUnSelected(m_sFullPath); 276 } else { 277 this.m_checkBox.setSelected(true); 278 this.m_tree.cellSelected(m_sFullPath); 279 } 280 m_tree.revalidate(); 281 m_tree.repaint(); 282 } 283 } 284 } 285 286 289 public void mouseEntered(MouseEvent arg0) { 290 } 291 292 295 public void mouseExited(MouseEvent arg0) { 296 } 297 298 301 public void mousePressed(MouseEvent arg0) { 302 } 303 304 307 public void mouseReleased(MouseEvent arg0) { 308 } 309 310 315 public String getFullPath() { 316 return this.m_sFullPath; 317 } 318 319 324 public void setSelected(boolean bSelected) { 325 if(this.m_checkBox!=null) { 326 this.m_checkBox.setSelected(bSelected); 327 } 328 } 329 330 335 protected boolean isChildrenPopulated() { 336 return this.m_bIsChildrenPopulated; 337 } 338 339 344 protected boolean isLeaf() { 345 return this.m_bIsLeaf; 346 } 347 } 348 | Popular Tags |