Red Squirrel Reflections
Dave Hoover explores the psychology of software development

Dave Hoover

All [Atom]
Craftsmanship [Atom]
Dynamic [Atom]
Intersection [Atom]
Learning [Atom]
Links [Atom]
Polyglot [Atom]
Projects [Atom]
XP [Atom]
Old Blog

Obtivian Blogs

Andy Maleh
Colin Harris
Fred Polgardy
Jim Breen
Kevin Taylor
Todd Webb
Turner King
Tyler Jennings


March 2009 (1)
January 2009 (1)
December 2008 (1)
October 2008 (3)
September 2008 (1)
June 2008 (4)
April 2008 (3)
March 2008 (1)
February 2008 (1)
August 2007 (1)
July 2007 (1)
June 2007 (1)
May 2007 (4)
April 2007 (3)
March 2007 (5)
February 2007 (6)
January 2007 (6)
December 2006 (10)
November 2006 (5)
October 2006 (8)
September 2006 (8)
August 2006 (5)
July 2006 (12)
June 2006 (7)
May 2006 (5)
April 2006 (5)
March 2006 (4)
February 2006 (2)
January 2006 (5)
December 2005 (5)
November 2005 (3)
October 2005 (3)
September 2005 (6)
August 2005 (4)
July 2005 (7)
June 2005 (14)
May 2005 (6)
April 2005 (8)
March 2005 (9)
February 2005 (11)
January 2005 (16)
Old Archives


Fri, 21 Jan 2005

Quote Manager Project -- Day 5

An ongoing pet project blog...

OK, I've hacked together an interface that has the fields I need...

And I just did a bit of refactoring to remove most of the duplication. Checking in...

This is a passive application for the moment. I'd like to provide it with an object that it can store the quote data in so that when I click the "Add" button, this object is populated with data. Perhaps this will be called a Quote? I'll just have it be an immutable value object for now...

package com.redsquirrel.quotes.model;

import java.util.Collection;

public class Quote {
    public final String text;
    public final Source source;
    public final Collection<Person> authors;
    public final Person quoter;

    public Quote(String text, Source source, Collection<Person> authors, Person quoter) {
        this.text = text;
        this.source = source;
        this.authors = authors;
        this.quoter = quoter;

package com.redsquirrel.quotes.model;

public class Source {
    public final String title;
    public final String page;
    public final String isbn;

    public Source(String title, String page, String isbn) {
        this.title = title; = page;
        this.isbn = isbn;

package com.redsquirrel.quotes.model;

public class Person {
    public final String firstName;
    public final String lastName;
    public final String url;

    public Person(String firstName, String lastName, String url) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.url = url;
This is kinda boring, which probably means I'm doing something wrong...or I am about to. I wish I had a pair programmer to reassure (or warn) me.

So now that I have my immutable value objects, I see that I'm going to be creating these objects rather than populating previously existing ones. Not sure if that's bad or good. I'm really tired right now.

OK, I just realized one of the things I've overlooked. I've only given the user the ability to enter one author per quote! Yikes, I'll have to deal with that later. I want to keep making progress...

OK, I guess this is progress. I've extracted the JButton and all of the JTextComponents into private final fields. I extracted the layout code to a private method. Finally, I added a anonymous ActionListener. Here's what it looks like (sans layout code)...

package com.redsquirrel.quotes.gui;

import com.redsquirrel.quotes.model.Quote;
import com.redsquirrel.quotes.model.Source;
import com.redsquirrel.quotes.model.Person;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JComponent;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Collection;
import java.util.ArrayList;

public class QuoteManagerPanel extends JPanel {
    private final JTextArea quoteText = new JTextArea(3, 15);
    private final JButton addButton = new JButton("Add");
    private final JTextField source = new JTextField(15);
    private final JTextField isbn = new JTextField(15);
    private final JTextField page = new JTextField(5);
    private final JTextField authorUrl = new JTextField(15);
    private final JTextField quoterUrl = new JTextField(15);
    private final JTextField authorFirstName = new JTextField(7);
    private final JTextField authorLastName = new JTextField(7);
    private final JTextField quoterFirstName = new JTextField(7);
    private final JTextField quoterLastName = new JTextField(7);

    public QuoteManagerPanel() {
        setLayout(new GridBagLayout());

        addButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Source source = new Source(QuoteManagerPanel.this.source.getText(), page.getText(), isbn.getText());
                Collection authors = new ArrayList();
                authors.add(new Person(authorFirstName.getText(), authorLastName.getText(), authorUrl.getText()));
                Person quoter = new Person(quoterFirstName.getText(), quoterLastName.getText(), quoterUrl.getText());
                new Quote(quoteText.getText(), source, authors, quoter);


    private void layoutForm() {
I have created a Quote! How sad that I don't know what to do with it. And damn that's some tedious code, just mapping GUI components to structs. As a developer, I'm not happy that there are no tests. And as a customer, I'm not happy that I can only input one author per quote. Before I figure out what to do with our freshly baked Quote, I need to figure out an acceptable solution to the N authors problem.

Checking in...

To solve the N authors problem, I will peruse the quotes file, find the quote with the greatest number of authors, and provide that many author fields. Let's appears that I quote at least two books that have three authors. I quote the Gang of Four, but refer to the authors in bulk, not individually. I'll update the GUI code to handle up to three authors...

[/projects/quotes] permanent link

powered by blosxom