001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * CompositorPanel.java
044: *
045: * Created on June 6, 2006, 4:06 PM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.modules.xml.schema.abe;
052:
053: import java.awt.BorderLayout;
054: import java.awt.Color;
055: import java.awt.Component;
056: import java.awt.Font;
057: import java.awt.Graphics;
058: import java.awt.Graphics2D;
059: import java.awt.Point;
060: import java.awt.Rectangle;
061: import java.awt.event.ActionEvent;
062: import java.awt.event.ActionListener;
063: import java.awt.event.KeyEvent;
064: import java.awt.event.KeyListener;
065: import java.awt.event.MouseAdapter;
066: import java.awt.event.MouseEvent;
067: import java.beans.PropertyChangeEvent;
068: import java.beans.PropertyChangeListener;
069: import java.util.List;
070: import javax.swing.Box;
071: import javax.swing.JComboBox;
072: import javax.swing.JLabel;
073: import javax.swing.JPanel;
074: import javax.swing.SpringLayout;
075: import javax.swing.SwingUtilities;
076: import javax.swing.border.EmptyBorder;
077: import javax.swing.border.LineBorder;
078: import org.netbeans.modules.xml.axi.AXIComponent;
079: import org.netbeans.modules.xml.axi.AXIModel;
080: import org.netbeans.modules.xml.axi.Compositor;
081: import org.netbeans.modules.xml.axi.Compositor.CompositorType;
082: import org.netbeans.modules.xml.axi.ContentModel;
083: import org.netbeans.modules.xml.axi.Element;
084: import org.netbeans.modules.xml.schema.abe.nodes.ABEAbstractNode;
085: import org.netbeans.modules.xml.schema.abe.nodes.CompositorNode;
086: import org.netbeans.modules.xml.schema.abe.palette.DnDHelper;
087: import org.openide.nodes.Node;
088: import org.openide.util.NbBundle;
089:
090: /**
091: *
092: * @author girix
093: */
094: public class CompositorPanel extends ElementsContainerPanel {
095: private static final long serialVersionUID = 7526472295622776147L;
096:
097: CompositorType compositorType;
098: ExpandCollapseButton expandButton;
099:
100: InplaceEditableLabel compositorTypeLabel;
101: JPanel compositorTypePanel;
102: JLabel contentModelInfoLabel;
103: private ABEAbstractNode compositorNode;
104:
105: private JLabel itemCountLabel;
106: private static final int BORDER_THICKNESS = 2;
107: private static final EmptyBorder emptyBorder = new EmptyBorder(
108: BORDER_THICKNESS, BORDER_THICKNESS, BORDER_THICKNESS,
109: BORDER_THICKNESS);
110:
111: public CompositorPanel(InstanceUIContext context,
112: Compositor compositor, Component parentPanel) {
113: super (context, compositor, parentPanel, true);
114: setBorder(emptyBorder);
115: //draw annotation
116: setDrawAnnotation(false);
117: initMouseListener();
118: initKeyListener();
119: makeNBNode();
120: addSelectionListener();
121:
122: compositor
123: .addPropertyChangeListener(new PropertyChangeListener() {
124: public void propertyChange(PropertyChangeEvent evt) {
125: SwingUtilities.invokeLater(new Runnable() {
126: public void run() {
127: verifyChildrenWithModel();
128: }
129: });
130: }
131: });
132: }
133:
134: protected void initMouseListener() {
135: addMouseListener(new MouseAdapter() {
136: public void mouseReleased(MouseEvent e) {
137: mouseClickedActionHandler(e, true);
138: }
139:
140: public void mouseClicked(MouseEvent e) {
141: mouseClickedActionHandler(e, false);
142: }
143:
144: public void mousePressed(MouseEvent e) {
145: mouseClickedActionHandler(e, true);
146: }
147: });
148: }
149:
150: protected void mouseClickedActionHandler(MouseEvent e,
151: boolean handelPopupOnly) {
152: if (e.getClickCount() == 1) {
153: if (e.isPopupTrigger()) {
154: context.getMultiComponentActionManager().showPopupMenu(
155: e, this );
156: return;
157: }
158: if (handelPopupOnly)
159: return;
160: //the tag is selected
161: if (e.isControlDown())
162: context.getComponentSelectionManager()
163: .addToSelectedComponents(this );
164: else
165: context.getComponentSelectionManager()
166: .setSelectedComponent(this );
167: }
168: }
169:
170: protected void initKeyListener() {
171: addKeyListener(new KeyListener() {
172: public void keyPressed(KeyEvent e) {
173: if (e.getKeyCode() == e.VK_F2) {
174: compositorTypeLabel.showEditor();
175: }
176: if (context.getFocusTraversalManager()
177: .isFocusChangeEvent(e))
178: context.getFocusTraversalManager().handleEvent(e,
179: CompositorPanel.this );
180: }
181:
182: public void keyReleased(KeyEvent e) {
183: }
184:
185: public void keyTyped(KeyEvent e) {
186: if (e.getKeyChar() == e.VK_SPACE) {
187: compositorTypeLabel.showEditor();
188:
189: }
190: }
191: });
192: }
193:
194: SpringLayout compositorTypePanelLayout;
195:
196: public void addHeaderPanel() {
197: AutoSizingPanel rbp = new AutoSizingPanel(context);
198: rbp.setHorizontalScaling(true);
199: rbp.setOpaque(false);
200: compositorTypePanel = rbp;
201: //compositorTypePanel.setOpaque(true);
202: compositorTypePanelLayout = new SpringLayout();
203: compositorTypePanel.setLayout(compositorTypePanelLayout);
204: compositorTypeLabel = new InplaceEditableLabel(
205: getCompositorTypeString());
206: compositorTypeLabel
207: .setForeground(InstanceDesignConstants.COMPOSITOR_TYPE_LABEL_COLOR);
208:
209: if (getAXIParent().isReadOnly()) {
210: //compositorTypeLabel.setIcon(UIUtilities.getImageIcon("import-include-redefine.png"));
211: compositorTypeLabel.setToolTipText(NbBundle.getMessage(
212: CompositorPanel.class, "TTP_COMPOSITOR_READONLY",
213: getCompositorType().getName()));
214: }
215:
216: //add indentation
217: if (!(parentPanel instanceof ElementPanel)) {
218: //if the parent panel is a compositor then dont indent
219: setPanelIndendation(0);
220: }
221:
222: Component hgap = Box
223: .createHorizontalStrut(getPanelIndendation());
224: compositorTypePanel.add(hgap);
225: compositorTypePanelLayout.putConstraint(SpringLayout.WEST,
226: hgap, 0, SpringLayout.WEST, compositorTypePanel);
227: compositorTypePanelLayout.putConstraint(SpringLayout.NORTH,
228: hgap, 0, SpringLayout.NORTH, compositorTypePanel);
229:
230: compositorTypePanel.add(compositorTypeLabel);
231: compositorTypePanelLayout.putConstraint(SpringLayout.WEST,
232: compositorTypeLabel, 0, SpringLayout.EAST, hgap);
233: compositorTypePanelLayout.putConstraint(SpringLayout.NORTH,
234: compositorTypeLabel, 0, SpringLayout.NORTH,
235: compositorTypePanel);
236:
237: hgap = Box.createHorizontalStrut(10);
238: compositorTypePanel.add(hgap);
239: compositorTypePanelLayout.putConstraint(SpringLayout.WEST,
240: hgap, 0, SpringLayout.EAST, compositorTypeLabel);
241: compositorTypePanelLayout.putConstraint(SpringLayout.NORTH,
242: hgap, 0, SpringLayout.NORTH, compositorTypePanel);
243:
244: CompositorPropertiesPanel cpp = new CompositorPropertiesPanel(
245: getCompositor(), context);
246: compositorTypePanel.add(cpp);
247: compositorTypePanelLayout.putConstraint(SpringLayout.WEST, cpp,
248: 0, SpringLayout.EAST, hgap);
249: compositorTypePanelLayout.putConstraint(SpringLayout.NORTH,
250: cpp, 0, SpringLayout.NORTH, compositorTypePanel);
251:
252: //add an artificial mouse listener for transmiting the mouse events to the parent
253: cpp.addMouseListener(new MouseAdapter() {
254: public void mouseClicked(MouseEvent e) {
255: CompositorPanel.this .dispatchEvent(e);
256: }
257:
258: public void mouseReleased(MouseEvent e) {
259: CompositorPanel.this .dispatchEvent(e);
260: }
261:
262: public void mousePressed(MouseEvent e) {
263: CompositorPanel.this .dispatchEvent(e);
264: }
265:
266: });
267:
268: compositorTypePanel.addMouseListener(new MouseAdapter() {
269: public void mouseClicked(MouseEvent e) {
270: CompositorPanel.this .dispatchEvent(e);
271: }
272:
273: public void mouseReleased(MouseEvent e) {
274: CompositorPanel.this .dispatchEvent(e);
275: }
276:
277: public void mousePressed(MouseEvent e) {
278: CompositorPanel.this .dispatchEvent(e);
279: }
280:
281: });
282:
283: hgap = Box.createHorizontalStrut(10);
284: compositorTypePanel.add(hgap);
285: compositorTypePanelLayout.putConstraint(SpringLayout.WEST,
286: hgap, 0, SpringLayout.EAST, cpp);
287: compositorTypePanelLayout.putConstraint(SpringLayout.NORTH,
288: hgap, 0, SpringLayout.NORTH, compositorTypePanel);
289:
290: //init item count label
291: itemCountLabel = new JLabel();
292: itemCountLabel.setForeground(Color.GRAY.brighter());
293: refreshItemCount();
294: compositorTypePanel.add(itemCountLabel);
295: compositorTypePanelLayout.putConstraint(SpringLayout.WEST,
296: itemCountLabel, 0, SpringLayout.EAST, hgap);
297: compositorTypePanelLayout.putConstraint(SpringLayout.NORTH,
298: itemCountLabel, 0, SpringLayout.NORTH,
299: compositorTypePanel);
300:
301: add(compositorTypePanel, BorderLayout.NORTH);
302:
303: //add an artificial mouse listener for transmiting the mouse events to the parent
304: compositorTypeLabel.addMouseListener(new MouseAdapter() {
305: public void mouseClicked(MouseEvent e) {
306: CompositorPanel.this .dispatchEvent(e);
307: }
308:
309: public void mouseReleased(MouseEvent e) {
310: CompositorPanel.this .dispatchEvent(e);
311: }
312:
313: public void mousePressed(MouseEvent e) {
314: CompositorPanel.this .dispatchEvent(e);
315: }
316:
317: });
318:
319: initCompositorTypeEditListener();
320: }
321:
322: protected void initCompositorTypeEditListener() {
323: compositorTypeLabel
324: .addPropertyChangeListener(new PropertyChangeListener() {
325: public void propertyChange(PropertyChangeEvent evt) {
326: if (evt
327: .getPropertyName()
328: .equals(
329: InplaceEditableLabel.PROPERTY_MODE_CHANGE)) {
330: if (evt.getNewValue() == InplaceEditableLabel.Mode.EDIT) {
331: //user selected edit give the editor JComponent
332: //show a combo box field
333: CompositorType options[] = filterAllIfNeeded(getCompositor());
334: final JComboBox field = new JComboBox(
335: options);
336: field
337: .setSelectedItem(getCompositorType());
338: field
339: .addActionListener(new ActionListener() {
340: public void actionPerformed(
341: ActionEvent e) {
342: CompositorType newType = (CompositorType) field
343: .getSelectedItem();
344: //do validation
345: compositorTypeLabel
346: .hideEditor();
347: setCompositorTypeInModel(newType);
348:
349: if (getParentContainerPanel() instanceof ElementPanel) {
350: //since model removes and adds all the element and compositors, open the element by default
351: ((ElementPanel) getParentContainerPanel())
352: .expandChild();
353: }
354: }
355: });
356: if (getAXIParent().isReadOnly()) {
357: String str = NbBundle
358: .getMessage(
359: CompositorPanel.class,
360: "MSG_READONLY_COMPOSITORTYPE_EDIT",
361: getCompositorType()
362: .getName());
363: compositorTypeLabel
364: .setEditInfoText(str,
365: context);
366: } else {
367: compositorTypeLabel
368: .setInlineEditorComponent(field);
369: }
370: }
371: }
372: }
373: });
374: }
375:
376: void initButton() {
377: expandButton.addActionListener(new ActionListener() {
378: public void actionPerformed(ActionEvent e) {
379: handleExpandOrCollapse();
380: }
381: });
382: }
383:
384: void handleExpandOrCollapse() {
385: if (!expandButton.isExpanded()) {
386: //expand
387: expandChild();
388: } else {
389: //collapse
390: collapseChild();
391: }
392: }
393:
394: void expandChild() {
395: if (childrenPanel != null) {
396: //children already added just show
397: childrenPanel.setVisible(true);
398: revalidate();
399: repaint();
400: } else {
401: //children, if present, are expanded and added by default.
402: }
403: }
404:
405: void collapseChild() {
406: if (childrenPanel != null) {
407: //children already added just hide
408: childrenPanel.setVisible(false);
409: revalidate();
410: repaint();
411: }
412: }
413:
414: void refreshItemCount() {
415: //add some space in the end to keep the label away from the border paint area.
416: int size = getAXIChildren().size();
417: String item = NbBundle.getMessage(ContainerPanel.class,
418: "LBL_ITEM_STRING");
419: String items = NbBundle.getMessage(ContainerPanel.class,
420: "LBL_ITEMS_STRING");
421: String itemStr = size == 1 ? item : items;
422: itemCountLabel.setText("[" + size + " " + itemStr + "] ");
423: }
424:
425: public void _paintComponent(Graphics g) {
426: Graphics2D g2d = (Graphics2D) g;
427: super .setAnnotationString(getCompositorType().toString());
428: Rectangle rect = this .getBounds();
429: int x = rect.x + this .getWidth() + 2;
430: int y = rect.y - 10;
431: Point pt = new Point(x, y);
432: super .setStartDrawPoint(pt);
433: super .paintComponent(g2d);
434: }
435:
436: public CompositorType getCompositorType() {
437: AXIComponent parent = getAXIParent();
438: if (parent instanceof Compositor)
439: return ((Compositor) parent).getType();
440:
441: return null;
442: }
443:
444: public String getCompositorTypeString() {
445: CompositorType compType = getCompositorType();
446: String comp = null;
447: switch (compType) {
448: case SEQUENCE:
449: comp = NbBundle.getMessage(CompositorPanel.class,
450: "LBL_Sequence");
451: break;
452: case CHOICE:
453: comp = NbBundle.getMessage(CompositorPanel.class,
454: "LBL_Choice");
455: break;
456: case ALL:
457: comp = NbBundle
458: .getMessage(CompositorPanel.class, "LBL_All");
459: break;
460: }
461: if (comp == null)
462: comp = getCompositorType().getName();
463: StringBuffer str = new StringBuffer(comp);
464: while (str.length() < 8)
465: str.append(" ");
466: return str.toString();
467: }
468:
469: public void setCompositorTypeInModel(CompositorType ctype) {
470: ((Compositor) getAXIParent()).setType(ctype);
471: }
472:
473: private Compositor getCompositor() {
474: return (Compositor) getAXIParent();
475: }
476:
477: public List<? extends AXIComponent> getAXIChildren() {
478: return getAXIParent().getChildren();
479: }
480:
481: public void removeElement(Element element) {
482: super .removeElement(element);
483: refreshItemCount();
484: }
485:
486: public void addElement(Element element) {
487: super .addElement(element);
488: refreshItemCount();
489: }
490:
491: public void addCompositor(Compositor newCompositor) {
492: //look in to the children list find out where the child was added
493: //create a new CompositorPanel and add @ that index. Adjust the layout accordingly
494: int index = getAXIChildren().indexOf(newCompositor);
495:
496: if (isAlreadyAdded(newCompositor) != null)
497: return;
498:
499: CompositorPanel cp = new CompositorPanel(context,
500: newCompositor, this );
501: addChildAt(cp, index);
502: refreshItemCount();
503: }
504:
505: public void removeChildCompositor(Compositor compositor) {
506: //look in to the children list find out where the child was present
507: //remove the CompositorPanel @ that index. Adjust the layout accordingly
508: Component rmComp = null;
509: for (Component component : getChildrenList()) {
510: if (component instanceof CompositorPanel) {
511: if (((CompositorPanel) component).getCompositor() == compositor) {
512: rmComp = component;
513: break;
514: }
515:
516: }
517: }
518: if (rmComp != null) {
519: removeComponent(rmComp);
520: }
521: refreshItemCount();
522: }
523:
524: private void addNewCompositorAt(TweenerPanel tweener,
525: DnDHelper.PaletteItem compType) {
526: int index = getChildrenList().indexOf(tweener);
527: if (index == -1) {
528: //must not happen
529: return;
530: }
531: index = index / 2;
532: AXIModel model = getAXIParent().getModel();
533:
534: Compositor comp = null;
535: switch (compType) {
536: case SEQUENCE:
537: comp = model.getComponentFactory().createSequence();
538: break;
539: case CHOICE:
540: comp = model.getComponentFactory().createChoice();
541: break;
542: case ALL:
543: comp = model.getComponentFactory().createAll();
544: break;
545: }
546:
547: if (comp == null)
548: return;
549:
550: model.startTransaction();
551: try {
552: getAXIParent().addChildAtIndex(comp, index);
553: } finally {
554: model.endTransaction();
555: }
556: }
557:
558: protected void setupAXIComponentListener() {
559: super .setupAXIComponentListener();
560: getAXIParent().addPropertyChangeListener(
561: new ModelEventMediator(this , getAXIParent()) {
562: public void _propertyChange(PropertyChangeEvent evt) {
563: if (evt.getPropertyName().equals(
564: Compositor.PROP_COMPOSITOR)) {
565: //a compositor event
566: if ((evt.getOldValue() == null)
567: && (evt.getNewValue() != null)) {
568: //new element added
569: addCompositor((Compositor) evt
570: .getNewValue());
571: } else if ((evt.getNewValue() == null)
572: && (evt.getOldValue() != null)) {
573: //old element removed
574: removeChildCompositor((Compositor) evt
575: .getOldValue());
576: }
577: } else if (evt.getPropertyName().equals(
578: Compositor.PROP_TYPE)) {
579: //handle compositor change event
580: compositorTypeLabel
581: .setText(getCompositorTypeString());
582: }
583: refreshItemCount();
584: }
585: });
586:
587: }
588:
589: public void visit(Compositor compositor) {
590: super .visit(compositor);
591: visitorResult = null;
592: CompositorPanel compPanel = new CompositorPanel(context,
593: compositor, CompositorPanel.this );
594: visitorResult = compPanel;
595: }
596:
597: public void tweenerDrop(TweenerPanel tweener,
598: DnDHelper.PaletteItem paletteItem) {
599: super .tweenerDrop(tweener, paletteItem);
600: if (DnDHelper.isCompositor(paletteItem)
601: && (paletteItem != paletteItem.ALL)
602: && ((Compositor) getAXIComponent()).getType() != CompositorType.ALL) {
603: //add only seq/choice
604: addNewCompositorAt(tweener, paletteItem);
605: }
606: }
607:
608: public void tweenerDragEntered(TweenerPanel tweener,
609: DnDHelper.PaletteItem paletteItem) {
610: super .tweenerDragEntered(tweener, paletteItem);
611: if (!tweenerDragAccept(tweener, paletteItem))
612: return;
613: //this.setDrawBorder(true);
614: LineBorder lineBorder = new LineBorder(
615: InstanceDesignConstants.DARK_BLUE, BORDER_THICKNESS,
616: true);
617: this .setBorder(lineBorder);
618: this .repaint();
619:
620: //set the info message for tweener panel to display
621:
622: ContentModel cm = getCompositor().getContentModel();
623: if (cm != null) {
624: String type = UIUtilities.getContentModelTypeString(cm
625: .getType());
626: String locDrpStrType = NbBundle.getMessage(
627: UIUtilities.class, "MSG_DROP_INFO_TYPE");
628: tweener.setDropInfoText(locDrpStrType + " " + type + " "
629: + cm.getName());
630: } else {
631: String locDrpStrLocal = NbBundle.getMessage(
632: UIUtilities.class, "MSG_DROP_INFO_LOCAL");
633: tweener.setDropInfoText(locDrpStrLocal
634: + getCompositor().getType().getName());
635: }
636: }
637:
638: public boolean tweenerDragAccept(TweenerPanel tweener,
639: DnDHelper.PaletteItem paletteItem) {
640: if (getAXIParent().isReadOnly()) {
641: String str = NbBundle.getMessage(CompositorPanel.class,
642: "MSG_READONLY_COMPOSITOR_DROP", getAXIParent()
643: .getContentModel().getName());
644: UIUtilities.showErrorMessageFor(str, context, tweener);
645: return false;
646: }
647:
648: if ((getCompositorType() == CompositorType.ALL)
649: && (paletteItem != DnDHelper.PaletteItem.ELEMENT)) {
650: String str = NbBundle.getMessage(CompositorPanel.class,
651: "MSG_ALL_COMPOSITOR_DROP_REJECT");
652: UIUtilities.showErrorMessageFor(str, context, tweener);
653: return false;
654: }
655: //accept only element and compositor
656: if ((paletteItem == DnDHelper.PaletteItem.ELEMENT)
657: || ((DnDHelper.isCompositor(paletteItem)) && (paletteItem != paletteItem.ALL))) {
658: return true;
659: }
660: String str = NbBundle.getMessage(CompositorPanel.class,
661: "MSG_COMPOSITOR_DROP_REJECT");
662: UIUtilities.showErrorMessageFor(str, context, tweener);
663: return false;
664: }
665:
666: public void tweenerDragExited(TweenerPanel tweener) {
667: super .tweenerDragExited(tweener);
668: UIUtilities.hideGlassMessage();
669: this .setBorder(emptyBorder);
670: this .repaint();
671: }
672:
673: protected void makeNBNode() {
674: compositorNode = new CompositorNode(
675: (Compositor) getAXIParent(), context);
676: if (getAXIParent().isReadOnly())
677: ((ABEAbstractNode) compositorNode).setReadOnly(true);
678: }
679:
680: public ABEAbstractNode getNBNode() {
681: return compositorNode;
682: }
683:
684: public AXIComponent getAXIComponent() {
685: return getAXIParent();
686: }
687:
688: public void removeCompositor() {
689: if (getAXIComponent() instanceof Compositor) {
690: AXIComponent axiComponent = getAXIComponent();
691: if (axiComponent.getModel() != null) {
692: context.getAXIModel().startTransaction();
693: try {
694: axiComponent.getParent().removeChild(
695: getAXIComponent());
696: } finally {
697: context.getAXIModel().endTransaction();
698: }
699: }
700: }
701: }
702:
703: private void addSelectionListener() {
704: addPropertyChangeListener(new PropertyChangeListener() {
705: public void propertyChange(PropertyChangeEvent evt) {
706: if (evt.getPropertyName().equals(PROP_SELECTED)) {
707: if (((Boolean) evt.getNewValue()).booleanValue()) {
708: //set the tag name color to orange
709: compositorTypeLabel
710: .setForeground(InstanceDesignConstants.COMPOSITOR_TYPE_LABEL_SELECTED_COLOR);
711: Font font = compositorTypeLabel.getFont();
712: font = new Font(font.getName(), Font.BOLD, font
713: .getSize());
714: compositorTypeLabel.setFont(font);
715: drawBoldString(true);
716: setBorder(new LineBorder(
717: InstanceDesignConstants.XP_ORANGE,
718: BORDER_THICKNESS, true));
719: } else {
720: //set the tage name color to normal color
721: compositorTypeLabel
722: .setForeground(InstanceDesignConstants.COMPOSITOR_TYPE_LABEL_COLOR);
723: Font font = compositorTypeLabel.getFont();
724: font = new Font(font.getName(), Font.PLAIN,
725: font.getSize());
726: compositorTypeLabel.setFont(font);
727: drawBoldString(false);
728: setBorder(emptyBorder);
729: }
730:
731: }
732: }
733: });
734: }
735:
736: public void showExpandButton(boolean show) {
737: expandButton.setVisible(show);
738: }
739:
740: public void accept(UIVisitor visitor) {
741: visitor.visit(this );
742: }
743:
744: public static CompositorType[] filterAllIfNeeded(
745: Compositor compositor) {
746: if (compositor.getParent() instanceof Compositor) {
747: //parent is also a compositor. This cant be all
748: return new CompositorType[] { CompositorType.SEQUENCE,
749: CompositorType.CHOICE };
750: }
751: for (AXIComponent child : compositor.getChildren()) {
752: if (child instanceof Compositor) {
753: //children contains a compositor so this cant be all
754: return new CompositorType[] { CompositorType.SEQUENCE,
755: CompositorType.CHOICE };
756: }
757: }
758: return CompositorType.values();
759:
760: }
761: }
|