bpel.editors/src/org/netbeans/modules/bpel/search/Decorator.java
author Vladimir Yaroslavskiy <yaroslavskiy@netbeans.org>
Wed, 28 Sep 2011 14:01:59 +0400
changeset 4891 fa2f6f3c723d
parent 4011 0d334c4dc92e
permissions -rw-r--r--
Fix selection on BPEL diagram
     1 /*
     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.
     5  * 
     6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
     7  * or http://www.netbeans.org/cddl.txt.
     8  * 
     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]"
    14  * 
    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.
    18  */
    19 package org.netbeans.modules.bpel.search;
    20 
    21 import java.awt.Color;
    22 import java.awt.Font;
    23 import java.util.ArrayList;
    24 import java.util.List;
    25 
    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;
    34 
    35 /**
    36  * @author Vladimir Yaroslavskiy
    37  * @version 2006.12.06
    38  */
    39 public final class Decorator extends DecorationProvider implements DecorationProviderFactory {
    40 
    41     public Decorator() {}
    42 
    43     public DecorationProvider createInstance(DesignView view) {
    44         return new Decorator(view);
    45     }
    46 
    47     private Decorator(DesignView view) {
    48         super(view);
    49         myHighlightedEntities = new ArrayList<BpelEntity>();
    50     }
    51 
    52     @Override
    53     public Decoration getDecoration(BpelEntity entity) {
    54         if ( !myIsClearSelection && mySelectedEntity == entity) {
    55             return new Decoration(new LabelStyleDescriptor(new Color(0x339900), element, Font.BOLD)); // glow
    56         }
    57         if ( !myIsClearHighlighting && myHighlightedEntities.contains(entity)) {
    58             return new Decoration(new GlowDescriptor(new Color(255, 255, 0), 20.0)); // highlight
    59         }
    60         return null;
    61     }
    62 
    63     @Override
    64     public void release() {
    65         mySelectedEntity = null;
    66         myHighlightedEntities = null;
    67     }
    68 
    69     void select(BpelEntity entity, VisualElement findedElement) {
    70         if (mySelectedEntity != null) {
    71             myIsClearSelection = true;
    72         }
    73         myIsClearSelection = false;
    74         mySelectedEntity = entity;
    75         element = findedElement;
    76         fireDecorationChanged();
    77     }
    78 
    79     void clearHighlighting() {
    80         myIsClearHighlighting = true;
    81         myIsClearSelection = true;
    82 
    83         fireDecorationChanged();
    84 
    85         myHighlightedEntities = new ArrayList<BpelEntity>();
    86         myIsClearHighlighting = false;
    87         myIsClearSelection = false;
    88     }
    89 
    90     void doHighlight(BpelEntity entity, boolean highlighted) {
    91         if (highlighted) {
    92             myHighlightedEntities.add(entity);
    93         } else {
    94             myHighlightedEntities.remove(entity);
    95         }
    96         myIsClearSelection = !highlighted;
    97         fireDecorationChanged();
    98     }
    99 
   100     static Decorator getDecorator(DesignView view) {
   101         List<DecorationProvider> providers = view.getDecorationManager().getProviders();
   102 
   103         for (DecorationProvider provider : providers) {
   104             if (provider instanceof Decorator) {
   105                 return (Decorator) provider;
   106             }
   107         }
   108         return null;
   109     }
   110 
   111     private VisualElement element;
   112     private boolean myIsClearSelection;
   113     private boolean myIsClearHighlighting;
   114     private BpelEntity mySelectedEntity;
   115     private List<BpelEntity> myHighlightedEntities;
   116 }