memberspecificationdialog.java

来自「proguard 一个java的混淆器」· Java 代码 · 共 498 行 · 第 1/2 页

JAVA
498
字号
        // Add all panels to the main panel.        JPanel mainPanel = new JPanel(layout);        mainPanel.add(tip(accessPanel,         "accessTip"),       panelConstraints);        mainPanel.add(tip(annotationTypePanel, "annotationTip"),   panelConstraints);        mainPanel.add(tip(typePanel, isField ? "fieldTypeTip" :                                               "returnTypeTip"),   panelConstraints);        mainPanel.add(tip(namePanel,           "nameTip"),         panelConstraints);        if (!isField)        {            mainPanel.add(tip(argumentsPanel, "argumentTypesTip"), panelConstraints);        }        mainPanel.add(tip(advancedButton, "advancedTip"), advancedButtonConstraints);        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("") ||            annotationType.equals("***") ? null : ClassUtil.internalType(annotationType);        if (name.equals("") ||            name.equals("*"))        {            name = null;        }        if (isField)        {            type =                type.equals("") ||                type.equals("***") ? null : ClassUtil.internalType(type);        }        else        {            if (type.equals(""))            {                type = ClassConstants.EXTERNAL_TYPE_VOID;            }            type =                type     .equals("***") &&                arguments.equals("...") ? null :                    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;            }        }    }    /**     * Attaches the tool tip from the GUI resources that corresponds to the     * given key, to the given component.     */    private static JComponent tip(JComponent component, String messageKey)    {        component.setToolTipText(msg(messageKey));        return component;    }    /**     * Returns the message from the GUI resources that corresponds to the given     * key.     */    private static String msg(String messageKey)    {         return GUIResources.getMessage(messageKey);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?