2007-04-13

The old C++/Gnome versionI have decided to reactivate XEland project. XELand is a small program, which generates night landscapes as stereo pairs for cross-eye viewing. Original version was written in C++/Gnome and had continually problems with compilation (due to lots of dependencies). The Java version Java version is of course free of such problems. Currently it uses two map generation methods (plus some variations). Generated height maps are seamless and can be saved as PNG images. The program requires only JDK 1.5 or above, and is very easy to use. To take full advantage of XEland you should learn cross-eye viewing. Support for anaglyph is expected soon.

2007-03-25

Java Generics: Instantiating Objects Of Type Parameter Without Passing Class Literal To Instance

Cause generics in Java 1.5 and 1.6 are implemented using erasure, in most cases you can not get class object for type parameter, which means that in your generic classes you can not instantiate objects of type parameters. Usually this is solved by special setup of generic class instance (by passing class literals to methods which instantiate objects of type parameter class) but it does not look too god. Fortunately, you can avoid such ugly code in some situations and make generic class smart enough to handle it by itself. More...

2007-03-23

C/GTK or Java/Swing Stopwatch

jstpw Maybe it's hard to believe but there is not too much stopwatch programs for Linux. So I have written one by myself. First was the C/GTK version. Coding it was rather painful for Java programmer accustomed to comfortable Eclipse IDE. So next day I decided to implement same functionality in Java/Swing. The Java version supports simple task tracking and can be started from the command line, via WebStart, or used as applet. Check project's page for downloads section.

2007-03-10

How To Enable UUID In EMF Generated Model To Get Copy&Paste Working

If you get very strange results using Copy&Paste in GMF diagram editor then in all likelihood your EMF model doesn’t use Universally Unique Identifiers. EMF’s XMIResourceImpl supports generation of UUID transparently but it’s disabled by default. Read more here.

2007-03-05

The Blog Has Been Moved

All old and new stuff can be found at new place.
Click here

2006-11-26

Color Scheme Generator for Charts

Sometimes one needs to show many data series on one chart. In such cases, usually distinction between those data series is achieved by using different colors for each data set. Most charting libraries leave colors selection to developer. This can be problem when there is need to choose more than six colors which can be easily distinguished by most people. Below you can find Python program which can be helpful.

Program generates palette of colors where each color can be easily distinguished from other colors in its neighborhood. Difference between colors is computed using W3C's formula for color contrast. Minimum contrast (brightness and color), palette size, neighborhood diameter and maximum number of iterations can be easily set in first few lines of program code.

New colors are created using pseudo-random generators and tested for minimum contrast. If contrast test fails, the color is dropped and new one is created. Besides of minimum required contrast, the size of neighborhood has great impact on probability that test will fail. Too big neighborhood diameter could make it impossible to create complete neighborhood and lock the program. To prevent this, there is limit for number of iterations.
#!/usr/bin/python

from random import randint

class Color:
   __c = [0, 0, 0]
   __cB = None
   def __init__(self, r=-1, g=-1, b=-1):
       if r == -1:
           r = randint(1,255)
       if g == -1:
           g = randint(1,255)
       if b == -1:
           b = randint(1,255)
       self.__c = [r, g, b]
   def __getitem__(self, key):
       return self.__c[key]
   def __setitem__(self, key, value):
       self.__c[key] = value
       self.__cB = None
   def getBritness(self):
       if self.__cB:
           return self.__cB
       else:
           self.__cB = ((self.__c[0] * 299) +
                       (self.__c[1] * 587) +
                       (self.__c[2] * 114)) / 1000
           return self.__cB
   def __sub__(self, other):
       return ((max(self.__c[0], other[0]) - min(self.__c[0], other[0])) +
               (max(self[1], other[1]) - min(self[1], other[1])) +
               (max(self[2], other[2]) - min(self[2], other[2])))
   def __str__(self):
       return "%02x%02x%02x" % (self.__c[0], self.__c[1], self.__c[2])

colors = []
num = 25
comparedNum = 5

c = Color()
colors.append(c)
stopper = 100000

minBrit = 35
minColDiff = 100

print "searching...",
for n in range(num)[1:]:
   while stopper:
       newC = Color()
       passed = 0
       for back in range(comparedNum):
           testedNum = n-(back+1)
           if testedNum < 0:
               passed += 1
               continue
           c = colors[testedNum]
           bDiff = abs(c.getBritness() - newC.getBritness())
           cDiff = c - newC
           if  cDiff >= minColDiff and  bDiff > minBrit:
               passed += 1
           else:
               break
       if passed == comparedNum:
           colors.append(newC)
           print "found:", newC,
           break

       stopper -= 1

if not stopper > 0:
   print "searching failed"
else:
   print "finished"


html = """
< head>

< /head>
< body>
""" % (800/n)

python = "colors = ("

for c in colors:
   html += '
\n' % c python += '"%s", ' % c python = python[:-2] + ")" html += "< /body>" out = file("colors.html", "w") print >>out, html print python out.close()

2006-11-21

Synchronizing EMF and GMF Generated Editors

Frequently one does not want graphical representation for objects of all classes of semantic model in a graphical diagram editor, but graphical objects usually have references to non-graphical and there is still need for creating and editing all of them. In that case it would be nice to reuse EMF generated editor for non-graphical elements as a helper for diagram editor, so there would be no need for creation of custom edit forms. Full article is here.