1 /*
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
94
95 int sortDirection = 0;
96 if ("ascending".equalsIgnoreCase(direction+"")) {
97 sortDirection = 1;
98 } else if ("descending".equalsIgnoreCase(direction+"")) {
99 sortDirection = -1;
100 } else if ("decending".equalsIgnoreCase(direction+"")) {
101 sortDirection = -1; // stupid misspelling that GM'ed in 10.5.0
102 }
103
104 final TableHeaderUI headerUI = target.getUI();
105 if (headerUI == null || !(headerUI instanceof AquaTableHeaderUI)) return;
106
107 final AquaTableHeaderUI aquaHeaderUI = (AquaTableHeaderUI)headerUI;
108 aquaHeaderUI.sortColumn = tableColumn.getModelIndex();
109 aquaHeaderUI.sortOrder = sortDirection;
110 final AquaTableCellRenderer renderer = aquaHeaderUI.new AquaTableCellRenderer();
111 tableColumn.setHeaderRenderer(renderer);
112 }
113
114 class AquaTableCellRenderer extends DefaultTableCellRenderer implements UIResource {
115 public Component getTableCellRendererComponent(final JTable localTable, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
116 if (localTable != null) {
117 if (header != null) {
118 setForeground(header.getForeground());
119 setBackground(header.getBackground());
120 setFont(UIManager.getFont("TableHeader.font"));
121 }
122 }
123
124 setText((value == null) ? "" : value.toString());
125
126 // Modify the table "border" to draw smaller, and with the titles in the right position
127 // and sort indicators, just like an NSSave/Open panel.
128 final AquaTableHeaderBorder cellBorder = AquaTableHeaderBorder.getListHeaderBorder();
129 final boolean thisColumnSelected = localTable.getColumnModel().getColumn(column).getModelIndex() == sortColumn;
130
131 cellBorder.setSelected(thisColumnSelected);
132 if (thisColumnSelected) {
133 cellBorder.setSortOrder(sortOrder);
|
1 /*
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
94
95 int sortDirection = 0;
96 if ("ascending".equalsIgnoreCase(direction+"")) {
97 sortDirection = 1;
98 } else if ("descending".equalsIgnoreCase(direction+"")) {
99 sortDirection = -1;
100 } else if ("decending".equalsIgnoreCase(direction+"")) {
101 sortDirection = -1; // stupid misspelling that GM'ed in 10.5.0
102 }
103
104 final TableHeaderUI headerUI = target.getUI();
105 if (headerUI == null || !(headerUI instanceof AquaTableHeaderUI)) return;
106
107 final AquaTableHeaderUI aquaHeaderUI = (AquaTableHeaderUI)headerUI;
108 aquaHeaderUI.sortColumn = tableColumn.getModelIndex();
109 aquaHeaderUI.sortOrder = sortDirection;
110 final AquaTableCellRenderer renderer = aquaHeaderUI.new AquaTableCellRenderer();
111 tableColumn.setHeaderRenderer(renderer);
112 }
113
114 @SuppressWarnings("serial") // Superclass is not serializable across versions
115 class AquaTableCellRenderer extends DefaultTableCellRenderer implements UIResource {
116 public Component getTableCellRendererComponent(final JTable localTable, final Object value, final boolean isSelected, final boolean hasFocus, final int row, final int column) {
117 if (localTable != null) {
118 if (header != null) {
119 setForeground(header.getForeground());
120 setBackground(header.getBackground());
121 setFont(UIManager.getFont("TableHeader.font"));
122 }
123 }
124
125 setText((value == null) ? "" : value.toString());
126
127 // Modify the table "border" to draw smaller, and with the titles in the right position
128 // and sort indicators, just like an NSSave/Open panel.
129 final AquaTableHeaderBorder cellBorder = AquaTableHeaderBorder.getListHeaderBorder();
130 final boolean thisColumnSelected = localTable.getColumnModel().getColumn(column).getModelIndex() == sortColumn;
131
132 cellBorder.setSelected(thisColumnSelected);
133 if (thisColumnSelected) {
134 cellBorder.setSortOrder(sortOrder);
|