@@ -133,14 +133,14 @@ public boolean isCellEditable(int row, int column) {
133133 dialog .add (contentPanel , BorderLayout .CENTER );
134134
135135 // 从scopePanel提取组件引用
136- JCheckBox enableScopeCheck = ( JCheckBox ) findComponentByName ( scopePanel , "enableScopeCheck" );
137- JComboBox <String > protocolCombo = ( JComboBox < String >) findComponentByName ( scopePanel , "protocolCombo" );
138- JTextField hostField = ( JTextField ) findComponentByName ( scopePanel , "hostField" );
139- JTextField pathField = ( JTextField ) findComponentByName ( scopePanel , "pathField" );
140- JCheckBox useRegexCheck = ( JCheckBox ) findComponentByName ( scopePanel , "useRegexCheck" );
141- JSpinner ttlSpinner = ( JSpinner ) findComponentByName ( scopePanel , "ttlSpinner" );
142- JComboBox <String > strategyCombo = ( JComboBox < String >) findComponentByName ( scopePanel , "strategyCombo" );
143- JSpinner prioritySpinner = ( JSpinner ) findComponentByName ( scopePanel , "prioritySpinner" );
136+ JCheckBox enableScopeCheck = findComponentByType ( scopePanel , "enableScopeCheck" , JCheckBox . class );
137+ JComboBox <? > protocolCombo = findComponentByType ( scopePanel , "protocolCombo" , JComboBox . class );
138+ JTextField hostField = findComponentByType ( scopePanel , "hostField" , JTextField . class );
139+ JTextField pathField = findComponentByType ( scopePanel , "pathField" , JTextField . class );
140+ JCheckBox useRegexCheck = findComponentByType ( scopePanel , "useRegexCheck" , JCheckBox . class );
141+ JSpinner ttlSpinner = findComponentByType ( scopePanel , "ttlSpinner" , JSpinner . class );
142+ JComboBox <? > strategyCombo = findComponentByType ( scopePanel , "strategyCombo" , JComboBox . class );
143+ JSpinner prioritySpinner = findComponentByType ( scopePanel , "prioritySpinner" , JSpinner . class );
144144
145145 // 底部按钮
146146 JPanel buttonPanel = new JPanel (new FlowLayout (FlowLayout .RIGHT ));
@@ -164,7 +164,8 @@ public boolean isCellEditable(int row, int column) {
164164
165165 String scopeJson = "null" ;
166166 if (enableScopeCheck .isSelected ()) {
167- String protocol = (String ) protocolCombo .getSelectedItem ();
167+ Object protocolObj = protocolCombo .getSelectedItem ();
168+ String protocol = protocolObj != null ? protocolObj .toString () : "" ;
168169 String host = hostField .getText ().trim ();
169170 String path = pathField .getText ().trim ();
170171 boolean useRegex = useRegexCheck .isSelected ();
@@ -176,7 +177,8 @@ public boolean isCellEditable(int row, int column) {
176177 }
177178
178179 int ttl = (Integer ) ttlSpinner .getValue ();
179- String strategy = (String ) strategyCombo .getSelectedItem ();
180+ Object strategyObj = strategyCombo .getSelectedItem ();
181+ String strategy = strategyObj != null ? strategyObj .toString () : "REPLACE" ;
180182 int priority = (Integer ) prioritySpinner .getValue ();
181183
182184 sendSessionHeadersToBackend (selectedHeaders , scopeJson , ttl , strategy , priority );
@@ -307,6 +309,21 @@ private Component findComponentByName(Container container, String name) {
307309 return null ;
308310 }
309311
312+ /**
313+ * 根据名称和类型安全地查找组件
314+ * @param container 容器
315+ * @param name 组件名称
316+ * @param type 期望的组件类型
317+ * @return 找到的组件,如果未找到或类型不匹配则返回null
318+ */
319+ private <T extends Component > T findComponentByType (Container container , String name , Class <T > type ) {
320+ Component component = findComponentByName (container , name );
321+ if (component != null && type .isInstance (component )) {
322+ return type .cast (component );
323+ }
324+ return null ;
325+ }
326+
310327 /**
311328 * 发送会话Header到后端
312329 */
0 commit comments