< prev index next >

src/java.desktop/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 @SuppressWarnings("serial") // JDK-implementation class
  62 public class FilePane extends JPanel implements PropertyChangeListener {
  63     // Constants for actions. These are used for the actions' ACTION_COMMAND_KEY
  64     // and as keys in the action maps for FilePane and the corresponding UI classes
  65 
  66     public static final String ACTION_APPROVE_SELECTION = "approveSelection";


1841             } else if (source instanceof JTable) {
1842                 JTable table = (JTable)source;
1843                 Point p = evt.getPoint();
1844                 index = table.rowAtPoint(p);
1845 
1846                 boolean pointOutsidePrefSize =
1847                         SwingUtilities2.pointOutsidePrefSize(
1848                             table, index, table.columnAtPoint(p), p);
1849 
1850                 if (pointOutsidePrefSize && !fullRowSelection) {
1851                     return;
1852                 }
1853 
1854                 // Translate point from table to list
1855                 if (index >= 0 && list != null &&
1856                     listSelectionModel.isSelectedIndex(index)) {
1857 
1858                     // Make a new event with the list as source, placing the
1859                     // click in the corresponding list cell.
1860                     Rectangle r = list.getCellBounds(index, index);
1861                     evt = new MouseEvent(list, evt.getID(),
1862                                          evt.getWhen(), evt.getModifiers(),
1863                                          r.x + 1, r.y + r.height/2,
1864                                          evt.getXOnScreen(),
1865                                          evt.getYOnScreen(),
1866                                          evt.getClickCount(), evt.isPopupTrigger(),
1867                                          evt.getButton());




1868                 }
1869             } else {
1870                 return;
1871             }
1872 
1873             if (index >= 0 && SwingUtilities.isLeftMouseButton(evt)) {
1874                 JFileChooser fc = getFileChooser();
1875 
1876                 // For single click, we handle editing file name
1877                 if (evt.getClickCount() == 1 && source instanceof JList) {
1878                     if ((!fc.isMultiSelectionEnabled() || fc.getSelectedFiles().length <= 1)
1879                         && index >= 0 && listSelectionModel.isSelectedIndex(index)
1880                         && getEditIndex() == index && editFile == null) {
1881 
1882                         editFileName(index);
1883                     } else {
1884                         if (index >= 0) {
1885                             setEditIndex(index);
1886                         } else {
1887                             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 @SuppressWarnings("serial") // JDK-implementation class
  64 public class FilePane extends JPanel implements PropertyChangeListener {
  65     // Constants for actions. These are used for the actions' ACTION_COMMAND_KEY
  66     // and as keys in the action maps for FilePane and the corresponding UI classes
  67 
  68     public static final String ACTION_APPROVE_SELECTION = "approveSelection";


1843             } else if (source instanceof JTable) {
1844                 JTable table = (JTable)source;
1845                 Point p = evt.getPoint();
1846                 index = table.rowAtPoint(p);
1847 
1848                 boolean pointOutsidePrefSize =
1849                         SwingUtilities2.pointOutsidePrefSize(
1850                             table, index, table.columnAtPoint(p), p);
1851 
1852                 if (pointOutsidePrefSize && !fullRowSelection) {
1853                     return;
1854                 }
1855 
1856                 // Translate point from table to list
1857                 if (index >= 0 && list != null &&
1858                     listSelectionModel.isSelectedIndex(index)) {
1859 
1860                     // Make a new event with the list as source, placing the
1861                     // click in the corresponding list cell.
1862                     Rectangle r = list.getCellBounds(index, index);
1863                     MouseEvent newEvent = new MouseEvent(list, evt.getID(),
1864                                          evt.getWhen(), evt.getModifiers(),
1865                                          r.x + 1, r.y + r.height/2,
1866                                          evt.getXOnScreen(),
1867                                          evt.getYOnScreen(),
1868                                          evt.getClickCount(), evt.isPopupTrigger(),
1869                                          evt.getButton());
1870                     MouseEventAccessor meAccessor = AWTAccessor.getMouseEventAccessor();
1871                     meAccessor.setCausedByTouchEvent(newEvent,
1872                         meAccessor.isCausedByTouchEvent(evt));
1873                     evt = newEvent;
1874                 }
1875             } else {
1876                 return;
1877             }
1878 
1879             if (index >= 0 && SwingUtilities.isLeftMouseButton(evt)) {
1880                 JFileChooser fc = getFileChooser();
1881 
1882                 // For single click, we handle editing file name
1883                 if (evt.getClickCount() == 1 && source instanceof JList) {
1884                     if ((!fc.isMultiSelectionEnabled() || fc.getSelectedFiles().length <= 1)
1885                         && index >= 0 && listSelectionModel.isSelectedIndex(index)
1886                         && getEditIndex() == index && editFile == null) {
1887 
1888                         editFileName(index);
1889                     } else {
1890                         if (index >= 0) {
1891                             setEditIndex(index);
1892                         } else {
1893                             resetEditIndex();


< prev index next >