Bug fixes and startup checks
[debian/openrocket] / src / net / sf / openrocket / gui / components / DescriptionArea.java
1 package net.sf.openrocket.gui.components;
2
3 import java.awt.Dimension;
4 import java.awt.Rectangle;
5
6 import javax.swing.JPanel;
7 import javax.swing.JScrollPane;
8 import javax.swing.ScrollPaneConstants;
9
10 import net.miginfocom.swing.MigLayout;
11
12 public class DescriptionArea extends JScrollPane {
13
14         private ResizeLabel text;
15         private MigLayout layout;
16         private JPanel panel;
17         
18         public DescriptionArea(int rows) {
19                 this(rows, -2);
20         }
21         
22         public DescriptionArea(int rows, float size) {
23                 super(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
24                                 ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
25                 
26                 layout = new MigLayout("ins 0 2px, fill");
27                 panel = new JPanel(layout);
28                 
29                 text = new ResizeLabel(" ",size);
30                 text.validate();
31                 Dimension dim = text.getPreferredSize();
32                 dim.height = (dim.height+2)*rows + 2;
33                 this.setPreferredSize(dim);
34                 
35                 panel.add(text, "growx");
36                 
37                 this.setViewportView(panel);
38                 this.revalidate();
39         }
40         
41         public void setText(String txt) {
42                 if (!txt.startsWith("<html>"))
43                         txt = "<html>" + txt;
44                 text.setText(txt);
45         }
46         
47         
48         @Override
49         public void validate() {
50                 
51                 Rectangle dim = this.getViewportBorderBounds();
52                 layout.setComponentConstraints(text, "width "+ dim.width + ", growx");
53                 super.validate();
54                 text.validate();
55
56         }
57         
58 }