package test;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.List;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;
public class ShowUIDefaults
extends JFrame {
SampleRenderer sampleRenderer;
public ShowUIDefaults
(String title
) {
super(title);
frame = this;
sampleRenderer = new SampleRenderer();
tabbedPane = getTabbedPane();
getContentPane().add(tabbedPane);
}
Map<String, Map<String, Object>> components = new HashMap<String, Map<String, Object>>();
// Build of Map of attributes for each component
for (Enumeration<Object> anEnum = defaults.keys(); anEnum.hasMoreElements();) {
String key
= anEnum.
nextElement().
toString();
Object value
= defaults.
get(key
);
Map<String, Object> componentMap = getComponentMap(components, key);
if (componentMap != null) {
componentMap.put(key, value);
}
}
pane.
setPreferredSize(new Dimension(800, 400
));
addComponentTabs(pane, components);
return pane;
}
private Map
<String, Object
> getComponentMap
(Map
<String, Map
<String, Object
>> components,
String key
) {
if (key.startsWith("class") || key.startsWith("javax")) {
return null;
}
// Component name is found before the first "."
int pos = key.indexOf(".");
if (pos == -1) {
if (key.endsWith("UI")) {
componentName = key.substring(0, key.length() - 2);
}
else {
componentName = "System Colors";
}
}
else {
componentName = key.substring(0, pos);
}
// Fix inconsistency
if (componentName.equals("Checkbox")) {
componentName = "CheckBox";
}
// Get the Map for this particular component
Map<String, Object> componentMap = components.get(componentName);
if (componentMap == null) {
componentMap = new HashMap<String, Object>();
components.put(componentName, componentMap);
}
return componentMap;
}
private void addComponentTabs
(JTabbedPane pane, Map
<String, Map
<String, Object
>> components
) {
String[] colName
= { "Key",
"Value",
"Sample" };
List<String> c = new ArrayList<String>(components.keySet());
for (Iterator<String> ci = c.iterator(); ci.hasNext();) {
Map<String, Object> attributes = components.get(component);
int i = 0;
List<String> a = new ArrayList<String>(attributes.keySet());
for (Iterator<String> ai = a.iterator(); ai.hasNext(); i++)
{
rowData[i][0] = attribute;
Object o
= attributes.
get(attribute
);
if (o != null) {
rowData[i][1] = o.toString();
rowData[i][2] = o;
}
else {
rowData[i][1] = "null";
rowData[i][2] = "";
}
}
table.setCellSelectionEnabled(true);
table.getColumnModel().getColumn(2).setCellRenderer(sampleRenderer);
table.getColumnModel().getColumn(0).setPreferredWidth(250);
table.getColumnModel().getColumn(1).setPreferredWidth(500);
table.getColumnModel().getColumn(2).setPreferredWidth(50);
}
}
public SampleRenderer() {
super();
setOpaque(true); //MUST do this for background to show up.
}
boolean hasFocus, int row, int column) {
setBackground(null);
setBorder(null);
setIcon(null);
setText("");
if (sample
instanceof Color) {
setBackground
((Color) sample
);
}
else if (sample
instanceof Border) {
}
else if (sample
instanceof Font) {
setText("Sample");
}
else if (sample
instanceof Icon) {
}
return this;
}
@Override
try {
super.paint(g);
}
// do nothing
}
}
}
public static void main
(String[] args
) {
try {
// UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
// UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
e.printStackTrace();
e.printStackTrace();
e.printStackTrace();
e.printStackTrace();
}
JFrame f
= new ShowUIDefaults
("UI Defaults");
f.
setDefaultCloseOperation(JFrame.
EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public static void saveOptionPaneIcons() {
try {
ImageIO.
write((BufferedImage)icon.
getImage(),
"png",
new File("C:/backup/error.png"));
e.printStackTrace();
}
}
}