1 19 package org.openharmonise.him.window.session; 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.Font ; 26 import java.awt.LayoutManager ; 27 import java.awt.event.MouseEvent ; 28 import java.awt.event.MouseListener ; 29 import java.text.SimpleDateFormat ; 30 import java.util.Date ; 31 32 import javax.swing.JLabel ; 33 import javax.swing.JPanel ; 34 35 import org.openharmonise.swing.FontManager; 36 import org.openharmonise.vfs.*; 37 import org.openharmonise.vfs.event.*; 38 import org.openharmonise.vfs.gui.*; 39 40 41 47 public class SessionEntry extends JPanel implements VirtualFileListener, LayoutManager , MouseListener { 48 49 private AbstractVirtualFileSystem m_vfs = null; 50 private String m_sPath = null; 51 52 private JLabel m_iconNameLabel = null; 53 private JLabel m_syncIcon = null; 54 55 int m_nWidth = 0; 56 57 private Color m_selectedColor = new Color (173,169,143); 58 private boolean m_bSelected = false; 59 60 private SessionInformation m_parent = null; 61 62 private String m_sReason = null; 63 66 public SessionEntry(SessionInformation parent, VirtualFile vfFile, String sReason) { 67 super(); 68 this.m_parent = parent; 69 this.m_sReason = sReason; 70 this.setup(vfFile); 71 } 72 73 private void setup(VirtualFile vfFile) { 74 this.setLayout(this); 75 this.setBackground(Color.WHITE); 76 77 String sDisplayName = ""; 78 if(vfFile!=null) { 79 this.m_vfs = vfFile.getVFS(); 80 this.m_sPath = vfFile.getFullPath(); 81 82 VirtualFile vfDisplay = vfFile.getVFS().getVirtualFile( ((VersionedVirtualFile)vfFile).getLogicalPath() ).getResource(); 83 sDisplayName = vfDisplay.getVFS().getVirtualFileSystemView().getDisplayName(vfDisplay); 84 } 85 86 87 91 Date dt = new Date (); 92 SimpleDateFormat formatter = new SimpleDateFormat ("HH:mm"); 93 94 this.m_iconNameLabel = new JLabel (sDisplayName + " - " + this.m_sReason + " at " + formatter.format(dt)); 95 this.m_iconNameLabel.setFont( FontManager.getInstance().getFont(FontManager.FONT_RESOURCE_TITLE) ); 96 if(vfFile!=null) { 97 this.m_iconNameLabel.setIcon( vfFile.getVFS().getVirtualFileSystemView().getIcon(vfFile) ); 98 } else { 99 this.m_iconNameLabel.setIcon( IconManager.getInstance().getIcon("16-document.gif") ); 100 } 101 this.m_iconNameLabel.addMouseListener(this); 102 this.add(this.m_iconNameLabel); 103 104 this.m_syncIcon = new JLabel (); 105 if(vfFile!=null && vfFile.isChanged()) { 106 this.m_syncIcon.setIcon( IconManager.getInstance().getIcon("16-command-sync-all.gif") ); 107 } else { 108 this.m_syncIcon.setIcon( IconManager.getInstance().getIcon("16-blank.gif") ); 109 } 110 this.m_syncIcon.addMouseListener(this); 111 this.add(this.m_syncIcon); 112 } 113 114 protected boolean isVirtualFileChanged() { 115 if(this.m_vfs!=null && this.m_sPath!=null) { 116 if(this.m_vfs.getVirtualFile(this.m_sPath).getResource().isChanged()) { 117 return true; 118 } else { 119 return false; 120 } 121 } else { 122 return false; 123 } 124 } 125 126 129 public void mouseClicked(MouseEvent arg0) { 130 if(this.m_bSelected) { 131 } else { 133 this.selectEntry(); 134 } 135 } 136 137 public AbstractVirtualFileSystem getVFS() { 138 return this.m_vfs; 139 } 140 141 public String getReason() { 142 return this.m_sReason; 143 } 144 145 public String getPath() { 146 return this.m_sPath; 147 } 148 149 public boolean isSelected() { 150 return this.m_bSelected; 151 } 152 153 protected void selectEntry() { 154 this.setBackground(this.m_selectedColor); 155 this.m_bSelected = true; 156 this.m_parent.entrySelected(this); 157 } 158 159 protected void deselectEntry() { 160 this.setBackground(Color.WHITE); 161 this.m_bSelected = false; 162 } 163 164 167 public void removeLayoutComponent(Component arg0) { 168 } 170 171 174 public void layoutContainer(Container arg0) { 175 m_nWidth = this.getParent().getParent().getParent().getWidth()-20; 176 this.m_iconNameLabel.setSize(this.getParent().getParent().getParent().getWidth()-40, 20); 177 this.m_iconNameLabel.setLocation(0,0); 178 179 this.m_syncIcon.setSize(20,20); 180 this.m_syncIcon.setLocation(this.getParent().getParent().getParent().getWidth()-40,0); 181 } 182 183 186 public Dimension getPreferredSize() { 187 return new Dimension (m_nWidth, 20); 188 } 189 190 193 public void addLayoutComponent(String arg0, Component arg1) { 194 } 196 197 200 public Dimension minimumLayoutSize(Container arg0) { 201 return this.getPreferredSize(); 202 } 203 204 207 public Dimension preferredLayoutSize(Container arg0) { 208 return new Dimension (m_nWidth, 20); 209 } 210 211 214 private SessionEntry(boolean arg0) { 215 super(arg0); 216 } 217 218 221 private SessionEntry(LayoutManager arg0) { 222 super(arg0); 223 } 224 225 229 private SessionEntry(LayoutManager arg0, boolean arg1) { 230 super(arg0, arg1); 231 } 232 233 236 public void mouseEntered(MouseEvent arg0) { 237 } 238 239 242 public void mouseExited(MouseEvent arg0) { 243 } 244 245 248 public void mousePressed(MouseEvent arg0) { 249 } 250 251 254 public void mouseReleased(MouseEvent arg0) { 255 } 256 257 260 public void virtualFileChanged(VirtualFileEvent vfe) { 261 } 262 } 263 | Popular Tags |