📄 classmemberspecificationdialog.java
字号:
JButton cancelButton = new JButton(GUIResources.getMessage("cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { hide(); } }); // Add all panels to the main panel. JPanel mainPanel = new JPanel(layout); mainPanel.add(accessPanel, 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 ClassMemberSpecification to be represented in this dialog. */ public void setClassMemberSpecification(ClassMemberSpecification classMemberSpecification) { String name = classMemberSpecification.name; String descriptor = classMemberSpecification.descriptor; // Set the access radio buttons. setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_PRIVATE, privateRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_PROTECTED, protectedRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_STATIC, staticRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_VOLATILE, volatileRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_TRANSIENT, transientRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_SYNCHRONIZED, synchronizedRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_NATIVE, nativeRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons); setClassMemberSpecificationRadioButtons(classMemberSpecification, 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)); argumentsTextField.setText(descriptor == null ? "" : ClassUtil.externalMethodArguments(descriptor)); } } /** * Returns the ClassMemberSpecification currently represented in this dialog. */ public ClassMemberSpecification getClassMemberSpecification() { String name = nameTextField.getText(); String type = typeTextField.getText(); String arguments = argumentsTextField.getText(); boolean fullWildcard = name.equals("") || type.equals(""); ClassMemberSpecification classMemberSpecification = fullWildcard ? new ClassMemberSpecification(0, 0, null, null) : new ClassMemberSpecification(0, 0, name, isField ? ClassUtil.internalType(type) : ClassUtil.internalMethodDescriptor(type, ListUtil.commaSeparatedList(arguments))); // Also get the access radio button settings. getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_PRIVATE, privateRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_PROTECTED, protectedRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_STATIC, staticRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_VOLATILE, volatileRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_TRANSIENT, transientRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_SYNCHRONIZED, synchronizedRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_NATIVE, nativeRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons); getClassMemberSpecificationRadioButtons(classMemberSpecification, ClassConstants.INTERNAL_ACC_STRICT, strictRadioButtons); return classMemberSpecification; } /** * 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 setClassMemberSpecificationRadioButtons(ClassMemberSpecification classMemberSpecification, int flag, JRadioButton[] radioButtons) { if (radioButtons != null) { int index = (classMemberSpecification.requiredSetAccessFlags & flag) != 0 ? 0 : (classMemberSpecification.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 getClassMemberSpecificationRadioButtons(ClassMemberSpecification classMemberSpecification, int flag, JRadioButton[] radioButtons) { if (radioButtons != null) { if (radioButtons[0].isSelected()) { classMemberSpecification.requiredSetAccessFlags |= flag; } else if (radioButtons[1].isSelected()) { classMemberSpecification.requiredUnsetAccessFlags |= flag; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -