1 54 55 package swingwtx.swing; 56 57 import java.beans.PropertyChangeEvent ; 58 import java.beans.PropertyChangeListener ; 59 import java.io.File ; 60 import java.util.Vector ; 61 62 import org.eclipse.swt.SWT; 63 64 import swingwt.awt.BorderLayout; 65 import swingwt.awt.Component; 66 import swingwt.awt.Dimension; 67 import swingwt.awt.FlowLayout; 68 import swingwt.awt.Frame; 69 import swingwt.awt.GridLayout; 70 import swingwt.awt.event.ActionEvent; 71 import swingwt.awt.event.ActionListener; 72 import swingwt.awt.event.ItemEvent; 73 import swingwt.awt.event.ItemListener; 74 import swingwt.awt.event.MouseAdapter; 75 import swingwt.awt.event.MouseEvent; 76 77 78 94 public class JFileChooser extends JPanel { 95 96 public static final int OPEN_DIALOG = 0; 97 public static final int SAVE_DIALOG = 1; 98 public static final int CUSTOM_DIALOG = 2; 99 100 public static final int CANCEL_OPTION = 1; 101 public static final String CANCEL_SELECTION = "CANCEL"; 102 public static final int APPROVE_OPTION = 0; 103 104 public static final int ERROR_OPTION = -1; 105 public static final int FILES_ONLY = 0; 106 public static final int DIRECTORIES_ONLY = 1; 107 public static final int FILES_AND_DIRECTORIES = 2; 108 109 public static final String ACCESSORY_CHANGED_PROPERTY = "AccessoryChangedProperty"; 111 public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY = "acceptAllFileFilterUsedChanged"; 112 public static final String DIALOG_TITLE_CHANGED_PROPERTY = "DialogTitleChangedProperty"; 113 public static final String DIALOG_TYPE_CHANGED_PROPERTY = "DialogTypeChangedProperty"; 114 public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY = "ChoosableFileFilterChangedProperty"; 115 public static final String FILE_VIEW_CHANGED_PROPERTY = "fileViewChanged"; 116 public static final String FILE_HIDING_CHANGED_PROPERTY = "FileHidingChanged"; 117 public static final String FILE_FILTER_CHANGED_PROPERTY = "fileFilterChanged"; 118 public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY = "fileSelectionChanged"; 119 public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY = "ApproveButtonTextChangedProperty"; 120 public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY = "ApproveButtonToolTipTextChangedProperty"; 121 public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY = "ApproveButtonMnemonicChangedProperty"; 122 public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY = "ControlButtonsAreShownChangedProperty"; 123 public static final String DIRECTORY_CHANGED_PROPERTY = "directoryChanged"; 124 public static final String SELECTED_FILE_CHANGED_PROPERTY = "SelectedFileChangedProperty"; 125 public static final String SELECTED_FILES_CHANGED_PROPERTY = "SelectedFilesChangedProperty"; 126 public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY = "MultiSelectionEnabledChangedProperty"; 127 public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY = "FileSystemViewChanged"; 128 129 protected int dialogType = OPEN_DIALOG; 130 protected String dialogTitle = ""; 131 protected int fileSelection = FILES_ONLY; 132 protected File curPath = new File (""); 133 protected File curFile = new File (""); 134 protected File [] curFiles = null; 135 protected boolean multiSelect = false; 136 protected String [] filters = null; 137 protected String [] filterNames = null; 138 139 protected Vector fileFilters = new Vector (); 140 141 152 public boolean useNative = true; 153 154 protected JTextField location = null; 157 protected JComboBox filter = null; 158 protected JPanel centralPanel = null; 159 protected JList fileList = null; 160 protected JPanel buttonPanel = null; 161 protected JButton okButton = null; 162 protected JComponent fcAccessory = null; 163 protected FileChooserDialog customDialog = null; 164 protected int dialogReturnValue = CANCEL_OPTION; 165 protected JFileChooser.FileFilterWrapper allFiles = null; 166 167 168 public JFileChooser() {this(new File ("")); } 169 public JFileChooser(String currentDirectoryPath) { 170 this(new File (currentDirectoryPath)); 171 } 172 public JFileChooser(File currentDirectory) { 173 curPath = currentDirectory; 174 layoutComponent(); 175 } 176 177 public File getSelectedFile() { return curFile; } 178 public void setSelectedFile(File file) { curFile = file; ensureFileIsVisible(file); } 179 180 public File [] getSelectedFiles() { return curFiles; } 181 public void setSelectedFiles(File [] selectedFiles) { curFiles = selectedFiles; } 182 183 public File getCurrentDirectory() { return curPath; } 184 public void setCurrentDirectory(File dir) { curPath = dir; ensureFileIsVisible(dir); } 185 public void changeToParentDirectory() { setCurrentDirectory(curPath.getParentFile()); } 186 187 199 public void scanDrives(JComboBox driveBox) { 200 201 if (SwingWTUtils.isWindows()) { 202 driveBox.addItem(new DriveEntry(new File ("A:"), "Floppy Disk (A:)")); 205 checkDriveEntry("C:", "Disk (C:)", driveBox); 206 checkDriveEntry("D:", "Disk (D:)", driveBox); 207 checkDriveEntry("E:", "Disk (E:)", driveBox); 208 checkDriveEntry("F:", "Disk (F:)", driveBox); 209 checkDriveEntry("G:", "Network Disk (G:)", driveBox); 210 checkDriveEntry("H:", "Network Disk (H:)", driveBox); 211 checkDriveEntry("I:", "Network Disk (I:)", driveBox); 212 checkDriveEntry("J:", "Network Disk (J:)", driveBox); 213 checkDriveEntry("K:", "Network Disk (K:)", driveBox); 214 checkDriveEntry("L:", "Network Disk (L:)", driveBox); 215 checkDriveEntry("M:", "Network Disk (M:)", driveBox); 216 checkDriveEntry("N:", "Network Disk (N:)", driveBox); 217 checkDriveEntry("O:", "Network Disk (O:)", driveBox); 218 checkDriveEntry("P:", "Network Disk (P:)", driveBox); 219 checkDriveEntry("Q:", "Network Disk (Q:)", driveBox); 220 checkDriveEntry("R:", "Network Disk (R:)", driveBox); 221 checkDriveEntry("S:", "Network Disk (S:)", driveBox); 222 checkDriveEntry("T:", "Network Disk (T:)", driveBox); 223 checkDriveEntry("U:", "Network Disk (U:)", driveBox); 224 checkDriveEntry("V:", "Network Disk (V:)", driveBox); 225 checkDriveEntry("W:", "Network Disk (W:)", driveBox); 226 checkDriveEntry("X:", "Network Disk (X:)", driveBox); 227 checkDriveEntry("Y:", "Network Disk (Y:)", driveBox); 228 checkDriveEntry("Z:", "Network Disk (Z:)", driveBox); 229 driveBox.setSelectedIndex(1); 232 } 233 else 234 { 235 checkDriveEntry("/", "Root (/)", driveBox); 236 checkDriveEntry("/mnt/auto", "Automatic Mount (/mnt/auto)", driveBox); 237 checkDriveEntry("/mnt/floppy", "Floppy Disk (/mnt/floppy)", driveBox); 238 checkDriveEntry("/cdrom", "CDROM (/cdrom)", driveBox); 239 checkDriveEntry("/cdrom1", "CDROM (/cdrom1)", driveBox); 240 checkDriveEntry("/mnt/cdrom", "CDROM (/mnt/cdrom)", driveBox); 241 checkDriveEntry("/mnt/dvd", "DVD ROM (/mnt/dvd)", driveBox); 242 checkDriveEntry("/mnt/windows", "Windows Disk (/mnt/windows)", driveBox); 243 checkDriveEntry("/mnt/win_c", "Windows Disk (/mnt/win_c)", driveBox); 244 checkDriveEntry("/mnt/win_d", "Windows Disk (/mnt/win_d)", driveBox); 245 checkDriveEntry("/mnt/removable", "Removable Device (/mnt/removable)", driveBox); 246 checkDriveEntry("/mnt/zip", "Zip Disk (/mnt/zip)", driveBox); 247 } 248 249 } 250 251 256 protected void checkDriveEntry(String path, String displayName, JComboBox driveBox) { 257 try { 258 File f = new File (path); 259 if (f.exists()) 260 driveBox.addItem(new DriveEntry(f, displayName)); 261 } 262 catch (Exception e) {} 263 } 264 265 268 public void rescanCurrentDirectory() { 269 270 if (filter == null) return; 272 273 try { 274 275 File loc = new File (curFile.getAbsolutePath()); 276 277 if (!loc.isDirectory()) 279 loc = curFile.getParentFile(); 280 281 if (loc == null) return; 284 285 File [] fulldir = loc.listFiles(); 287 Vector matches = new Vector (); 288 JFileChooser.FileFilterWrapper w = (JFileChooser.FileFilterWrapper) filter.getSelectedItem(); 289 swingwtx.swing.filechooser.FileFilter theFilter = null; 290 if (w != null) theFilter = w.getFilter(); 291 292 for (int i = 0; i < fulldir.length; i++) { 293 if (fulldir[i].getName().startsWith(".")){} 294 else if (theFilter == null) 296 matches.add(fulldir[i]); 297 else if (theFilter.accept(fulldir[i])) 298 matches.add(fulldir[i]); 299 } 300 301 boolean needsParent = (loc.getParentFile() != null); 302 303 File [] filteredDir = null; 304 305 int noFiles = ( needsParent ? matches.size() + 1 : matches.size() ); 306 filteredDir = new File [noFiles]; 307 308 if (needsParent) 310 filteredDir[0] = curFile.getAbsoluteFile().getParentFile(); 311 312 for (int i = 0; i < matches.size(); i++) { 313 if (needsParent) 314 filteredDir[i + 1] = (File ) matches.get(i); 315 else 316 filteredDir[i] = (File ) matches.get(i); 317 } 318 319 sortFiles(filteredDir); 321 322 fileList.setListData( filteredDir ); 324 325 } 326 catch (StringIndexOutOfBoundsException e) { 327 e.printStackTrace(); 332 } 333 334 } 335 336 public void ensureFileIsVisible(File f) { } 337 338 public boolean getControlButtonsAreShown() { return buttonPanel.getParent() != null; } 339 public void setControlButtonsAreShown(boolean b) { 340 if (b) 341 add(buttonPanel, BorderLayout.SOUTH); 342 else 343 remove(buttonPanel); 344 } 345 public int getDialogType() { return dialogType; } 346 public void setDialogType(int dialogType) { this.dialogType = dialogType; } 347 public void setDialogTitle(String dialogTitle) { this.dialogTitle = dialogTitle; } 348 public void setApproveButtonToolTipText(String toolTipText) { okButton.setToolTipText(toolTipText); } 349 public String getApproveButtonToolTipText() { return okButton.getToolTipText(); } 350 public void setApproveButtonMnemonic(int mnemonic) { okButton.setMnemonic(mnemonic); } 351 public void setApproveButtonMnemonic(char mnemonic) { okButton.setMnemonic(mnemonic); } 352 public void setApproveButtonText(String approveButtonText) { okButton.setText(approveButtonText); } 353 public String getApproveButtonText() { return okButton.getText(); } 354 public JComponent getAccessory() { return fcAccessory; } 355 public void setAccessory(JComponent newAccessory) { useNative = false; fcAccessory = newAccessory; centralPanel.add(newAccessory, BorderLayout.EAST); } 356 public void setFileSelectionMode(int mode) { fileSelection = mode; } 357 public int getFileSelectionMode() { return fileSelection; } 358 public boolean isFileSelectionEnabled() {return (fileSelection == FILES_ONLY || fileSelection == FILES_AND_DIRECTORIES);} 359 public boolean isDirectorySelectionEnabled() { return (fileSelection == FILES_AND_DIRECTORIES || fileSelection == DIRECTORIES_ONLY);} 360 public void setMultiSelectionEnabled(boolean b) { multiSelect = b; } 361 public boolean isMultiSelectionEnabled() { return multiSelect; } 362 public boolean isFileHidingEnabled() { return false;} 363 public void setFileHidingEnabled(boolean b) {} 364 365 373 public void setExtensionFilters(String [] extensions, String [] names) { 374 filters = extensions; 375 filterNames = names; 376 } 377 378 public void setFileFilter(swingwtx.swing.filechooser.FileFilter fileFilter) { 379 useNative = false; 380 FileFilterWrapper wrapper = new FileFilterWrapper(fileFilter); 381 filter.addItem(wrapper); 382 filter.setSelectedItem(wrapper); 383 } 384 385 public swingwtx.swing.filechooser.FileFilter getFileFilter() { return (swingwtx.swing.filechooser.FileFilter) filter.getSelectedItem(); } 386 public swingwtx.swing.filechooser.FileFilter[] getChoosableFileFilters() { 387 swingwtx.swing.filechooser.FileFilter[] ff = new swingwtx.swing.filechooser.FileFilter[fileFilters.size()]; 388 for (int i = 0; i < fileFilters.size(); i++) { 389 ff[i] = (swingwtx.swing.filechooser.FileFilter) fileFilters.get(i); 390 } 391 return ff; 392 } 393 public void addChoosableFileFilter(swingwtx.swing.filechooser.FileFilter f) { 394 JFileChooser.FileFilterWrapper w = new JFileChooser.FileFilterWrapper(f); 395 filter.addItem(w); 396 } 397 public boolean removeChoosableFileFilter(swingwtx.swing.filechooser.FileFilter f) { 398 for (int i = 0; i < filter.getItemCount(); i++) 399 if ( ((FileFilterWrapper) filter.getItemAt(i)).getFilter().equals(f) ) { 400 filter.removeItemAt(i); 401 return true; 402 } 403 return false; 404 } 405 public void resetChoosableFileFilters() { 406 filter.removeAllItems(); 407 fileFilters.removeAllElements(); 408 } 409 public boolean isAcceptAllFileFilterUsed() { return true; } 410 public void setAcceptAllFileFilterUsed(boolean b) {} 411 412 415 public int showOpenDialog(Component parent) { 416 if (useNative) 417 return showNativeOpenDialog(parent); 418 else 419 return showCustomOpenDialog(parent); 420 } 421 422 protected int showCustomOpenDialog(Component parent) { 423 dialogType = OPEN_DIALOG; 424 String dt = (dialogTitle.equals("") ? "Open" : dialogTitle); 425 customDialog = new FileChooserDialog(dt, this); 426 rescanCurrentDirectory(); customDialog.show(); 428 return dialogReturnValue; 429 } 430 431 protected int showNativeOpenDialog(Component parent) { 432 dialogType = OPEN_DIALOG; 433 org.eclipse.swt.widgets.FileDialog f = new org.eclipse.swt.widgets.FileDialog(parent.getPeer().getShell(), SWT.OPEN | (multiSelect ? SWT.MULTI : SWT.NONE) ); 434 if (dialogTitle.equals("")) 435 f.setText("Open"); 436 else 437 f.setText(dialogTitle); 438 439 if (curPath == null) curPath = new File (""); 440 f.setFilterPath(curPath.getAbsolutePath()); 441 442 if (filters != null) { 443 f.setFilterExtensions(filters); 444 f.setFilterNames(filterNames); 445 } 446 String chosen = f.open(); 447 if (chosen == null) return CANCEL_OPTION; 448 452 if (multiSelect) { 453 curFile = new File (chosen); 454 curFiles = new File [f.getFileNames().length]; 455 for (int i = 0; i < f.getFileNames().length; i++) { 456 curFiles[i] = new File (f.getFileNames()[i]); 457 } 458 curPath = curFile.getParentFile(); 459 } 460 else { 461 curFile = new File (chosen); 462 curPath = curFile.getParentFile(); 463 } 464 return APPROVE_OPTION; 465 } 466 467 public int showSaveDialog(Component parent) { 468 if (useNative) 469 return showNativeSaveDialog(parent); 470 else 471 return showCustomSaveDialog(parent); 472 } 473 474 protected int showNativeSaveDialog(Component parent) { 475 dialogType = SAVE_DIALOG; 476 org.eclipse.swt.widgets.FileDialog f = new org.eclipse.swt.widgets.FileDialog(parent.getPeer().getShell(), SWT.SAVE ); 477 if (dialogTitle.equals("")) 478 f.setText("Save As"); 479 else 480 f.setText(dialogTitle); 481 f.setFilterPath(curPath.getAbsolutePath()); 482 if (filters != null) { 483 f.setFilterExtensions(filters); 484 f.setFilterNames(filterNames); 485 } 486 487 String chosen = f.open(); 488 if (chosen == null) return CANCEL_OPTION; 489 493 if (multiSelect) { 494 curFile = new File (chosen); 495 curFiles = new File [f.getFileNames().length]; 496 for (int i = 0; i < f.getFileNames().length; i++) { 497 curFiles[i] = new File (f.getFileNames()[i]); 498 } 499 curPath = curFile.getParentFile(); 500 } 501 else { 502 curFile = new File (chosen); 503 curPath = curFile.getParentFile(); 504 } 505 return APPROVE_OPTION; 506 } 507 508 protected int showCustomSaveDialog(Component parent) { 509 dialogType = SAVE_DIALOG; 510 String dt = (dialogTitle.equals("") ? "Save" : dialogTitle); 511 customDialog = new FileChooserDialog(dt, this); 512 rescanCurrentDirectory(); customDialog.show(); 514 515 if (curPath.isDirectory()) { 519 String newFile = curPath.getAbsolutePath(); 520 if (!newFile.endsWith(File.separator)) 521 newFile += File.separator; 522 curPath = new File (newFile + location.getText()); 523 } 524 525 return dialogReturnValue; 526 } 527 528 public String getTitle() { return dialogTitle; } 529 public void setTitle(String title) { dialogTitle = title; } 530 531 535 public File [] sortFiles(File [] sort) { 536 537 boolean madeAChange = true; 538 while (madeAChange) { 539 madeAChange = false; 540 for (int i = 0; i < sort.length-1; i++) { 541 int pos = sort[i].toString().compareTo(sort[i+1].toString()); 542 if ( pos > 0 ) { 543 File buf = sort[i+1]; 544 sort[i+1] = sort[i]; 545 sort[i] = buf; 546 buf = null; 547 madeAChange = true; 548 } 549 } 550 } 551 return sort; 552 } 553 554 557 protected void firePropertyChangeEvent(String propertyName, Object oldValue, Object newValue) { 558 PropertyChangeEvent e = new PropertyChangeEvent (this, propertyName, oldValue, newValue); 559 for (int i = 0; i < propertyChangeListeners.size(); i++) { 560 ((PropertyChangeListener ) propertyChangeListeners.get(i)).propertyChange(e); 561 } 562 } 563 564 567 protected void layoutComponent() { 568 569 setLayout(new BorderLayout()); 570 571 JPanel pnlTool = new JPanel(new BorderLayout()); 573 574 pnlTool.add(new JLabel("Drive:"), BorderLayout.WEST); 576 final JComboBox drives = new JComboBox(); 577 drives.setPreferredSize(new Dimension(200, 25)); 578 pnlTool.add(drives, BorderLayout.CENTER); 579 scanDrives(drives); 580 drives.addItemListener(new ItemListener() { 581 public void itemStateChanged(ItemEvent e) { 582 583 DriveEntry d = (DriveEntry) drives.getSelectedItem(); 584 585 curPath = (File ) d.fileRef; 587 rescanCurrentDirectory(); 588 } 589 }); 590 591 add(pnlTool, BorderLayout.NORTH); 593 594 centralPanel = new JPanel(); 596 centralPanel.setLayout(new BorderLayout()); 597 598 fileList = new JList(); 600 fileList.setCellRenderer(new JFileChooser.FileListRenderer()); 601 fileList.addMouseListener(new MouseAdapter() { 603 public void mouseClicked(MouseEvent e) { 604 605 curFile = null; 607 if (fileList.getSelectedIndex() == -1) return; 609 if (fileList.getSelectedValue() == null) return; 610 611 curFile = (File ) fileList.getSelectedValue(); 613 curPath = curFile.getParentFile(); 614 615 if(e.getClickCount() == 2) { 618 if (!curFile.isDirectory()) { 619 location.setText( curFile.getName() ); 620 firePropertyChangeEvent( SELECTED_FILE_CHANGED_PROPERTY, null, fileList.getSelectedValue()); 621 okButton.processActionEvent(0); } else { 623 rescanCurrentDirectory(); 624 } 625 } else { 626 if (!curFile.isDirectory()) { 627 location.setText( curFile.getName() ); 628 firePropertyChangeEvent( SELECTED_FILE_CHANGED_PROPERTY, null, fileList.getSelectedValue()); 629 } 630 } 631 } 632 }); 633 634 centralPanel.add(fileList, BorderLayout.CENTER); 635 636 JPanel entryBoxes = new JPanel(); 638 entryBoxes.setLayout(new GridLayout(2, 0)); 639 640 JPanel pnlLocation = new JPanel(); 642 pnlLocation.setLayout(new BorderLayout()); 643 JLabel lblLoc = new JLabel("Location:"); 644 pnlLocation.add(lblLoc, BorderLayout.WEST); 645 lblLoc.setPreferredSize(new Dimension(100, 25)); 646 647 location = new JTextField(); 648 pnlLocation.add(location, BorderLayout.CENTER); 649 650 entryBoxes.add(pnlLocation); 651 652 JPanel pnlFilter = new JPanel(); 654 pnlFilter.setLayout(new BorderLayout()); 655 JLabel lblFilter = new JLabel("Filter:"); 656 pnlFilter.add(lblFilter, BorderLayout.WEST); 657 lblFilter.setPreferredSize(new Dimension(100, 25)); 658 659 filter = new JComboBox(); 660 pnlFilter.add(filter, BorderLayout.CENTER); 661 filter.setPreferredSize(new Dimension(300, 25)); 662 allFiles = new JFileChooser.FileFilterWrapper(new JFileChooser.AllFileFilter()); 663 filter.addItem(allFiles); 664 filter.addItemListener( new ItemListener() { 665 public void itemStateChanged(ItemEvent e) { 666 rescanCurrentDirectory(); 667 } 668 }); 669 670 entryBoxes.add(pnlFilter); 671 672 centralPanel.add(entryBoxes, BorderLayout.SOUTH); 673 674 675 add(centralPanel, BorderLayout.CENTER); 676 677 buttonPanel = new JPanel(); 679 buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); 680 681 okButton = (JButton) buttonPanel.add(new JButton("Ok")); 682 okButton.setMnemonic('o'); 683 okButton.addActionListener(new ActionListener() { 685 public void actionPerformed(ActionEvent e) { 686 dialogReturnValue = APPROVE_OPTION; 687 688 if(multiSelect) { 689 Object [] aktFiles = fileList.getSelectedValues(); 690 int length = aktFiles.length; 691 curFiles = new File [length]; 692 for(int i = 0; i < length; i++) { 693 curFiles[i] = (File ) aktFiles[i]; 694 } 695 } 696 697 if (customDialog != null) customDialog.dispose(); 698 } 699 }); 700 701 JButton cancelButton = (JButton) buttonPanel.add(new JButton("Cancel")); 702 cancelButton.setMnemonic('c'); 703 cancelButton.addActionListener(new ActionListener() { 705 public void actionPerformed(ActionEvent e) { 706 dialogReturnValue = CANCEL_OPTION; 707 if (customDialog != null) customDialog.dispose(); 708 } 709 }); 710 711 add(buttonPanel, BorderLayout.SOUTH); 712 713 } 715 716 720 private class FileChooserDialog extends JDialog { 721 public FileChooserDialog(String title, JFileChooser fc) { 722 super((Frame) null, title); 723 this.setSize(512, 384); 724 this.getContentPane().setLayout(new BorderLayout()); 725 this.getContentPane().add(fc, BorderLayout.CENTER); 726 this.setModal(true); 727 this.setLocationRelativeTo(null); 728 } 729 } 730 731 734 private class FileListRenderer extends JLabel implements ListCellRenderer { 735 736 ImageIcon dirIcon = new ImageIcon(getClass().getResource("/swingwtx/swing/filechooser/dir.gif")); 737 738 public FileListRenderer() { 739 } 741 742 public swingwt.awt.Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 743 744 File f = (File ) value; 745 746 if (index == 0) { 748 setText(".."); 749 setIcon(dirIcon); 750 return this; 751 } 752 753 String name = f.getName(); 755 if (name.indexOf(File.separator) != -1) 756 name = name.substring(name.lastIndexOf(File.separator), name.length()); 757 setText(name); 758 759 boolean isDir = f.isDirectory(); 761 setIcon(isDir ? dirIcon : null); 762 763 return this; 764 } 765 } 766 767 private class AllFileFilter extends swingwtx.swing.filechooser.FileFilter { 768 public boolean accept(File f) { 769 return true; 770 } 771 public String getDescription() { 772 return "All Files"; 773 } 774 } 775 776 780 private class FileFilterWrapper { 781 private swingwtx.swing.filechooser.FileFilter filter = null; 782 public FileFilterWrapper(swingwtx.swing.filechooser.FileFilter f) { 783 filter = f; 784 } 785 public swingwtx.swing.filechooser.FileFilter getFilter() { return filter; } 786 public String toString() { 787 return filter.getDescription(); 788 } 789 } 790 791 792 796 private class DriveEntry { 797 public File fileRef = null; 798 public String displayName = null; 799 public DriveEntry(File file, String displayName) { fileRef = file; this.displayName = displayName; } 800 public String toString() { return displayName; } 801 } 802 } 803 | Popular Tags |