-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathCHeader.java
More file actions
86 lines (71 loc) · 2.8 KB
/
Copy pathCHeader.java
File metadata and controls
86 lines (71 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// -*- mode: java; c-basic-offset: 2; -*-
// Copyright 2009-2011 Google, All Rights reserved
// Copyright 2011-2012 MIT, All rights reserved
// Released under the MIT License https://raw.github.com/mit-cml/app-inventor/master/mitlicense.txt
package openblocks.codeblockutil;
import info.clearthought.layout.TableLayout;
import info.clearthought.layout.TableLayoutConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class CHeader extends JPanel {
private static final int LEFTNAV_WIDTH = 180;
private static final int HEADER_HEIGHT = 40;
private JLabel headerLabel;
public CHeader(JComponent[] buttonsLeft, JComponent[] buttonsRight) {
super();
this.setOpaque(false);
double[][] size = {
{LEFTNAV_WIDTH, TableLayoutConstants.FILL},
{HEADER_HEIGHT}};
this.setLayout(new TableLayout(size));
headerLabel = new JLabel("", JLabel.LEFT);
headerLabel.setOpaque(false);
headerLabel.setFont(new Font("Arial", Font.BOLD, 15));
headerLabel.setForeground(Color.WHITE);
headerLabel.setPreferredSize(new Dimension(LEFTNAV_WIDTH, HEADER_HEIGHT));
// set left margin
headerLabel.setBorder(new EmptyBorder(0, 10, 0, 0));
this.add(headerLabel, "0, 0, l, c");
JPanel buttonPane = new JPanel();
buttonPane.setOpaque(false);
buttonPane.setLayout(new BorderLayout());
JPanel leftButtonPane = new JPanel();
leftButtonPane.setOpaque(false);
// don't understand why this pane is not vertically centered
leftButtonPane.setBorder(new EmptyBorder(2, 0, 0, 0));
for(int j = 0; j < buttonsLeft.length; j++){
leftButtonPane.add(buttonsLeft[j]);
}
buttonPane.add(leftButtonPane, BorderLayout.WEST);
// this.add(leftButtonPane, "1, 0, l, c");
JPanel rightButtonPane = new JPanel();
rightButtonPane.setOpaque(false);
for(int j = 0; j < buttonsRight.length; j++){
rightButtonPane.add(buttonsRight[j]);
}
buttonPane.add(rightButtonPane, BorderLayout.EAST);
// this.add(rightButtonPane, "2, 0, r, c");
this.add(buttonPane, "1, 0, f, c");
}
public void setHeaderText(String headerText) {
headerLabel.setText(headerText);
}
public void paint(Graphics g){
Graphics2D g2 = (Graphics2D )g;
g2.setColor(CGraphite.medgreen);
g2.fillRect(0,0,this.getWidth(), this.getHeight());
super.paint(g);
}
public void resize(){
this.invalidate();
this.revalidate();
}
}