001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * Created on Feb 25, 2004
044: *
045: */
046: package org.netbeans.modules.uml.ui.controls.editcontrol;
047:
048: import java.awt.BorderLayout;
049: import java.awt.GridBagConstraints;
050: import java.awt.GridBagLayout;
051: import java.awt.Insets;
052: import java.awt.event.ActionListener;
053:
054: import javax.swing.Box;
055: import javax.swing.JButton;
056: import javax.swing.JLabel;
057: import javax.swing.JList;
058: import javax.swing.JPanel;
059: import javax.swing.JScrollPane;
060: import javax.swing.ListSelectionModel;
061: import javax.swing.event.ListSelectionEvent;
062: import javax.swing.event.ListSelectionListener;
063:
064: import org.netbeans.modules.uml.core.support.umlsupport.IStrings;
065: import org.netbeans.modules.uml.ui.support.drawingproperties.DrawingPropertyResource;
066: import org.netbeans.modules.uml.ui.swing.commondialogs.JCenterDialog;
067:
068: import java.awt.event.ActionEvent;
069:
070: /**
071: * @author jingmingm
072: *
073: */
074: public class EditControlClassChooser extends JCenterDialog {
075: protected static String m_ClassName = "";
076:
077: protected JLabel m_selectedClassName = null;
078: protected static JLabel m_sampleField = null;
079: protected JButton m_cancel = null;
080: protected JButton m_ok = null;
081: protected static JList m_NameList = null;
082:
083: protected void init(IStrings strs) {
084: getContentPane().setLayout(new BorderLayout());
085:
086: JPanel namePanel = new JPanel();
087: namePanel.setLayout(new GridBagLayout());
088:
089: getContentPane().add(namePanel, BorderLayout.CENTER);
090: JPanel buttonPanel = new JPanel();
091: getContentPane().add(buttonPanel, BorderLayout.SOUTH);
092:
093: // Add Class name
094: m_selectedClassName = new JLabel();
095: m_selectedClassName.setText(DrawingPropertyResource
096: .getString("IDS_CHOOSECLASSLABEL"));
097: GridBagConstraints constraints = new GridBagConstraints();
098: constraints.gridx = 0;
099: constraints.gridy = 0;
100: constraints.insets = new Insets(10, 5, 10, 5);
101: constraints.fill = GridBagConstraints.BOTH;
102: namePanel.add(m_selectedClassName, constraints);
103:
104: Object[] names = strs.toArray();
105: m_NameList = new JList(names);
106: m_NameList.setVisibleRowCount(10);
107: m_NameList
108: .setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
109: m_NameList
110: .addListSelectionListener(new ListSelectionListener() {
111: public void valueChanged(ListSelectionEvent e) {
112: JList names = (JList) e.getSource();
113: m_ClassName = (String) names.getSelectedValue();
114: }
115: });
116:
117: JScrollPane pane = new JScrollPane(m_NameList);
118: constraints = new GridBagConstraints();
119: constraints.gridx = 0;
120: constraints.gridy = 1;
121: constraints.fill = GridBagConstraints.BOTH;
122: constraints.weightx = 1.0;
123: constraints.weighty = 1.0;
124: constraints.insets = new Insets(0, 5, 0, 5);
125: namePanel.add(pane, constraints);
126:
127: // Add buttons
128: m_ok = new JButton();
129: m_ok.setText(DrawingPropertyResource.getString("IDS_OK"));
130: buttonPanel.add(m_ok, BorderLayout.WEST);
131: m_ok.addActionListener(new ActionListener() {
132: public void actionPerformed(ActionEvent e) {
133: okPressed(e);
134: }
135: });
136:
137: m_cancel = new JButton();
138: m_cancel.setText(DrawingPropertyResource
139: .getString("IDS_CANCEL"));
140: buttonPanel.add(m_cancel, BorderLayout.EAST);
141: m_cancel.addActionListener(new ActionListener() {
142: public void actionPerformed(ActionEvent e) {
143: cancelPressed(e);
144: }
145: });
146: setTitle(DrawingPropertyResource.getString("IDS_CHOOSECLASS"));
147: setSize(400, 300);
148: }
149:
150: public EditControlClassChooser(IStrings strs) {
151: init(strs);
152: }
153:
154: protected void cancelPressed(ActionEvent e) {
155: m_ClassName = null;
156: dispose();
157: }
158:
159: protected void okPressed(ActionEvent e) {
160: dispose();
161: }
162:
163: public String selectClass() {
164: String name = null;
165: setModal(true);
166: setVisible(true);
167: name = m_ClassName;
168: return name;
169: }
170:
171: }
|