| 1 19 package org.openharmonise.him.serverconfig.permissions.tree; 20 21 import java.awt.Color ; 22 import java.awt.Component ; 23 import java.awt.Container ; 24 import java.awt.Dimension ; 25 import java.awt.LayoutManager ; 26 import java.awt.event.MouseEvent ; 27 import java.awt.event.MouseListener ; 28 29 import javax.swing.Icon ; 30 import javax.swing.JCheckBox ; 31 import javax.swing.JLabel ; 32 import javax.swing.JPanel ; 33 import javax.swing.UIManager ; 34 35 import org.openharmonise.vfs.metadata.value.*; 36 37 38 45 public class PermissionsTreeCell 46 extends JPanel  47 implements MouseListener , LayoutManager { 48 49 52 private Icon m_icon = null; 53 54 57 private String m_sText = null; 58 59 62 private JLabel m_iconLabel = new JLabel (); 63 64 67 private JLabel m_textLabel = new JLabel (); 68 69 72 private JCheckBox m_checkBox = new JCheckBox (); 73 74 77 private PermissionsTreeNode m_node = null; 78 79 86 public PermissionsTreeCell(PermissionsTreeNode node, Icon icon, String sText) { 87 super(); 88 this.m_node = node; 89 this.m_icon = icon; 90 this.m_sText = sText; 91 this.setup(); 92 } 93 94 97 private PermissionsTreeCell(boolean arg0) { 98 super(arg0); 99 } 100 101 104 private PermissionsTreeCell(LayoutManager arg0) { 105 super(arg0); 106 } 107 108 112 private PermissionsTreeCell(LayoutManager arg0, boolean arg1) { 113 super(arg0, arg1); 114 } 115 116 120 private void setup() { 121 122 boolean bChecked = false; 123 124 this.setLayout(this); 125 this.setBackground(Color.WHITE); 126 this.m_textLabel.setFont( UIManager.getFont("Tree.font") ); 127 128 this.m_textLabel.setEnabled(this.m_node.getEnabled()); 129 130 this.m_iconLabel.setIcon(this.m_icon); 131 this.m_iconLabel.setPreferredSize(new Dimension (20,20)); 132 this.add(this.m_iconLabel); 133 if(this.m_node.isLeaf()) { 134 this.m_textLabel.setText(this.m_sText); 135 } else { 136 this.m_textLabel.setText(this.m_node.getDisplayName()); 137 } 138 this.m_textLabel.setPreferredSize(new Dimension (this.m_textLabel.getPreferredSize().width,20)); 139 this.add(this.m_textLabel); 140 this.m_checkBox.setPreferredSize(new Dimension (17,20)); 141 142 this.m_checkBox.setBackground(Color.WHITE); 143 if(this.m_node.isLeaf()) { 144 this.add(this.m_checkBox); 145 } 146 if(this.m_node.isLeaf()) { 147 ValueValue valInst = (ValueValue) this.m_node.getPropertyInstance().getNewValueInstance(); 148 valInst.setValue(this.m_node.getValue().getHREF()); 149 bChecked = this.m_node.getPropertyInstance().getValues().contains( valInst ); 150 if(bChecked) { 151 this.m_checkBox.setSelected(true); 152 } 153 } else if(!this.m_node.isLeaf()) { 154 155 } 156 } 157 158 159 160 163 public void removeLayoutComponent(Component arg0) { 164 } 165 166 169 public void layoutContainer(Container arg0) { 170 int nWidth = 0; 171 if(this.m_node.isLeaf()) { 172 this.m_checkBox.setSize( 20,20 ); 173 } 174 this.m_textLabel.setSize( this.m_textLabel.getPreferredSize() ); 175 this.m_iconLabel.setSize( this.m_iconLabel.getPreferredSize() ); 176 177 this.m_iconLabel.setLocation(0,0); 178 nWidth = nWidth + 17; 179 if(this.m_node.isLeaf()) { 180 this.m_checkBox.setLocation(nWidth,0); 181 nWidth = nWidth + 22; 182 } 183 this.m_textLabel.setLocation(nWidth,0); 184 } 185 186 189 public void addLayoutComponent(String arg0, Component arg1) { 190 } 191 192 195 public Dimension minimumLayoutSize(Container arg0) { 196 return this.getPreferredSize(); 197 } 198 199 202 public Dimension preferredLayoutSize(Container arg0) { 203 return this.getPreferredSize(); 204 } 205 206 209 public Dimension getPreferredSize() { 210 int nWidth = this.m_checkBox.getPreferredSize().width + this.m_iconLabel.getPreferredSize().width + this.m_textLabel.getPreferredSize().width; 211 return new Dimension (nWidth+3, 20); 212 } 213 214 217 public void mouseClicked(MouseEvent me) { 218 if(me.getPoint().x > this.m_checkBox.getLocation().x 219 && me.getPoint().x < this.m_checkBox.getLocation().x + this.m_checkBox.getWidth() 220 && me.getPoint().y > this.m_checkBox.getLocation().y 221 && me.getPoint().y < this.m_checkBox.getLocation().y + this.m_checkBox.getHeight()) { 222 if(this.m_checkBox.isSelected()) { 223 this.m_checkBox.setSelected(false); 224 } else { 225 this.m_checkBox.setSelected(true); 226 } 227 } 228 } 229 230 233 public void mouseEntered(MouseEvent arg0) { 234 } 235 236 239 public void mouseExited(MouseEvent arg0) { 240 } 241 242 245 public void mousePressed(MouseEvent arg0) { 246 } 247 248 251 public void mouseReleased(MouseEvent arg0) { 252 } 253 254 } 255 | Popular Tags |