omgraphichandlerlayer.java
来自「OpenMap是一个基于JavaBeansTM的开发工具包。利用OpenMap你」· Java 代码 · 共 1,519 行 · 第 1/4 页
JAVA
1,519 行
* hasn't been set, it will create a StandardMapMouseInterpreter. Otherwise,
* it returns whatever has been set as the interpreter, which could be null.
*/
public synchronized MapMouseInterpreter getMouseEventInterpreter() {
if (getMouseModeIDsForEvents() != null && mouseEventInterpreter == null) {
setMouseEventInterpreter(new StandardMapMouseInterpreter(this));
}
return mouseEventInterpreter;
}
/**
* Query asked from the MouseDelegator for interest in receiving
* MapMouseEvents. This returns a MapMouseInterpreter that has been told to
* listen for events from the MapMouseModes in setMouseModeIDsForEvents().
*/
public MapMouseListener getMapMouseListener() {
MapMouseListener mml = getMouseEventInterpreter();
if (mml != null) {
if (Debug.debugging("layer")) {
String[] modes = mml.getMouseModeServiceList();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < modes.length; i++) {
sb.append(modes[i] + ", ");
}
Debug.output("Layer " + getName() + " returning "
+ mml.getClass().getName()
+ " as map mouse listener that listens to: "
+ sb.toString());
}
}
return mml;
}
/**
* A flag to tell the layer to be selfish about consuming MouseEvents it
* receives. If set to true, it will consume events so that other layers
* will not receive the events. If false, lower layers will also receive
* events, which will let them react too. Intended to let other layers
* provide information about what the mouse is over when editing is
* occuring.
*/
public void setConsumeEvents(boolean consume) {
consumeEvents = consume;
if (mouseEventInterpreter instanceof StandardMapMouseInterpreter) {
((StandardMapMouseInterpreter) mouseEventInterpreter).setConsumeEvents(getConsumeEvents());
}
}
public boolean getConsumeEvents() {
return consumeEvents;
}
/**
* This is the important method call that determines what MapMouseModes the
* interpreter for this layer responds to. The MapMouseInterpreter calls
* this so it can respond to MouseDelegator queries. You can
* programmatically call setMouseModeIDsForEvents with the mode IDs to set
* these values, or set the mouseModes property for this layer set to a
* space-separated list of mode IDs.
*/
public String[] getMouseModeIDsForEvents() {
return mouseModeIDs;
}
/**
* Use this method to set which mouse modes this layer responds to. The
* array should contain the mouse mode IDs.
*/
public void setMouseModeIDsForEvents(String[] mm) {
if (Debug.debugging("layer")) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < mm.length; i++) {
sb.append(mm[i] + " ");
}
Debug.output("For layer " + getName() + ", setting mouse modes to "
+ sb.toString());
}
mouseModeIDs = mm;
if (mouseEventInterpreter instanceof StandardMapMouseInterpreter) {
((StandardMapMouseInterpreter) mouseEventInterpreter).setMouseModeServiceList(mm);
}
}
/**
* Query asking if OMGraphic is highlightable, which means that something in
* the GUI should change when the mouse is moved or dragged over the given
* OMGraphic. Highlighting shows that something could happen, or provides
* cursory information about the OMGraphic. Responding true to this method
* may cause getInfoText() and getToolTipTextFor() methods to be called
* (depends on the MapMouseInterpetor).
*/
public boolean isHighlightable(OMGraphic omg) {
return true;
}
/**
* Query asking if an OMGraphic is selectable, or able to be moved, deleted
* or otherwise modified. Responding true to this method may cause select()
* to be called (depends on the MapMouseInterpertor) so the meaning depends
* on what the layer does in select.
*/
public boolean isSelectable(OMGraphic omg) {
return false;
}
/**
* A current list of select OMGraphics.
*/
protected OMGraphicList selectedList;
/**
* Retrieve the list of currently selected OMGraphics.
*/
public OMGraphicList getSelected() {
return selectedList;
}
// //// Reactions
/**
* Fleeting change of appearance for mouse movements over an OMGraphic.
*/
public void highlight(OMGraphic omg) {
omg.select();
omg.generate(getProjection());
repaint();
}
/**
* Notification to set OMGraphic to normal appearance.
*/
public void unhighlight(OMGraphic omg) {
omg.deselect();
omg.generate(getProjection());
repaint();
}
/**
* Designate a list of OMGraphics as selected.
*/
public void select(OMGraphicList list) {
if (list != null) {
Iterator it = list.iterator();
while (it.hasNext()) {
if (selectedList == null) {
selectedList = new OMGraphicList();
}
OMGraphic omg = (OMGraphic) it.next();
if (omg instanceof OMGraphicList
&& !((OMGraphicList) omg).isVague()) {
select((OMGraphicList) omg);
} else {
selectedList.add(omg);
}
}
}
}
/**
* Designate a list of OMGraphics as deselected.
*/
public void deselect(OMGraphicList list) {
if (list != null) {
Iterator it = list.iterator();
while (it.hasNext() && selectedList != null) {
OMGraphic omg = (OMGraphic) it.next();
if (omg instanceof OMGraphicList
&& !((OMGraphicList) omg).isVague()) {
deselect((OMGraphicList) omg);
} else {
selectedList.remove(omg);
}
}
}
}
/**
* Remove OMGraphics from the layer.
*/
public OMGraphicList cut(OMGraphicList omgl) {
OMGraphicList list = getList();
if (list != null && omgl != null) {
Iterator it = omgl.iterator();
while (it.hasNext()) {
list.remove((OMGraphic) it.next());
}
}
return omgl;
}
/***************************************************************************
* Return a copy of an OMGraphic. Not implemented yet.
*/
public OMGraphicList copy(OMGraphicList omgl) {
return null;
}
/**
* Add OMGraphics to the Layer.
*/
public void paste(OMGraphicList omgl) {
OMGraphicList list = getList();
if (list != null && omgl != null) {
Iterator it = omgl.iterator();
while (it.hasNext()) {
list.add((OMGraphic) it.next());
}
}
}
/**
* If applicable, should return a short, informational string about the
* OMGraphic to be displayed in the InformationDelegator. Return null if
* nothing should be displayed.
*/
public String getInfoText(OMGraphic omg) {
return null;
}
/**
* If applicable, should return a tool tip for the OMGraphic. Return null if
* nothing should be shown.
*/
public String getToolTipTextFor(OMGraphic omg) {
return null;
}
/**
* Return a JMenu with contents applicable to a popup menu for a location
* over the map. The popup doesn't concern any OMGraphics, and should be
* presented for a click on the map background.
*
* @param mme a MapMouseEvent describing the location over where the menu
* items should apply, in case different options are appropriate for
* different places.
* @return a JMenu for the map. Return null or empty List if no input
* required.
*/
public List getItemsForMapMenu(MapMouseEvent mme) {
return null;
}
/**
* Return a java.util.List containing input for a JMenu with contents
* applicable to a popup menu for a location over an OMGraphic.
*
* @return a List containing options for the given OMGraphic. Return null or
* empty list if there are no options.
*/
public List getItemsForOMGraphicMenu(OMGraphic omg) {
return null;
}
/**
* A query from the MapMouseInterpreter wondering if the
* GestureResponsePolicy wants events pertaining to mouse movements over the
* map that are not over an OMGraphic. If the GestureResponsePolicy responds
* true, then the mouseOver and leftClick methods will be called on the
* GestureResponsePolicy by the interpreter. There is no rightClick method
* that is called, because a right click will always cause a
* getItemsForMapMenu() method to be called.
*/
public boolean receivesMapEvents() {
return false;
}
/**
* A notification that the mouse cursor has been moved over the map, not
* over any of the OMGraphics on the GestureResponsePolicy. This only gets
* called if the response to receiveMapEvents is true.
*
* @param mme MapMouseEvent describing the location of the mouse.
* @return true of this information is to be considered consumed and should
* not be passed to anybody else.
*/
public boolean mouseOver(MapMouseEvent mme) {
return false;
}
/**
* A notification that the mouse has been clicked with the left mouse button
* on the map, and not on any of the OMGraphics. This only gets called if
* the response to receiveMapEvents is true. Right clicks on the map are
* always reported to the getItemsForMapMenu method.
*
* @param mme MapMouseEvent describing the location of the mouse.
* @return true of this information is to be considered consumed and should
* not be passed to anybody else.
*/
public boolean leftClick(MapMouseEvent mme) {
return false;
}
/**
* Create a JPanel that has a slider to control the layer transparency. An
* action listener that calls layer repaint() when the value changes will be
* added to the slider.
*
* @param label the label for the panel around the slider.
* @param orientation JSlider.HORIZONTAL/JSlider.VERTICAL
* @param initialValue an initial transparency value between 0-1, 0 being
* clear.
* @return
*/
public JPanel getTransparencyAdjustmentPanel(String label, int orientation,
float initialValue) {
JPanel opaquePanel = PaletteHelper.createPaletteJPanel(label);
JSlider opaqueSlide = new JSlider(orientation, 0/* min */, 255/* max */, (int) (255f * initialValue)/* inital */);
java.util.Hashtable dict = new java.util.Hashtable();
dict.put(new Integer(0),
new JLabel(i18n.get(OMGraphicHandlerLayer.class,
"clearSliderLabel",
"clear")));
dict.put(new Integer(255),
new JLabel(i18n.get(OMGraphicHandlerLayer.class,
"opqueSliderLabel",
"opaque")));
opaqueSlide.setLabelTable(dict);
opaqueSlide.setPaintLabels(true);
opaqueSlide.setMajorTickSpacing(50);
opaqueSlide.setPaintTicks(true);
opaqueSlide.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent ce) {
JSlider slider = (JSlider) ce.getSource();
if (slider.getValueIsAdjusting()) {
OMGraphicHandlerLayer.this.setTransparency((float) slider.getValue() / 255f);
repaint();
}
}
});
opaquePanel.add(opaqueSlide);
return opaquePanel;
}
/**
* Set the transparency of the layer. This transparency is applied during
* rendering.
*
* @param value 0f for clear, 1f for opaque.
*/
public void setTransparency(float value) {
AlphaComposite ac = null;
if (value != 1f) {
ac = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, value);
}
getRenderPolicy().setComposite(ac);
}
/**
* Get the transparency value for this layer.
*
* @return 1 if opaque, 0 for clear.
*/
public float getTransparency() {
float ret = 1f;
RenderPolicy rp = getRenderPolicy();
if (rp != null) {
Composite comp = rp.getComposite();
if (comp instanceof AlphaComposite) {
ret = ((AlphaComposite) comp).getAlpha();
}
}
return ret;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?