Posted by Jacob von Eyben on December 30th, 2011
It is pretty easy to create a drop shadow or immerse effect like this in iOS.
Here is two static helper methods I created to do the trick.
The first method is capable of dropping a shadow from one view onto another:
+ (void)dropColor:(UIColor *)dropColor from:(UIView *)dropFromView onto:(UIView *)toView x:(CGFloat)x y:(CGFloat)y {
CGFloat cornerRadius = [[dropFromView layer] cornerRadius];
UIView *shadow = [[[UIView alloc] initWithFrame:dropFromView.frame] autorelease];
[[shadow layer] setCornerRadius:cornerRadius];
CGRect dropRect = dropFromView.frame;
shadow.frame = CGRectMake(dropRect.origin.x + x, dropRect.origin.y + y, dropRect.size.width, dropRect.size.height);
[shadow setBackgroundColor:dropColor];
[toView insertSubview:shadow belowSubview:dropFromView];
}
The second takes advantage of the first and creates an effect that makes it looks like the first view is immersed into the other:
+ (void)immerse:(UIView *)immerseView into:(UIView *)toView depth:(CGFloat)depth {
CGFloat x = 0.7;
CGFloat y = 1.4;
[UIUtil dropColor:[UIColor darkGrayColor] from:immerseView onto:toView x:-1 * x * depth y:-1 * y * depth];
[UIUtil dropColor:[UIColor whiteColor] from:immerseView onto:toView x:x*depth y:y*depth];
}
The following effect can be added to a tableview by doing this:
- (void)viewDidLoad {
[super viewDidLoad];
[[_tableView layer] setCornerRadius:5];
[UIUtil immerse:_tableView into:self.view depth:1.5];
}

Posted in ios, iphone, mac, objective-c | No Comments »
Posted by Jacob von Eyben on September 18th, 2011
I have seen a couple of iPhone apps using an UITabBarController having an arrow showing just above the selected UITabBarItem as an extra visual pointer to the current visible view. At the same time the arrow moves animated between the items as the user selects them.
I decided to try implement the same effect and I have shared my solution here.
The solution is made generic enough to handle any number of UITabBarItems in the UITabBarController and basically what it does is:
- In the viewDidAppear selector, the arrow is places above the first element. This is done by calculating the size and location (also known as the CGRect) of the first UITabBarItem. Then a new UIImageView is created and positioned centered and above the UITabBarItem. Again some math is used to find the offset to use for the newly created UIImageView
- In the didSelectItem a transition is used to animate the movement of the arrow between the items as they are selected.
My CustomUITabBarController.h and CustomUITabBarController.m files looks like this:
@interface CustomUITabBarController : UITabBarController {
@private
UIImageView *_imageView;
}
@end
The actual implementation looks like follows:
@interface CustomUITabBarController ()
@property(nonatomic, retain) UIImageView *imageView;
@end
@implementation CustomUITabBarController
@synthesize imageView = _imageView;
- (CGRect) rectForItem:(UITabBarItem *)item {
NSUInteger itemsInTabBar = [self.tabBar.items count];
CGSize itemSize = CGSizeMake(self.tabBar.frame.size.width / itemsInTabBar, self.tabBar.frame.size.height);
//find current selected item index
int currentIndexSelected = 0;
//if the item is nil, we keep the index at zero (selects the first element)
if (item != nil) {
for (int i = 0; i < itemsInTabBar; i++) {
UITabBarItem *currentItem = [self.tabBar.items objectAtIndex:(NSUInteger) i];
if (currentItem == item) {
currentIndexSelected = i;
}
}
}
//construct the rect that defines the current selected item
return CGRectMake(lrint(currentIndexSelected * itemSize.width), itemSize.height, itemSize.width, itemSize.height);
}
- (CGRect)getRectForImage:(UIImage *)markerImage andTabPosition:(CGRect)itemRect {
CGFloat windowHeight = [UIScreen mainScreen].bounds.size.height;
CGRect markerImageRect = CGRectMake(itemRect.origin.x + lrint(itemRect.size.width / 2) - lrint(markerImage.size.width / 2), windowHeight - itemRect.size.height - markerImage.size.height, markerImage.size.width, markerImage.size.height);
return markerImageRect;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated]; //To change the template use AppCode | Preferences | File Templates.
UIImage * markerImage = [UIImage imageNamed:@"tabMarker.png"];
CGRect firstItemRect = [self rectForItem:nil];
CGRect markerImageRect = [self getRectForImage:markerImage andTabPosition:firstItemRect];
_imageView = [[UIImageView alloc] initWithFrame:markerImageRect];
_imageView.image = markerImage;
[self.view addSubview:_imageView];
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
CGRect selectedItemRect = [self rectForItem:item];
[UIView beginAnimations:@"move tabMarker" context:nil];
[UIView setAnimationDuration:0.3f];
_imageView.transform = CGAffineTransformMakeTranslation(selectedItemRect.origin.x,0);
[UIView commitAnimations];
}
...
@end
Posted in how to, ios, iphone, mac, objective-c | No Comments »
Posted by Jacob von Eyben on November 12th, 2009
If you need to log sql statements using hibernate you can turn debug on for the org.hibernate.sql logger.
That will log all sql statement, but the actual parameter values will not be logged.
To log the values bound to the hibernate prepared statements, you can turn on trace for the org.hibernate.type logger.
Unfortunately (apparently because of perfomance) the value of the org.hibernate.type logger is evaulated once in a static block, and cached, see: EnumType.java.
That prevents you from turning the log on and off during runtime using a simple jsp page like the log4jAdmin.jsp. Note that if it were possible you still had to add trace to the page as debug is currently the lowest value.
Of course there must be a reason why the hibernate implementation are caching the value of the org.hibernate.type logger, but I believe it is still valuable to be able to turn on sql logging with parameters at runtime.
For that purpose I came across the logDriver. A simple database driver written by Ryan Bloom, that is wrapping an existing jdbc driver.
To use the logdriver all you have to do is set the driver and connection url as follows:
driver:net.rkbloom.logdriver.LogDriver
url:jdbc:log_real_driver_class:real_jdbc_connection_url
Now you can turn on logging by setting the net.rkbloom.logdriver logger to debug.
Posted in how to, java | 1 Comment »
Posted by Jacob von Eyben on June 5th, 2009
Yesterday I created a appengine project testing the JPA/Spring/Wicket stack.
This was created using the build.xml file found in the appengine documentation. It all worked fine, but I would like to build my project using maven so I started looking for a good maven plugin.
I found this blog talking about what features a good plugin should contain and a guy from the kindleit company claiming that they actually had implemented a maven-gae-plugin capable of executing most of these tasks.
Unfortunately I ran into several problems using this plugin, hence I have created an issue.
Untill these tasks in the issue has been fixed I would like to use another plugin.
Can anybody guide me in the direction of a more stable plugin?
Posted in java, maven | 1 Comment »
Posted by Jacob von Eyben on October 24th, 2008
Everytime I have a new machine or a new ssh access to setup I forgot how to configure the access so I don’t have to type the username each time (if I login with a different user).
At the same time I would like to use a private rsa key. So here goes a note to myself and other scatter brains
Instead of always have to type username and password like this:
[jeyben@machine ~]$ ssh username@www.ancientprogramming.com
Password:
Last login: Fri Oct 24 16:31:03 2008 from somewhere
[username@servername ~]$
I would like to just do the following:
[jeyben@machine ~]$ ssh ancientprogramming
Last login: Fri Oct 24 16:31:03 2008 from somewhere
[username@servername ~]$
Create and use a public/private key pair
Client
$ ssh-keygen -t rsa
$ scp ~/.ssh/id_rsa.pub www.ancientprogramming.com:~
Server
$ cat ~/id_rsa.pub >> .ssh/authorized_keys
Modify .ssh/config
Host ancientprogramming
User <username>
Port 22
HostName www.ancientprogramming.com
LocalForward 3307 localhost:3306 (setup a localforward for the default mysql port)
Posted in how to, ssh | No Comments »
Posted by Jacob von Eyben on October 16th, 2008
Support for primitive datatypes is added to the latest 1.2.1 release of fixedformat4j. I would like to thank Marcos Lois Bermúdez for contributing with this extension. The latest release can be downloaded here.
The same 1.2.1 release also fixed the bug that made it impossible to use annotate and format static nested classes and inner classes
The complete changelist can be found on the project website.
In a few days the release should be available from ibiblio.
I encourage all users of fixedformat4j to contribute or create issues if they find a bug or would like new features to be added.
Posted in fixedformat4j, java | No Comments »
Posted by Jacob von Eyben on June 27th, 2008
Mac OS X doesn’t remount network drives when booted. You have to do this yourselves.
You can easily automate this by creating an application using the automator and add it to your login items.

You automator script should contain two items:
- Get Specified Servers
- Connect to Servers
Save the script as an application and put it into login items for your user account. This will execute your small application each time you login and you should be reconnected to your NAS on startup.
Posted in how to, mac | No Comments »
Posted by Jacob von Eyben on June 12th, 2008
This evening I released a new version of fixedformat4j containing improved error reporting when failing to parse data using the FixedFormatManager.
The lack of good error reporting was a bit of a pain. It was not easy to see where in the parsing failed and it was not possible to get a complete list of format instructions.
A new ParseException is now thrown which contains the nessesary information.
See example of the new and improved stacktrace:
com.ancientprogramming.fixedformat4j.format.ParseException: failed to parse 'barfooba' at offset 16 as java.util.Date from 'foobarfoobarfoobarfoobar'. Got format instructions from com.ancientprogramming.fixedformat4j.format.impl.MyRecord.getDateData. See details{FormatContext{offset=16, dataType=java.util.Date, formatter=com.ancientprogramming.fixedformat4j.format.impl.ByTypeFormatter}, FormatInstructions{length=8, alignment=LEFT, paddingChar=' ', fixedFormatPatternData=FixedFormatPatternData{pattern='yyyyMMdd'}, fixedFormatBooleanData=FixedFormatBooleanData{trueValue='T', falseValue='F'}, fixedFormatNumberData=FixedFormatNumberData{signing=NOSIGN, positiveSign='+', negativeSign='-'}, fixedFormatDecimalData=FixedFormatDecimalData{decimals=2, useDecimalDelimiter=false, decimalDelimiter='.'}}}
at com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.readDataAccordingFieldAnnotation(FixedFormatManagerImpl.java:179)
at com.ancientprogramming.fixedformat4j.format.impl.FixedFormatManagerImpl.load(FixedFormatManagerImpl.java:70)
Feel free to download the latest version and take a look at the changelist.
Posted in java | No Comments »
Posted by Jacob von Eyben on June 5th, 2008
Many maven projects uses the maven site plugin to generate there documentation.
The maven-site-plugin uses the doxia to let authors write xdoc, apt and fml documents as the source for there project documentation. These written documents is processed by doxia to generate html and merged into the complete project site by the maven-site-plugin.
I found doxia and especially the apt language somehow lacking in functionality. I would like to use the syntaxhighlighter to be able to highlight code examples on the fixedformat4j project.
Doxia comes out-of-the-box with a small bunch of macros and you have the ability to write custom macros as well.
Custom macro
I wrote a simple macro based on the core snippet macro:
pom.xml:
org.apache.maven.doxia
doxia-modules
1.0-alpha-11
4.0.0
com.ancientprogramming.maven.doxia
doxia-module-syntaxhighlighter
1.0-alpha-11
Doxia :: syntaxhighlighter
org.codehaus.plexus
plexus-maven-plugin
descriptor
Changes to the snippet plugin:
...
public void execute(Sink sink, MacroRequest request)
throws MacroExecutionException {
System.out.println("ancientprogramming - running execute");
String id = (String) request.getParameter("id");
required(id, "id");
String urlParam = (String) request.getParameter("url");
String fileParam = (String) request.getParameter("file");
String codeParam = (String) request.getParameter("code");
required(codeParam, "code");
URL url;
if (!StringUtils.isEmpty(urlParam)) {
try {
url = new URL(urlParam);
}
catch (MalformedURLException e) {
throw new IllegalArgumentException(urlParam + " is a malformed URL");
}
} else if (!StringUtils.isEmpty(fileParam)) {
File f = new File(fileParam);
if (!f.isAbsolute()) {
f = new File(request.getBasedir(), fileParam);
}
try {
url = f.toURL();
}
catch (MalformedURLException e) {
throw new IllegalArgumentException(urlParam + " is a malformed URL");
}
} else {
throw new IllegalArgumentException("Either the 'url' or the 'file' param has to be given.");
}
StringBuffer snippet;
try {
snippet = getSnippet(url, id);
}
catch (IOException e) {
throw new MacroExecutionException("Error reading snippet", e);
}
sink.rawText("... syntaxhighlighter prefix ...");
sink.rawText(snippet.toString());
sink.rawText("... syntaxhighlighter postfix ...");
}
...
Note: wordpress obfuscates the above code where I wrote the syntax hightlighter pre and post fix. You can see what you actually should write at the syntaxhighligther project.
Use custom macro
To be able to use the macro you have to add your macro as dependency to the maven-site-plugin:
org.apache.maven.plugins
maven-site-plugin
${basedir}/src/site
src/site/fixedformat4j-template.vm
com.ancientprogramming.maven.doxia
doxia-module-syntaxhighlighter
1.0-alpha-11
Now you can use the macro by writing the following in your apt files:
%{code-snippet|id=basicusage|code=java|file=../../BasicUsageRecord.java}
Change your site template
Before the the source can be highlighted in your documentation you should add the syntaxhighlighter javascript and stylesheets to your template.
See how to change your template here.
Posted in how to, java, maven | No Comments »
Posted by Jacob von Eyben on June 5th, 2008
Today I found fixedformat4j was obtained at sonarsoftware and it was exciting to see that it scored pretty well compared to some other very well known opensource projects like the commons series, some of the spring module and even the Apache Maven project.
I didn’t know sonar before today. They describe them as:
Sonar is an entreprise quality control tool, distributed under the terms of the GNU LGPL. Its basic purpose is to join existing continuous integration tools to place Java development projects under quality control.
Even though the metrics at sonar doesn’t draw the complete picture on how good or mature a project is, it still gives a hint.
Posted in fixedformat4j, java | No Comments »