• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /barrelfish-2018-10-04/usr/eclipseclp/Visualisation/src/com/parctechnologies/eclipse/visualisation/
1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  The ECLiPSe Constraint Logic Programming System.
15// The Initial Developer of the Original Code is  Cisco Systems, Inc.
16// Portions created by the Initial Developer are
17// Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18//
19// Contributor(s):
20//
21// END LICENSE BLOCK
22
23package com.parctechnologies.eclipse.visualisation;
24
25import java.awt.event.*;
26import java.awt.*;
27import javax.swing.*;
28import java.util.*;
29
30/**
31 * Superclass of actions performed on Viewlets.
32 */
33public class ViewletAction extends AbstractAction
34{
35  public void actionPerformed(ActionEvent event)
36  {
37
38  }
39
40  public ViewletAction(String name)
41  {
42    super(name);
43    putValue(Action.SMALL_ICON, new EmptyIcon(20,20));
44  }
45
46  /**
47   * We override equals so that two ViewletActions are equal if they are
48   * instances of the same class. This is important when determining whether
49   * one action can be performed on two different Viewlets. If the second
50   * Viewlet has an action which equals the first Viewlet's action then the
51   * it makes sense to provide a compoundAction which acts on both viewlets.
52   */
53  public boolean equals(Object obj)
54  {
55    if(obj.getClass().equals(this.getClass()))
56    {
57      return(true);
58    }
59    else
60    {
61      return(super.equals(obj));
62    }
63  }
64
65  /**
66   * If you override equals you have to override hashCode to make sure that two
67   * equals Actions also have the same hashCode. We do this by using the Class'
68   * hashcode (two actions of the same class must therefore have the same
69   * hashcode).
70   */
71  public int hashCode()
72  {
73    return(getClass().hashCode());
74  }
75
76  /**
77   * For subclasses, this should return a ViewletAction which represents
78   * this viewletAction applied to the multiple viewlets in the parameter
79   * Collection. If such an action cannot be performed on multiple viewlets,
80   * the returned action should be disabled.
81   */
82  public ViewletAction createCompoundAction(Collection viewlets)
83  {
84    return(null);
85  }
86
87  /**
88   * EmptyIcon is the default icon for viewletActions. The reason to have this
89   * is to make all the actions aligned in a menu, whether or not they have
90   * icons.
91   */
92  private class EmptyIcon implements Icon
93  {
94    private int height;
95    private int width;
96
97    public EmptyIcon(int width, int height)
98    {
99      this.width = width;
100      this.height = height;
101    }
102
103    public int getIconHeight()
104    {
105      return(height);
106    }
107
108    public int getIconWidth()
109    {
110      return(width);
111    }
112
113    public void paintIcon(Component c, Graphics g, int x, int y)
114    {
115    }
116  }
117
118}
119