Category: Programmieren


Custom configuration sections for .NET made easy

Februar 2nd, 2012 — 11:13pm

Currently I’m working on a bigger project, containing a quit complex web service, talking to a even more complex command line application. Today I realised, that the configuration of my web service was in the need of becoming a little bit more flexible than originally estimated. As I’ve already written a few custom configuration sections, I was desperately trying to find an easier solution as the creation of configuration sections is an extremely time consuming but yet stupid task.

On my search through the web I found this great Visual Studio 2010 plugin which offers a visual designer for creating configuration sections. Despite saving time on writing code, this plugin also creates appropriate xsd schemas which enables Visual Studio to offer auto completion on changing the configuration file.

After installing the plugin, add a new item to your project of the type ConfigurationSectionDesigner which will appear in the add item dialog. The rest is a piece of cake!

I have immediately fallen in love with this plugin.

Comment » | .NET

Java: Checking which scrolling direction is enabled in Mac OS Lion

August 16th, 2011 — 8:08pm

With the introduce of Mac OS Lion Apple added the option to enable “natural scrolling” which simply inverts the scrolling direction of input devices to get an iOS like scrolling behavior. However, some Apps may require to ‘invert the inverted scrolling’, like Apps which use scrolling for zooming, which indeed should not be inverted. Unfortunately Apple dropped the development of Java and didn’t added a method or property to get the scrolling behaviour.

So today I tried to find a solution which helps to find out if natural scrolling is enabled or not in Java. I know that the preference would be saved in a .plist file so I checked with fseventer which one it was. After this the only thing I had to do was finding a library which allowed me to read .plist files and to check the scrolling property.

You will need this library to run the snippet.

try {
    File globalPref = new File(System.getProperty("user.home") + "/Library/Preferences/.GlobalPreferences.plist");
    NSDictionary dict = (NSDictionary)PropertyListParser.parse(globalPref);
 
    NSNumber pref = (NSNumber)dict.objectForKey("com.apple.swipescrolldirection");
 
    if(pref.boolValue()) {
        //natural scrolling is enabled
    }
 
 
} catch (Exception ex) {
    System.out.println("Faild to parse plist: " + ex.getMessage());
}

Hopefully this small snippet will be useful.

Comment » | Digitale Welt, Java, Macintosh, Programmieren

Getting ready

Februar 6th, 2011 — 11:28pm

Few more tweaks and ready to go :)

Comment » | Cocoa & Objective-C, Digitale Welt, Macintosh

Cocoa is sucking and ruling synchronously

Januar 29th, 2011 — 1:09am

Slowly I’m getting a feeling of how to create apps with the help of objective-c and cocoa. And it both sucks and rules at the same time!

At first, the things I like. Bindings. They are impressing! Generating small apps without a single line of code, visualizing data with several UI components fast. Makes really fun. Also objective-c as a programming language is cool combined with cocoa as the framework, even if objective-c feels a little bit outdated compared to something like C#.

Now what really sucks. Creating layouts with the interface builder. In took me nearly an hour, to complete a simple view like this:

A basic window with a NSSPlitView and a NSOutlineView. At first, positioning the elements not to overlap was a pain in the ass. Second, my simple wish to fix the size of the left view seemed to be impossible within the interface builder. After a little bit of googling I’ve found following snippet.

-(void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:
(NSSize)oldSize
{
	CGFloat dividerThickness = [sender dividerThickness];
	NSRect leftRect  = [[[sender subviews] objectAtIndex:0] frame];
	NSRect rightRect = [[[sender subviews] objectAtIndex:1] frame];
	NSRect newFrame  = [sender frame];
 
	leftRect.size.height = newFrame.size.height;
	leftRect.origin = NSMakePoint(0, 0);
	rightRect.size.width = newFrame.size.width - leftRect.size.width
	- dividerThickness;
	rightRect.size.height = newFrame.size.height;
	rightRect.origin.x = leftRect.size.width + dividerThickness;
 
	[[[sender subviews] objectAtIndex:0] setFrame:leftRect];
	[[[sender subviews] objectAtIndex:1] setFrame:rightRect];
}

As nearly every component can have a delegate defined which is triggered at certain actions, this one is triggered on resizing the split view. Simply, the old size of the left side is taken and kept, while the new size of the right side will be passed through.

Now going to fill this stuff with life!

Comment » | Macintosh, Programmieren

Handling touch events in Java on Mac OS X

Oktober 30th, 2010 — 12:58pm

Two days ago I discovered that Apple has implemented multi touch support with the Java update 2 for Snow Leopard and update 7 for Leopard into the Java API. Immediately I had to play with it and have written following little sample application. Further I’ve discovered that Apple also implemented support to detect horizontal scrolling, by abusing the shift modifier on MouseWheelEvents. It is quit fun to use and I have the idea of an MultiTouch Tetris (“Touchris”) floating around in my head ;)

package net.saraarauhito.gesturetest;
 
import com.apple.eawt.event.GestureUtilities;
import com.apple.eawt.event.MagnificationEvent;
import com.apple.eawt.event.MagnificationListener;
import com.apple.eawt.event.RotationEvent;
import com.apple.eawt.event.RotationListener;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
 
/**
 *
 * @author Jan-Peter Zurek
 */
public class Gesturetest {
 
    public static JFrame f;
    public static double rot = 0;
    public static Rectangle r = new Rectangle(125, 125, 50, 50);
    public static BufferedImage img;
 
    public static void main(String[] args) throws Exception {
        // Put your own image here
        img = ImageIO.read(new File("your_image.jpg"));
 
        SwingUtilities.invokeLater(new Runnable() {
                public void run() {
            f = new JFrame();
            f.setSize(300, 300);
            JPanel p = new JPanel();
            p.setSize(300, 300);
            f.add(p);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            f.createBufferStrategy(2);
 
            f.addMouseWheelListener(new MouseWheelListener() {
 
                /* Apple added support for horizontal scrolling by
                 * using the shift modifier
                 */
                public void mouseWheelMoved(MouseWheelEvent e) {
                    if(!e.isShiftDown()) {
                        if(e.getWheelRotation() < 0)                             
                            r.y -= 2;
                         if(e.getWheelRotation() > 0)
                            r.y += 2;
                    } else {
                        if(e.getWheelRotation() < 0)
                             r.x -= 2;
                         if(e.getWheelRotation() > 0)
                            r.x += 2;
                    }
 
                    draw();
                }
 
            });
 
            GestureUtilities.addGestureListenerTo(p, new MagnificationListener() {
 
                public void magnify(MagnificationEvent e) {
                    if(e.getMagnification() > 0) {
                        r.setBounds((int)r.getX() - 1, (int)r.getY() - 1,
                                (int)r.getWidth() + 2, (int)r.getHeight() + 2);
                    } else if (e.getMagnification() < 0) {
                         r.setBounds((int)r.getX() + 1, (int)r.getY() + 1,
                                 (int)r.getWidth() -2, (int)r.getHeight() - 2);
                     }
                     draw();
                 }
             });
             GestureUtilities.addGestureListenerTo(p, new RotationListener() {
                     public void rotate(RotationEvent e) {
                         if(e.getRotation() > 0)
                            rot -= 2;
                        if(e.getRotation() < 0)
                            rot += 2;
 
                        draw();
                    }
                });
            }
        });
    }
 
    private static void draw() {
        Graphics2D g = (Graphics2D) f.getGraphics();
        int mx = r.x + (r.width / 2);
        int my = r.y + (r.height / 2);
        g.clearRect(0, 0, 300, 300)
        g.rotate(rot / 100, mx, my);
        g.setColor(Color.red);
        g.drawImage(img, r.x, r.y, r.width, r.height, null);
        g.rotate(-(rot / 100), mx, my);
        g.dispose();
    }
}

Use rotation and zoom gesture to rotate and zoom the picture and move it with two fingers around the window.

Comment » | Java, Macintosh, Programmieren

jResizer for Mac released

Oktober 25th, 2010 — 10:32pm

Today I publish my first application for OS X, called jResizer. Recently I had to resize some images and stumbled upon the fact that the preview.app of OS X doesn’t offer any option to select the sampling mode for resizing an image like billinear or bicubic. Even the famous pixelmator doesn’t offer this option.

As I’ve recently pushed my Java knowledge a little, I decided to write a small, fully OS X integrated, Java application over the weekend for easy resizing pictures and the possibility to select between the different sampling modes.

You can use drag and drop to drop an image into the app or just press Command-O or the choose button to select an image. Change the resolution, press save, save as, command-s or shift-command-s and you will find your image saved as a .png file.

I’m not quit sure, but I believe that my App will require that you have the latest Java update from Apple installed.

For future releases I plan to ingrate several file formats for saving, unit selection (pixel/cm/inch) and batch resizing.

I want to thank Kenneth Orr from Exploding Pixels for his great work on MacWidgets, which I’ve slightly modified for my use.

jResizer Download

Comment » | Macintosh, Programmieren

jPong PreAlpha Release!

August 2nd, 2010 — 11:15pm

Da wir das nächste Jahr an der Berufsschule beginnen werden, Java zu lernen, dachte ich, dass ich gut bersten wäre, meine Kenntnisse darin wieder etwas aufzufrischen. Nach ca. 1 Tag experimentieren mit NetBeans und dem JDK ist dabei nun jPong, ein super simpler Pong Klon in Java entstanden, der aber durchaus authentisch daher kommt ;)

Wer sich als Alpha-Tester bereit erklären möchte, kann das Spiel hier laden. Vorausgesetzt wird das aktuelle JRE. Das Spiel sollte unter Linux, Windows und Mac OS X laufen!

Der rechte Spieler wird über die Pfeiltasten, der Linke über die Tasten W und S gesteuert.
Für die nächsten Versionen sind noch ein vernünftiger GameOver Screen und eine KI geplant.

Viel Spaß beim testen :)

Comment » | Programmieren

Objectiv-C lieben und hassen lernen

Februar 7th, 2010 — 10:09am

Seit ca. 1 1/2 Wochen habe ich mich endlich dazu aufraffen können, mir ein Buch zu schnappen, um mich mit Objectiv-C und CoCoa auf dem Mac zu befassen. Angeregt durch den Podcast “xcode von NULL auf einhundert” kaufte ich mir das Buch “CoCoa Programming for Mac OS X” von Aaron Hillegass – und ich bin begeistert. Dieses Buch ist das Beste, was ich bisher gelesen habe um eine Programmiersprache zu lernen. Als einen alten ANSI C Hasen, ist das Buch genau richtige für mich. Für Menschen ohne C Erfahrung dürfte das Buch jedoch noch sieben Siegel besitzen, die es gilt aufzubrechen. Hier empfehle ich ein Buch der Leibnitz Universität Hannover, mit dem Titel “Die Programmiersprache C. Ein Nachschlagewerk“. Wer die Chance hat, dieses Buch an seiner Universität erwerben zu können, sollte die geschätzten 5€ ruhig investieren.

Um auf meine Erfahrungen mit Objectiv-C zurückzukommen, da bin ich derzeit noch gespaltener Meinung. In manchen Punkten finde ich, dass die Sprache sehr schön zu lesen und zu schreiben ist, andererseits herrscht an manchen Stellen ein recht hoher Schreibaufwand, mit einem nicht immer ganz einheitlichen Syntax. Das hat Microsoft mit C#, meiner Meinung nach, besser hinbekommen. Aber ich werde weiter in diesem Bereich aktiv lernen und demnächst hoffentlich anfangen, die eine oder andere kleine Applikation für Mac OS X und das iPhone zu schreiben ;)

Comment » | Programmieren

Back to top