Search in sources :

Example 1 with Tool

use of processing.app.tools.Tool in project processing by processing.

the class Base method populateToolsMenu.

public void populateToolsMenu(JMenu toolsMenu) {
    // If this is the first run, need to build out the lists
    if (internalTools == null) {
        rebuildToolList();
    }
    //    coreTools = ToolContribution.loadAll(Base.getToolsFolder());
    //    contribTools = ToolContribution.loadAll(Base.getSketchbookToolsFolder());
    //    Collections.sort(coreTools);
    //    Collections.sort(contribTools);
    //    Collections.sort(coreTools, new Comparator<ToolContribution>() {
    //      @Override
    //      public int compare(ToolContribution o1, ToolContribution o2) {
    //        return o1.getMenuTitle().compareTo(o2.getMenuTitle());
    //      }
    //    });
    toolsMenu.removeAll();
    for (Tool tool : internalTools) {
        toolsMenu.add(createToolItem(tool));
    }
    toolsMenu.addSeparator();
    if (coreTools.size() > 0) {
        for (Tool tool : coreTools) {
            toolsMenu.add(createToolItem(tool));
        }
        toolsMenu.addSeparator();
    }
    if (contribTools.size() > 0) {
        for (Tool tool : contribTools) {
            toolsMenu.add(createToolItem(tool));
        }
        toolsMenu.addSeparator();
    }
    JMenuItem item = new JMenuItem(Language.text("menu.tools.add_tool"));
    item.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ContributionManager.openTools();
        }
    });
    toolsMenu.add(item);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) Tool(processing.app.tools.Tool)

Example 2 with Tool

use of processing.app.tools.Tool in project processing by processing.

the class Base method initInternalTool.

protected void initInternalTool(String className) {
    try {
        Class<?> toolClass = Class.forName(className);
        final Tool tool = (Tool) toolClass.newInstance();
        tool.init(this);
        internalTools.add(tool);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) Tool(processing.app.tools.Tool)

Example 3 with Tool

use of processing.app.tools.Tool in project processing by processing.

the class Base method rebuildToolList.

public void rebuildToolList() {
    // Only do this once because the list of internal tools will never change
    if (internalTools == null) {
        internalTools = new ArrayList<Tool>();
        initInternalTool("processing.app.tools.CreateFont");
        initInternalTool("processing.app.tools.ColorSelector");
        initInternalTool("processing.app.tools.Archiver");
        if (Platform.isMacOS()) {
            initInternalTool("processing.app.tools.InstallCommander");
        }
    }
    // No need to reload these either
    if (coreTools == null) {
        coreTools = ToolContribution.loadAll(Base.getToolsFolder());
        for (Tool tool : coreTools) {
            tool.init(this);
        }
    }
    // Rebuilt when new tools installed, etc
    contribTools = ToolContribution.loadAll(Base.getSketchbookToolsFolder());
    for (Tool tool : contribTools) {
        try {
            tool.init(this);
        // With the exceptions, we can't call statusError because the window
        // isn't completely set up yet. Also not gonna pop up a warning because
        // people may still be running different versions of Processing.
        } catch (VerifyError ve) {
            System.err.println("\"" + tool.getMenuTitle() + "\" is not " + "compatible with this version of Processing");
        } catch (NoSuchMethodError nsme) {
            System.err.println("\"" + tool.getMenuTitle() + "\" is not " + "compatible with this version of Processing");
            System.err.println("The " + nsme.getMessage() + " method no longer exists.");
            Messages.loge("Incompatible Tool found during tool.init()", nsme);
        } catch (NoClassDefFoundError ncdfe) {
            System.err.println("\"" + tool.getMenuTitle() + "\" is not " + "compatible with this version of Processing");
            System.err.println("The " + ncdfe.getMessage() + " class is no longer available.");
            Messages.loge("Incompatible Tool found during tool.init()", ncdfe);
        } catch (AbstractMethodError ame) {
            System.err.println("\"" + tool.getMenuTitle() + "\" is not " + "compatible with this version of Processing");
        //        ame.printStackTrace();
        } catch (Error err) {
            System.err.println("An error occurred inside \"" + tool.getMenuTitle() + "\"");
            err.printStackTrace();
        } catch (Exception ex) {
            System.err.println("An exception occurred inside \"" + tool.getMenuTitle() + "\"");
            ex.printStackTrace();
        }
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) Tool(processing.app.tools.Tool)

Aggregations

Tool (processing.app.tools.Tool)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JMenuItem (javax.swing.JMenuItem)1