KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > presentation > dpanels > DControlPanel


1 package discRack.presentation.dpanels;
2
3 import discRack.presentation.delements.*;
4
5 import java.awt.*;
6
7 /**
8  * Base class for panels with buttons that manages it's controlled panel.
9  *
10  * @author Sasa Bojanic
11  * @version 1.0
12  */

13 public abstract class DControlPanel extends DPanel {
14    protected DPanel controlledPanel;
15
16
17    public DControlPanel (DCollection myOwner,String JavaDoc title,
18       boolean isVertical,boolean hasBorder) {
19       super(myOwner,0,title,isVertical,hasBorder);
20    }
21
22    public void setControlledPanel(DPanel controlledPanel) {
23       this.controlledPanel = controlledPanel;
24    }
25
26    protected Dimension getPreferredDimension (String JavaDoc[] s) {
27       double longest=0;
28       double w=0;
29       for (int i=0;i<s.length; i++) {
30          String JavaDoc n=s[i];
31          try {
32             w=getFontMetrics(getFont()).stringWidth(s[i]);
33             if (w>longest) longest=w;
34          } catch(Exception JavaDoc ex) {}
35       }
36       double h=getFontMetrics(getFont()).getHeight();
37
38       w=longest+25;
39       //w=longest+20;
40
if (w<30) w=30;
41
42       return new Dimension((int)w,(int)h);
43    }
44
45 }
46
Popular Tags