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 org.apache.log4j.chainsaw.icons.ChainsawIcons;
21  
22  import javax.swing.*;
23  import java.awt.*;
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  
28  /**
29   * @author Paul Smith <psmith@apache.org>
30   */
31  public class ChainsawColumns {
32      private static final List<String> columnNames = new ArrayList<>();
33  
34      static {
35          columnNames.add(ChainsawConstants.LOGGER_COL_NAME);
36          columnNames.add(ChainsawConstants.LOG4J_MARKER_COL_NAME_LOWERCASE.toUpperCase()); //add uppercase col name
37          columnNames.add(ChainsawConstants.TIMESTAMP_COL_NAME);
38          columnNames.add(ChainsawConstants.LEVEL_COL_NAME);
39          columnNames.add(ChainsawConstants.THREAD_COL_NAME);
40          columnNames.add(ChainsawConstants.MESSAGE_COL_NAME);
41          columnNames.add(ChainsawConstants.NDC_COL_NAME);
42          columnNames.add(ChainsawConstants.THROWABLE_COL_NAME);
43          columnNames.add(ChainsawConstants.CLASS_COL_NAME);
44          columnNames.add(ChainsawConstants.METHOD_COL_NAME);
45          columnNames.add(ChainsawConstants.FILE_COL_NAME);
46          columnNames.add(ChainsawConstants.LINE_COL_NAME);
47          columnNames.add(ChainsawConstants.MILLIS_DELTA_COL_NAME_LOWERCASE.toUpperCase()); //add uppercase col name
48  
49          //NOTE:  ID must ALWAYS be last field because the model adds this value itself as an identifier to the end of the consructed vector
50          columnNames.add(ChainsawConstants.ID_COL_NAME);
51      }
52  
53      public static final int INDEX_LOGGER_COL_NAME = 1;
54      public static final int INDEX_LOG4J_MARKER_COL_NAME = 2;
55      public static final int INDEX_TIMESTAMP_COL_NAME = 3;
56      public static final int INDEX_LEVEL_COL_NAME = 4;
57      public static final int INDEX_THREAD_COL_NAME = 5;
58      public static final int INDEX_MESSAGE_COL_NAME = 6;
59      public static final int INDEX_NDC_COL_NAME = 7;
60      public static final int INDEX_THROWABLE_COL_NAME = 8;
61      public static final int INDEX_CLASS_COL_NAME = 9;
62      public static final int INDEX_METHOD_COL_NAME = 10;
63      public static final int INDEX_FILE_COL_NAME = 11;
64      public static final int INDEX_LINE_COL_NAME = 12;
65      public static final int INDEX_MILLIS_DELTA_COL_NAME = 13;
66      public static final int INDEX_ID_COL_NAME = 14;
67  
68      public static final Cursor CURSOR_FOCUS_ON;
69  
70      static {
71          CURSOR_FOCUS_ON = Toolkit.getDefaultToolkit().createCustomCursor(new ImageIcon(ChainsawIcons.WINDOW_ICON).getImage(), new Point(3, 3), "FocusOn");
72      }
73  
74      private ChainsawColumns() {
75      }
76  
77      public static List<String> getColumnsNames() {
78          return columnNames;
79      }
80  
81      /**
82       * Given the index which matches one of the static constants in this class, returns the resolved
83       * Column name as a string label.
84       *
85       * @param columnIndex (note this is a 1 based collection)
86       * @return column name
87       */
88      public static String getColumnName(int columnIndex) {
89          return getColumnsNames().get(columnIndex - 1).toString();
90      }
91  }