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: package org.netbeans.modules.cnd.builds;
043:
044: import java.util.Vector;
045: import java.util.ResourceBundle;
046: import java.awt.event.KeyEvent;
047: import java.awt.Toolkit;
048: import java.awt.Point;
049: import java.awt.event.ActionListener;
050: import java.awt.event.ActionEvent;
051: import java.beans.PropertyChangeEvent;
052: import java.beans.PropertyChangeListener;
053: import java.beans.PropertyEditorSupport;
054:
055: import javax.swing.JPanel;
056: import javax.swing.JList;
057: import javax.swing.JDialog;
058: import javax.swing.JFrame;
059: import javax.swing.JButton;
060: import javax.swing.event.ListSelectionListener;
061: import javax.swing.event.ListSelectionEvent;
062: import javax.swing.Timer;
063: import javax.accessibility.AccessibleContext;
064:
065: import org.openide.NotifyDescriptor;
066: import org.openide.DialogDisplayer;
067: import org.openide.explorer.propertysheet.PropertyEnv;
068: import org.openide.util.NbBundle;
069:
070: public class TargetEditor extends javax.swing.JPanel implements
071: PropertyChangeListener {
072: private JList targetList = null;
073: private Vector listData = new Vector();
074: private Timer isVisibleTimer;
075: private PropertyEditorSupport editor;
076:
077: private JDialog dialog = null;
078: private JButton okButton;
079: private JButton cancelButton;
080: private int returnValue = 0;
081: public final static int OK_OPTION = 0;
082: public final static int CANCEL_OPTION = 1;
083: private ResourceBundle bundle = NbBundle
084: .getBundle(TargetEditor.class);
085:
086: public TargetEditor(String[] targets, PropertyEditorSupport editor,
087: PropertyEnv env) {
088: this .editor = editor;
089: initComponents();
090: addButton.setMnemonic(bundle.getString(
091: "TARGET_EDITOR_ADD_BUTTON_MNEMONIC").toCharArray()[0]);
092: editButton
093: .setMnemonic(bundle.getString(
094: "TARGET_EDITOR_CHANGE_BUTTON_MNEMONIC")
095: .toCharArray()[0]);
096: removeButton
097: .setMnemonic(bundle.getString(
098: "TARGET_EDITOR_REMOVE_BUTTON_MNEMONIC")
099: .toCharArray()[0]);
100: upButton.setMnemonic(bundle.getString(
101: "TARGET_EDITOR_UP_BUTTON_MNEMONIC").toCharArray()[0]);
102: downButton.setMnemonic(bundle.getString(
103: "TARGET_EDITOR_DOWN_BUTTON_MNEMONIC").toCharArray()[0]);
104:
105: for (int i = 0; i < targets.length; i++)
106: listData.add(targets[i]);
107: targetList = new JList();
108: targetList.setListData(listData);
109: targetList
110: .addListSelectionListener(new TargetSelectionListener());
111: targetList.addKeyListener(new java.awt.event.KeyAdapter() {
112: public void keyPressed(java.awt.event.KeyEvent evt) {
113: targetListKeyPressed(evt);
114: }
115: });
116: scrollPane.setViewportView(targetList);
117: listLabel.setLabelFor(targetList);
118: checkSelection();
119:
120: initAccessibility();
121:
122: isVisibleTimer = new Timer(100, new ActionListener() {
123: public void actionPerformed(ActionEvent evt) {
124: if (addButton.isVisible()) {
125: if (targetList.getModel().getSize() > 0) {
126: targetList.setSelectedIndex(0);
127: targetList.requestFocus();
128: } else {
129: addButton.requestFocus();
130: }
131: isVisibleTimer.stop();
132: }
133: }
134: });
135: isVisibleTimer.start();
136:
137: if (env != null) {
138: env.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
139: env.addPropertyChangeListener(this );
140: }
141: }
142:
143: private void initAccessibility() {
144: AccessibleContext context;
145:
146: context = getAccessibleContext();
147: context.setAccessibleName(bundle
148: .getString("ACSN_TARGET_EDITOR"));
149: context.setAccessibleDescription(bundle
150: .getString("ACSD_TARGET_EDITOR"));
151:
152: context = targetList.getAccessibleContext();
153: context.setAccessibleName(bundle.getString("ACSN_TARGET_LIST"));
154: context.setAccessibleDescription(bundle
155: .getString("ACSD_TARGET_LIST"));
156:
157: context = scrollPane.getAccessibleContext();
158: context.setAccessibleName(bundle.getString("ACSN_TARGET_LIST"));
159: context.setAccessibleDescription(bundle
160: .getString("ACSD_TARGET_LIST"));
161:
162: context = scrollPane.getHorizontalScrollBar()
163: .getAccessibleContext();
164: context.setAccessibleName(bundle.getString("ACSN_TARGET_LIST"));
165: context.setAccessibleDescription(bundle
166: .getString("ACSD_TARGET_LIST"));
167:
168: context = scrollPane.getVerticalScrollBar()
169: .getAccessibleContext();
170: context.setAccessibleName(bundle.getString("ACSN_TARGET_LIST"));
171: context.setAccessibleDescription(bundle
172: .getString("ACSD_TARGET_LIST"));
173:
174: addButton.getAccessibleContext().setAccessibleDescription(
175: addButton.getText());
176: editButton.getAccessibleContext().setAccessibleDescription(
177: editButton.getText());
178: removeButton.getAccessibleContext().setAccessibleDescription(
179: removeButton.getText());
180: upButton.getAccessibleContext().setAccessibleDescription(
181: upButton.getText());
182: downButton.getAccessibleContext().setAccessibleDescription(
183: downButton.getText());
184: }
185:
186: /** This method is called from within the constructor to
187: * initialize the form.
188: * WARNING: Do NOT modify this code. The content of this method is
189: * always regenerated by the Form Editor.
190: */
191: private void initComponents() {//GEN-BEGIN:initComponents
192: java.awt.GridBagConstraints gridBagConstraints;
193:
194: dataPanel = new javax.swing.JPanel();
195: listLabel = new javax.swing.JLabel();
196: scrollPane = new javax.swing.JScrollPane();
197: controlsPanel = new javax.swing.JPanel();
198: addButton = new javax.swing.JButton();
199: editButton = new javax.swing.JButton();
200: removeButton = new javax.swing.JButton();
201: upButton = new javax.swing.JButton();
202: downButton = new javax.swing.JButton();
203:
204: setLayout(new java.awt.BorderLayout());
205:
206: setRequestFocusEnabled(false);
207: dataPanel.setLayout(new java.awt.GridBagLayout());
208:
209: dataPanel.setRequestFocusEnabled(false);
210: listLabel.setDisplayedMnemonic(java.util.ResourceBundle
211: .getBundle("org/netbeans/modules/cnd/builds/Bundle")
212: .getString("TARGET_EDITOR_LIST_MNEMONIC").charAt(0));
213: listLabel.setText(java.util.ResourceBundle.getBundle(
214: "org/netbeans/modules/cnd/builds/Bundle").getString(
215: "TARGET_EDITOR_LIST_LBL"));
216: gridBagConstraints = new java.awt.GridBagConstraints();
217: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
218: gridBagConstraints.insets = new java.awt.Insets(11, 10, 0, 0);
219: dataPanel.add(listLabel, gridBagConstraints);
220:
221: scrollPane.setBackground(new java.awt.Color(255, 255, 255));
222: scrollPane
223: .setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
224: scrollPane.setRequestFocusEnabled(false);
225: gridBagConstraints = new java.awt.GridBagConstraints();
226: gridBagConstraints.gridx = 0;
227: gridBagConstraints.gridy = 1;
228: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
229: gridBagConstraints.weightx = 1.0;
230: gridBagConstraints.weighty = 1.0;
231: gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
232: dataPanel.add(scrollPane, gridBagConstraints);
233:
234: controlsPanel.setLayout(new java.awt.GridBagLayout());
235:
236: controlsPanel.setRequestFocusEnabled(false);
237: addButton.setText(java.util.ResourceBundle.getBundle(
238: "org/netbeans/modules/cnd/builds/Bundle").getString(
239: "TARGET_EDITOR_ADD_BUTTON_LBL"));
240: addButton
241: .addActionListener(new java.awt.event.ActionListener() {
242: public void actionPerformed(
243: java.awt.event.ActionEvent evt) {
244: addButtonActionPerformed(evt);
245: }
246: });
247:
248: gridBagConstraints = new java.awt.GridBagConstraints();
249: gridBagConstraints.gridx = 0;
250: gridBagConstraints.gridy = 0;
251: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
252: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
253: controlsPanel.add(addButton, gridBagConstraints);
254:
255: editButton.setText(java.util.ResourceBundle.getBundle(
256: "org/netbeans/modules/cnd/builds/Bundle").getString(
257: "TARGET_EDITOR_CHANGE_BUTTON_LBL"));
258: editButton
259: .addActionListener(new java.awt.event.ActionListener() {
260: public void actionPerformed(
261: java.awt.event.ActionEvent evt) {
262: editButtonActionPerformed(evt);
263: }
264: });
265:
266: gridBagConstraints = new java.awt.GridBagConstraints();
267: gridBagConstraints.gridx = 0;
268: gridBagConstraints.gridy = 1;
269: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
271: controlsPanel.add(editButton, gridBagConstraints);
272:
273: removeButton.setText(java.util.ResourceBundle.getBundle(
274: "org/netbeans/modules/cnd/builds/Bundle").getString(
275: "TARGET_EDITOR_REMOVE_BUTTON_LBL"));
276: removeButton
277: .addActionListener(new java.awt.event.ActionListener() {
278: public void actionPerformed(
279: java.awt.event.ActionEvent evt) {
280: removeButtonActionPerformed(evt);
281: }
282: });
283:
284: gridBagConstraints = new java.awt.GridBagConstraints();
285: gridBagConstraints.gridx = 0;
286: gridBagConstraints.gridy = 2;
287: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
288: gridBagConstraints.insets = new java.awt.Insets(0, 6, 6, 0);
289: controlsPanel.add(removeButton, gridBagConstraints);
290:
291: upButton.setText(java.util.ResourceBundle.getBundle(
292: "org/netbeans/modules/cnd/builds/Bundle").getString(
293: "TARGET_EDITOR_UP_BUTTON_LBL"));
294: upButton.addActionListener(new java.awt.event.ActionListener() {
295: public void actionPerformed(java.awt.event.ActionEvent evt) {
296: upButtonActionPerformed(evt);
297: }
298: });
299:
300: gridBagConstraints = new java.awt.GridBagConstraints();
301: gridBagConstraints.gridx = 0;
302: gridBagConstraints.gridy = 3;
303: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
304: gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 0);
305: controlsPanel.add(upButton, gridBagConstraints);
306:
307: downButton.setText(java.util.ResourceBundle.getBundle(
308: "org/netbeans/modules/cnd/builds/Bundle").getString(
309: "TARGET_EDITOR_DOWN_BUTTON_LBL"));
310: downButton
311: .addActionListener(new java.awt.event.ActionListener() {
312: public void actionPerformed(
313: java.awt.event.ActionEvent evt) {
314: downButtonActionPerformed(evt);
315: }
316: });
317:
318: gridBagConstraints = new java.awt.GridBagConstraints();
319: gridBagConstraints.gridx = 0;
320: gridBagConstraints.gridy = 4;
321: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
322: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
323: controlsPanel.add(downButton, gridBagConstraints);
324:
325: gridBagConstraints = new java.awt.GridBagConstraints();
326: gridBagConstraints.gridx = 1;
327: gridBagConstraints.gridy = 1;
328: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
329: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
330: gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 10);
331: dataPanel.add(controlsPanel, gridBagConstraints);
332:
333: add(dataPanel, java.awt.BorderLayout.CENTER);
334:
335: }//GEN-END:initComponents
336:
337: private void targetListKeyPressed(java.awt.event.KeyEvent evt) {
338: // Add your handling code here:
339: processKeyEvent(evt);
340: }
341:
342: private void handleEscape(java.awt.event.KeyEvent evt) {
343: // Add your handling code here:
344: if (evt.isConsumed())
345: return;
346: if (evt.getKeyChar() == KeyEvent.VK_ESCAPE) {
347: evt.consume();
348: closeAction(dialog, CANCEL_OPTION);
349: }
350: }
351:
352: private void editAction() {
353: NotifyDescriptor.InputLine notifyDescriptor = new NotifyDescriptor.InputLine(
354: "", bundle.getString("TARGET_DIALOG_TITLE")); // NOI18N
355: int selectedIndex = targetList.getSelectedIndex();
356: notifyDescriptor.setInputText((String) listData
357: .elementAt(selectedIndex));
358: DialogDisplayer.getDefault().notify(notifyDescriptor);
359: if (notifyDescriptor.getValue() == NotifyDescriptor.OK_OPTION
360: && notifyDescriptor.getInputText().length() > 0) {
361: Object tmp = listData.elementAt(selectedIndex);
362: listData.removeElementAt(selectedIndex);
363: listData
364: .add(selectedIndex, notifyDescriptor.getInputText());
365: targetList.setListData(listData);
366: targetList.setSelectedIndex(selectedIndex);
367: }
368: checkSelection();
369: if (dialog != null)
370: dialog.setVisible(true); // to retain focus
371: editButton.requestFocus();
372: }
373:
374: private void editButtonActionPerformed(
375: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editButtonActionPerformed
376: // Add your handling code here:
377: editAction();
378: }//GEN-LAST:event_editButtonActionPerformed
379:
380: private void downAction() {
381: int selectedIndex = targetList.getSelectedIndex();
382: if (selectedIndex < 0)
383: return;
384: if (selectedIndex >= (listData.size() - 1))
385: return;
386: Object tmp = listData.elementAt(selectedIndex);
387: listData.removeElementAt(selectedIndex);
388: listData.add(++selectedIndex, tmp);
389: targetList.setListData(listData);
390: if (selectedIndex >= 0) {
391: targetList.ensureIndexIsVisible(selectedIndex);
392: targetList.setSelectedIndex(selectedIndex);
393: }
394: checkSelection();
395: if (dialog != null)
396: dialog.setVisible(true); // to retain focus
397: if (downButton.isEnabled())
398: downButton.requestFocus();
399: else
400: upButton.requestFocus();
401: }
402:
403: private void downButtonActionPerformed(
404: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downButtonActionPerformed
405: // Add your handling code here:
406: downAction();
407: }//GEN-LAST:event_downButtonActionPerformed
408:
409: private void upAction() {
410: int selectedIndex = targetList.getSelectedIndex();
411: if (selectedIndex <= 0)
412: return;
413: Object tmp = listData.elementAt(selectedIndex);
414: listData.removeElementAt(selectedIndex);
415: listData.add(--selectedIndex, tmp);
416: targetList.setListData(listData);
417: if (selectedIndex >= 0) {
418: targetList.ensureIndexIsVisible(selectedIndex);
419: targetList.setSelectedIndex(selectedIndex);
420: }
421: checkSelection();
422: if (dialog != null)
423: dialog.setVisible(true); // to retain focus
424: if (upButton.isEnabled())
425: upButton.requestFocus();
426: else
427: downButton.requestFocus();
428: }
429:
430: private void upButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upButtonActionPerformed
431: // Add your handling code here:
432: upAction();
433: }//GEN-LAST:event_upButtonActionPerformed
434:
435: private void removeAction() {
436: int selectedIndex = targetList.getSelectedIndex();
437: if (selectedIndex < 0)
438: return;
439: listData.removeElementAt(selectedIndex);
440: targetList.setListData(listData);
441: selectedIndex = (selectedIndex >= listData.size()) ? selectedIndex - 1
442: : selectedIndex;
443: if (selectedIndex >= 0) {
444: targetList.ensureIndexIsVisible(selectedIndex);
445: targetList.setSelectedIndex(selectedIndex);
446: }
447: checkSelection();
448: if (dialog != null)
449: dialog.setVisible(true); // to retain focus
450: if (removeButton.isEnabled())
451: removeButton.requestFocus();
452: else
453: addButton.requestFocus();
454: }
455:
456: private void removeButtonActionPerformed(
457: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
458: // Add your handling code here:
459: removeAction();
460: }//GEN-LAST:event_removeButtonActionPerformed
461:
462: private void addAction() {
463: NotifyDescriptor.InputLine notifyDescriptor = new NotifyDescriptor.InputLine(
464: "", bundle.getString("TARGET_DIALOG_TITLE")); // NOI18N
465: int addAtIndex = 0;
466: int selectedIndex = targetList.getSelectedIndex();
467: if (selectedIndex >= 0 && selectedIndex <= listData.size() - 1)
468: addAtIndex = selectedIndex + 1;
469: DialogDisplayer.getDefault().notify(notifyDescriptor);
470: if (notifyDescriptor.getValue() == NotifyDescriptor.OK_OPTION
471: && notifyDescriptor.getInputText() != null
472: && notifyDescriptor.getInputText().length() > 0) {
473: listData.add(addAtIndex, notifyDescriptor.getInputText());
474: targetList.setListData(listData);
475: targetList.setSelectedIndex(addAtIndex);
476: }
477: addButton.requestFocus();
478:
479: checkSelection();
480: if (dialog != null)
481: dialog.setVisible(true); // to retain focus
482: addButton.requestFocus();
483: }
484:
485: private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
486: // Add your handling code here:
487: addAction();
488: }//GEN-LAST:event_addButtonActionPerformed
489:
490: // Variables declaration - do not modify//GEN-BEGIN:variables
491: private javax.swing.JButton addButton;
492: private javax.swing.JPanel controlsPanel;
493: private javax.swing.JPanel dataPanel;
494: private javax.swing.JButton downButton;
495: private javax.swing.JButton editButton;
496: private javax.swing.JLabel listLabel;
497: private javax.swing.JButton removeButton;
498: private javax.swing.JScrollPane scrollPane;
499: private javax.swing.JButton upButton;
500:
501: // End of variables declaration//GEN-END:variables
502:
503: private void checkSelection() {
504: int i = targetList.getSelectedIndex();
505: if (i >= 0) {
506: addButton.setEnabled(true);
507: removeButton.setEnabled(true);
508: editButton.setEnabled(true);
509: if (i == 0)
510: upButton.setEnabled(false);
511: else
512: upButton.setEnabled(true);
513: if (i >= listData.size() - 1)
514: downButton.setEnabled(false);
515: else
516: downButton.setEnabled(true);
517: } else {
518: addButton.setEnabled(true);
519: removeButton.setEnabled(false);
520: editButton.setEnabled(false);
521: upButton.setEnabled(false);
522: downButton.setEnabled(false);
523: }
524: }
525:
526: private class TargetSelectionListener implements
527: ListSelectionListener {
528: public void valueChanged(ListSelectionEvent e) {
529: if (e.getValueIsAdjusting())
530: return;
531: checkSelection();
532: }
533: }
534:
535: public String getTargets() {
536: String targets = null;
537: for (int i = 0; i < targetList.getModel().getSize(); i++) {
538: if (i == 0)
539: targets = (String) targetList.getModel()
540: .getElementAt(0);
541: else
542: targets = targets + ", "
543: + targetList.getModel().getElementAt(i); // NOI18N
544: }
545: return targets;
546: }
547:
548: private Object getPropertyValue() throws IllegalStateException {
549: return getTargets();
550: }
551:
552: public void propertyChange(PropertyChangeEvent evt) {
553: if (PropertyEnv.PROP_STATE.equals(evt.getPropertyName())
554: && evt.getNewValue() == PropertyEnv.STATE_VALID) {
555: editor.setValue(getPropertyValue());
556: }
557: }
558:
559: private void closeAction(JDialog dialog, int ret) {
560: if (dialog != null) {
561: dialog.setVisible(false);
562: dialog.dispose();
563: returnValue = ret;
564: }
565: }
566:
567: public int showOpenDialog(JFrame parent) {
568: //Frame frame = parent instanceof Frame ? (Frame) parent : (Frame)SwingUtilities.getAncestorOfClass(Frame.class, parent);
569: dialog = new JDialog(parent, true);
570: dialog.getContentPane().add(this );
571: dialog.setTitle(bundle.getString("TARGET_EDITOR_TITLE"));
572: AccessibleContext context = dialog.getAccessibleContext();
573: context.setAccessibleName(bundle
574: .getString("ACSN_TARGET_EDITOR"));
575: context.setAccessibleDescription(bundle
576: .getString("ACSD_TARGET_EDITOR"));
577:
578: java.awt.event.KeyAdapter keyListener = new java.awt.event.KeyAdapter() {
579: public void keyPressed(java.awt.event.KeyEvent evt) {
580: handleEscape(evt);
581: }
582: };
583:
584: java.awt.GridBagConstraints gridBagConstraints;
585: JPanel buttonPanel = new JPanel();
586: okButton = new JButton();
587: okButton.setText(bundle
588: .getString("TARGET_EDITOR_OK_BUTTON_LBL"));
589: okButton.addActionListener(new java.awt.event.ActionListener() {
590: public void actionPerformed(java.awt.event.ActionEvent evt) {
591: closeAction(dialog, OK_OPTION);
592: }
593: });
594: okButton.getAccessibleContext().setAccessibleDescription(
595: okButton.getText());
596: getRootPane().setDefaultButton(okButton);
597:
598: cancelButton = new JButton();
599: cancelButton.setText(bundle
600: .getString("TARGET_EDITOR_CANCEL_BUTTON_LBL"));
601: cancelButton
602: .addActionListener(new java.awt.event.ActionListener() {
603: public void actionPerformed(
604: java.awt.event.ActionEvent evt) {
605: closeAction(dialog, CANCEL_OPTION);
606: }
607: });
608: cancelButton.getAccessibleContext().setAccessibleDescription(
609: cancelButton.getText());
610:
611: // Handle escape key press (is this really necessary to do per button ???? FIXUP
612: okButton.addKeyListener(keyListener);
613: cancelButton.addKeyListener(keyListener);
614: addButton.addKeyListener(keyListener);
615: editButton.addKeyListener(keyListener);
616: removeButton.addKeyListener(keyListener);
617: upButton.addKeyListener(keyListener);
618: downButton.addKeyListener(keyListener);
619: addKeyListener(keyListener);
620:
621: buttonPanel.setLayout(new java.awt.GridBagLayout());
622:
623: gridBagConstraints = new java.awt.GridBagConstraints();
624: gridBagConstraints.gridx = 0;
625: gridBagConstraints.gridy = 0;
626: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
627: buttonPanel.add(okButton, gridBagConstraints);
628:
629: gridBagConstraints = new java.awt.GridBagConstraints();
630: gridBagConstraints.gridx = 1;
631: gridBagConstraints.gridy = 0;
632: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
633: gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
634: buttonPanel.add(cancelButton, gridBagConstraints);
635:
636: gridBagConstraints = new java.awt.GridBagConstraints();
637: gridBagConstraints.gridx = 0;
638: gridBagConstraints.gridy = 2;
639: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
640: gridBagConstraints.insets = new java.awt.Insets(12, 0, 10, 10);
641: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
642: dataPanel.add(buttonPanel, gridBagConstraints);
643: //---
644: okButton.setPreferredSize(cancelButton.getPreferredSize());
645:
646: dialog.pack();
647: dialog.setLocation(findScreenCenter(dialog));
648: dialog.setVisible(true);
649: return returnValue;
650: }
651:
652: private Point findScreenCenter(JDialog dialog) {
653: Toolkit toolkit = Toolkit.getDefaultToolkit();
654: int x = toolkit.getScreenSize().width / 2 - dialog.getHeight()
655: / 2;
656: int y = toolkit.getScreenSize().height / 2 - dialog.getWidth()
657: / 2;
658: return new Point(x, y);
659: }
660: }
|