IlvButton コンポーネントは簡単なボタンで、クリックすることで JavaScript™
コードを呼び出すことができます。ページにボタンを追加して拡大/縮小できます。
ボタンに加え、JavaScript パネルを追加すると、メイン・ビューの回りにフレームを作成できます。JavaScript パネルとは、HTML を含めることができるページの領域です。パネルの作成は、IlvUtil.js ファイルで定義されたクラス
IlvHTMLPanel
を使用して行います。ページの本体は以下のようになります。
<body onload="init()" onunload="IlvObject.callDispose()" onresize="handleResize()" bgcolor="#ffffff" > <script> //position of the main view var y = 40 var x = 40 var h = 270 var w = 440 // Creates a frame around the main view var frameBackground = new IlvHTMLPanel(’’) frameBackground.setBounds(x-20, y-20, w+210, h+80) frameBackground.setVisible(true) frameBackground.setBackgroundColor(’#21bdbd’) var frameTopLeft = new IlvHTMLPanel(’<IMG src="images/frame_topleft.gif">’) frameTopLeft.setBounds(x-20, y-20, 40, 40) frameTopLeft.setVisible(true) var frameBottomLeft =new IlvHTMLPanel(’<IMG src="images/frame_bottomleft.gif">’) frameBottomLeft.setBounds(x-20, y+h+20, 40, 40) frameBottomLeft.setVisible(true) var frameTopRight = new IlvHTMLPanel(’<IMG src="images/frame_topright.gif">’) frameTopRight.setBounds(x+w+150, y-20, 40, 40) frameTopRight.setVisible(true) var frameBottomRight = new IlvHTMLPanel(’<IMG src="images/frame_bottomright.gif">’) frameBottomRight.setBounds(x+w+150, y+h+20, 40, 40) frameBottomRight.setVisible(true) var frameTop = new IlvHTMLPanel(’<IMG src="images/frame_top.gif">’) frameTop.setBounds(x+20, y-20, 570, 40) frameTop.setVisible(true) var frameBottom = new IlvHTMLPanel(’<IMG src="images/frame_bottom.gif">’) frameBottom.setBounds(x+20, y+h+20, 570, 40) frameBottom.setVisible(true)
var frameLeft = new IlvHTMLPanel(’<IMG src="images/frame_left.gif">’) frameLeft.setBounds(x-20, y+20, 5, 270) frameLeft.setVisible(true) var frameRight = new IlvHTMLPanel(’<IMG src="images/frame_right.gif">’) frameRight.setBounds(x+w+185, y+20, 5, 270) frameRight.setVisible(true) var border = new IlvHTMLPanel(’’) border.setBounds(x+w+45, y, 130, h) border.setVisible(true) border.setBackgroundColor(’#09a5a5’) var secondBorder = new IlvHTMLPanel(’’) secondBorder.setBounds(x+w+47, y+2, 128, h-2) secondBorder.setVisible(true) secondBorder.setBackgroundColor(’#21d6d6’) // message panel var messagePanel = new IlvHTMLPanel(’’) messagePanel.setBounds(x, y+h+20, w, 25) messagePanel.setVisible(true) messagePanel.setBackgroundColor(’#21d6d6’) IlvButton.defaultMessagePanel = messagePanel; // Rogue Wave logo var logo = new IlvHTMLPanel(’<IMG src="images/ilog.gif">’) logo.setBounds(x+w+95, y+h+10, 85, 40) logo.setVisible(true) IlvButton.defaultInfoPanel = messagePanel; // Main view var view = new IlvView(x, y, w, h) view.setRequestURL(’/xmlgrapher/demo.xmlgrapher.servlet.XmlGrapherServlet’) view.setMessagePanel(messagePanel) // Overview window. var overview=new IlvOverview(x+w+50, y+4, 120, 70, view) overview.setColor(’white’) overview.setMessagePanel(messagePanel) // Legend var legend = new IlvLegend(x+w+50, y+150 ,120, 115, view) legend.setTitle(’Themes’) legend.setTitleBackgroundColor(’#21bdbd’) legend.setTextColor(’white’) legend.setBackgroundColor(’#21d6d6’) legend.setTitleFontSize(2); // Some buttons for navigation var topbutton, bottombutton, rightbutton, leftbutton topbutton = new IlvButton(x+w/2, y-15, 30, 13,’images/north.gif’,’view.panNorth()’) topbutton.setRolloverImage(’images/northh.gif’) topbutton.setToolTipText(’pan north’) topbutton.setMessage(’pan the map to the north’)
bottombutton = new IlvButton(x+w/2, y+h, 33, 13,’images/south.gif’,’view.panSouth()’) bottombutton.setRolloverImage(’images/southh.gif’) bottombutton.setToolTipText(’pan south’) bottombutton.setMessage(’pan the map to the south’) leftbutton=new IlvButton(x-13, y+h/2-10, 13, 30,’images/west.gif’,’view.panWest()’) leftbutton.setRolloverImage(’images/westh.gif’) leftbutton.setToolTipText(’pan west’) leftbutton.setMessage(’pan the map to the west’) rightbutton=new IlvButton(x+w, y+h/2-25, 13, 28, ’images/east.gif’, ’view.panEast()’) rightbutton.setRolloverImage(’images/easth.gif’) rightbutton.setToolTipText(’pan east’) rightbutton.setMessage(’pan the map to the east’) // Buttons to zoom in and out var zoominbutton, zoomoutbutton zoominbutton=new IlvButton(x+w+30, y+h-16,12, 12, ’images/zoom.gif’, ’view.zoomIn()’) zoominbutton.setRolloverImage(’images/zoomh.gif’) zoominbutton.setMessage(’click to zoom by 2’) zoominbutton.setToolTipText(’Zoom In’) zoomoutbutton=new IlvButton(x+w+30, y, 12, 12, ’images/unzoom.gif’, ’view.zoomOut()’) zoomoutbutton.setRolloverImage(’images/unzoomh.gif’) zoomoutbutton.setMessage(’click to zoom out by 2’) zoomoutbutton.setToolTipText(’Zoom Out’) view.toHTML() overview.toHTML() legend.toHTML() topbutton.toHTML() bottombutton.toHTML() leftbutton.toHTML() rightbutton.toHTML() zoomoutbutton.toHTML() zoominbutton.toHTML() </script> </body> </hmtl>
ページは次のようになります。
![mapstep4.gif](../../JViews_Framework/usradvfwork/_media/mapstep4_default.gif)
ページ周囲のフレームは次の行で作成されました。
var frameBackground = new IlvHTMLPanel(’’) frameBackground.setBounds(x-20, y-20, w+210, h+80) frameBackground.setVisible(true) frameBackground.setBackgroundColor(’#21bdbd’) var frameTopLeft = new IlvHTMLPanel(’<IMG src="images/frame_topleft.gif">’) frameTopLeft.setBounds(x-20, y-20, 40, 40) frameTopLeft.setVisible(true) var frameBottomLeft=new IlvHTMLPanel(’<IMG src="images/frame_bottomleft.gif">’) frameBottomLeft.setBounds(x-20, y+h+20, 40, 40) frameBottomLeft.setVisible(true) var frameTopRight = new IlvHTMLPanel(’<IMG src="images/frame_topright.gif">’) frameTopRight.setBounds(x+w+150, y-20, 40, 40) frameTopRight.setVisible(true) var frameBottomRight = new IlvHTMLPanel(’<IMG src="images/frame_bottomright.gif">’) frameBottomRight.setBounds(x+w+150, y+h+20, 40, 40) frameBottomRight.setVisible(true) var frameTop = new IlvHTMLPanel(’<IMG src="images/frame_top.gif">’) frameTop.setBounds(x+20, y-20, 570, 40) frameTop.setVisible(true) var frameBottom = new IlvHTMLPanel(’<IMG src="images/frame_bottom.gif">’) frameBottom.setBounds(x+20, y+h+20, 570, 40) frameBottom.setVisible(true) var frameLeft = new IlvHTMLPanel(’<IMG src="images/frame_left.gif">’) frameLeft.setBounds(x-20, y+20, 5, 270) frameLeft.setVisible(true) var frameRight = new IlvHTMLPanel(’<IMG src="images/frame_right.gif">’) frameRight.setBounds(x+w+185, y+20, 5, 270) frameRight.setVisible(true)
これで隅に 4 つの JavaScript パネル、側面にさらに 4 つの追加パネル、背景に 1 つパネルが作成されます。
フレームの隅と側面は簡単な GIF イメージで構成されています。
次の行で、南、北、東、西へパンするボタンが追加されました。
topbutton = new IlvButton(x+w/2, y-15, 30, 13,’images/north.gif’,’view.panNorth()’) topbutton.setRolloverImage(’images/northh.gif’) topbutton.setToolTipText(’pan north’) topbutton.setMessage(’pan the map to the north’) bottombutton = new IlvButton(x+w/2, y+h, 33, 13,’images/south.gif’,’view.panSouth()’) bottombutton.setRolloverImage(’images/southh.gif’) bottombutton.setToolTipText(’pan south’) bottombutton.setMessage(’pan the map to the south’) leftbutton=new IlvButton(x-13, y+h/2-10, 13, 30,’images/west.gif’,’view.panWest()’) leftbutton.setRolloverImage(’images/westh.gif’) leftbutton.setToolTipText(’pan west’) leftbutton.setMessage(’pan the map to the west’) rightbutton=new IlvButton(x+w, y+h/2-25, 13, 28, ’images/east.gif’, ’view.panEast()’) rightbutton.setRolloverImage(’images/easth.gif’) rightbutton.setToolTipText(’pan east’) rightbutton.setMessage(’pan the map to the east’)
ボタンは、その位置とサイズ、メイン・イメージとロールオーバー・イメージの 2 つのイメージ、ボタンをクリックすると実行される JavaScript で定義されます。
北へパンするには、 IlvView の
panNorth
メソッドを使用します。次の行で拡大/縮小する 2 つのボタンが追加作成されました。
var zoominbutton, zoomoutbutton zoominbutton=new IlvButton(x+w+30, y+h-16,12, 12, ’images/zoom.gif’, ’view.zoomIn()’) zoominbutton.setRolloverImage(’images/zoomh.gif’) zoominbutton.setMessage(’click to zoom by 2’) zoominbutton.setToolTipText(’Zoom In’) zoomoutbutton=new IlvButton(x+w+30, y, 12, 12, ’images/unzoom.gif’, ’view.zoomOut()’) zoomoutbutton.setRolloverImage(’images/unzoomh.gif’) zoomoutbutton.setMessage(’click to zoom out by 2’) zoomoutbutton.setToolTipText(’Zoom Out’)
各ボタンには
message
プロパティーが設定されています。マウスがボタンの上に置かれると、ブラウザーの状況ウィンドウに、メッセージが自動的に表示されます。メッセージは追加パネルにも表示できます。このため、行: IlvButton.defaultInfoPanel=messagePanel
によってボタンのメッセージが JavaScript メッセージ・パネルにも表示されることが分かります。