package jas.util; import java.awt.Component; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Graphics; import java.awt.Insets; import java.awt.LayoutManager; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.Border; /** * A JPanel which has a checkbox embedded in its border. The contents of the panel * are automatically insensitized when the checkbox is turned off. */ public class CheckBoxBorderPanel extends JPanel implements ItemListener { public CheckBoxBorderPanel(String title) { this(title,null,null); } public CheckBoxBorderPanel(String title, Border border) { this(title,border,null); } public CheckBoxBorderPanel(String title, LayoutManager layout) { this(title,null,layout); } public CheckBoxBorderPanel(String title, Border border, LayoutManager layout) { if (layout == null) layout = new FlowLayout(); if (border == null) border = BorderFactory.createEtchedBorder(); checkbox = new JCheckBox(title); setLayout(layout); setBorder(border); add(checkbox,0); checkbox.addItemListener(this); } public void doLayout() { setEnabled(); checkbox.setVisible(false); super.doLayout(); checkbox.setVisible(true); Dimension size = checkbox.getPreferredSize(); checkbox.setSize(size); checkbox.setLocation(20,0); } public void itemStateChanged(ItemEvent e) { setEnabled(); } private void setEnabled() { boolean set = checkbox.isSelected(); Component[] children = getComponents(); for (int i=0; i