package com.apple.laf;
import java.awt.*;
import java.util.Enumeration;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicTableHeaderUI;
import javax.swing.table.*;
import com.apple.laf.ClientPropertyApplicator;
import com.apple.laf.ClientPropertyApplicator.Property;
import com.apple.laf.AquaUtils.RecyclableSingleton;
public class extends BasicTableHeaderUI {
private int ;
protected int sortColumn;
protected int ;
public static ComponentUI (final JComponent c) {
return new AquaTableHeaderUI();
}
public void () {
super.installDefaults();
final TableCellRenderer renderer = header.getDefaultRenderer();
if (renderer instanceof UIResource && renderer instanceof DefaultTableCellRenderer) {
final DefaultTableCellRenderer defaultRenderer = (DefaultTableCellRenderer)renderer;
originalHeaderAlignment = defaultRenderer.getHorizontalAlignment();
defaultRenderer.setHorizontalAlignment(SwingConstants.LEADING);
}
}
public void () {
final TableCellRenderer renderer = header.getDefaultRenderer();
if (renderer instanceof UIResource && renderer instanceof DefaultTableCellRenderer) {
final DefaultTableCellRenderer defaultRenderer = (DefaultTableCellRenderer)renderer;
defaultRenderer.setHorizontalAlignment(originalHeaderAlignment);
}
super.uninstallDefaults();
}
final static RecyclableSingleton<ClientPropertyApplicator<JTableHeader, JTableHeader>> = new RecyclableSingleton<ClientPropertyApplicator<JTableHeader, JTableHeader>>() {
@Override
protected ClientPropertyApplicator<JTableHeader, JTableHeader> () {
return new ClientPropertyApplicator<JTableHeader, JTableHeader>(
new Property<JTableHeader>("JTableHeader.selectedColumn") {
public void (final JTableHeader target, final Object value) {
tickle(target, value, target.getClientProperty("JTableHeader.sortDirection"));
}
},
new Property<JTableHeader>("JTableHeader.sortDirection") {
public void (final JTableHeader target, final Object value) {
tickle(target, target.getClientProperty("JTableHeader.selectedColumn"), value);
}
}
);
}
};
static ClientPropertyApplicator<JTableHeader, JTableHeader> () {
return TABLE_HEADER_APPLICATORS.get();
}
static void (final JTableHeader target, final Object selectedColumn, final Object direction) {
final TableColumn tableColumn = getTableColumn(target, selectedColumn);
if (tableColumn == null) return;
int sortDirection = 0;
if ("ascending".equalsIgnoreCase(direction+"")) {
sortDirection = 1;
} else if ("descending".equalsIgnoreCase(direction+"")) {
sortDirection = -1;
} else if ("decending".equalsIgnoreCase(direction+"")) {
sortDirection = -1;
}
final TableHeaderUI headerUI = target.getUI();
if (headerUI == null || !(headerUI instanceof AquaTableHeaderUI)) return;
final AquaTableHeaderUI aquaHeaderUI = (AquaTableHeaderUI)headerUI;
aquaHeaderUI.sortColumn = tableColumn.getModelIndex();
aquaHeaderUI.sortOrder = sortDirection;
final AquaTableCellRenderer renderer = aquaHeaderUI.new AquaTableCellRenderer();
tableColumn.setHeaderRenderer(renderer);
}
class extends DefaultTableCellRenderer implements UIResource {
public Component (final JTable localTable, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
if (localTable != null) {
if (header != null) {
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(UIManager.getFont("TableHeader.font"));
}
}
setText((value == null) ? "" : value.toString());
final AquaTableHeaderBorder cellBorder = AquaTableHeaderBorder.getListHeaderBorder();
final boolean thisColumnSelected = localTable.getColumnModel().getColumn(column).getModelIndex() == sortColumn;
cellBorder.setSelected(thisColumnSelected);
if (thisColumnSelected) {
cellBorder.setSortOrder(sortOrder);
} else {
cellBorder.setSortOrder(AquaTableHeaderBorder.SORT_NONE);
}
setBorder(cellBorder);
return this;
}
}
protected static TableColumn getTableColumn(final JTableHeader target, final Object value) {
if (value == null || !(value instanceof Integer)) return null;
final int columnIndex = ((Integer)value).intValue();
final TableColumnModel columnModel = target.getColumnModel();
if (columnIndex < 0 || columnIndex >= columnModel.getColumnCount()) return null;
return columnModel.getColumn(columnIndex);
}
protected static AquaTableHeaderBorder getAquaBorderFrom(final JTableHeader header, final TableColumn column) {
final TableCellRenderer renderer = column.getHeaderRenderer();
if (renderer == null) return null;
final Component c = renderer.getTableCellRendererComponent(header.getTable(), column.getHeaderValue(), false, false, -1, column.getModelIndex());
if (!(c instanceof JComponent)) return null;
final Border border = ((JComponent)c).getBorder();
if (!(border instanceof AquaTableHeaderBorder)) return null;
return (AquaTableHeaderBorder)border;
}
protected void () {
super.installListeners();
getTableHeaderApplicators().attachAndApplyClientProperties(header);
}
protected void () {
getTableHeaderApplicators().removeFrom(header);
super.uninstallListeners();
}
private int () {
int height = 0;
boolean accomodatedDefault = false;
final TableColumnModel columnModel = header.getColumnModel();
for (int column = 0; column < columnModel.getColumnCount(); column++) {
final TableColumn aColumn = columnModel.getColumn(column);
if (aColumn.getHeaderRenderer() != null || !accomodatedDefault) {
final Component comp = getHeaderRendererAqua(column);
final int rendererHeight = comp.getPreferredSize().height;
height = Math.max(height, rendererHeight);
if (rendererHeight > 4) {
accomodatedDefault = true;
}
}
}
return height;
}
private Component (final int columnIndex) {
final TableColumn aColumn = header.getColumnModel().getColumn(columnIndex);
TableCellRenderer renderer = aColumn.getHeaderRenderer();
if (renderer == null) {
renderer = header.getDefaultRenderer();
}
return renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, columnIndex);
}
private Dimension (long width) {
if (width > Integer.MAX_VALUE) {
width = Integer.MAX_VALUE;
}
return new Dimension((int)width, getHeaderHeightAqua());
}
public Dimension (final JComponent c) {
long width = 0;
final Enumeration<TableColumn> enumeration = header.getColumnModel().getColumns();
while (enumeration.hasMoreElements()) {
final TableColumn aColumn = enumeration.nextElement();
width = width + aColumn.getMinWidth();
}
return createHeaderSizeAqua(width);
}
public Dimension (final JComponent c) {
long width = 0;
final Enumeration<TableColumn> enumeration = header.getColumnModel().getColumns();
while (enumeration.hasMoreElements()) {
final TableColumn aColumn = enumeration.nextElement();
width = width + aColumn.getPreferredWidth();
}
return createHeaderSizeAqua(width);
}
}