<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: whiteboardqueue code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 11:45:57 GMT</pubDate>
    <description>DZone Snippets: whiteboardqueue code</description>
    <item>
      <title>Undo the last shape stored in the whiteboard message buffer</title>
      <link>http://snippets.dzone.com/posts/show/5335</link>
      <description>This ECMAScript implements an undo feature for the SVG whiteboard. When the user presses CTRL+Z the last shape in the message_buffer variable is removed.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  function undoLast() {&lt;br /&gt;    ipos = getLastMethodPos(message_buffer,-1)&lt;br /&gt;    if (ipos &gt; 0)&lt;br /&gt;      message_buffer = message_buffer.substring(0, ipos)&lt;br /&gt;    else&lt;br /&gt;      message_buffer = ''    &lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  function getLastMethodPos(message, pos) {&lt;br /&gt;    i = message.indexOf('&lt;method', pos+1)&lt;br /&gt;    if (i &gt;= 0) &lt;br /&gt;      result = getLastMethodPos(message, i)&lt;br /&gt;    else&lt;br /&gt;      result = pos &lt;br /&gt;    return result;&lt;br /&gt;  }&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Here's an example of the messages (containing shapes) stored in the message_buffer&lt;br /&gt;&lt;code&gt;&lt;br /&gt;"&lt;method name='create'&gt;&lt;params&gt;&lt;param var='type'&gt;shape&lt;/param&gt;&lt;param var='body'&gt;&lt;br /&gt;polyline%20x%3D%27524%27%20y%3D%27198%27%20fill%3D%27none%27%20stroke%3D%27red%27%20id%3D&lt;br /&gt;%27348553%27%20stroke-width%3D%272%27%20points%3D%27524%2C198%20523%2C198%20522%2C198%20521%2C198%20&lt;br /&gt;513%2C198%20511%2C198%20503%2C198%20495%2C200%20493%2C200%20485%2C204%20483%2C205%20475%2C207%20474%&lt;br /&gt;2C208%20470%2C212%20466%2C216%20465%2C217%20464%2C219%20463%2C220%20463%2C222%20463%2C223%20463%2C22&lt;br /&gt;5%20463%2C226%20463%2C228%20464%2C230%20465%2C231%20466%2C233%20467%2C234%20471%2C238%20472%2C238%20&lt;br /&gt;478%2C242%20484%2C246%20485%2C247%20488%2C247%20489%2C248%20491%2C248%20493%2C249%20496%2C249%20497%&lt;br /&gt;2C249%20505%2C249%20515%2C249%20521%2C247%20531%2C245%20533%2C245%20539%2C243%20547%2C243%20548%2C24&lt;br /&gt;3%20550%2C242%20555%2C237%20556%2C237%20557%2C235%20558%2C234%20558%2C233%20559%2C231%20559%2C230%20&lt;br /&gt;560%2C228%20560%2C226%20560%2C222%20559%2C221%20559%2C220%20559%2C219%20559%2C217%20559%2C216%20558%&lt;br /&gt;2C215%20558%2C214%20556%2C208%20555%2C206%20555%2C205%20553%2C199%20549%2C191%20547%2C185%20546%2C18&lt;br /&gt;4%20544%2C176%20540%2C170%20539%2C168%20535%2C162%20534%2C161%20528%2C155%20528%2C154%20524%2C148%20&lt;br /&gt;518%2C144%20517%2C143%20511%2C139%20509%2C138%20501%2C134%20499%2C133%20491%2C129%20489%2C129%20479%&lt;br /&gt;2C129%20469%2C129%20467%2C129%20459%2C129%20457%2C129%20454%2C129%20452%2C129%20446%2C131%20438%2C13&lt;br /&gt;1%20437%2C132%20435%2C132%20435%2C133%20434%2C133%20434%2C134%20433%2C134%20433%2C135%27%23%3A&lt;br /&gt;&lt;/param&gt;&lt;param var='sender'&gt;34855&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;&lt;method name='create'&gt;&lt;params&gt;&lt;param &lt;br /&gt;var='type'&gt;shape&lt;/param&gt;&lt;param var='body'&gt;polyline%20x%3D%27457%27%20y%3D%27175%27%20fill%3D%27none&lt;br /&gt;%27%20stroke%3D%27red%27%20id%3D&lt;br /&gt;%27348554%27%20stroke-width%3D%272%27%20points%3D%27457%2C175%20456%2C175%20455%2C176%20454%2C176%20&lt;br /&gt;453%2C177%20452%2C177%20451%2C177%20449%2C178%20448%2C179%20442%2C181%20440%2C183%20438%2C184%20438%&lt;br /&gt;2C185%20437%2C186%20436%2C187%20435%2C189%20435%2C191%20434%2C193%20434%2C194%20433%2C195%20433%2C19&lt;br /&gt;6%20431%2C200%20431%2C201%20431%2C203%20431%2C205%20431%2C206%20431%2C207%20431%2C208%20431%2C209%20&lt;br /&gt;431%2C210%20431%2C211%20431%2C212%20431%2C213%20431%2C214%20431%2C215%20431%2C216%20431%2C217%20432%&lt;br /&gt;2C223%20432%2C224%20432%2C225%20432%2C226%20433%2C226%20433%2C227%20433%2C228%20433%2C229%20434%2C22&lt;br /&gt;9%20434%2C230%20435%2C231%20435%2C233%20435%2C234%20436%2C235%20437%2C236%20437%2C237%20438%2C237%20&lt;br /&gt;438%2C238%20438%2C239%20438%2C240%20439%2C240%20439%2C241%20443%2C245%20444%2C246%20444%2C247%20445%&lt;br /&gt;2C247%20446%2C248%20447%2C248%20448%2C248%20448%2C249%20449%2C249%20450%2C250%20451%2C251%20452%2C25&lt;br /&gt;2%20454%2C253%20455%2C253%20461%2C255%20462%2C255%20464%2C256%20466%2C256%20467%2C257%20469%2C257%20&lt;br /&gt;469%2C258%20471%2C259%20472%2C259%20474%2C260%20475%2C260%20477%2C261%20478%2C261%20480%2C262%20481%&lt;br /&gt;2C262%20481%2C263%20482%2C263%20483%2C263%20484%2C263%20485%2C263%20486%2C263%20489%2C263%20491%2C26&lt;br /&gt;3%20492%2C263%20495%2C263%20496%2C263%20502%2C261%20504%2C261%20507%2C261%20509%2C261%20510%2C261%20&lt;br /&gt;511%2C261%20512%2C261%20513%2C261%20515%2C261%20517%2C261%20518%2C261%20520%2C260%20523%2C260%20524%&lt;br /&gt;2C260%20526%2C259%20528%2C259%20529%2C259%20534%2C258%20535%2C258%20536%2C257%20537%2C257%20538%2C25&lt;br /&gt;7%20540%2C257%27%23%3A&lt;/param&gt;&lt;param var='sender'&gt;34855&lt;/param&gt;&lt;/params&gt;&lt;/method&gt;"&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In the above example there are 2 methods calls ready to be sent to the server, the 2nd method would be removed after the undoLast() function had executed.&lt;br /&gt;&lt;br /&gt;The methods are ready to be passed to the function getLatestMessages which passes the request through the ProjectX API, which then returns the results. &lt;br /&gt;&lt;br /&gt;This code only removes the shape before it's sent to the server, I still need to write the code to delete a shape which is in the server whiteboardqueue, and remove the shape element from the web browser display (SVG DOM).</description>
      <pubDate>Mon, 07 Apr 2008 23:42:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5335</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
    <item>
      <title>Deleting a redundant shape message from the whiteboard queue</title>
      <link>http://snippets.dzone.com/posts/show/5325</link>
      <description>This code is used to remove a message from the whiteboard queue containing a shape which has recently moved it's position (x and y coordinates) on the board. Code extract from whiteboardqueue.rb&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;  def call_delete_shape(params)&lt;br /&gt;    #get the shape's message id.&lt;br /&gt;    doc = Document.new(params)&lt;br /&gt;    shape_id = doc.root.elements["param[@var='id']"].text.to_s&lt;br /&gt;    initialize_doc&lt;br /&gt;&lt;br /&gt;    doc_xml = Document.new(decode2(@doc_file.root.to_s))&lt;br /&gt;    id = doc_xml.root.elements["records/message/body/*[@id='#{shape_id}']"].parent.parent.attributes.get_attribute('id')&lt;br /&gt;    delete_record(id)&lt;br /&gt;    save_file&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;*update 10:04pm*&lt;br /&gt;Added the link to the project code http://github.com/jrobertson/whiteboardqueue/tree</description>
      <pubDate>Sat, 05 Apr 2008 19:39:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5325</guid>
      <author>jrobertson (James Robertson)</author>
    </item>
  </channel>
</rss>
