Chorn Sokun's Weblog

Conquer inner fear, push it to the limit!

From Java Swing Dimension JFormattedTextField bite

leave a comment »

Today, I poke around Java Swing to build up a simple data entry. One thing I wanted to do is to create a number input field so as usually I hack through the API document and found this little JFormattedTextField component. By the judge from the API point of view it is pretty easy to use. All we have to do is instantiate the component with preferred format or mask and that is pretty much about it.

numField = newJFormattedTextField(NumberFormat.getIntegerInstance());
container.add(numField);

Now, I wanted to hook an event listener to this field and retrive new value

/* this, container which implements PropertyChangeListener */
numField.addPropertyChangeListener("value", this);

So basically we got this:

numField = new JFormattedTextField(NumberFormat.getIntegerInstance());
numField.addPropertyChangeListener("value", this);
container.add(numField);

Now if you try to call .setValue(new Integer(100)) you will present with an exception java.lang.NullPointerException. After inspecting the PropertyChangeEvent class definition I believe that Java try to compare old value and new value, but we haven’t set any value before we hook up an event listener. Therefore, Java takes it liberties to raise an error in our face and that is fair enough right?

How to fix this? Well, it is simple set initial value before hook an event listener would solve the problem.

numField = new JFormattedTextField(NumberFormat.getIntegerInstance());
numField.setValue(new Integer(0)); // this line is your savier!
numField.addPropertyChangeListener("value", this);
container.add(numField);

Written by Chorn Sokun

May 13, 2014 at 8:06 am

Posted in Programming

Tagged with ,

Joljet mobile client

leave a comment »

A few years ago, I built a music portal to experience ExtJS and of cause to create my own music listening experience. It was fun and I have learnt a lot from this exercise from hand craft the app, built script and caching optimization. As always with great power come great responsibility. Due to the size of ExtJS core, the page load is not satisfy by most. However, the site hosted on cheap server and not using any CDN therefore I can’t push it too far.

Moving on, I have done with ExtJS and I know the site works perfectly on desktop platform. However, on mobile it is kind of suck. But well, as a pet project I’m not too worry about that until I’m need to listen to my favorite song on the go then mobile client is needed. So, I decided to built one for myself AGAIN! :D. Yeah, again. Why not after all I’m a craftman I love builting stuffs.

Now here is the plan

Image

I’m going to built mobile client which reuse all functionality from the portal and at the same time extending the functionalities to support offline, favorite & playlist customization or by the way I don’t want to be responsible for username & password so I am going to offload that task to Facebook.

Sound interesting right ;) to make it more interesting I shall say that I have no clue how to built a mobile app at this point. But, let see how long it will take for me to built one :D

 

Written by Chorn Sokun

May 12, 2014 at 8:07 am

Use jQuery select an option from dropdown

leave a comment »

Self note

<select id="target">
<option selected>--- blank</option>
<option value="21">test1</option>
<option value="12">test2</option>
<option value="30">test3</option>
</select>

Using index:

  $('#target>option:eq(1)').attr('selected', true);
  // test1 will be select

Or select by value:

  $(#target>option[value=30]').attr('selected', true);
  // test3 will be select

 

Written by Chorn Sokun

November 11, 2012 at 12:02 pm

Yii overwrite accessRules in base class

leave a comment »

Suppose you defined a base class Controller with basic accessRules

class Controller extends CController
{
  public function filters()
  {
    return array(
      'accessControl',
      'postOnly + delete',
    );
  }

  public function accessRules() {
    return array(
      // allow authenticated user to perform 'create' and 'update' actions
      array('allow', 'actions'=>; array('index', 'view'), 'users' => '@'),

      // deny all users
      array('deny', 'users'=>'*'),
    );
  }
}

and you want to add (overwrite) rules in derived class, using array_merge here how you do it:

class Site extends Controller
{
  public function accessRules()
  {
    return array_merge(
      // allow all user to perform 'help' actions
      array( array('allow', 'actions'=> array('help'), 'users' => '*') ),

      // parent go last
      parent::accessRules()
    );
  }
}

As best practice your base class default access rule is deny all by default.

Written by Chorn Sokun

October 22, 2012 at 3:34 pm

Code Reading Skills for ExtJS newbie

leave a comment »

@samnangchhun wrote a blog post talking about this particular subject, I just want to share my experience exploring a new tool especially the ExtJS library from sencha.com

Now there is something special about sencha.com which I love, they put alot of effort in documenting their library API as well as sample projects in every release.

But like any other developers out there the only page in the document that I would read slowly is getting start, once I could say hello I would try to solve my problem with this new library/framework. That the only way that keep me focus and dig deeper into the document, source code, sample project, testing unit whatever available. At the end of the day I would know that this is the right tool or not.

How do i get this quick in adapting with new environment? I walk the same path as what @samnangchhun described in his blog and I did it enough that I can quick capture the convention and pattern of the thing I want to know. So if you haven’t read enough code do it now ;)

Great weekend everyone.

Written by Chorn Sokun

May 5, 2012 at 4:23 pm

Play!

with one comment

Out of my boredom I usually tune in some random Khmer Oldies Songs just to remind myself the glorious era where sound of the music would flew into the deepest of my heart and cheer me up. What I did in the pass was collect all my favorite songs and classified it manually and sometime after clean up my station I let iTune screw up my collection a big pain in the a^^ and as my habit of trying out new os release like Ubuntu every 6 months I got to remind myself backup the music collection before I do something silly. That works out quiet well until I am get lazy and decided not to waste my time move back and force I truth the Internet to play me my favorite songs :) which mean I optimize my money Internet expend when I am not using it for some secrecy works ;)

How it works out for me? YouTube! Yeah, what can’t be find on YouTube right? Except that streaming video on my connection is damn slow and like chopping my head every time the buffer loading. So I tried something lighter pure sound and that tons of site offer free mp3 and I do enjoy using those site which some of you may already know and love. But I am just too demand I want some control over what I want to listen, I want to be able to easily share my playlist with my close friends so they can rejoice in hearing the songs. It turn out that a few site does offer these ability, why am I still not happy? Because the site need to know about me want me to become a member and I kind of like what the f???ck. It like I have to tell my radio who I am before it play me the song kind of thing.

So enough is enough, I thought to myself “look geek if it doesn’t work out, do it yourself” ah huh, that was what I use to talk with my dest friend (sad he’d gone) why don’t we do something about it, It’d be fun. Now that I am bored it justified enough that I block sometime to deliver our plan and so I start prototype the project #sidekick and show it to a few friends get their feedback some -/+ and finally I got it out of the door “JolJET Hits” or should I call it “JolJET Hits Online Music Player” still have an issue of naming it properly but here how it looks:

JolJET Player v2

JolJET Player v2

A typic music player portable as it should be since it developed using HTML 5 and Sencha ExtJS technology blah blah blah not so interesting for an engineer to talk about tools. But hey it’s not bad for the cost of home stay during Khmer New Year instead of enjoying myself sight seeing Thansur Bokor Resort and weeks after to stabilize. But as the passion fill up I glad I spend my time develop this little product so that what I can do now:

  • On first visit to the site the app will load up default playlist fill with about 250 songs enough  if you want to just hear some noise the whole day
  • If you so obsess about what you want to hear then Clear all and start adding your favorite songs from: a) Library b) Artist Collection or c) Blind search
  • when you found it select it (multiple select is supported) and click on Add to playlist to append selected song to your current playlist
  • or if you so want to hear the song immediately just double click it and you got it
  • Not just that if your like to listen to the music during your work hours (I usually did :D) close your browser as soon as your boss walk to your desk, and revisit the site after he/she gone nice trick yeah ;) who never cheat. But I had implemented is the app will remember not only your selected song but it remember your last play song and resume it for you (Thanks Sothy Chanty for  his suggestion)
  • But how about I want my friend to listen to a song. NO NOT 1 songs my collection, well we got you covered from Now Playing tab you find a menu call Sharing just select your favorite sharing technical twitter/facebook and you done

Now that more like an ado why don’t you jump to the site and experience it yourself? Here the link http://play.joljet.net as always I love to hear your comments/suggestions you can do it here or post on facebook page http://www.facebook.com/play.joljet.net

Hope you enjoy the sound LIKE if you LIKED for sharing is caring and have a great weekend ;)

Written by Chorn Sokun

May 5, 2012 at 12:05 am

[mac os x lion] Reset a user’s password in single user mode

leave a comment »

Lesson learn for mac newbie, always show input method in login screen otherwise here how you going to get back into your machine.
  1. Boot into single user mode (press Command-S at power on)
  2. Type fsck -fy
  3. Type mount -uw /
  4. Type launchctl load /System/Library/LaunchDaemons/com.apple.opendirectoryd.plist
  5. Type dscl . -passwd /Users/username password, replacing username with the targeted user and password with the desired password. Ignore the error message!
  6. Reboot

Written by Chorn Sokun

March 2, 2012 at 11:42 am

Posted in Tips & Tricks

Tagged with

Follow

Get every new post delivered to your Inbox.