JAL-1807 - Bob's last(?) before leaving Dundee -- adds fast file loading
[jalviewjs.git] / src / jalview / appletgui / TitledPanel.java
1 package jalview.appletgui;
2
3 import awt2swing.Frame;
4 import java.awt.Graphics;
5 import java.awt.Insets;
6 import awt2swing.Label;
7 import awt2swing.Panel;
8 import java.awt.event.WindowAdapter;
9 import java.awt.event.WindowEvent;
10
11 public class TitledPanel extends Panel
12 {
13
14   private String title;
15
16   private Insets insets = new Insets(10, 10, 10, 10);
17
18   public TitledPanel()
19   {
20     this("");
21   }
22
23   public TitledPanel(String title)
24   {
25     this.setTitle(title);
26   }
27
28   public Insets getInsets()
29   {
30     return insets;
31   }
32
33   public void paintComponent(Graphics g)
34   {
35     super.paintComponent(g);
36     g.setColor(getForeground());
37     g.drawRect(5, 5, getWidth() - 10, getHeight() - 10);
38     int width = g.getFontMetrics().stringWidth(getTitle());
39     g.setColor(getBackground());
40     g.fillRect(10, 0, width, 10);
41     g.setColor(getForeground());
42     awt2swing.Util.drawString(g, getTitle(), 10, 10);
43   }
44
45   /**
46    * @j2sIgnore
47    * 
48    * @param args
49    */
50   public static void main(String[] args)
51   {
52     Frame f = new Frame("TitledPanel Tester");
53
54     TitledPanel p = new TitledPanel("Title of Panel");
55     p.add(new Label("Label 1"));
56     p.add(new Label("Label 2"));
57     p.add(new Label("Label 3"));
58     f.add(p);
59
60     f.addWindowListener(new WindowAdapter()
61     {
62       public void windowClosing(WindowEvent e)
63       {
64         System.exit(0);
65       }
66     });
67     f.setBounds(300, 300, 300, 300);
68     f.setVisible(true);
69   }
70
71   public String getTitle()
72   {
73     return title;
74   }
75
76   public void setTitle(String title)
77   {
78     this.title = title;
79   }
80 }