Thursday, September 23, 2010

Break Time with Web Pics


My latest version of Break Time has contextual Web Pics. You put in a theme for pictures you would like to see, and it pings Yahoo Picture search and grabs a random picture.

In this example, you can see some of the possibilities it came up with when I prompted it with mountain.

It aint perfect yet because you have to modify the config file in the installation directory for it to work, but still, I think it looks rather nice.

Why not download it from here and see what you think? You need to be taking breaks every 15 minutes while you are at the computer, Break Time makes sure that you do!

Tuesday, March 30, 2010

A cooler Easter Break Time....

So, I finished a new version that is kind of fun. instead of a blah window, it has a cute little set of easter bunnies. But if you start it up, in 15 minutes, it will remind you to take a break. I even built an installer for it. You can access it here:

http://www.fishnetgames.net

Another cool thing I like about it is that it gives you the minutes left until the break in the status bar itself.

Give it a try. I promise, no spyware. Then email me to tell me if you think it could be useful to give you much needed breaks!

Thursday, March 18, 2010

Converting My Swing Break Reminder to Groovy: Part 1



I have ergonomic muscle strain issues. Experts recommend that you take breaks every 15 minutes to alleviate that pain, and give your muscles a rest. So, a long time ago, I wrote a small java app that would remind me to take a break every fifteen minutes. Here is the code for it:

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowStateListener;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.Locale;
import java.util.ArrayList;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import com.ocpsoft.pretty.time.BasicTimeFormat;
import com.ocpsoft.pretty.time.TimeFormat;
import com.ocpsoft.pretty.time.TimeUnit;
import com.ocpsoft.pretty.time.PrettyTime;
import com.ocpsoft.pretty.time.units.Second;
import com.ocpsoft.pretty.time.units.Minute;

/**
* Created by IntelliJ IDEA.
* User: BrentFisher
* Date: Aug 18, 2009
* Time: 2:07:18 PM
* To change this template use File | Settings | File Templates.
*/
public class TimeReminderWindow {

public static void main(String [] args){
TimeReminderWindow trw = new TimeReminderWindow();
trw.start();

}

long timeToWait = 15 * 60 * 1000;// 15 minutes
long lastUpdate = System.currentTimeMillis();

private void start() {
final JFrame frame = new JFrame("Time Reminder");
final JButton button = new JButton("Click here to reset");
final PrettyTime p = new PrettyTime();

frame.getContentPane().add(new JLabel("Take a break",SwingConstants.CENTER), BorderLayout.CENTER);
frame.getContentPane().add(button, BorderLayout.NORTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setBounds(screenSize.width/2 - (640/2),
screenSize.height/2 - (480/2),640,480);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
lastUpdate = System.currentTimeMillis();
frame.setState(JFrame.ICONIFIED);
}
});
Timer timer = new Timer(1000, new ActionListener(){
public void actionPerformed(ActionEvent e) {
long now = System.currentTimeMillis();
if(now - lastUpdate > timeToWait){
frame.setState(JFrame.NORMAL);
frame.toFront();
}
frame.setTitle("Break " + p.format(new Date(lastUpdate + timeToWait)));

}
});
lastUpdate = System.currentTimeMillis();
timer.start();
// frame.pack();
frame.setVisible(true);
}
}


The Book Groovy in Action claims that writing Swing code in Java is three to four times longer. So, I'm gonna put that to the test in this article. Plus, I've always wanted to put in some helpful ergonomic reminders in too, so I'll see if I can do that.

Here is the code, and here is the reminder window:

import javax.swing.*;
import java.awt.*;
import java.util.Date;
import com.ocpsoft.pretty.time.PrettyTime;
import groovy.swing.SwingBuilder;
import java.awt.BorderLayout as BL
import java.awt.event.ActionListener
import java.awt.event.ActionEvent

long timeToWait = 15 * 60 * 1000;// 15 minutes
long lastUpdate = System.currentTimeMillis();
def swing = new SwingBuilder()
final PrettyTime p = new PrettyTime();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
def button1 = swing.button( 'Click here to reset')

def frame = swing.frame(title: 'Time Reminder',
defaultCloseOperation: JFrame.EXIT_ON_CLOSE,
bounds: new Rectangle((int) screenSize.width / 2 - (640 / 2),
(int) screenSize.height / 2 - (480 / 2), 640, 480)) {
panel(layout: new BL()) {
widget(button1,constraints: BL.NORTH)
label constraints: BL.CENTER, horizontalAlignment: SwingConstants.CENTER, 'Take a break'
}
}
button1.actionPerformed = {
lastUpdate = System.currentTimeMillis();
frame.setState(JFrame.ICONIFIED);
}

Timer timer = new Timer(1000, {ActionEvent e ->
long now = System.currentTimeMillis();
if (now - lastUpdate > timeToWait) {
frame.setState(JFrame.NORMAL);
frame.toFront();
}
frame.setTitle("Break ${p.format(new Date(lastUpdate + timeToWait))}");
} as ActionListener);

lastUpdate = System.currentTimeMillis();
timer.start();
// frame.pack();
frame.setVisible(true);



But I have to say, the whole part of getting the button registered for action performed was pretty tricky and I spent more than half an hour doing it. The code was reduced to 43 lines from 71, but the builder part was actually trickier than I thought it would be, and both use 15 lines of code. So, I'm not completely sold on its usefulness.

Part II will be to query Google for some ergonomic images, and automatically put those on the screen. Stay tuned...

Monday, January 18, 2010

Giving Aid to Haiti

OK, OK, I know that only believers are supposed to be charitable, and I've tried to resist the temptation to give in to my humanity. As much as I have struggled to resist the temptation, I could no longer resist. I have donated to the international Red Cross and Doctors without borders.

Won't you take a minute to help the Red Cross or Doctors without borders too?

Follow the link on this page, or choose a different route. There are so many ways to get your money there.

Cheers!

in reference to: Skeptic » eSkeptic » Sunday, January 17th, 2010 (view on Google Sidewiki)

Wednesday, January 13, 2010

Groovy business rules

I love this way to make the DSL presented here. I just wish I could find more ways to put it into a sandbox, besides the heavy hand of the java security sand box.

in reference to: Practical Groovy DSL (view on Google Sidewiki)

Great post on showing code in blogger

Thanks Vivian for showing me how to post code on blogspot. As a burgeoning code blogger, this really helps out!

in reference to: Vivian's Tech Blog: How to post source code in blogspot.com (view on Google Sidewiki)

Creating a Groovy DSL for Financial Product Fee Schedules


I'm currently working on a project that requires a variable fee schedule.
E.g.

Product Name Category Feature Value Date Range Functional Setting Applicability
General ACH Generation






ACH Generation Fees ACH Transaction Fee 1.00 Account Open Date Account Closed Date 0 to 10 transactions


ACH Transaction Fee .50 Account Open Date Account Closed Date 10 or more transactions

Credit Card Generation Fees CC Transaction Fee 1.00 Account Open Date Account Closed Date 0 to 10 transactions


CC Transaction Fee .50 Account Open Date Account Closed Date 10 or more transactions

I need a way to specify the date range that would include things such as account open date and plus 3 months and transaction ranges. Groovy DSL seems like the perfect fit. See Guillame Laforge's example here.

I came up with the following:

package com.aps.utils

import com.aps.util.DateUtil
import org.codehaus.groovy.runtime.TimeCategory


class ProductCatalogDSLTests extends GroovyTestCase {


def account

void setUp() {
account = new Account(from: DateUtil.sdf.parse("01-01-2010"))
}

void testAccountOpenedDate() {
def rule = 'transactionDate > account.from'
def binding = new Binding()
binding.account = account
def shell = new GroovyShell(binding)
def date = DateUtil.sdf.parse('01-10-2010')
binding.transactionDate = date
assert shell.evaluate(rule)
binding.transactionDate = DateUtil.sdf.parse('05-10-2009')
assertFalse shell.evaluate(rule)

}

void testAccountOpenedDate_plus3() {
def rule = 'transactionDate < account.from+6.months'
def binding = new Binding()
binding.account = account
def shell = new GroovyShell(binding)
def date = DateUtil.sdf.parse('01-10-2010')
binding.transactionDate = date
use(TimeCategory) {
assert shell.evaluate(rule)
binding.transactionDate = DateUtil.sdf.parse('05-10-2010')
assert shell.evaluate(rule)
}
}

void testTransactionMinimum() {
def rule1 = 'account.transactions.size < 10'
def rule2 = 'account.transactions.size >= 10'
def date = DateUtil.sdf.parse('01-10-2010')
0..5.each {
account.transactions << new AccountTransaction(amount: 15.00, postDate: date)
}
def binding = new Binding()
binding.account = account
def shell = new GroovyShell(binding)
binding.transactionDate = date
use(TimeCategory) {
assert shell.evaluate(rule1)
assertFalse shell.evaluate(rule2)
}
}

void testTransactionMinimumThisMonth() {
def rule1 = 'account.transactions.collect{it.postDate.month == transactionDate.month}.size < 10'
def rule2 = 'account.transactions.collect{it.postDate.month == transactionDate.month}.size >= 10'
def date = DateUtil.sdf.parse('01-10-2010')
use(TimeCategory) {
assertEquals 0 , date.month
assertEquals 10 , date.date
assertEquals 2010 - 1900 , date.year
0..5.each {
account.transactions << new AccountTransaction(amount: 15.00, postDate: date)
}
def binding = new Binding()
binding.account = account
def shell = new GroovyShell(binding)
binding.transactionDate = date
assert shell.evaluate(rule1)
assertFalse shell.evaluate(rule2)
}
}
}
class Account {
Date from
Date to
def transactions = []
}
class AccountTransaction {
BigDecimal amount
Date postDate
}

It ended up working well for dynamic business rule selectors.