2 * The contents of this file are subject to the terms of the Common Development
3 * and Distribution License (the License). You may not use this file except in
4 * compliance with the License.
6 * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7 * or http://www.netbeans.org/cddl.txt.
9 * When distributing Covered Code, include this CDDL Header Notice in each file
10 * and include the License file at http://www.netbeans.org/cddl.txt.
11 * If applicable, add the following below the CDDL Header, with the fields
12 * enclosed by brackets [] replaced by your own identifying information:
13 * "Portions Copyrighted [year] [name of copyright owner]"
15 * The Original Software is NetBeans. The Initial Developer of the Original
16 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17 * Microsystems, Inc. All Rights Reserved.
19 package org.netbeans.modules.bpel.search;
21 import java.awt.Color;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.netbeans.modules.bpel.model.api.BpelEntity;
27 import org.netbeans.modules.bpel.design.DesignView;
28 import org.netbeans.modules.bpel.design.decoration.Decoration;
29 import org.netbeans.modules.bpel.design.decoration.DecorationProvider;
30 import org.netbeans.modules.bpel.design.decoration.DecorationProviderFactory;
31 import org.netbeans.modules.bpel.design.decoration.GlowDescriptor;
32 import org.netbeans.modules.bpel.design.decoration.LabelStyleDescriptor;
33 import org.netbeans.modules.bpel.design.model.elements.VisualElement;
36 * @author Vladimir Yaroslavskiy
39 public final class Decorator extends DecorationProvider implements DecorationProviderFactory {
43 public DecorationProvider createInstance(DesignView view) {
44 return new Decorator(view);
47 private Decorator(DesignView view) {
49 myHighlightedEntities = new ArrayList<BpelEntity>();
53 public Decoration getDecoration(BpelEntity entity) {
54 if ( !myIsClearSelection && mySelectedEntity == entity) {
55 return new Decoration(new LabelStyleDescriptor(new Color(0x339900), element, Font.BOLD)); // glow
57 if ( !myIsClearHighlighting && myHighlightedEntities.contains(entity)) {
58 return new Decoration(new GlowDescriptor(new Color(255, 255, 0), 20.0)); // highlight
64 public void release() {
65 mySelectedEntity = null;
66 myHighlightedEntities = null;
69 void select(BpelEntity entity, VisualElement findedElement) {
70 if (mySelectedEntity != null) {
71 myIsClearSelection = true;
73 myIsClearSelection = false;
74 mySelectedEntity = entity;
75 element = findedElement;
76 fireDecorationChanged();
79 void clearHighlighting() {
80 myIsClearHighlighting = true;
81 myIsClearSelection = true;
83 fireDecorationChanged();
85 myHighlightedEntities = new ArrayList<BpelEntity>();
86 myIsClearHighlighting = false;
87 myIsClearSelection = false;
90 void doHighlight(BpelEntity entity, boolean highlighted) {
92 myHighlightedEntities.add(entity);
94 myHighlightedEntities.remove(entity);
96 myIsClearSelection = !highlighted;
97 fireDecorationChanged();
100 static Decorator getDecorator(DesignView view) {
101 List<DecorationProvider> providers = view.getDecorationManager().getProviders();
103 for (DecorationProvider provider : providers) {
104 if (provider instanceof Decorator) {
105 return (Decorator) provider;
111 private VisualElement element;
112 private boolean myIsClearSelection;
113 private boolean myIsClearHighlighting;
114 private BpelEntity mySelectedEntity;
115 private List<BpelEntity> myHighlightedEntities;