pikopong

it's all about knowledge

Java Printing Fix for Linux with CUPS

with 18 comments

Apparently, there’s a bug in Java where people using newer version of CUPS cannot print (can’t even display the print dialog) due to a null pointer exception and this is actually a known bug. So, how do we fix this? For people who use Gnome, you can refer to this page.

However, for people who uses non gui environment such as Fluxbox, Openbox and etc (Gnome and KDE user can use these steps too), you can fix it by editing your CUPS printers configuration file. You can get edit the file at /etc/cups/printers.conf

<DefaultPrinter Printer>
# Printer configuration file for CUPS v1.3.7
# Written by cupsd on 2008-09-08 11:24
.
.
.
Option orientation-requested 3
</Printer>

Make sure you add line 7 to every configuration for every printer you’ve installed. If you cannot find the file, you probably haven’t configured any printer yet.

This fix is simply to make sure CUPS will provide a page orientation setting to Java.

The exception:

Caused by: java.lang.NullPointerException: null attribute
        at sun.print.IPPPrintService.isAttributeValueSupported(IPPPrintService.java:1147)
        at sun.print.ServiceDialog$OrientationPanel.updateInfo(ServiceDialog.java:2121)
        at sun.print.ServiceDialog$PageSetupPanel.updateInfo(ServiceDialog.java:1263)
        at sun.print.ServiceDialog.updatePanels(ServiceDialog.java:437)
        at sun.print.ServiceDialog.initPrintDialog(ServiceDialog.java:195)
        at sun.print.ServiceDialog.(ServiceDialog.java:124)
        at javax.print.ServiceUI.printDialog(ServiceUI.java:188)
        at sun.print.RasterPrinterJob.printDialog(RasterPrinterJob.java:855)
        at sun.print.PSPrinterJob.printDialog(PSPrinterJob.java:421)

Refer to some of the discussions here:

UPDATE: I forgot to add, you need to restart your CUPS after editing the configuration (Thanks to Brandon Bell)

Tested on Slackware 12.1, JDK 1.6 Update 7, CUPS 1.3.7

Written by amree

September 9th, 2008 at 10:08 am

Posted in linux

Tagged with , , ,

Auto Resize JTable Column Width

with 10 comments

This code should resize your JTable column width based on the contents of the header and data.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    public JTable autoResizeColWidth(JTable table, DefaultTableModel model) {
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setModel(model);
 
        int margin = 5;
 
        for (int i = 0; i < table.getColumnCount(); i++) {
            int                     vColIndex = i;
            DefaultTableColumnModel colModel  = (DefaultTableColumnModel) table.getColumnModel();
            TableColumn             col       = colModel.getColumn(vColIndex);
            int                     width     = 0;
 
            // Get width of column header
            TableCellRenderer renderer = col.getHeaderRenderer();
 
            if (renderer == null) {
                renderer = table.getTableHeader().getDefaultRenderer();
            }
 
            Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
 
            width = comp.getPreferredSize().width;
 
            // Get maximum width of column data
            for (int r = 0; r < table.getRowCount(); r++) {
                renderer = table.getCellRenderer(r, vColIndex);
                comp     = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false,
                        r, vColIndex);
                width = Math.max(width, comp.getPreferredSize().width);
            }
 
            // Add margin
            width += 2 * margin;
 
            // Set the width
            col.setPreferredWidth(width);
        }
 
        ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(
            SwingConstants.LEFT);
 
        // table.setAutoCreateRowSorter(true);
        table.getTableHeader().setReorderingAllowed(false);
 
        return table;
    }

Example:

1
2
3
// Must pass the model
DefaultTableModel model = new DefaultTableModel();
jTable = autoResizeColWidth(jTable, model);

Tested on JRE v5 and JRE v6

Written by amree

August 13th, 2008 at 2:49 pm

Posted in programming

Tagged with , ,

Japanese Drama: Kurosagi

without comments

Kurosagi

“In this word, there are three types of swindlers. Those who defraud other people’s money, Shirosagi. Those who deceive others by manipulating their feelings, Akasagi. And then, using the Shirosagi and Akasagi as his only source of food, is the ultimate swindler in history. His name is Kurosagi” Pretty cool eh ? That’s the opening text of this drama.

Kurosagi is the latest JDrama I’ve watched. I’m actually not really a fan of JDrama since most of the stories are more about relationships. I haven’t known any drama that focuses more on action and stuffs, but maybe that’s because I’m just not exposed enough to the world of JDrama ;) I think the last time JDrama I watched was Friends (god damn Kyoko Fukada looks so cute in this drama).

Anyway, enough of Friends, I wanna talk about Kurosagi. The drama is about how a victim of a con case which in turns became a con artist himself. The main difference between him and other swindlers is that he only cons from bad swindlers. That storyline alone got me hooked to this 11 episodes drama. The story kinda like Matchstick Men by Nicholas Cage. So, if you like this Comedy/Drama/Thriller/Crime/Romance (just a little bit), go grab the DVD, totally worth it, but of course, I just downloaded it from the net :) Oh yes, you can get more information about the actor and the actress from DramaWiki. Enjoy the drama!

Written by amree

June 4th, 2008 at 2:07 am

Posted in vids

Tagged with

Reading MyKad using Visual Basic

with 19 comments

It seems that a lot of people asking how to read MyKad using Visual Basic, but since I don’t have the slightest idea on how to code in VB, I started to search around. To my surprise, Xenon (the one who reverse engineered MyKad to get the APDU) actually wrote a small application in VB to read MyKad. So, for those who can’t afford to buy SDK from commercial company, you can download the code here for FREE !

VB Application to read MyKad


View the discussion
Download the code

Written by amree

May 28th, 2008 at 12:32 am

Posted in programming

Tagged with , , ,

Hospital Universiti Sains Malaysia at WCIT 2008

with 2 comments

WCIT 2008

In case you didn’t know, HUSM stands for Hospital Universiti Sains Malaysia and I’m currently working there. Early this year, my head of the department got invited by MDeC to this event. The event took place at Kuala Lumpur Convention Center from 18/5/2008 to 22/5/2008. You can read all the information about WCIT here.

To my surprise, we were the only hospital that manage software development all by ourselves. Even though Hospital Universiti Kebangsaan Malaysia started developing their own, they still has to rely on vendors in terms of hardware and the database (they’re using Oracle). Other hospitals didn’t actually bring their own IT Department people, instead they sent their vendors. However, they’re some from Kementerian Kesihatan Malaysia who brought their own IT people even though the application they brought was coded by the vendor (the only difference is that they own the code, not the vendor).

The event was a really an eye opener for me. I saw lots of new technologies that has been integrated into our daily lives. It’s pretty cool to see the advancement of IT industries in Malaysia. I managed to meet some interesting developers, managers and others who has a lot of experience in the industry itself. Not to forget, I also managed to come close to our Prime Minister and also Yang di Pertuan Agong. It was almost as I could actually slap their back, but of course I didn’t do it, hey, I still love my job :)

However, I’m a little bit disappointed with the technology used. Lots of people/developers/vendors in the government still rely on non-open source software. Why should you pay when you can get it free? That’s what HUSM is trying to say in the event. We’ve developed our own software and save millions of ringgit, but of course, other managements don’t care, they think as long as they have the money, they’ll just spend it to the max. What they don’t realize is that some of the money that shouldn’t be spent in the first place could be used for other things. Now, imagine that mindset in each and every head of the department (including non-IT) in Malaysia. We could actually save billions and our IT people will gain knowledge more than ever.

I’m also surprised other IT Department didn’t bother to ask us much about the technologies that are being used in our applications. I mean, it’s not that weird if the end user didn’t ask what database that we use, but IT people ? Come on, it’s like a chef is not interested in asking about the recipe (ok, maybe a bad analogy there, but you should get my point).

Even though we just got small booth (read: very very small), I think we somehow manage to tell the people that HUSM is different. I’m looking forward to another event like this. Till then, enjoy the photos taken using Canon A710 at my Picasa Web Albums.

P/S: Thanks to MDeC for the invitation, we really appreciate it :)

Written by amree

May 25th, 2008 at 6:37 pm

Posted in husm

Tagged with , , ,