Click sensitivity in Swing

November 2nd, 2012 in Java | , , ,

In our latest application we found that users complain about the sensitivity on minor mouse vibrations during clicking on components. I also found that using a pen tablet it is almost impossible to keep it steady enough for a click to be registered.

Instead a small change in mouse X, Y will cause a mouseDragged notification instead of a mouseClicked.

The solution is to add a function that will check for a tolerance and, if within, cause a click to be executed instead.

In the MouseListener class we add this:

 Java |  copy code |? 
class ToleranceMouseListener implements MouseMotionListener, MouseListener {
	// Our tolerance in both x and y direction
	private static int CLICK_TOLERANCE = 5;
 
	// The point where we pressed the mouse button down
	private Point startPoint;
 
	// Method for checking the tolerance 
	private boolean checkDragTolerance(Point e) {
		if (startPoint != null) {
			float changesx = Math.abs(e.x - startPoint.x);
			float changesy = Math.abs(e.y - startPoint.y);
 
			return (changesx < CLICK_TOLERANCE && changesy < CLICK_TOLERANCE);
		}
		return false;
	}
 
	// Store where we pressed the mouse button down
	@Override
	public void mousePressed(MouseEvent e) {
		startPoint = e.getPoint();
	}
 
	// The magic happens as we release the mouse button
	@Override
	public void mouseReleased(MouseEvent e) {
		/** Creates a small buffer for what is considered a mouse press vs mouse drag */
		if (checkDragTolerance(e.getPoint())) {
			System.out.println("Redirect click");
			mouseClicked(e);
			return;
		}
 
		// Code for mouse dragged here, if any
	} 
 
	// Plus empty methods
	...
}

I am a TED translator

October 18th, 2010 in Blog | ,

A while back I was watching a TED video. Randomly I decided to look at what languages were available for subtitles. This is not one of the most watched videos on TED, and of course, my own native language, Norwegian, was not represented. I dug a bit further and found the list of videos that have been translated to Norwegian. Out of 700+ videos only a handful were available in Norwegian.

“OK”, I thought, “I will translate this one.” So I applied to translate the video. By the way it was Brian Cox: Why we need the explorers, go watch it, though no-one has reviewed my translation yet so it’s not available. I wasn’t expecting the questions and commitment they have to make sure the volunteer translators are up to par. One of their questions was: “Why do you want to translate for TED?”

Why do I want to translate?

I often advocate that English is a required skill, especially in Norway where it is our primary second language. However, as a – can I say? – former dyslectic I understand the difficulties of consuming any kind of information, and even more so information not in ones primary language. I believe the content in TED talks to be of high importance. I believe that the utmost concern for the consumer of a TED talk to gain a good grasp of what the speaker wishes to convey.

Reading is an excellent way of consuming information. The transcript is available while watching the talk,  and optionally on the sidebar where it can be read in ones own time. A native translation will enable most readers of the language to view and understand the content. The content will instantly be available to most with the basic reading abilities of a young student.

What’s in it for me?
As mentioned earlier, I am a sufferer of dyslexia (they just had to make it a hard word to spell, didn’t they?) I have spent a good many years trying to overcome its difficulties. When tired, b, d, and p will still trip me up. Is “ball” spelled with one or two ‘l’s? Every time I write a word it is reinforced in my brain. They say practice makes perfect. I am still fighting to overcome it, and to maintain my hold on it. (Though, still I do struggle reading out loud, so please, never ask me to do that.)

I also have a fifteen year old step-daughter. While she is a native English speaker, I want the information available to her and to her classmates, my family, my colleagues, and everyone else who natively speaks Norwegian. I believe in a lot of the information TED stands for, I believe a lot of it is important (and the rest? Informational, funny, or interesting.)

A query for you
Earlier today I asked a question on a semi-popular Norwegian blog, and I will follow it up here. If you had a choice, what would you like me to translate? Are certain things more important to you? Should I translate the latest talk? The most popular talk? I would love to hear from all and everyone. If there are very specific talks you want translated, the feel free to request that as well. I can also be contacted through email, my first name @ this domain.

(Though, I do see the irony, as this is written in English… )

Up ahead, my goal is to translate – at least – one new TED talk per week, time and timing allowing. This weeks talk was Jessa Gamble: Our natural sleep cycle, chosen because I have experience the sleeping patterns she describes.

Next weeks talk will be Brian Cox on CERN’s supercollider, because I like super colliders, and because Brian Cox rocks ;)

And one last request, translate a TED talk today, so that more people can enjoy this content. Be a hero!

If you do not feel up to the task of translating a complete talk, join up to review a finished translation, as they are often delayed due to too few reviewers.

I am a TED translator, and damn proud to be so too.

Book review: The City and the city, by China Miéville

October 17th, 2010 in Book reviews | , ,

I recently received my latest Amazon.co.uk order, which contained Nation by Terry Pratchett, Earth Ascendant and The Grand Conjunction by Sean Williams, Saturn’s Children by Charles Stross, and The City & The City by China Miéville.

The books main plot is the solving of a murder, but in the vein of Mievilles usual writing the setting is pretty unorthodox. Besźel and Ul Qoma are two cities with a different past. At some point in time these two cities merged, not by growing into each other, but by being merged into the same physical space. Whilst one side of the road might be Besźel the other side might be in Ul Qoma. Some corners of the city space is so crosshatched and overlapped that each step might bring you into the other city. The job of solving the murder is by no means made easier due to the crime being connected to both cities, which would either be in breach (unauthorized movement between the cities, or have gone through the single and well-guarded checkpoint between the cities.)

Because these two cities spaces are intertwined the mysterious entity called Breach are overseeing the borders. One is not allowed to cross into the other city, nor interact or see anything, people having to “unsee” anything that belongs to the other city. Only at one place can one legally travel between the two cities.

Miéville gave Borders an interview on the book, which can be watched online. I also recommend visiting his blog rejectamentalist manifesto. The book has garnered very good reviews, and has won the BSFA Award for Best Novel of 2009, and the Arthur C. Clarke Award in 2010. It is also a nominee for Best Novel in the 2010 Hugo Award.

I give it a 4/5. Enjoyable story, excellent writing, but could have explained better.

About the author
China Miéville, born 1972 in England, has 7 books behind him, and another book (Kraken) coming this year. Following in the tradition 1920s-1930s fantasy writers he’s a self-professed weird fiction writer. Many of his books are set in alternate universes with steam-punk influences and non-human characters and monsters. He has several nominations and have won the Arthur C. Clarke Award twice with The Scar and Iron Council. He also writes fiction for young adults.

Books: King Rat, Perdido Street Station, The Scar, Iron Council, Un Lun Dun, and The City & The City, and also a number of short-stories.

Welcome!

June 5th, 2010 in Blog

Hi there! If you’re seeing this you’ve probably come across my website in its infancy. I’m still in the progress of ironing out the kinks and moving in. Feel free to leave me feedback in the comment form underneath, or explore the few bits I’ve have up, for now, that would be the about page.