diff --git a/core.ui/src/org/netbeans/core/ui/options/general/AdvancedProxyPanel.form b/core.ui/src/org/netbeans/core/ui/options/general/AdvancedProxyPanel.form --- a/core.ui/src/org/netbeans/core/ui/options/general/AdvancedProxyPanel.form +++ b/core.ui/src/org/netbeans/core/ui/options/general/AdvancedProxyPanel.form @@ -6,8 +6,12 @@ + + + + diff --git a/core.ui/src/org/netbeans/core/ui/options/general/AdvancedProxyPanel.java b/core.ui/src/org/netbeans/core/ui/options/general/AdvancedProxyPanel.java --- a/core.ui/src/org/netbeans/core/ui/options/general/AdvancedProxyPanel.java +++ b/core.ui/src/org/netbeans/core/ui/options/general/AdvancedProxyPanel.java @@ -42,6 +42,8 @@ import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; +import org.openide.DialogDescriptor; +import org.openide.NotificationLineSupport; /** * @@ -53,6 +55,7 @@ private String oldHttpsPort; private String oldSocksHost; private String oldSocksPort; + private DialogDescriptor dd = null; /** Creates new form AdvancedProxyPanel */ AdvancedProxyPanel (GeneralOptionsModel model) { @@ -84,6 +87,35 @@ followHttpPortIfDemand (); } }); + tfHttpsProxyPort.getDocument().addDocumentListener(new DocumentListener() { + + public void insertUpdate(DocumentEvent arg0) { + validatePortValue(tfHttpsProxyPort.getText()); + } + + public void removeUpdate(DocumentEvent arg0) { + validatePortValue(tfHttpsProxyPort.getText()); + } + + public void changedUpdate(DocumentEvent arg0) { + validatePortValue(tfHttpsProxyPort.getText()); + } + }); + tfSocksPort.getDocument().addDocumentListener(new DocumentListener() { + + public void insertUpdate(DocumentEvent arg0) { + validatePortValue(tfSocksPort.getText()); + } + + public void removeUpdate(DocumentEvent arg0) { + validatePortValue(tfSocksPort.getText()); + } + + public void changedUpdate(DocumentEvent arg0) { + validatePortValue(tfSocksPort.getText()); + } + }); + } // helps implement OptionsPanelController @@ -176,12 +208,55 @@ } private void followHttpPortIfDemand () { + String port = tfHttpProxyPort.getText(); + validatePortValue(port); + if (! cbSameProxySettings.isSelected ()) { return ; } - String port = tfHttpProxyPort.getText (); + tfHttpsProxyPort.setText (port); tfSocksPort.setText (port); + + } + + private void validatePortValue(String port) { + clearError(); + if (port != null && port.length() > 0) { + try { + Integer.parseInt(port); + } catch (NumberFormatException nfex) { + showError(org.openide.util.NbBundle.getMessage( + AdvancedProxyPanel.class, + "LBL_AdvancedProxyPanel_PortError")); // NOI18N + } + } + } + + private void showError(String message) { + if (dd != null) { + NotificationLineSupport notificationLineSupport = + dd.getNotificationLineSupport(); + if (notificationLineSupport != null) { + notificationLineSupport.setErrorMessage(message); + } + dd.setValid(false); + } + } + + private void clearError() { + if (dd != null) { + NotificationLineSupport notificationLineSupport = + dd.getNotificationLineSupport(); + if (notificationLineSupport != null) { + notificationLineSupport.clearMessages(); + } + dd.setValid(true); + } + } + + public void setDialogDescriptor(DialogDescriptor dd) { + this.dd = dd; } /** This method is called from within the constructor to diff --git a/core.ui/src/org/netbeans/core/ui/options/general/Bundle.properties b/core.ui/src/org/netbeans/core/ui/options/general/Bundle.properties --- a/core.ui/src/org/netbeans/core/ui/options/general/Bundle.properties +++ b/core.ui/src/org/netbeans/core/ui/options/general/Bundle.properties @@ -150,6 +150,8 @@ LBL_GeneralOptionsPanel_bMoreProxy.AN=Advanced Proxy Settings LBL_GeneralOptionsPanel_bMoreProxy.AD=Open Advanced Proxy Settings +LBL_GeneralOptionsPanel_PortError=Port number must be an integer value. + LBL_GeneralOptionsPanel_lWebProxy=Proxy Settings\: LBL_AdvancedProxyPanel_lHttpProxyHost=HTTP &Proxy\: @@ -173,6 +175,7 @@ LBL_AdvancedProxyPanel_cbSameProxySettings=Use the same proxy settings for &all protocols LBL_AdvancedProxyPanel_Title=Advanced Proxy Options +LBL_AdvancedProxyPanel_PortError=Port number must be an integer value. GeneralOptionsPanel.rbUseSystemProxy.text=&Use System Proxy Settings GeneralOptionsPanel.lWebBrowser.text=&Web Browser\: GeneralOptionsPanel.rbNoProxy.text=&No Proxy diff --git a/core.ui/src/org/netbeans/core/ui/options/general/GeneralOptionsPanel.form b/core.ui/src/org/netbeans/core/ui/options/general/GeneralOptionsPanel.form --- a/core.ui/src/org/netbeans/core/ui/options/general/GeneralOptionsPanel.form +++ b/core.ui/src/org/netbeans/core/ui/options/general/GeneralOptionsPanel.form @@ -1,6 +1,9 @@
+ + + @@ -21,7 +24,7 @@ - + @@ -36,11 +39,15 @@ - + + + + + - + @@ -55,10 +62,10 @@ - + - + @@ -98,7 +105,10 @@ - + + + + @@ -276,5 +286,13 @@ + + + + + + + + diff --git a/core.ui/src/org/netbeans/core/ui/options/general/GeneralOptionsPanel.java b/core.ui/src/org/netbeans/core/ui/options/general/GeneralOptionsPanel.java --- a/core.ui/src/org/netbeans/core/ui/options/general/GeneralOptionsPanel.java +++ b/core.ui/src/org/netbeans/core/ui/options/general/GeneralOptionsPanel.java @@ -41,20 +41,30 @@ package org.netbeans.core.ui.options.general; +import java.awt.Color; import java.awt.Component; import java.awt.Cursor; +import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeSupport; import java.net.MalformedURLException; import java.net.URL; import javax.swing.AbstractButton; import javax.swing.ButtonGroup; +import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.UIManager; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import org.netbeans.beaninfo.editors.HtmlBrowser; +import org.netbeans.spi.options.OptionsPanelController; import org.openide.DialogDescriptor; import org.openide.DialogDisplayer; import org.openide.awt.Mnemonics; +import org.openide.util.ImageUtilities; import org.openide.util.Lookup; import org.openide.util.NbBundle; @@ -69,6 +79,8 @@ private GeneralOptionsModel model; private HtmlBrowser.FactoryEditor editor; private AdvancedProxyPanel advancedPanel; + private PropertyChangeSupport support = new PropertyChangeSupport(this); + private boolean valid = true; /** @@ -76,6 +88,15 @@ */ public GeneralOptionsPanel () { initComponents (); + + Color nbErrorForeground = UIManager.getColor("nb.errorForeground"); + if (nbErrorForeground == null) { + nbErrorForeground = new Color(255, 0, 0); + } + errorLabel.setForeground(nbErrorForeground); + Image img = ImageUtilities.loadImage("org/netbeans/core/ui/resources/error.png"); //NOI18N + errorLabel.setIcon(new ImageIcon(img)); + errorLabel.setVisible(false); loc (lWebBrowser, "Web_Browser"); loc (lWebProxy, "Web_Proxy"); @@ -95,6 +116,21 @@ cbWebBrowser.addActionListener (this); tfProxyHost.addActionListener (this); tfProxyPort.addActionListener (this); + + tfProxyPort.getDocument().addDocumentListener(new DocumentListener(){ + + public void insertUpdate(DocumentEvent e) { + validatePortValue(); + } + + public void removeUpdate(DocumentEvent e) { + validatePortValue(); + } + + public void changedUpdate(DocumentEvent e) { + validatePortValue(); + } + }); ButtonGroup bgProxy = new ButtonGroup (); bgProxy.add (rbNoProxy); @@ -165,6 +201,7 @@ jUsageCheck = new javax.swing.JCheckBox(); lblUsageInfo = new javax.swing.JLabel(); lblLearnMore = new javax.swing.JLabel(); + errorLabel = new javax.swing.JLabel(); lWebBrowser.setLabelFor(cbWebBrowser); org.openide.awt.Mnemonics.setLocalizedText(lWebBrowser, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lWebBrowser.text")); // NOI18N @@ -236,6 +273,8 @@ } }); + errorLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( @@ -246,7 +285,7 @@ .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() .add(lWebBrowser) .add(18, 18, 18) - .add(cbWebBrowser, 0, 1131, Short.MAX_VALUE) + .add(cbWebBrowser, 0, 1132, Short.MAX_VALUE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(editBrowserButton)) .add(jSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1291, Short.MAX_VALUE) @@ -260,11 +299,14 @@ .add(layout.createSequentialGroup() .add(17, 17, 17) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(bMoreProxy) + .add(layout.createSequentialGroup() + .add(bMoreProxy) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .add(errorLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1105, Short.MAX_VALUE)) .add(layout.createSequentialGroup() .add(lProxyHost) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(tfProxyHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 957, Short.MAX_VALUE) + .add(tfProxyHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1016, Short.MAX_VALUE) .add(12, 12, 12) .add(lProxyPort) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) @@ -274,10 +316,10 @@ .add(lUsage) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(lblUsageInfo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1171, Short.MAX_VALUE) + .add(lblUsageInfo, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1205, Short.MAX_VALUE) .add(layout.createSequentialGroup() .add(jUsageCheck) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 690, Short.MAX_VALUE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 838, Short.MAX_VALUE)) .add(lblLearnMore)))) .add(0, 0, 0)) ); @@ -307,7 +349,9 @@ .add(tfProxyHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(lProxyPort)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(bMoreProxy) + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(bMoreProxy) + .add(errorLabel)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(jSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) @@ -325,6 +369,7 @@ bMoreProxy.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "LBL_GeneralOptionsPanel_bMoreProxy.AD")); // NOI18N editBrowserButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.editBrowserButton.AN")); // NOI18N editBrowserButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.editBrowserButton.AD")); // NOI18N + errorLabel.getAccessibleContext().setAccessibleName(""); // NOI18N }// //GEN-END:initComponents private void editBrowserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editBrowserButtonActionPerformed @@ -358,6 +403,8 @@ advancedPanel = new AdvancedProxyPanel (model); } DialogDescriptor dd = new DialogDescriptor (advancedPanel, loc ("LBL_AdvancedProxyPanel_Title")); + advancedPanel.setDialogDescriptor(dd); + dd.createNotificationLineSupport(); advancedPanel.update (tfProxyHost.getText (), tfProxyPort.getText ()); DialogDisplayer.getDefault ().createDialog (dd).setVisible (true); if (DialogDescriptor.OK_OPTION.equals (dd.getValue ())) { @@ -407,6 +454,7 @@ private javax.swing.JButton bMoreProxy; private javax.swing.JComboBox cbWebBrowser; private javax.swing.JButton editBrowserButton; + private javax.swing.JLabel errorLabel; private javax.swing.JSeparator jSeparator2; private javax.swing.JSeparator jSeparator3; private javax.swing.JCheckBox jUsageCheck; @@ -424,7 +472,47 @@ private javax.swing.JTextField tfProxyPort; // End of variables declaration//GEN-END:variables - + + private void validatePortValue() { + clearError(); + + boolean oldValid = valid; + valid = isPortValid(); + if (!valid) { + showError(loc("LBL_GeneralOptionsPanel_PortError")); // NOI18N + } + + if (oldValid != valid) { + support.firePropertyChange( + new PropertyChangeEvent(this, + OptionsPanelController.PROP_VALID, oldValid, valid)); + } + } + + private boolean isPortValid() { + String port = tfProxyPort.getText(); + boolean portStatus = true; + if (port != null && port.length() > 0) { + try { + Integer.parseInt(port); + } catch (NumberFormatException nfex) { + portStatus = false; + } + } + + return portStatus; + } + + private void showError(String message) { + errorLabel.setVisible(true); + errorLabel.setText(message); + } + + private void clearError() { + errorLabel.setText(""); + errorLabel.setVisible(false); + } + private static String loc (String key, String... params) { return NbBundle.getMessage (GeneralOptionsPanel.class, key, params); } @@ -560,7 +648,7 @@ } boolean dataValid () { - return true; + return isPortValid(); } boolean isChanged () { @@ -569,6 +657,16 @@ if (!tfProxyPort.getText ().equals (model.getHttpProxyPort ())) return true; return changed; } + + @Override + public void addPropertyChangeListener(java.beans.PropertyChangeListener l) { + support.addPropertyChangeListener(l); + } + + @Override + public void removePropertyChangeListener(java.beans.PropertyChangeListener l) { + support.removePropertyChangeListener(l); + } public void actionPerformed (ActionEvent e) { changed = true; diff --git a/core.ui/src/org/netbeans/core/ui/resources/error.png b/core.ui/src/org/netbeans/core/ui/resources/error.png new file mode 100644 index 0000000000000000000000000000000000000000..7d0ea445ad52de447e5ab7d483938a637ea84255 GIT binary patch literal 730 zc$@*+0ww*4P)L* zh%lT1ssS0|2{Z&CfS5q6&4Pk4fByepY*<*x@bT6yhF|aAG5mh}mVrfBm;qz~hz9XN z;vjjDI*@vhK7arM8}JusvvFb~!}}{&7=FEe&F~wDf4+Lf@a6VxumK<%#0QCkOuMd0*D1pA3Kh{)Nl`0~!F*2M|DTFJKq|#J_+6cP%G}fejReJUk44frg+M0MrK% zKuj<%{0I6E8GizXxPZMqgXQ7FU>d|nR|C=q5I{^Y7qG%OPyh;jrKTnZb{QEkjhx^> z>R6%r00IcCXV0%+u{(f?haZ^I*jQK?Sb&(7m6hR6V`J3n;qz10bX9P&D=otnuiY=4goc9 z{`qqqKmf5oo%;=F$U2awzYiWPPSMf=hp;Fx;E(~x*>kR4V>tZ#ckEW6W{^IB0AfM% zGuRN2Pyb%KhBG%F1!~>~)ePbT1P~*7b_RI|NNM89&evg@K>#4Y0CcrqFDiIQj{pDw M07*qoM6N<$f_}v}MF0Q*