ワールドウィンドディスプレイに右クリックJPopupMenu
を追加する必要があります。世界風表示はJPanel
です。私はちょうどApplicationTemplate.AppPanel
内部クラスのメンバ変数とメソッドをコピーして、World Windの例のApplicationTemplate
クラスからコピーし、GUIに貼り付けました.WWディスプレイが必要です。this.add(component)
の参照がコピーされたコードからmyJPanel.add(component)
に変更されました。ワールドウィンドでJPopupMenuを取得
ポップアップメニューの欠如以外は素晴らしいことでした。私は自分のアプリケーションに埋め込まれたWorld Windの表示を持っていて、アプリケーションのダイアログからそれを制御しています。
ワールドワイドディスプレイのJPanel
にJPopupMenu
を追加しても、全く表示されていないようです。私は右クリックし、何もポップアップしません。私はワールドウインドウの上のコンポーネント(WWDはBorderLayout
CENTER、他のコンポーネントは北にある)にメニューを添付することができるので、これはメニューを隠す重量の軽いJavaコンポーネントの問題ではないと思います。メニューは幸せにそれによって隠されることなく世界風ディスプレイの空間に入るでしょう。ただ、安全のために、私はJPopupMenu
さんsetLightWeightPopupEnabled(false)
を設定し、私はJPopupMenu.setDefaultLightWeightPopupEnabled(false)
をしたメインクラスの静的初期化子のトップに私は世界の風表示が含まれているJPanel
に添付MouseListener
とテスト、およびのどれをやりましたMouseListener
イベントが発生しています。だから私の最高の推測は、JPanel
にJPopupMenu
を追加するべきではなく、代わりにそれをwwdオブジェクトの特定のサブコンポーネントに追加するべきだということです。 wwdオブジェクト自体にはポップアップメニューを追加するメソッドがないようで、wwdのメソッドでは "getGLCanvas"のようなものは表示されません。私がここで適切な道を歩いているなら、どのコンポーネントをメニューに追加すべきですか、どのようにそのコンポーネントにアクセスしますか?
私の質問はとてもシンプルなので、どうかと思われます。をワールドウィンドディスプレイに表示するにはどうすればいいですか?
二次的には、MouseListener
をディスプレイに表示することも同じですが、その回答はディスプレイにJPopupMenu
が表示されていない場合があります。
以下は、私が挿入したWorld Windのテンプレートコードとその変更内容です。別のクラスではgetComponent()
を使用して、アプリケーションのユーザーインターフェイスにWorld Windディスプレイを含むJPanel
を追加します。私は何か重要な場合に備えて、私がコメントした既定のWorld Windのものを残しました。レイヤー名のString []を通るループは、地図と単位のスケールだけを簡単に表示するための手段でした。 JPopupMenu
コードがコンストラクタの途中にあります。面倒なコードについては申し訳ありませんが、私はあなたがそれを最高の援助のためにそのまま見なければならないと考えました。
class MyClass
{
protected JComponent component;
public JComponent getComponent() { return component; }
protected WorldWindow wwd;
protected StatusBar statusBar;
protected ToolTipController toolTipController;
protected HighlightController highlightController;
MyClass()
{
boolean includeStatusBar = false;
component = new JPanel(new BorderLayout());
this.wwd = this.createWorldWindow();
((Component) this.wwd).setPreferredSize(new Dimension(200,200));//canvasSize);
// Create the default model as described in the current worldwind properties.
Model m = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME);
this.wwd.setModel(m);
// Setup a select listener for the worldmap click-and-go feature
// this.wwd.addSelectListener(new ClickAndGoSelectListener(this.getWwd(), WorldMapLayer.class));
component.add((Component) this.wwd, BorderLayout.CENTER);
if (includeStatusBar)
{
this.statusBar = new StatusBar();
component.add(statusBar, BorderLayout.PAGE_END);
this.statusBar.setEventSource(wwd);
}
// Add controllers to manage highlighting and tool tips.
// this.toolTipController = new ToolTipController(this.getWwd(), AVKey.DISPLAY_NAME, null);
// this.highlightController = new HighlightController(this.getWwd(), SelectEvent.ROLLOVER);
java.util.List<String> desiredLayers = Arrays.asList(
new String[] { "Blue Marble May 2004", /*"i-cubed Landsat",*/ "Scale bar"
});
for(Layer layer : getWwd().getModel().getLayers())
{
if(desiredLayers.contains(layer.getName()))
{
System.out.println("INCLUDE " + layer.getName());
layer.setEnabled(true);
}
else
{
System.out.println("EXCLUDE " + layer.getName());
layer.setEnabled(false);
}
}
JMenu menuZoom = new JMenu("Zoom");
JMenuItem menuZoom_1028 = new JMenuItem("1028");
menuZoom.add(menuZoom_1028);
JMenuItem menuZoom_512 = new JMenuItem("512");
menuZoom.add(menuZoom_512);
JMenuItem menuZoom_256 = new JMenuItem("256");
menuZoom.add(menuZoom_256);
JMenuItem menuZoom_128 = new JMenuItem("128");
menuZoom.add(menuZoom_128);
JMenuItem menuZoom_64 = new JMenuItem("64");
menuZoom.add(menuZoom_64);
JMenuItem menuZoom_32 = new JMenuItem("32");
menuZoom.add(menuZoom_32);
JPopupMenu rclickMenu = new JPopupMenu();
rclickMenu.add(menuZoom);
component.setComponentPopupMenu(rclickMenu);
menuZoom.getPopupMenu().setLightWeightPopupEnabled(false);
component.addMouseListener(new MouseListener()
{
@Override
public void mouseClicked(MouseEvent e)
{
System.out.println("mouseClicked");
}
@Override
public void mousePressed(MouseEvent e)
{
System.out.println("mousePressed");
}
@Override
public void mouseReleased(MouseEvent e)
{
System.out.println("mouseReleased");
}
@Override
public void mouseEntered(MouseEvent e)
{
System.out.println("mouseEntered");
}
@Override
public void mouseExited(MouseEvent e)
{
System.out.println("mouseExited");
}
});
}
protected WorldWindow createWorldWindow()
{
return new WorldWindowGLCanvas();
}
public WorldWindow getWwd()
{
return wwd;
}
public StatusBar getStatusBar()
{
return statusBar;
}
}