KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > rero > dialogs > toolkit > APanel


1 package rero.dialogs.toolkit;
2
3 import javax.swing.*;
4 import javax.swing.event.*;
5
6 import java.awt.*;
7 import java.awt.event.*;
8
9 import java.util.*;
10
11 public abstract class APanel extends JPanel
12 {
13    protected GridBagConstraints constraints;
14    protected GridBagLayout layout;
15
16    public abstract void setupDialog(Object JavaDoc value); /* to be done *immediaely* before displaying the component */
17    public abstract Object JavaDoc getValue(Object JavaDoc value);
18
19    public APanel()
20    {
21        constraints = new GridBagConstraints();
22        constraints.gridwidth = GridBagConstraints.REMAINDER;
23        constraints.fill = GridBagConstraints.BOTH;
24        constraints.weightx = 1.0;
25        constraints.insets = new Insets(0, 0, 2, 0);
26
27        layout = new GridBagLayout();
28        setLayout(layout);
29    }
30
31    /** called whenever this panel is added to a dialog, so the parent dialog can be processed by this panel */
32    public void processParent(ADialog parent)
33    {
34         
35    }
36
37    public void addComponent(JComponent blah)
38    {
39        layout.setConstraints(blah, constraints);
40        add(blah);
41    }
42
43    public static JComponent mergeComponents(JLabel label, JComponent c)
44    {
45        JPanel temp = new JPanel();
46        temp.setLayout(new BorderLayout());
47        temp.add(label, BorderLayout.WEST);
48        temp.add(c, BorderLayout.CENTER);
49        
50        return temp;
51    }
52
53    public static JComponent mergeComponents(JLabel label, JComponent c, int gapint)
54    {
55        JPanel temp = new JPanel();
56        temp.setLayout(new BorderLayout());
57        temp.add(label, BorderLayout.WEST);
58        temp.add(c, BorderLayout.CENTER);
59        
60        JPanel gap = new JPanel();
61        gap.setPreferredSize(new Dimension(gapint, 0));
62        temp.add(gap, BorderLayout.EAST);
63
64        return temp;
65    }
66 }
67
Popular Tags