media @ VU
[] readme course preface I 1 2 II 3 4 III 5 6 7 IV 8 9 10 V 11 12 afterthoughts appendix references examples resources _

talk show tell print

music-dossier-searchBox.vr

music-dossier-searchBox.vr (wrl ) [ flux / bitmanagement / cortona / octaga ]


  
  
  #hoi ik ben een search box
  #als er op de knop nieuwe zoek actie gedrukt is,
  #laat ik een venster zien waarin de gebruiker zijn zoek opdracht kan in toetsen
  #als de gebruiker op enter drukt, voer ik de zoek actie uit
  #ik laat daarna de zoek resultaten zien
  #als de gebruiker op een zoek resultaat drukt stuur ik het ID van het geklikte 
  #resultaat naar de concept graph
  EXTERNPROTO KeySensor
  [
          eventIn SFBool eventsProcessed
          exposedField SFBool enabled 
          eventOut SFInt32 keyPress
          eventOut SFInt32 keyRelease
          eventOut SFInt32 actionKeyPress
          eventOut SFInt32 actionKeyRelease
          eventOut SFBool shiftKey_changed
          eventOut SFBool controlKey_changed
          eventOut SFBool altKey_changed
          eventOut SFBool isActive
  ]
  [
   "urn:inet:blaxxun.com:node:KeySensor",
   "http://www.blaxxun.com/vrml/protos/nodes.wrl#KeySensor"
  ]
  
  EXTERNPROTO ScrollPane [
          eventIn        SFString loadURL
          eventIn        SFString setText
          eventIn SFInt32 scrollText
          eventOut SFString linkClicked
          field SFInt32 maxCharsOnALine
  ]
  "music-dossier-text.wrl#ScrollPane"
  
  EXTERNPROTO magnify [
          eventIn        SFFloat        transparency
  ]
  "models/buttonBar/search/search_button.wrl#ModelSearchNode"
  
  PROTO SearchBox [
          eventIn MFNode setNodes
          eventOut SFString clickedID
          eventOut SFBool        ready
          eventIn        SFFloat        endTransparency
  ]{
  
          DEF onOffSW Switch {
                  whichChoice        0
                  choice [
                          Group {
                                  children [
                                          Transform {
                                                  translation        -3 14 0 
                                                  children [
                                                          DEF searchbutton magnify        {}
                                                          DEF activateSearchFieldTS TouchSensor        {}
                                                  ]
                                          }
  
                                          DEF searchSwitch Switch {
                                                  whichChoice        -1
                                                  choice [
                                                          Group {
                                                                  children [
                                                                          Transform {
                                                                                  translation        -3 -3.4 5
                                                                                  children [
                                                                                          Shape {
                                                                                                  geometry Text {
                                                                                                          string "Search for:"
                                  #                                                                        fontStyle FontStyle        {
                                  #                                                                                justify        "LEFT"
                                                                                  
  
                                  #                                                                        }
  
                                                                                                  }
                                                                                          }
                                                                                  ]
  
                                                                          }
  
                                                                          Transform {         # close button
                                                                                  translation        4.4 -3 5
                                                                                  children [
                                                                                          DEF butclosebb TouchSensor {
                                                                                          }
                                                                                          Shape {
                                                                                                  geometry Box {
                                                                                                          size 1 1 0.01
                                                                                                  }
                                                                                                  appearance Appearance {
                                                                                                          texture ImageTexture {
                                                                                                                  url        "images/close.jpg"
                                                                                                          }
                                                                                                          material DEF closebutton Material {
                                                                                                          }
                                                                                                  }
                                                                                          }
                                                                                  ]
                                                                          }        
  
                                                                          DEF        search_go_button Transform {
                                                                                  translation        2.1 -4.8 0
                                                                                  scale 0.4 0.4 0.4
                                                                                  children [
                                                                                          DEF        search_go_butTS TouchSensor {}
                                                                                          DEF        searchgobut magnify        {}
                                                                                   ]
  
                                                                          }
                                                                          DEF invoerTransform Transform  # search input field
                                                                          {
                                                                                  translation        -0.35 -4.5 5                         # -0.7 -6.5 5         
                                                                                  children [
                                                                                          Transform {
                                                                                                  translation        0 0 -1
                                                                                                  children [
                                                                                                          DEF newSearchTS TouchSensor        {}
                                                                                                          Shape {
                                                                                                                  appearance Appearance {
                                                                                                                          material DEF invoerBox Material {
                                                                                                                                  ambientIntensity 0
                                                                                                                                  shininess 0
                                                                                                                          }
                                                                                                                  }
                                                                                                                  geometry Box {
                                                                                                                          size 7 1.1 0
                                                                                                                  }
                                                                                                          }
                                                                                                  ]
                                                                                          }
                                                                                          Transform {
                                                                                                  translation        -2.7 -0.1 0
                                                                                                  scale 20 20 20 
                                                                                                  children [
                                                                                      Shape
                                                                                  {
                                                                                          appearance Appearance
                                                                                          {
                                                                                                  material DEF zoektekst Material
                                                                                                  {
                                                                                                          ambientIntensity 0
                                                                                                          shininess .08
                                                                                                          diffuseColor 0 0 0
                                                                                                          specularColor .29 .3 .29
                                                                                                  }
                                                                                          }
                                                                                          geometry DEF invoerText Text
                                                                                          {
                                                                                                  maxExtent 0.55
                                                                                                  fontStyle FontStyle
                                                                                                  {
                                                                                                          justify        "LEFT"
                                                                                                          size 0.05
                                                                                                  }
                                                                                          }
                  
                                                                                  }
                  
                                                                          ]
  
                                                                  }
                                                          ]
                                                  }
  
                                                  Transform {          # output field
                                                          translation        0.8 -9 5
                                                          scale 8 8 1
                                                          children [
                                                                  DEF searchResultsField ScrollPane {
                                                                                  maxCharsOnALine 25
                                                                                  linkClicked        IS clickedID
  
                                                                  }
                                                          ]
                                                  }
  
                                          ]
                                  }
                          ]
                  }
          ]
  }
  
          DEF cursorAnimator TimeSensor
          {
                  loop TRUE
                  enabled        FALSE
                  cycleInterval .2
          }
  
          DEF        keySensor KeySensor        {}
  
  DEF searchOperation Script {
          # als touch sensor: dan switchen
          # add route naar keypress
          
          eventIn        SFBool newSearch
          eventIn        SFBool activateSearchField
          eventIn        SFInt32        keyPress
          eventIn        SFBool search_go_button 
          field SFNode cursorAnimator USE        cursorAnimator
          field SFNode keySensor USE keySensor
          field SFNode invoerText USE        invoerText
          field SFString nieuweNaam ""
          field SFBool cursor FALSE
          eventOut SFString searchString 
          eventIn        SFBool closeSearchField
          eventOut SFBool        ready IS ready
          field MFString TEST ""
          eventIn        SFTime cursorAnimatie
  
          eventOut SFInt32 whatSearchStatus
          
          url        "javascript:
  
          function initialize() {
                  ready = true;
                  whatSearchStatus = -1;//do not show search box at the start
          }
  
          function activateSearchField(value) {
                  if (value) {
                          whatSearchStatus = 0; // show search box
                          newSearch(true); // activates listening for keyboard input for search
                  }
          }
  
          function closeSearchField(value) {
                  if (value) {
                          whatSearchStatus = -1;
                  }
          }
  
          function newSearch(value) { //is called when clicked on the input field or when search box is shown
                  if (value) registerNewKeyword();
          }
  
          // starts listening for keyboard input, animates cursor
          function registerNewKeyword()
          {
                  nieuweNaam='';
                  if (!cursorAnimator.enabled) {
                          cursorAnimator.enabled=true;
                          Browser.addRoute(cursorAnimator, 'cycleTime', Browser.getScript(), 'cursorAnimatie');
                          Browser.addRoute(keySensor, 'keyPress', Browser.getScript(), 'keyPress');
                  }
          }
  
          // makes cursor blink
          function cursorAnimatie()
          {
                  cursor=!cursor;
                  invoerText.string=new MFString(nieuweNaam+(cursor?'_':'  '));
          }
  
          // called after go button is pressed: stops listening to input and sends query to search script
          function search_go_button(value){         //
                          
                  if(value && nieuweNaam.length!=0){
                     searchString = nieuweNaam;
                     eindeRegistratie();
                     return;
  
                  }
  
          }
  
          function keyPress(key,nu)
          {
          //        if(nu==startTijd) return;
                  if(key==13 && nieuweNaam.length!=0)           // newline <enter>
                  {
                          searchString = nieuweNaam;
                          eindeRegistratie();
                          return;
                  }
                  else if(key==27)
                  {
                          //herstelTop10();
                          eindeRegistratie();
                          return;
                  }
                  else if(key==8)
                  {
                          nieuweNaam=nieuweNaam.substring(0,nieuweNaam.length-1);
  
                  }
                  else if(key>64 && key<91 && nieuweNaam.length<20)
                  {
                          if(!keySensor.shiftKey_changed) key+=32;
                          nieuweNaam+=new SFString.fromCharCode(key);
                  }
                  else if(((key>47 && key<58) || key==32) && nieuweNaam.length<20)
                  {
                          nieuweNaam+=new SFString.fromCharCode(key);
                  }
                  invoerText.string=new MFString(nieuweNaam+(cursor?'_':' '));
          }
  
          function gaZoeken(naam) {
                  //print('ik ga ' + naam + ' Zoeken');
          }
  
          function eindeRegistratie()
          {
                  cursorAnimator.enabled=false;
                  Browser.deleteRoute(cursorAnimator, 'cycleTime', Browser.getScript(), 'cursorAnimatie');
                  Browser.deleteRoute(keySensor, 'keyPress', Browser.getScript(), 'keyPress');
                          
  //                invoerText.string=new MFString('');
          }
  
          
  
          "
  }
  ]
  }        
          ROUTE searchOperation.whatSearchStatus TO searchSwitch.whichChoice
          ROUTE newSearchTS.isActive        TO searchOperation.newSearch
          ROUTE activateSearchFieldTS.isActive TO        searchOperation.activateSearchField
          ROUTE butclosebb.isActive TO searchOperation.closeSearchField
          ROUTE search_go_butTS.isActive TO searchOperation.search_go_button
  
          DEF        searchScript Script        {
  
                  eventIn        MFNode nodes IS setNodes
                  eventIn        SFString searchString
  #                eventIn        SFString linkClicked
                  eventOut SFString searchResultsOut
  
                  url        "javascript:
                  // checks every node if shortName contains the search string, and puts results in text link format.
                  // the C cedille in the short names of the info items are replaced by c's to make matches between c-accent and c's  possible
                  function searchString(value) {
                          var searchResults = '';
                          for (i = 0; i < nodes.length; i ++) {
                                  if (isInString(value,replaceC_Cedille(nodes[i].infoObject.shortName))) {
                                          searchResults += ' [[' + nodes[i].ID + ' ' + nodes[i].infoObject.shortName + ']]\n\n'; 
                                  }
                          }
                          if(searchResults == '')         {
                                  searchResultsOut = 'No results found for: '+ searchString;}
                          //print('zoek resultaten' + searchResults);
                    else{
                          searchResultsOut = searchResults;
                  }
                  }
  
                  // checks if item is contained in string
                  function isInString(item,string) {
                          var pos = string.toLowerCase().indexOf(item.toLowerCase());
                          if (pos >=0) return true;
                          else return false;
                  }
  
                  // replaces every c cedille in string with a c
                  function replaceC_Cedille (string) {
                          var output = '';
                          for (i = 0; i < string.length; i ++) {
                                  if (string.charAt(i) == '') {
                                          output += 'c';
                                  } else {
                                          output += string.charAt(i);
                                  }
                          }
                          return output;
                  }
  
                  "
          }
          ROUTE searchOperation.searchString TO searchScript.searchString
          ROUTE searchScript.searchResultsOut        TO searchResultsField.setText
  #        ROUTE searchResultsField.linkClicked TO        searchScript.linkClicked
  
          DEF        timer TimeSensor {
                  loop TRUE
                  enabled        TRUE
  
          }
  
          DEF        modelScript Script {
                  eventIn        SFBool rollOver
                  eventIn        SFBool rollOverGoButton
                  eventIn SFTime time
                  eventIn        SFFloat        setTransparency IS endTransparency
                  field SFFloat beginTransparency 0
                  eventOut SFFloat transparency
                  field SFTime beginTimeTransparency 0
                  field SFBool transparencyEffectEnabled FALSE
                  field SFFloat totalTimeTransparency 2
                  eventOut SFInt32 whichchoice
              eventOut MFString rollOverText
                  eventOut MFString rollOverTextGoButton
          
                  url        "javascript:
                  function initialize() {
                          transparency = beginTransparency;
                  }
  
                  // transparency effect, see buttonbar.wrl for explanation
                  function time(value) {
                          if (transparencyEffectEnabled) {
                                  var factor = (value - beginTimeTransparency) / totalTimeTransparency;
                                  if (factor < 1) {
                                          transparency = factor * (setTransparency - beginTransparency) + beginTransparency;
                                  } else {
                                          transparency = setTransparency;
                                          transparencyEffectEnabled = false;
                                          if (setTransparency == 1) whichchoice = -1;
  
                                  }
                          }
                  }
  
                  function setTransparency (value,time) {
                          //print('transparantie is: ');
                          whichchoice = 0;
                          beginTimeTransparency = time;
                          beginTransparency = transparency;
                          transparencyEffectEnabled = true;
                  }
                  
                  function rollOver(value){
                          if (value){
                          //print ('rollOver search is true');        
                           rollOverText = 'search';
                                   
                          }
                          else{
                           rollOverText = '';
                  
                          }
                     
                  }
  
                  function rollOverGoButton(value){
                          if (value){
                          //print ('rollOver search is true');        
                           rollOverTextGoButton = 'search';
                                   
                          }
                          else{
                           rollOverTextGoButton  = '';
                  
                          }
  
                   }
  
                  
  
                  "
  
          }
  
          DEF rollOverSearchText Transform { # rollover text for the search button
                  translation        -1.5 14 0
                  children [
                          Shape {
                                  geometry DEF rolloverSearchText Text {  
                                   string        ""
                                  }
                          }
                  
                  ]        
          }
  
          DEF rollOverSearchGoText Transform { # rollover text for the search_go button
                  translation        3 -5 0
                  children [
                          Shape {
                                  geometry DEF rolloverSearchGoText Text {  
                                   string        ""
                                   fontStyle FontStyle {
                                    
                                   }
                                  }
                          }
                  
                  ]        
          }
  
          ROUTE activateSearchFieldTS.isOver TO modelScript.rollOver
          ROUTE search_go_butTS.isOver TO        modelScript.rollOverGoButton
          ROUTE modelScript.rollOverTextGoButton TO rolloverSearchGoText.string
          ROUTE modelScript.rollOverText TO rolloverSearchText.string
  
          ROUTE timer.time TO        modelScript.time
          ROUTE modelScript.transparency TO closebutton.transparency
          ROUTE modelScript.transparency TO invoerBox.transparency
          ROUTE modelScript.transparency TO zoektekst.transparency
          ROUTE modelScript.transparency TO searchbutton.transparency
          ROUTE modelScript.whichchoice TO onOffSW.whichChoice
  
          
  
  }
  
  SearchBox {}
  
  


(C) A. Eliëns 21/5/2007

You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.