2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.util
.xml
.ui
;
18 import javax
.swing
.table
.TableCellRenderer
;
25 public class StripeTableCellRenderer
implements TableCellRenderer
{
26 private final TableCellRenderer myRenderer
;
27 private static final double FACTOR
= 0.92;
29 public StripeTableCellRenderer(final TableCellRenderer renderer
) {
30 myRenderer
= renderer
;
34 public StripeTableCellRenderer() {
38 public static Color
darken(Color color
) {
39 return new Color(Math
.max((int)(color
.getRed() *FACTOR
), 0),
40 Math
.max((int)(color
.getGreen()*FACTOR
), 0),
41 Math
.max((int)(color
.getBlue() *FACTOR
), 0));
44 public Component
getTableCellRendererComponent(JTable table
, Object value
, boolean isSelected
, boolean hasFocus
, int row
, int column
) {
45 final JComponent component
= (JComponent
)getRenderer(row
, column
).getTableCellRendererComponent(table
, value
, isSelected
, hasFocus
, row
, column
);
46 if (row
% 2 != 0 && !isSelected
) {
47 component
.setBackground(darken(table
.getBackground()));
49 component
.setBackground(isSelected ? table
.getSelectionBackground() : table
.getBackground());
51 component
.setOpaque(true);
55 protected TableCellRenderer
getRenderer(int row
, int column
) {