Something went wrong. Try again.
2-APL UPC project.
Something went wrong. Try again.
2.2 kB · 74 lines
Java
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475package blockworld.lib;
import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.Insets;
import javax.swing.BorderFactory;import javax.swing.JComponent;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.border.Border;
/** * Groups a set of attribute views together into a Panel. The group has a title * that is shown in a border. */public class AttrGroup extends JPanel {
private static final long serialVersionUID = -1420253091328660372L;
protected GridBagLayout gridbag = new GridBagLayout();
protected GridBagConstraints constraints = new GridBagConstraints();
/** Construct a AttrGroup with the title "Attributes". */ public AttrGroup() { this( "Attributes" ); }
/** * Construct a group with the specified title. * * @param title * The title of this group, this shown in a border. */ public AttrGroup( String title ) { Border etche = BorderFactory.createEtchedBorder();
setBorder( BorderFactory.createTitledBorder( etche, title ) ); // setLayout(new GridLayout(0, 2, 5, 0));
// / set initial layout settings setLayout( gridbag ); constraints.anchor = GridBagConstraints.EAST; constraints.insets = new Insets( 1, 5, 2, 5 ); }
protected void addRow( String descr, JComponent view ) { JLabel label = new JLabel( descr );
label.setLabelFor( view );
constraints.gridwidth = GridBagConstraints.RELATIVE; // next-to-last constraints.fill = GridBagConstraints.NONE; // reset to default constraints.weightx = 0.0; // reset to default
gridbag.setConstraints( label, constraints ); add( label );
constraints.gridwidth = GridBagConstraints.REMAINDER; // end row constraints.fill = GridBagConstraints.HORIZONTAL; constraints.weightx = 1.0; gridbag.setConstraints( view, constraints ); add( view ); }
/** * Add a read only int attribute to this attribute group. This constructs * the correct view and adds a label showing the attribute name. */ public void add( ROIntegerAttr attr ) { addRow( attr.getName(), new ROIntegerView( attr ) ); }}