Advertisement
Advertisement
| 09.02.2008 at 09:30PM PDT, ID: 23698217 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: |
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.filechooser.FileSystemView;
import sun.awt.shell.ShellFolder;
public class MainClass {
public static void main(String args[]) throws Exception {
MainClass mc = new MainClass();
Object elements[][] = { {"first.doc",mc.getIcone(mc.getExtension("first.doc".toUpperCase()))},
{"second.pdf",mc.getIcone(mc.getExtension("second.pdf".toUpperCase()))},
{"third.txt",mc.getIcone(mc.getExtension("third.txt".toUpperCase()))} ,
{"first.doc",mc.getIcone(mc.getExtension("first.doc".toUpperCase()))},
{"second.pdf",mc.getIcone(mc.getExtension("second.pdf".toUpperCase()))},
{"third.txt",mc.getIcone(mc.getExtension("third.txt".toUpperCase()))}
};
JFrame frame = new JFrame("Trial");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JList jlist = new JList(elements);
ListCellRenderer renderer = new ComplexCellRenderer();
jlist.setCellRenderer(renderer);
jlist.setLayoutOrientation(JList.HORIZONTAL_WRAP);
jlist.setVisibleRowCount(-1);
JScrollPane scrollPane = new JScrollPane(jlist);
frame.add(scrollPane, BorderLayout.CENTER);
frame.setSize(300, 200);
frame.setVisible(true);
}
public String getExtension(String name)
{
if(name.lastIndexOf(".")!=-1)
{
String extensionPossible = name.substring(name.lastIndexOf(".")+1, name.length());
if(extensionPossible.length()>6)
{
return "";
}
else
{
return extensionPossible;
}
}
else return "";
}
public Icon getIcone(String extension)
{
File file;
String cheminIcone = "";
if(((System.getProperties().get("os.name").toString()).startsWith("Mac")))
cheminIcone = System.getProperties().getProperty("file.separator");
else if(((System.getProperties().get("os.name").toString()).startsWith("Linux")))
cheminIcone = "/"+"tmp"+"/BoooDrive-"+System.getProperty("user.name")+"/";
else cheminIcone = System.getenv("TEMP") + System.getProperties().getProperty("file.separator");
File repIcone = new File(cheminIcone);
if(!repIcone.exists()) repIcone.mkdirs();
try
{
if(extension.equals("FOLDER"))
{
file = new File(cheminIcone + "icon");
file.mkdir();
}
else
{
file = new File(cheminIcone + "icon." + extension.toLowerCase());
file.createNewFile();
}
Icon icone = getSystemIcon(file);
file.delete();
return icone;
}
catch (IOException e){ }
return null;
}
public static Icon getSystemIcon(File f) {
if (f != null) {
Class fsv = FileSystemView.class;
try {
Method m = fsv.getDeclaredMethod("getShellFolder", new Class[]{File.class});
m.setAccessible(true);
ShellFolder sf = (ShellFolder) m.invoke(FileSystemView.getFileSystemView(), f);
Image img = sf.getIcon(true);
if (img != null) {
return new ImageIcon(img, sf.getFolderType());
} else {
return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
}
} catch (Exception e) {e.printStackTrace();}
}
return null;
}
}
class ComplexCellRenderer implements ListCellRenderer {
protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
public Component getListCellRendererComponent(JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
Icon icon = null;
String theText = null;
JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index,
isSelected, cellHasFocus);
renderer.setVerticalTextPosition(JLabel.BOTTOM);
renderer.setHorizontalTextPosition(JLabel.CENTER);
if (value instanceof Object[]) {
Object values[] = (Object[]) value;
theText = (String) values[0];
icon = (Icon) values[1];
} else {
}
renderer.setText(theText);
renderer.setIcon(icon);
return renderer;
}
}
|