142 |
|
|
143 |
/** |
/** |
144 |
* DOCUMENT ME! |
* DOCUMENT ME! |
145 |
* |
* |
146 |
* @param e DOCUMENT ME! |
* @param e |
147 |
|
* DOCUMENT ME! |
148 |
*/ |
*/ |
149 |
public void actionPerformed(ActionEvent e) |
public void actionPerformed(ActionEvent e) |
150 |
{ |
{ |
151 |
Object obj = filelist.getSelectedValue(); |
Object obj = new String(parentPath + entry.getText()); |
152 |
if (obj != null) |
if (obj != null) |
153 |
{ |
{ |
154 |
File f = filechooser.getFileSystemView().createFileObject(obj |
File f = filechooser.getFileSystemView().createFileObject( |
155 |
.toString()); |
obj.toString()); |
156 |
if (filechooser.isTraversable(f) && |
if (filechooser.isTraversable(f) |
157 |
filechooser.getFileSelectionMode() == JFileChooser.FILES_ONLY) |
&& filechooser.isDirectorySelectionEnabled()) |
158 |
filechooser.setCurrentDirectory(f); |
filechooser.setCurrentDirectory(f); |
159 |
else |
else |
160 |
{ |
{ |
161 |
filechooser.setSelectedFile(f); |
filechooser.setSelectedFile(f); |
162 |
filechooser.approveSelection(); |
filechooser.approveSelection(); |
163 |
closeDialog(); |
closeDialog(); |
164 |
} |
} |
165 |
} |
} |
166 |
} |
} |
167 |
} |
} |
360 |
|
|
361 |
/** |
/** |
362 |
* DOCUMENT ME! |
* DOCUMENT ME! |
363 |
* |
* |
364 |
* @param e DOCUMENT ME! |
* @param e |
365 |
|
* DOCUMENT ME! |
366 |
*/ |
*/ |
367 |
public void mouseClicked(MouseEvent e) |
public void mouseClicked(MouseEvent e) |
368 |
{ |
{ |
369 |
if (list.getSelectedValue() == null) |
if (list.getSelectedValue() == null) |
370 |
return; |
return; |
371 |
FileSystemView fsv = filechooser.getFileSystemView(); |
FileSystemView fsv = filechooser.getFileSystemView(); |
372 |
if (timer.isRunning() |
if (timer.isRunning() |
373 |
&& list.getSelectedValue().toString().equals(lastSelected.toString())) |
&& list.getSelectedValue().toString().equals(lastSelected.toString())) |
374 |
{ |
{ |
375 |
File f = fsv.createFileObject(lastSelected.toString()); |
File f = fsv.createFileObject(lastSelected.toString()); |
376 |
timer.stop(); |
timer.stop(); |
377 |
if (filechooser.isTraversable(f)) |
if (filechooser.isTraversable(f)) |
378 |
{ |
{ |
379 |
filechooser.setCurrentDirectory(f); |
filechooser.setCurrentDirectory(f); |
380 |
filechooser.rescanCurrentDirectory(); |
filechooser.rescanCurrentDirectory(); |
381 |
} |
} |
382 |
else |
else |
383 |
{ |
{ |
384 |
filechooser.setSelectedFile(f); |
filechooser.setSelectedFile(f); |
385 |
filechooser.approveSelection(); |
filechooser.approveSelection(); |
386 |
closeDialog(); |
closeDialog(); |
387 |
} |
} |
388 |
} |
} |
389 |
else |
else |
390 |
{ |
{ |
391 |
File f = fsv.createFileObject(list.getSelectedValue().toString()); |
String path = list.getSelectedValue().toString(); |
392 |
if (filechooser.isTraversable(f)) |
File f = fsv.createFileObject(path); |
393 |
{ |
if (filechooser.isTraversable(f)) |
394 |
setDirectorySelected(true); |
{ |
395 |
setDirectory(f); |
setDirectorySelected(true); |
396 |
} |
setDirectory(f); |
397 |
else |
} |
398 |
{ |
else |
399 |
setDirectorySelected(false); |
{ |
400 |
setDirectory(null); |
setDirectorySelected(false); |
401 |
} |
setDirectory(null); |
402 |
lastSelected = list.getSelectedValue().toString(); |
} |
403 |
timer.restart(); |
lastSelected = path; |
404 |
|
parentPath = path.substring(0, path.lastIndexOf("/") + 1); |
405 |
|
entry.setText(path.substring(path.lastIndexOf("/") + 1)); |
406 |
|
timer.restart(); |
407 |
} |
} |
408 |
} |
} |
409 |
|
|
410 |
/** |
/** |
411 |
* DOCUMENT ME! |
* DOCUMENT ME! |
412 |
* |
* |
413 |
* @param e DOCUMENT ME! |
* @param e |
414 |
|
* DOCUMENT ME! |
415 |
*/ |
*/ |
416 |
public void mouseEntered(MouseEvent e) |
public void mouseEntered(MouseEvent e) |
417 |
{ |
{ |
949 |
/** DOCUMENT ME! */ |
/** DOCUMENT ME! */ |
950 |
JPanel closePanel; |
JPanel closePanel; |
951 |
|
|
952 |
|
/** Text box that displays file name */ |
953 |
|
JTextField entry; |
954 |
|
|
955 |
|
/** Current parent path */ |
956 |
|
String parentPath; |
957 |
|
|
958 |
// -- end private -- |
// -- end private -- |
959 |
private class ListLabelRenderer |
private class ListLabelRenderer extends JLabel implements ListCellRenderer |
|
extends JLabel |
|
|
implements ListCellRenderer |
|
960 |
{ |
{ |
961 |
/** DOCUMENT ME! */ |
/** DOCUMENT ME! */ |
962 |
final Color selected = new Color(153, 204, 255); |
final Color selected = new Color(153, 204, 255); |
1068 |
|
|
1069 |
/** |
/** |
1070 |
* DOCUMENT ME! |
* DOCUMENT ME! |
1071 |
* |
* |
1072 |
* @param c DOCUMENT ME! |
* @param c |
1073 |
|
* DOCUMENT ME! |
1074 |
*/ |
*/ |
1075 |
public void installUI(JComponent c) |
public void installUI(JComponent c) |
1076 |
{ |
{ |
1077 |
if (c instanceof JFileChooser) |
if (c instanceof JFileChooser) |
1078 |
{ |
{ |
1079 |
JFileChooser fc = (JFileChooser) c; |
JFileChooser fc = (JFileChooser) c; |
1080 |
fc.resetChoosableFileFilters(); |
fc.resetChoosableFileFilters(); |
1081 |
createModel(); |
createModel(); |
1082 |
clearIconCache(); |
clearIconCache(); |
1083 |
installDefaults(fc); |
installDefaults(fc); |
1084 |
installComponents(fc); |
installComponents(fc); |
1085 |
installListeners(fc); |
installListeners(fc); |
1086 |
|
|
1087 |
|
Object path = filechooser.getCurrentDirectory(); |
1088 |
|
if (path != null) |
1089 |
|
parentPath = path.toString().substring(path.toString().lastIndexOf("/")); |
1090 |
} |
} |
1091 |
} |
} |
1092 |
|
|
1093 |
/** |
/** |
1094 |
* DOCUMENT ME! |
* DOCUMENT ME! |
1095 |
* |
* |
1096 |
* @param c DOCUMENT ME! |
* @param c |
1097 |
|
* DOCUMENT ME! |
1098 |
*/ |
*/ |
1099 |
public void uninstallUI(JComponent c) |
public void uninstallUI(JComponent c) |
1100 |
{ |
{ |
1106 |
} |
} |
1107 |
|
|
1108 |
// FIXME: Indent the entries in the combobox |
// FIXME: Indent the entries in the combobox |
1109 |
private void boxEntries() |
// Made this method package private to access it from within inner classes |
1110 |
|
// with better performance |
1111 |
|
void boxEntries() |
1112 |
{ |
{ |
1113 |
ArrayList parentFiles = new ArrayList(); |
ArrayList parentFiles = new ArrayList(); |
1114 |
File parent = filechooser.getCurrentDirectory(); |
File parent = filechooser.getCurrentDirectory(); |
1116 |
parent = filechooser.getFileSystemView().getDefaultDirectory(); |
parent = filechooser.getFileSystemView().getDefaultDirectory(); |
1117 |
while (parent != null) |
while (parent != null) |
1118 |
{ |
{ |
1119 |
String name = parent.getName(); |
String name = parent.getName(); |
1120 |
if (name.equals("")) |
if (name.equals("")) |
1121 |
name = parent.getAbsolutePath(); |
name = parent.getAbsolutePath(); |
1122 |
|
|
1123 |
parentFiles.add(parentFiles.size(), name); |
parentFiles.add(parentFiles.size(), name); |
1124 |
parent = parent.getParentFile(); |
parent = parent.getParentFile(); |
1125 |
} |
} |
1126 |
|
|
1127 |
if (parentFiles.size() == 0) |
if (parentFiles.size() == 0) |
1276 |
JLabel fileNameLabel = new JLabel("File Name:"); |
JLabel fileNameLabel = new JLabel("File Name:"); |
1277 |
JLabel fileTypesLabel = new JLabel("Files of Type:"); |
JLabel fileTypesLabel = new JLabel("Files of Type:"); |
1278 |
|
|
1279 |
JTextField entry = new JTextField(); |
entry = new JTextField(); |
1280 |
filters = new JComboBox(); |
filters = new JComboBox(); |
1281 |
filterEntries(); |
filterEntries(); |
1282 |
|
|
1495 |
|
|
1496 |
/** |
/** |
1497 |
* DOCUMENT ME! |
* DOCUMENT ME! |
1498 |
* |
* |
1499 |
* @param fc DOCUMENT ME! |
* @param fc |
1500 |
* |
* DOCUMENT ME! |
1501 |
* @return DOCUMENT ME! |
* @return DOCUMENT ME! |
1502 |
*/ |
*/ |
1503 |
public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) |
public PropertyChangeListener createPropertyChangeListener(JFileChooser fc) |
1504 |
{ |
{ |
1505 |
return new PropertyChangeListener() |
return new PropertyChangeListener() |
1506 |
|
{ |
1507 |
|
public void propertyChange(PropertyChangeEvent e) |
1508 |
{ |
{ |
1509 |
public void propertyChange(PropertyChangeEvent e) |
// FIXME: Multiple file selection waiting on JList multiple selection |
1510 |
{ |
// bug. |
1511 |
// FIXME: Multiple file selection waiting on JList multiple selection bug. |
if (e.getPropertyName().equals( |
1512 |
if (e.getPropertyName().equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) |
JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) |
1513 |
{ |
{ |
1514 |
if (filechooser.getSelectedFile() == null) |
if (filechooser.getSelectedFile() == null) |
1515 |
setFileName(null); |
setFileName(null); |
1516 |
else |
else |
1517 |
setFileName(filechooser.getSelectedFile().toString()); |
setFileName(filechooser.getSelectedFile().toString()); |
1518 |
int index = -1; |
int index = -1; |
1519 |
File file = filechooser.getSelectedFile(); |
File file = filechooser.getSelectedFile(); |
1520 |
for (index = 0; index < model.getSize(); index++) |
for (index = 0; index < model.getSize(); index++) |
1521 |
if (((File) model.getElementAt(index)).equals(file)) |
if (((File) model.getElementAt(index)).equals(file)) |
1522 |
break; |
break; |
1523 |
if (index == -1) |
if (index == -1) |
1524 |
return; |
return; |
1525 |
filelist.setSelectedIndex(index); |
filelist.setSelectedIndex(index); |
1526 |
filelist.ensureIndexIsVisible(index); |
filelist.ensureIndexIsVisible(index); |
1527 |
filelist.revalidate(); |
filelist.revalidate(); |
1528 |
filelist.repaint(); |
filelist.repaint(); |
1529 |
} |
} |
1530 |
else if (e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY)) |
else if (e.getPropertyName().equals( |
1531 |
{ |
JFileChooser.DIRECTORY_CHANGED_PROPERTY)) |
1532 |
//boxEntries(); |
{ |
1533 |
filelist.clearSelection(); |
filelist.clearSelection(); |
1534 |
filelist.revalidate(); |
filelist.revalidate(); |
1535 |
filelist.repaint(); |
filelist.repaint(); |
1536 |
setDirectorySelected(false); |
setDirectorySelected(false); |
1537 |
setDirectory(filechooser.getCurrentDirectory()); |
setDirectory(filechooser.getCurrentDirectory()); |
1538 |
} |
boxEntries(); |
1539 |
else if (e.getPropertyName().equals(JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) |
} |
1540 |
|| e.getPropertyName().equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) |
else if (e.getPropertyName().equals( |
1541 |
filterEntries(); |
JFileChooser.CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY) |
1542 |
else if (e.getPropertyName().equals(JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY) |
|| e.getPropertyName().equals( |
1543 |
|| e.getPropertyName().equals(JFileChooser.DIALOG_TITLE_CHANGED_PROPERTY)) |
JFileChooser.FILE_FILTER_CHANGED_PROPERTY)) |
1544 |
{ |
filterEntries(); |
1545 |
Window owner = SwingUtilities.windowForComponent(filechooser); |
else if (e.getPropertyName().equals( |
1546 |
if (owner instanceof JDialog) |
JFileChooser.DIALOG_TYPE_CHANGED_PROPERTY) |
1547 |
((JDialog) owner).setTitle(getDialogTitle(filechooser)); |
|| e.getPropertyName().equals( |
1548 |
accept.setText(getApproveButtonText(filechooser)); |
JFileChooser.DIALOG_TITLE_CHANGED_PROPERTY)) |
1549 |
accept.setToolTipText(getApproveButtonToolTipText(filechooser)); |
{ |
1550 |
accept.setMnemonic(getApproveButtonMnemonic(filechooser)); |
Window owner = SwingUtilities.windowForComponent(filechooser); |
1551 |
} |
if (owner instanceof JDialog) |
1552 |
else if (e.getPropertyName().equals(JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY)) |
((JDialog) owner).setTitle(getDialogTitle(filechooser)); |
1553 |
accept.setText(getApproveButtonText(filechooser)); |
accept.setText(getApproveButtonText(filechooser)); |
1554 |
else if (e.getPropertyName().equals(JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY)) |
accept.setToolTipText(getApproveButtonToolTipText(filechooser)); |
1555 |
accept.setToolTipText(getApproveButtonToolTipText(filechooser)); |
accept.setMnemonic(getApproveButtonMnemonic(filechooser)); |
1556 |
else if (e.getPropertyName().equals(JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) |
} |
1557 |
accept.setMnemonic(getApproveButtonMnemonic(filechooser)); |
else if (e.getPropertyName().equals( |
1558 |
else if (e.getPropertyName().equals(JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) |
JFileChooser.APPROVE_BUTTON_TEXT_CHANGED_PROPERTY)) |
1559 |
{ |
accept.setText(getApproveButtonText(filechooser)); |
1560 |
if (filechooser.getControlButtonsAreShown()) |
else if (e.getPropertyName().equals( |
1561 |
{ |
JFileChooser.APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY)) |
1562 |
GridBagConstraints c = new GridBagConstraints(); |
accept.setToolTipText(getApproveButtonToolTipText(filechooser)); |
1563 |
c.gridy = 1; |
else if (e.getPropertyName().equals( |
1564 |
bottomPanel.add(filters, c); |
JFileChooser.APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY)) |
1565 |
|
accept.setMnemonic(getApproveButtonMnemonic(filechooser)); |
1566 |
c.fill = GridBagConstraints.BOTH; |
else if (e.getPropertyName().equals( |
1567 |
c.gridy = 2; |
JFileChooser.CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY)) |
1568 |
c.anchor = GridBagConstraints.EAST; |
{ |
1569 |
bottomPanel.add(closePanel, c); |
if (filechooser.getControlButtonsAreShown()) |
1570 |
bottomPanel.revalidate(); |
{ |
1571 |
bottomPanel.repaint(); |
GridBagConstraints c = new GridBagConstraints(); |
1572 |
bottomPanel.doLayout(); |
c.gridy = 1; |
1573 |
} |
bottomPanel.add(filters, c); |
1574 |
else |
|
1575 |
bottomPanel.remove(closePanel); |
c.fill = GridBagConstraints.BOTH; |
1576 |
} |
c.gridy = 2; |
1577 |
else if (e.getPropertyName().equals(JFileChooser.ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY)) |
c.anchor = GridBagConstraints.EAST; |
1578 |
{ |
bottomPanel.add(closePanel, c); |
1579 |
if (filechooser.isAcceptAllFileFilterUsed()) |
bottomPanel.revalidate(); |
1580 |
filechooser.addChoosableFileFilter(getAcceptAllFileFilter(filechooser)); |
bottomPanel.repaint(); |
1581 |
else |
bottomPanel.doLayout(); |
1582 |
filechooser.removeChoosableFileFilter(getAcceptAllFileFilter(filechooser)); |
} |
1583 |
} |
else |
1584 |
else if (e.getPropertyName().equals(JFileChooser.ACCESSORY_CHANGED_PROPERTY)) |
bottomPanel.remove(closePanel); |
1585 |
{ |
} |
1586 |
JComponent old = (JComponent) e.getOldValue(); |
else if (e.getPropertyName().equals( |
1587 |
if (old != null) |
JFileChooser.ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY)) |
1588 |
getAccessoryPanel().remove(old); |
{ |
1589 |
JComponent newval = (JComponent) e.getNewValue(); |
if (filechooser.isAcceptAllFileFilterUsed()) |
1590 |
if (newval != null) |
filechooser.addChoosableFileFilter(getAcceptAllFileFilter(filechooser)); |
1591 |
getAccessoryPanel().add(newval); |
else |
1592 |
} |
filechooser.removeChoosableFileFilter(getAcceptAllFileFilter(filechooser)); |
1593 |
if (e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY) |
} |
1594 |
|| e.getPropertyName().equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY) |
else if (e.getPropertyName().equals( |
1595 |
|| e.getPropertyName().equals(JFileChooser.FILE_HIDING_CHANGED_PROPERTY)) |
JFileChooser.ACCESSORY_CHANGED_PROPERTY)) |
1596 |
rescanCurrentDirectory(filechooser); |
{ |
1597 |
|
JComponent old = (JComponent) e.getOldValue(); |
1598 |
|
if (old != null) |
1599 |
|
getAccessoryPanel().remove(old); |
1600 |
|
JComponent newval = (JComponent) e.getNewValue(); |
1601 |
|
if (newval != null) |
1602 |
|
getAccessoryPanel().add(newval); |
1603 |
|
} |
1604 |
|
if (e.getPropertyName().equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY) |
1605 |
|
|| e.getPropertyName().equals( |
1606 |
|
JFileChooser.FILE_FILTER_CHANGED_PROPERTY) |
1607 |
|
|| e.getPropertyName().equals( |
1608 |
|
JFileChooser.FILE_HIDING_CHANGED_PROPERTY)) |
1609 |
|
rescanCurrentDirectory(filechooser); |
1610 |
|
|
1611 |
filechooser.revalidate(); |
filechooser.revalidate(); |
1612 |
filechooser.repaint(); |
filechooser.repaint(); |
1613 |
} |
} |
1614 |
}; |
}; |
1615 |
} |
} |
1616 |
|
|
1617 |
/** |
/** |
1618 |
* DOCUMENT ME! |
* DOCUMENT ME! |
1619 |
* |
* |
1620 |
* @return DOCUMENT ME! |
* @return DOCUMENT ME! |
1621 |
*/ |
*/ |
1622 |
public String getFileName() |
public String getFileName() |