Here is the source code to the FilterCommand plugin. Someone may find this useful in developing their own plugins. Same rules on how to make the package structure. (Third Party)
Start.java
package FilterCommand;

import java.util.*;
import java.io.*;
import java.net.*;
import java.sql.*;
import java.text.*;
import javax.swing.*;
import crushftp.server.*;

public class Start implements Serializable
{
	Properties settings = new Properties();
	String version = "4.0";
	GUI g = null;

	public Properties getDefaults()
	{
		Properties p = new Properties();
		p.put("enabled","false");
		p.put("debug","false");
		p.put("version",version);
		return p;
	}

	public void setSettings(Properties p) throws Exception
	{
		settings = p;
		if (g != null) g.setSettings(settings);
	}

	public Properties getSettings()
	{
		if (g != null) settings = g.getSettings();
		settings.put("version",version);
		return settings;
	}

	public javax.swing.JPanel getPrefsPanel()
	{
		if (g == null) g = new GUI();
		g.setParent(this);
		g.setSettings(settings);
		return g;
	}

	public Object run(Properties info)
	{
		if (!settings.getProperty("enabled").equalsIgnoreCase("true")) return null;

		if (info.getProperty("action","").equals("log")) //we only get called with an event if this plugin was targeted for an event
		{
			String data = info.getProperty("data");
		}
		return null;
	}

	public void testSettings()
	{
		String error = "OK";
		try
		{
		}
		catch(Exception e)
		{
			error = e.toString();
		}
		JOptionPane.showMessageDialog(null, error, "Alert",JOptionPane.ERROR_MESSAGE);
	}

	public String get(String key)
	{
		return settings.getProperty(key);
	}

}


GUI.java

package FilterCommand;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
import java.lang.reflect.*;

public class GUI extends JPanel
{
	private JLabel jLabel1 = new JLabel();
	private JTextField command_field = new JTextField();

	public GUI()
	{
		try
		{
			jbInit();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}

	Object parent = null;
	private JPanel jPanel1 = new JPanel();
	private JCheckBox enabled_cb = new JCheckBox();
	private JCheckBox debug_cb = new JCheckBox();
    private JTextField usernames_field = new JTextField();
    private JLabel jLabel7 = new JLabel();
    private JLabel jLabel8 = new JLabel();
    private JLabel jLabel9 = new JLabel();
    private JLabel jLabel2 = new JLabel();
    private JTextField data_field = new JTextField();
    private JLabel jLabel3 = new JLabel();
    private JTextField responseCode_field = new JTextField();
    private JLabel jLabel4 = new JLabel();
    private JTextField responseData_field = new JTextField();
    private JLabel jLabel5 = new JLabel();
	public void setParent(Object parent)
	{
		this.parent = parent;
	}

	void jbInit() throws Exception
	{
		this.setLayout(null);
		jPanel1.setBorder(BorderFactory.createEtchedBorder());
		jPanel1.setBounds(new Rectangle(2, 38, 583, 334));
		jPanel1.setLayout(null);
		enabled_cb.setFont(new java.awt.Font("Arial", 0, 12));
        enabled_cb.setText("Enabled");
		enabled_cb.setBounds(new Rectangle(6, 6, 100, 22));
		debug_cb.setBounds(new Rectangle(122, 6, 100, 22));
		debug_cb.setFont(new java.awt.Font("Arial", 0, 12));
        debug_cb.setText("Debug");
        jPanel1.add(jLabel1, null);
		this.add(enabled_cb, null);
		this.add(debug_cb, null);
		this.add(jPanel1, null);
        jPanel1.add(jLabel2, null);
	}

	public Properties getSettings()
	{
		Properties p = new Properties();
		p.put("enabled",enabled_cb.isSelected()+"");
		p.put("debug",debug_cb.isSelected()+"");
		return p;
	}

	public void setSettings(Properties p)
	{
		  enabled_cb.setSelected(p.getProperty("enabled").equalsIgnoreCase("true"));
		  debug_cb.setSelected(p.getProperty("debug").equalsIgnoreCase("true"));
	}

	void test_btn_actionPerformed(ActionEvent e)
	{
		Properties p = getSettings();
		try
		{
			Method setSettings = parent.getClass().getMethod("setSettings",new Class[] { new Properties().getClass() });
			setSettings.invoke(parent,new Object[]{p});
			Method testSettings = parent.getClass().getMethod("testSettings",null);
			testSettings.invoke(parent,null);
		}
		catch(Exception ee)
		{
		}
	}

}

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-1) was last changed on 09-Oct-2016 18:14 by Ben Spink
G’day (anonymous guest)

OLD WIKI!!!#

New: CrushFTPv9#

OLD WIKI!!!#


CrushFTP8 | What's New

Referenced by
LeftMenu
Third Party

JSPWiki