package tutorial.sample5;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.Graphics;

import javax.activation.DataHandler;

import java.awt.*;
import javax.swing.*;

public class HelloWorldService{

  /**
   * @wlws:part text location="attachment"
   * @wlws:part return location="attachment"
   */
  public Image helloAttachmentWorld( String text ){
    BufferedImage image = new BufferedImage( 300, 100, 
        BufferedImage.TYPE_INT_RGB );

    Graphics graphics = image.getGraphics();
    graphics.drawString( text, 10, 10 );

    return image; 
  }

  /**
   * @wlws:part dh location="attachment"
   * @wlws:part return location="attachment"
   */
  public DataHandler echoDataHandler(DataHandler dh) {
    return dh;
  }

  /**
   * @wlws:part dh location="attachment"
   * @wlws:part return location="attachment"
   */
  public DataHandler[] echoDataHandlerArray(DataHandler[] dh) {
    return dh;
  }

  /**
   * @wlws:part images location="attachment"
   * @wlws:part return location="attachment"
   */
  public Image[] echoImageArray(Image[] images) {
    return images;
  }

  private void displayImage( Image image ){
    JFrame frame = new JFrame( "Server Attachment Sample" );
    frame.setSize( 300, 100 );
    frame.getContentPane().setLayout( new FlowLayout() );
    frame.getContentPane().add( new JLabel( new ImageIcon( image ) ) );
    frame.setVisible( true );

    try{
      Thread.sleep( 5000 );
    }catch( Exception e ){}

    frame.setVisible( false );
  }
}

