Kensuke Matsuzaki
2013-04-15 ed566a162c780faa0d6c84fac8fbbd3738586445
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.BorderLayout;
19 import java.awt.Color;
20 import java.awt.Font;
21 import java.awt.GridLayout;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import javax.swing.JLabel;
26 import javax.swing.JPanel;
27 import javax.swing.JScrollPane;
28 import javax.swing.JTextArea;
29 import javax.swing.SwingConstants;
30
31 import com.gitblit.models.SettingModel;
32 import com.gitblit.utils.StringUtils;
33
34 /**
35  * This panel displays the metadata for a particular setting.
36  * 
37  * @author James Moger
38  */
39 public class SettingPanel extends JPanel {
40
41     private static final long serialVersionUID = 1L;
42     private JTextArea descriptionArea;
43     private JLabel settingName;
44     private JLabel settingDefault;
45     private JLabel sinceVersion;
46     private JLabel directives;
47
48     public SettingPanel() {
49         super();
50         initialize();
51     }
52
2a99c3 53     public SettingPanel(SettingModel setting) {
JM 54         this();
55         setSetting(setting);
56     }
57
b75734 58     private void initialize() {
JM 59         descriptionArea = new JTextArea();
60         descriptionArea.setRows(6);
61         descriptionArea.setFont(new Font("monospaced", Font.PLAIN, 11));
2a99c3 62         descriptionArea.setEditable(false);
b75734 63
JM 64         settingName = new JLabel(" ");
65         settingName.setFont(settingName.getFont().deriveFont(Font.BOLD));
66
67         settingDefault = new JLabel(" ");
68
69         sinceVersion = new JLabel(" ", SwingConstants.RIGHT);
70         sinceVersion.setForeground(new Color(0, 0x80, 0));
71
72         directives = new JLabel(" ", SwingConstants.RIGHT);
73         directives.setFont(directives.getFont().deriveFont(Font.ITALIC));
74
75         JPanel settingParameters = new JPanel(new GridLayout(2, 2, 0, 0));
76         settingParameters.add(settingName);
77         settingParameters.add(sinceVersion);
78         settingParameters.add(settingDefault, BorderLayout.CENTER);
79         settingParameters.add(directives);
80
81         JPanel settingPanel = new JPanel(new BorderLayout(5, 5));
82         settingPanel.add(settingParameters, BorderLayout.NORTH);
83         settingPanel.add(new JScrollPane(descriptionArea), BorderLayout.CENTER);
84         setLayout(new BorderLayout(0, 0));
85         add(settingPanel, BorderLayout.CENTER);
86     }
87
88     public void setSetting(SettingModel setting) {
89         settingName.setText(setting.name);
90         if (setting.since == null) {
91             sinceVersion.setText("custom");
2a99c3 92         } else {
b75734 93             sinceVersion.setText("since " + setting.since);
JM 94         }
2a99c3 95         settingDefault.setText(Translation.get("gb.default") + ": " + setting.defaultValue);
b75734 96
JM 97         List<String> values = new ArrayList<String>();
98         if (setting.caseSensitive) {
99             values.add("CASE-SENSITIVE");
100         }
101         if (setting.spaceDelimited) {
102             values.add("SPACE-DELIMITED");
103         }
104         if (setting.restartRequired) {
105             values.add("RESTART REQUIRED");
106         }
107         directives.setText(StringUtils.flattenStrings(values, ", "));
108
109         descriptionArea.setText(setting.description);
110         descriptionArea.setCaretPosition(0);
111     }
112
113     public void clear() {
114         settingName.setText(" ");
115         settingDefault.setText(" ");
116         sinceVersion.setText(" ");
117         directives.setText(" ");
118         descriptionArea.setText("");
119     }
120 }