commit | author | age
|
44f2da
|
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 |
|
ee25c8
|
18 |
import java.awt.BasicStroke;
|
44f2da
|
19 |
import java.awt.Color;
|
JM |
20 |
import java.awt.GradientPaint;
|
|
21 |
import java.awt.Graphics;
|
|
22 |
import java.awt.Graphics2D;
|
f306ef
|
23 |
import java.awt.GridLayout;
|
JM |
24 |
import java.awt.Insets;
|
44f2da
|
25 |
import java.awt.Paint;
|
JM |
26 |
import java.awt.geom.Point2D;
|
|
27 |
import java.awt.geom.Rectangle2D;
|
f306ef
|
28 |
import java.text.SimpleDateFormat;
|
JM |
29 |
import java.util.Date;
|
44f2da
|
30 |
|
ee25c8
|
31 |
import javax.swing.ImageIcon;
|
44f2da
|
32 |
import javax.swing.JLabel;
|
JM |
33 |
import javax.swing.JPanel;
|
ee25c8
|
34 |
|
JM |
35 |
import com.gitblit.utils.StringUtils;
|
44f2da
|
36 |
|
JM |
37 |
public class HeaderPanel extends JPanel {
|
|
38 |
|
|
39 |
private static final long serialVersionUID = 1L;
|
|
40 |
|
f306ef
|
41 |
private final Insets insets = new Insets(5, 5, 5, 5);
|
JM |
42 |
|
44f2da
|
43 |
private Color lightColor = new Color(0, 0, 0x60);
|
JM |
44 |
|
f306ef
|
45 |
private JLabel headerLabel;
|
JM |
46 |
|
|
47 |
private JLabel refreshLabel;
|
|
48 |
|
ee25c8
|
49 |
public HeaderPanel(String text, String icon) {
|
f306ef
|
50 |
// super(new FlowLayout(FlowLayout.LEFT), true);
|
JM |
51 |
super(new GridLayout(1, 2, 5, 5), true);
|
44f2da
|
52 |
setOpaque(true);
|
JM |
53 |
setBackground(new Color(0, 0, 0x20));
|
|
54 |
|
f306ef
|
55 |
headerLabel = new JLabel(text);
|
ee25c8
|
56 |
if (!StringUtils.isEmpty(icon)) {
|
f306ef
|
57 |
headerLabel.setIcon(new ImageIcon(getClass().getResource("/" + icon)));
|
ee25c8
|
58 |
}
|
f306ef
|
59 |
headerLabel.setForeground(Color.white);
|
JM |
60 |
headerLabel.setFont(headerLabel.getFont().deriveFont(14f));
|
|
61 |
add(headerLabel);
|
|
62 |
|
|
63 |
refreshLabel = new JLabel("", JLabel.RIGHT);
|
|
64 |
refreshLabel.setForeground(Color.white);
|
|
65 |
add(refreshLabel);
|
|
66 |
}
|
|
67 |
|
|
68 |
public void setText(String text) {
|
|
69 |
headerLabel.setText(text);
|
|
70 |
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
71 |
refreshLabel.setText("refreshed " + df.format(new Date()));
|
|
72 |
}
|
|
73 |
|
|
74 |
@Override
|
|
75 |
public Insets getInsets() {
|
|
76 |
return insets;
|
44f2da
|
77 |
}
|
JM |
78 |
|
|
79 |
@Override
|
|
80 |
public void paintComponent(Graphics oldG) {
|
|
81 |
Graphics2D g = (Graphics2D) oldG;
|
|
82 |
Point2D startPoint = new Point2D.Float(0, 0);
|
|
83 |
Point2D endPoint = new Point2D.Float(0, getHeight());
|
|
84 |
Paint gradientPaint = new GradientPaint(startPoint, lightColor, endPoint, getBackground(),
|
|
85 |
false);
|
|
86 |
g.setPaint(gradientPaint);
|
|
87 |
g.fill(new Rectangle2D.Double(0, 0, getWidth(), getHeight()));
|
ee25c8
|
88 |
g.setColor(new Color(0xff, 0x99, 0x00));
|
JM |
89 |
int stroke = 2;
|
|
90 |
g.setStroke(new BasicStroke(stroke));
|
|
91 |
g.drawLine(0, getHeight() - 1, getWidth(), getHeight() - 1);
|
44f2da
|
92 |
}
|
JM |
93 |
}
|