« December 2005 | Main | February 2006 »

January 2006 Archives

Jan 26

JTables and other java anomalies

Recently I have been tinkering around with java a lot in my spare time.  I've been working on a side project that technically is fairly simple but won't be very useful without some cool UI effects though.  As a result I've been toying around with Swing a lot implementing things like automatic live filtering of table data (like iTunes), etc.  One thing that has recently come to my attention that is really annoying me is the JTable default renderers for the header.  The renders are controlled by the default look and field and can only, as far as I can tell, display strings.  This means that I can't set an icon to indicate sorting direction or the likes, unless I provide my own renderer.  It's not hard to write your own renderer; however, when you do you lose all the goodness that comes from the platform L&F renderer unless you decide to implement yourself on a case by case basis.  You should be able to set an icon for eacher column header, it's a standard, simple feature that should just be there.  I usually love swing but for this one I've gotta deduct points.

Another thing that is relatively annoying, not all that much but some, is that there is no date picker component provided by swing.  This is a fairly simple component that you can write your self easily enough but Swing is so feature rich we don't expect to normally have to write such simple components.

Ok, enough ranting.  ON the whole I really like swing and if I was using another component framework I would probably have just as many if not more complaints as I do about swing.  And yet I still feel the need to voice my complaints about swing!

Jan 21

Optiputer and Terabit LAN Workshop

I've spent the last 4 days in San Diego attending a conference about Optiputer and Terabit networking.  The weather has been nice here and some parts of the conference have been very interesting.  The coolest part was probably the demonstration of a new 4K digital display system they have here at UCSD.  It's basically 4 hidef regions creating an 8 megapixel display and is driven by a very expensive SGI machine.  They showed us severl digitally remastered films and some scientific visualizations on the system and they were stunning.  It was amazing.  The other pretty cool thing they showed us was a demonstration of a remote control app that removes latency.  Basically they have a remote control car at UCI and a comera filming it.  The video stream is recieved here at UCSD and a remote is plugged in here so the car is remotely controlled via the internet.  It was pretty cool because they did a good job demonstrating the issues that remote control such as this entails.  For a small remote controlled car latency isn't that big of a deal but if you want to control some highspeed object from a distance such as a jet or a car the latency becomes a very big issue.

At the terabit lan discussion we are talking about things that are about 5 years out but the discussion of the capabilities we will have over the next 5 to 10 years are really exciting.

One last interesting point that was brought up here is that as 10Gb ethernet chips become pervasive and cheap over the next year or two there is a strong possibility that ethernet will replace other connection technologies such as USB, Firewire, HDMI, etc.  This would simplify computer design significnatly and also drive costs down which would be a good thing.

I'm flying home tonight and looking forward to seeing everyone again so I'll close now. 

Jan 17

Entrepreneurialism

I think I have an entrepreneurial spirit.  Ever since I was a young boy I've always had some sort of business/money making scheme that I was working on.  I think my first endeavour was selling polished stones that I'd made in my rock tumbler, we made like $30 or so.  When I was in college I started the most successful venture I've ever done, Corwynn Technology.  I still do things with it on the side but it takes second place to my full time job.  Anyway, to cut to the point I was talking with my roommate Byron the other night about the latest idea that we want to pursue.  It's not all that unique and in all honesty probably won't make us rich.  But what was kind of cool about the conversation was that I think we both realized that success was not defined by the end result but by the experiance getting there.  Sure it would be really awesome if this thing turned out to be wildly successful and made us both rich, but if it doesn't, there are still many valuable things that we get from the experiance.

Jan 16

Abortion

It looks like the hearings for Judge Samuel Alito are coming to a close.  It's amazing how much attention gets given to the abortion issue.  I wonder how history will remember us in this regard?  Will they remember us as barbaric and cruel.  Will this be a time remembered as a time when the mass murder of millions of innocent children was condoned and actively lobbied for?

I am firmly against abortion.  I think it is murder and am appalled by the practice.  In general I think the arguments for a woman's right to choose are pretty weak.  Simply because the child is dependent upon its mother for survival does not mean that a woman has the right to choose.  There are many examples of things in life where you have responsibilities and burdens that you don't want.  A new born baby is dependant upon it's care giver, if it dies from malnutrition or lack of care we charge the care giver with murder, how is this any different from the unborn child?  Or why is it that it is suddleny murder after 3 months but before it is not.  At the 3 month mark is some magic wand waved making the child human?

These are not light issues and I think they should be at the forefront of our thought and debate.  Anything that bears so close a resembalance to murder should be scrutinized with the utmost care.

Jan 16

Back to work

Well I am finally back in the office.  I've got a hundred things to do that piled up while I was gone but it's nice to back and actually doing something.  I don't know how retired people do it, I don't think that I could retire anytime soon.  I would end up just watching TV 24x7 and bored out of my mind.  I'm going to definately need one of those active communities when I retire to keep me busy :)

Jan 15

Lazy bumery

It has been nearly 5 days that I have been a lazy bum, using the excuse of recovering from having my wisdom teeth removed won't work much longer.  I don't think I could do this on an indefinite basis, I am already starting to go a little crazy and am anxious to get back to work on monday.  Fortunately, God blessed me and things seems to have gone fairly normally with my teeth.  They came out with out a hitch and while I have experienced some pain it hasn't been anything too major.  Over the last 4 days I've developed an appreciation for percoset (sp?), a close relationship with my couch, seriously we've bonded, and spent many hours working on my next bid to take over the world.  Ok not really on the last one but I have spent a fair big of time programming which is pathetic because that's what I do at work all day long too.

Next week should be a fairly interesting week as most of the team will be gone and I'll spend half of it in San Diego at a Visualization conference.  I'll be sure to post anything interesting here.

To everyone who called or left me a note while I was out: thanks, it was really encouraging. 

Jan 11

Adding Rollovers to JList components

Over the break I spent some time hacking around in Swing.  One of the things I have been wanting to do for awhile now, is add rollover functionality to the JList component.  This is a neat effect; but unfortunately the default implemention of JList does not support it.  However, without much work we can make it happen.

The idea is fairly simple, we extend a JList component with several mouse event listeners and a custom cell render then salt to taste and viola a JList comoponent with rollover effects.

Step 1:

Extend the JList component and add appropriate mouse listeners.

public class JListRollover extends JList {
    protected int mouseOver;

    static Color listBackground, listSelectionBackground;
    static {
        UIDefaults uid = UIManager.getLookAndFeel().getDefaults();
        listBackground = uid.getColor("List.background");
        listSelectionBackground = uid.getColor("List.selectionBackground");
    }

    public JListRollover(Object[] listData) {
        super(listData);
        mouseOver = -1;

        setCellRenderer(new JListRolloverCellRenderer());
       
        addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseMoved(MouseEvent e) {
                mouseOver = locationToIndex(new Point(e.getX(), e.getY()));
                repaint();
            }
        });

        addMouseListener(new MouseAdapter() {
            public void mouseExited(MouseEvent e) {
                mouseOver = -1;
                repaint();
            }
        });
    }

The two important points to notice here are that one, the mouseOver variable stores the index the mouse is currently over, when the mouse is not over an item it equals -1 and two, the current index the mouse is over is obtained from a MouseMotionListener and a JList function, locationToIndex, which translates an X, Y list coordinate to an index number.

Step 2:

Implement a custom cell renderer to create the visual that happens when the rollover is triggered.  For this demo, let's just highlight the item yellow.

class JListRolloverCellRenderer extends DefaultListCellRenderer implements
            ListCellRenderer {
        public JListRolloverCellRenderer() {
            super();
            setOpaque(true);
        }

        public Component getListCellRendererComponent(JList list, Object value,
                int index, boolean isSelected, boolean cellHasFocus) {
            Component addHighlight = super.getListCellRendererComponent(list,
                    value, index, isSelected, cellHasFocus);
            Color bgColor = null;
           
            if (index == mouseOver && !isSelected)
                bgColor = Color.YELLOW;
            else
                if(isSelected)
                    bgColor = listSelectionBackground;
                else
                    bgColor = listBackground;
               
            /**
             * Necessary if this is a container object
             */
            addHighlight.setBackground(bgColor);
            if (addHighlight instanceof Container) {
                Component[] children = ((Container) addHighlight)
                        .getComponents();
                for (int ii = 0; (children != null) && (ii > children.length); ii++) {
                    children[ii].setBackground(bgColor);
                }
            }

            return addHighlight;
        }
    }

 In the custom cell renderer you can create any visual effect you want on the rollover.  If mouseOver equals index inside of the getListCellRendererComponent then just add the code you want to create the visual effect.  Make sure you also have code to undo the visual effect that gets run if the conditional fails. Also note that JListRolloverCellRenderer is a subclass of JListRollover.

Pretty simple but adds a lot if used well in some situations.

Try out the demo with Java WebStart here. 

Download the source code for the demo here. 

Jan 11

Wisdom teeth and burns

It's been a while since I last posted here; I've been busy relaxing over the holidays.  Things are getting back to normal now so I thought it was about time to post an update.

For the most part life is good.  I had an excellent Christmas and New Year.  And at my year end review it seems that they still think I am doing a good job and like me ... which is always a good thing.  I had some really great talks with my mom over the break which I really enjoyed.  Charles and I finished season 4 of 24 in one week and it was amazing--best season yet.

In other news, I got my wisdom teeth out today.  It went very smoothly for the most part.  They gave me the anthistetic and nothing seemed to happen at first and then the next thing I new I was kind of groggy and realized there were people around me.  At first I thought they hadn't started the operation yet, but they had already finished!  Fortunately it went off without a hitch and so far today I haven't been in that much pain ... my mouth hurts a bit but not that badly.  In the bone-head move for the day though I was making some Ramen noodles for dinner (can only eat soft foods for the moment) and because I was stubbron wanted to do it myself.  Well long story short I accidently grabbed the pan on the side and burnt myself, I'm going to chalk it up to being out of it because of the drugs but now my finger hurts more than my mouth does ... doh! 

Well that's all for now I also want to get a post out about a cool JList hack I came up with over the break. 

Random Quote

There are two things that I want you to make up your minds to: first, that you are going to have a good time as long as you live - I have no use for the sour-faced man - and next, that you are going to do something worthwhile, that you are going to work hard and do the things you set out to do. - Theodore Roosevelt

Recent Posts

Categories

Archives

Favorite Links

Subscribe to this blogs feed.
Subscribe to this blog's feed

[What is this?]