📄 memberspecificationdialog.java
字号:
mainPanel.add(accessPanel, panelConstraints); mainPanel.add(annotationTypePanel, panelConstraints); mainPanel.add(typePanel, panelConstraints); mainPanel.add(namePanel, panelConstraints); if (!isField) { mainPanel.add(argumentsPanel, panelConstraints); } 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 MemberSpecification to be represented in this dialog. */ public void setMemberSpecification(MemberSpecification memberSpecification) { String annotationType = memberSpecification.annotationType; String name = memberSpecification.name; String descriptor = memberSpecification.descriptor; // Set the class name text fields. annotationTypeTextField.setText(annotationType == null ? "" : ClassUtil.externalType(annotationType)); // Set the access radio buttons. setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_PRIVATE, privateRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_PROTECTED, protectedRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_STATIC, staticRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_VOLATILE, volatileRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_TRANSIENT, transientRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_SYNCHRONIZED, synchronizedRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_NATIVE, nativeRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons); setMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_STRICT, strictRadioButtons); // Set the class name text fields. nameTextField.setText(name == null ? "" : name); if (isField) { typeTextField .setText(descriptor == null ? "" : ClassUtil.externalType(descriptor)); } else { typeTextField .setText(descriptor == null ? "" : ClassUtil.externalMethodReturnType(descriptor)); argumentTypesTextField.setText(descriptor == null ? "" : ClassUtil.externalMethodArguments(descriptor)); } } /** * Returns the MemberSpecification currently represented in this dialog. */ public MemberSpecification getMemberSpecification() { String annotationType = annotationTypeTextField.getText(); String name = nameTextField.getText(); String type = typeTextField.getText(); String arguments = argumentTypesTextField.getText(); // Convert all class member specifications into the internal format. annotationType = annotationType.equals("") ? null : ClassUtil.internalType(annotationType); if (name.equals("") || name.equals("*")) { name = null; } if (type.equals("") || type.equals("*")) { type = null; } if (name != null || type != null) { if (isField) { if (type == null) { type = ClassConstants.EXTERNAL_TYPE_INT; } type = ClassUtil.internalType(type); } else { if (type == null) { type = ClassConstants.EXTERNAL_TYPE_VOID; } type = ClassUtil.internalMethodDescriptor(type, ListUtil.commaSeparatedList(arguments)); } } MemberSpecification memberSpecification = new MemberSpecification(0, 0, annotationType, name, type); // Also get the access radio button settings. getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_PRIVATE, privateRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_PROTECTED, protectedRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_STATIC, staticRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_VOLATILE, volatileRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_TRANSIENT, transientRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_SYNCHRONIZED, synchronizedRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_NATIVE, nativeRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons); getMemberSpecificationRadioButtons(memberSpecification, ClassConstants.INTERNAL_ACC_STRICT, strictRadioButtons); return memberSpecification; } /** * 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 setMemberSpecificationRadioButtons(MemberSpecification memberSpecification, int flag, JRadioButton[] radioButtons) { if (radioButtons != null) { int index = (memberSpecification.requiredSetAccessFlags & flag) != 0 ? 0 : (memberSpecification.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 getMemberSpecificationRadioButtons(MemberSpecification memberSpecification, int flag, JRadioButton[] radioButtons) { if (radioButtons != null) { if (radioButtons[0].isSelected()) { memberSpecification.requiredSetAccessFlags |= flag; } else if (radioButtons[1].isSelected()) { memberSpecification.requiredUnsetAccessFlags |= flag; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -