Source Code Cross Referenced for EditControlImpl.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » ui » controls » editcontrol » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » uml » org.netbeans.modules.uml.ui.controls.editcontrol 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003:         *
0004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005:         *
0006:         * The contents of this file are subject to the terms of either the GNU
0007:         * General Public License Version 2 only ("GPL") or the Common
0008:         * Development and Distribution License("CDDL") (collectively, the
0009:         * "License"). You may not use this file except in compliance with the
0010:         * License. You can obtain a copy of the License at
0011:         * http://www.netbeans.org/cddl-gplv2.html
0012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
0013:         * specific language governing permissions and limitations under the
0014:         * License.  When distributing the software, include this License Header
0015:         * Notice in each file and include the License file at
0016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
0017:         * particular file as subject to the "Classpath" exception as provided
0018:         * by Sun in the GPL Version 2 section of the License file that
0019:         * accompanied this code. If applicable, add the following below the
0020:         * License Header, with the fields enclosed by brackets [] replaced by
0021:         * your own identifying information:
0022:         * "Portions Copyrighted [year] [name of copyright owner]"
0023:         *
0024:         * Contributor(s):
0025:         *
0026:         * The Original Software is NetBeans. The Initial Developer of the Original
0027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
0028:         * Microsystems, Inc. All Rights Reserved.
0029:         *
0030:         * If you wish your version of this file to be governed by only the CDDL
0031:         * or only the GPL Version 2, indicate your decision by adding
0032:         * "[Contributor] elects to include this software in this distribution
0033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
0034:         * single choice of license, a recipient has the option to distribute
0035:         * your version of this file under either the CDDL, the GPL Version 2 or
0036:         * to extend the choice of license to its licensees as provided above.
0037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
0038:         * Version 2 license, then the option applies only if the new code is
0039:         * made subject to such option by the copyright holder.
0040:         */
0041:
0042:        package org.netbeans.modules.uml.ui.controls.editcontrol;
0043:
0044:        import java.awt.BorderLayout;
0045:        import java.awt.Color;
0046:        import java.awt.Component;
0047:        import java.awt.Dimension;
0048:        import java.awt.Font;
0049:        import java.awt.FontMetrics;
0050:        import java.awt.Point;
0051:        import java.awt.event.ActionEvent;
0052:        import java.awt.event.ActionListener;
0053:        import java.awt.event.FocusEvent;
0054:        import java.awt.event.FocusListener;
0055:        import java.awt.event.InputEvent;
0056:        import java.awt.event.InputMethodEvent;
0057:        import java.awt.event.InputMethodListener;
0058:        import java.awt.event.KeyEvent;
0059:        import java.awt.event.KeyListener;
0060:        import java.awt.event.MouseEvent;
0061:        import java.awt.event.MouseListener;
0062:        import java.lang.ref.WeakReference;
0063:        import java.text.CharacterIterator;
0064:        import java.util.Vector;
0065:
0066:        import javax.swing.AbstractAction;
0067:        import javax.swing.JButton;
0068:        import javax.swing.JMenuItem;
0069:        import javax.swing.JPanel;
0070:        import javax.swing.JPopupMenu;
0071:        import javax.swing.JScrollPane;
0072:        import javax.swing.JTextArea;
0073:        import javax.swing.JTextField;
0074:        import javax.swing.KeyStroke;
0075:        import javax.swing.SwingUtilities;
0076:        import javax.swing.ToolTipManager;
0077:        import javax.swing.border.LineBorder;
0078:        import javax.swing.event.CaretEvent;
0079:        import javax.swing.event.CaretListener;
0080:        import javax.swing.event.DocumentEvent;
0081:        import javax.swing.event.DocumentListener;
0082:        import javax.swing.text.DefaultEditorKit;
0083:        import javax.swing.text.JTextComponent;
0084:        import javax.swing.text.Keymap;
0085:
0086:        import org.netbeans.modules.uml.core.coreapplication.ICoreProduct;
0087:        import org.netbeans.modules.uml.core.eventframework.EventBlocker;
0088:        import org.netbeans.modules.uml.core.eventframework.IEventDispatcher;
0089:        import org.netbeans.modules.uml.core.metamodel.common.commonactivities.IActivityNode;
0090:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IElement;
0091:        import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
0092:        import org.netbeans.modules.uml.core.metamodel.core.foundation.IPackage;
0093:        import org.netbeans.modules.uml.core.metamodel.dynamics.ILifeline;
0094:        import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IClassifier;
0095:        import org.netbeans.modules.uml.core.metamodel.structure.IComment;
0096:        import org.netbeans.modules.uml.core.support.umlsupport.IStrings;
0097:        import org.netbeans.modules.uml.core.support.umlsupport.ProductRetriever;
0098:        import org.netbeans.modules.uml.core.support.umlsupport.StringUtilities;
0099:        import org.netbeans.modules.uml.core.support.umlutils.IPropertyDefinition;
0100:        import org.netbeans.modules.uml.ui.controls.projecttree.IProjectTreeControl;
0101:        import org.netbeans.modules.uml.ui.products.ad.applicationcore.IADProduct;
0102:        import org.netbeans.modules.uml.ui.products.ad.compartments.ETCompartment;
0103:        import org.netbeans.modules.uml.ui.products.ad.compartments.IADCompartment;
0104:        import org.netbeans.modules.uml.ui.products.ad.compartments.IADEditableCompartment;
0105:        import org.netbeans.modules.uml.ui.support.DispatchHelper;
0106:        import org.netbeans.modules.uml.ui.support.ProductHelper;
0107:        import org.netbeans.modules.uml.ui.support.applicationmanager.IProduct;
0108:        import org.netbeans.modules.uml.ui.support.drawingproperties.DrawingPropertyResource;
0109:        import org.netbeans.modules.uml.ui.support.viewfactorysupport.ICompartment;
0110:        import org.netbeans.modules.uml.ui.swing.projecttree.ProjectTreeCellEditor;
0111:
0112:        /**
0113:         * @author sumitabhk
0114:         *
0115:         */
0116:        public class EditControlImpl extends JPanel implements  IEditControl,
0117:                InputMethodListener {
0118:            static final JTextComponent.KeyBinding[] defaultBindings = { new JTextComponent.KeyBinding(
0119:                    KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK),
0120:                    DefaultEditorKit.copyAction),
0121:            //new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK), DefaultEditorKit.pasteAction),
0122:            //new JTextComponent.KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK), DefaultEditorKit.cutAction)
0123:            };
0124:
0125:            //private JTextField m_Field = null;
0126:            private JTextComponent m_Field = null;
0127:            private JButton m_Button = null;
0128:            private JPanel m_Panel = null;
0129:            private JPopupMenu m_TooltipMenu = null;
0130:
0131:            private ITranslator m_Translator = null;
0132:            private IEditControlEventDispatcher m_EventDispatcher = null;
0133:            private String m_InitialData = "";
0134:            private boolean m_Modified = false;
0135:            private String m_SeparatorList = "";
0136:
0137:            private boolean m_VeryFirstTime = false;
0138:            private boolean m_IgnoreTextUpdate = false;
0139:            private boolean m_UpdatingField = false;
0140:            private Point m_LocationOnScreen = null;
0141:            private String m_TooltipText = "";
0142:            //private Color m_TooltipBGColor = UIManager.getColor("ToolTip.foreground");
0143:            private Color m_TooltipBGColor = new Color(232, 228, 232); //UIManager.getColor("controlLtHighlight");
0144:
0145:            private EditControlDocumentListener m_docListener = new EditControlDocumentListener();
0146:            private WeakReference m_Parent = null;
0147:
0148:            private int m_SelectionStartPos = 0;
0149:            private int m_SelectionEndPos = 0;
0150:
0151:            private int m_InitialLoc = 0;
0152:
0153:            private boolean m_ShiftDown = false;
0154:            private boolean m_ControlDown = false;
0155:            private int m_LastKey = 0;
0156:            private Color m_BackgroundColor = null;
0157:
0158:            private boolean m_IsMultiline = false;
0159:            private boolean m_ShowTooltips = true;
0160:
0161:            private IStrings m_List = null;
0162:
0163:            // state maintenance variables for in-between InputMethodTextChanged calls
0164:            private int ime_SelectionStartPos = 0;
0165:            private int ime_SelectionEndPos = 0;
0166:            private int ime_InitialLoc = 0;
0167:            private boolean ime_Cached = false;
0168:            private StringBuffer ime_CachedChars = null;
0169:
0170:            /**
0171:             *
0172:             */
0173:            public EditControlImpl(Object parent) {
0174:                //      this();
0175:                //      m_Parent = parent;
0176:                super ();
0177:
0178:                m_Parent = new WeakReference(parent);
0179:                establishPreferences();
0180:                initComponents();
0181:                initControl();
0182:            }
0183:
0184:            public EditControlImpl() {
0185:                super ();
0186:
0187:                establishPreferences();
0188:                initComponents();
0189:                initControl();
0190:            }
0191:
0192:            private void establishPreferences() {
0193:                //kris richards - "ShowEditToolTip" pref expunged. Set to "PSK_YES".
0194:                //this method no longer does anything.
0195:            }
0196:
0197:            private class CutAction extends AbstractAction {
0198:                /* (non-Javadoc)
0199:                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
0200:                 */
0201:                public void actionPerformed(ActionEvent e) {
0202:                    setSel(m_Field.getSelectionStart(), m_Field
0203:                            .getSelectionEnd());
0204:                    m_Translator.cutToClipboard();
0205:                    //         m_Field.paste();
0206:                }
0207:            }
0208:
0209:            private class PasteAction extends AbstractAction {
0210:                /* (non-Javadoc)
0211:                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
0212:                 */
0213:                public void actionPerformed(ActionEvent e) {
0214:                    setSel(m_Field.getSelectionStart(), m_Field
0215:                            .getSelectionEnd());
0216:                    m_Translator.pasteFromClipboard();
0217:                    //         m_Field.paste();
0218:                }
0219:            }
0220:
0221:            protected void initControl() {
0222:                //now instantiate the event dispatcher
0223:                ICoreProduct prod = ProductRetriever.retrieveProduct();
0224:                if (prod != null) {
0225:                    // Get the edit control event dispatcher
0226:                    DispatchHelper disp = new DispatchHelper();
0227:                    IEventDispatcher dispatcher = disp
0228:                            .getEditControlDispatcher();
0229:                    putEventDispatcher(dispatcher);
0230:                }
0231:
0232:                // Added support for copy, cut & paste
0233:                Keymap map = m_Field.getKeymap();
0234:                JTextComponent.loadKeymap(map, defaultBindings, m_Field
0235:                        .getActions());
0236:                {
0237:                    KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_V,
0238:                            InputEvent.CTRL_MASK);
0239:                    map.addActionForKeyStroke(keyStroke, new PasteAction());
0240:                    keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_X,
0241:                            InputEvent.CTRL_MASK);
0242:                    map.addActionForKeyStroke(keyStroke, new CutAction());
0243:
0244:                    m_Field.setKeymap(map);
0245:                }
0246:
0247:                m_Field.addCaretListener(new CaretListener() {
0248:
0249:                    public void caretUpdate(CaretEvent e) {
0250:                        if (m_Translator != null) {
0251:                            if (m_ShowTooltips) {
0252:                                m_Translator.updateHints();
0253:                            }
0254:                        }
0255:                    }
0256:                });
0257:
0258:                //		m_Field.getDocument().addDocumentListener(m_docListener);
0259:
0260:                //I want the tooltips to show continuously.
0261:                ToolTipManager.sharedInstance().setInitialDelay(0);
0262:                ToolTipManager.sharedInstance().setDismissDelay(1000000);
0263:
0264:                m_Field.addFocusListener(new FocusListener() {
0265:
0266:                    public void focusGained(FocusEvent e) {
0267:                        try {
0268:                            showToolTip(e);
0269:                        } catch (Exception exp) {
0270:                            exp.printStackTrace();
0271:                        }
0272:                    }
0273:
0274:                    public void focusLost(FocusEvent e) {
0275:                        hideToolTip(e);
0276:                    }
0277:                });
0278:
0279:                m_Field.addKeyListener(new KeyListener() {
0280:                    //we want this key listener to handle "ENTER" and "ESCAPE" key presses -
0281:                    // "ENTER" - commits the changes
0282:                    // "ESCAPE" - cancels the changes.
0283:
0284:                    public void keyTyped(KeyEvent e) {
0285:                        handleTypedKey(e);
0286:                        e.consume();
0287:                    }
0288:
0289:                    public void keyPressed(KeyEvent e) {
0290:                        handleKeyDown(e);
0291:                        //e.consume();
0292:                    }
0293:
0294:                    public void keyReleased(KeyEvent e) {
0295:                        e.consume();
0296:                        //handleKey(e);
0297:                    }
0298:                });
0299:
0300:                m_Field.addMouseListener(new MouseListener() {
0301:
0302:                    public void mouseClicked(MouseEvent arg0) {
0303:                        //				if (arg0.getClickCount() == 2)
0304:                        //				{
0305:                        //					//some field will be selected, so set the selection start and end accordingly.
0306:                        //					Object source = arg0.getSource();
0307:                        //					if (source != null && source instanceof JTextField)
0308:                        //					{
0309:                        //						JTextField field = (JTextField)source;
0310:                        //						int start = field.getSelectionStart();
0311:                        //						int end = field.getSelectionEnd();
0312:                        //						setSel(start, end);
0313:                        //					}
0314:                        //				}
0315:                        arg0.consume();
0316:                    }
0317:
0318:                    public void mousePressed(MouseEvent arg0) {
0319:                        //I want to set the selection start and end positions if its single click.
0320:                        if (arg0.getClickCount() == 1) {
0321:                            int pos = getCurrentPosition();
0322:                            setSel(pos, pos);
0323:                        }
0324:                    }
0325:
0326:                    public void mouseReleased(MouseEvent arg0) {
0327:                        arg0.consume();
0328:                    }
0329:
0330:                    public void mouseEntered(MouseEvent arg0) {
0331:                        arg0.consume();
0332:                    }
0333:
0334:                    public void mouseExited(MouseEvent arg0) {
0335:                        arg0.consume();
0336:                    }
0337:                });
0338:
0339:                m_Field.addInputMethodListener(this );
0340:            }
0341:
0342:            private void handleTypedKey(KeyEvent e) {
0343:                if (!(e.isAltDown() || e.isControlDown() || e.isMetaDown())) {
0344:                    char ch = e.getKeyChar();
0345:                    if ((int) ch != 8 // don't need backspace key_typed 
0346:                            && (int) ch != 127 // don't need delete key_typed, see 4904441
0347:                            && (int) ch != 10) // don't need enter key_typed either
0348:                    {
0349:                        handleTypedChar(ch);
0350:                    }
0351:                }
0352:            }
0353:
0354:            public void handleTypedChar(char ch) {
0355:                //something is typed
0356:                int currPos = getCurrentPosition();
0357:                m_InitialLoc = getCurrentPosition();
0358:                //System.out.println("handleTypedChar:currPos1="+currPos);
0359:
0360:                IEditControlField field = getCurrentField();
0361:                String toIns = Character.toString(ch);
0362:                //    String toIns = "";
0363:                //      if (e.isShiftDown())
0364:                //      {
0365:                //         toIns = String.valueOf(Character.toString(ch));
0366:                //      }
0367:                //      else
0368:                //      {
0369:                //         toIns = String.valueOf(Character.toLowerCase(ch));
0370:                //      }
0371:                boolean selectedText = false;
0372:                setSel(m_Field.getSelectionStart(), m_Field.getSelectionEnd());
0373:                if (m_SelectionEndPos != m_SelectionStartPos) {
0374:                    selectedText = true;
0375:                    currPos = m_SelectionStartPos;
0376:                }
0377:                if (m_Translator != null) {
0378:                    int index = m_SeparatorList.indexOf(toIns);
0379:                    boolean isHandled = false;
0380:                    if (index >= 0) {
0381:                        isHandled = m_Translator.handleTopLevelSeparators(ch);
0382:                    }
0383:                    if (!isHandled) {
0384:                        isHandled = m_Translator.handleChar(toIns);
0385:
0386:                        if (isHandled) {
0387:                            //if I have handled here, then we are going to move caret position by one.
0388:                            String text = m_Field.getText();
0389:                            if (text != null) {
0390:                                if (selectedText) {
0391:                                    //System.out.println("handleTypedChar:currPos2="+currPos);
0392:                                    m_Field.setCaretPosition(currPos + 1);
0393:                                } else {
0394:                                    if (text.length() > m_InitialLoc) {
0395:                                        //System.out.println("handleTypedChar:m_InitialLoc="+m_InitialLoc);
0396:                                        m_Field
0397:                                                .setCaretPosition(m_InitialLoc + 1);
0398:                                    } else {
0399:                                        m_Field.setCaretPosition(text.length());
0400:                                    }
0401:                                }
0402:                            }
0403:                        }
0404:                    }
0405:                }
0406:            }
0407:
0408:            public void handleKeyDown(int keyCode, int nShift) {
0409:                m_InitialLoc = getCurrentPosition();
0410:                boolean consumeEvent = true;
0411:                boolean selectedText = false;
0412:                if (m_SelectionEndPos != m_SelectionStartPos) {
0413:                    selectedText = true;
0414:                }
0415:                int pos = getCurrentPosition();
0416:                if (keyCode == KeyEvent.VK_ENTER) {
0417:                    //commit the changes to the edit control
0418:                    if (getAssociatedParent() != null) {
0419:                        if (getAssociatedParent() instanceof  ETCompartment) {
0420:                            ((ETCompartment) getAssociatedParent()).save();
0421:                        } else if (getAssociatedParent() instanceof  ProjectTreeCellEditor) {
0422:                            ((ProjectTreeCellEditor) getAssociatedParent())
0423:                                    .stopCellEditing();
0424:                        }
0425:                    }
0426:                    consumeEvent = false;
0427:                } else if (keyCode == KeyEvent.VK_ESCAPE) {
0428:                    //cancel out the changes made to edit control
0429:                    if (getAssociatedParent() != null) {
0430:                        if (getAssociatedParent() instanceof  ETCompartment) {
0431:                            ((ETCompartment) getAssociatedParent())
0432:                                    .cancelEditing();
0433:                        } else if (getAssociatedParent() instanceof  ProjectTreeCellEditor) {
0434:                            ((ProjectTreeCellEditor) getAssociatedParent())
0435:                                    .cancelCellEditing();
0436:                        }
0437:                    }
0438:                    consumeEvent = false;
0439:                } else if (keyCode == KeyEvent.VK_DELETE) {
0440:                    if (m_Translator != null) {
0441:                        m_Translator.handleDelete(true);
0442:
0443:                        //we need to reposition caret at the original position if nothing is selected
0444:                        if (selectedText) {
0445:                            m_Field.setCaretPosition(m_SelectionEndPos);
0446:                        } else {
0447:                            m_Field.setCaretPosition(m_InitialLoc);
0448:                        }
0449:                    }
0450:                } else if (keyCode == KeyEvent.VK_BACK_SPACE) {
0451:                    if (m_Translator != null) {
0452:                        m_Translator.handleDelete(false);
0453:
0454:                        //we need to reposition caret at one less than original position if nothing is selected
0455:                        if (m_InitialLoc > 0) {
0456:                            if (selectedText) {
0457:                                m_Field.setCaretPosition(m_SelectionEndPos);
0458:                            } else {
0459:                                m_Field.setCaretPosition(m_InitialLoc - 1);
0460:                            }
0461:                        } else {
0462:                            m_Field.setCaretPosition(m_InitialLoc);
0463:                        }
0464:                    }
0465:                } else if (keyCode == KeyEvent.VK_RIGHT
0466:                        || keyCode == KeyEvent.VK_LEFT
0467:                        || keyCode == KeyEvent.VK_TAB) {
0468:                    if (m_Translator != null) {
0469:                        m_Translator.handleKeyDown(keyCode);
0470:                    }
0471:                } else if (keyCode == KeyEvent.VK_HOME
0472:                        || keyCode == KeyEvent.VK_END
0473:                        || keyCode == KeyEvent.VK_SHIFT
0474:                        || keyCode == KeyEvent.VK_INSERT
0475:                        || keyCode == KeyEvent.VK_F1
0476:                        || keyCode == KeyEvent.VK_F2
0477:                        || keyCode == KeyEvent.VK_F3
0478:                        || keyCode == KeyEvent.VK_F4
0479:                        || keyCode == KeyEvent.VK_F5
0480:                        || keyCode == KeyEvent.VK_F6
0481:                        || keyCode == KeyEvent.VK_F7
0482:                        || keyCode == KeyEvent.VK_F8
0483:                        || keyCode == KeyEvent.VK_F9
0484:                        || keyCode == KeyEvent.VK_F10
0485:                        || keyCode == KeyEvent.VK_F11
0486:                        || keyCode == KeyEvent.VK_F12
0487:                        || keyCode == KeyEvent.VK_F13
0488:                        || keyCode == KeyEvent.VK_F14
0489:                        || keyCode == KeyEvent.VK_F15
0490:                        || keyCode == KeyEvent.VK_F16
0491:                        || keyCode == KeyEvent.VK_F17
0492:                        || keyCode == KeyEvent.VK_F18
0493:                        || keyCode == KeyEvent.VK_F19
0494:                        || keyCode == KeyEvent.VK_F20
0495:                        || keyCode == KeyEvent.VK_F21
0496:                        || keyCode == KeyEvent.VK_F22
0497:                        || keyCode == KeyEvent.VK_F23
0498:                        || keyCode == KeyEvent.VK_F24
0499:                        || keyCode == KeyEvent.VK_ALT
0500:                        || keyCode == KeyEvent.VK_CONTROL) {
0501:                    consumeEvent = false;
0502:                } else {
0503:                    //we will get here when the edit control is not yet shown but the user keeps typing/ a fast typer.
0504:                    if (m_Translator != null) {
0505:                        if (nShift == 1) {
0506:                            String str = String.valueOf(Character
0507:                                    .toLowerCase((char) keyCode));
0508:                            m_Translator.handleChar(str);
0509:                        } else {
0510:                            String str = String.valueOf(Character
0511:                                    .toString((char) keyCode));
0512:                            m_Translator.handleChar(str);
0513:                        }
0514:                    }
0515:                }
0516:
0517:                //		if (consumeEvent && !e.isConsumed())
0518:                //		{
0519:                //			e.consume();
0520:                //		}
0521:
0522:                //I want to set the selection start and end positions.
0523:                pos = getCurrentPosition();
0524:                setSel(pos, pos);
0525:            }
0526:
0527:            public void handleKeyDown(KeyEvent e) {
0528:                int keyCode = e.getKeyCode();
0529:                m_InitialLoc = getCurrentPosition();
0530:                IEditControlField initField = getCurrentField();
0531:                //in case of mouse selection, we will come here with selected text.
0532:                boolean consumeEvent = true;
0533:                boolean resetSel = true;
0534:                boolean selectedText = false;
0535:                m_ControlDown = e.isControlDown();
0536:                m_ShiftDown = e.isShiftDown();
0537:                m_LastKey = e.getKeyCode();
0538:                int pos = getCurrentPosition();
0539:                if (keyCode == KeyEvent.VK_ENTER) {
0540:                    //if control is down, then we need to show the drop down for type etc.
0541:                    if (isControlDown()) {
0542:                        // handle the hint if
0543:                        handleHint();
0544:                    } else {
0545:                        //commit the changes to the edit control
0546:                        if (getAssociatedParent() != null) {
0547:                            if (getAssociatedParent() instanceof  ETCompartment) {
0548:                                ((ETCompartment) getAssociatedParent()).save();
0549:                            } else if (getAssociatedParent() instanceof  ProjectTreeCellEditor) {
0550:                                if (!((ProjectTreeCellEditor) getAssociatedParent())
0551:                                        .stopCellEditing()) {
0552:                                    //cancel cell editing and go back to prev state.
0553:                                    cancelCellEditing();
0554:                                }
0555:                                IProduct prod = ProductHelper.getProduct();
0556:                                if (prod instanceof  IADProduct) {
0557:                                    IADProduct adProd = (IADProduct) prod;
0558:                                    IProjectTreeControl tree = adProd
0559:                                            .getProjectTree();
0560:                                    if (tree != null) {
0561:                                        tree.refresh(true);
0562:                                    }
0563:                                }
0564:
0565:                            }
0566:                        }
0567:                        consumeEvent = false;
0568:                    }
0569:                } else if (keyCode == KeyEvent.VK_ESCAPE) {
0570:                    //cancel cell editing and go back to prev state.
0571:                    cancelCellEditing();
0572:                    consumeEvent = false;
0573:                } else if (keyCode == KeyEvent.VK_HOME
0574:                        || keyCode == KeyEvent.VK_END
0575:                        || keyCode == KeyEvent.VK_SHIFT
0576:                        || keyCode == KeyEvent.VK_INSERT
0577:                        || keyCode == KeyEvent.VK_F1
0578:                        || keyCode == KeyEvent.VK_F2
0579:                        || keyCode == KeyEvent.VK_F3
0580:                        || keyCode == KeyEvent.VK_F4
0581:                        || keyCode == KeyEvent.VK_F5
0582:                        || keyCode == KeyEvent.VK_F6
0583:                        || keyCode == KeyEvent.VK_F7
0584:                        || keyCode == KeyEvent.VK_F8
0585:                        || keyCode == KeyEvent.VK_F9
0586:                        || keyCode == KeyEvent.VK_F10
0587:                        || keyCode == KeyEvent.VK_F11
0588:                        || keyCode == KeyEvent.VK_F12
0589:                        || keyCode == KeyEvent.VK_F13
0590:                        || keyCode == KeyEvent.VK_F14
0591:                        || keyCode == KeyEvent.VK_F15
0592:                        || keyCode == KeyEvent.VK_F16
0593:                        || keyCode == KeyEvent.VK_F17
0594:                        || keyCode == KeyEvent.VK_F18
0595:                        || keyCode == KeyEvent.VK_F19
0596:                        || keyCode == KeyEvent.VK_F20
0597:                        || keyCode == KeyEvent.VK_F21
0598:                        || keyCode == KeyEvent.VK_F22
0599:                        || keyCode == KeyEvent.VK_F23
0600:                        || keyCode == KeyEvent.VK_F24
0601:                        || keyCode == KeyEvent.VK_ALT
0602:                        || keyCode == KeyEvent.VK_CONTROL) {
0603:                    consumeEvent = false;
0604:                    resetSel = false;
0605:                } else {
0606:                    if (keyCode == KeyEvent.VK_DOWN) {
0607:                        if (m_IsMultiline) {
0608:                            consumeEvent = false;
0609:                            resetSel = false;
0610:                        } else {
0611:                            if (isControlDown()) {
0612:                                handleHint();
0613:                            }
0614:                        }
0615:                    } else if (keyCode == KeyEvent.VK_UP) {
0616:                        if (m_IsMultiline) {
0617:                            consumeEvent = false;
0618:                            resetSel = false;
0619:                        }
0620:                    } else if (keyCode == KeyEvent.VK_RIGHT
0621:                            || keyCode == KeyEvent.VK_LEFT
0622:                            || keyCode == KeyEvent.VK_TAB) {
0623:
0624:                        if (isShiftDown() && (keyCode != KeyEvent.VK_TAB)) {
0625:                            //let the text field handle it.
0626:                            resetSel = false;
0627:                            consumeEvent = false;
0628:                        } else {
0629:                            if (m_IsMultiline) {
0630:                                consumeEvent = false;
0631:                                resetSel = false;
0632:                            } else {
0633:                                if (m_Translator != null) {
0634:                                    if (m_Translator.getEditControl() == null)
0635:                                        m_Translator.setEditControl(this );
0636:                                    m_Translator.handleKeyDown(keyCode);
0637:                                }
0638:                            }
0639:                        }
0640:                    } else if (m_ControlDown) {
0641:                        // The above condition is a HACK to allow copy, cut & paste to work properly.
0642:                        resetSel = false;
0643:                        consumeEvent = false;
0644:                    } else {
0645:                        //we might have something selected on the field, so reset our selection start and end.
0646:                        setSel(m_Field.getSelectionStart(), m_Field
0647:                                .getSelectionEnd());
0648:                        if (m_SelectionEndPos != m_SelectionStartPos) {
0649:                            selectedText = true;
0650:                        }
0651:                        if (keyCode == KeyEvent.VK_DELETE) {
0652:                            if (m_Translator != null) {
0653:                                m_Translator.handleKeyDown(keyCode);
0654:
0655:                                //we need to reposition caret at the original position if nothing was selected to start with.
0656:                                if (selectedText) {
0657:                                    m_Field.setCaretPosition(m_SelectionEndPos);
0658:                                } else {
0659:
0660:                                    //if we have removed the field we started with, I want to position myself
0661:                                    //at the end of previous visible field
0662:                                    if (initField != null) {
0663:                                        if (initField.getVisible()) {
0664:                                            m_Field
0665:                                                    .setCaretPosition(m_InitialLoc);
0666:                                        } else {
0667:                                            m_Field.setCaretPosition(initField
0668:                                                    .getFieldStartPos());
0669:                                        }
0670:                                    }
0671:                                }
0672:                            }
0673:                        } else if (keyCode == KeyEvent.VK_BACK_SPACE) {
0674:                            if (m_Translator != null) {
0675:                                m_Translator.handleKeyDown(keyCode);
0676:
0677:                                //we need to reposition caret at one less than original position if nothing was selected.
0678:                                if (m_InitialLoc > 0) {
0679:                                    if (selectedText) {
0680:                                        m_Field
0681:                                                .setCaretPosition(m_SelectionEndPos);
0682:                                    } else {
0683:                                        //if we have removed the field we started with, I want to position myself
0684:                                        //at the end of previous visible field
0685:                                        if (initField != null) {
0686:                                            if (initField.getVisible()) {
0687:                                                m_Field
0688:                                                        .setCaretPosition(m_InitialLoc - 1);
0689:                                            } else {
0690:                                                m_Field
0691:                                                        .setCaretPosition(initField
0692:                                                                .getFieldStartPos());
0693:                                            }
0694:                                        }
0695:                                    }
0696:                                } else {
0697:                                    m_Field.setCaretPosition(m_InitialLoc);
0698:                                }
0699:                            }
0700:                        } else {
0701:                            //handleTypedKey(e);
0702:                            consumeEvent = false;
0703:                            resetSel = false;
0704:                        }
0705:                    }
0706:                }
0707:
0708:                if (consumeEvent && !e.isConsumed()) {
0709:                    e.consume();
0710:                }
0711:
0712:                if (resetSel) {
0713:                    //I want to set the selection start and end positions.
0714:                    pos = getCurrentPosition();
0715:                    setSel(pos, pos);
0716:                }
0717:            }
0718:
0719:            private void hideToolTip(FocusEvent e) {
0720:                Component other = e.getOppositeComponent();
0721:                if (other == null
0722:                        || (!other.equals(m_Button) && !other.equals(m_Panel) && !other
0723:                                .equals(this ))) {
0724:                    m_TooltipMenu.setBounds(0, 0, 0, 0);
0725:                    m_TooltipMenu.setVisible(false);
0726:                }
0727:            }
0728:
0729:            private void cancelCellEditing() {
0730:                //deactivate the edit control
0731:                deactivate();
0732:
0733:                //cancel out the changes made to edit control
0734:                if (getAssociatedParent() != null) {
0735:                    if (getAssociatedParent() instanceof  ETCompartment) {
0736:                        ((ETCompartment) getAssociatedParent()).cancelEditing();
0737:                    } else if (getAssociatedParent() instanceof  ProjectTreeCellEditor) {
0738:                        ((ProjectTreeCellEditor) getAssociatedParent())
0739:                                .cancelCellEditing();
0740:                    }
0741:                }
0742:
0743:                return;
0744:            }
0745:
0746:            private void showToolTip(FocusEvent e) {
0747:                try {
0748:                    if (m_ShowTooltips) {
0749:                        Point p = e.getComponent().getLocationOnScreen();
0750:
0751:                        FontMetrics metrix = m_Field.getFontMetrics(m_Field
0752:                                .getFont());
0753:                        int fieldHeight = metrix.getHeight();
0754:
0755:                        metrix = m_TooltipMenu.getFontMetrics(m_TooltipMenu
0756:                                .getFont());
0757:                        int width = metrix.stringWidth(m_TooltipText);
0758:                        int height = (int) metrix.getHeight();
0759:
0760:                        m_TooltipMenu.setBounds(p.x, p.y - height - fieldHeight
0761:                                / 2, width, height);
0762:                        m_TooltipMenu.setLocation(p.x, p.y - height
0763:                                - fieldHeight / 2);
0764:                        m_TooltipMenu.setVisible(true);
0765:                        m_TooltipMenu.updateUI();
0766:                    }
0767:                } catch (Exception exc) {
0768:                    //do nothing
0769:                }
0770:            }
0771:
0772:            private void handleFieldModified(DocumentEvent e) {
0773:                try {
0774:                    m_UpdatingField = true;
0775:                    if (m_VeryFirstTime || m_IgnoreTextUpdate) {
0776:                        m_VeryFirstTime = false;
0777:                        return;
0778:                    }
0779:                    int length = e.getLength();
0780:                    int pos = e.getOffset();
0781:                    IEditControlField pField = getCurrentField();
0782:                    if (pField != null) {
0783:                        String text = m_Field.getText();
0784:                        String initText = pField.getText();
0785:                        String newText = "";
0786:                        boolean lastCharDeleted = false;
0787:                        if (e.getType().equals(DocumentEvent.EventType.INSERT)) {
0788:                            m_SelectionStartPos = pos;
0789:                            m_SelectionEndPos = pos;
0790:                            //process the insert of text
0791:                            String changedText = text.substring(pos, pos
0792:                                    + length);
0793:
0794:                            //there is a possibility that user is entering an optional field
0795:                            int nEnd = pField.getTextEndPos();
0796:                            boolean isHandled = false;
0797:                            if (m_Translator != null) {
0798:                                char toIns = changedText.charAt(0);
0799:                                int index = m_SeparatorList.indexOf(toIns);
0800:                                if (index >= 0) {
0801:                                    isHandled = m_Translator
0802:                                            .handleTopLevelSeparators(changedText
0803:                                                    .charAt(0));
0804:                                }
0805:                                if (!isHandled) {
0806:                                    isHandled = m_Translator
0807:                                            .handleChar(changedText);
0808:                                }
0809:                            }
0810:
0811:                            if (!isHandled) {
0812:                                if (pos >= nEnd) {
0813:                                } else {
0814:                                    if (changedText.trim().length() > 0) {
0815:                                        String leftText = "";
0816:                                        String rightText = "";
0817:                                        int nStart = pField.getTextStartPos();
0818:                                        //we might be adding value for a new field in which case
0819:                                        //initText will be "".
0820:                                        if (pos > nStart
0821:                                                && initText.length() > (pos - nStart)) {
0822:                                            leftText = initText.substring(0,
0823:                                                    pos - nStart);
0824:                                            rightText = initText.substring(pos
0825:                                                    - nStart);
0826:                                        } else if (pos == nStart) {
0827:                                            //we are adding somthing to the start of this field
0828:                                            rightText = initText;
0829:                                        }
0830:                                        newText = leftText + changedText
0831:                                                + rightText;
0832:                                        pField.setText(newText);
0833:                                    }
0834:                                }
0835:                            }
0836:                        } else if (e.getType().equals(
0837:                                DocumentEvent.EventType.REMOVE)) {
0838:                            if (m_Translator != null) {
0839:                                m_SelectionStartPos = pos;
0840:                                m_SelectionEndPos = pos + length;
0841:                                m_Translator.handleChar("");
0842:                            } else {
0843:                                //process the remove of text
0844:                                String leftText = "";
0845:                                String rightText = "";
0846:                                int nStart = pField.getTextStartPos();
0847:                                //if this is the last character in this field that is removed,
0848:                                //I cannot do proper substrings
0849:                                if (pos >= nStart) {
0850:                                    leftText = initText.substring(0, pos
0851:                                            - nStart);
0852:                                }
0853:                                if (initText.length() >= (pos - nStart + length)) {
0854:                                    rightText = initText.substring(pos - nStart
0855:                                            + length);
0856:                                }
0857:                                newText = leftText + rightText;
0858:                                if (newText.length() == 0) {
0859:                                    lastCharDeleted = true;
0860:                                }
0861:                                pField.setText(newText);
0862:                            }
0863:                        }
0864:
0865:                        if (!m_Modified) {
0866:                            setModified(true);
0867:                        }
0868:
0869:                        //I need to move all the fields after this field, so that
0870:                        //they have right Text and Field positions
0871:                        if (m_Translator != null) {
0872:                            m_Translator.updateFieldPositions(pField);
0873:                        }
0874:                    }
0875:                } catch (Exception exc) {
0876:                    exc.printStackTrace();
0877:                } finally {
0878:                    m_UpdatingField = false;
0879:                }
0880:            }
0881:
0882:            //DefaultStyledDocument doc = new DefaultStyledDocument();
0883:
0884:            private void initComponents() {
0885:                setOpaque(false);
0886:                setBorder(null);
0887:                m_Panel = new JPanel();
0888:                m_Panel.setBorder(null);
0889:                m_Panel.setLayout(null);
0890:                m_Panel.setOpaque(false);
0891:                //m_Panel.setPreferredSize(new Dimension(200, 3));
0892:
0893:                m_TooltipMenu = new JPopupMenu();
0894:                m_TooltipMenu.setBackground(m_TooltipBGColor);
0895:                m_TooltipMenu.setOpaque(true);
0896:                m_TooltipMenu.setBorder(LineBorder.createGrayLineBorder());
0897:                m_TooltipMenu.setAlignmentX(0);
0898:                m_TooltipMenu.setAlignmentY(0);
0899:                //m_TooltipMenu.setLayout(null);
0900:                m_TooltipMenu.setBounds(0, 0, 0, 0);
0901:
0902:                ICompartment compartment = null;
0903:
0904:                setLayout(new BorderLayout());
0905:                if (getAssociatedParent() instanceof  ICompartment) {
0906:                    compartment = (ETCompartment) getAssociatedParent();
0907:                    if (compartment.getTextWrapping() == true) {
0908:                        // Fixed 115914.
0909:                        //JTextArea area = new JTextArea(doc);
0910:                        JTextArea area = new JTextArea();
0911:                        area.setLineWrap(true);
0912:                        area.setWrapStyleWord(true);
0913:                        m_Field = area;
0914:
0915:                        m_IsMultiline = true;
0916:
0917:                        JScrollPane scrollPane = new JScrollPane(m_Field);
0918:                        scrollPane
0919:                                .setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
0920:                        scrollPane
0921:                                .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
0922:                        scrollPane.setBorder(null);
0923:
0924:                        scrollPane
0925:                                .setVerticalScrollBar(new javax.swing.JScrollBar() {
0926:                                    public java.awt.Dimension getPreferredSize() {
0927:                                        return new java.awt.Dimension(0, 0);
0928:                                    }
0929:
0930:                                    public java.awt.Dimension getMinimumSize() {
0931:                                        return new java.awt.Dimension(0, 0);
0932:                                    }
0933:
0934:                                    public java.awt.Dimension getMaximumSize() {
0935:                                        return new java.awt.Dimension(0, 0);
0936:                                    }
0937:                                });
0938:                        add(scrollPane, BorderLayout.CENTER);
0939:
0940:                    } else {
0941:                        JTextField field = new JTextField();
0942:                        // field.setDocument(doc);
0943:                        // field.setHorizontalAlignment(javax.swing.JTextField.CENTER);
0944:                        m_Field = field;
0945:                        add(m_Field, BorderLayout.CENTER);
0946:                    }
0947:                } else {
0948:                    m_Field = new JTextField();
0949:                    add(m_Field, BorderLayout.CENTER);
0950:                }
0951:                m_Field.setBorder(null);
0952:
0953:                m_Button = new JButton();
0954:                m_Button.setEnabled(true);
0955:                m_Button.setPreferredSize(new Dimension(2, 2));
0956:                m_Button.setOpaque(false);
0957:                m_Button.setBackground(m_TooltipBGColor);
0958:                m_Button.setFocusable(false); //I do not want this button to steal focus from the field
0959:                final Point p = this .getLocation();
0960:                final Component comp = this ;
0961:                m_Button.addActionListener(new ActionListener() {
0962:
0963:                    public void actionPerformed(ActionEvent e) {
0964:                        handleHint();
0965:                    }
0966:                });
0967:
0968:                m_Button.setBounds(0, 0, 15, 3);
0969:                add(m_Panel, BorderLayout.SOUTH);
0970:                m_Panel.setBounds(0, 0, 200, 3);
0971:                m_Panel.setOpaque(false);
0972:            }
0973:
0974:            public void setCaretPosition(int pos) {
0975:                m_Field.setCaretPosition(pos);
0976:            }
0977:
0978:            /* (non-Javadoc)
0979:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setAutoSize(boolean)
0980:             */
0981:            public void setAutoSize(boolean value) {
0982:                // TODO Auto-generated method stub
0983:
0984:            }
0985:
0986:            /* (non-Javadoc)
0987:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getAutoSize()
0988:             */
0989:            public boolean getAutoSize() {
0990:                // TODO Auto-generated method stub
0991:                return false;
0992:            }
0993:
0994:            /* (non-Javadoc)
0995:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setrefFont(java.awt.Font)
0996:             */
0997:            public void setrefFont(Font value) {
0998:                // TODO Auto-generated method stub
0999:
1000:            }
1001:
1002:            /* (non-Javadoc)
1003:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setHFont(int)
1004:             */
1005:            public void setHFont(int value) {
1006:                // TODO Auto-generated method stub
1007:
1008:            }
1009:
1010:            /* (non-Javadoc)
1011:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getBackColor()
1012:             */
1013:            public void getBackColor() {
1014:                // TODO Auto-generated method stub
1015:
1016:            }
1017:
1018:            /* (non-Javadoc)
1019:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setrefBackColor(long)
1020:             */
1021:            public void setrefBackColor(long value) {
1022:                // TODO Auto-generated method stub
1023:
1024:            }
1025:
1026:            /* (non-Javadoc)
1027:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setBackColor(long)
1028:             */
1029:            public void setBackColor(long value) {
1030:                // TODO Auto-generated method stub
1031:
1032:            }
1033:
1034:            /* (non-Javadoc)
1035:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getForeColor()
1036:             */
1037:            public Color getForeColor() {
1038:                Color retVal = null;
1039:
1040:                if (m_Field != null) {
1041:                    retVal = m_Field.getForeground();
1042:                }
1043:
1044:                return retVal;
1045:            }
1046:
1047:            /* (non-Javadoc)
1048:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setForeColor(long)
1049:             */
1050:            public void setForeColor(Color value) {
1051:                if (m_Field != null) {
1052:                    m_Field.setForeground(value);
1053:                }
1054:            }
1055:
1056:            /* (non-Javadoc)
1057:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setrefForeColor(long)
1058:             */
1059:            public void setrefForeColor(long value) {
1060:                // TODO Auto-generated method stub
1061:
1062:            }
1063:
1064:            /* (non-Javadoc)
1065:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#activate(int, int)
1066:             */
1067:            public void activate(int KeyCode, int nPos) {
1068:                // TODO Auto-generated method stub
1069:
1070:            }
1071:
1072:            /**
1073:             * Deactivate the edit control
1074:             */
1075:            public void deactivate() {
1076:                // prevent recursion
1077:                boolean bInDeactivate = false;
1078:                if (!bInDeactivate) {
1079:                    bInDeactivate = true;
1080:
1081:                    // notify listeners we're shutting down
1082:                    if (m_EventDispatcher != null) {
1083:                        IEditEventPayload payload = m_EventDispatcher
1084:                                .createEventPayload();
1085:                        if (payload != null) {
1086:                            String sText = getText();
1087:                            payload.setKey(m_LastKey);
1088:                            payload.setModified(getModified());
1089:                            payload.setText(sText);
1090:                        }
1091:                        m_EventDispatcher.fireDeactivate(this , payload);
1092:                        m_EventDispatcher = null;
1093:                    }
1094:
1095:                    // Fix for Sun issue #6185901:
1096:                    // When the edit control is completed it needs to remove the key bindings so that,
1097:                    // in this issue as an example, the paste operation is not handled by this edit control.
1098:
1099:                    // Remove our key bindings
1100:                    m_Field.getKeymap().removeBindings();
1101:                }
1102:            }
1103:
1104:            /**
1105:             * Returns the translator attached to this control.
1106:             *
1107:             * @param pTranslator
1108:             */
1109:            public ITranslator getTranslator() {
1110:                return m_Translator;
1111:            }
1112:
1113:            /**
1114:             * Attaches a translator to this control.
1115:             *
1116:             * @param pTranslator
1117:             */
1118:            public void setTranslator(ITranslator pTranslator) {
1119:                // set our translator then set reverse pointer
1120:                m_Translator = pTranslator;
1121:
1122:                m_Translator.setEditControl(this );
1123:                String str = m_Field.getText();
1124:                m_InitialData = str;
1125:                m_Modified = false;
1126:            }
1127:
1128:            /* (non-Javadoc)
1129:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getMultiline()
1130:             */
1131:            public boolean getMultiline() {
1132:                return m_IsMultiline;
1133:            }
1134:
1135:            public int getSelStartPos() {
1136:                if (m_SelectionStartPos >= 0) {
1137:                    return m_SelectionStartPos;
1138:                } else {
1139:                    return getCurrentPosition();
1140:                }
1141:            }
1142:
1143:            public int getSelEndPos() {
1144:                if (m_SelectionEndPos >= 0) {
1145:                    return m_SelectionEndPos;
1146:                } else {
1147:                    return getCurrentPosition();
1148:                }
1149:            }
1150:
1151:            /* (non-Javadoc)
1152:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getSel(int, int)
1153:             */
1154:            public long getSel(int nStartChar, int nEndChar) {
1155:                // TODO Auto-generated method stub
1156:                return 0;
1157:            }
1158:
1159:            /* (non-Javadoc)
1160:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setSel(int, int)
1161:             */
1162:            public long setSel(int startPos, int endPos) {
1163:                //if (m_Modified)
1164:                {
1165:                    m_Field.setSelectionStart(startPos);
1166:                    m_Field.setSelectionEnd(endPos);
1167:                    m_SelectionStartPos = startPos;
1168:                    m_SelectionEndPos = endPos;
1169:                }
1170:                return 0;
1171:            }
1172:
1173:            /* (non-Javadoc)
1174:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#replaceSel(java.lang.String)
1175:             */
1176:            public void replaceSel(String sText) {
1177:                // TODO Auto-generated method stub
1178:
1179:            }
1180:
1181:            /**
1182:             * Establishes the control's event dispatcher (used internally only).
1183:             *
1184:             * @param pDispatcher
1185:             */
1186:            public void putEventDispatcher(IEventDispatcher pDispatcher) {
1187:                m_EventDispatcher = null;
1188:                if (pDispatcher != null
1189:                        && pDispatcher instanceof  IEditControlEventDispatcher) {
1190:                    m_EventDispatcher = (IEditControlEventDispatcher) pDispatcher;
1191:                }
1192:            }
1193:
1194:            /**
1195:             * Gets the control's event dispatcher (used internally only).
1196:             *
1197:             * @param pDispatcher
1198:             */
1199:            public IEventDispatcher getEventDispatcher() {
1200:                return m_EventDispatcher;
1201:            }
1202:
1203:            /* (non-Javadoc)
1204:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getModified()
1205:             */
1206:            public boolean getModified() {
1207:                return m_Modified;
1208:            }
1209:
1210:            /* (non-Javadoc)
1211:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setModified(boolean)
1212:             */
1213:            public void setModified(boolean value) {
1214:                m_Modified = value;
1215:            }
1216:
1217:            /* (non-Javadoc)
1218:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#lineLength(int)
1219:             */
1220:            public int lineLength(int nLine) {
1221:                // TODO Auto-generated method stub
1222:                return 0;
1223:            }
1224:
1225:            /* (non-Javadoc)
1226:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#lineIndex(int)
1227:             */
1228:            public int lineIndex(int nLine) {
1229:                // TODO Auto-generated method stub
1230:                return 0;
1231:            }
1232:
1233:            /* (non-Javadoc)
1234:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getStyle()
1235:             */
1236:            public int getStyle() {
1237:
1238:                return 0;
1239:            }
1240:
1241:            /* (non-Javadoc)
1242:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setStyle(int)
1243:             */
1244:            public void setStyle(long value) {
1245:                if (m_Field instanceof  JTextField) {
1246:                    JTextField field = (JTextField) m_Field;
1247:                    int alignment = JTextField.LEFT;
1248:                    if ((value & IADEditableCompartment.RIGHT) == IADEditableCompartment.RIGHT) {
1249:                        alignment = JTextField.RIGHT;
1250:                    } else if ((value & IADCompartment.CENTER) == IADCompartment.CENTER) {
1251:                        alignment = JTextField.CENTER;
1252:                    }
1253:
1254:                    field.setHorizontalAlignment(alignment);
1255:                }
1256:            }
1257:
1258:            /**
1259:             * Updates the control's window with the current contents of the translator.
1260:             *
1261:             * @return HRESULT
1262:             */
1263:            public void refresh() {
1264:                if (m_Translator != null) {
1265:                    m_Translator.updateFieldPositions(null);
1266:                    String str = m_Translator.getCurrent();
1267:                    setText(str);
1268:                }
1269:            }
1270:
1271:            /* (non-Javadoc)
1272:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getOverstrike()
1273:             */
1274:            public boolean getOverstrike() {
1275:                // TODO Auto-generated method stub
1276:                return false;
1277:            }
1278:
1279:            /* (non-Javadoc)
1280:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setOverstrike(boolean)
1281:             */
1282:            public void setOverstrike(boolean value) {
1283:                // TODO Auto-generated method stub
1284:
1285:            }
1286:
1287:            /* (non-Javadoc)
1288:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getTooltipText(java.lang.StringBuffer, java.lang.StringBuffer, java.lang.StringBuffer)
1289:             */
1290:            public long getTooltipText(StringBuffer sLeft,
1291:                    StringBuffer sSubject, StringBuffer sRight) {
1292:                // TODO Auto-generated method stub
1293:                return 0;
1294:            }
1295:
1296:            /**
1297:             *
1298:             * Update the tooltip's text.  If all 3 text parts are empty the tooltip window is dismissed.
1299:             *
1300:             * @param sLeft Left part of the tooltip text
1301:             * @param sSubject Subject part, this will be displayed in a bold font
1302:             * @param sRight Right part of the tooltip text.
1303:             *
1304:             * @return HRESULT
1305:             *
1306:             */
1307:            public void setTooltipText(String sLeft, String sSubject,
1308:                    String sRight) {
1309:                sLeft = StringUtilities
1310:                        .replaceAllSubstrings(sLeft, "<", "&lt;");
1311:                sSubject = StringUtilities.replaceAllSubstrings(sSubject, "<",
1312:                        "&lt;");
1313:                sRight = StringUtilities.replaceAllSubstrings(sRight, "<",
1314:                        "&lt;");
1315:                sLeft = StringUtilities
1316:                        .replaceAllSubstrings(sLeft, ">", "&gt;");
1317:                sSubject = StringUtilities.replaceAllSubstrings(sSubject, ">",
1318:                        "&gt;");
1319:                sRight = StringUtilities.replaceAllSubstrings(sRight, ">",
1320:                        "&gt;");
1321:                String tooltip = "<html>" + sLeft + "<b>" + sSubject + "</b>"
1322:                        + sRight + "</html>";
1323:
1324:                //m_Field.setToolTipText(tooltip);
1325:                m_TooltipText = tooltip;
1326:
1327:                //tooltip = sLeft + "<b>" + sSubject + "</b>" + sRight;
1328:
1329:                Point p = this .getLocation();
1330:                if (m_LocationOnScreen != null) {
1331:                    p = m_LocationOnScreen;
1332:                }
1333:                m_TooltipMenu.removeAll();
1334:                Font f = m_TooltipMenu.getFont();
1335:
1336:                m_TooltipMenu.setFont(f.deriveFont(Font.PLAIN));
1337:                JMenuItem item = m_TooltipMenu.add(tooltip);
1338:                item.setFont(f.deriveFont(Font.PLAIN));
1339:                item.setAlignmentX(0);
1340:                item.setAlignmentY(0);
1341:                item.setBorder(null);
1342:                item.setBackground(m_TooltipBGColor);
1343:                FontMetrics metrix = item.getFontMetrics(item.getFont());
1344:                int width = metrix.stringWidth(tooltip);
1345:
1346:                item.setOpaque(false);
1347:                p = m_TooltipMenu.getLocation();
1348:                if (p != null) {
1349:                    m_TooltipMenu.setBounds(p.x, p.y - metrix.getHeight(),
1350:                            width, metrix.getHeight());
1351:                    IEditControlField pField = m_Translator.getCurrentField();
1352:                    if (pField != null) {
1353:                        int nStart = pField.getTextStartPos();
1354:                        int nEnd = pField.getTextEndPos();
1355:                        int curPos = getCurrentPosition();
1356:
1357:                        if ((curPos == nStart) || (curPos == nEnd)) {
1358:                            //There is potentially tooltip length change, so update its size
1359:                            //till I hide and reshow the tooltip, size does not change.
1360:                            //m_TooltipMenu.setVisible(false);
1361:                            //m_TooltipMenu.setVisible(true);
1362:                        }
1363:                    }
1364:
1365:                    //m_TooltipMenu.setPreferredSize(new Dimension(width,20));
1366:                    //m_TooltipMenu.updateUI();
1367:                }
1368:
1369:                //if (!m_TooltipMenu.isVisible())
1370:                //{
1371:                //	m_TooltipMenu.setVisible(true);
1372:                //}
1373:            }
1374:
1375:            /* (non-Javadoc)
1376:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setEnableTooltip(boolean)
1377:             */
1378:            public void setEnableTooltip(boolean value) {
1379:                m_ShowTooltips = value;
1380:                m_TooltipMenu.setVisible(value);
1381:            }
1382:
1383:            /**
1384:             * Force the tooltip to be re-loaded and re-displayed.
1385:             *
1386:             * @return HRESULT
1387:             */
1388:            public void updateToolTip() {
1389:                if (m_Translator != null) {
1390:                    if (m_ShowTooltips) {
1391:                        m_Translator.updateToolTip();
1392:                    }
1393:                }
1394:            }
1395:
1396:            /* (non-Javadoc)
1397:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setCurrentPosition(int)
1398:             */
1399:            public void setCurrentPosition(int value) {
1400:                String text = m_Field.getText();
1401:                if (text != null && text.length() >= value) {
1402:                    m_Field.setCaretPosition(value);
1403:                }
1404:            }
1405:
1406:            /* (non-Javadoc)
1407:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getCurrentPosition()
1408:             */
1409:            public int getCurrentPosition() {
1410:                return m_Field.getCaretPosition();
1411:            }
1412:
1413:            /* (non-Javadoc)
1414:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getAutoExpand()
1415:             */
1416:            public boolean getAutoExpand() {
1417:                // TODO Auto-generated method stub
1418:                return false;
1419:            }
1420:
1421:            /* (non-Javadoc)
1422:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#setAutoExpand(boolean)
1423:             */
1424:            public void setAutoExpand(boolean value) {
1425:                // TODO Auto-generated method stub
1426:
1427:            }
1428:
1429:            /* (non-Javadoc)
1430:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#showHintBar(int)
1431:             */
1432:            public void showHintBar(int nPos) {
1433:                FontMetrics metrix = m_Field.getFontMetrics(m_Field.getFont());
1434:                String text = m_Field.getText();
1435:                int length = 0;
1436:                if (text != null && text.length() >= nPos) {
1437:                    String str = text.substring(0, nPos);
1438:                    length = metrix.stringWidth(str);
1439:                }
1440:                m_Panel.removeAll();
1441:                m_Panel.setBounds(0, 0, 200, 3);
1442:                m_Panel.repaint();
1443:                m_Button.setBounds(length, 0, 15, 3);
1444:                m_Panel.add(m_Button);
1445:                if (m_BackgroundColor != null) {
1446:                    m_Panel.setForeground(m_BackgroundColor);
1447:                    m_Panel.setBackground(m_BackgroundColor);
1448:                    m_Panel.setUI(this .getUI());
1449:                }
1450:                m_Panel.invalidate();
1451:                m_Panel.repaint();
1452:            }
1453:
1454:            /*
1455:             * hides the hint bar
1456:             */
1457:            public void hideHintBar() {
1458:                m_Panel.removeAll();
1459:                m_Panel.invalidate();
1460:                m_Panel.repaint();
1461:                if (m_BackgroundColor != null) {
1462:                    m_Panel.setForeground(m_BackgroundColor);
1463:                    m_Panel.setBackground(m_BackgroundColor);
1464:                    m_Panel.setUI(this .getUI());
1465:                }
1466:                m_Panel.setBounds(0, 0, 200, 3);
1467:                m_Panel.repaint();
1468:                //m_Button.reshape(0,0,0,0);
1469:                //m_Panel.add(m_Button);
1470:            }
1471:
1472:            /**
1473:             * Deactivate the edit control and save any information
1474:             * edited by user.
1475:             */
1476:            public void handleSave() {
1477:                m_TooltipMenu.setVisible(false);
1478:                boolean bModified = getModified();
1479:                if (m_Translator != null && bModified) {
1480:                    m_Translator.saveModelElement();
1481:                }
1482:
1483:                //get related element and see if the change was really made
1484:                //if the element name did not change we have a problem, in which case,
1485:                //revert back to the old name
1486:                String sText = getText();
1487:                if (m_Translator != null) {
1488:                    Object object = m_Translator.getElement();
1489:                    if (object instanceof  INamedElement) {
1490:                        INamedElement element = (INamedElement) object;
1491:                        String name = element.getName();
1492:                        if (!name.equals(sText)) {
1493:                            setText(name);
1494:                        }
1495:                    }
1496:                }
1497:
1498:                // Fix for Sun issue #6185901:
1499:                // When the edit control is completed it needs to deactivate so
1500:                // that, in this issue as an example, the paste operation is
1501:                // not handled by this edit control.
1502:                // Before fixing this issue there was code to call
1503:                // m_EventDispatcher.fireDeactivate(), but that is no longer necessary
1504:                // since that code is in deactivate().
1505:
1506:                // notify listeners we're shutting down
1507:                deactivate();
1508:            }
1509:
1510:            public void handleRollback() {
1511:                m_TooltipMenu.setVisible(false);
1512:            }
1513:
1514:            /* (non-Javadoc)
1515:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#handleHint()
1516:             */
1517:            public void handleHint() {
1518:                if (m_Translator != null) {
1519:                    m_Translator.handleHint();
1520:                }
1521:            }
1522:
1523:            /* (non-Javadoc)
1524:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#displayList(boolean, com.embarcadero.describe.umlsupport.IStrings, int, java.lang.String)
1525:             */
1526:            public void displayList(boolean bList, IStrings pList, int nStart,
1527:                    String sInitialText) {
1528:                if (pList != null) {
1529:                    long count = pList.getCount();
1530:                    JPopupMenu menu = new JPopupMenu();
1531:                    if (count > 0) {
1532:                        boolean addMoreItems = false;
1533:                        if (count > 25) {
1534:                            count = 25;
1535:                            addMoreItems = true;
1536:                            m_List = pList;
1537:                        }
1538:                        for (int i = 0; i < count; i++) {
1539:                            String str = pList.item(i);
1540:                            //menu.add(str);
1541:                            JMenuItem item = new JMenuItem(str);
1542:                            item.addActionListener(new ActionListener() {
1543:
1544:                                public void actionPerformed(ActionEvent e) {
1545:                                    performActionOnMenuItemSelected(e);
1546:                                }
1547:                            });
1548:                            menu.add(item);
1549:                        }
1550:
1551:                        if (addMoreItems) {
1552:                            JMenuItem item = new JMenuItem(
1553:                                    DrawingPropertyResource
1554:                                            .getString("IDS_MOREITEMS"));
1555:                            item.addActionListener(new ActionListener() {
1556:
1557:                                public void actionPerformed(ActionEvent e) {
1558:                                    performActionOnMenuItemSelected(e);
1559:                                }
1560:                            });
1561:                            menu.add(item);
1562:                        }
1563:                    }
1564:                    Point p = m_Button.getLocation();
1565:                    //menu.show(this, p.x, p.y+20);
1566:                    menu.show(m_Button, 0, 0);
1567:                }
1568:            }
1569:
1570:            private String showSelectDialog() {
1571:                String retVal = "";
1572:                EditControlClassChooser chooser = new EditControlClassChooser(
1573:                        m_List);
1574:                retVal = chooser.selectClass();
1575:                return retVal;
1576:            }
1577:
1578:            public void performActionOnMenuItemSelected(ActionEvent e) {
1579:                Object obj = e.getSource();
1580:                if (obj != null) {
1581:                    String newText = ((JMenuItem) obj).getText();
1582:
1583:                    if (newText != null
1584:                            && newText.equals(DrawingPropertyResource
1585:                                    .getString("IDS_MOREITEMS"))) {
1586:                        //show a dialog to the user listing all the types found.
1587:                        newText = showSelectDialog();
1588:                    }
1589:
1590:                    if (m_Translator != null && newText != null
1591:                            && newText.length() > 0) {
1592:                        IEditControlField pField = m_Translator
1593:                                .handleHintText(newText);
1594:
1595:                        if (pField != null) {
1596:                            int nStart = pField.getTextStartPos();
1597:                            int nEnd = pField.getTextEndPos();
1598:                            //update the value on IEditControlField
1599:                            //pField.setText(newText);
1600:                            if (!m_Modified) {
1601:                                setModified(true);
1602:                            }
1603:
1604:                            //also update the text on the Edit control display
1605:                            String currText = m_Field.getText();
1606:                            String textToDisplay = currText
1607:                                    .substring(0, nStart)
1608:                                    + newText + currText.substring(nEnd);
1609:
1610:                            //since I am going to set whole text for this edit field, I
1611:                            //somehow need to ignore update of the EditcontrolFields
1612:                            setText(textToDisplay);
1613:
1614:                            //I need to move all the fields after this field, so that
1615:                            //they have right Text and Field positions
1616:                            if (m_Translator != null) {
1617:                                m_Translator.updateFieldPositions(pField);
1618:                            }
1619:
1620:                            //now I want to reset my cursor to the end of this field's end pos
1621:                            int newPos = pField.getTextEndPos();
1622:                            m_Field.setCaretPosition(newPos);
1623:                            setSel(newPos, newPos);
1624:                        }
1625:                    }
1626:                }
1627:            }
1628:
1629:            /* (non-Javadoc)
1630:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getCurrentField()
1631:             */
1632:            public IEditControlField getCurrentField() {
1633:                IEditControlField retField = null;
1634:                if (m_Translator != null) {
1635:                    retField = m_Translator.getCurrentField();
1636:                }
1637:                return retField;
1638:            }
1639:
1640:            /* (non-Javadoc)
1641:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#registerAccelerator(int, long)
1642:             */
1643:            public void registerAccelerator(int nChar, long nModifier) {
1644:                // TODO Auto-generated method stub
1645:
1646:            }
1647:
1648:            /**
1649:             * Sets the element this edit control will edit.
1650:             *
1651:             * @param pElement [in] The edit control
1652:             */
1653:            public void setElement(IElement pElement) {
1654:                // I need to block all the events at this point, so that while building property elements, we do not
1655:                //fire events.
1656:                boolean origVal = EventBlocker.startBlocking();
1657:                try {
1658:                    //we do not want to show tooltips if we are editing a classifier or activity node or package.
1659:                    if (pElement instanceof  IClassifier
1660:                            || pElement instanceof  IActivityNode
1661:                            || pElement instanceof  IPackage) {
1662:                        setEnableTooltip(false);
1663:                    }
1664:                    m_Translator = new TranslatorImpl();
1665:                    m_Translator.setElement(pElement);
1666:                    setTranslator(m_Translator);
1667:                    m_Translator.setEditControl(this );
1668:
1669:                    if (pElement instanceof  IComment) {
1670:                        //this will select the comment text
1671:                        getCommentField();
1672:                    } else if (pElement instanceof  ILifeline) {
1673:                        //this will select the comment text
1674:                        getRepClassifierField();
1675:                    } else {
1676:                        //this will select the name text.
1677:                        IEditControlField nameField = getNameField();
1678:                        if (nameField == null) {
1679:                            //we could not find a name field to select so select the first field.
1680:                            if (m_Translator != null) {
1681:                                IEditControlField field = m_Translator
1682:                                        .getNextField(null);
1683:                                if (field != null) {
1684:                                    int startPos = field.getTextStartPos();
1685:                                    int endPos = field.getTextEndPos();
1686:                                    setSel(startPos, endPos);
1687:                                }
1688:                            }
1689:                        }
1690:                    }
1691:                    //m_Field.setCaretPosition(nameField.getTextEndPos());
1692:                } finally {
1693:                    EventBlocker.stopBlocking(origVal);
1694:                }
1695:            }
1696:
1697:            /**
1698:             * A list of separator characters used by the fields
1699:             * @param sList
1700:             *
1701:             * @return HRESULT
1702:             */
1703:            public String getSeparatorList() {
1704:                return m_SeparatorList;
1705:            }
1706:
1707:            /**
1708:             * A list of separator characters used by the fields
1709:             * @param sList
1710:             *
1711:             * @return HRESULT
1712:             */
1713:            public void setSeparatorList(String sList) {
1714:                m_SeparatorList = sList;
1715:            }
1716:
1717:            /* (non-Javadoc)
1718:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#calcNewPos(int)
1719:             */
1720:            public int calcNewPos(int changeLineBy) {
1721:                // TODO Auto-generated method stub
1722:                return 0;
1723:            }
1724:
1725:            /* (non-Javadoc)
1726:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getText()
1727:             */
1728:            public String getText() {
1729:                // TODO Auto-generated method stub
1730:                return m_Field.getText();
1731:            }
1732:
1733:            /*
1734:             * sets the text that is displayed on the edit control.
1735:             * While setting the text, change events are fired,
1736:             * I need to prevent them so am setting ignoreTextUpdate.
1737:             */
1738:            public void setText(String value) {
1739:                try {
1740:                    if (m_UpdatingField) {
1741:                        final String str = value;
1742:                        //we are right now updating the text, so do invokeLater
1743:                        SwingUtilities.invokeLater(new Runnable() {
1744:
1745:                            public void run() {
1746:                                if (m_Translator != null) {
1747:                                    IEditControlField pField = m_Translator
1748:                                            .getCurrentField();
1749:                                    int pos = getCurrentPosition();
1750:                                    if (pField != null) {
1751:                                        String name = pField.getName();
1752:                                        int nStart = pField
1753:                                                .getLastTextStartPos();
1754:                                        if (nStart != pos) {
1755:                                            pos = nStart;
1756:                                        }
1757:                                    }
1758:                                    m_IgnoreTextUpdate = true;
1759:                                    m_Field.setText(str);
1760:                                    m_IgnoreTextUpdate = false;
1761:                                    setCaretPosition(pos);
1762:                                }
1763:                            }
1764:                        });
1765:
1766:                    } else {
1767:                        m_Field.setText(value);
1768:                        //select the name field
1769:                        getNameField();
1770:                    }
1771:                } catch (Exception e) {
1772:                    e.printStackTrace();
1773:                }
1774:            }
1775:
1776:            public void setCharacter(int nKeyCode, int nShift) {
1777:                //if we are editing a lifeline we need to select the representing classifier.
1778:                IEditControlField field = null;
1779:                if (m_Translator != null) {
1780:                    IElement pEle = m_Translator.getElement();
1781:                    if (pEle != null && pEle instanceof  ILifeline) {
1782:                        field = getRepClassifierField();
1783:                    }
1784:                }
1785:                if (field == null) {
1786:                    field = getNameField();
1787:                    if (field == null) {
1788:                        //try to see if this is a comment field
1789:                        field = getCommentField();
1790:
1791:                        if (field == null) {
1792:                            //we want to select the first field
1793:                            if (m_Translator != null) {
1794:                                field = m_Translator.getNextField(null);
1795:                                if (field != null) {
1796:                                    int startPos = field.getTextStartPos();
1797:                                    int endPos = field.getTextEndPos();
1798:                                    setSel(startPos, endPos);
1799:                                }
1800:                            }
1801:                        }
1802:                    }
1803:                }
1804:
1805:                if (field != null) {
1806:                    String str = "";
1807:                    if (nShift == 1) {
1808:                        str = String.valueOf(Character
1809:                                .toLowerCase((char) nKeyCode));
1810:                    } else {
1811:                        str = String.valueOf(Character
1812:                                .toString((char) nKeyCode));
1813:                    }
1814:
1815:                    ITranslator pTrans = getTranslator();
1816:                    int pos = field.getTextStartPos();
1817:                    if (pTrans != null) {
1818:                        pTrans.handleChar(str);
1819:                    } else {
1820:                        field.setText(str);
1821:                    }
1822:                    //m_Field.replaceSelection(str);
1823:
1824:                    //I want to set the selection start and end positions.
1825:                    pos += str.length();
1826:                    setSel(pos, pos);
1827:                    m_Field.setCaretPosition(pos);
1828:                }
1829:            }
1830:
1831:            private IEditControlField getNameField() {
1832:                IEditControlField field = null;
1833:                if (m_Translator != null) {
1834:                    Vector fields = m_Translator.getTextFields();
1835:                    if (fields != null) {
1836:                        int count = fields.size();
1837:                        for (int i = 0; i < count; i++) {
1838:                            IEditControlField tempField = (IEditControlField) fields
1839:                                    .get(i);
1840:                            IPropertyDefinition pDef = tempField
1841:                                    .getPropertyDefinition();
1842:                            if (pDef != null) {
1843:                                String name = pDef.getName();
1844:                                if (name != null
1845:                                        && name.equals("NameWithAlias")) {
1846:                                    field = tempField;
1847:                                    break;
1848:                                }
1849:                            }
1850:                        }
1851:
1852:                        if (field != null) {
1853:                            int startPos = field.getTextStartPos();
1854:                            int endPos = field.getTextEndPos();
1855:                            setSel(startPos, endPos);
1856:                        }
1857:                    }
1858:                }
1859:                return field;
1860:            }
1861:
1862:            private IEditControlField getRepClassifierField() {
1863:                IEditControlField field = null;
1864:                if (m_Translator != null) {
1865:                    Vector fields = m_Translator.getTextFields();
1866:                    if (fields != null) {
1867:                        int count = fields.size();
1868:                        for (int i = 0; i < count; i++) {
1869:                            IEditControlField tempField = (IEditControlField) fields
1870:                                    .get(i);
1871:                            IPropertyDefinition pDef = tempField
1872:                                    .getPropertyDefinition();
1873:                            if (pDef != null) {
1874:                                String name = pDef.getName();
1875:                                if (name != null
1876:                                        && name
1877:                                                .equals("RepresentingClassifier")) {
1878:                                    field = tempField;
1879:                                    break;
1880:                                }
1881:                            }
1882:                        }
1883:
1884:                        if (field != null) {
1885:                            int startPos = field.getTextStartPos();
1886:                            int endPos = field.getTextEndPos();
1887:                            setSel(startPos, endPos);
1888:                        }
1889:                    }
1890:                }
1891:                return field;
1892:            }
1893:
1894:            private IEditControlField getCommentField() {
1895:                IEditControlField field = null;
1896:                if (m_Translator != null) {
1897:                    Vector fields = m_Translator.getTextFields();
1898:                    if (fields != null) {
1899:                        int count = fields.size();
1900:                        for (int i = 0; i < count; i++) {
1901:                            IEditControlField tempField = (IEditControlField) fields
1902:                                    .get(i);
1903:                            IPropertyDefinition pDef = tempField
1904:                                    .getPropertyDefinition();
1905:                            if (pDef != null) {
1906:                                String name = pDef.getName();
1907:                                if (name != null && name.equals("Comment")) {
1908:                                    field = tempField;
1909:                                    break;
1910:                                }
1911:                            }
1912:                        }
1913:
1914:                        if (field != null) {
1915:                            int startPos = field.getTextStartPos();
1916:                            int endPos = field.getTextEndPos();
1917:                            setSel(startPos, endPos);
1918:                        }
1919:                    }
1920:                }
1921:
1922:                //if we are getting the comment field, we do not want to show the tooltips.
1923:                if (field != null) {
1924:                    setEnableTooltip(false);
1925:                }
1926:
1927:                return field;
1928:            }
1929:
1930:            public boolean isShiftDown() {
1931:                return m_ShiftDown;
1932:            }
1933:
1934:            public boolean isControlDown() {
1935:                return m_ControlDown;
1936:            }
1937:
1938:            private class EditControlDocumentListener implements 
1939:                    DocumentListener {
1940:                public void insertUpdate(DocumentEvent e) {
1941:                    handleFieldModified(e);
1942:                }
1943:
1944:                public void removeUpdate(DocumentEvent e) {
1945:                    handleFieldModified(e);
1946:                }
1947:
1948:                public void changedUpdate(DocumentEvent e) {
1949:                    handleFieldModified(e);
1950:                }
1951:            }
1952:
1953:            public void setEditControlBackground(Color c) {
1954:                m_Field.setBackground(c);
1955:                m_Panel.setBackground(c);
1956:                m_Button.setBackground(c);
1957:                this .setBackground(c);
1958:                m_BackgroundColor = c;
1959:            }
1960:
1961:            /**
1962:             * 
1963:             */
1964:            public void setFont(Font value) {
1965:                if (m_Field != null) {
1966:                    m_Field.setFont(value);
1967:                }
1968:            }
1969:
1970:            /**
1971:             * 
1972:             */
1973:            public Font getFont() {
1974:                Font retVal = null;
1975:                if (m_Field != null) {
1976:                    retVal = m_Field.getFont();
1977:                }
1978:
1979:                return retVal;
1980:            }
1981:
1982:            /*
1983:             *  (non-Javadoc)
1984:             * @see org.netbeans.modules.uml.ui.controls.editcontrol.IEditControl#getAssociatedParent()
1985:             */
1986:            public Object getAssociatedParent() {
1987:                return (m_Parent != null) ? m_Parent.get() : null;
1988:            }
1989:
1990:            /* (non-Javadoc)
1991:             * @see java.awt.event.InputMethodListener#caretPositionChanged(java.awt.event.InputMethodEvent)
1992:             */
1993:            public void caretPositionChanged(InputMethodEvent event) {
1994:                // TODO Auto-generated method stub
1995:
1996:            }
1997:
1998:            /* (non-Javadoc)
1999:             * @see java.awt.event.InputMethodListener# (java.awt.event.InputMethodEvent)
2000:             */
2001:            public void inputMethodTextChanged(InputMethodEvent event) {
2002:                if (!ime_Cached) {
2003:                    ime_SelectionStartPos = m_Field.getSelectionStart();
2004:                    ime_SelectionEndPos = m_Field.getSelectionEnd();
2005:                    if (ime_SelectionStartPos != ime_SelectionEndPos) {
2006:                        ime_InitialLoc = Math.min(ime_SelectionStartPos,
2007:                                ime_SelectionEndPos);
2008:                    } else {
2009:                        ime_InitialLoc = m_Field.getCaretPosition();
2010:                    }
2011:                    ime_Cached = true;
2012:                    ime_CachedChars = new StringBuffer();
2013:                }
2014:
2015:                int committedCharacterCount = event
2016:                        .getCommittedCharacterCount();
2017:                CharacterIterator iter = event.getText();
2018:                if (iter != null
2019:                        && ((iter.getEndIndex() - iter.getBeginIndex()) > committedCharacterCount)) {
2020:                    if (ime_CachedChars != null) {
2021:                        char ch = iter.first();
2022:                        for (int i = 0; i < committedCharacterCount; i++) {
2023:                            ime_CachedChars.append(ch);
2024:                            ch = iter.next();
2025:                        }
2026:                    }
2027:                } else {
2028:
2029:                    // Push the caret back as part of faking the text input.
2030:                    int pos = ime_InitialLoc;
2031:                    setCurrentPosition(pos);
2032:                    // Fake the key input since handleTypedChar() does the right things.
2033:
2034:                    if (ime_CachedChars != null) {
2035:                        for (int i = 0; i < ime_CachedChars.length(); i++) {
2036:                            handleTypedChar(ime_CachedChars.charAt(i));
2037:                            setCurrentPosition(++pos);
2038:                        }
2039:                    }
2040:
2041:                    if (iter != null) {
2042:                        for (char ch = iter.first(); ch != CharacterIterator.DONE; ch = iter
2043:                                .next()) {
2044:                            handleTypedChar(ch);
2045:                            setCurrentPosition(++pos);
2046:                        }
2047:                    }
2048:                    for (int i = ime_SelectionStartPos; i < ime_SelectionEndPos; i++) {
2049:                        m_Translator.handleKeyDown(127);
2050:                    }
2051:                    ime_Cached = false;
2052:                    ime_CachedChars = null;
2053:
2054:                    event.consume();
2055:
2056:                    //commit the changes to the edit control
2057:                    setModified(true);
2058:                    m_Translator.setModified(true);
2059:                    if (getCurrentField() != null) {
2060:                        getCurrentField().setModified(true);
2061:                    }
2062:                    if (getAssociatedParent() != null) {
2063:                        if (getAssociatedParent() instanceof  ETCompartment) {
2064:                            ; //((ETCompartment)getAssociatedParent()).save();
2065:                        } else if (getAssociatedParent() instanceof  ProjectTreeCellEditor) {
2066:                            ((ProjectTreeCellEditor) getAssociatedParent())
2067:                                    .stopCellEditing();
2068:                        }
2069:                    }
2070:                }
2071:            }
2072:        }
w___w__w__.j__av_a_2__s_._c___o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.