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.newdialog;
0043:
0044: import java.awt.BorderLayout;
0045: import java.awt.Component;
0046: import java.awt.Container;
0047: import java.awt.Dimension;
0048: import java.awt.Font;
0049: import java.awt.GridBagConstraints;
0050: import java.awt.GridBagLayout;
0051: import java.io.File;
0052: import java.util.Iterator;
0053: import java.util.List;
0054: import java.util.Vector;
0055:
0056: import javax.swing.Icon;
0057: import javax.swing.JFrame;
0058: import javax.swing.JLabel;
0059: import javax.swing.JList;
0060: import javax.swing.JPanel;
0061: import javax.swing.ListCellRenderer;
0062: import javax.swing.ListSelectionModel;
0063: import javax.swing.border.TitledBorder;
0064: import javax.swing.JScrollPane;
0065: import javax.swing.event.*;
0066:
0067: import org.dom4j.Document;
0068:
0069: import org.netbeans.modules.uml.common.generics.ETPairT;
0070: import org.netbeans.modules.uml.core.metamodel.core.foundation.IConfigManager;
0071: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamedElement;
0072: import org.netbeans.modules.uml.core.metamodel.core.foundation.INamespace;
0073: import org.netbeans.modules.uml.core.metamodel.diagrams.IDiagramKind;
0074: import org.netbeans.modules.uml.core.metamodel.diagrams.IProxyDiagram;
0075: import org.netbeans.modules.uml.core.metamodel.dynamics.IInteraction;
0076: import org.netbeans.modules.uml.core.metamodel.infrastructure.coreinfrastructure.IOperation;
0077: import org.netbeans.modules.uml.core.support.umlsupport.ProductRetriever;
0078: import org.netbeans.modules.uml.core.support.umlsupport.XMLManip;
0079: import org.netbeans.modules.uml.core.support.umlutils.ETList;
0080: import org.netbeans.modules.uml.ui.support.UserSettings;
0081: import org.netbeans.modules.uml.ui.support.commonresources.CommonResourceManager;
0082: import org.netbeans.modules.uml.ui.support.diagramsupport.IProxyDiagramManager;
0083: import org.netbeans.modules.uml.ui.support.diagramsupport.ProxyDiagramManager;
0084: import org.netbeans.modules.uml.ui.support.wizard.IWizardSheet;
0085: import org.netbeans.modules.uml.ui.support.wizard.WizardInteriorPage;
0086: import org.openide.DialogDisplayer;
0087: import org.openide.NotifyDescriptor;
0088:
0089: /**
0090: * @author sumitabhk
0091: * @author cbeckham
0092: *
0093: */
0094: public class NewDiagramUI extends WizardInteriorPage implements
0095: INewDialogUI, ListSelectionListener {
0096: private static final String PG_CAPTION = NewDialogResources
0097: .getString("NewDiagramUI.NEWWIZARD_CAPTION"); // NOI18N
0098: private static final String PG_TITLE = NewDialogResources
0099: .getString("NewDiagramUI.NEWWIZARD_TITLE"); // NOI18N
0100: private static final String PG_SUBTITLE = NewDialogResources
0101: .getString("NewDiagramUI.NEWWIZARD_SUBTITL"); // NOI18N
0102:
0103: public NewDiagramUI(IWizardSheet parent, String caption,
0104: String headerTitle, String headerSubTitle) {
0105: super (parent);//, caption, headerTitle, headerSubTitle);
0106: createUI();
0107: }
0108:
0109: public NewDiagramUI(IWizardSheet parent) {
0110: this (parent, PG_CAPTION, PG_TITLE, PG_SUBTITLE);
0111: }
0112:
0113: public NewDiagramUI(IWizardSheet parent,
0114: INewDialogTabDetails details) {
0115: super (parent, PG_CAPTION, PG_TITLE, PG_SUBTITLE);
0116: if (details instanceof INewDialogDiagramDetails) {
0117: m_Details = (INewDialogDiagramDetails) details;
0118: }
0119: createUI();
0120: }
0121:
0122: /* The only reason to set the size is because the list will not be
0123: * wide enough on larger fontsizes The
0124: * algorithm is rather arbitrary but works well in this instance.
0125: * Charles Beckham
0126: */
0127: private java.awt.Dimension getListDimensions() {
0128: int fontsize = getFontSize();
0129: int width = 150;
0130: int height = 180;
0131: int multiplyer = 1;
0132:
0133: if (fontsize > 17)
0134: multiplyer = 3;
0135: width = width
0136: + Math.round(width * (multiplyer * fontsize / 100f));
0137: height = height
0138: + Math.round(height * (multiplyer * fontsize / 100f));
0139:
0140: return new java.awt.Dimension(width, height);
0141: }
0142:
0143: private int getFontSize() {
0144: int fontsize;
0145: java.awt.Font f = javax.swing.UIManager.getFont("controlFont"); //NOI18N
0146: if (f != null) {
0147: fontsize = f.getSize();
0148: } else {
0149: fontsize = 12;
0150: }
0151: return fontsize;
0152: }
0153:
0154: /**
0155: * Enables us to adjust the panel size to handle larger fonts
0156: * CBeckham
0157: */
0158: private Dimension setPanelSize() {
0159:
0160: int fontsize;
0161: java.awt.Font f = javax.swing.UIManager.getFont("controlFont"); //NOI18N
0162: if (f != null) {
0163: fontsize = f.getSize();
0164: } else {
0165: fontsize = 12;
0166: }
0167: int width = 600;
0168: int height = 500;
0169: int multiplyer = 2;
0170:
0171: if (fontsize > 17)
0172: multiplyer = 3;
0173: width = width
0174: + Math.round(width * (multiplyer * fontsize / 100f));
0175: height = height
0176: + Math.round(height * (multiplyer * fontsize / 100f));
0177:
0178: return new java.awt.Dimension(width, height);
0179: }
0180:
0181: protected void createUI() {
0182: super .createUI();
0183: //setPreferredSize(setPanelSize());
0184:
0185: jPanel1 = new JPanel();
0186: jLabel1 = new javax.swing.JLabel();
0187: jLabel3 = new javax.swing.JLabel();
0188: jTextField1 = new javax.swing.JTextField();
0189: jLabel2 = new javax.swing.JLabel();
0190: jComboBox1 = new javax.swing.JComboBox();
0191: jTextFieldDiagram = new javax.swing.JTextField();
0192: jButton1 = new javax.swing.JButton();
0193: jButton2 = new javax.swing.JButton();
0194:
0195: //setLayout(new java.awt.GridBagLayout());
0196: jPanel1.setLayout(new java.awt.GridBagLayout());
0197:
0198: IConfigManager conMan = ProductRetriever.retrieveProduct()
0199: .getConfigManager();
0200: String fileName = conMan.getDefaultConfigLocation();
0201: fileName += "NewDialogDefinitions.etc"; // NOI18N
0202: m_doc = XMLManip.getDOMDocument(fileName);
0203: org.dom4j.Node node = m_doc
0204: .selectSingleNode("//PropertyDefinitions/PropertyDefinition"); // NOI18N
0205: list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
0206: list.setCellRenderer(new ElementListCellRenderer());
0207: list.setLayout(new GridBagLayout());
0208: //changed by Cbeckham to account for large fontsize
0209: list.setPreferredSize(getListDimensions());
0210: if (getFontSize() > 16)
0211: scrollPane.getViewport().setView(list);
0212: // end of CBeckham code add
0213:
0214: if (node != null) {
0215: org.dom4j.Element elem = (org.dom4j.Element) node;
0216: String name = elem.attributeValue("name"); // NOI18N
0217:
0218: Vector elements = new Vector();
0219: List nodeList = m_doc
0220: .selectNodes("//PropertyDefinition/aDefinition[@name='" // NOI18N
0221: + "Diagram" + "']/aDefinition"); // NOI18N
0222: if (list != null) {
0223: int diaKind = IDiagramKind.DK_ALL;
0224: if (m_Details != null) {
0225: diaKind = m_Details.getAvailableDiagramKinds();
0226: }
0227: int count = nodeList.size();
0228: for (int i = 0; i < count; i++) {
0229: org.dom4j.Element subNode = (org.dom4j.Element) nodeList
0230: .get(i);
0231: String subName = subNode
0232: .attributeValue("displayName"); // NOI18N
0233: subName = NewDialogResources.getString(subName);
0234:
0235: if (diaKind == IDiagramKind.DK_ALL) {
0236: elements.add(subName);
0237: } else {
0238: //only some of diagram kinds are valid
0239: if (subName.equals(NewDialogResources
0240: .getString("PSK_CLASS_DIAGRAM"))) // NOI18N
0241: {
0242: if ((diaKind & IDiagramKind.DK_CLASS_DIAGRAM) == IDiagramKind.DK_CLASS_DIAGRAM) {
0243: elements.add(subName);
0244: }
0245: } else if (subName.equals(NewDialogResources
0246: .getString("PSK_ACTIVITY_DIAGRAM"))) // NOI18N
0247: {
0248: if ((diaKind & IDiagramKind.DK_ACTIVITY_DIAGRAM) == IDiagramKind.DK_ACTIVITY_DIAGRAM) {
0249: elements.add(subName);
0250: }
0251: } else if (subName
0252: .equals(NewDialogResources
0253: .getString("PSK_COLLABORATION_DIAGRAM"))) // NOI18N
0254: {
0255: if ((diaKind & IDiagramKind.DK_COLLABORATION_DIAGRAM) == IDiagramKind.DK_COLLABORATION_DIAGRAM) {
0256: elements.add(subName);
0257: }
0258: } else if (subName.equals(NewDialogResources
0259: .getString("PSK_COMPONENT_DIAGRAM"))) // NOI18N
0260: {
0261: if ((diaKind & IDiagramKind.DK_COMPONENT_DIAGRAM) == IDiagramKind.DK_COMPONENT_DIAGRAM) {
0262: elements.add(subName);
0263: }
0264: } else if (subName.equals(NewDialogResources
0265: .getString("PSK_DEPLOYMENT_DIAGRAM"))) // NOI18N
0266: {
0267: if ((diaKind & IDiagramKind.DK_DEPLOYMENT_DIAGRAM) == IDiagramKind.DK_DEPLOYMENT_DIAGRAM) {
0268: elements.add(subName);
0269: }
0270: } else if (subName.equals(NewDialogResources
0271: .getString("PSK_SEQUENCE_DIAGRAM"))) // NOI18N
0272: {
0273: if ((diaKind & IDiagramKind.DK_SEQUENCE_DIAGRAM) == IDiagramKind.DK_SEQUENCE_DIAGRAM) {
0274: elements.add(subName);
0275: }
0276: } else if (subName.equals(NewDialogResources
0277: .getString("PSK_STATE_DIAGRAM"))) // NOI18N
0278: {
0279: if ((diaKind & IDiagramKind.DK_STATE_DIAGRAM) == IDiagramKind.DK_STATE_DIAGRAM) {
0280: elements.add(subName);
0281: }
0282: } else if (subName.equals(NewDialogResources
0283: .getString("PSK_USE_CASE_DIAGRAM"))) // NOI18N
0284: {
0285: if ((diaKind & IDiagramKind.DK_USECASE_DIAGRAM) == IDiagramKind.DK_USECASE_DIAGRAM) {
0286: elements.add(subName);
0287: }
0288: }
0289: }
0290: }
0291: }
0292:
0293: list.setListData(elements);
0294: UserSettings userSettings = new UserSettings();
0295: if (userSettings != null) {
0296: String value = userSettings.getSettingValue(
0297: "NewDialog", "LastChosenDiagramType"); // NOI18N
0298:
0299: if (value != null && value.length() > 0) {
0300: list.setSelectedValue(value, true);
0301: }
0302: }
0303:
0304: if (list.getSelectedIndex() == -1) {
0305: list.setSelectedIndex(0);
0306: }
0307: }
0308:
0309: list.setBorder(new TitledBorder(
0310: null,
0311: "", // NOI18N
0312: javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
0313: javax.swing.border.TitledBorder.DEFAULT_POSITION,
0314: new java.awt.Font("Dialog", 0, 12))); // NOI18N
0315: //m_DetailPanel.setBackground(Color.WHITE);
0316:
0317: JLabel diaNameLabel = new JLabel();
0318: diaNameLabel.setText(NewDialogResources
0319: .determineText(NewDialogResources
0320: .getString("NewDiagramUI.DIAGRAM_TYPE_LBL"))); // NOI18N
0321: NewDialogResources.setMnemonic(diaNameLabel, NewDialogResources
0322: .getString("NewDiagramUI.DIAGRAM_TYPE_LBL")); // NOI18N
0323: diaNameLabel.setLabelFor(list);
0324:
0325: GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
0326: gridBagConstraints.gridx = 0;
0327: gridBagConstraints.gridy = 0;
0328: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST;
0329: gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 5);
0330: //gridBagConstraints.weightx = 1.0;
0331: gridBagConstraints.weighty = 1.0;
0332: jPanel1.add(diaNameLabel, gridBagConstraints);
0333:
0334: gridBagConstraints = new java.awt.GridBagConstraints();
0335: gridBagConstraints.fill = GridBagConstraints.BOTH;
0336: gridBagConstraints.gridx = 1;
0337: gridBagConstraints.gridy = 0;
0338: gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 5);
0339: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0340: gridBagConstraints.weightx = 1.0;
0341: gridBagConstraints.weighty = 1.0;
0342:
0343: //Add list selection listener. Fix for bug#6283146
0344: list.addListSelectionListener(this );
0345:
0346: // CBeckham - added this code to add a scroll bar to list when
0347: // using very very large fonts
0348: if (getFontSize() > 16)
0349: jPanel1.add(scrollPane, gridBagConstraints);
0350: else
0351: jPanel1.add(list, gridBagConstraints);
0352: // end of CBeckham code add
0353:
0354: jLabel3.setText(NewDialogResources
0355: .determineText(NewDialogResources
0356: .getString("NewDiagramUI.DIAGRAM_NAME_LBL"))); // NOI18N
0357: NewDialogResources.setMnemonic(jLabel3, NewDialogResources
0358: .getString("NewDiagramUI.DIAGRAM_NAME_LBL")); // NOI18N
0359: gridBagConstraints = new java.awt.GridBagConstraints();
0360: gridBagConstraints.gridx = 0;
0361: gridBagConstraints.gridy = 1;
0362: // gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0363: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0364: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
0365: //gridBagConstraints.weightx = 0.2;
0366: gridBagConstraints.weighty = 0.1;
0367: jPanel1.add(jLabel3, gridBagConstraints);
0368:
0369: jTextField1.setText("jTextField1"); // NOI18N
0370: jLabel3.setLabelFor(jTextField1);
0371: //jTextField1.setPreferredSize(new java.awt.Dimension(120, 20));
0372:
0373: gridBagConstraints = new java.awt.GridBagConstraints();
0374: gridBagConstraints.gridx = 1;
0375: gridBagConstraints.gridy = 1;
0376: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0377: //gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
0378: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0379: gridBagConstraints.insets = new java.awt.Insets(10, 5, 0, 5);
0380: gridBagConstraints.weightx = 0.8;
0381: gridBagConstraints.weighty = 0.1;
0382: jPanel1.add(jTextField1, gridBagConstraints);
0383:
0384: jLabel2.setText(NewDialogResources
0385: .determineText(NewDialogResources
0386: .getString("NewDiagramUI.NAMESPACE_LBL"))); // NOI18N
0387: NewDialogResources.setMnemonic(jLabel2, NewDialogResources
0388: .getString("NewDiagramUI.NAMESPACE_LBL")); // NOI18N
0389: jLabel2.setLabelFor(jComboBox1);
0390: gridBagConstraints = new java.awt.GridBagConstraints();
0391: gridBagConstraints.gridx = 0;
0392: gridBagConstraints.gridy = 2;
0393: // gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0394: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
0395: //gridBagConstraints.weightx = 0.2;
0396: gridBagConstraints.weighty = 0.1;
0397: gridBagConstraints.insets = new java.awt.Insets(10, 0, 5, 0);
0398: jPanel1.add(jLabel2, gridBagConstraints);
0399:
0400: // cvc - CR#6269238
0401: // make namespace uneditable (select options only)
0402: // jComboBox1.setEditable(true);
0403: jComboBox1.setEditable(false);
0404: NewDialogResources.setFocusAccelerator(jComboBox1,
0405: NewDialogResources
0406: .getString("NewDiagramUI.NAMESPACE_LBL")); // NOI18N
0407: //jComboBox1.setPreferredSize(new java.awt.Dimension(120, 25));
0408: gridBagConstraints = new java.awt.GridBagConstraints();
0409: gridBagConstraints.gridx = 1;
0410: gridBagConstraints.gridy = 2;
0411: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0412: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0413: gridBagConstraints.insets = new java.awt.Insets(10, 5, 5, 5);
0414: gridBagConstraints.weightx = 0.8;
0415: gridBagConstraints.weighty = 0.1;
0416: jPanel1.add(jComboBox1, gridBagConstraints);
0417:
0418: gridBagConstraints = new java.awt.GridBagConstraints();
0419: gridBagConstraints.gridx = 0;
0420: gridBagConstraints.gridy = 0;
0421: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0422: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0423: gridBagConstraints.weightx = 1.0;
0424: gridBagConstraints.weighty = 1.0;
0425:
0426: JPanel contentPane = new JPanel();
0427: contentPane.setBorder(new TitledBorder(null, "",
0428: TitledBorder.DEFAULT_JUSTIFICATION,
0429: TitledBorder.DEFAULT_POSITION, new Font("Dialog", 0,
0430: getFontSize()))); // NOI18N
0431:
0432: contentPane.setLayout(new GridBagLayout());
0433: contentPane.add(jPanel1, gridBagConstraints);
0434: add(contentPane, BorderLayout.CENTER);
0435: }
0436:
0437: protected boolean onInitDialog() {
0438: return super .onInitDialog();
0439: }
0440:
0441: public boolean onDismiss() {
0442: INewDialogTabDetails details = getResults(true);
0443: if (null == details) {
0444: return false;
0445: }
0446:
0447: // NewDialogResultProcessor processor = new NewDialogResultProcessor();
0448: // processor.handleResult(details);
0449: IWizardSheet parent = getParentSheet();
0450: if (parent != null && parent instanceof JDefaultNewDialog) {
0451: ((JDefaultNewDialog) parent).setResult(details);
0452: }
0453:
0454: UserSettings userSettings = new UserSettings();
0455: if (userSettings != null) {
0456: // write it back out to the ini file
0457: userSettings.setSettingValue("NewDialog", // NOI18N
0458: "LastChosenDiagramType", // NOI18N
0459: (String) list.getSelectedValue());
0460: }
0461: return super .onDismiss();
0462: }
0463:
0464: public void onSetActive() {
0465: super .onSetActive();
0466: getParentSheet().setButtonEnabled(IWizardSheet.PSWIZB_FINISH,
0467: true);
0468: getParentSheet().setButtonEnabled(IWizardSheet.PSWIZB_NEXT,
0469: false);
0470: //m_headerImage.setIcon(getHelpIcon());
0471: loadComponents();
0472: }
0473:
0474: public void onWizardBack() {
0475: super .onWizardBack();
0476: }
0477:
0478: public void onWizardNext() {
0479: //super.onWizardNext();
0480: }
0481:
0482: /**
0483: *
0484: */
0485: // public NewDiagramUI()
0486: // {
0487: // super();
0488: // initComponents();
0489: // loadComponents();
0490: // jTextField1.selectAll();
0491: // jTextField1.requestFocus();
0492: // setPreferredSize(new Dimension(400, 400));
0493: // }
0494: //
0495: // public NewDiagramUI(INewDialogDiagramDetails details)
0496: // {
0497: // super();
0498: // initComponents();
0499: // INamespace space = null;
0500: // String name = "";
0501: // int kind = 0;
0502: // int availableKinds = 0;
0503: // if (details != null)
0504: // {
0505: // space = details.getNamespace();
0506: // name = details.getName();
0507: // kind = details.getDiagramKind();
0508: // availableKinds = details.getAvailableDiagramKinds();
0509: // }
0510: // //load namespaces
0511: // if (jComboBox1 != null)
0512: // {
0513: // NewDialogUtilities.loadNamespace(jComboBox1, space);
0514: // }
0515: //
0516: // if (name == null || name.length() == 0)
0517: // {
0518: // //set default diagram name
0519: // jTextField1.setText(NewDialogUtilities.getDefaultDiagramName());
0520: // }
0521: // else
0522: // {
0523: // jTextField1.setText(name);
0524: // }
0525: // jTextField1.selectAll();
0526: // jTextField1.requestFocus();
0527: // String sKind = getDiagramKind(kind);
0528: // jTextFieldDiagram.setText(sKind);
0529: // setPreferredSize(new Dimension(400, 400));
0530: // }
0531: private String getDiagramKind(int kind) {
0532: String retStr = ""; //$NON-NLS-1$
0533: switch (kind) {
0534: case IDiagramKind.DK_ACTIVITY_DIAGRAM:
0535: retStr = NewDialogResources
0536: .getString("NewDiagramUI.ACTIVITY_DIAGRAM"); // NOI18N
0537: break;
0538:
0539: case IDiagramKind.DK_CLASS_DIAGRAM:
0540: retStr = NewDialogResources
0541: .getString("NewDiagramUI.CLASS_DIAGRAM"); // NOI18N
0542: break;
0543:
0544: case IDiagramKind.DK_COLLABORATION_DIAGRAM:
0545: retStr = NewDialogResources
0546: .getString("NewDiagramUI.COLLABORATION_DIAGRAM"); // NOI18N
0547: break;
0548:
0549: case IDiagramKind.DK_COMPONENT_DIAGRAM:
0550: retStr = NewDialogResources
0551: .getString("NewDiagramUI.COMPONENT_DIAGRAM"); // NOI18N
0552: break;
0553:
0554: case IDiagramKind.DK_DEPLOYMENT_DIAGRAM:
0555: retStr = NewDialogResources
0556: .getString("NewDiagramUI.DEPLOYMENT_DIAGRAM"); // NOI18N
0557: break;
0558:
0559: case IDiagramKind.DK_SEQUENCE_DIAGRAM:
0560: retStr = NewDialogResources
0561: .getString("NewDiagramUI.SEQUENCE_DIAGRAM"); // NOI18N
0562: break;
0563:
0564: case IDiagramKind.DK_STATE_DIAGRAM:
0565: retStr = NewDialogResources
0566: .getString("NewDiagramUI.STATE_DIAGRAM"); // NOI18N
0567: break;
0568:
0569: case IDiagramKind.DK_USECASE_DIAGRAM:
0570: retStr = NewDialogResources
0571: .getString("NewDiagramUI.USE_CASE_DIAGRAM"); // NOI18N
0572: break;
0573:
0574: default:
0575: retStr = NewDialogResources
0576: .getString("NewDiagramUI.CLASS_DIAGRAM"); // NOI18N
0577: break;
0578: }
0579: return retStr;
0580: }
0581:
0582: /**
0583: * Loads the combo boxes and initializes the default names
0584: */
0585: private void loadComponents() {
0586: //load namespaces
0587: if (jComboBox1 != null) {
0588: //NewDialogUtilities.loadNamespace(jComboBox1, null);
0589: NewDialogUtilities.loadNamespace(jComboBox1, m_Details
0590: .getNamespace());
0591: // Fix for bug#6283146
0592: for (int i = 0; i < jComboBox1.getItemCount(); i++)
0593: saveNamespaces.add(jComboBox1.getItemAt(i));
0594: valueChanged(null);
0595: }
0596:
0597: //set default diagram name
0598: jTextField1.setText(NewDialogUtilities.getDefaultDiagramName());
0599: jTextField1.selectAll();
0600: jTextField1.requestFocus();
0601:
0602: }
0603:
0604: /** This method is called from within the constructor to
0605: * initialize the form.
0606: * WARNING: Do NOT modify this code. The content of this method is
0607: * always regenerated by the Form Editor.
0608: */
0609: private void initComponents() {
0610: java.awt.GridBagConstraints gridBagConstraints;
0611:
0612: jPanel1 = new JPanel();
0613: jLabel1 = new javax.swing.JLabel();
0614: jLabel3 = new javax.swing.JLabel();
0615: jTextField1 = new javax.swing.JTextField();
0616: jLabel2 = new javax.swing.JLabel();
0617: jComboBox1 = new javax.swing.JComboBox();
0618: jTextFieldDiagram = new javax.swing.JTextField();
0619: jButton1 = new javax.swing.JButton();
0620: jButton2 = new javax.swing.JButton();
0621:
0622: setLayout(new java.awt.GridBagLayout());
0623: jPanel1.setLayout(new java.awt.GridBagLayout());
0624:
0625: // addWindowListener(new java.awt.event.WindowAdapter() {
0626: // public void windowClosing(java.awt.event.WindowEvent evt) {
0627: // closeDialog(evt);
0628: // }
0629: // });
0630:
0631: // jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
0632: // jLabel1.setFont(new java.awt.Font("Dialog", 0, 12));
0633: // jLabel1.setText("Adding Diagram kind:");
0634: // jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);
0635: // jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
0636: // gridBagConstraints = new java.awt.GridBagConstraints();
0637: // gridBagConstraints.gridx = 0;
0638: // gridBagConstraints.gridy = 0;
0639: // gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0640: // gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
0641: // gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0642: // add(jLabel1, gridBagConstraints);
0643:
0644: jLabel3.setText(NewDialogResources
0645: .getString("NewDiagramUI.DIAGRAM_NAME_LBL")); // NOI18N
0646: gridBagConstraints = new java.awt.GridBagConstraints();
0647: gridBagConstraints.gridx = 0;
0648: gridBagConstraints.gridy = 0;
0649: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0650: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0651: gridBagConstraints.weightx = 1.0;
0652: gridBagConstraints.weighty = 0.1;
0653: jPanel1.add(jLabel3, gridBagConstraints);
0654:
0655: jTextField1.setText("jTextField1"); // NOI18N
0656: //jTextField1.setPreferredSize(new java.awt.Dimension(120, 20));
0657:
0658: gridBagConstraints = new java.awt.GridBagConstraints();
0659: gridBagConstraints.gridx = 0;
0660: gridBagConstraints.gridy = 1;
0661: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0662: //gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
0663: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0664: gridBagConstraints.weightx = 1.0;
0665: gridBagConstraints.weighty = 0.1;
0666: jPanel1.add(jTextField1, gridBagConstraints);
0667:
0668: jLabel2.setText(NewDialogResources
0669: .getString("NewDiagramUI.NAMESPACE_LBL")); // NOI18N
0670: gridBagConstraints = new java.awt.GridBagConstraints();
0671: gridBagConstraints.gridx = 0;
0672: gridBagConstraints.gridy = 2;
0673: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0674: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0675: gridBagConstraints.weightx = 1.0;
0676: gridBagConstraints.weighty = 0.1;
0677: gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
0678: jPanel1.add(jLabel2, gridBagConstraints);
0679:
0680: // cvc - CR#6269238
0681: // make namespace uneditable (choose options only)
0682: jComboBox1.setEditable(true);
0683: //jComboBox1.setPreferredSize(new java.awt.Dimension(120, 25));
0684: gridBagConstraints = new java.awt.GridBagConstraints();
0685: gridBagConstraints.gridx = 0;
0686: gridBagConstraints.gridy = 3;
0687: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0688: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0689: gridBagConstraints.weightx = 1.0;
0690: gridBagConstraints.weighty = 0.1;
0691: jPanel1.add(jComboBox1, gridBagConstraints);
0692:
0693: gridBagConstraints = new java.awt.GridBagConstraints();
0694: gridBagConstraints.gridx = 0;
0695: gridBagConstraints.gridy = 0;
0696: //gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0697: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
0698: gridBagConstraints.weightx = 1.0;
0699: gridBagConstraints.weighty = 1.0;
0700: add(jPanel1, gridBagConstraints);
0701:
0702: // jTextFieldDiagram.setEditable(false);
0703: // jTextFieldDiagram.setBorder(null);
0704: // jTextFieldDiagram.setText("jTextField2");
0705: // gridBagConstraints = new java.awt.GridBagConstraints();
0706: // gridBagConstraints.gridx = 1;
0707: // gridBagConstraints.gridy = 0;
0708: // gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0709: // gridBagConstraints.insets = new java.awt.Insets(0, 5, 10, 0);
0710: // add(jTextFieldDiagram, gridBagConstraints);
0711: //
0712: // jButton1.setText("Finish");
0713: // gridBagConstraints = new java.awt.GridBagConstraints();
0714: // gridBagConstraints.gridx = 0;
0715: // gridBagConstraints.gridy = 6;
0716: // gridBagConstraints.insets = new java.awt.Insets(20, 0, 0, 5);
0717: // add(jButton1, gridBagConstraints);
0718: // jButton1.addActionListener(new java.awt.event.ActionListener() {
0719: // public void actionPerformed(java.awt.event.ActionEvent evt) {
0720: // jTextField1ActionPerformed(evt);
0721: // }
0722: // });
0723: //
0724: // jButton2.setText("Cancel");
0725: // gridBagConstraints = new java.awt.GridBagConstraints();
0726: // gridBagConstraints.gridx = 1;
0727: // gridBagConstraints.gridy = 6;
0728: // gridBagConstraints.insets = new java.awt.Insets(20, 5, 0, 0);
0729: // add(jButton2, gridBagConstraints);
0730: // jButton2.addActionListener(new java.awt.event.ActionListener() {
0731: // public void actionPerformed(java.awt.event.ActionEvent evt) {
0732: // closeDialog();
0733: // }
0734: // });
0735:
0736: doLayout();
0737: }
0738:
0739: private void jTextField1ActionPerformed(
0740: java.awt.event.ActionEvent evt) {
0741: INewDialogTabDetails result = getResults(false);
0742: NewDialogResultProcessor processor = new NewDialogResultProcessor();
0743: processor.handleResult(result);
0744: }
0745:
0746: /**
0747: * @return
0748: */
0749: private INewDialogTabDetails getResults(boolean bShowErrorMessage) {
0750: INewDialogDiagramDetails details = null;
0751:
0752: ETPairT<Boolean, String> pair = dataIsValid();
0753: if (pair.getParamOne().booleanValue()) {
0754: details = new NewDialogDiagramDetails();
0755:
0756: // Get the diagram kind
0757: String diaType = (String) list.getSelectedValue();
0758: if (diaType.equals(NewDialogResources
0759: .getString("PSK_SEQUENCE_DIAGRAM"))) // NOI18N
0760: {
0761: details
0762: .setDiagramKind(IDiagramKind.DK_SEQUENCE_DIAGRAM);
0763: } else if (diaType.equals(NewDialogResources
0764: .getString("PSK_ACTIVITY_DIAGRAM"))) // NOI18N
0765: {
0766: details
0767: .setDiagramKind(IDiagramKind.DK_ACTIVITY_DIAGRAM);
0768: } else if (diaType.equals(NewDialogResources
0769: .getString("PSK_CLASS_DIAGRAM"))) // NOI18N
0770: {
0771: details.setDiagramKind(IDiagramKind.DK_CLASS_DIAGRAM);
0772: } else if (diaType.equals(NewDialogResources
0773: .getString("PSK_COLLABORATION_DIAGRAM"))) // NOI18N
0774: {
0775: details
0776: .setDiagramKind(IDiagramKind.DK_COLLABORATION_DIAGRAM);
0777: } else if (diaType.equals(NewDialogResources
0778: .getString("PSK_COMPONENT_DIAGRAM"))) // NOI18N
0779: {
0780: details
0781: .setDiagramKind(IDiagramKind.DK_COMPONENT_DIAGRAM);
0782: } else if (diaType.equals(NewDialogResources
0783: .getString("PSK_DEPLOYMENT_DIAGRAM"))) // NOI18N
0784: {
0785: details
0786: .setDiagramKind(IDiagramKind.DK_DEPLOYMENT_DIAGRAM);
0787: } else if (diaType.equals(NewDialogResources
0788: .getString("PSK_STATE_DIAGRAM"))) // NOI18N
0789: {
0790: details.setDiagramKind(IDiagramKind.DK_STATE_DIAGRAM);
0791: } else if (diaType.equals(NewDialogResources
0792: .getString("PSK_USE_CASE_DIAGRAM"))) // NOI18N
0793: {
0794: details.setDiagramKind(IDiagramKind.DK_USECASE_DIAGRAM);
0795: }
0796:
0797: // Set the name
0798: details.setName(jTextField1.getText());
0799:
0800: // Get the namespace
0801: INamespace selectedNamespace = NewDialogUtilities
0802: .getNamespace((String) jComboBox1.getSelectedItem());
0803:
0804: details.setNamespace(selectedNamespace);
0805: } else if (bShowErrorMessage) {
0806: String message = pair.getParamTwo();
0807: if (message != null && message.trim().length() > 0) {
0808: NotifyDescriptor.Message notifyDesc = new NotifyDescriptor.Message(
0809: message, NotifyDescriptor.WARNING_MESSAGE);
0810: DialogDisplayer.getDefault().notify(notifyDesc);
0811: }
0812: } else {
0813: // Added this code so the behavior does not change for this case
0814: details = new NewDialogDiagramDetails();
0815: }
0816:
0817: return details;
0818: }
0819:
0820: /**
0821: * @return
0822: */
0823: public ETPairT<Boolean, String> dataIsValid() {
0824: boolean bDataIsValid = true;
0825: String message = null;
0826: ETPairT<Boolean, String> retVals = null;
0827:
0828: String sDiagramName = jTextField1.getText();
0829: String trimmedName = sDiagramName.trim();
0830: int trimmedLen = trimmedName.length();
0831:
0832: //boolean bNameHasSpace = !sDiagramName.equals( sDiagramName.trim() );
0833: boolean bNameHasSpaces = sDiagramName.length() > trimmedLen;
0834:
0835: //Jyothi: Adding logic to reject diagram names with a dot or a space -- Fix for Bug#6359779
0836: boolean bNameHasDot = sDiagramName.contains(".");
0837:
0838: if ((trimmedLen > 0) && !bNameHasSpaces && !bNameHasDot) {
0839: String diaType = (String) list.getSelectedValue();
0840: if (diaType.length() <= 0) {
0841: // Nothing selected
0842: message = NewDialogResources
0843: .getString("IDS_PLEASESELECTADIAGRAM"); // NOI18N
0844: bDataIsValid = false;
0845: } else {
0846: // Get the namespace
0847: INamespace selectedNamespace = NewDialogUtilities
0848: .getNamespace((String) jComboBox1
0849: .getSelectedItem());
0850: if (selectedNamespace != null) {
0851: retVals = isValidDiagramForNamespace(diaType,
0852: selectedNamespace);
0853: } else {
0854: // Something bad happened. We added a namespace to
0855: // the combo and couldn't get it back out!
0856: message = NewDialogResources
0857: .getString("IDS_FAILEDTOGETNAMESPACE"); // NOI18N
0858: bDataIsValid = false;
0859: }
0860: }
0861: } else // diagram is not valid: is empty or has dot or has leading/trailing spaces
0862: {
0863: if (trimmedLen == 0) {
0864: message = NewDialogResources
0865: .getString("IDS_DIAGRAMNAME_EMPTY"); // NOI18N
0866: } else if (bNameHasSpaces) {
0867: message = NewDialogResources
0868: .getString("IDS_DIAGRAMNAME_HAS_SPACES"); // NOI18N
0869: } else if (bNameHasDot) {
0870: message = NewDialogResources
0871: .getString("IDS_DIAGRAMNAME_HAS_DOT"); // NOI18N
0872: }
0873: bDataIsValid = false;
0874: }
0875:
0876: if (null == retVals) {
0877: retVals = new ETPairT<Boolean, String>(new Boolean(
0878: bDataIsValid), message);
0879: }
0880:
0881: return retVals;
0882: }
0883:
0884: protected ETPairT<Boolean, String> isValidDiagramForNamespace(
0885: final String diaType, INamespace namespace) {
0886: ETPairT<Boolean, String> retVals = null;
0887:
0888: if (namespace != null) {
0889: if (diaType.equals(NewDialogResources
0890: .getString("NewDiagramUI.COLLABORATION_DIAGRAM"))) // NOI18N
0891: {
0892: retVals = isValidBehaviorDiagramForNamespace(
0893: IDiagramKind.DK_COLLABORATION_DIAGRAM,
0894: namespace);
0895: } else if (diaType.equals(NewDialogResources
0896: .getString("NewDiagramUI.SEQUENCE_DIAGRAM"))) // NOI18N
0897: {
0898: retVals = isValidBehaviorDiagramForNamespace(
0899: IDiagramKind.DK_SEQUENCE_DIAGRAM, namespace);
0900: }
0901: }
0902:
0903: return retVals;
0904: }
0905:
0906: protected ETPairT<Boolean, String> isValidBehaviorDiagramForNamespace(
0907: final int nTestKind, INamespace namespace) {
0908: // When the namespace is either an operation or interaction,
0909: // make sure there is one or zero diagram of either collaboration
0910: // or sequence type. For other namespaces, an interaction
0911: // will be created (somewhere else).
0912:
0913: boolean bIsValidForNamespace = true;
0914: String message = null;
0915:
0916: if (namespace != null) {
0917: boolean bUseInteractionMessage = true;
0918:
0919: IInteraction interaction = null;
0920: if (namespace instanceof IInteraction) {
0921: interaction = (IInteraction) namespace;
0922: } else if (namespace instanceof IOperation) {
0923: bUseInteractionMessage = false;
0924:
0925: // Look for an interaction where we will look for a diagram
0926: ETList<INamedElement> namedElements = namespace
0927: .getOwnedElements();
0928:
0929: for (Iterator iter = namedElements.iterator(); iter
0930: .hasNext();) {
0931: INamedElement namedElement = (INamedElement) iter
0932: .next();
0933:
0934: if (namedElement instanceof IInteraction) {
0935: interaction = (IInteraction) namedElement;
0936: break;
0937: }
0938: }
0939: }
0940:
0941: // Since there should only be one seq diagram
0942: // (or one collaboration diagram)
0943: // in tree per Interaction, prevent user from
0944: // creating multiple diagrams.
0945:
0946: INamespace currentNamespace = (IInteraction) interaction;
0947: if (currentNamespace != null) {
0948: IProxyDiagramManager diagramManager = new ProxyDiagramManager();
0949: if (diagramManager != null) {
0950: ETList<IProxyDiagram> proxyDiagrams = diagramManager
0951: .getDiagramsInNamespace(currentNamespace);
0952:
0953: for (Iterator iter = proxyDiagrams.iterator(); iter
0954: .hasNext();) {
0955: IProxyDiagram proxyDiagram = (IProxyDiagram) iter
0956: .next();
0957: int nKind = proxyDiagram.getDiagramKind();
0958:
0959: if (nTestKind == nKind) {
0960: switch (nTestKind) {
0961: case IDiagramKind.DK_COLLABORATION_DIAGRAM:
0962: message = NewDialogResources
0963: .getString(bUseInteractionMessage ? "IDS_ONE_COD_PER_INTERACTION" // NOI18N
0964: : "IDS_ONE_COD_PER_OPERATION"); // NOI18N
0965: break;
0966:
0967: default:
0968: assert (false);
0969: // do we have another behavioral type diagram?
0970: case IDiagramKind.DK_SEQUENCE_DIAGRAM:
0971: message = NewDialogResources
0972: .getString(bUseInteractionMessage ? "IDS_ONE_SQD_PER_INTERACTION" // NOI18N
0973: : "IDS_ONE_SQD_PER_OPERATION"); // NOI18N
0974: break;
0975: }
0976:
0977: bIsValidForNamespace = false;
0978: }
0979: }
0980: }
0981: }
0982: }
0983:
0984: return new ETPairT<Boolean, String>(new Boolean(
0985: bIsValidForNamespace), message);
0986: }
0987:
0988: /** Closes the dialog */
0989: private void closeDialog() {
0990: setVisible(false);
0991: Container parent = getTopLevelAncestor();
0992: if (parent != null && parent instanceof JFrame) {
0993: ((JFrame) parent).dispose();
0994: }
0995: }
0996:
0997: // Variables declaration - do not modify
0998: private JPanel jPanel1;
0999: private javax.swing.JButton jButton1;
1000: private javax.swing.JButton jButton2;
1001: private javax.swing.JComboBox jComboBox1;
1002: private javax.swing.JLabel jLabel1;
1003: private javax.swing.JLabel jLabel2;
1004: private javax.swing.JLabel jLabel3;
1005: private javax.swing.JTextField jTextField1;
1006: private static javax.swing.JTextField jTextFieldDiagram;
1007: private java.util.List saveNamespaces = new java.util.ArrayList();
1008:
1009: private Document m_doc = null;
1010: private JList list = new JList();
1011: private JScrollPane scrollPane = new JScrollPane();
1012: private INewDialogDiagramDetails m_Details = null;
1013:
1014: /**
1015: * @param selOnTab
1016: */
1017: public static void setElementType(String selOnTab) {
1018: jTextFieldDiagram.setText(selOnTab);
1019: }
1020:
1021: /* (non-Javadoc)
1022: * @see org.netbeans.modules.uml.ui.controls.newdialog.INewDialogUI#nextButtonClicked()
1023: */
1024: public JPanel nextButtonClicked() {
1025: // TODO Auto-generated method stub
1026: return null;
1027: }
1028:
1029: /*
1030: * This method will create new diagram based on the user input
1031: */
1032: public INewDialogTabDetails finishButtonClicked() {
1033: INewDialogTabDetails result = null;
1034: try {
1035: result = getResults(false);
1036: // NewDialogResultProcessor processor = new NewDialogResultProcessor();
1037: // boolean isProcessed = processor.handleResult(result);
1038: // if (isProcessed)
1039: // {
1040: // closeDialog();
1041: // }
1042: // else
1043: // {
1044: // ETSystem.out.println("Error in create diagram");
1045: // }
1046: } catch (Exception e) {
1047: e.printStackTrace();
1048: }
1049: return result;
1050: }
1051:
1052: /* (non-Javadoc)
1053: * @see org.netbeans.modules.uml.ui.controls.newdialog.INewDialogUI#getHelpText()
1054: */
1055: public String getHelpText() {
1056: // TODO Auto-generated method stub
1057: return "Adding " + jTextFieldDiagram.getText(); // NOI18N
1058: }
1059:
1060: /* (non-Javadoc)
1061: * @see org.netbeans.modules.uml.ui.controls.newdialog.INewDialogUI#getHelpIcon()
1062: */
1063: public Icon getHelpIcon() {
1064: Icon icon = null;
1065: icon = NewDialogUtilities.getIconForResource(jTextFieldDiagram
1066: .getText());
1067: return icon;
1068: }
1069:
1070: // End of variables declaration
1071:
1072: public boolean enableNextButton() {
1073: return false;
1074: }
1075:
1076: //list selection listener callback
1077: public void valueChanged(ListSelectionEvent e) {
1078: // Fix for bug#6283146
1079: jComboBox1.removeAllItems();
1080: String diaType = (String) list.getSelectedValue();
1081: if (diaType.equals(NewDialogResources
1082: .getString("PSK_SEQUENCE_DIAGRAM"))) // NOI18N
1083: {
1084: if (saveNamespaces.size() > 0)
1085: jComboBox1.addItem(saveNamespaces.get(0));
1086: } else {
1087: for (int i = 0; i < saveNamespaces.size(); i++)
1088: jComboBox1.addItem(saveNamespaces.get(i));
1089: }
1090: }
1091:
1092: class ElementListCellRenderer extends JLabel implements
1093: ListCellRenderer {
1094: public Icon getImageIcon(String diaName) {
1095: Icon retIcon = null;
1096: String displayName = NewDialogResources
1097: .getStringKey(diaName);
1098: String str = "//PropertyDefinition/aDefinition[@name='"
1099: + // NOI18N
1100: "Diagram" + "']/aDefinition[@displayName='"
1101: + displayName + "']"; // NOI18N
1102:
1103: org.dom4j.Node node = m_doc.selectSingleNode(str);
1104: if (node.getNodeType() == org.dom4j.Element.ELEMENT_NODE) {
1105: org.dom4j.Element elem = (org.dom4j.Element) node;
1106: String fileName = elem.attributeValue("image"); // NOI18N
1107: File file = new File(fileName);
1108:
1109: retIcon = CommonResourceManager.instance()
1110: .getIconForFile(fileName);
1111: }
1112:
1113: return retIcon;
1114: }
1115:
1116: public Component getListCellRendererComponent(JList list,
1117: Object value, // value to display
1118: int index, // cell index
1119: boolean isSelected, // is the cell selected
1120: boolean cellHasFocus) // the list and the cell have the focus
1121: {
1122: String s = value.toString();
1123: setText(s);
1124: setIcon(getImageIcon(s));
1125:
1126: if (isSelected) {
1127: setBackground(list.getSelectionBackground());
1128: setForeground(list.getSelectionForeground());
1129: }
1130:
1131: else {
1132: setBackground(list.getBackground());
1133: setForeground(list.getForeground());
1134: }
1135:
1136: setEnabled(list.isEnabled());
1137: setFont(list.getFont());
1138: setOpaque(true);
1139: return this;
1140: }
1141: }
1142: }
|