Vitavonni

Mon, 25 May 2009

If you're wondering why your circle is a diamond ...

... you might be bitten by this Java bug rendering arcs as straight lines at large zoom levels.

It looks like a classic to me: in order to improve rendering performance, you approximate arcs with straight lines at small resolutions (if it's just 2 pixels big, nobody will be able to tell the difference). Except of course, when you end up doing the same approximation at a large zoom value - of course a 100-pixel circle looks different from a 100-pixel diamond.

Reported in 2005, still not fixed in current Java (we're in 2009 now).

Sun is really slow at fixing Java bugs.

See also a related Apache Batik bug report. Fortunately, this only applies to Java rendered graphics - SVG export, PDF, Postscript are all fine.

[category: /en | Permalink]

Sat, 16 May 2009

Adobe GoLive question

Is there any way to provide an alternate CSS stylesheet for GoLive CS2 only, not for regular browsers? Because there are some things in that layout that are too difficult for the GoLive renderer, it doesn't display them right. The pages are still editable (just plain XHTML), it's just not looking right in GoLive (advanced CSS).

The site already has alternate stylesheets for browsers such as the broken Internet Explorers, so if I could convince GoLive to use their stylesheet it might be looking a lot better in the editor, too ...

I am aware that GoLive CS2 has been abandoned in favor of DreamWeaver. Still it's going to be used in a project I help with the web templates.

(Other options would be Kompozer and Amaya, but none of them seem really fit for production use: Amaya was just removed from Debian because it had some security issues and the maintainers had the impression the code was such a mess that there will be much more such issues. And Kompozer seemed to be a mostly dead branch of a Gecko hack (although there has been a new alpha release this year) ... is there some reliable opensource non-source HTML editor that I'm missing?)

P.S. Sorry, no comments in this blog. Use Email: erich AT debian ORG

[category: /en/web | Permalink]

Tue, 12 May 2009

Java hacks: Generics and toArray

Arrays and Generics in Java do not mix very well. In order to create an array, you need to know the object class the array is supposed to store.

Arrays in Java are special: they can efficiently store primitive data types. The expected difference in efficiency between byte[] and Byte[] is pretty big (of course some good VM might optimize) for obvious reasons (think of: references, garbage collection, pointer sizes, ...).

This is probably why you need to know the type before creating an array (because an array of primitive types such as byte will be different from one that stores objects of some kind).

In particular, the following Java code

  String[] foo = (String[]) new Object[0];
results in a run time error ("[Ljava.lang.Object; cannot be cast to [Ljava.lang.String;"). But it gets more confusing when you introduce generics:

public static <T> T[] test() {
  T[] te = (T[]) new Object[0];
  System.err.println(te.length);
  return te;
}

String[] foobar = test();

will print "0", then throw the same run time error in the foobar line.

What happens here is that in the test() method, T actually is replaced with "Object" at compile time. Thus the array type works just fine, and so does the call to te.length. Upon returning, it is then cast into a String[] array and fails.

Now here comes a crazy Java hack:

public static <T> T[] test(T... ts) {
  T[] te = (T[]) java.lang.reflect.Array.
      newInstance(ts.getClass().getComponentType(), 0);
  System.err.println(te.length);
  return te;
}

String[] foobar = test();

The exception is gone, foobar is of the proper type now!

A result of discovering this hack are these two methods:

public static <T> T[] newArrayOfNull(int len, T... ts) {
  // Varargs hack!
  return (T[]) java.lang.reflect.Array.
      newInstance(ts.getClass().getComponentType(), len);
}

public static <T> T[] toArray(Collection<T> coll, T... ts) { // Varargs hack! return coll.toArray(ts); }

Notice how elegant the last method looks - and it finally allows you to do toArray(collection) instead of collection.toArray(new WhateverClassTheCollectionHas[0]).

Note that this is still a hack, and may or may not work with all Java compilers, JREs and/or Java versions.

Update: Note that this 'hack' is also not transitive. The context calling toArray needs to know the object type at compile time. So it doesn't save you much more than writing "new KnownClass[0]" etc.

Update: So I'm actually not using this - it's just a hack, and often quite hackish. The problem is that when you call e.g. toArray in an Generics context, it will actually create an array of "Object", so it makes much more sense to verbosely specify the class you want to use for the arrays (and get some reliability in use back).

[category: /en | Permalink]

Dropbox experiences?

Has anyone experience with Dropbox?

It seems to be an interesting web storage service, with 2 GB of free storage.

However, the Linux client seems to be closed source (which is understandable, it seems to have a lot of neat features) - so I intend to use the web interface only (at least for now).

Update #2: There is a RFP bug for Debian, some Source is on the download site. And while this sort (except the images) is GPL, it's just the nautilus integration part, not the daemon you also need.

Did you try Dropbox? Does it work well? I know some people (especially Windows users) who could benefit a lot from a service like that, so I wonder if I should recommend them Dropbox. Or is there some better alternative (it should allow sharing of files though - synchronization is not as essential, it is a lot about exchanging files too large for usual email in small user groups; still synchronization probably is a comfortable way of transferring the files without having to think about it yourself)?

No comments in this blog - email me via erich AT debian ORG.

P.S. I know there is some referral program to get more storage, feel free to send me your referral link - I'll remove this PS once I've signed up.

P.P.S. There also is Ubuntu one, but as far as I can tell Ubuntu only so far. Looks very similar.

P.P.P.S. So far, I've received a lot of praise for DropBox.

P^4.S. My own referral link, feel free to use this to sign up (+256 MB for you, too!) and "upgrade" my account.

[category: /en/web | Permalink]
Menu
[planet.debian]
[planet.xmlhack]
[planet SELinux]
[munichblogs]
[email]
[RSS 2 feed]
[English RSS 2]
Categories
< May 2009 >
SuMoTuWeThFrSa
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
31      
Archives
2010-Mar
2010-Feb
2010-Jan
2009-Dec
2009-Nov
2009-Oct
2009-Sep
2009-Aug
2009-Jul
2009-Jun
2009-May
2009-Apr
2009-Mar
2009-Feb
2009-Jan
2008-Dec
2008-Nov
2008-Oct
2008-Sep
2008-Aug
2008-Jul
2008-May
2008-Apr
2008-Mar
2008-Feb
2008-Jan
2007-Dec
2007-Nov
2007-Oct
2007-Sep
2007-Aug
2007-Jul
2007-Jun
2007-May
2007-Apr
2007-Mar
2007-Feb
2007-Jan
2006-Dec
2006-Nov
2006-Oct
2006-Sep
2006-Aug
2006-Jul
2006-Jun
2006-May
2006-Apr
2006-Mar
2006-Feb
2006-Jan
2005-Dec
2005-Nov
2005-Oct
2005-Sep
2005-Aug
2005-Jul
2005-Jun
2005-May
2005-Apr
2005-Mar
2005-Feb
2005-Jan
2004-Dec
2004-Nov
2004-Oct
2004-Sep
2004-Aug
2004-Jul
Other links:
Swing and the City - Lindy Hop in Munich