1 19 package org.openharmonise.him.editors.pagegui; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 24 import javax.swing.*; 25 26 import org.openharmonise.swing.FontManager; 27 import org.openharmonise.vfs.*; 28 import org.openharmonise.vfs.gui.*; 29 30 31 38 public class ResourceDisplayPanel extends JPanel implements LayoutManager, MouseListener { 39 40 43 private String m_sFilePath = null; 44 45 48 private AbstractVirtualFileSystem m_vfs = null; 49 50 53 private Color m_selectedColor = new Color(173,169,143); 54 55 58 private JLabel m_label = null; 59 60 63 public ResourceDisplayPanel() { 64 super(); 65 this.setup(); 66 } 67 68 72 private void setup() { 73 this.setLayout(this); 74 this.setBorder(BorderFactory.createEtchedBorder()); 75 this.setBackground(Color.WHITE); 76 this.m_label = new JLabel(); 77 this.m_label.addMouseListener(this); 78 this.m_label.setIcon( IconManager.getInstance().getIcon("16-blank.gif") ); 79 this.m_label.setFont( FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE) ); 80 this.add(m_label); 81 } 82 83 88 public void setVirtualFile(VirtualFile vfFile) { 89 if(vfFile!=null) { 90 this.m_sFilePath = vfFile.getFullPath(); 91 this.m_vfs = vfFile.getVFS(); 92 VirtualFileSystemView vfsView = this.m_vfs.getVirtualFileSystemView(); 93 94 this.m_label.setText( vfsView.getDisplayName(vfFile) ); 95 this.m_label.setIcon( vfsView.getIcon(vfFile) ); 96 } else { 97 this.m_sFilePath = null; 98 this.m_vfs = null; 99 100 this.m_label.setText( "" ); 101 this.m_label.setIcon( IconManager.getInstance().getIcon("16-blank.gif") ); 102 } 103 104 this.setSelected(false); 105 106 this.validateTree(); 107 this.repaint(); 108 } 109 110 115 public VirtualFile getVirtualFile() { 116 if(this.m_vfs!=null && this.m_sFilePath!=null) { 117 return this.m_vfs.getVirtualFile(m_sFilePath).getResource(); 118 } else { 119 return null; 120 } 121 } 122 123 126 public void mouseClicked(MouseEvent ae) { 127 if(ae.getSource()==this.m_label) { 128 if(this.getBackground()==Color.WHITE) { 129 this.setSelected(true); 130 } else { 131 this.setSelected(false); 132 } 133 this.validateTree(); 134 this.repaint(); 135 } 136 } 137 138 143 private void setSelected(boolean bSelected) { 144 if(bSelected) { 145 this.setBackground(this.m_selectedColor); 146 this.m_label.setBackground(this.m_selectedColor); 147 } else { 148 this.setBackground(Color.WHITE); 149 this.m_label.setBackground(Color.WHITE); 150 } 151 } 152 153 158 public boolean isSelected() { 159 return this.getBackground()==this.m_selectedColor; 160 } 161 162 165 public void layoutContainer(Container arg0) { 166 this.m_label.setSize(this.getSize()); 167 this.m_label.setLocation(0, 0); 168 } 169 170 173 private ResourceDisplayPanel(boolean arg0) { 174 super(arg0); 175 } 176 177 180 private ResourceDisplayPanel(LayoutManager arg0) { 181 super(arg0); 182 } 183 184 188 private ResourceDisplayPanel(LayoutManager arg0, boolean arg1) { 189 super(arg0, arg1); 190 } 191 192 195 public void addLayoutComponent(String arg0, Component arg1) { 196 } 197 198 201 public void removeLayoutComponent(Component arg0) { 202 } 203 204 207 public Dimension minimumLayoutSize(Container arg0) { 208 return this.getPreferredSize(); 209 } 210 211 214 public Dimension preferredLayoutSize(Container arg0) { 215 return this.getPreferredSize(); 216 } 217 218 221 public Dimension getPreferredSize() { 222 return new Dimension(100, 20); 223 } 224 225 228 public void mouseEntered(MouseEvent arg0) { 229 } 230 231 234 public void mouseExited(MouseEvent arg0) { 235 } 236 237 240 public void mousePressed(MouseEvent arg0) { 241 } 242 243 246 public void mouseReleased(MouseEvent arg0) { 247 } 248 249 } 250 | Popular Tags |