<commit_before>/* 
 * Copyright 2014 <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package se.trixon.toolbox.core.base;

import java.awt.event.ActionEvent;
import java.util.MissingResourceException;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import org.netbeans.api.options.OptionsDisplayer;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
import se.trixon.toolbox.core.ToolProvider;
import se.trixon.toolbox.core.actions.ToolInfoAction;
import se.trixon.toolbox.core.actions.ToolOptionsAction;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public abstract class ToolController implements ToolProvider {

    private ActionMap mActionMap;
    private ToolTopComponent mToolTopComponent;

    public ToolController() {
    }

    public ToolController(ToolTopComponent toolTopComponent) {
        mToolTopComponent = toolTopComponent;
        mActionMap = toolTopComponent.getActionMap();

        init();
    }

    @Override
    public String getCategory() {
        return getResource("OpenIDE-Module-Display-Category");
    }

    @Override
    public String getDescription() {
        return getResource("OpenIDE-Module-Short-Description");
    }

    @Override
    public String getName() {
        return getResource("OpenIDE-Module-Name");
    }

    @Override
    public String getOptionsPath() {
        return null;
    }

    public String getResource(String key) {
        try {
            return NbBundle.getMessage(this.getClass(), key);
        } catch (MissingResourceException e) {
            return "";
        }
    }

    public ToolTopComponent getToolTopComponent() {
        return mToolTopComponent;
    }

    protected void setActiveInformation(boolean state) {

        if (state) {
            mActionMap.put(ToolInfoAction.KEY, new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    showDescription();
                }
            });
        } else {
            mActionMap.remove(ToolInfoAction.KEY);
        }
    }

    protected void setActiveOptions(boolean state) {
        if (state) {
            mActionMap.put(ToolOptionsAction.KEY, new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    showOptions();
                }
            });
        } else {
            mActionMap.remove(ToolOptionsAction.KEY);
        }
    }

    private void init() {
        setActiveInformation(true);
        setActiveOptions(getOptionsPath() != null);
    }

    private void showDescription() {
        String message = String.format("%s %s\n%s\n\n%s", getName(), getVersion(), getDescription(), getCopyright());

        NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Message(message, NotifyDescriptor.INFORMATION_MESSAGE);
        notifyDescriptor.setTitle(NbBundle.getMessage(ToolInfoAction.class, "CTL_ToolInfoAction"));
        DialogDisplayer.getDefault().notify(notifyDescriptor);
    }

    private void showOptions() {
        OptionsDisplayer.getDefault().open(getOptionsPath());
    }
}
<commit_msg>New Tool meta info structure<commit_after>/*
 * Copyright 2014 <NAME>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package se.trixon.toolbox.core.base;

import java.awt.event.ActionEvent;
import java.util.MissingResourceException;
import javax.swing.AbstractAction;
import javax.swing.ActionMap;
import org.netbeans.api.options.OptionsDisplayer;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.util.NbBundle;
import se.trixon.toolbox.core.ToolProvider;
import se.trixon.toolbox.core.actions.ToolInfoAction;
import se.trixon.toolbox.core.actions.ToolOptionsAction;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public class ToolController implements ToolProvider {

    private ActionMap mActionMap;
    private ToolTopComponent mToolTopComponent;

    public ToolController() {
    }

    public ToolController(ToolTopComponent toolTopComponent) {
        mToolTopComponent = toolTopComponent;
        mActionMap = toolTopComponent.getActionMap();

        init();
    }

    @Override
    public String getCategory() {
        return getResource("Tool-Category");
    }

    @Override
    public String getCopyright() {
        return getResource("Tool-Copyright");
    }

    @Override
    public String getDescription() {
        return getResource("Tool-Description");
    }

    @Override
    public String getLicense() {
        return getResource("Tool-License");
    }

    @Override
    public String getName() {
        return getResource("Tool-Name");
    }

    @Override
    public String getOptionsPath() {
        return null;
    }

    public String getResource(String key) {
        try {
            return NbBundle.getMessage(this.getClass(), key);
        } catch (MissingResourceException e) {
            return "";
        }
    }

    public ToolTopComponent getToolTopComponent() {
        return mToolTopComponent;
    }

    @Override
    public String getVersion() {
        return getResource("Tool-Version");
    }

    protected void setActiveInformation(boolean state) {

        if (state) {
            mActionMap.put(ToolInfoAction.KEY, new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    showDescription();
                }
            });
        } else {
            mActionMap.remove(ToolInfoAction.KEY);
        }
    }

    protected void setActiveOptions(boolean state) {
        if (state) {
            mActionMap.put(ToolOptionsAction.KEY, new AbstractAction() {

                @Override
                public void actionPerformed(ActionEvent ae) {
                    showOptions();
                }
            });
        } else {
            mActionMap.remove(ToolOptionsAction.KEY);
        }
    }

    private void init() {
        setActiveInformation(true);
        setActiveOptions(getOptionsPath() != null);
    }

    private void showDescription() {
        String message = String.format("%s %s\n%s\n\n%s", getName(), getVersion(), getDescription(), getCopyright());

        NotifyDescriptor notifyDescriptor = new NotifyDescriptor.Message(message, NotifyDescriptor.INFORMATION_MESSAGE);
        notifyDescriptor.setTitle(NbBundle.getMessage(ToolInfoAction.class, "CTL_ToolInfoAction"));
        DialogDisplayer.getDefault().notify(notifyDescriptor);
    }

    private void showOptions() {
        OptionsDisplayer.getDefault().open(getOptionsPath());
    }
}

{'fraction_non_alphanumeric': 0.09518842091537358, 'fraction_numerical': 0.002086321554309558, 'mean_word_length': 2.7088974854932304, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4823284', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1971, 'n_words': 491}