1 19 package org.openharmonise.him.metadata.range.swing.range.details; 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.him.window.messages.*; 29 import org.openharmonise.vfs.*; 30 31 32 37 public class RangeSelectionList extends JPanel 38 implements MouseListener, LayoutManager { 39 40 private Object [] m_values = null; 41 42 private JPanel m_list = null; 43 44 private JScrollPane m_scroller = null; 45 46 private int m_nHeight = 0; 47 48 private int m_nWidth = 150; 49 50 53 public RangeSelectionList() { 54 super(); 55 this.setup(); 56 } 57 58 public RangeSelectionList(Object [] vals) { 59 super(); 60 m_values = vals; 61 this.setup(); 62 } 63 64 67 private RangeSelectionList(boolean arg0) { 68 super(arg0); 69 } 70 71 74 private RangeSelectionList(LayoutManager arg0) { 75 super(arg0); 76 } 77 78 82 private RangeSelectionList(LayoutManager arg0, boolean arg1) { 83 super(arg0, arg1); 84 } 85 86 private void setup() { 87 this.setLayout(new BorderLayout()); 88 89 90 this.setBackground(Color.WHITE); 91 92 m_list = new JPanel(); 93 m_list.setLayout(this); 94 95 m_scroller = new JScrollPane(m_list, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 96 m_scroller.setPreferredSize(new Dimension(270,300)); 97 m_scroller.setBorder(BorderFactory.createEmptyBorder()); 98 99 this.add(m_scroller); 100 this.validate(); 101 } 102 103 public String getSelectedPath() { 104 for(int i=0; i<m_list.getComponentCount(); i++) { 105 if((m_list.getComponent(i) instanceof RangeSelectionCell)) { 106 if( ((RangeSelectionCell)m_list.getComponent(i)).isSelected() ) { 107 return ((RangeSelectionCell)m_list.getComponent(i)).getPath(); 108 } 109 } 110 } 111 return null; 112 } 113 114 117 public void removeLayoutComponent(Component arg0) { 118 } 119 120 123 public void layoutContainer(Container container) { 124 int nCount = container.getComponentCount(); 125 int nHeight = 0; 126 127 nCount = container.getComponentCount(); 128 for(int i=0; i<nCount; i++) { 129 Component comp = container.getComponent(i); 130 comp.setSize(comp.getPreferredSize()); 131 comp.setLocation(0, nHeight); 132 nHeight = nHeight + comp.getPreferredSize().height; 133 } 134 if(nHeight!=this.m_nHeight) { 135 this.m_nHeight = nHeight; 136 if(nHeight>300) { 137 ((JPanel)container).setPreferredSize(new Dimension(m_nWidth, nHeight)); 138 this.m_scroller.validate(); 139 } else { 140 ((JPanel)container).setPreferredSize(new Dimension(m_nWidth,300)); 141 this.m_scroller.validate(); 142 } 143 } 144 } 145 146 147 148 149 152 public void addLayoutComponent(String arg0, Component arg1) { 153 } 154 155 158 public Dimension minimumLayoutSize(Container arg0) { 159 return new Dimension(m_nWidth, this.m_values.length*20); 160 } 161 162 165 public Dimension preferredLayoutSize(Container arg0) { 166 return new Dimension(m_nWidth, this.m_values.length*20); 167 } 168 169 170 173 public Dimension getPreferredSize() { 174 return new Dimension(300,300); 175 } 176 177 public void removeFile(String sPath) { 178 for(int i=0; i<m_list.getComponentCount(); i++) { 179 if((m_list.getComponent(i) instanceof RangeSelectionCell)) { 180 if( ((RangeSelectionCell)m_list.getComponent(i)).getPath().equals(sPath) ) { 181 this.m_list.remove(m_list.getComponent(i)); 182 } 183 } 184 } 185 this.validateTree(); 186 this.repaint(); 187 } 188 189 public void removeSelected() { 190 for(int i=0; i<m_list.getComponentCount(); i++) { 191 if((m_list.getComponent(i) instanceof RangeSelectionCell)) { 192 if( ((RangeSelectionCell)m_list.getComponent(i)).isSelected() ) { 193 this.m_list.remove(m_list.getComponent(i)); 194 } 195 } 196 } 197 this.validateTree(); 198 this.repaint(); 199 } 200 201 204 public void mouseClicked(MouseEvent me) { 205 if(me.getSource() instanceof RangeSelectionCell) { 206 RangeSelectionCell cell = (RangeSelectionCell) me.getSource(); 207 for(int i=0; i<m_list.getComponentCount(); i++) { 208 if((m_list.getComponent(i) instanceof RangeSelectionCell)) { 209 ((RangeSelectionCell)m_list.getComponent(i)).setSelected(false); 210 } 211 } 212 if ( (me.getModifiersEx() & (MouseEvent.CTRL_DOWN_MASK)) == MouseEvent.CTRL_DOWN_MASK) { 213 cell.setSelected(false); 214 } else { 215 cell.setSelected(true); 216 } 217 } 218 this.validateTree(); 219 this.repaint(); 220 } 221 222 225 public void mouseEntered(MouseEvent arg0) { 226 } 227 228 231 public void mouseExited(MouseEvent arg0) { 232 } 233 234 237 public void mousePressed(MouseEvent arg0) { 238 } 239 240 243 public void mouseReleased(MouseEvent arg0) { 244 } 245 246 public void addFile(String sPath, AbstractVirtualFileSystem vfs) { 247 ArrayList aReasons = new ArrayList(); 248 249 try { 250 RangeSelectionCell cell = new RangeSelectionCell(this, sPath, vfs); 251 boolean bFound = false; 252 for(int i=0; i<m_list.getComponentCount(); i++) { 253 if((m_list.getComponent(i) instanceof RangeSelectionCell) && ((RangeSelectionCell)m_list.getComponent(i)).equals(cell)) { 254 bFound=true; 255 } 256 } 257 if(!bFound) { 258 cell.addMouseListener(this); 259 m_list.add(cell); 260 } 261 } catch(NullPointerException npe) { 262 MessageHandler.getInstance().fireMessageEvent("One of the Sections for this Range has not been found.", MessageHandler.TYPE_ERROR); 263 } 264 265 this.validateTree(); 266 267 m_scroller.validate(); 268 } 269 270 public List getPaths() { 271 ArrayList aPaths = new ArrayList(); 272 for(int i=0; i<m_list.getComponentCount(); i++) { 273 if((m_list.getComponent(i) instanceof RangeSelectionCell)) { 274 aPaths.add( ((RangeSelectionCell)m_list.getComponent(i)).getPath() ); 275 } 276 } 277 return aPaths; 278 } 279 280 } 281 282 | Popular Tags |