📄 classspecificationdialog.java
字号:
cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { hide(); } }); // Add all panels to the main panel. JPanel mainPanel = new JPanel(layout); mainPanel.add(commentsPanel, panelConstraints); if (fullKeepOptions) { mainPanel.add(keepOptionPanel, panelConstraints); mainPanel.add(allowOptionPanel, panelConstraints); } mainPanel.add(accessPanel, panelConstraints); mainPanel.add(annotationTypePanel, panelConstraints); mainPanel.add(classNamePanel, panelConstraints); mainPanel.add(extendsAnnotationTypePanel, panelConstraints); mainPanel.add(extendsClassNamePanel, panelConstraints); mainPanel.add(memberSpecificationsPanel, stretchPanelConstraints); mainPanel.add(okButton, okButtonConstraints); mainPanel.add(cancelButton, cancelButtonConstraints); getContentPane().add(mainPanel); } /** * Adds a JLabel and three JRadioButton instances in a ButtonGroup to the * given panel with a GridBagLayout, and returns the buttons in an array. */ private JRadioButton[] addRadioButtonTriplet(String labelText, JPanel panel) { GridBagConstraints labelConstraints = new GridBagConstraints(); labelConstraints.anchor = GridBagConstraints.WEST; labelConstraints.insets = new Insets(2, 10, 2, 10); GridBagConstraints buttonConstraints = new GridBagConstraints(); buttonConstraints.insets = labelConstraints.insets; GridBagConstraints lastGlueConstraints = new GridBagConstraints(); lastGlueConstraints.gridwidth = GridBagConstraints.REMAINDER; lastGlueConstraints.weightx = 1.0; // Create the radio buttons. JRadioButton radioButton0 = new JRadioButton(); JRadioButton radioButton1 = new JRadioButton(); JRadioButton radioButton2 = new JRadioButton(); // Put them in a button group. ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(radioButton0); buttonGroup.add(radioButton1); buttonGroup.add(radioButton2); // Add the label and the buttons to the panel. panel.add(new JLabel(labelText), labelConstraints); panel.add(radioButton0, buttonConstraints); panel.add(radioButton1, buttonConstraints); panel.add(radioButton2, buttonConstraints); panel.add(Box.createGlue(), lastGlueConstraints); return new JRadioButton[] { radioButton0, radioButton1, radioButton2 }; } /** * Sets the KeepSpecification to be represented in this dialog. */ public void setKeepSpecification(KeepSpecification keepSpecification) { boolean markClasses = keepSpecification.markClasses; boolean markConditionally = keepSpecification.markConditionally; boolean allowShrinking = keepSpecification.allowShrinking; boolean allowOptimization = keepSpecification.allowOptimization; boolean allowObfuscation = keepSpecification.allowObfuscation; // Figure out the proper keep radio button and set it. JRadioButton keepOptionRadioButton = markConditionally ? keepClassesWithMembersRadioButton : markClasses ? keepClassesAndMembersRadioButton : keepClassMembersRadioButton; keepOptionRadioButton.setSelected(true); // Set the allow radio buttons. allowShrinkingRadioButton .setSelected(allowShrinking); allowOptimizationRadioButton.setSelected(allowOptimization); allowObfuscationRadioButton .setSelected(allowObfuscation); setClassSpecification(keepSpecification); } /** * Sets the ClassSpecification to be represented in this dialog. */ public void setClassSpecification(ClassSpecification classSpecification) { String comments = classSpecification.comments; String annotationType = classSpecification.annotationType; String className = classSpecification.className; String extendsAnnotationType = classSpecification.extendsAnnotationType; String extendsClassName = classSpecification.extendsClassName; List keepFieldOptions = classSpecification.fieldSpecifications; List keepMethodOptions = classSpecification.methodSpecifications; // Set the comments text area. commentsTextArea.setText(comments == null ? "" : comments); // Set the access radio buttons. setClassSpecificationRadioButtons(classSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons); setClassSpecificationRadioButtons(classSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons); setClassSpecificationRadioButtons(classSpecification, ClassConstants.INTERNAL_ACC_INTERFACE, interfaceRadioButtons); setClassSpecificationRadioButtons(classSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons); // Set the class and annotation text fields. annotationTypeTextField .setText(annotationType == null ? "" : ClassUtil.externalType(annotationType)); classNameTextField .setText(className == null ? "*" : ClassUtil.externalClassName(className)); extendsAnnotationTypeTextField.setText(extendsAnnotationType == null ? "" : ClassUtil.externalType(extendsAnnotationType)); extendsClassNameTextField .setText(extendsClassName == null ? "" : ClassUtil.externalClassName(extendsClassName)); // Set the keep class member option list. memberSpecificationsPanel.setMemberSpecifications(keepFieldOptions, keepMethodOptions); } /** * Returns the KeepSpecification currently represented in this dialog. */ public KeepSpecification getKeepSpecification() { boolean markClasses = !keepClassMembersRadioButton .isSelected(); boolean markConditionally = keepClassesWithMembersRadioButton.isSelected(); boolean allowShrinking = allowShrinkingRadioButton .isSelected(); boolean allowOptimization = allowOptimizationRadioButton .isSelected(); boolean allowObfuscation = allowObfuscationRadioButton .isSelected(); return new KeepSpecification(markClasses, markConditionally, allowShrinking, allowOptimization, allowObfuscation, getClassSpecification()); } /** * Returns the ClassSpecification currently represented in this dialog. */ public ClassSpecification getClassSpecification() { String comments = commentsTextArea.getText(); String annotationType = annotationTypeTextField.getText(); String className = classNameTextField.getText(); String extendsAnnotationType = extendsAnnotationTypeTextField.getText(); String extendsClassName = extendsClassNameTextField.getText(); ClassSpecification classSpecification = new ClassSpecification(comments.equals("") ? null : comments, 0, 0, annotationType.equals("") ? null : ClassUtil.internalType(annotationType), className.equals("") || className.equals("*") ? null : ClassUtil.internalClassName(className), extendsAnnotationType.equals("") ? null : ClassUtil.internalType(extendsAnnotationType), extendsClassName.equals("") ? null : ClassUtil.internalClassName(extendsClassName)); // Also get the access radio button settings. getClassSpecificationRadioButtons(classSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons); getClassSpecificationRadioButtons(classSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons); getClassSpecificationRadioButtons(classSpecification, ClassConstants.INTERNAL_ACC_INTERFACE, interfaceRadioButtons); getClassSpecificationRadioButtons(classSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons); // Get the keep class member option lists. classSpecification.fieldSpecifications = memberSpecificationsPanel.getMemberSpecifications(true); classSpecification.methodSpecifications = memberSpecificationsPanel.getMemberSpecifications(false); return classSpecification; } /** * Shows this dialog. This method only returns when the dialog is closed. * * @return <code>CANCEL_OPTION</code> or <code>APPROVE_OPTION</code>, * depending on the choice of the user. */ public int showDialog() { returnValue = CANCEL_OPTION; // Open the dialog in the right place, then wait for it to be closed, // one way or another. pack(); setLocationRelativeTo(getOwner()); show(); return returnValue; } /** * Sets the appropriate radio button of a given triplet, based on the access * flags of the given keep option. */ private void setClassSpecificationRadioButtons(ClassSpecification classSpecification, int flag, JRadioButton[] radioButtons) { int index = (classSpecification.requiredSetAccessFlags & flag) != 0 ? 0 : (classSpecification.requiredUnsetAccessFlags & flag) != 0 ? 1 : 2; radioButtons[index].setSelected(true); } /** * Updates the access flag of the given keep option, based on the given radio * button triplet. */ private void getClassSpecificationRadioButtons(ClassSpecification classSpecification, int flag, JRadioButton[] radioButtons) { if (radioButtons[0].isSelected()) { classSpecification.requiredSetAccessFlags |= flag; } else if (radioButtons[1].isSelected()) { classSpecification.requiredUnsetAccessFlags |= flag; } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -