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-2006 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: package org.netbeans.modules.mercurial.ui.clone;
042:
043: import java.awt.Dialog;
044: import java.awt.event.ActionEvent;
045: import java.awt.event.ActionListener;
046: import java.beans.PropertyChangeEvent;
047: import java.beans.PropertyChangeListener;
048: import java.net.MalformedURLException;
049: import javax.swing.JButton;
050: import javax.swing.JRadioButton;
051: import javax.swing.event.DocumentEvent;
052: import javax.swing.event.DocumentListener;
053: import org.openide.DialogDescriptor;
054: import org.openide.DialogDisplayer;
055: import org.openide.util.HelpCtx;
056: import java.io.File;
057:
058: /**
059: *
060: * @author Padraig O'Briain
061: */
062: public class Clone implements PropertyChangeListener {
063:
064: private ClonePanel panel;
065: private JButton okButton;
066: private JButton cancelButton;
067: private final DocumentListener listener;
068:
069: /** Creates a new instance of Clone */
070: public Clone(File repository, File to) {
071: panel = new ClonePanel(repository, to);
072: okButton = new JButton();
073: org.openide.awt.Mnemonics.setLocalizedText(okButton,
074: org.openide.util.NbBundle.getMessage(CloneAction.class,
075: "CTL_CloneForm_Action_Clone"));
076: okButton.getAccessibleContext().setAccessibleName(
077: org.openide.util.NbBundle.getMessage(Clone.class,
078: "ACSN_CloneForm_Action_Clone")); // NOI18N
079: okButton.getAccessibleContext().setAccessibleDescription(
080: org.openide.util.NbBundle.getMessage(Clone.class,
081: "ACSD_CloneForm_Action_Clone")); // NOI18N
082: cancelButton = new JButton();
083: org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
084: org.openide.util.NbBundle.getMessage(CloneAction.class,
085: "CTL_CloneForm_Action_Cancel"));
086: cancelButton.getAccessibleContext().setAccessibleDescription(
087: org.openide.util.NbBundle.getMessage(Clone.class,
088: "ACSD_CloneForm_Action_Cancel")); // NOI18N
089: cancelButton.getAccessibleContext().setAccessibleName(
090: org.openide.util.NbBundle.getMessage(Clone.class,
091: "ACSN_CloneForm_Action_Cancel")); // NOI18N
092: this .listener = new DocumentListener() {
093: public void insertUpdate(DocumentEvent e) {
094: nameChange();
095: }
096:
097: public void removeUpdate(DocumentEvent e) {
098: nameChange();
099: }
100:
101: public void changedUpdate(DocumentEvent e) {
102: nameChange();
103: }
104: };
105: panel.toTextField.getDocument().addDocumentListener(listener);
106: }
107:
108: public boolean showDialog() {
109: DialogDescriptor dialogDescriptor = new DialogDescriptor(panel,
110: org.openide.util.NbBundle.getMessage(Clone.class,
111: "CTL_CloneDialog")); // NOI18N
112:
113: dialogDescriptor.setModal(true);
114: dialogDescriptor.setOptions(new Object[] { okButton,
115: cancelButton });
116: dialogDescriptor.setHelpCtx(new HelpCtx(this .getClass()));
117: dialogDescriptor.setValid(false);
118:
119: Dialog dialog = DialogDisplayer.getDefault().createDialog(
120: dialogDescriptor);
121: dialog.getAccessibleContext().setAccessibleDescription(
122: org.openide.util.NbBundle.getMessage(Clone.class,
123: "ACSD_CloneDialog")); // NOI18N
124: dialog.setVisible(true);
125: dialog.setResizable(false);
126: boolean ret = dialogDescriptor.getValue() == okButton;
127: return ret;
128: }
129:
130: private void nameChange() {
131: if (panel.toTextField.getText().trim().length() > 0)
132: okButton.setEnabled(true);
133: else
134: okButton.setEnabled(false);
135: }
136:
137: public void propertyChange(PropertyChangeEvent evt) {
138: if (okButton != null) {
139: boolean valid = ((Boolean) evt.getNewValue())
140: .booleanValue();
141: okButton.setEnabled(valid);
142: }
143: }
144:
145: public String getOutputFileName() {
146: if (panel == null)
147: return null;
148: return panel.getOutputFileName().trim();
149: }
150: }
|