|
Red Squirrel Reflections
Dave Hoover explores the psychology of software development
|
|
Fri, 21 Jan 2005Quote 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
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;
this.page = 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
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
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 see...it 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... |