< prev index next >

src/share/classes/sun/swing/FilePane.java

Print this page




  27 import java.awt.*;
  28 import java.awt.event.*;
  29 import java.beans.PropertyChangeEvent;
  30 import java.beans.PropertyChangeListener;
  31 import java.io.*;
  32 import java.text.DateFormat;
  33 import java.text.MessageFormat;
  34 import java.util.*;
  35 import java.util.List;
  36 import java.util.concurrent.Callable;
  37 
  38 import javax.accessibility.AccessibleContext;
  39 import javax.swing.*;
  40 import javax.swing.border.*;
  41 import javax.swing.event.*;
  42 import javax.swing.filechooser.*;
  43 import javax.swing.plaf.basic.*;
  44 import javax.swing.table.*;
  45 import javax.swing.text.*;
  46 


  47 import sun.awt.shell.*;
  48 
  49 /**
  50  * <b>WARNING:</b> This class is an implementation detail and is only
  51  * public so that it can be used by two packages. You should NOT consider
  52  * this public API.
  53  * <p>
  54  * This component is intended to be used in a subclass of
  55  * javax.swing.plaf.basic.BasicFileChooserUI. It realies heavily on the
  56  * implementation of BasicFileChooserUI, and is intended to be API compatible
  57  * with earlier implementations of MetalFileChooserUI and WindowsFileChooserUI.
  58  *
  59  * @author Leif Samuelsson
  60  */
  61 public class FilePane extends JPanel implements PropertyChangeListener {
  62     // Constants for actions. These are used for the actions' ACTION_COMMAND_KEY
  63     // and as keys in the action maps for FilePane and the corresponding UI classes
  64 
  65     public final static String ACTION_APPROVE_SELECTION = "approveSelection";
  66     public final static String ACTION_CANCEL            = "cancelSelection";


1818             } else if (source instanceof JTable) {
1819                 JTable table = (JTable)source;
1820                 Point p = evt.getPoint();
1821                 index = table.rowAtPoint(p);
1822 
1823                 boolean pointOutsidePrefSize =
1824                         SwingUtilities2.pointOutsidePrefSize(
1825                             table, index, table.columnAtPoint(p), p);
1826 
1827                 if (pointOutsidePrefSize && !fullRowSelection) {
1828                     return;
1829                 }
1830 
1831                 // Translate point from table to list
1832                 if (index >= 0 && list != null &&
1833                     listSelectionModel.isSelectedIndex(index)) {
1834 
1835                     // Make a new event with the list as source, placing the
1836                     // click in the corresponding list cell.
1837                     Rectangle r = list.getCellBounds(index, index);
1838                     evt = new MouseEvent(list, evt.getID(),
1839                                          evt.getWhen(), evt.getModifiers(),
1840                                          r.x + 1, r.y + r.height/2,
1841                                          evt.getXOnScreen(),
1842                                          evt.getYOnScreen(),
1843                                          evt.getClickCount(), evt.isPopupTrigger(),
1844                                          evt.getButton());




1845                 }
1846             } else {
1847                 return;
1848             }
1849 
1850             if (index >= 0 && SwingUtilities.isLeftMouseButton(evt)) {
1851                 JFileChooser fc = getFileChooser();
1852 
1853                 // For single click, we handle editing file name
1854                 if (evt.getClickCount() == 1 && source instanceof JList) {
1855                     if ((!fc.isMultiSelectionEnabled() || fc.getSelectedFiles().length <= 1)
1856                         && index >= 0 && listSelectionModel.isSelectedIndex(index)
1857                         && getEditIndex() == index && editFile == null) {
1858 
1859                         editFileName(index);
1860                     } else {
1861                         if (index >= 0) {
1862                             setEditIndex(index);
1863                         } else {
1864                             resetEditIndex();




  27 import java.awt.*;
  28 import java.awt.event.*;
  29 import java.beans.PropertyChangeEvent;
  30 import java.beans.PropertyChangeListener;
  31 import java.io.*;
  32 import java.text.DateFormat;
  33 import java.text.MessageFormat;
  34 import java.util.*;
  35 import java.util.List;
  36 import java.util.concurrent.Callable;
  37 
  38 import javax.accessibility.AccessibleContext;
  39 import javax.swing.*;
  40 import javax.swing.border.*;
  41 import javax.swing.event.*;
  42 import javax.swing.filechooser.*;
  43 import javax.swing.plaf.basic.*;
  44 import javax.swing.table.*;
  45 import javax.swing.text.*;
  46 
  47 import sun.awt.AWTAccessor;
  48 import sun.awt.AWTAccessor.MouseEventAccessor;
  49 import sun.awt.shell.*;
  50 
  51 /**
  52  * <b>WARNING:</b> This class is an implementation detail and is only
  53  * public so that it can be used by two packages. You should NOT consider
  54  * this public API.
  55  * <p>
  56  * This component is intended to be used in a subclass of
  57  * javax.swing.plaf.basic.BasicFileChooserUI. It realies heavily on the
  58  * implementation of BasicFileChooserUI, and is intended to be API compatible
  59  * with earlier implementations of MetalFileChooserUI and WindowsFileChooserUI.
  60  *
  61  * @author Leif Samuelsson
  62  */
  63 public class FilePane extends JPanel implements PropertyChangeListener {
  64     // Constants for actions. These are used for the actions' ACTION_COMMAND_KEY
  65     // and as keys in the action maps for FilePane and the corresponding UI classes
  66 
  67     public final static String ACTION_APPROVE_SELECTION = "approveSelection";
  68     public final static String ACTION_CANCEL            = "cancelSelection";


1820             } else if (source instanceof JTable) {
1821                 JTable table = (JTable)source;
1822                 Point p = evt.getPoint();
1823                 index = table.rowAtPoint(p);
1824 
1825                 boolean pointOutsidePrefSize =
1826                         SwingUtilities2.pointOutsidePrefSize(
1827                             table, index, table.columnAtPoint(p), p);
1828 
1829                 if (pointOutsidePrefSize && !fullRowSelection) {
1830                     return;
1831                 }
1832 
1833                 // Translate point from table to list
1834                 if (index >= 0 && list != null &&
1835                     listSelectionModel.isSelectedIndex(index)) {
1836 
1837                     // Make a new event with the list as source, placing the
1838                     // click in the corresponding list cell.
1839                     Rectangle r = list.getCellBounds(index, index);
1840                     MouseEvent newEvent = new MouseEvent(list, evt.getID(),
1841                                          evt.getWhen(), evt.getModifiers(),
1842                                          r.x + 1, r.y + r.height/2,
1843                                          evt.getXOnScreen(),
1844                                          evt.getYOnScreen(),
1845                                          evt.getClickCount(), evt.isPopupTrigger(),
1846                                          evt.getButton());
1847                     MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
1848                     meAccessor.setCausedByTouchEvent(newEvent,
1849                         meAccessor.isCausedByTouchEvent(evt));
1850                     evt = newEvent;
1851                 }
1852             } else {
1853                 return;
1854             }
1855 
1856             if (index >= 0 && SwingUtilities.isLeftMouseButton(evt)) {
1857                 JFileChooser fc = getFileChooser();
1858 
1859                 // For single click, we handle editing file name
1860                 if (evt.getClickCount() == 1 && source instanceof JList) {
1861                     if ((!fc.isMultiSelectionEnabled() || fc.getSelectedFiles().length <= 1)
1862                         && index >= 0 && listSelectionModel.isSelectedIndex(index)
1863                         && getEditIndex() == index && editFile == null) {
1864 
1865                         editFileName(index);
1866                     } else {
1867                         if (index >= 0) {
1868                             setEditIndex(index);
1869                         } else {
1870                             resetEditIndex();


< prev index next >