Programming with a mouse unit.

William Overington

Copyright 2001 William Overington

Tuesday 17 July 2001

This document introduces some software to simulate a mouse unit of a DVB-MHP terminal upon a web page.

First of all let me say that I am not purporting expertise in how the DVB-MHP system works. I am seeking in this document to present a web based simulation of what I want a very simple program that uses a mouse to do on a DVB-MHP system, from the standpoint of an application programmer who wishes to program content to be broadcast to run on a DVB-MHP system, yet having the knowledge that a mouse is not an obligatory feature on a DVB-MHP terminal and that there is a software method available to detect whether any particular DVB-MHP terminal has a mouse attached.

From presenting this web based simulation and hopefully it becoming read by experts who will know how to convert it to run on a DVB-MHP terminal, I hope to learn how to program such a program to run on a DVB-MHP terminal. I feel that small specific examples such as this program will be helpful generally, for as DVB-MHP becomes established, with many software authors seeking to program content, then many of them will have no great knowledge of the underlying construction of the DVB-MHP platform but will simply wish to program upon the platform as it exists. This may be especially true of people who are not primarily programmers yet who wish to program their own content, such as a free to the end user distance education package, into DVB-MHP format ready for broadcasting and wish to use only a number of the more commonly used features of the Java programming language.

I begin by generating a file ast00601.java as a copy of the file ast00501.java that I used in the "Programming with twenty buttons." document. I change the name of the class to become ast00601 and change the date.

I add the word MouseListener at the top of the program.

I add

int pressx,pressy;

in the global declarations.

I add the mouse listener adding the line

addMouseListener(this);

to the program. I have included this immediately after adding the buttons.

I add five functions to handle mouse events that might be generated by the MouseListener, notwithstanding that I shall only use one of them and the other four I shall program to do nothing.

I now proceed to program the mousePressed function in the very particular way that I need for this simulation and to add other software.

I shall also make other changes and additions to the software, though I mention that no alterations are being made to the software that sets up the buttons and the fonts.

This web based simulation needs a mouse to run on the web. Yet in the simulated DVB-MHP terminal there may or may not be a mouse unit available. The program needs to deal with both cases, as the same program that is being broadcast on a DVB-MHP channel may be received by some terminals that have a mouse unit and by some terminals that do not have a mouse unit attached.

I use the terms "web mouse" and "DVB-MHP mouse" to help explain the situation.

The web mouse is always present in this simulation, the DVB-MHP mouse may or may not be present depending upon the parameters of the simulation at any time.

In my simulation I provide the facility as to whether to use the DVB-MHP mouse by clicking with the web mouse in the lower part of the white area that is between the simulated display screen and the simulated hand held infra-red control device. Clicking in the left half of the white area will mean that there is not a DVB-MHP mouse present in the simulation and clicking in the right half of the white area will mean that there is a DVB-MHP mouse present in the simulation. I say clicking, and one may click, yet I program this with the mousePressed function.

I mentioned the lower part of the white area. The upper part of that white area is unused so as to give a blank area below the simulated display screen just in case a click intended for the bottom of the simulated display screen is clicked a few pixels low in error. With the present arrangement such an erroneous click will just be ignored: otherwise the simulation management environment might be unintentionally commanded to restart the simulation with possibly a different choice of whether to have a DVB-MHP mouse simulated as being attached to the simulated DVB-MHP terminal.

Please note that clicking in the lower part of the white area causes an obeycode of 1 to be acted upon. That is, the simulation restarts with the new status of whether the DVB-MHP mouse is present. The mousePressed function does not cause any indication as to whether there is a DVB-MHP mouse attached to the system to appear on the screen. In this example, I have chosen, within the application program part of the simulation, to output messages which indicate whether a mouse is attached to the simulated DVB-MHP terminal. That is because this particular application program benefits from that output. However, in some other application program simulated using this same mousePressed function a programmer may well choose not to make any on screen statement as to whether a mouse is connected to the DVB-MHP terminal.

Please note that for this program that the obeying of the software in the paint function for obeycode having a value of 1 includes drawing the simulated display screen as black. This is because the software in the paint function for obeycode having a value of 1 is obeyed not only at start up but whenever the status of whether a DVB-MHP is simulated as having a mouse attached is changed.

From the DVB-MHP specification it appears that detection of whether a mouse is present will be performed using a method named getInputDeviceSupported in relation to a mouse unit that returns true if a mouse exists in the system, false otherwise. As yet I do not understand how to set this up for a program running on a DVB-MHP platform and in any case I do not have a DVB-MHP platform upon which to try it, so I am using a function that I call SIMULATION_FOR_MOUSE_getInputDeviceSupported which returns true if a DVB-MHP mouse is simulated as being in the system at the time that the function is called, false otherwise. This is implemented by using a boolean variable named SIMULATION_DVB_MHP_MOUSE_ATTACHED that starts off as false and may be altered in value by clicking in the white areas previously mentioned. A convention of using this program is that the simulated application (that is, in this case, the three triangles display) may use the method SIMULATION_FOR_MOUSE_getInputDeviceSupported but not the boolean value of SIMULATION_DVB_MHP_MOUSE_ATTACHED directly. When it is possible to convert the program to run on a DVB-MHP terminal, the function SIMULATION_FOR_MOUSE_getInputDeviceSupported can be changed to become getInputDeviceSupported for whatever object is necessary in that conversion. The value of SIMULATION_DVB_MHP_MOUSE_ATTACHED will be meaningless in the DVB-MHP version of the program and the SIMULATION_DVB_MHP_MOUSE_ATTACHED variable will not need to exist in the DVB-MHP version of the program as SIMULATION_DVB_MHP_MOUSE_ATTACHED is just a value used in this web based simulation of the DVB-MHP system.

I shall make this demonstration program act such that, if there is a mouse unit being simulated as being available on the DVB-MHP terminal, the program draws a yellow triangle onto the simulated display screen in response to three mouse presses upon the simulated display screen, the vertices of the triangle being where the mouse presses take place.

If there is not a simulated DVB-MHP mouse attached to the simulated DVB-MHP terminal, the program will say so and draw a yellow triangle in a fixed position, saying that that is a typical result.

Thus the demonstration program will be a simulation of a program that may be broadcast on a DVB-MHP system, making provision for checking on each end user terminal as to whether a mouse is available and acting accordingly upon the result of such checking.

Here is a link to viewing the web based simulation. A Java enabled browser is required.

The web based simulation of programming with a mouse unit.

Here is the source code of the Java applet.

import java.awt.*;
import java.awt.event.*;
 
public class ast00601 extends java.applet.Applet implements
                               ActionListener,MouseListener
 
// Software written by William Overington
// WOverington@ngo.globalnet.co.uk
// 17 July 2001
// Copyright 2001 William Overington
//
 
  {
    int obeycode;
    int storedobeycode;
    int pressx,pressy;
 
    int point;
    int x1,y1,x2,y2,x3,y3;
 
    boolean SIMULATION_DVB_MHP_MOUSE_ATTACHED=false;
// this is what the simulation management environment knows
 
    boolean mouseattached;
// this is what the simulated program knows
 
    Button colourButton1  = new Button("");
    Button colourButton2  = new Button("");
    Button colourButton3  = new Button("");
    Button colourButton4  = new Button("");
    Button digitButton0   = new Button("0");
    Button digitButton1   = new Button("1");
    Button digitButton2   = new Button("2");
    Button digitButton3   = new Button("3");
    Button digitButton4   = new Button("4");
    Button digitButton5   = new Button("5");
    Button digitButton6   = new Button("6");
    Button digitButton7   = new Button("7");
    Button digitButton8   = new Button("8");
    Button digitButton9   = new Button("9");
    Button upButton       = new Button("^");
    Button downButton     = new Button("v");
    Button leftButton     = new Button("<");
    Button rightButton    = new Button(">");
    Button enterButton    = new Button("E");
    Button teletextButton = new Button("T");
 
// polyglot compatibility section starts
    String gomessagea1of2="Please click on the screen in three";
    String gomessagea2of2="places to draw a triangle.";
    String nomessagea="No mouse attached.";
    String nomessageb="With a mouse the program draws triangles.";
    String nomessagec="Here is a typical result.";
// polyglot compatibility section finishes
 
    Font buttonsfont,displayfont;
 
    public void init()
      {
        setLayout(null);
        setBounds(0,0,512,400);
 
        buttonsfont = new Font("SansSerif", Font.PLAIN, 18);
        displayfont = new Font("SansSerif", Font.PLAIN, 24);
        setFont(buttonsfont);
 
        colourButton1.addActionListener(this);
        colourButton1.setLocation(16,327);
        colourButton1.setSize(25,25);
        colourButton1.setBackground(Color.red);
        add(colourButton1);
        colourButton2.addActionListener(this);
        colourButton2.setLocation(48,327);
        colourButton2.setSize(25,25);
        colourButton2.setBackground(Color.green);
        add(colourButton2);
        colourButton3.addActionListener(this);
        colourButton3.setLocation(80,327);
        colourButton3.setSize(25,25);
        colourButton3.setBackground(Color.yellow);
        add(colourButton3);
        colourButton4.addActionListener(this);
        colourButton4.setLocation(112,327);
        colourButton4.setSize(25,25);
        colourButton4.setBackground(Color.blue);
        add(colourButton4);
        digitButton0.addActionListener(this);
        digitButton0.setLocation(16,359);
        digitButton0.setSize(25,25);
        digitButton0.setBackground(Color.lightGray);
        add(digitButton0);
        digitButton1.addActionListener(this);
        digitButton1.setLocation(48,359);
        digitButton1.setSize(25,25);
        digitButton1.setBackground(Color.lightGray);
        add(digitButton1);
        digitButton2.addActionListener(this);
        digitButton2.setLocation(80,359);
        digitButton2.setSize(25,25);
        digitButton2.setBackground(Color.lightGray);
        add(digitButton2);
        digitButton3.addActionListener(this);
        digitButton3.setLocation(112,359);
        digitButton3.setSize(25,25);
        digitButton3.setBackground(Color.lightGray);
        add(digitButton3);
        digitButton4.addActionListener(this);
        digitButton4.setLocation(144,359);
        digitButton4.setSize(25,25);
        digitButton4.setBackground(Color.lightGray);
        add(digitButton4);
        digitButton5.addActionListener(this);
        digitButton5.setLocation(176,359);
        digitButton5.setSize(25,25);
        digitButton5.setBackground(Color.lightGray);
        add(digitButton5);
        digitButton6.addActionListener(this);
        digitButton6.setLocation(208,359);
        digitButton6.setSize(25,25);
        digitButton6.setBackground(Color.lightGray);
        add(digitButton6);
        digitButton7.addActionListener(this);
        digitButton7.setLocation(240,359);
        digitButton7.setSize(25,25);
        digitButton7.setBackground(Color.lightGray);
        add(digitButton7);
        digitButton8.addActionListener(this);
        digitButton8.setLocation(272,359);
        digitButton8.setSize(25,25);
        digitButton8.setBackground(Color.lightGray);
        add(digitButton8);
        digitButton9.addActionListener(this);
        digitButton9.setLocation(304,359);
        digitButton9.setSize(25,25);
        digitButton9.setBackground(Color.lightGray);
        add(digitButton9);
        upButton.addActionListener(this);
        upButton.setLocation(372,327);
        upButton.setSize(25,25);
        upButton.setBackground(Color.lightGray);
        add(upButton);
        downButton.addActionListener(this);
        downButton.setLocation(372,359);
        downButton.setSize(25,25);
        downButton.setBackground(Color.lightGray);
        add(downButton);
        leftButton.addActionListener(this);
        leftButton.setLocation(340,343);
        leftButton.setSize(25,25);
        leftButton.setBackground(Color.lightGray);
        add(leftButton);
        rightButton.addActionListener(this);
        rightButton.setLocation(404,343);
        rightButton.setSize(25,25);
        rightButton.setBackground(Color.lightGray);
        add(rightButton);
        enterButton.addActionListener(this);
        enterButton.setLocation(439,359);
        enterButton.setSize(25,25);
        enterButton.setBackground(Color.lightGray);
        add(enterButton);
        teletextButton.addActionListener(this);
        teletextButton.setLocation(471,359);
        teletextButton.setSize(25,25);
        teletextButton.setBackground(Color.lightGray);
        add(teletextButton);
 
        addMouseListener(this);
 
        setBackground(Color.black);
 
        obeycode=1;
        storedobeycode=1;
 
      }
 
    public void actionPerformed(ActionEvent event)
      {
        Object source = event.getSource();
 
        if (source == colourButton1)
          {
            obeycode=51;
            repaint();
          }
        else
        if (source == colourButton2)
          {
            obeycode=52;
            repaint();
          }
        else
        if (source == colourButton3)
          {
            obeycode=53;
            repaint();
          }
        else
        if (source == colourButton4)
          {
            obeycode=54;
            repaint();
          }
        else
        if (source == digitButton0)
          {
            obeycode=20;
            repaint();
          }
        else
        if (source == digitButton1)
          {
            obeycode=21;
            repaint();
          }
        else
        if (source == digitButton2)
          {
            obeycode=22;
            repaint();
          }
        else
        if (source == digitButton3)
          {
            obeycode=23;
            repaint();
          }
        else
        if (source == digitButton4)
          {
            obeycode=24;
            repaint();
          }
        else
        if (source == digitButton5)
          {
            obeycode=25;
            repaint();
          }
        else
        if (source == digitButton6)
          {
            obeycode=26;
            repaint();
          }
        else
        if (source == digitButton7)
          {
            obeycode=27;
            repaint();
          }
        else
        if (source == digitButton8)
          {
            obeycode=28;
            repaint();
          }
        else
        if (source == digitButton9)
          {
            obeycode=29;
            repaint();
          }
        else
        if (source == upButton)
          {
            obeycode=61;
            repaint();
          }
        else
        if (source == downButton)
          {
            obeycode=62;
            repaint();
          }
        else
        if (source == leftButton)
          {
            obeycode=63;
            repaint();
          }
        else
        if (source == rightButton)
          {
            obeycode=64;
            repaint();
          }
        else
        if (source == enterButton)
          {
            obeycode=91;
            repaint();
          }
        else
        if (source == teletextButton)
          {
            obeycode=92;
            repaint();
          }
 
      }
 
    public void mousePressed(MouseEvent e)
      {
        pressx=e.getX();
        pressy=e.getY();
 
        if ((pressy > 300) & (pressy < 311))
// then a command to the simulation environment management is intended
//
// the 300 is used in the test rather than 288 so as to give a blank area below
// the simulated display screen just in case a click intended for the bottom
// of the simulated display screen is clicked a few pixels low in error 
          {
            if (pressx < 256) // simulated no DVB-MHP mouse
              {
                SIMULATION_DVB_MHP_MOUSE_ATTACHED=false;
              }
            else // simulated DVB-MHP mouse present
              {
                SIMULATION_DVB_MHP_MOUSE_ATTACHED=true;
              }
            obeycode=1;
            repaint();
          }
        else if (pressy <= 287)
// then a click within the simulation on the simulated display screen is intended
          {
            if(SIMULATION_DVB_MHP_MOUSE_ATTACHED)
              {
                obeycode=41;
                repaint();
              }
            else
              {
                donothing();
              }
          }
        else
// the mouse press is on the simulated hand held infra-red control device
// or the upper part of the white area and is disregarded
          {
            donothing();
          }
 
      }
 
    public void mouseReleased(MouseEvent e)
      {
 
      }
 
    public void mouseClicked(MouseEvent e)
      {
 
      }
 
    public void mouseEntered(MouseEvent e)
      {
       
      }
 
    public void mouseExited(MouseEvent e)
      {
        
      }
 
    public void paint(Graphics screen)
      {
 
        storedobeycode=obeycode;
 
        screen.setFont(displayfont);
 
        if (obeycode == 1)
          {
// start up for the simulation management
            screen.setColor(Color.black);
            screen.fillRect(0,0,512,288);
            screen.setColor(Color.white);
            screen.fillRect(0,288,512,112);
            screen.setColor(Color.gray);
            screen.fillRoundRect(0,311,512,89,20,20);
            screen.clipRect(0,0,512,288);
// start up for the program that is being simulated
            mouseattached=SIMULATION_FOR_MOUSE_getInputDeviceSupported();
            if(mouseattached)
              {
                screen.setColor(Color.yellow);
                screen.drawString(gomessagea1of2,20,50);
// gomessagea1of2 in English is "Please click on the screen in three"
                screen.drawString(gomessagea2of2,20,100);
// gomessagea2of2 in English is "places to draw a triangle."
                point=1;
              }
            else // no mouse attached
              {
                screen.setColor(Color.yellow);
                screen.drawString(nomessagea,20,50);
// nomessagea in English is "No mouse attached."
                screen.drawString(nomessageb,20,100);
// nomessageb in English is "With a mouse the program draws triangles."
                screen.drawString(nomessagec,20,150);
// nomessagec in English is "Here is a typical result."
                screen.setColor(Color.yellow);
                x1=50;
                y1=200;
                x2=400;
                y2=170;
                x3=220;
                y3=250;
                screen.drawLine(x1,y1,x2,y2);
                screen.drawLine(x2,y2,x3,y3);
                screen.drawLine(x3,y3,x1,y1);
              }
          }
 
        if(obeycode == 41)
          {
            if (point == 1)
              {
                x1=pressx;
                y1=pressy;
                screen.setColor(Color.black);
                screen.fillRect(0,0,512,288);
                screen.setColor(Color.yellow);
                screen.drawLine(x1,y1,x1,y1);
// placing one pixel on the screen at the chosen point
                point=2;
              }
            else if (point == 2)
              {
                x2=pressx;
                y2=pressy;
                screen.setColor(Color.yellow);
                screen.drawLine(x1,y1,x2,y2);
                point=3;
              }
            else
              {
                x3=pressx;
                y3=pressy;
                screen.setColor(Color.yellow);
                screen.drawLine(x2,y2,x3,y3);
                screen.drawLine(x3,y3,x1,y1);
                point=1;
              }
          }
 
        obeycode=1;      
      }
 
    public void update(Graphics screen)
      {
        paint(screen);
      }
 
    private void donothing()
      {
//      does nothing
      }
 
    private boolean SIMULATION_FOR_MOUSE_getInputDeviceSupported()
      {
        return SIMULATION_DVB_MHP_MOUSE_ATTACHED;
      }
 
  }

The question that I still need to resolve is how to write a Java program that produces upon a DVB-MHP system the same graphic demonstration that appears in the upper panel of this web based simulation.

However, I feel that this software does enable authorship of software for Astrolabe Channel to proceed. Hopefully at some stage whatever software has by that time been produced in simulation will be fairly easily converted to run on DVB-MHP terminals, and hopefully the very fact that that software is available and ready to go will, on a parallel to the scientific adage that chance favours the prepared observer, perhaps by being available and ready to go will favour the chances of Astrolabe Channel becoming broadcast on one or more DVB-MHP services throughout the world.

 

Astrolabe Channel

Copyright 2001 William Overington

This file is accessible as follows.

http://www.users.globalnet.co.uk/~ngo/ast00600.htm