pikopong

it's all about knowledge

Reading Mifare 1K Card using Java in Linux

with 37 comments

At the end of last year, my friends and I were tasked to read our staff card. The main objective was pretty simple, to create a library where we don’t have to depend on the vendor everytime we want to read our own staff card and the library should also be working on Windows and Linux (that means Java to us).

Working Environment

  1. Slackware 12.2
  2. JDK 6 Update 11
  3. Netbeans 6.5
  4. libusb 0.1.12
  5. Windows Binary of JPC/SC Java API 0.8.0
  6. Your contactless smartcard reader’s driver

Read the rest of this entry »

Written by amree

February 11th, 2009 at 4:27 pm

Posted in programming

My First Experience using Canon 40D

with 2 comments

On the 5th of September 2008, I bought my first DSLR gears during my trip to Kuala Lumpur. The items are Canon 40D, Canon Speedlite 580EX II, Canon 50mm f/1.8 and some other things for about RM 5,000 which I don’t think is a really good bargain, but definitely better than what I’ll get if I bought them in Kelantan.

Ever since that purchase, I’ve been reading the manual whenever I got free time as I thought how am I supposed to be a better photographer if I don’t know the full potential of my camera ? I also managed to get some pirated book about the camera such as Canon EOS 40D Digital Field Guide. I was actually preparing myself for my uncle’s engagement event on the 3rd day of Hari Raya Aidilfitri. However, another event added to my list which is my cousin’s wedding event. I’m pretty happy that I finally had the chance to try whatever I learnt to the real world since using the chair in my room as a model is getting boring.

So, fast forward to my cousin’s wedding day. The main event that day was “Akad Nikah” which took place at a mosque near her house. Sadly, on my first try out as a photographer using my new camera, I made a lot of mistakes, lots of them. These are the mistakes that I knew (there are definitely more):

  1. I didn’t identify the main characters for the event thus there are only a few photos of them.
  2. Overuse of f/1.8 resulting a very bad group photos.
  3. Always beware with the additional characters such as children playing around which spoiled my shot with their blur movement.
  4. Wrong setting for shutter speed whenever I want to capture a candid moment such as hugging, shaking hands and so on.
  5. I need to ask them to look at me whenever I want to take photos (yes, I forgot to ask them to do that every time there are other photographers around).
  6. I need to know in advance the settings for the indoor and outdoor. Almost all of my outdoor shots after the event (which took place indoor) were overexposed as I didn’t have the time to test the correct settings.
  7. Always test other flash exposures even though the initial setting is OK at the first try.
  8. I should’ve known the limitation of my 50mm lens.
  9. I should not feel shy whenever I want to get close the subject.

So, what about the mistakes that I’ve done during my uncle’s engagement day ? This is the list:

  1. All the previous mistakes ;)

However, one thing for sure, I really need to start saving and buy a wide angle lens. 50mm is great for portrait shots, but not for group shots or even two people at some distance in a cramp room. *Sigh*, there’re still so many things to learn.

Written by amree

October 7th, 2008 at 8:59 am

Posted in photography

Printing to PDF Using CUPS

without comments

  1. Install CUPS-PDF based on your distro, you can download if from here.
  2. Click this link http://localhost:631 or type it into your browser.
  3. If the page requested a username and password, just enter your root username and password.
  4. Go the “Administration” tab and select “Add Printer” in the Printer section.
  5. For “Add Printer” page, put a name for your virtual PDF printer, any name will do. Then click “Continue”.
  6. For the second page, that is “Device for a”, you should select “CUPS-PDF (Virtual PDF Driver)”. If it’s not there, then you haven’t execute Step 1 successfully.
  7. In the 3rd page, choose “Generic” as the Make and then click “Continue”.
  8. 4th page, choose “Generic CUPS-PDF Printer (en)” as the model and then click “Add Printer”. You’re done, but we need to customize where the file will be located when you printed it.
  9. Edit /etc/cups/cups-pdf.conf in your favourite editor.
  10. Put these lines at the end of the file and save it (both can be customized):
  11. 1
    2
    
    Out /home/${USER}/Desktop
    Label 1
  1. The first line actually tell CUPS to print your file to the Desktop and the second line will make sure your file won’t be overwritten by the newer one.
  2. Restart your CUPS, for Slackware users, you can type this command /etc/rc.d/rc.cups restart
  3. So, that’s all and good luck !

Tested on Slackware 12.1, CUPS 1.3.7

Written by amree

September 10th, 2008 at 10:01 am

Posted in linux

Java Printing Fix for Linux with CUPS

with 17 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

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