/* * Created on 12.08.2004 * * @author Jens Guenther */ package de.unirostock.AbstractFactory.example.awt; import java.awt.Color; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import javax.swing.JLabel; import javax.swing.JPanel; import de.unirostock.AbstractFactory.example.Ship; import de.unirostock.AbstractFactory.example.ShipFactory; import de.unirostock.AbstractFactory.example.Shipyard; public final class AssembledShipPanel extends JPanel { /** * * @uml.property name="factory" * @uml.associationEnd multiplicity="(0 1)" */ ShipFactory itsFactory; /** * * @uml.property name="shipyard" * @uml.associationEnd multiplicity="(0 1)" */ Shipyard itsShipyard; JLabel itsImageLabel; JLabel itsLabelType; JLabel itsLabelLoadingSpace; JLabel itsLabelMasts; JLabel itsLabelSails; public AssembledShipPanel() { itsShipyard = new Shipyard(); initGraphics(); } protected void init( ShipFactory factory ) { itsFactory = factory; itsImageLabel.setIcon( itsFactory.getPhotoIcon()); itsShipyard.setShipFactory( factory ); Ship ship = itsShipyard.assembleShip(); itsLabelType.setText( ""+ship.getType()); itsLabelLoadingSpace.setText( ""+ship.getLoadingSpace()); itsLabelMasts.setText( ""+ship.getMastCount()); itsLabelSails.setText( ""+ship.getSailCount()); } private void initGraphics() { setBackground( new Color( 255,255,255 )); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout( gridbag ); // image label itsImageLabel = new JLabel(); itsImageLabel.setBackground( new Color( 255,255,255 )); c.insets = new Insets( 25,5,5,25 ); c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.NONE; c.gridwidth = 1; c.gridheight= 5; gridbag.setConstraints( itsImageLabel, c ); add( itsImageLabel ); // Label type JLabel labelT = new JLabel( "Schiffstyp" ); labelT.setBackground( new Color( 255,255,255 )); c.insets = new Insets( 25,5,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 1; c.gridheight= 1; gridbag.setConstraints( labelT, c ); add( labelT ); // Label type value itsLabelType = new JLabel(); itsLabelType.setBackground( new Color( 255,255,255 )); itsLabelType.setHorizontalAlignment( JLabel.RIGHT ); c.insets = new Insets( 25,15,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight= 1; gridbag.setConstraints( itsLabelType, c ); add( itsLabelType ); // Label loading space JLabel labelLS = new JLabel( "Laderaum" ); labelLS.setBackground( new Color( 255,255,255 )); c.insets = new Insets( 5,5,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 1; c.gridheight= 1; gridbag.setConstraints( labelLS, c ); add( labelLS ); // Label loading space value itsLabelLoadingSpace = new JLabel(); itsLabelLoadingSpace.setBackground( new Color( 255,255,255 )); itsLabelLoadingSpace.setHorizontalAlignment( JLabel.RIGHT ); c.insets = new Insets( 5,15,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight= 1; gridbag.setConstraints( itsLabelLoadingSpace, c ); add( itsLabelLoadingSpace ); // Label masts JLabel labelM = new JLabel( "Anzahl Masten" ); labelM.setBackground( new Color( 255,255,255 )); c.insets = new Insets( 5,5,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 1; c.gridheight= 1; gridbag.setConstraints( labelM, c ); add( labelM ); // Label masts value itsLabelMasts = new JLabel(); itsLabelMasts.setBackground( new Color( 255,255,255 )); itsLabelMasts.setHorizontalAlignment( JLabel.RIGHT ); c.insets = new Insets( 5,15,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight= 1; gridbag.setConstraints( itsLabelMasts, c ); add( itsLabelMasts ); // Label sails JLabel labelS = new JLabel( "Anzahl Segel" ); labelS.setBackground( new Color( 255,255,255 )); c.insets = new Insets( 5,5,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = 1; c.gridheight= 1; gridbag.setConstraints( labelS, c ); add( labelS ); // Label sails value itsLabelSails = new JLabel(); itsLabelSails.setBackground( new Color( 255,255,255 )); itsLabelSails.setHorizontalAlignment( JLabel.RIGHT ); c.insets = new Insets( 5,15,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight= 1; gridbag.setConstraints( itsLabelSails, c ); add( itsLabelSails ); // space1 JPanel space1 = new JPanel(); space1.setBackground( new Color( 255,255,255 )); c.weightx = 1.0; c.weighty = 1.0; c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints( space1, c ); add( space1 ); } }