Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of Sun Microsystems nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.sun.swingset3.utilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.AbstractAction;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.LookAndFeel;
import javax.swing.RowFilter;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableRowSorter;
/**
* Simple application which displays the contents of the UIDefaults hash map
* for the current look and feel.
*
* @author aim
*/
public class DefaultsDisplay extends JPanel {
private static final int rowHeight = 32;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("UIDefaults Display");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new DefaultsDisplay());
frame.pack();
frame.setVisible(true);
}
});
}
private String OSXLookAndFeelName; // hack for look-and-feel name mismatch on OS X
private Map lookAndFeelsMap;
private final Map defaultsTablesMap;
private JComboBox lookAndFeelComboBox;
private JCheckBox onlyVisualsCheckBox;
private JTabbedPane tabPane;
private RowFilter visualsFilter;
/** Creates a new instance of DefaultsDisplayer */
public DefaultsDisplay() {
defaultsTablesMap = new HashMap();
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
if (System.getProperty("os.name").equals("Mac OS X")) {
OSXLookAndFeelName = UIManager.getLookAndFeel().getName();
}
} catch (Exception ex) {
// better work :-)
}
setLayout(new BorderLayout());
JPanel controls = new JPanel();
controls.add(createLookAndFeelControl());
controls.add(createFilterControl());
add(controls, BorderLayout.NORTH);
tabPane = new JTabbedPane();
add(tabPane, BorderLayout.CENTER);
addDefaultsTab();
}
protected JComponent createLookAndFeelControl() {
JPanel panel = new JPanel();
JLabel label = new JLabel("Current Look and Feel");
lookAndFeelComboBox = new JComboBox();
label.setLabelFor(lookAndFeelComboBox);
panel.add(label);
panel.add(lookAndFeelComboBox);
// Look for toolkit look and feels first
UIManager.LookAndFeelInfo lookAndFeelInfos[] = UIManager.getInstalledLookAndFeels();
lookAndFeelsMap = new HashMap();
for(UIManager.LookAndFeelInfo info : lookAndFeelInfos) {
String name = info.getName();
// workaround for problem where Info and name property don't match on OS X
if (name.equals("Mac OS X")) {
name = OSXLookAndFeelName;
}
// workaround for bug where Nimbus classname is incorrect
lookAndFeelsMap.put(name, name.equals("Nimbus")?
"com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" :
info.getClassName());
lookAndFeelComboBox.addItem(name);
}
lookAndFeelComboBox.setSelectedItem(UIManager.getLookAndFeel().getName());
lookAndFeelComboBox.addActionListener(new ChangeLookAndFeelAction());
return panel;
}
protected JComponent createFilterControl() {
onlyVisualsCheckBox = new JCheckBox("Show Only Visual Defaults");
onlyVisualsCheckBox.setSelected(true);
onlyVisualsCheckBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
boolean showOnlyVisuals = onlyVisualsCheckBox.isSelected();
for(int i = 0; i < tabPane.getTabCount() ; i++) {
JScrollPane scrollpane = (JScrollPane)tabPane.getComponentAt(i);
JTable table = (JTable)scrollpane.getViewport().getView();
TableRowSorter sorter = (TableRowSorter)table.getRowSorter();
sorter.setRowFilter(showOnlyVisuals? visualsFilter : null);
}
}
});
return onlyVisualsCheckBox;
}
protected boolean hasDefaultsTab(String lookAndFeelName) {
return defaultsTablesMap.get(lookAndFeelName) != null;
}
protected void addDefaultsTab() {
LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
JScrollPane scrollPane = new JScrollPane(createDefaultsTable());
tabPane.addTab(lookAndFeel.getName() + " Defaults", scrollPane);
defaultsTablesMap.put(lookAndFeel.getName(), scrollPane);
}
protected JTable createDefaultsTable() {
JTable table = new JTable(new UIDefaultsTableModel());
table.setRowHeight(rowHeight);
table.setShowHorizontalLines(false);
table.setShowVerticalLines(false);
table.setIntercellSpacing(new Dimension(0,0));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
initFilters(table);
DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
Color rowColors[] = new Color[2];
rowColors[0] = UIManager.getColor("Table.background");
rowColors[1] = new Color((int)(rowColors[0].getRed() * .90),
(int)(rowColors[0].getGreen() * .95),
(int)(rowColors[0].getBlue() * .95));
int width = 0;
TableColumn column = new TableColumn();
column.setCellRenderer(new KeyRenderer(rowColors));
column.setModelIndex(UIDefaultsTableModel.KEY_COLUMN);
column.setHeaderValue("Key");
column.setPreferredWidth(250);
columnModel.addColumn(column);
width += column.getPreferredWidth();
column = new TableColumn();
column.setCellRenderer(new RowRenderer(rowColors));
column.setModelIndex(UIDefaultsTableModel.TYPE_COLUMN);
column.setHeaderValue("Type");
column.setPreferredWidth(250);
columnModel.addColumn(column);
width += column.getPreferredWidth();
column = new TableColumn();
column.setCellRenderer(new ValueRenderer(rowColors));
column.setModelIndex(UIDefaultsTableModel.VALUE_COLUMN);
column.setHeaderValue("Value");
column.setPreferredWidth(300);
columnModel.addColumn(column);
width += column.getPreferredWidth();
table.setColumnModel(columnModel);
table.setPreferredScrollableViewportSize(new Dimension(width, 12 * rowHeight));
return table;
}
protected void initFilters(JTable table) {
TableRowSorter sorter = new TableRowSorter(table.getModel());
table.setRowSorter(sorter);
if (visualsFilter == null) {
visualsFilter = new RowFilter() {
public boolean include(Entry extends UIDefaultsTableModel, ? extends Integer> entry) {
UIDefaultsTableModel model = entry.getModel();
Object defaultsValue = model.getValueAt(entry.getIdentifier().intValue(),
UIDefaultsTableModel.VALUE_COLUMN);
return defaultsValue instanceof Color ||
defaultsValue instanceof Font ||
defaultsValue instanceof Icon;
}
};
}
if (onlyVisualsCheckBox.isSelected()) {
sorter.setRowFilter(visualsFilter);
}
}
private class ChangeLookAndFeelAction extends AbstractAction {
public ChangeLookAndFeelAction() {
super("Change LookAndFeel");
}
public void actionPerformed(ActionEvent event) {
String lookAndFeelName = (String)lookAndFeelComboBox.getSelectedItem();
try {
UIManager.setLookAndFeel(lookAndFeelsMap.get(lookAndFeelName));
SwingUtilities.updateComponentTreeUI(DefaultsDisplay.this.getTopLevelAncestor());
if (!hasDefaultsTab(lookAndFeelName)) {
addDefaultsTab();
}
tabPane.setSelectedComponent(defaultsTablesMap.get(lookAndFeelName));
} catch (Exception ex) {
System.err.println("could not change look and feel to " + lookAndFeelName);
System.err.println(ex);
}
}
}
private static class UIDefaultsTableModel extends AbstractTableModel {
private static final int KEY_COLUMN = 0;
private static final int TYPE_COLUMN = 1;
private static final int VALUE_COLUMN = 2;
private UIDefaults defaults;
private List