1 6 21 22 package de.schlichtherle.io.swing; 23 24 import de.schlichtherle.io.*; 25 26 import java.awt.*; 27 import javax.swing.*; 28 29 36 public class JFileChooser extends javax.swing.JFileChooser { 37 38 private PaintingLock paintingLock = getPaintingLock(); 39 private volatile short paintingDisabled; 40 41 public JFileChooser() { 42 super(FileSystemView.getFileSystemView()); 43 super.setFileView(new FileView(super.getFileView())); 44 super.setDoubleBuffered(false); 45 } 46 47 public JFileChooser(ArchiveDetector archiveDetector) { 48 super(FileSystemView.getFileSystemView(archiveDetector)); 49 super.setFileView(new FileView(super.getFileView())); 50 super.setDoubleBuffered(false); 51 } 52 53 59 public java.io.File getSelectedFile() { 60 java.io.File file = super.getSelectedFile(); 61 return ((FileSystemView) getFileSystemView()).wrap(file); 62 } 63 64 71 public java.io.File [] getSelectedFiles() { 72 java.io.File files[] = super.getSelectedFiles(); 73 if (files != null) { 74 FileSystemView fsv = (FileSystemView) getFileSystemView(); 75 for (int i = files.length; --i >= 0; ) { 76 files[i] = fsv.wrap(files[i]); 77 } 79 } 80 return files; 81 } 82 83 public Icon getIcon(final java.io.File file) { 84 beginPaintingDisabled(); 85 try { 86 return super.getIcon(file); 87 } finally { 88 endPaintingDisabled(); 89 } 90 } 91 92 public String getTypeDescription(final java.io.File file) { 93 beginPaintingDisabled(); 94 try { 95 return super.getTypeDescription(file); 96 } finally { 97 endPaintingDisabled(); 98 } 99 } 100 101 public boolean isTraversable(final java.io.File file) { 102 beginPaintingDisabled(); 103 try { 104 return super.isTraversable(file); 105 } finally { 106 endPaintingDisabled(); 107 } 108 } 109 110 public void paint(final Graphics g) { 111 if (paintingDisabled > 0) { 112 117 } else { 118 beginPaintingDisabled(); 119 try { 120 super.paintChildren(g); 121 } finally { 122 endPaintingDisabled(); 123 } 124 } 125 } 126 127 private void beginPaintingDisabled() { 128 synchronized (getPaintingLock()) { 129 paintingDisabled++; 130 } 131 } 132 133 private void endPaintingDisabled() { 134 synchronized (getPaintingLock()) { 135 paintingDisabled--; 136 if (paintingDisabled <= 0) 137 repaint(); 138 } 139 } 140 141 145 private final PaintingLock getPaintingLock() { 146 if (paintingLock == null) 147 paintingLock = new PaintingLock(); 148 return paintingLock; 149 } 150 151 private static class PaintingLock { 152 } 153 } 154 | Popular Tags |