public class TLcdGXYMultiPointEditControllerModel extends Object
TLcdGXYMultiPointEditControllerModel
contains the logic for
editing objects on an ILcdGXYView
.
The most important concepts of this class are the following:
The methods that correspond with the above concepts are typically invoked in that order, but
the implementation must not depend on this exact order.
The editingCandidates are those objects that are involved in the editing
process. The method takes into account the modes to define the involved
objects. If it is for example asked to return the editing candidates for a
EDIT_WHAT_LABELS
mode, it only returns objects that have labels
next to them.
While the edit process is ongoing (e.g., the user is performing a drag), the
objects are not edited all the time, they are just painted in their temporary
state. The method paintEditing takes care of this. This method is typically
invoked often (e.g., on mouse drag) while the edit process is ongoing.
Once the edit is complete, the method applyEdit performs the actual edit
operation to the editing candidates. It delegates the real work to the ILcdGXYEditor
s or the ILcdGXYLabelEditor
s of the editing
candidates, depending on the modes.
The edit operations, performed by applyEdit
, can be
undone, provided the ILcdGXYEditor
s and/or ILcdGXYLabelEditor
s to which the real work is delegated implement ILcdUndoableSource
as well, to indicate that they support undo. Please
refer to the developer guide for more information about undo.
The method snapTarget
returns the target to snap the
edited objects to. Please refer to the developer guide for an overview
of snapping.
This edit controller model supports body label editing, see TLcdLabelLocation.isBodyLabel()
.
When a body label is translated (EDIT_HOW_TRANSLATING
), its domain object is translated
instead. When a body label is reshaped (EDIT_HOW_RESHAPING
), it is translated instead.
This is done by calling the ILcdGXYLabelEditor
with the
ILcdGXYLabelEditor.TRANSLATED
mode instead of
ILcdGXYLabelEditor.RESHAPED
.
Subclasses can override these methods to alter their behavior. They can also
introduce new modes, but care should be taken to override all methods, so
that they all know how to handle this new mode (calling super
with an existing mode could be useful). Integer constants used for those new
modes should be greater than or equal to 1 << 25
.
Note: editing labels is only supported if:
ILcdGXYLabelPainter2
(not just ILcdGXYLabelPainter
)
ILcdGXYEditableLabelsLayer
ILcdGXYLabelEditor
is set to the layer.
TLcdGXYEditControllerModel2
is that
this model supports multiple input points.TLcdGXYEditControllerModel2
Modifier and Type | Field and Description |
---|---|
static int |
EDIT_HOW_NO_CHANGE
Mode defining that no changes should be made.
|
static int |
EDIT_HOW_RESHAPING
Mode defining that editing should reshape the editing candidates.
|
static int |
EDIT_HOW_TRANSLATING
Mode defining that editing should translate the editing candidates.
|
static int |
EDIT_WHAT_FIRST_TOUCHED_LABEL
Mode defining that editing (e.g., translating or reshaping) should act on
the first touched label only.
|
static int |
EDIT_WHAT_LABELS
Mode defining that editing (e.g., translating or reshaping) should act on
the labels.
|
static int |
EDIT_WHAT_NO_CHANGE
Mode defining that no changes should be made.
|
static int |
EDIT_WHAT_OBJECTS
Mode defining that editing (e.g., translating or reshaping) should act on
the objects (e.g., the points, polylines, ...).
|
Constructor and Description |
---|
TLcdGXYMultiPointEditControllerModel()
Default constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addUndoableListener(ILcdUndoableListener aListener)
Adds a listener to this source, so this listener is notified when something undoable has
happened.
|
boolean |
applyEdit(ILcdGXYView aGXYView,
ILcdGXYLayerSubsetList aSnappables,
List<Point> aFrom,
List<Point> aTo,
int aEditHow,
int aEditWhat,
ILcdGXYLayerSubsetList aEditingCandidates)
Applies the edit to every object of the given subset, by delegating the real work to
ILcdGXYEditor.edit with the mode TRANSLATED (or RESHAPED if aEditHow is
EDIT_HOW_RESHAPING ). |
protected TLcdCompositeUndoable |
createSingleObjectUndoable(Object aDomainObject,
ILcdGXYLayer aLayer,
ILcdGXYView aGXYView,
List<Point> aFrom,
List<Point> aTo,
int aEditHow,
int aEditWhat,
ILcdGXYLayerSubsetList aEditingCandidates)
Creates the composite undoable that will wrap all the undoables generated by a single
ILcdGXYEditor for a single domain object. |
protected TLcdCompositeUndoable |
createTotalOperationUndoable(ILcdGXYView aGXYView,
List<Point> aFrom,
List<Point> aTo,
int aEditHow,
int aEditWhat,
ILcdGXYLayerSubsetList aEditingCandidates)
Creates the composite undoable that will wrap all undoables generated by all the underlying
editors for all the edited domain objects.
|
static String |
editHowAsString(int aEditHow)
Utility method that converts the given edit-how mode to a human readable
string.
|
ILcdGXYLayerSubsetList |
editingCandidates(ILcdGXYView aGXYView,
ILcdGXYLayerSubsetList aSnappables,
List<Point> aFrom,
List<Point> aTo,
int aEditHow,
int aEditWhat)
Returns the set of candidates for editing, respecting the given modes.
For
EDIT_HOW_TRANSLATING ,
the candidates are those objects that are selected, visible and editable
on the given ILcdGXYView . |
static String |
editWhatAsString(int aEditWhat)
Utility method that converts the given edit-what mode to a human readable
string.
|
protected void |
fireUndoableHappened(ILcdUndoable aUndoable)
Notify all undoable listeners that
aUndoable has happened. |
int |
getSensitivity()
This method returns the sensitivity that will be used when editing objects or labels.
|
void |
paintEditing(Graphics aGraphics,
ILcdGXYView aGXYView,
ILcdGXYLayerSubsetList aSnappables,
List<Point> aFrom,
List<Point> aTo,
int aEditHow,
int aEditWhat,
ILcdGXYLayerSubsetList aEditingCandidates)
Paints the given set of edit candidates in their temporary editing state.
|
void |
removeUndoableListener(ILcdUndoableListener aListener)
Removes the specified listener so it is no longer notified.
|
void |
setSensitivity(int aSensitivity)
This method sets the sensitivity that should be used by painters/editors to determine which
object (or part of the object) is edited by the input device (usually the mouse).
|
void |
setStringTranslator(ILcdStringTranslator aStringTranslator)
Sets the
ILcdStringTranslator that this controller model should use to
translate the Strings that will be visible in the user interface. |
com.luciad.view.gxy.controller.TLcdGXYMultiPointEditControllerModel.SnapTargetInfo |
snapTarget(ILcdGXYView aGXYView,
ILcdGXYLayerSubsetList aSnappables,
List<Point> aFrom,
List<Point> aTo,
int aEditHow,
int aEditWhat,
Object aObjectToSnap,
ILcdGXYLayer aObjectToSnapGXYLayer)
Tries to retrieve a snap target from the given aSnappables.
|
public static final int EDIT_HOW_RESHAPING
ILcdGXYEditor
and ILcdGXYLabelEditor
.public static final int EDIT_HOW_TRANSLATING
ILcdGXYEditor
and ILcdGXYLabelEditor
.public static final int EDIT_HOW_NO_CHANGE
public static final int EDIT_WHAT_OBJECTS
public static final int EDIT_WHAT_LABELS
public static final int EDIT_WHAT_FIRST_TOUCHED_LABEL
public static final int EDIT_WHAT_NO_CHANGE
public TLcdGXYMultiPointEditControllerModel()
public void paintEditing(Graphics aGraphics, ILcdGXYView aGXYView, ILcdGXYLayerSubsetList aSnappables, List<Point> aFrom, List<Point> aTo, int aEditHow, int aEditWhat, ILcdGXYLayerSubsetList aEditingCandidates)
Paints the given set of edit candidates in their temporary editing state. The real painting
work is delegated to ILcdGXYPainter.paint
with
the mode ILcdGXYPainter.TRANSLATING
or ILcdGXYPainter.RESHAPING
, depending on aEditHow. Similarly for labels, the
work is delegated to ILcdGXYLabelPainter2.paintLabel
with the mode ILcdGXYLabelPainter2.TRANSLATING
or ILcdGXYLabelPainter2.RESHAPING
.
When either the aEditHow
is EDIT_HOW_NO_CHANGE
or aEditWhat
is EDIT_WHAT_NO_CHANGE
, this method will do nothing.
The painting of the snaps (of a label) will be delegated to the (label) painters as well.
However, the context will only contain one input point. This means when this method is called
with multiple points in aFrom
and aTo
possibly leading to multiple
snap targets, the painting of the snaps will be done for each snap target and corresponding
input point individually and not for all snap targets and corresponding input points at
once.
aGraphics
- The graphics to draw on.aGXYView
- The ILcdGXYView
, provided as contextual information.aSnappables
- The list of potential snapping candidates, provided as contextual
information.aFrom
- A list with point(s) where the edit originated. Should have the same
length as aTo
, and the order of the points in both lists
should be the same, e.g. the location of the first point of
aFrom
when the edit terminated should be passed as the
first point in aTo
.aTo
- A list with point(s) where the edit terminated (so far). Should have
the same length as aFrom
, and the order of the points in
both list should be the same, e.g. the location of the first point of
aFrom
when the edit terminated should be passed as the
first point in aTo
.aEditHow
- The edit-how mode: one of the constants in this class that start with
EDIT_HOW
.aEditWhat
- The edit-what mode: one of the constants in this class that start
with EDIT_WHAT
. For example the result of the method
editWhatMode
.aEditingCandidates
- The objects (and their corresponding layers) that are being edited.public ILcdGXYLayerSubsetList editingCandidates(ILcdGXYView aGXYView, ILcdGXYLayerSubsetList aSnappables, List<Point> aFrom, List<Point> aTo, int aEditHow, int aEditWhat)
EDIT_HOW_TRANSLATING
,
the candidates are those objects that are selected, visible and editable
on the given ILcdGXYView
.
If, for these candidates, an object handle is touched, only the object to which the touched
handle belongs is returned, otherwise all candidates are returned.
For EDIT_HOW_RESHAPING
and
EDIT_WHAT_FIRST_TOUCHED_LABEL
,
it returns the first selected object that is visible, editable and touched.
Touched is defined as ILcdGXYPainter.isTouched(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext)
or ILcdGXYLabelPainter2.isLabelTouched(java.awt.Graphics, int, com.luciad.view.gxy.ILcdGXYContext)
, depending on aEditWhat.aGXYView
- The ILcdGXYView
, provided as contextual information.aSnappables
- The list of potential snapping candidates, provided as contextual
information.aFrom
- A list with point(s) where the edit originated. Should have the same length
as aTo
, and the order of the points in both lists should be the
same, e.g. the location of the first point of aFrom
when the
edit terminated should be passed as the first point in aTo
.aTo
- A list with point(s) where the edit terminated (so far). Should have the
same length as aFrom
, and the order of the points in both list
should be the same, e.g. the location of the first point of
aFrom
when the edit terminated should be passed as the first
point in aTo
.aEditHow
- The edit-how mode: one of the constants in this class that start with
EDIT_HOW
.aEditWhat
- The edit-what mode: one of the constants in this class that start with
EDIT_WHAT
. For example the result of the method editWhatMode
.null
.public boolean applyEdit(ILcdGXYView aGXYView, ILcdGXYLayerSubsetList aSnappables, List<Point> aFrom, List<Point> aTo, int aEditHow, int aEditWhat, ILcdGXYLayerSubsetList aEditingCandidates)
Applies the edit to every object of the given subset, by delegating the real work to ILcdGXYEditor.edit
with the mode TRANSLATED
(or RESHAPED
if aEditHow
is
EDIT_HOW_RESHAPING
). All input points are passed to the edit
method.
Note that the actual meaning of reshaping and translating is defined by the implementation of
ILcdGXYPainter/ILcdGXYEditor
that is used.
Similarly editing labels is delegated to ILcdGXYLabelEditor.editLabel
with the mode ILcdGXYLabelEditor.TRANSLATED
or ILcdGXYLabelEditor.RESHAPED
.
This method will do nothing if aEditHow
is EDIT_HOW_NO_CHANGE
or if
aEditWhat
is EDIT_WHAT_NO_CHANGE
,
and just return false
.
After all objects/labels are edited, the needed model changed events and label location changed events are fired.
After the edit is completed, an TLcdUndoableEvent
is fired to the
registered listeners
if any undo information was provided by the
ILcdGXYEditor
s or ILcdGXYLabelEditor
s to which the real work is
delegated. They can do so by implementing the ILcdUndoableSource
interface and by firing an TLcdUndoableEvent
when their edit
or editLabel
method is invoked. The undoable event this class sends out to its listeners is a
composite undoable composed of all the events send out by the ILcdGXYEditor
s or
ILcdGXYLabelEditor
s.
aGXYView
- The ILcdGXYView
, provided as contextual information.aSnappables
- The list of potential snapping candidates.aFrom
- A list with point(s) where the edit originated. Should have the same
length as aTo
, and the order of the points in both lists
should be the same, e.g. the location of the first point of
aFrom
when the edit terminated should be passed as the
first point in aTo
.aTo
- A list with point(s) where the edit terminated (so far). Should have
the same length as aFrom
, and the order of the points in
both list should be the same, e.g. the location of the first point of
aFrom
when the edit terminated should be passed as the
first point in aTo
.aEditHow
- The edit-how mode: one of the constants in this class that start with
EDIT_HOW
.aEditWhat
- The edit-what mode: one of the constants in this class that start
with EDIT_WHAT
. For example the result of the method
editWhatMode
.aEditingCandidates
- The objects (and their corresponding layers) that need to be edited.protected TLcdCompositeUndoable createTotalOperationUndoable(ILcdGXYView aGXYView, List<Point> aFrom, List<Point> aTo, int aEditHow, int aEditWhat, ILcdGXYLayerSubsetList aEditingCandidates)
applyEdit
method.
This default implementation returns a TLcdCompositeUndoable
with the display name
"Edit Objects". Override this method if you want another name.aGXYView
- The view for which the edit operation is being performed for which
the undoable is created.aFrom
- A list with point(s) where the edit originated. Should have the same
length as aTo
, and the order of the points in both lists
should be the same, e.g. the location of the first point of
aFrom
when the edit terminated should be passed as the
first point in aTo
.aTo
- A list with point(s) where the edit terminated (so far). Should have
the same length as aFrom
, and the order of the points in
both list should be the same, e.g. the location of the first point of
aFrom
when the edit terminated should be passed as the
first point in aTo
.aEditHow
- The edit-how mode: one of the constants in this class that start with
EDIT_HOW
.aEditWhat
- The edit-what mode: one of the constants in this class that start
with EDIT_WHAT
. For example the result of the method
editWhatMode
.aEditingCandidates
- The objects (and their corresponding layers) that need to be edited.null
.protected TLcdCompositeUndoable createSingleObjectUndoable(Object aDomainObject, ILcdGXYLayer aLayer, ILcdGXYView aGXYView, List<Point> aFrom, List<Point> aTo, int aEditHow, int aEditWhat, ILcdGXYLayerSubsetList aEditingCandidates)
ILcdGXYEditor
for a single domain object. This method is called from the
applyEdit
method.
The default implementation returns a TLcdCompositeUndoable
with the display name
"Edit " + String.valueOf(aDomainObject)
.aDomainObject
- The domain object from the model which is being edited.aLayer
- The layer of the domain object which is being edited.aGXYView
- The view for which the edit operation is being performed for which
the undoable is created.aFrom
- A list with point(s) where the edit originated. Should have the same
length as aTo
, and the order of the points in both lists
should be the same, e.g. the location of the first point of
aFrom
when the edit terminated should be passed as the
first point in aTo
.aTo
- A list with point(s) where the edit terminated (so far). Should have
the same length as aFrom
, and the order of the points in
both list should be the same, e.g. the location of the first point of
aFrom
when the edit terminated should be passed as the
first point in aTo
.aEditHow
- The edit-how mode: one of the constants in this class that start with
EDIT_HOW
.aEditWhat
- The edit-what mode: one of the constants in this class that start
with EDIT_WHAT
. For example the result of the method
editWhatMode
.aEditingCandidates
- The objects (and their corresponding layers) that need to be edited.null
.public com.luciad.view.gxy.controller.TLcdGXYMultiPointEditControllerModel.SnapTargetInfo snapTarget(ILcdGXYView aGXYView, ILcdGXYLayerSubsetList aSnappables, List<Point> aFrom, List<Point> aTo, int aEditHow, int aEditWhat, Object aObjectToSnap, ILcdGXYLayer aObjectToSnapGXYLayer)
Tries to retrieve a snap target from the given aSnappables. It does so by invoking snapTarget
(or labelSnapTarget
, depending on
aEditWhat) on the ILcdGXYPainter
s (or ILcdGXYLabelPainter2
s) of the
objects in aSnappables. If the snap target returned by one of those painters is accepted
by the ILcdGXYEditor
of aObjectToSnap, it is returned.
More concrete: for each input point exactly one snap target is searched by asking the
painters of the snapping candidates whether they have a snap target for that particular input
point. This means the call to the painter is done with a context containing only one input
point. If the painter returns a snap target, this snap target is verified by the editor. Hence the acceptSnapTarget
method of
the editor is also called with a context containing only one input point.
As soon as a snap target is found for an input point, this method stops searching and
continues with the next input point. All found snap targets (and possibly null
values when no snap target was found for an input point) are stored in one
SnapTargetInfo
object. This SnapTargetInfo
groups the snap
information of all input points into one object.
Further on, the information contained in the SnapTargetInfo
object will be
passed on to the edit method of the ILcdGXYEditor
. In that
edit
method, the context will contain all input points and snap targets for each
input point (or null
when no snap target could be found).
When no snap target can be found this method returns null
aGXYView
- The ILcdGXYView
, provided as contextual information.aSnappables
- The list of potential snapping candidates.aFrom
- A list with point(s) where the edit originated. Should have the
same length as aTo
, and the order of the points in
both lists should be the same, e.g. the location of the first
point of aFrom
when the edit terminated should be
passed as the first point in aTo
.aTo
- A list with point(s) where the edit terminated (so far). Should
have the same length as aFrom
, and the order of the
points in both list should be the same, e.g. the location of the
first point of aFrom
when the edit terminated should
be passed as the first point in aTo
.aEditHow
- The edit-how mode: one of the constants in this class that start
with EDIT_HOW
.aEditWhat
- The edit-what mode: one of the constants in this class that start
with EDIT_WHAT
. For example the result of the method
editWhatMode
.aObjectToSnap
- the object that would like to snap to one of the candidates in
aSnappables, so basically the object that is being edited.aObjectToSnapGXYLayer
- the layer whose model contains aObjectToSnap.public static String editHowAsString(int aEditHow)
aEditHow
- The edit how mode, one of the constants in
this class that start with EDIT_HOW
.public static String editWhatAsString(int aEditWhat)
aEditWhat
- The edit what mode, one of the constants in
this class that start with EDIT_WHAT
.public void setStringTranslator(ILcdStringTranslator aStringTranslator)
Sets the ILcdStringTranslator
that this controller model should use to
translate the Strings
that will be visible in the user interface.
This method should be called before this editor is used. Any Strings
already
created by this controller model will not be translated with the specified translator.
The following list of Strings
are translated by the given instance:
String
is used as the pattern for a
MessageFormat
.aStringTranslator
- The ILcdStringTranslator
that should be used. Must not be
null
.public void addUndoableListener(ILcdUndoableListener aListener)
ILcdUndoableSource
addUndoableListener
in interface ILcdUndoableSource
aListener
- The listener to be notified when something undoable has happened.public void removeUndoableListener(ILcdUndoableListener aListener)
ILcdUndoableSource
removeUndoableListener
in interface ILcdUndoableSource
aListener
- The listener to remove.protected void fireUndoableHappened(ILcdUndoable aUndoable)
aUndoable
has happened.aUndoable
- The undoable of which the listeners should be notified.public int getSensitivity()
TLcdGXYContext
passed to the
painters/editors.setSensitivity(int)
,
TLcdGXYContext.getSensitivity()
public void setSensitivity(int aSensitivity)
aSensitivity
- the sensitivity that will be used for painting/editing purposes.getSensitivity()
,
TLcdGXYSelectControllerModel2.setSensitivity(int)