/* * 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 java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import de.unirostock.AbstractFactory.example.ShipFactory; public final class ViewComponentPanel extends JPanel implements ActionListener { /** * * @uml.property name="factory" * @uml.associationEnd multiplicity="(0 1)" */ ShipFactory itsFactory; JLabel itsImageLabel; private final static String BT_HULL = "BT_HULL"; private final static String BT_MASTS = "BT_MASTS"; private final static String BT_SAILS = "BT_SAILS"; private final static String BT_SHIP = "BT_SHIP"; public ViewComponentPanel() { initGraphics(); } public void actionPerformed( ActionEvent e ) { String cmd = e.getActionCommand(); if( cmd.equals( BT_HULL )) itsImageLabel.setIcon( itsFactory.getHullIcon()); if( cmd.equals( BT_MASTS )) itsImageLabel.setIcon( itsFactory.getMastsIcon()); if( cmd.equals( BT_SAILS )) itsImageLabel.setIcon( itsFactory.getSailsIcon()); if( cmd.equals( BT_SHIP )) itsImageLabel.setIcon( itsFactory.getPlanIcon()); } protected void init( ShipFactory factory ) { itsFactory = factory; itsImageLabel.setIcon( itsFactory.getPlanIcon()); } 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 ); // button hull JButton btHull = new JButton( "Rumpf" ); btHull.setActionCommand( BT_HULL ); btHull.addActionListener( this ); c.insets = new Insets( 25,5,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight= 1; gridbag.setConstraints( btHull, c ); add( btHull ); // button masts JButton btMasts = new JButton( "Masten" ); btMasts.setActionCommand( BT_MASTS ); btMasts.addActionListener( this ); c.insets = new Insets( 5,5,5,5 ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints( btMasts, c ); add( btMasts ); // button sails JButton btSails = new JButton( "Segel" ); btSails.setActionCommand( BT_SAILS ); btSails.addActionListener( this ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints( btSails, c ); add( btSails ); // 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 ); // button ship JButton btShip = new JButton( "Schiff" ); btShip.setActionCommand( BT_SHIP ); btShip.addActionListener( this ); c.weightx = 1.0; c.weighty = 0; c.fill = GridBagConstraints.HORIZONTAL; c.gridwidth = GridBagConstraints.REMAINDER; gridbag.setConstraints( btShip, c ); add( btShip ); } }