1
package ca.ubc.cs.spl.aspectPatterns.examples.factoryMethod.java;
3
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
5
* This file is part of the design patterns project at UBC
7
* The contents of this file are subject to the Mozilla Public License
8
* Version 1.1 (the "License"); you may not use this file except in
9
* compliance with the License. You may obtain a copy of the License at
10
* either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
12
* Software distributed under the License is distributed on an "AS IS" basis,
13
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14
* for the specific language governing rights and limitations under the
17
* The Original Code is ca.ubc.cs.spl.aspectPatterns.
19
* For more details and the latest version of this code, please see:
20
* http://www.cs.ubc.ca/labs/spl/projects/aodps.html
25
import javax.swing.JFrame;
26
import javax.swing.JPanel;
27
import javax.swing.JComponent;
28
import java.awt.event.WindowAdapter;
29
import java.awt.event.WindowEvent;
30
import java.awt.Point;
33
* Defines the <i>GUIComponentCreator</i> interface with the
34
* <i>factoryMethod()</i> method signature and the <i>anOperation()</i>
35
* method that uses it. For details, see GoF, page 108.<p>
37
* The factory method is <code>createComponent</code> and it creates
38
* A JComponent (a button or a label, in this case). The <i>anOperation()</i>
39
* method <code>showFrame()</code> uses the factory method to show a small
42
* @author Jan Hannemann
43
* @author Gregor Kiczales
44
* @version 1.1, 02/11/04
50
public abstract class GUIComponentCreator {
53
* The factory method to be concretized by subclasses.
55
* @returns the created <i>ConcreteProduct</i>
58
public abstract JComponent createComponent();
61
* Another factory method to create a title for the GUI frame created
64
* @returns the title for the GUI frame
67
public abstract String getTitle();
70
* the position for the next frame to be created (on the screen). This
71
* variable is used to make sure new frames appear staggered and don't
72
* entirely overlap with existing frames.
75
private static Point lastFrameLocation = new Point(0, 0);
78
* Creates a <code>JFrame</code>, puts the <code>JComponent</code> that
79
* is created by the factory method into it and displays the frame. This
80
* Method also provides a <code>WindowListener</code>.
83
public final void showFrame() {
84
JFrame frame = new JFrame(getTitle());
86
frame.addWindowListener(new WindowAdapter() {
87
public void windowClosing(WindowEvent e) {System.exit(0);}
90
JPanel panel = new JPanel();
92
panel.add(createComponent());
94
frame.getContentPane().add(panel);
96
frame.setLocation(lastFrameLocation);
97
lastFrameLocation.translate(75, 75);
98
frame.setVisible(true);
b'\\ No newline at end of file'