// ********************************************************************** // ********************************************************************** package com.obrctm.openmap.editor; import com.bbn.openmap.Environment; import com.bbn.openmap.gui.Tool; import com.bbn.openmap.gui.WindowSupport; import com.bbn.openmap.InformationDelegator; import com.bbn.openmap.MapHandler; import com.bbn.openmap.MapHandlerChild; import com.bbn.openmap.omGraphics.*; import com.bbn.openmap.tools.drawing.*; import com.bbn.openmap.util.Debug; import com.bbn.openmap.util.PaletteHelper; import java.awt.*; import java.awt.event.*; import java.beans.*; import java.beans.beancontext.*; import java.util.*; import javax.swing.*; /** * This tool is a widget that calls the OMDrawingTool to create a * specific graphic. The launcher is completely configured by * EditToolLaunchers and OMGraphicHandlers that it finds in a * MapHandler. There are no methods to manually add stuff to this * GUI. */ public class GraphicEditToolLauncher extends OMDrawingToolLauncher { String[] rtc = { "Lat/Lon", "X/Y", "X/Y Offset" }; protected JComboBox requestors; public GraphicEditToolLauncher() { super(); //setWindowSupport(new WindowSupport(this, "Editor Tool Launcher")); try { resetGUI(); } catch (Exception e) { e.printStackTrace(); } } public void setRequestor(String aName) { if (requestors == null) return; requestors.setSelectedItem(aName); } /** * Build the stuff that goes in the launcher. * * Metoda pokrywa metodę resetGUI() z com.bbn.openmap.util.OMDrawingToolLauncher. Jedyna * różnica to fakt, że zmienna JComboBox requestors nie jest lokalna. W ten sposób możliwy * staje się dostęp do tego pola dla metody setRequestor() * */ public void resetGUI() { removeAll(); JPanel palette = new JPanel(); palette.setLayout(new BoxLayout(palette, BoxLayout.Y_AXIS)); palette.setAlignmentX(Component.CENTER_ALIGNMENT); // LEFT palette.setAlignmentY(Component.CENTER_ALIGNMENT); // BOTTOM String[] requestorNames = new String[drawingToolRequestors.size()]; if (Debug.debugging("omdtl")) { Debug.output("Have " + requestorNames.length + " REQUESTORS"); } for (int i = 0; i < requestorNames.length; i++) { requestorNames[i] = ((DrawingToolRequestor)drawingToolRequestors.elementAt(i)).getName(); if (requestorNames[i] == null) { Debug.output("OMDrawingToolLauncher has a requestor that is unnamed. Please assign a name to the requestor"); requestorNames[i] = "-- Unnamed --"; } if (Debug.debugging("omdtl")) { Debug.output("Adding REQUESTOR " + requestorNames[i] + " to menu"); } } requestors = new JComboBox(requestorNames); requestors.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox jcb = (JComboBox) e.getSource(); String currentChoice = (String)jcb.getSelectedItem(); setCurrentRequestor(currentChoice); } }); if (requestorNames.length > 0) { requestors.setSelectedIndex(0); } JPanel panel = PaletteHelper.createPaletteJPanel("Send To:"); panel.add(requestors); palette.add(panel); if (Debug.debugging("omdtl")) { Debug.output("Figuring out tools, using names"); } panel = PaletteHelper.createPaletteJPanel("Graphic Type:"); panel.add(getToolWidgets(useTextEditToolTitles)); palette.add(panel); String[] renderTypes = new String[3]; renderTypes[OMGraphic.RENDERTYPE_LATLON - 1] = rtc[0]; renderTypes[OMGraphic.RENDERTYPE_XY - 1] = rtc[1]; renderTypes[OMGraphic.RENDERTYPE_OFFSET - 1] = rtc[2]; JComboBox renderTypeList = new JComboBox(renderTypes); renderTypeList.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox jcb = (JComboBox) e.getSource(); String currentChoice = (String)jcb.getSelectedItem(); if (currentChoice == rtc[2]) { defaultGraphicAttributes.setRenderType(OMGraphic.RENDERTYPE_OFFSET); } else if (currentChoice == rtc[1]) { defaultGraphicAttributes.setRenderType(OMGraphic.RENDERTYPE_XY); } else { defaultGraphicAttributes.setRenderType(OMGraphic.RENDERTYPE_LATLON); } } }); renderTypeList.setSelectedIndex(defaultGraphicAttributes.getRenderType() - 1); panel = PaletteHelper.createVerticalPanel("Graphic Attributes:"); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); JPanel panel2 = PaletteHelper.createVerticalPanel("Rendering Type:"); panel2.add(renderTypeList); JPanel panel3 = PaletteHelper.createVerticalPanel("Line Types and Colors:"); panel3.add(defaultGraphicAttributes.getGUI()); panel.add(panel2); panel.add(panel3); palette.add(panel); JButton createButton = new JButton("Create Graphic"); createButton.setActionCommand(CreateCmd); createButton.addActionListener(this); JPanel dismissBox = new JPanel(); JButton dismiss = new JButton("Close"); dismissBox.setLayout(new BoxLayout(dismissBox, BoxLayout.X_AXIS)); dismissBox.setAlignmentX(Component.CENTER_ALIGNMENT); dismissBox.setAlignmentY(Component.BOTTOM_ALIGNMENT); dismissBox.add(createButton); dismissBox.add(dismiss); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setAlignmentX(Component.CENTER_ALIGNMENT); setAlignmentY(Component.BOTTOM_ALIGNMENT); add(palette); add(dismissBox); dismiss.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { getWindowSupport().killWindow(); } }); } }