carfield.com.hk Button.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.mediator.aspectj; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the &quot;License&quot;); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an &quot;AS IS&quot; basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.patterns. * * Contributor(s): */ import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; /** * Basically a JButton with an ActionListener. The listener call * &lt;code&gt;clicked()&lt;/code&gt; when the button gets clicked. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.0, 05/13/02 */ class Button extends JButton { /** * Creates a new &lt;code&gt;Button&lt;/code&gt; object with the provided label. * * @param name the label for the new &lt;code&gt;Button&lt;/code&gt; object */ public Button(String name) { super(name); this.setActionCommand(name); this.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { clicked(); } }); } public void clicked() {} }</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z Label.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.mediator.aspectj; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the &quot;License&quot;); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an &quot;AS IS&quot; basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.patterns. * * Contributor(s): */ import javax.swing.*; /** * Basically a JLabel. On object of this class is be the &lt;i&gt;Mediator&lt;/i&gt;. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.0, 05/13/02 */ public class Label extends JLabel { /** * Creates a new &lt;code&gt;Label&lt;/code&gt; object with the provided string. * * @param s the tag for the new &lt;code&gt;Label&lt;/code&gt; object */ public Label(String s) { super(s); } }</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z Main.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.mediator.aspectj; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the &quot;License&quot;); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an &quot;AS IS&quot; basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.patterns. * * Contributor(s): */ import javax.swing.*; import java.awt.event.*; /** * Implements the driver for the mediator design pattern example.&lt;p&gt; * * Intent: &lt;i&gt;Define an object that encapsulates how a set of objects * interact. Mediator promotes loose coupling by keeping objects from * referring to each other explicitly, and it lets you vary their interaction * independently.&lt;/i&gt;&lt;p&gt; * * Participatng objects are &lt;code&gt;Button&lt;/code&gt;s as &lt;i&gt;Colleague&lt;/i&gt;s, * and a &lt;code&gt;Label&lt;/code&gt; as &lt;i&gt;Mediator&lt;/i&gt;. * * Every time an event of interest (a button click) occurs, the mediating * &lt;code&gt;Label&lt;/code&gt; is updated and it updates the calling button. * * &lt;p&gt;&lt;i&gt;This is the AspectJ version.&lt;/i&gt;&lt;p&gt; * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.0, 05/13/02 * * @see Button * @see Label */ public class Main { static JFrame frame = new JFrame(&quot;Mediator Demo&quot;); static Button button1 = new Button(&quot;Button1&quot;); static Button button2 = new Button(&quot;Button2&quot;); static Label label = new Label (&quot;Click a button!&quot;); /** * Implements the driver for the mediator example. It creates a small * GUI with a label and two buttons. The buttons are &lt;i&gt;Colleague&lt;/i&gt;s, * the label is the &lt;i&gt;Mediator&lt;/i&gt;. * * Each button click causes the mediator to update itself and the * calling button. */ public static void main(String[] args) {; frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }); JPanel panel = new JPanel(); panel.add(label); panel.add(button1); panel.add(button2); frame.getContentPane().add(panel); frame.pack(); frame.setVisible(true); MediatorImplementation.aspectOf().setMediator(button1, label); MediatorImplementation.aspectOf().setMediator(button2, label); } }</TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z MediatorImplementation.java 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">package examples.mediator.aspectj; /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * This file is part of the design patterns project at UBC * * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the &quot;License&quot;); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/. * * Software distributed under the License is distributed on an &quot;AS IS&quot; basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is ca.ubc.cs.spl.patterns. * * Contributor(s): */ import ca.ubc.cs.spl.pattern.library.MediatorProtocol; /** * Concretizes the mediation relationship for &lt;code&gt;Button&lt;/code&gt; (colleague) * and &lt;code&gt;Label&lt;/code&gt; (mediator). button clicks trigger updates. * * @author Jan Hannemann * @author Gregor Kiczales * @version 1.0, 05/13/02 */ public aspect MediatorImplementation extends MediatorProtocol { /** * Assings the &lt;code&gt;Colleague&lt;/code&gt; role to the &lt;code&gt;Button&lt;/code&gt; * class. Roles are modeled as (empty) interfaces. */ declare parents: Button implements Colleague; /** * Assings the &lt;code&gt;Colleague&lt;/code&gt; role to the &lt;code&gt;Label&lt;/code&gt; * class. Roles are modeled as (empty) interfaces. */ declare parents: Label implements Mediator; /** * Defines what changes on Colleagues cause their mediator to be notified * (here: Button clicks) * * @param cs the colleague on which the change occured */ protected pointcut change(Colleague c): (call(void Button.clicked()) &amp;&amp; target(c)); /** * Defines how the &lt;code&gt;Mediator&lt;/code&gt; is to be updated when a change * to a &lt;code&gt;Colleague&lt;/code&gt; occurs. Here, the label's text is set * depending on which button was clicked. The appropriate button's label * is also updated. * * @param c the colleague on which a change of interest occured * @param m the mediator to be notifed of the change */ protected void notifyMediator(Colleague c, Mediator m) { Button button = (Button) c; Label label = (Label) m; if (button == Main.button1) { label.setText(&quot;Button1 clicked&quot;); } else if (button == Main.button2) { label.setText(&quot;Button2 clicked&quot;); } button.setText(&quot;(Done)&quot;); } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z files.lst 2004-03-24T16:00:00Z 2004-03-24T16:00:00Z <br/><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2004-03-24T16:00:00Z