📄 filelistview.java
字号:
String lowerFileName = fullFileName.toLowerCase();
if (file_list[i].isDirectory()) {
if (lowerFileName.endsWith(":\\")){ /*only on Windows*/
data[0][i] = diskIcon;
if (i == 0 && file_list[i].equals(parentDir))
data[1][i] = "..";
else
data[1][i] = fullFileName;
}else{
data[0][i] = dirIcon;
if (i == 0 && file_list[i].equals(parentDir))
data[1][i] = "..";
else {
//data[1][i] = fullFileName.substring(fullFileName.lastIndexOf(fileSeparator) + 1);
data[1][i] = file_list[i].getName();
}
}
}else{
//Modified by Neoya 2002-03-07
/*
if (lowerFileName.endsWith(".jpg"))
data[0][i] = jpgIcon;
else if (lowerFileName.endsWith(".gif"))
data[0][i] = gifIcon;
else if (lowerFileName.endsWith(".bmp"))
data[0][i] = bmpIcon;
else if (lowerFileName.endsWith(".png"))
data[0][i] = pngIcon;
else if (lowerFileName.endsWith(".pcx"))
data[0][i] = pcxIcon;
else if (lowerFileName.endsWith(".tif"))
data[0][i] = tifIcon;
else if (lowerFileName.endsWith(".xpm"))
data[0][i] = xpmIcon;
else if (lowerFileName.endsWith(".pnm"))
data[0][i] = pnmIcon;
else
data[0][i] = ukIcon;
*/
data[0][i]=typedImages.getImageIcon(lowerFileName);
//data[1][i] = fullFileName.substring(fullFileName.lastIndexOf(fileSeparator) + 1);
data[1][i] = file_list[i].getName();
}
ImageInfo imageInfo=typedImages.getImageInfo(fullFileName);
//Get size
data[2][i]=imageInfo.getSize();
//Get date
data[3][i]=imageInfo.getDate();
//Get type
data[4][i]=imageInfo.getType();
data[5][i]=imageInfo.getProperty();
}
return data;
}
public File[] makeFileList(File directory) {
try {
//Modified by Neoya 2002-03-06
if (!(directory.exists()&&directory.isDirectory()))
return null;
parentDir = directory.getParentFile();
File[] temp;
int file_array_length = directory.listFiles().length;
if (parentDir != null){
temp = new File[file_array_length + 1];
temp[0] = parentDir;
System.arraycopy(directory.listFiles(), 0, temp, 1, file_array_length);
}else
temp=directory.listFiles();
//Make Directories Appear First:
int j=0;
File tempFile;
for(int i=0;i<temp.length;i++){
if (temp[i].isDirectory()&&(j!=i)){
j++;
tempFile=temp[j];
temp[j]=temp[i];
temp[i]=tempFile;
}
}
return temp;
}catch(SecurityException e){
System.out.println("Access Denied at directory"+directory);
return null;
}catch(Exception e){
return null;
}
}
public void PopupTriggered(MouseEvent e) {
int selectedRow = fileListTable.rowAtPoint(e.getPoint());
fileListTable.setRowSelectionInterval(selectedRow, selectedRow);
if (!selectedFileIsDirectory())
popupMenu.show(fileListTable, e.getX(), e.getY());
else
if (selectedFileIsLinkToUpperDirectory())
linkPopupMenu.show(fileListTable, e.getX(), e.getY());
else
dirPopupMenu.show(fileListTable, e.getX(), e.getY());
}
public void DoChangeDir(){
File temp = file_list[fileListTable.getSelectedRow()];
if ( temp.isDirectory() )
{
currentDir = temp.getAbsolutePath();
parentFrame.setTitle("JCDSee - " + currentDir);
RefreshFileList(temp);
}
}
public String getSelectedFile() {
selectedRow = fileListTable.getSelectedRow();
if (selectedRow < 0) {selectedRow = 0;}
if (file_list!=null)
//Modified by Neoya to fit the sort view
//return ( file_list[selectedRow] ).toString();
return ( file_list[sorter.getIndex(selectedRow)] ).toString();
else
return "";
}
public boolean selectedFileIsDirectory() {
selectedRow = fileListTable.getSelectedRow();
if (selectedRow < 0)
selectedRow = 0;
return file_list[selectedRow].isDirectory();
}
public boolean selectedFileIsLinkToUpperDirectory() {
selectedRow = fileListTable.getSelectedRow();
if (selectedRow == 0 && parentDir!=null && parentDir.exists())
return true;
else
return false;
}
public String getNextImage() {
if (selectedRow <= file_list.length-2) {
selectedRow++;
//return ( file_list[selectedRow] ).toString();
return (file_list[sorter.getIndex(selectedRow)]).toString();
}
else
return null;
}
public String getPreviousImage() {
//if (selectedRow >= 2) {
if (selectedRow >= 1) {
selectedRow--;
//return ( file_list[selectedRow] ).toString();
return ( file_list[sorter.getIndex(selectedRow)] ).toString();
}
else
return null;
}
public void SelectCurrentFile() {
fileListTable.setRowSelectionInterval(selectedRow, selectedRow);
}
public int getSelectedIndex() {
return fileListTable.getSelectedRow();
}
public File[] getFileList() {
return file_list;
}
public String getCurrentDir() {
return currentDir;
}
public void dislayImageFullScreen() {
parentFrame.Display_Image_FullScreen(getSelectedFile());
}
public void dislaySelectedImageFullScreen() {
parentFrame.Display_Selected_Image_FullScreen();
}
public void deleteSelectedFile() {
int selectedRow = fileListTable.getSelectedRow();
File tempFile = new File(getSelectedFile());
if (tempFile.delete()) {
RefreshFileList();
int rowCount = fileListTable.getRowCount();
if (selectedRow < rowCount)
fileListTable.setRowSelectionInterval(selectedRow, selectedRow);
else
fileListTable.setRowSelectionInterval(rowCount - 1, rowCount - 1);
}
else
JOptionPane.showMessageDialog(null, "Cannot delete " +
tempFile.getName() + " file");
}
public void RefreshFileList(File directory){
try {
file_list = null;
file_list = makeFileList(directory);
currentDir = directory.toString();
parentDir = directory.getParentFile();
if (parentDir == null) // disable the Go Up tool bar button
parentFrame.setEnableGoUpButton(false);
else
parentFrame.setEnableGoUpButton(true);
data = makeFileListData();
dataModel.RefreshFileList(data);
parentFrame.setTitle(directory.toString());
parentFrame.parentDir = directory.getParentFile();
parentFrame.fileTree.setSelectionPath(directory);
this.validate();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Your " + directory.toString() + " drive is not ready");
}
}
public void RefreshFileList() { //refresh current directory
try {
file_list = null;
file_list = makeFileList(new File(currentDir));
data = makeFileListData();
dataModel.RefreshFileList(data);
this.validate();
} catch (Exception ex) {/* something wrong */}
}
/**
* A class to render colored view in FileListTable
* @author Neoya M <neoyaa@yahoo.com> 2002-03-07
*/
class ColorRenderer extends JLabel
implements TableCellRenderer {
public ColorRenderer(boolean isBordered) {
super();
this.setOpaque(true); //MUST do this for background to show up.
}
public Component getTableCellRendererComponent(
JTable table, Object color,
boolean isSelected, boolean hasFocus,
int row, int column) {
String filename="";
//filename=table.getValueAt(row,1).toString();//Error when columns move
filename=table.getModel().getValueAt(row,1).toString();
filename=currentDir + "\\" + filename;
this.setBackground(typedImages.getImageColor(filename));
if(table.getSelectedRow()==row){
this.setBackground(new Color(0,0,150));
this.setForeground(Color.white);
}else{
this.setForeground(Color.black);
}
if(table.getColumnName(column).equals("Size")){//Size
String text=table.getValueAt(row,column).toString();
if (!text.equals("0"))
this.setText(text+"KB "); //Two spaces to make a better look
else
this.setText("");
this.setHorizontalAlignment(SwingConstants.RIGHT);
}else{
this.setText(table.getValueAt(row,column).toString());
this.setHorizontalAlignment(SwingConstants.LEFT);
}
return this;
}
}
/**
* Show the columns of the list table
* @author Neoya M <neoyaa@yahoo.com> 2002-03-13
*/
public void setShowColumn(String name,boolean value){
if(name.equals(Properties.SHOW_COLUMN_SIZE))
setShowColumn(2,value);
else if(name.equals(Properties.SHOW_COLUMN_DATE))
setShowColumn(3,value);
else if(name.equals(Properties.SHOW_COLUMN_TYPE))
setShowColumn(4,value);
else if(name.equals(Properties.SHOW_COLUMN_PROPERTIES))
setShowColumn(5,value);
}
public void setShowColumn(int column,boolean value){
sorter.setShowColumn(column,value);
//Reset the columns width
TableColumn c;
for (int i = 0; i < 2; i++) {
c = fileListTable.getColumnModel().getColumn(i);
if (i == 0) {
c.setPreferredWidth(18); //icon column
c.setMaxWidth(18);
c.setMinWidth(18);
} else {
c.setPreferredWidth(110); // filename column
c.setMinWidth(110);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -