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  /*
19   * Created on 11/09/2003
20   *
21   * To change the template for this generated file go to
22   * Window - Preferences - Java - Code Generation - Code and Comments
23   */
24  package org.apache.log4j.chainsaw;
25  
26  import javax.swing.*;
27  import javax.swing.table.TableCellEditor;
28  import java.awt.*;
29  import java.awt.event.ActionEvent;
30  import java.awt.event.ActionListener;
31  
32  
33  /**
34   * An "editor" that doesn't allow editing, but allows the user to press a "..." for more detail about this
35   * Column.
36   *
37   * @author Paul Smith <psmith@apache.org>
38   */
39  class ThrowableRenderPanel extends AbstractCellEditor
40      implements TableCellEditor {
41      private final SmallButton btn = new SmallButton();
42      private final JLabel lbl = new JLabel("");
43      private final JPanel panel = new JPanel();
44      private Color background = new Color(255, 255, 254);
45      private final Color COLOR_ODD = new Color(230, 230, 230);
46      private final Action showStackTraceAction;
47  
48      ThrowableRenderPanel() {
49          panel.setLayout(new BorderLayout());
50          panel.add(lbl, BorderLayout.CENTER);
51          panel.add(btn, BorderLayout.EAST);
52          lbl.setOpaque(false);
53  //    btn.setOpaque(false);
54          showStackTraceAction =
55              new AbstractAction("...") {
56                  public void actionPerformed(ActionEvent e) {
57                  }
58              };
59          showStackTraceAction.putValue(
60              Action.SHORT_DESCRIPTION, "Display the full stack trace in a popup");
61          btn.setAction(showStackTraceAction);
62      }
63  
64      void addActionListener(ActionListener l) {
65          btn.addActionListener(l);
66      }
67  
68      /* (non-Javadoc)
69       * @see javax.swing.table.TableCellEditor#getTableCellEditorComponent(javax.swing.JTable, java.lang.Object, boolean, int, int)
70       */
71      public Component getTableCellEditorComponent(
72          JTable table, Object value, boolean isSelected, int row, int column) {
73          if (value instanceof String[] && ((String[]) value).length > 0) {
74              lbl.setText(((String[]) value)[0]);
75          } else {
76              lbl.setText("");
77          }
78  
79          if (isSelected) {
80              panel.setBackground(table.getSelectionBackground());
81              panel.setForeground(table.getSelectionForeground());
82          } else if ((row % 2) != 0) {
83              panel.setBackground(COLOR_ODD);
84              panel.setForeground(table.getSelectionForeground());
85          } else {
86              panel.setBackground(background);
87              panel.setForeground(table.getSelectionForeground());
88          }
89  
90          return panel;
91      }
92  
93      /* (non-Javadoc)
94       * @see javax.swing.CellEditor#getCellEditorValue()
95       */
96      public Object getCellEditorValue() {
97          return lbl.getText();
98      }
99  }