Steven Houben Student Human-Computer Interaction

28Apr/100

C# Event

Introduction

Most people can use the standard events that are build-in most objects in the .Net framework. Visual Studio and MonoDevelop provide  both a very simple interface to create, edit, delete or change events. These interfaces hide the logic behind the event  for the programmer. This is fine for most situations but when confronted with custom events, the problems start. In this blogpost I am demonstrating and explaining how you can create a custom event.

Event?

An event is a notification message that is send from one object to another object. It is used to notify an other object about the changed state of the object. Lets use an example to explain the context of events. Image we have a class called Main, that holds the application logic. In this  Main class we want to use a parser, a xml analyzer for example. We declare a new instance of the object Parser by using a piece of code that could look like this:

Parser parser = new Parser();

We can now access the parser class from the main class by using its methods and properties. We could for example call the method parse and set the property TimeOutTime:

parser.parse(data);
parser.TimeOutTime = 2;

In figure 1 you can see a conceptual representation of this process. The down arrow demonstrates this instantiation and use of methods and properties. If we would send some raw data to the parser in order to change something in our main class, it would be nice that the parser can send back the result of the parse method. One way could be to add a return type to the parse method. This can be efficient in some situations but when timing, or threading are an issue this may not work well. We could perhaps let the Parser class create an instance of the main class, so we can use the methods and properties of the main class to update it. The latter wont work because the new instance is not the same as the existing instance that created the parser class in the first place. Although both instances are of the same object, they are not the same. Another issue that may be of concern is the fact that the parse class doesn't really need to know anything about the main class. It simply wants to process data and output the result. With the usage of an event the parse class can simply send a Parsed message when the parsing is done. In figure 1 you can see this process. The Parser class simply sends a Parsed event when it is done parsing. This  instantiation of Class B by Class A and the usage of an event to notify class A should make clear that Class A uses Class B but Class B has in fact no knowledge about Class A, it is simply used by Class A. This is called Loose Coupling [1].

Fig 1: Conceptual event model

Event in C# (.Net)

To create a custom event in .net we need three components: a delegate [2], an event arguments class and the event. We will use the example of the Main class and the Parse class to demonstrate how to implement an event in c#. You can find the complete class files at the bottom of the page.

It is not necessary to have a deep understanding of a delegate. Simply remember that a delegate is basically a type-safe pointer that points to a specific memory address. A delegate is used as a point where you can hook your event on ( a callback function). An event is actually an instance of a delegate. The delegate is a static point that links your event message from one class to an other class.

So, first of all we need to create a delegate outside (!) all classes. You typically do this at the top of your code file inside the namespace but outside(!!) the class. In our example we are creating an event for the Parser class so we will put the delegate in this file but outside(!!!) the class.

public delegate void ParserHandler(Object obj, ParserEventArgs e);

We named our delegate ParserHandler, as it is going to handle parser events. The arguments for our delegate are an object and a ParserEventArgs class. We will use the object so we can check what instance has send the event. The ParserEventArgs doesn't exist so we need to make it.

Any event arguments class holds information about the state of the object. This class is the actual message or notification we are sending to another class. In this case we want to send a result back to another class. There are two ways we can do this:

  1. First of all we could create an empty EventArgs  class. When an event is send the Main class will receive an empty event message. This may seem not seem very useful but we could use this event as a trigger to retrieve information. The parse could have a property Result. When we receive this empty message we know that the Result property is updated with the new result and we can retrieve it by using the property.
  2. Secondly we can put the result into the EventArgs and send it over. When the main class receives the message we can find the result inside the message

Iin this example we are using the second method. We need to create a new class ParserEventArgs that hold a Object field and a Result field:

  public class ParserEventArgs
    {
        public string Result { get; set; }
        public Object Object { get; set; }
        public ParserEventArgs() { }
        public ParserEventArgs(Object obj, string result)
        {
            this.Result = result;
            this.Object = obj;
        }
    }

Now that we've got our delegate and our ParseEventArgs class, it is time to implement our event. First of all we need to create our event:

 public event ParserHandler parserEventHandler = null;

Place this event inside the Parser class. Next we are going to wrap this event for simplicity and to make sure the event is never null.

 protected void OnParseEvent(ParserEventArgs e)
        {
            if (parserEventHandler != null)
            {
                parserEventHandler(this, e);
            }
        }

If we now want to send the event, in this case when the parsing is done, we simply need to call the OnParseEvent method:

 public void Parse(Object rawdata)
        {
            //parse code here
            string result = "ParsedData";

            OnParseEvent(new ParserEventArgs(this, result));
        }

The Parser class is now modified to send an event when the parse function is done. We can now use this in our main class:

>class Main
    {
        Parser parser = new Parser();
        public Main()
        {
            parser.parserEventHandler += new ParserHandler(parser_Parsed);
            parser.Parse("RAWDATA");
        }
        private void parser_Parsed(object sender, ParserEventArgs e)
        {
            string result = e.Result;
        }
    }

This may seem familiar as this code is basically what the IDE generate when you use a standard event. In the main class we create a parser object. In the constructor we hook an event listener to this and call the parse method. When the raw data is parsed the parsed object sends a Parsed event that we are catching with our handler.

The complete Parser class:

namespace Parser
    {
        public delegate void ParserHandler(Object obj, ParserEventArgs e);
        public class Parser
        {
            public event ParserHandler parserEventHandler = null;

            public void Parse(Object rawdata)
            {
                //parse code here
                string result = "ParsedData";

                OnParseEvent(new ParserEventArgs(this, result));
            }
            protected void OnParseEvent(ParserEventArgs e)
            {
                if (parserEventHandler != null)
                {
                    parserEventHandler(this, e);
                }
            }
        }
        public class ParserEventArgs
        {
            public string Result { get; set; }
            public Object Object { get; set; }
            public ParserEventArgs() { }
            public ParserEventArgs(Object obj, string result)
            {
                this.Result = result;
                this.Object = obj;
            }
        }
    }

References

[1] Loose Coupling, http://en.wikipedia.org/wiki/Loose_coupling

[2] Delegate, http://en.wikipedia.org/wiki/Delegate_(.NET)

24Feb/100

A c# mobile paint module

Introduction

This small module was part of a project for the course Tools and Technologies of User Interfaces at Uhasselt. We built a Todo application that exploited the properties of mobile devices (gps, touch, accelerometer, ...).

Mobile Paint

For this project I was looking for a small paint application that could be used to create notes that could be attached to a specific todo. Since no open source mobile paint application seemed to do the job I wrote a small c# .Net paint module that can be added to any mobile application via drag and drop from the toolbox. It only supports basic free drawing with 6 colors and a variable brush size. Drawing shapes, lines, ... are not implemented but can be easily added if necessary.[1] You can also set a bitmap (like a map, frame,...) as canvas.

Licence

Copyright (c) Steven Houben

This code is free software; you can redistribute it and/or modify it  under the terms of the GNU Lesser General Public License 3 or later, as published by the Free Software Foundation. Check  [2] for details.

Downloads

  1. Compiled DLL [download] (1 file - DLL)
  2. Source Code [download] (1 file: class files)
  3. Test + Source Visual Studio Project [download] (2 projects + builds)

Support

I am not actively developing or supporting this control. However if you add functionality or find any bugs you may contact me via this blog (comment or email) and I will update the code.

References

[1] .net Shape manipulation demonstration, http://blog.anxma.com/?s=shape

[2] http://www.gnu.org/copyleft/lesser.html

Tagged as: , , , No Comments
21Jan/102

Pilers, filers and tossers vs desktop

Piler vs Filer

I consider myself a ? on the desktop?

View Results

Loading ... Loading ...

Introduction

There are basically two kinds of people: filers and pilers. The first tend to categorize, alphabetize, order and file all their documents while the latter tend to stack their documents in piles or groups of related documents. Both organizational styles seem to criticize each other but apparently there is a direct correlation between personality and organizational style.  This means that a persons actions is dictated by their personality type. Anxious people for example tend to be filers as everything in their world (and workspace) needs to be organized as they need to feel that they are in control of the situation. Pilers on the other hand seem to be "the big picture" kind of people who rarely get lost in details.  They use a self-defined dependable system in their piling method which allows them to use their spatial memory to remember what document or memo can be found in what pile. But there is a third kind of organizing style which is sometimes confused with piling: tossing. A tosser seems to deal with details by not dealing with them at all. He seems to have a clear lack of organization.

According to the Pendaflex research 48% of the population are pilers, 38% are filers and 14% are tossers. [1]

Desktop Metaphor

For my master thesis [2] I am planning on building a context-aware activity manager as an effort to re-frame the existing desktop metaphor [3]. The desktop metaphor was initially introduced to exploit the user's knowledge about the interaction with a classical desktop to decrease the complexity in human - computer interaction. In other words: the desktop workspace as you know it is based on your desk.

The problem with this metaphor is the fact that some tasks performed by users are exceeding the possibilities of the metaphor thereby constraining the user while performing the task. In other words: the desktop metaphor is holding back users in certain situations. In my master thesis I want to check how activity theory could help in re-framing the desktop metaphor.

File management

Modern operating systems let users organize their documents and files in a hierarchical file system. The desktop is used as the workspace and (cognitive) entry point of this hierarchy. Unfortunately this system forces users in becoming (partially) filers. Research has shown that there are three ways people use the desktop workspace:

  1. Those who use the desktop for information piling and only file important information in the hierarchy (Piler). These people have different folders on their workspace that contain lots of documents related to specific topics. (fe. Work, Backup, Todo, Games,...) These people tend to have a lot of shortcuts on their desktop as well. Pilers also use the file hierarchy but only do this( once a month) for really important information or when they feel that their 'piles' are getting cluttered.
  2. Those who keep their desktop clean and file all their documents in the hierarchy (Filer). These people use the desktop for documents and files they are currently using but at the end of the day or when the job is finished they immediately save their documents in the correct folder.
  3. Those who clutter their desktop and file nothing (Tosser). Tossers simply drop everything on their desktop. They only seem to clean their desktop when nothing can be added to the desktop. Cleaning their desktop usually means copying all the files on the desktop and pasting this in a 'backup' folder.

Although many use the hierarchy to organized documents etc, multimedia files like audio and video are mostly saved in the same folder. An external application (fe. a media player) is then used to organize, search and manage the files.[3]

Since files are an essential part of activity-based computing I am considering to add some piling possibilities to the application. But before I even consider doing this I wanted to see if the numbers provided by the Pendaflex research are in fact correct.

I would like to ask you to send a link to this blogs to your colleagues and friends.  All they have to do is fill in the poll at the start of this blog.

Thanks

References

[1] The Psychology of Stacking,  http://www.pendaflex.com/enUS/PressRelease/The_Psychology_of_Stacking.html

[2] Steven Houben, Master Thesis, http://blog.anxma.com/master/

[3] Victor Kaptelinin, Beyond the Desktop Metaphor, http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=11154

17Jan/100

Google vs China: Fundamental problems

What

Most of you have probably already heard about the cyber-attacks on Google and other international IT companies performed by the Chinese government. The latter attempted to access for example the Google mail account of Chinese human rights activists.[1]  MacAfee labs  stated in their official blog that the hack was done using a new vulnerability in Internet Explorer [4]:

In our investigation we discovered that one of the malware samples involved in this broad attack exploits a new, not publicly known vulnerability in Microsoft Internet Explorer.

George Kurtz - MacAfee Labs

Google responded to the attack by stating it is now considering a new approach to the China situation [2]. In the past Google received much criticism for censoring the Google search result in China. This self-censorship is done to comply with the Chinese law that forbids information sharing about certain subjects (including parts of Chinese History).

Problems

A lot has been said, even on this blog [5][6],  about the amount of information  that Google is storing about its users.  Although Google is the company that is actually storing the information, Google has no purpose or interest in abusing or reselling this information. The more dangerous players in the privacy game are governments or other organisations that may want to advise the Google database to extract information about certain people. Governments could do this via court or other legal ways.  But the fact that a government would try to cyber-attack a company as Google in order to gather information about people of interest to that government wasn't even part of this much debated privacy equation. This situation is actually exposing a very large problem: many security systems, encryption techniques, database security,... are "100%" safe against hackers or bot nets. But when the government of the largest country in the world, with an IT-agency with an alleged size of more then 40000 employees, is actively working on ways to hack security systems, these security systems may not be 100% safe. If Google in fact didn't "hack back" the source that cyber-attacked them, we probably didn't even know that the Chinese government was doing this. How can software developers protect their applications and information against this kind of enemy?

Since the attack was done via a vulnerability in Internet Explorer, this raises questions about security and bugs in many systems. Until know bugs and minor security flaws in software weren't that big of a problem to most of its users as many considered it part of the system. Scientific research [7] has even shown  that many people aren't that bothered with software bugs when they appear in non-critical systems. But what if these minor bugs are exploited to extract much more sensitive information?  This isn't really a new problem as it has happened before but it does put the problem back on the foreground. Can and does software have be 100% bug free?

References

[1] Google, Citing Attack, Threatens to Exit China, NY Times,http://www.nytimes.com/2010/01/13/world/asia/13beijing.html

[2] A new approach to China, Official Google blog, http://googleblog.blogspot.com/2010/01/new-approach-to-china.html

[3] Google censors itself for China, BBC, http://news.bbc.co.uk/2/hi/technology/4645596.stm

[4] MacAfee Blog, http://news.cnet.com/8301-27080_3-10435232-245.html

[5] [DUTCH] Google: Vloek of zege, Steven Houben,  http://anxma.com/blog/index.php/2009/10/23/google-vloek-of-zege-dutch/

[6] Google, Steven Houben, http://anxma.com/blog/index.php/2009/05/29/google/

[7] Acceptable defect rate, http://www.sei.cmu.edu/library/assets/dietz.pdf

8Jan/100

Juan Enriquez: As The future catches you

Juan Enriquez [1] discusses his latest book, As the Future Catches You: How Genomics and Other Forces Are Changing Your Life, Work, Health, and Wealth[2]. This power point style book , excerpt @ [3], describes the correlation between technology, wealth, education, evolution and governments. A must read masterpiece.

References

[1] http://www.biotechonomy.com/juan.htm

[2] http://www.amazon.com/As-Future-Catches-You-Genomics/dp/0609609033

[3] http://hbswk.hbs.edu/archive/2616.html

19Dec/090

The Design of Future Things

Professor Emeritus Donald Norman [1-2] discusses his latest book: The Design of Future Things [3].

References

[1] Donald Norman's jnd website, http://www.jnd.org/

[2] Donald Norman http://en.wikipedia.org/wiki/Donald_Norman

[3] The Design of Future Things, 2007,  http://www.amazon.com/Design-Future-Things-Author-Everyday/dp/0465002277

29Nov/094

How to write a scientific paper?

My girlfriend Evi (who's a PhD-student NeuroScience at Maastricht University) wrote a nice short summary about how to write a scientific paper. The summary is based on a keynote by Dr. Stuart Spencer, editor of “the Lancet”, the world's leading general medical journal and specialty journals in Oncology, Neurology and Infectious Diseases.
Although the keynote was specific about writing medical papers the summary is still very helpful for anyone who needs to write a scientific paper regardless what science or domain.

[Download] [Html]


WRITING SCIENTIFIC PAPERS

Evi Vlassaks

November 29, 2009

This summary is based on the keynote of Dr. Stuart Spencer, editor of  "the Lancet".

1 The article

  • Where are journals interested in?
    • Is the research question (RQ) important?;
    • short, clear, precise title; begin with a keyword, no abbreviations, answer the question;
    • clinically usefull;
    • brevity: make it as short as possible ;
    • keep it simple.

2 General tips

  • Write the first draft as though you were explaining it for a layperson
  • Write it in active form
  • Write as you would speak
  • Use short sentences
    • Max 20-30 words;
    • use variable length sentences.
  • Use signposts:
    • for example: First, second, third,…; on the other hand; by contrast; therefore; in summary
  • Paragraphs: different topics in different paragraphs
  • Attention for details

3 Article structure

  • Abstract: 250 words focus on the interpretation of the results.
  • Introduction: One page summary of:
    • What we know;
    • what we don't know;
    • why we did this RQ.
  • Methods: Explain the methods in great detail (what, why and when)
  • Results: Two to three page text
    • Don't duplicate text, figures or tables;
    • discuss positive results first.
  • Discussion: reflection of the introduction
    • Two to four pages;
    • start with the results;
    • discuss strengths;
    • discuss weaknesses and possible causes or solutions;
    • compare the results with literature;
    • discuss future directions;
    • end with a positive note;
    • don't end with : `Future studies are needed…'.
  • References : 20 - 35 references per article
    • Only one or two references per point;
    • add reviews to your references;
  • Figure and table list
    • The figures and tables should be clear and self explanatory;
    • describe them in a meaningful title.
  • Covering letter
    • Use the editor's name;
    • make it a personal letter.
  • Post review :
    • be humble!!!!
27Nov/090

10/GUI

What

10/GUI [1] is a (summer) project started by R. Clayton Miller. In this video he examines the benefits and limitations inherent in current mouse-based and window-oriented interfaces, the problems facing other potential solutions, and visualizes his proposal for a completely new way of interacting with desktop computers. His proposal isn't based on scientific data or relevant research but is the vision of the author himself, who is a graphical designer.

It is however nice to see that even beyond the Computer Science /  Human-Computer Interaction community people are realizing that the current implementation of the desktop interaction is to limited for many modern tasks or activities .

The Video

References

[1] http://10gui.com/

24Nov/090

A C# (.net) Extended Panel

What?

I was cleaning up my external HD and came across a project I did a few years ago. The idea behind the project was:

  1. Extend the standard System.Windows.Panel[1] with transparency and an alpha channel
  2. Master the use of  smart tags in Visual Studio (design time support for programmers)

shPanel

The shPanel control is an extension of the standard System.Windows.Panel [1] control. I basically derived the standard panel, added basic gradient support and build in an alpha channel for the gradient colors. The user can switch between UserDrawMode and SystemDrawMode. The latter uses the standard .net draw call and doesn't care about the added properties. The UserDrawMode on the other hand uses 2 colors and a gradient mode as input for a custom draw call. I have also added 2 schemes that basically set the GradientColor1 and GradientColor2 properties. I remember thinking about implementing a XML system for gradient definition but I guess I never came to that.

Next to the added functionality I also provided the control with smart tags so the User Interface designer can quickly access and change the most relevant properties of that control. In this case I assumed that the UserDrawMode was the the most relevant property as it decides how the control is rendered. Secondly It also made sense to me to add smart tags for all added functionality.

And yes sh is an abbreviation for my name :) .

Licence

Copyright (c) Steven Houben

This code is free software; you can redistribute it and/or modify it  under the terms of the GNU Lesser General Public License 3 or later, as published by the Free Software Foundation. Check  [2] for details.

Download

  1. Compiled DLL [Download] (1 file - DLL)
  2. Source Code [Download] (4 files: class files)
  3. Test + Source Visual Studio Project [Download] (32 files: 2 projects - no builds)

Support & contribution

I am not actively developing or supporting this control. However if you add functionality or find any bugs you may contact me via this blog (comment or email) and I will update the code.

Thanks to Phil Wright for tips on the use of smart tags. [3]

Reference

[1] http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx

[2] http://www.gnu.org/copyleft/lesser.html

[3] http://www.componentfactory.com/blog/2005/10/adding-smart-tags/

23Nov/090

Orbis on softpedia.com

Today I received en email from an editor of Softpedia stating that they have downloaded the Orbis Testbuild and tested it in their lab. Check it out at http://www.softpedia.com/get/Programming/File-Editors/Orbis.shtml

"Orbis" has been tested in the Softpedia labs using several
industry-leading security solutions and found to be completely clean of
adware/spyware components. We are impressed with the quality of your
product and encourage you to keep these high standards in the future.

To assure our visitors that Orbis is clean, we have granted it with the
"100% FREE" Softpedia award. To let your users know about this
certification, you may display this award on your website, on software
boxes or inside your product.