TutorialTest.java :  » Math » migen » uk » ac » lkl » migen » exp » help » Java Open Source

Java Open Source » Math » migen 
migen » uk » ac » lkl » migen » exp » help » TutorialTest.java
package uk.ac.lkl.migen.exp.help;

import java.awt.event.ActionEvent;

import javax.swing.JButton;
import javax.swing.JComponent;

import uk.ac.lkl.common.ui.jft.CallOut;
import uk.ac.lkl.common.ui.jft.CircleHighlight;
import uk.ac.lkl.common.ui.jft.PaperNoteCallOut;
import uk.ac.lkl.common.ui.jft.Stencil;
import uk.ac.lkl.common.ui.jft.ThoughtBubbleCallOut;
import uk.ac.lkl.migen.system.ai.feedback.ui.callout.CallOutForAttribute;
import uk.ac.lkl.migen.system.expresser.ExternalInterface;
import uk.ac.lkl.migen.system.expresser.model.ModelColor;
import uk.ac.lkl.migen.system.expresser.model.shape.block.BlockShape;
import uk.ac.lkl.migen.system.expresser.model.shape.block.PatternShape;
import uk.ac.lkl.migen.system.expresser.ui.AttributeManifest;
import java.awt.event.ActionListener;

public class TutorialTest implements ActionListener {

    Stencil stencil;

    public TutorialTest(Stencil stencil) {
  this.stencil= stencil;  
    }

    public int state = 0; 

    private void toggleStencil() {
  if (stencil.isVisible()) {
      stencil.removeAll();
      stencil.setVisible(false);
  } else {
      stencil.setVisible(true);
  }  
    }

    public void next()  {
  System.out.println("NEXT CALLED:" + state);
  CallOut callOut;
  JButton button;

  //the selected tab for thet tuorial
  int selectedTabbedPanel = ExternalInterface.getTabbedPanelSelectedIndex();

  @SuppressWarnings("unused")
  JComponent numberSource = ExternalInterface.getNumberSource();
  @SuppressWarnings("unused")
  JComponent blueTile = ExternalInterface.getTileButton(ModelColor.BLUE);
  //JComponent playButton = ExternalInterface.getPlayButton();
//  JComponent slaveCanvas = ExternalInterface.getSlaveCanvas(selectedTabbedPanel);
  JComponent masterCanvas = ExternalInterface.getMasterCanvas(selectedTabbedPanel);

  //stencil.addHoleFor(ExternalInterface.getMasterCanvas(0));


  //the pattern
  BlockShape thePattern = ExternalInterface.getShapes(selectedTabbedPanel).get(0);
  System.out.println("The Pattern");
  System.out.println(thePattern);

  switch (state) {
  case 0: 

      callOut = new ThoughtBubbleCallOut();
      callOut.setContent("Now you can: <br>1. Unlock a number <br>2. Animate a pattern <br> <br>If you are happy, click next.");
      button = new JButton("Next");
      button.addActionListener(this);
      callOut.add(button);
      stencil.add(callOut);
      toggleStencil();

      state = 1;
      break;
  case 1:

      //open the tutorial pattern manifest
      ExternalInterface.setPropertyListOpen(selectedTabbedPanel, thePattern, true);

      AttributeManifest propertiesManifest = ExternalInterface.getManifestOpenForShape(selectedTabbedPanel, thePattern);

      callOut = new PaperNoteCallOut();
      callOut.setContent("Click the building block icon,<br>it opens its properties.");
      button = new JButton("OK");
      //this is the proper listener for here but...
      button.addActionListener(this);
      //...stopping the tutorial here for KK to test soemthing
      //      button.addActionListener(new ActionListener() {
      //
      //    public void actionPerformed(ActionEvent e) {
      //        toggleStencil();
      //    }
      //
      //      });

      callOut.addTarget(propertiesManifest.getThumbNailButton());
      stencil.addHoleFor(propertiesManifest.getThumbNailButton());
      callOut.add(button);

      stencil.add(callOut);
      toggleStencil();

      state = 2;
      break;
  case 2:


      BlockShape baseShape = thePattern.getAttributeValue(PatternShape.SHAPE); 

      AttributeManifest propertiesManifest2 = ExternalInterface.getManifestOpenForShape(selectedTabbedPanel, thePattern);

      AttributeManifest bbPropertiesManifest  =  propertiesManifest2.showBuildingBlockManifest(baseShape);

      JComponent numberOfBuildingBlocksArea = (JComponent)bbPropertiesManifest.getConstructionExpressionStart();


      callOut = new ThoughtBubbleCallOut();
      callOut.setContent("<b>Think:</b> how many tiles make<br>the building block?");
      button = new JButton("OK");
      button.addActionListener(this);
      callOut.addTarget(numberOfBuildingBlocksArea);

      stencil.addHoleFor(masterCanvas);
      callOut.add(button);

      stencil.add(callOut);
      toggleStencil();

      state = 3;
      break;

  case 3:

      String text = "As you know, if you unlock a<br>number, you can change it.";
      CallOutForAttribute callout = new CallOutForAttribute(selectedTabbedPanel, thePattern, PatternShape.ITERATIONS ,text); 
      callout.addActionListenerToOkButton(this);

      stencil.add(callout);
      toggleStencil();

      state = 4;
      break;
  case 4:

      text = "Change the number of building blocks, and see what happens.";
      CallOut callout2 = new PaperNoteCallOut();
      callout2.setContent(text);
      button = new JButton("OK");
      callout2.add(button);
      callout2.addTarget(ExternalInterface.getRowPanelForAttributeOfHandle(selectedTabbedPanel, thePattern, PatternShape.ITERATIONS).getExpressionPanel()); 
      callout2.addHighlightTarget(ExternalInterface.getRowPanelForAttributeOfHandle(selectedTabbedPanel, thePattern, PatternShape.ITERATIONS).getExpressionPanel()); 
      callout2.setHighlight(new CircleHighlight());

      button.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
        toggleStencil();
    }

      });

      stencil.add(callout2);
      toggleStencil();

      state = 5;
      break;
  case 5:

      text = "Well done. <br> Make sure you name your unlocked number.";
      CallOut callout4 = new PaperNoteCallOut();
      callout4.setContent(text);
      button = new JButton("OK");
      callout4.add(button);
      callout4.addTarget(ExternalInterface.getRowPanelForAttributeOfHandle(selectedTabbedPanel, thePattern, PatternShape.ITERATIONS).getExpressionPanel()); 
      callout4.addHighlightTarget(ExternalInterface.getRowPanelForAttributeOfHandle(selectedTabbedPanel, thePattern, PatternShape.ITERATIONS).getExpressionPanel()); 
      callout4.setHighlight(new CircleHighlight());

      button.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
        toggleStencil();
    }

      });

      stencil.add(callout4);
      toggleStencil();

      state = 6;
      break;
  case 6:

      text = "Well done.<br>Now let's see how to colour<br>the General (Any) Model.";
      CallOut callout3 = new PaperNoteCallOut();
      callout3.setContent(text);
      button = new JButton("OK");
      callout3.add(button);
      button.addActionListener(new ActionListener() {

    public void actionPerformed(ActionEvent e) {
        toggleStencil();
    }

      });

      stencil.add(callout3);
      toggleStencil();

      state = 6;
      break;
  case 7:
      //toggleStencil();
      System.out.println("case 6 - not working at the moment");

      //stencil.removeAll();
      //this was before when we were sending frame
      //TODO: think how to do this now that stencil is sent
      //stencil = new Stencil(frame,false);
      //stencil.addCoverFor(ExternalInterface.getSlaveCanvas(0));
      //stencil.addCoverFor(numberSource);
      //System.out.println("New stencil added");
      break;
  default:
      System.err.println("Unexpected state " + state);
  }
    }

    public void actionPerformed(ActionEvent e)
    {
  toggleStencil();
  next();
    }



}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.