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