James Moger
2012-09-10 fabe060d3a435f116128851f828e35c2af5fde67
commit | author | age
b75734 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package com.gitblit.client;
17
18 import java.awt.Color;
19 import java.awt.Component;
20 import java.awt.Font;
21
22 import javax.swing.JTable;
23 import javax.swing.table.DefaultTableCellRenderer;
24
25 import com.gitblit.models.SettingModel;
26
27 /**
28  * SettingModel cell renderer that indicates if a setting is the default or
29  * modified.
30  * 
31  * @author James Moger
32  * 
33  */
34 public class SettingCellRenderer extends DefaultTableCellRenderer {
35
36     private static final long serialVersionUID = 1L;
37
38     private final Font defaultFont;
39
40     private final Font modifiedFont;
41
42     public SettingCellRenderer() {
43         defaultFont = getFont();
44         modifiedFont = defaultFont.deriveFont(Font.BOLD);
45     }
46
47     public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
48             boolean hasFocus, int row, int column) {
49         super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
50         if (value instanceof SettingModel) {
51             SettingModel setting = (SettingModel) value;
52             if (setting.isDefaultValue()) {
53                 this.setFont(defaultFont);
54                 if (!isSelected) {
55                     this.setForeground(Color.BLACK);
56                 }
57             } else {
58                 this.setFont(modifiedFont);
59                 if (!isSelected) {
60                     this.setForeground(Color.BLUE);
61                 }
62             }
63             this.setText(setting.getString(""));
64         }
65         return this;
66     }
67 }