~ubuntu-branches/ubuntu/natty/aspectj/natty

« back to all changes in this revision

Viewing changes to org.aspectj/modules/docs/sandbox/ubc-design-patterns/src/ca/ubc/cs/spl/aspectPatterns/examples/factoryMethod/java/GUIComponentCreator.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2009-10-04 16:37:23 UTC
  • mfrom: (1.1.3 upstream) (3.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091004163723-ck4y7j7fhjxskkie
Tags: 1.6.6+dfsg-1
* New upstream release.
  - Update 02_use_gjdoc.diff patch
* Update my email address

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package ca.ubc.cs.spl.aspectPatterns.examples.factoryMethod.java;
2
 
 
3
 
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
4
 
 *
5
 
 * This file is part of the design patterns project at UBC
6
 
 *
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/.
11
 
 *
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
15
 
 * License.
16
 
 *
17
 
 * The Original Code is ca.ubc.cs.spl.aspectPatterns.
18
 
 * 
19
 
 * For more details and the latest version of this code, please see:
20
 
 * http://www.cs.ubc.ca/labs/spl/projects/aodps.html
21
 
 *
22
 
 * Contributor(s):   
23
 
 */
24
 
 
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;
31
 
 
32
 
/**
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> 
36
 
 *
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
40
 
 * GUI. 
41
 
 *
42
 
 * @author  Jan Hannemann
43
 
 * @author  Gregor Kiczales
44
 
 * @version 1.1, 02/11/04
45
 
 * 
46
 
 * @see ButtonCreator
47
 
 * @see LabelCreator
48
 
 */ 
49
 
 
50
 
public abstract class GUIComponentCreator {
51
 
    
52
 
    /**
53
 
     * The factory method to be concretized by subclasses.
54
 
     *
55
 
     * @returns the created <i>ConcreteProduct</i>
56
 
     */
57
 
 
58
 
    public abstract JComponent createComponent(); 
59
 
    
60
 
    /**
61
 
     * Another factory method to create a title for the GUI frame created
62
 
     * by this class.
63
 
     *
64
 
     * @returns the title for the GUI frame
65
 
     */
66
 
     
67
 
    public abstract String getTitle(); 
68
 
 
69
 
    /** 
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.
73
 
     */
74
 
     
75
 
    private static Point lastFrameLocation = new Point(0, 0);
76
 
 
77
 
    /** 
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>. 
81
 
     */
82
 
     
83
 
    public final void showFrame() {
84
 
        JFrame frame = new JFrame(getTitle());
85
 
        
86
 
                frame.addWindowListener(new WindowAdapter() {
87
 
                        public void windowClosing(WindowEvent e) {System.exit(0);}
88
 
                });
89
 
                    
90
 
                JPanel panel = new JPanel();
91
 
        
92
 
                panel.add(createComponent());
93
 
                
94
 
                frame.getContentPane().add(panel);
95
 
                frame.pack();    
96
 
                frame.setLocation(lastFrameLocation);
97
 
                lastFrameLocation.translate(75, 75);
98
 
                frame.setVisible(true);  
99
 
    }
100
 
}               
101
 
 
102
 
    
 
 
b'\\ No newline at end of file'