View Javadoc

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17
    18  package org.apache.log4j.chainsaw;
    19
    20  import javax.swing.*;
    21  import java.awt.*;
    22
    23
    24  /**
    25   * An Icon that is a Nice arrow to be used for displaying which
    26   * Column is being used for sorting.
    27   *
    28   * @author Claude Duguay
    29   */
    30  public class SortArrowIcon implements Icon {
    31      public static final int NONE = 0;
    32      public static final int DECENDING = 1;
    33      public static final int ASCENDING = 2;
    34      protected int direction;
    35      protected int width = 8;
    36      protected int height = 8;
    37
    38      public SortArrowIcon(int direction) {
    39          this.direction = direction;
    40      }
    41
    42      public int getIconWidth() {
    43          return width;
    44      }
    45
    46      public int getIconHeight() {
    47          return height;
    48      }
    49
    50      public void paintIcon(Component c, Graphics g, int x, int y) {
    51          Color bg = c.getBackground();
    52          Color light = bg.brighter();
    53          Color shade = bg.darker();
    54
    55          int w = width;
    56          int h = height;
    57          int m = w / 2;
    58
    59          if (direction == ASCENDING) {
    60              g.setColor(shade);
    61              g.drawLine(x, y, x + w, y);
    62              g.drawLine(x, y, x + m, y + h);
    63              g.setColor(light);
    64              g.drawLine(x + w, y, x + m, y + h);
    65          }
    66
    67          if (direction == DECENDING) {
    68              g.setColor(shade);
    69              g.drawLine(x + m, y, x, y + h);
    70              g.setColor(light);
    71              g.drawLine(x, y + h, x + w, y + h);
    72              g.drawLine(x + m, y, x + w, y + h);
    73          }
    74      }
    75  }