home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 November
/
Chip_1998-11_cd.bin
/
tema
/
Cafe
/
jfc.bin
/
BasicDirectoryPaneUI.java
< prev
next >
Wrap
Text File
|
1998-02-26
|
4KB
|
155 lines
/*
* @(#)BasicDirectoryPaneUI.java 1.9 98/02/03
*
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
package com.sun.java.swing.plaf.basic;
import com.sun.java.swing.*;
import com.sun.java.swing.preview.*;
import com.sun.java.swing.preview.JDirectoryPane;
import com.sun.java.swing.event.*;
import com.sun.java.swing.plaf.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.io.File;
import java.util.*;
/**
* A Basic L&F implementation of DirectoryPaneUI.
*
* @version 1.9 02/03/98
*
* @author Ray Ryan
* @author James Gosling
* @author Jeff Dinkins
*/
public class BasicDirectoryPaneUI extends DirectoryPaneUI {
protected JDirectoryPane directoryPane;
protected JList list;
protected JScrollPane scroller = null;
//
// ComponentUI Interface Implementation methods
//
public static ComponentUI createUI(JComponent c) {
return new BasicDirectoryPaneUI((JDirectoryPane)c);
}
public BasicDirectoryPaneUI(JDirectoryPane b) {
}
/**
* If necessary, create this UI's list and scroller.
* Put a BorderLayout in the component. Add the
* scroller to the "Center".
*/
public void installUI(JComponent c) {
directoryPane = (JDirectoryPane) c;
directoryPane.setLayout(new BorderLayout());
list = new JList();
list.setCellRenderer(new LabelCellRenderer());
list.setBackground(Color.white);
list.setModel(directoryPane.getModel());
// Do something useful on double-click
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
directoryPane.performDoubleClick();
}
}
});
scroller = new JScrollPane(list);
scroller.setBorder(BorderFactory.createLoweredBevelBorder());
directoryPane.add(scroller, BorderLayout.CENTER);
list.setSelectionModel(directoryPane.getListSelectionModel());
}
public void uninstallUI(JComponent c) {
if(c != directoryPane)
throw new IllegalComponentStateException(
this + " was asked to deinstall() "
+ c + " when it only knows about "
+ directoryPane + ".");
directoryPane.remove(scroller);
}
static Icon directoryIcon = null;
static Icon fileIcon = null;
static Icon computerIcon = null;
static Icon hardDriveIcon = null;
static Icon floppyDriveIcon = null;
static class LabelCellRenderer extends BasicListCellRenderer {
LabelCellRenderer() {
if (directoryIcon == null) {
directoryIcon = UIManager.getIcon("DirectoryPane.directoryIcon");
fileIcon = UIManager.getIcon("DirectoryPane.fileIcon");
computerIcon = UIManager.getIcon("DirectoryPane.computerIcon");
hardDriveIcon = UIManager.getIcon("DirectoryPane.hardDriveIcon");
floppyDriveIcon = UIManager.getIcon("DirectoryPane.floppyDriveIcon");
}
}
public Component getListCellRendererComponent(
JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index,
isSelected, cellHasFocus);
TypedFile file = (TypedFile)value;
String name = file.getName();
if (name.equals("")) name = file.getPath();
setText(name);
Icon icon = file.getIcon();
if (icon == null) {
FileType type = file.getType();
if (type instanceof FileType.Computer) {
icon = computerIcon;
}
else if (type instanceof FileType.FloppyDrive) {
icon = floppyDriveIcon;
}
else if (type instanceof FileType.HardDrive) {
icon = hardDriveIcon;
}
else if (type instanceof FileType.Folder) {
icon = directoryIcon;
} else {
icon = fileIcon;
}
}
setIcon(icon);
return this;
}
}
}