- java.lang.Object
-
- devplugin.ProgramReceiveTarget
-
- All Implemented Interfaces:
java.lang.Comparable<ProgramReceiveTarget>
public final class ProgramReceiveTarget extends java.lang.Object implements java.lang.Comparable<ProgramReceiveTarget>
Is a target for receiving of program from other plugins.
If your plugin should be able to receive programs from other plugins and handle those programs in a specific way you have to create ProgramReceiveTargets for the plugin.
To do this use the constructorpublic ProgramReceiveTarget(ProgramReceiveIf receiveIf, String name, String targetId)
. ThereceiveIf
is you Plugin, thename
is the name the user will be see for selection of the target and thetargetId
is a unique id which is used for identifying the target.
If your plugin only supports one target simply don't override the methodgetProgramReceiveTargets()
.
If you want to compare two targets always use the equals method.
Example:
Plugin name MyPlugin.
MyPlugin is a plugin which want to receive programs for two types of targets. One target will be used to show the received programs in a dialog window, the other target will be used to mark the programs for the plugin.
MyPlugin overrides the methods used for identifying it as a receiveable plugin:
public boolean canReceiveProgramsWithTarget() {
return true;
}
public boolean receivePrograms(int eventType, Program[] programArr, ProgramReceiveTarget receiveTarget) {
ProgramReceiveTarget[] targets = getSupportedTargets();
if(targets[0].equals(receiveTarget)
showProgramsInDialog(programArr);
else if (targets[1].equals(receiveTarget)
for(Program p : programArr)
p.mark(this);
}
public ProgramReceiveTarget[] getProgramReceiveTargets() {
return getSupportedTargets();
}
The methodgetSupportedTargets()
looks like this:
private ProgramReceiveTarget[] getSupportedTargets() {
ProgramReceiveTarget target1 = new ProgramReceiveTarget(this,"Show programs in dialog","showDialog");
ProgramReceiveTarget target2 = new ProgramReceiveTarget(this,"Mark programs for MyPlugin","markPrograms");
return new ProgramReceiveTarget[] {target1,target2};
}
With this code the plugin MyPlugin is able to receive the programs from other plugins and handle it in the specified manner.
- Since:
- 2.5
- Author:
- René Mach
-
-
Field Summary
Fields Modifier and Type Field Description static int
TYPE_EVENT_ADDED
Type used to signalize the receiving plugin that the programs were added by the sender.static int
TYPE_EVENT_REMOVED
Type used to signalize the receiving plugin that the programs were removed by the sender.static int
TYPE_EVENT_UNDIFINED
Type for sending programs to plugins with no information about the handling of the send programs.
-
Constructor Summary
Constructors Constructor Description ProgramReceiveTarget(int eventTypeSupported, ProgramReceiveIf receiveIf, java.lang.String name, java.lang.String targetId)
Creates an instance of the ProgramReceiveTarget.ProgramReceiveTarget(ProgramReceiveIf receiveIf, java.lang.String name, java.lang.String targetId)
Creates an instance of the ProgramReceiveTarget.ProgramReceiveTarget(java.io.ObjectInputStream in)
Creates an instance of the ProgramReceiveTarget.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description int
compareTo(ProgramReceiveTarget other)
static ProgramReceiveTarget[]
createDefaultTargetArrayForProgramReceiveIf(ProgramReceiveIf receiveIf)
Creates the default target for a ProgramReceiveIf.static ProgramReceiveTarget
createDefaultTargetForProgramReceiveIfId(java.lang.String receiveIfId)
Creates the default target for an id of a ProgramReceiveIf.boolean
equals(java.lang.Object o)
int
getEventType()
Gets the event type the sending plugin to handle.static int
getEventTypeForSendingAction(java.awt.Component parent, ProgramReceiveTarget target)
Asks the user to select the type of sending of the programs.ProgramReceiveIf
getReceifeIfForIdOfTarget()
java.lang.String
getReceiveIfId()
int
getSupportedEventType()
Gets the supported event type of this target.java.lang.String
getTargetId()
java.lang.String
getTargetName()
get the target name (for display)int
hashCode()
static boolean
isDefaultProgramReceiveTargetForProgramReceiveIf(ProgramReceiveIf receiveIf, ProgramReceiveTarget receiveTarget)
Checks if the given target is the default target for the given ProgramReceiveIf.boolean
isReceiveTargetWithIdOfProgramReceiveIf(ProgramReceiveIf receiveIf, java.lang.String id)
Checks if the given id is used by this instance of ProgramReceiveTarget and contains to the given ProgramReceiveIf.boolean
receivePrograms(int type, Program[] programs)
Send the programs to the receive targetvoid
receivePrograms(Program[] programs)
Deprecated.since 4.2.2 usereceivePrograms(int, Program[])
instead.boolean
receiveValues(int type, java.lang.String[] values)
Send the programs to the receive targetvoid
setEventType(int eventType)
Sets the event type to use when using this target.java.lang.String
toString()
void
writeData(java.io.ObjectOutputStream out)
Use this to save a target.
-
-
-
Field Detail
-
TYPE_EVENT_UNDIFINED
public static final int TYPE_EVENT_UNDIFINED
Type for sending programs to plugins with no information about the handling of the send programs.- Since:
- 4.2.2
- See Also:
- Constant Field Values
-
TYPE_EVENT_ADDED
public static final int TYPE_EVENT_ADDED
Type used to signalize the receiving plugin that the programs were added by the sender.- Since:
- 4.2.2
- See Also:
- Constant Field Values
-
TYPE_EVENT_REMOVED
public static final int TYPE_EVENT_REMOVED
Type used to signalize the receiving plugin that the programs were removed by the sender.- Since:
- 4.2.2
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ProgramReceiveTarget
public ProgramReceiveTarget(ProgramReceiveIf receiveIf, java.lang.String name, java.lang.String targetId)
Creates an instance of the ProgramReceiveTarget. Use this to create a target from the plugin for the other plugins to read.- Parameters:
receiveIf
- The ProgramReceiveIf (your Plugin) to create for.name
- The name of the target.targetId
- The unique id of the target.
-
ProgramReceiveTarget
public ProgramReceiveTarget(int eventTypeSupported, ProgramReceiveIf receiveIf, java.lang.String name, java.lang.String targetId)
Creates an instance of the ProgramReceiveTarget. Use this to create a target from the plugin for the other plugins to read. NOTE: If a target should supportTYPE_EVENT_ADDED
andTYPE_EVENT_REMOVED
the eventTypeSupported has to be set toTYPE_EVENT_ADDED
+TYPE_EVENT_REMOVED
- Parameters:
eventTypeSupported
- The event type supported by this target.receiveIf
- The ProgramReceiveIf (your Plugin) to create for.name
- The name of the target.targetId
- The unique id of the target.
-
ProgramReceiveTarget
public ProgramReceiveTarget(java.io.ObjectInputStream in) throws java.io.IOException, java.lang.ClassNotFoundException
Creates an instance of the ProgramReceiveTarget. Use this to load an target previously saved withwriteData(ObjectOutputStream)
.- Parameters:
in
- The input stream.- Throws:
java.io.IOException
- Thrown if an IO operation went wrong.java.lang.ClassNotFoundException
- Thrown if a class could not be found.
-
-
Method Detail
-
createDefaultTargetArrayForProgramReceiveIf
public static ProgramReceiveTarget[] createDefaultTargetArrayForProgramReceiveIf(ProgramReceiveIf receiveIf)
Creates the default target for a ProgramReceiveIf.- Parameters:
receiveIf
- The ProgramReceiveIf to create the null target for.- Returns:
- The default target for ProgramReceiveIf.
-
createDefaultTargetForProgramReceiveIfId
public static ProgramReceiveTarget createDefaultTargetForProgramReceiveIfId(java.lang.String receiveIfId)
Creates the default target for an id of a ProgramReceiveIf.- Parameters:
receiveIfId
- The id of the ProgramReceiveIf to create for.- Returns:
- The default target for the id of the ProgramReceiveIf.
-
writeData
public void writeData(java.io.ObjectOutputStream out) throws java.io.IOException
Use this to save a target.- Parameters:
out
- The stream to write to.- Throws:
java.io.IOException
- Thrown if an IO operation went wrong.
-
getTargetName
public java.lang.String getTargetName()
get the target name (for display)- Returns:
- target name
- Since:
- 3.0
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getReceiveIfId
public java.lang.String getReceiveIfId()
- Returns:
- The id of the ProgramReceiveIf of this target.
-
getTargetId
public java.lang.String getTargetId()
- Returns:
- The id of this target.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getReceifeIfForIdOfTarget
public ProgramReceiveIf getReceifeIfForIdOfTarget()
- Returns:
- The ProgramReceiveIf for the ProgramReceiveIfId of this target.
-
isDefaultProgramReceiveTargetForProgramReceiveIf
public static boolean isDefaultProgramReceiveTargetForProgramReceiveIf(ProgramReceiveIf receiveIf, ProgramReceiveTarget receiveTarget)
Checks if the given target is the default target for the given ProgramReceiveIf.- Parameters:
receiveIf
- The ProgramReceiveIf to check.receiveTarget
- The ProgramReceiveTarget to check.- Returns:
- True if the receiveTarget is the default ProgramReceiveTarget for the ProgramReceiveIf.
-
isReceiveTargetWithIdOfProgramReceiveIf
public boolean isReceiveTargetWithIdOfProgramReceiveIf(ProgramReceiveIf receiveIf, java.lang.String id)
Checks if the given id is used by this instance of ProgramReceiveTarget and contains to the given ProgramReceiveIf.- Parameters:
id
- The id to check.receiveIf
- The receive if to which the ProgramReceiveTarget is connected.- Returns:
- True if this instance is using the id and contains to the given ProgramReceiveIf.
-
compareTo
public int compareTo(ProgramReceiveTarget other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<ProgramReceiveTarget>
-
receivePrograms
@Deprecated(since="4.2.2") public void receivePrograms(Program[] programs)
Deprecated.since 4.2.2 usereceivePrograms(int, Program[])
instead.Send the programs to the receive target- Parameters:
programs
- programs to send- Since:
- 3.0
-
receivePrograms
public boolean receivePrograms(int type, Program[] programs)
Send the programs to the receive target- Parameters:
type
- The type of the send programs.programs
- programs to send- Since:
- 4.2.2
-
receiveValues
public boolean receiveValues(int type, java.lang.String[] values)
Send the programs to the receive target- Parameters:
type
- The type of the send programs.values
- values to send- Since:
- 4.2.2
-
getSupportedEventType
public int getSupportedEventType()
Gets the supported event type of this target. NOTE: If a target supportsTYPE_EVENT_ADDED
andTYPE_EVENT_REMOVED
it will return a value ofTYPE_EVENT_ADDED
+TYPE_EVENT_REMOVED
- Returns:
- The supported event type.
- Since:
- 4.2.2
-
getEventType
public int getEventType()
Gets the event type the sending plugin to handle.- Returns:
- The event type
- Since:
- 4.2.2
-
setEventType
public void setEventType(int eventType)
Sets the event type to use when using this target. NOTE: If this target should support adding and removing of programs, set the type toTYPE_EVENT_ADDED
+TYPE_EVENT_REMOVED
- Parameters:
eventType
-- Since:
- 4.2.2
-
getEventTypeForSendingAction
public static int getEventTypeForSendingAction(java.awt.Component parent, ProgramReceiveTarget target)
Asks the user to select the type of sending of the programs.- Parameters:
parent
- The parent component for the option dialog.target
- The receive target to get the event type for.- Returns:
- The type to use for sending of the programs
- Since:
- 4.2.2
-
-