/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2010 Oracle and/or its affiliates. All rights reserved.
*
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License. When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*
* Contributor(s):
*
* Portions Copyrighted 2008 Sun Microsystems, Inc.
*/
package org.netbeans.modules.ruby.debugger.ui;
import java.beans.PropertyChangeListener;
import javax.swing.JPanel;
import org.netbeans.modules.ruby.debugger.Util;
import org.netbeans.modules.ruby.platform.spi.RubyDebuggerImplementation;
import org.netbeans.spi.debugger.ui.Controller;
import org.openide.util.Lookup;
import org.openide.util.NbBundle;
public final class ConnectPanel extends JPanel {
private ConnectController controller;
public ConnectPanel() {
initComponents();
// default values
hostField.setText("localhost"); // NOI18N
portField.setText("7000"); // NOI18N
timeoutField.setText("15"); // NOI18N
controller = new ConnectController();
}
ConnectController getController() {
return controller;
}
private boolean check() {
try {
getPort();
} catch (NumberFormatException _) {
Util.showWarning(NbBundle.getMessage(ConnectPanel.class, "ConnectPanel.InvalidPort"));
return false;
}
return true;
}
private String getHost() {
return hostField.getText().trim();
}
private int getPort() {
return Integer.parseInt(portField.getText().trim());
}
private int getTimeout() {
try {
return Integer.parseInt(timeoutField.getText().trim());
} catch (NumberFormatException nfe) {
return 15; // default 15s
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
hostLabel = new javax.swing.JLabel();
hostField = new javax.swing.JTextField();
portLabel = new javax.swing.JLabel();
portField = new javax.swing.JTextField();
timeoutLabel = new javax.swing.JLabel();
timeoutField = new javax.swing.JTextField();
hostLabel.setLabelFor(hostField);
org.openide.awt.Mnemonics.setLocalizedText(hostLabel, org.openide.util.NbBundle.getMessage(ConnectPanel.class, "ConnectPanel.hostLabel.text")); // NOI18N
portLabel.setLabelFor(portField);
org.openide.awt.Mnemonics.setLocalizedText(portLabel, org.openide.util.NbBundle.getMessage(ConnectPanel.class, "ConnectPanel.portLabel.text")); // NOI18N
timeoutLabel.setLabelFor(timeoutField);
org.openide.awt.Mnemonics.setLocalizedText(timeoutLabel, org.openide.util.NbBundle.getMessage(ConnectPanel.class, "ConnectPanel.timeoutLabel.text")); // NOI18N
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(hostLabel)
.add(portLabel)
.add(timeoutLabel))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(portField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
.add(hostField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE)
.add(timeoutField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 361, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(hostLabel)
.add(hostField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(portLabel)
.add(portField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(timeoutLabel)
.add(timeoutField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField hostField;
private javax.swing.JLabel hostLabel;
private javax.swing.JTextField portField;
private javax.swing.JLabel portLabel;
private javax.swing.JTextField timeoutField;
private javax.swing.JLabel timeoutLabel;
// End of variables declaration//GEN-END:variables
final class ConnectController implements Controller {
public boolean ok() {
final RubyDebuggerImplementation debugger = Lookup.getDefault().lookup(RubyDebuggerImplementation.class);
if (!check()) {
return false;
}
new Thread(new Runnable() {
public void run() {
debugger.attach(getHost(), getPort(), getTimeout());
}
}, "Ruby Debugger Attach").start();
return true;
}
public boolean isValid() {
return true;
}
public boolean cancel() {
return true;
}
public void addPropertyChangeListener(PropertyChangeListener l) {
}
public void removePropertyChangeListener(PropertyChangeListener l) {
}
}
}