38 |
|
|
39 |
package javax.swing.plaf.metal; |
package javax.swing.plaf.metal; |
40 |
|
|
41 |
|
import gnu.java.security.action.SetAccessibleAction; |
42 |
|
|
43 |
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
44 |
import java.awt.Component; |
import java.awt.Component; |
45 |
import java.awt.Container; |
import java.awt.Container; |
196 |
listView = true; |
listView = true; |
197 |
JFileChooser fc = getFileChooser(); |
JFileChooser fc = getFileChooser(); |
198 |
fc.remove(fileTablePanel); |
fc.remove(fileTablePanel); |
199 |
fileListPanel = createList(fc); |
createList(fc); |
200 |
|
|
201 |
fileList.getSelectionModel().clearSelection(); |
fileList.getSelectionModel().clearSelection(); |
202 |
if (index.length > 0) |
if (index.length > 0) |
|
{ |
|
|
|
|
203 |
for (int i = 0; i < index.length; i++) |
for (int i = 0; i < index.length; i++) |
204 |
fileList.getSelectionModel().addSelectionInterval(index[i], index[i]); |
fileList.getSelectionModel().addSelectionInterval(index[i], index[i]); |
|
} |
|
205 |
|
|
206 |
fc.add(fileListPanel, BorderLayout.CENTER); |
fc.add(fileListPanel, BorderLayout.CENTER); |
207 |
fc.revalidate(); |
fc.revalidate(); |
232 |
fc.remove(fileListPanel); |
fc.remove(fileListPanel); |
233 |
|
|
234 |
if (fileTable == null) |
if (fileTable == null) |
235 |
fileTablePanel = createDetailsView(fc); |
createDetailsView(fc); |
236 |
else |
else |
237 |
updateTable(); |
updateTable(); |
238 |
|
|
289 |
else if (n.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) |
else if (n.equals(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY)) |
290 |
{ |
{ |
291 |
File file = filechooser.getSelectedFile(); |
File file = filechooser.getSelectedFile(); |
292 |
if (file == null) |
|
293 |
|
if (file != null |
294 |
|
&& filechooser.getDialogType() == JFileChooser.SAVE_DIALOG) |
295 |
|
{ |
296 |
|
if (file.isDirectory() && filechooser.isTraversable(file)) |
297 |
|
{ |
298 |
|
filechooser.setApproveButtonText(openButtonText); |
299 |
|
filechooser.setApproveButtonToolTipText(openButtonToolTipText); |
300 |
|
} |
301 |
|
else if (file.isFile()) |
302 |
|
{ |
303 |
|
filechooser.setApproveButtonText(saveButtonText); |
304 |
|
filechooser.setApproveButtonToolTipText(saveButtonToolTipText); |
305 |
|
} |
306 |
|
} |
307 |
|
|
308 |
|
if (file == null || !file.isFile()) |
309 |
setFileName(null); |
setFileName(null); |
310 |
else |
else |
311 |
setFileName(file.getName()); |
setFileName(file.getName()); |
344 |
fileTable.revalidate(); |
fileTable.revalidate(); |
345 |
fileTable.repaint(); |
fileTable.repaint(); |
346 |
} |
} |
347 |
|
|
348 |
setDirectorySelected(false); |
setDirectorySelected(false); |
349 |
File currentDirectory = filechooser.getCurrentDirectory(); |
File currentDirectory = filechooser.getCurrentDirectory(); |
350 |
setDirectory(currentDirectory); |
setDirectory(currentDirectory); |
420 |
if (n.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY) |
if (n.equals(JFileChooser.DIRECTORY_CHANGED_PROPERTY) |
421 |
|| n.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY) |
|| n.equals(JFileChooser.FILE_FILTER_CHANGED_PROPERTY) |
422 |
|| n.equals(JFileChooser.FILE_HIDING_CHANGED_PROPERTY)) |
|| n.equals(JFileChooser.FILE_HIDING_CHANGED_PROPERTY)) |
423 |
rescanCurrentDirectory(filechooser); |
{ |
424 |
|
// Remove editing component |
425 |
|
if (fileTable != null) |
426 |
|
fileTable.removeAll(); |
427 |
|
if (fileList != null) |
428 |
|
fileList.removeAll(); |
429 |
|
startEditing = false; |
430 |
|
|
431 |
|
// Set text on button back to original. |
432 |
|
if (filechooser.getDialogType() == JFileChooser.SAVE_DIALOG) |
433 |
|
{ |
434 |
|
filechooser.setApproveButtonText(saveButtonText); |
435 |
|
filechooser.setApproveButtonToolTipText(saveButtonToolTipText); |
436 |
|
} |
437 |
|
|
438 |
|
rescanCurrentDirectory(filechooser); |
439 |
|
} |
440 |
|
|
441 |
filechooser.revalidate(); |
filechooser.revalidate(); |
442 |
filechooser.repaint(); |
filechooser.repaint(); |
891 |
int index = list.locationToIndex(e.getPoint()); |
int index = list.locationToIndex(e.getPoint()); |
892 |
File[] sf = fc.getSelectedFiles(); |
File[] sf = fc.getSelectedFiles(); |
893 |
if ((!fc.isMultiSelectionEnabled() || (sf != null && sf.length <= 1)) |
if ((!fc.isMultiSelectionEnabled() || (sf != null && sf.length <= 1)) |
894 |
&& index >= 0 && editFile == null && list.isSelectedIndex(index)) |
&& index >= 0 && !startEditing && list.isSelectedIndex(index)) |
895 |
{ |
{ |
896 |
Object tmp = list.getModel().getElementAt(index); |
Object tmp = list.getModel().getElementAt(index); |
897 |
if (lastSelected != null && lastSelected.equals(tmp)) |
if (lastSelected != null && lastSelected.equals(tmp)) |
1051 |
{ |
{ |
1052 |
File[] sf = fc.getSelectedFiles(); |
File[] sf = fc.getSelectedFiles(); |
1053 |
if ((!fc.isMultiSelectionEnabled() || (sf != null && sf.length <= 1)) |
if ((!fc.isMultiSelectionEnabled() || (sf != null && sf.length <= 1)) |
1054 |
&& editFile == null) |
&& !startEditing) |
1055 |
{ |
{ |
1056 |
editFile = (File) selVal; |
editFile = (File) selVal; |
1057 |
editFile(row); |
editFile(row); |
1081 |
completeEditing(); |
completeEditing(); |
1082 |
String path = selVal.toString(); |
String path = selVal.toString(); |
1083 |
File f = fsv.createFileObject(path); |
File f = fsv.createFileObject(path); |
1084 |
|
fc.setSelectedFile(f); |
1085 |
if (fc.isTraversable(f)) |
if (fc.isTraversable(f)) |
1086 |
{ |
{ |
1087 |
setDirectorySelected(true); |
setDirectorySelected(true); |
1093 |
setDirectory(null); |
setDirectory(null); |
1094 |
} |
} |
1095 |
lastSelected = selVal; |
lastSelected = selVal; |
1096 |
setFileName(path.substring(path.lastIndexOf("/") + 1)); |
if (f.isFile()) |
1097 |
|
setFileName(path.substring(path.lastIndexOf("/") + 1)); |
1098 |
|
else if (fc.getFileSelectionMode() == JFileChooser.DIRECTORIES_ONLY) |
1099 |
|
setFileName(path); |
1100 |
} |
} |
1101 |
fileTable.repaint(); |
fileTable.repaint(); |
1102 |
} |
} |
1116 |
startEditing = true; |
startEditing = true; |
1117 |
editField = new JTextField(editFile.getName()); |
editField = new JTextField(editFile.getName()); |
1118 |
editField.addActionListener(new EditingActionListener()); |
editField.addActionListener(new EditingActionListener()); |
1119 |
|
|
1120 |
|
// Need to adjust y pos |
1121 |
|
bounds.y = row * table.getRowHeight(); |
1122 |
editField.setBounds(bounds); |
editField.setBounds(bounds); |
1123 |
|
|
1124 |
table.add(editField); |
table.add(editField); |
1318 |
topPanel.add(dirPanel); |
topPanel.add(dirPanel); |
1319 |
topPanel.add(controls, BorderLayout.EAST); |
topPanel.add(controls, BorderLayout.EAST); |
1320 |
fc.add(topPanel, BorderLayout.NORTH); |
fc.add(topPanel, BorderLayout.NORTH); |
1321 |
fileListPanel = createList(fc); |
fc.add(createList(fc), BorderLayout.CENTER); |
|
fc.add(fileListPanel, BorderLayout.CENTER); |
|
1322 |
JPanel bottomPanel = getBottomPanel(); |
JPanel bottomPanel = getBottomPanel(); |
1323 |
filterModel = createFilterComboBoxModel(); |
filterModel = createFilterComboBoxModel(); |
1324 |
JComboBox fileFilterCombo = new JComboBox(filterModel); |
JComboBox fileFilterCombo = new JComboBox(filterModel); |
1447 |
*/ |
*/ |
1448 |
protected void installListeners(JFileChooser fc) |
protected void installListeners(JFileChooser fc) |
1449 |
{ |
{ |
1450 |
|
directoryComboBox.setAction(new DirectoryComboBoxAction()); |
1451 |
|
fc.addPropertyChangeListener(filterModel); |
1452 |
listSelList = createListSelectionListener(fc); |
listSelList = createListSelectionListener(fc); |
1453 |
doubleClickList = this.createDoubleClickListener(fc, fileList); |
doubleClickList = this.createDoubleClickListener(fc, fileList); |
1454 |
singleClickList = new SingleClickListener(fileList); |
singleClickList = new SingleClickListener(fileList); |
1455 |
directoryComboBox.setAction(new DirectoryComboBoxAction()); |
fileList.addListSelectionListener(listSelList); |
1456 |
fc.addPropertyChangeListener(filterModel); |
fileList.addMouseListener(doubleClickList); |
1457 |
|
fileList.addMouseListener(singleClickList); |
1458 |
super.installListeners(fc); |
super.installListeners(fc); |
1459 |
} |
} |
1460 |
|
|
1501 |
*/ |
*/ |
1502 |
protected JPanel createList(JFileChooser fc) |
protected JPanel createList(JFileChooser fc) |
1503 |
{ |
{ |
|
JPanel panel = new JPanel(new BorderLayout()); |
|
1504 |
if (fileList == null) |
if (fileList == null) |
1505 |
fileList = new JList(); |
{ |
1506 |
fileList.setModel(getModel()); |
fileListPanel = new JPanel(new BorderLayout()); |
1507 |
|
fileList = new JList(getModel()); |
1508 |
fileList.removeListSelectionListener(listSelList); |
scrollPane = new JScrollPane(fileList); |
1509 |
fileList.removeMouseListener(doubleClickList); |
// FIXME: fileList.setLayoutOrientation(JList.VERTICAL_WRAP); |
1510 |
fileList.removeMouseListener(singleClickList); |
fileList.setCellRenderer(new FileRenderer()); |
1511 |
|
} |
|
fileList.setModel(getModel()); |
|
|
// FIXME: fileList.setLayoutOrientation(JList.VERTICAL_WRAP); |
|
|
|
|
|
if (fc.isMultiSelectionEnabled()) |
|
|
fileList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
|
1512 |
else |
else |
1513 |
fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
{ |
1514 |
|
fileList.setModel(getModel()); |
1515 |
fileList.addListSelectionListener(listSelList); |
fileListPanel.removeAll(); |
1516 |
fileList.addMouseListener(doubleClickList); |
scrollPane.setViewport(new JViewport()); |
1517 |
fileList.addMouseListener(singleClickList); |
scrollPane.getViewport().setView(fileList); |
1518 |
|
} |
1519 |
fileList.setCellRenderer(new FileRenderer()); |
fileListPanel.add(scrollPane); |
1520 |
scrollPane = new JScrollPane(fileList); |
|
1521 |
panel.add(scrollPane); |
return fileListPanel; |
|
return panel; |
|
1522 |
} |
} |
1523 |
|
|
1524 |
/** |
/** |
1543 |
fileTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
fileTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
1544 |
|
|
1545 |
fileTable.setShowGrid(false); |
fileTable.setShowGrid(false); |
|
fileTable.setIntercellSpacing(new Dimension(0, 0)); |
|
1546 |
fileTable.setColumnSelectionAllowed(false); |
fileTable.setColumnSelectionAllowed(false); |
1547 |
fileTable.setDefaultRenderer(Object.class, new TableFileRenderer()); |
fileTable.setDefaultRenderer(Object.class, new TableFileRenderer()); |
1548 |
|
|
1549 |
tableClickList = new TableClickListener(fileTable, fc); |
tableClickList = new TableClickListener(fileTable, fc); |
1550 |
fileTable.addMouseListener(tableClickList); |
fileTable.addMouseListener(tableClickList); |
1551 |
|
|
1552 |
return updateTable(); |
return updateTable(); |
1553 |
} |
} |
1554 |
|
|
1559 |
*/ |
*/ |
1560 |
JPanel updateTable() |
JPanel updateTable() |
1561 |
{ |
{ |
1562 |
if (!listView) |
DefaultTableModel mod = (DefaultTableModel) fileTable.getModel(); |
1563 |
{ |
ListModel lm = fileList.getModel(); |
1564 |
DefaultTableModel mod = (DefaultTableModel) fileTable.getModel(); |
DateFormat dt = DateFormat.getDateTimeInstance(DateFormat.SHORT, |
1565 |
ListModel lm = fileList.getModel(); |
DateFormat.SHORT); |
1566 |
int size = lm.getSize(); |
File curr = null; |
1567 |
int rc = mod.getRowCount(); |
int size = lm.getSize(); |
1568 |
|
int rc = mod.getRowCount(); |
1569 |
// If there are not enough rows |
|
1570 |
for (int x = rc; x < size; x++) |
// If there are not enough rows |
1571 |
mod.addRow(new Object[3]); |
for (int x = rc; x < size; x++) |
1572 |
|
mod.addRow(new Object[3]); |
|
for (int i = 0; i < size; i++) |
|
|
{ |
|
|
File curr = (File) lm.getElementAt(i); |
|
|
fileTable.setValueAt(curr.getName(), i, 0); |
|
|
fileTable.setValueAt(formatSize(curr.length()), i, 1); |
|
|
DateFormat dt = DateFormat.getDateTimeInstance(DateFormat.SHORT, |
|
|
DateFormat.SHORT); |
|
|
fileTable.setValueAt(dt.format(new Date(curr.lastModified())), i, 2); |
|
|
} |
|
1573 |
|
|
1574 |
// If there are too many rows |
for (int i = 0; i < size; i++) |
1575 |
while (rc > size) |
{ |
1576 |
mod.removeRow(--rc); |
curr = (File) lm.getElementAt(i); |
1577 |
|
fileTable.setValueAt(curr.getName(), i, 0); |
1578 |
scrollPane.setViewport(new JViewport()); |
fileTable.setValueAt(formatSize(curr.length()), i, 1); |
1579 |
scrollPane.getViewport().setView(fileTable); |
fileTable.setValueAt(dt.format(new Date(curr.lastModified())), i, 2); |
|
scrollPane.setColumnHeaderView(fileTable.getTableHeader()); |
|
|
scrollPane.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); |
|
|
|
|
|
fileTablePanel.removeAll(); |
|
|
fileTablePanel.add(scrollPane); |
|
1580 |
} |
} |
1581 |
|
|
1582 |
|
// If there are too many rows |
1583 |
|
while (rc > size) |
1584 |
|
mod.removeRow(--rc); |
1585 |
|
|
1586 |
|
scrollPane.setViewport(new JViewport()); |
1587 |
|
scrollPane.getViewport().setView(fileTable); |
1588 |
|
scrollPane.setColumnHeaderView(fileTable.getTableHeader()); |
1589 |
|
scrollPane.getViewport().setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); |
1590 |
|
|
1591 |
|
fileTablePanel.removeAll(); |
1592 |
|
fileTablePanel.add(scrollPane); |
1593 |
|
|
1594 |
return fileTablePanel; |
return fileTablePanel; |
1595 |
} |
} |
1596 |
|
|
1597 |
/** |
/** |
1598 |
* Formats bytes into the appropriate size. |
* Formats bytes into the appropriate size. |
1599 |
* |
* |
1600 |
* @param bytes - the number of bytes to convert |
* @param bytes - |
1601 |
|
* the number of bytes to convert |
1602 |
* @return a string representation of the size |
* @return a string representation of the size |
1603 |
*/ |
*/ |
1604 |
private String formatSize(long bytes) |
private String formatSize(long bytes) |
1814 |
directoryModel.setSelectedItem(fc.getCurrentDirectory()); |
directoryModel.setSelectedItem(fc.getCurrentDirectory()); |
1815 |
getModel().validateFileCache(); |
getModel().validateFileCache(); |
1816 |
if (!listView) |
if (!listView) |
1817 |
updateTable(); |
updateTable(); |
1818 |
else |
else |
1819 |
fileList.revalidate(); |
createList(fc); |
1820 |
} |
} |
1821 |
|
|
1822 |
/** |
/** |