FOLLOW ME Twitter Facebook Вконтакте LinkedIn RSS Feed

2048 game in Java

Mar 28, 2014
Category: Java
Tags: ,

I’m so addicted to 2048 and I decided to write it in Java. I combined all algorithms and approaches I found on Github and the Internet, and I finally have the game in just one java file. You can find sources here:

IconLoader library

Mar 5, 2014
Category: Java
Tags: ,

Welcome IconLoader a small and useful library for icons handling in Java

IntelliJ IDEA plugins development : Diagrams

Jan 22, 2014
Category: IntelliJ IDEA

Diagrams are only available in Ultimate version of IntelliJ IDEA and Diagram Support is implemented using a commercial library called yFiles. This library has a bit complicated API and if you use yFiles it’s difficult to make something really simple in a short period of time. That’s why I made a diagram framework on top of yFiles. We (IntelliJ team) are using this framework inside Ultimate project and I can’t provide some real code examples. Sorry!

However, I’ve made a very simple plugin that shows how to deal with the diagram framework. You can find source code and java docs of the diagram framework API on GitHub

Don’t forget to setup Plugin SDK properly before you start and read instructions in

Video is available here:

How to extend the WordPress cookie timeout

Dec 30, 2013
Category: Tips and Tricks

First of all: I really like WordPress. I’ve been using it since 2004 or so. At the moment I’m registered on a several WordPress-based web-sites where I write comments and interact with other people from time to time. The thing I really don’t understand in the WordPress architecture is why WordPress has hard-coded cookie timeout for only 14 days? It makes me angry all the time I see that a WP-based web-site forgot who I am.

Hopefully, if you’re a web-site administrator, this is an easy-to-fix problem. All you need is to slightly change your current theme’s function.php file. What you should do:
1. Go to the Admin Panel and then Appearance -> Editor
2. Click on Theme Functions (functions.php)
3. Paste this code to the end of the file, but before ?> ending tag.

function custom_auth_cookie_expiration($date) {
  return 365 * 24 * 60 * 60; // one year in seconds

add_filter('auth_cookie_expiration', 'custom_auth_cookie_expiration');

365 here is a number of days. You can change it as you wish.

Bug with stringWidth() in JDK 1.7.0_40

Sep 13, 2013
Category: Java

Today I found that JDK 1.7.0_40 has a bug in the strings width calculation for some fonts. The problem easily reproduces with Retina displays. I wrote a test to do this:

import javax.swing.*;
import java.awt.*;

 * @author Konstantin Bulenkov
public class TextWidthTest extends JFrame {
  public TextWidthTest() throws HeadlessException {
    super("Text Width Test in JDK 1.7.0_40");
    setSize(280, 40);
    final String str = "nnnnnnnnnnnnnnnnnnnn.txt";
    JComponent customComp = new JComponent() {
      protected void paintComponent(Graphics g) {
        FontMetrics fm = getFontMetrics(getFont());
        g.fillRect(0, 0, fm.stringWidth(str), fm.getHeight());
        g.drawString(str, 0, fm.getHeight());
    Font font = new Font("Lucida Grande", Font.PLAIN, 12);

  public static void main(String[] args) {
    new TextWidthTest();

I was playing with the test and found out that FontMetrics returns a wrong width for some combinations of symbols and fonts. I decided to have a break after this:


Font rendering: Apple JDK 6 vs Oracle JDK 1.7.0_40

Sep 12, 2013
Category: Java

The Oracle JDK version 1.7.0_40 contains significant improvements in font rendering comparing to latest builds of Apple JDK 1.6

Apple JDK with Quartz

Oracle JDK 1.7.0_40

First screenshot was made with Apple JDK. Quartz Graphics Framework enabled by passing as a system property to render text and graphics. Anyway, fonts and colours under Apple JDK with Quartz look so different in java applications comparing to native ones. The good news is that fonts look natively with new Oracle JDK. It uses new approaches to render texts.

Also Apple JDK with Quartz modifies colours while rendering and makes them more soft. Look at the difference in backgrounds on the pictures. They have the same background colour… sort of…

How to restore unreadable USB flash drive under Mac OS X

Sep 1, 2013
Category: Tips and Tricks

USB Flash Drive recovery Today I found that I can’t access to my 8Gb USB flash drive. I can find it in Finder, but the System gets stuck while accessing to it. What to do? If you want to recover data from a USB flash it’s better to stop reading this post now and continue googling “USB flash data recovery” or something. Here’s a step-by-step instruction how to make your USB flash drive work again under Mac OS X.

1. Open Terminal and go to /dev

$ cd /dev

2. Now it’s time to find your flash drive in /dev. Typically it’s /dev/diskN where N could be 0, 1, 2, 3, etc

$ diskutil list
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *121.3 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            120.5 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *8.1 GB     disk3
   1:                        EFI                         209.7 MB   disk3s1
   2:       Microsoft Basic Data KB                      7.9 GB     disk3s2

OK! It’s disk number 3, i.e. /dev/disk3 Remember the name of partition (it’s KB in my case). Your flash drive is mounted as /Volumes/NAME Continue reading »

Idea 11 Icon pack updates

Jul 12, 2013
Category: IntelliJ IDEA

I moved my IntelliJ IDEA plugin “Idea 11 Icon pack” to the official plugin repository. Now, permanent link is The plugin is now available through Preferences -> Plugins -> Browse Repositories


Retina support in Oracle JDK 1.7.0_40 and above

Jun 23, 2013
Category: Java

Hi everyone!

A few days ago I installed Oracle JDK (version 1.7.0_40) built especially for early access purposes. So, it’s not the final release. The build contains tons of bug fixes and backports from JDK 8 for AWT/Swing and that was the main point why I started to play with it. As you might have heard, Retina support was one of the major issues in all 1.7.* releases. I’d say there was no Retina support before the build 1.7.0_40. I’m going to show you some differences of Retina support in Apple and Oracle JDKs.

1. isRetina() method

That’s funny, but there is no public API for it in Oracle JDK 7. Here is how we (IntelliJ IDEA team) do it under Apple JDK:

class IsRetina {
  public static final boolean isRetina = isRetina();

  private static boolean isRetina() {
    try {
      final boolean[] isRetina = new boolean[1];
      new apple.awt.CImage.HiDPIScaledImage(1, 1, BufferedImage.TYPE_INT_ARGB) {
        public void drawIntoImage(BufferedImage image, float v) {
          isRetina[0] = v > 1;
      return isRetina[0];
    catch (Throwable e) {
      return false;

Continue reading »