001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.design.decoration.components;
021:
022: import java.awt.Dimension;
023: import java.awt.Graphics;
024: import java.awt.Point;
025: import java.awt.event.MouseEvent;
026: import java.awt.event.MouseListener;
027: import javax.swing.Icon;
028: import javax.swing.ImageIcon;
029: import javax.swing.JLabel;
030: import org.netbeans.modules.bpel.design.DesignView;
031: import org.netbeans.modules.bpel.design.decoration.Decoration;
032: import org.netbeans.modules.bpel.design.model.patterns.Pattern;
033: import org.netbeans.modules.bpel.design.selection.FlowlinkTool;
034: import org.netbeans.modules.bpel.model.api.BpelEntity;
035: import org.netbeans.modules.bpel.model.api.support.UniqueId;
036:
037: /**
038: *
039: * @author aa160298
040: */
041: public class LinkToolButton extends JLabel implements
042: DecorationComponent, MouseListener {
043:
044: private UniqueId omReference;
045: private DesignView designView;
046:
047: //private Pattern pattern;
048:
049: public LinkToolButton(Pattern pattern) {
050: super (ICON_GRAY);
051:
052: omReference = pattern.getOMReference().getUID();
053: designView = pattern.getModel().getView();
054:
055: setOpaque(false);
056: setBorder(null);
057: setBackground(null);
058: setFocusable(false);
059:
060: setPreferredSize(new Dimension(16, 16));
061:
062: addMouseListener(this );
063: }
064:
065: public Pattern getPattern() {
066: BpelEntity be = omReference.getModel().getEntity(omReference);
067: return (be == null) ? null : designView.getModel().getPattern(
068: be);
069: }
070:
071: public void setPosition(Point p) {
072: Dimension size = getPreferredSize();
073: setBounds(p.x - size.width / 2, p.y - size.height / 2,
074: size.width, size.height);
075: }
076:
077: protected void paintComponent(Graphics g) {
078: Point point = getMousePosition();
079:
080: Pattern pattern = getPattern();
081:
082: if (pattern == null) {
083: return;
084: }
085:
086: FlowlinkTool flowLinkTool = pattern.getModel().getView()
087: .getFlowLinkTool();
088:
089: if (flowLinkTool.isActive()) {
090: if (flowLinkTool.isValidLocation()) {
091: ICON.paintIcon(this , g, 0, 0);
092: } else {
093: ICON_RED.paintIcon(this , g, 0, 0);
094: }
095: } else {
096: boolean rollover = (point != null) && (0 <= point.x)
097: && (point.x < getWidth()) && (0 <= point.y)
098: && (point.y < getHeight());
099:
100: if (rollover) {
101: ICON.paintIcon(this , g, 0, 0);
102: } else {
103: ICON_GRAY.paintIcon(this , g, 0, 0);
104: }
105: }
106: }
107:
108: public void mouseClicked(MouseEvent e) {
109: }
110:
111: public void mousePressed(MouseEvent e) {
112: }
113:
114: public void mouseReleased(MouseEvent e) {
115: }
116:
117: public void mouseEntered(MouseEvent e) {
118: repaint();
119: }
120:
121: public void mouseExited(MouseEvent e) {
122: repaint();
123: }
124:
125: private static final String ICON_PATH = "resources/envelope_small.png"; // NOI18N
126: private static final String ICON_GRAY_PATH = "resources/envelope_small_gray.png"; // NOI18N
127: private static final String ICON_RED_PATH = "resources/envelope_small_red.png"; // NOI18N
128:
129: private static final Icon ICON;
130: private static final Icon ICON_GRAY;
131: private static final Icon ICON_RED;
132:
133: static {
134: ICON = new ImageIcon(Decoration.class.getResource(ICON_PATH));
135: ICON_GRAY = new ImageIcon(Decoration.class
136: .getResource(ICON_GRAY_PATH));
137: ICON_RED = new ImageIcon(Decoration.class
138: .getResource(ICON_RED_PATH));
139: }
140: }
|