/* * Licensed Materials - Property of Perforce Software, Inc. * © Copyright Perforce Software, Inc. 2014, 2021 * © Copyright IBM Corp. 2009, 2014 * © Copyright ILOG 1996, 2009 * All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: * The Software and Documentation were developed at private expense and * are "Commercial Items" as that term is defined at 48 CFR 2.101, * consisting of "Commercial Computer Software" and * "Commercial Computer Software Documentation", as such terms are * used in 48 CFR 12.212 or 48 CFR 227.7202-1 through 227.7202-4, * as applicable. */ package shared; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.ComponentOrientation; import java.awt.Container; import java.awt.Dimension; import java.awt.Font; import java.awt.Frame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.HeadlessException; import java.awt.Image; import java.awt.Insets; import java.awt.Point; import java.awt.RenderingHints; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.security.AccessControlException; import java.sql.DriverManager; import java.util.Arrays; import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Random; import java.util.Vector; import javax.swing.AbstractButton; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JCheckBoxMenuItem; import javax.swing.JComboBox; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.JRootPane; import javax.swing.JScrollPane; import javax.swing.JSeparator; import javax.swing.JSlider; import javax.swing.JSplitPane; import javax.swing.JTable; import javax.swing.JToggleButton; import javax.swing.JToolTip; import javax.swing.JTree; import javax.swing.KeyStroke; import javax.swing.OverlayLayout; import javax.swing.SpringLayout; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.Timer; import javax.swing.ToolTipManager; import javax.swing.UIManager; import javax.swing.border.EtchedBorder; import javax.swing.border.TitledBorder; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.plaf.basic.BasicHTML; import javax.swing.tree.TreePath; import ilog.views.IlvConstants; import ilog.views.IlvGrapher; import ilog.views.IlvGraphic; import ilog.views.IlvGraphicEnumeration; import ilog.views.IlvManager; import ilog.views.IlvManagerLayer; import ilog.views.IlvManagerView; import ilog.views.IlvManagerViewInteractor; import ilog.views.IlvNamedProperty; import ilog.views.IlvPoint; import ilog.views.IlvRect; import ilog.views.IlvTransformer; import ilog.views.IlvUtil; import ilog.views.event.InteractorChangedEvent; import ilog.views.event.InteractorListener; import ilog.views.event.ManagerContentChangedEvent; import ilog.views.event.ManagerContentChangedListener; import ilog.views.event.ManagerSelectionChangedEvent; import ilog.views.event.ManagerSelectionListener; import ilog.views.event.ObjectInsertedEvent; import ilog.views.interactor.IlvMakePolyPointsInteractor; import ilog.views.interactor.IlvManagerMagViewInteractor; import ilog.views.interactor.IlvPolyPointsObjectFactory; import ilog.views.maps.ExceptionHandler; import ilog.views.maps.IlvAltitudeDataSource; import ilog.views.maps.IlvAreaOfInterest; import ilog.views.maps.IlvAttributeInfoProperty; import ilog.views.maps.IlvAttributeProperty; import ilog.views.maps.IlvCoordinate; import ilog.views.maps.IlvCoordinateSystemProperty; import ilog.views.maps.IlvDisplayPreferences; import ilog.views.maps.IlvDisplayPreferencesProperty; import ilog.views.maps.IlvFeatureAttribute; import ilog.views.maps.IlvFeatureAttributeProperty; import ilog.views.maps.IlvMapLayerTreeProperty; import ilog.views.maps.IlvMapOutputStream; import ilog.views.maps.IlvMapScaleLimiter; import ilog.views.maps.IlvMapUtil; import ilog.views.maps.attribute.IlvAttributeArray; import ilog.views.maps.attribute.IlvStringAttribute; import ilog.views.maps.beans.IlvCompass; import ilog.views.maps.beans.IlvDataSourcePanel; import ilog.views.maps.beans.IlvExceptionMessage; import ilog.views.maps.beans.IlvJAdvancedZoomControl; import ilog.views.maps.beans.IlvJAreaOfInterestPanel; import ilog.views.maps.beans.IlvJAutomaticScaleBar; import ilog.views.maps.beans.IlvJCompass; import ilog.views.maps.beans.IlvJCoordinateSystemEditorPanel; import ilog.views.maps.beans.IlvJDisplayPreferencesEditorPanel; import ilog.views.maps.beans.IlvJMapLegend; import ilog.views.maps.beans.IlvJMapScaleControl; import ilog.views.maps.beans.IlvJMapsManagerViewControlBar; import ilog.views.maps.beans.IlvJMouseCoordinateViewer; import ilog.views.maps.beans.IlvJOverview; import ilog.views.maps.beans.IlvLayerTreePanel; import ilog.views.maps.beans.IlvMapAnnotationToolBar; import ilog.views.maps.beans.IlvMapLayer; import ilog.views.maps.beans.IlvMapLayerTreeModel; import ilog.views.maps.beans.IlvMapLegendPanel; import ilog.views.maps.beans.IlvMapScaleComputation; import ilog.views.maps.datasource.IlvGraphicLayerDataSource; import ilog.views.maps.datasource.IlvMapDataSource; import ilog.views.maps.datasource.IlvMapDataSourceModel; import ilog.views.maps.datasource.IlvMapDataSourceProperty; import ilog.views.maps.datasource.IlvShapeDataSource; import ilog.views.maps.export.IlvKMLExporter; import ilog.views.maps.export.IlvMapExportDialog; import ilog.views.maps.export.IlvSDOExporter; import ilog.views.maps.export.IlvShapeExporter; import ilog.views.maps.export.SDOConnectionPanel; import ilog.views.maps.format.image.IlvRasterBasicImageReader; import ilog.views.maps.graphic.IlvMapSelectionFactory; import ilog.views.maps.graphic.style.IlvGraphicPathStyle; import ilog.views.maps.graphic.style.IlvMapCompositeStyle; import ilog.views.maps.graphic.style.IlvMapStyle; import ilog.views.maps.graphic.style.IlvMapStyleBeanInfo; import ilog.views.maps.graphic.style.IlvPolylineStyle; import ilog.views.maps.interactor.IlvContinuousZoomInteractor; import ilog.views.maps.interactor.IlvManagerViewRotateInteractor; import ilog.views.maps.interactor.IlvMapPanInteractor; import ilog.views.maps.interactor.IlvSeeThroughConfigurationPanel; import ilog.views.maps.interactor.IlvSeeThroughInteractor; import ilog.views.maps.label.IlvMapLabelStyle; import ilog.views.maps.label.IlvMapLabeler; import ilog.views.maps.label.IlvMapLabelerProperty; import ilog.views.maps.measures.IlvMakeMeasureInteractor; import ilog.views.maps.print.IlvMapPrintingController; import ilog.views.maps.projection.IlvProjectionUtil; import ilog.views.maps.raster.IlvRasterTemporaryFileManager; import ilog.views.maps.raster.datasource.IlvRasterDataSourceFactory; import ilog.views.maps.srs.coordsys.IlvCoordinateSystem; import ilog.views.maps.srs.coordsys.IlvGeographicCoordinateSystem; import ilog.views.maps.srs.coordsys.IlvProjectedCoordinateSystem; import ilog.views.maps.srs.coordtrans.IlvCoordinateTransformation; import ilog.views.maps.srs.coordtrans.IlvCoordinateTransformationException; import ilog.views.print.IlvManagerPrintableDocument; import ilog.views.print.IlvPrintAreaInteractor; import ilog.views.sdm.IlvSDMEngine; import ilog.views.swing.IlvJScrollManagerView; import ilog.views.swing.IlvThreadedActivityMonitor; import ilog.views.swing.IlvThreadedActivityMonitorPanel; import ilog.views.swing.IlvThreadedActivityMonitorProperty; import ilog.views.swing.IlvToolTipManager; import ilog.views.util.IlvImageUtil; import ilog.views.util.IlvProductUtil; import ilog.views.util.internal.IlvPopUserBrowser; import ilog.views.util.print.IlvPrintableDocument; import ilog.views.util.swing.IlvSwingUtil; import nodefense.InteractorsDefLess; import plugins.SDOLoadAction; import plugins.ShapeLoadAction; import shared.ui.AdvancedTabbedPane; import utils.CoordinateSystemDictionaryManager; import utils.GCManager; import utils.GridManager; import utils.IvlFileManager; import utils.SymbologyManager; import utils.TileCacheManager; import utils.TileDebugManager; /** * base JViews Maps show case. */ SuppressWarnings("serial") public abstract class BaseDemo extends JRootPane implements PropertyChangeListener { /** * A boolean that allows to load a simplified default map when set to true. * Note, this parameter can be changed in the MapBuilder.settings file */ protected boolean useSimplifiedDefaultMap = true; /** * A boolean to control whether the map needs to be updated for each change of * the projection in the coordinate panel. */ protected boolean autoReprojection; static { // to change the default appearance of the split pane dividers everywhere in // this application. UIManager.put("SplitPaneDivider.border", BorderFactory.createEmptyBorder()); //$NON-NLS-1$ UIManager.put("SplitPane.dividerSize", Integer.valueOf(5));//$NON-NLS-1$ /* * since JViews 8.1 : display a message to the user when a deep exception * happens */ IlvMapUtil.setExceptionHandler(new ExceptionHandler() { Override public void handle(Exception e) throws Exception { new IlvExceptionMessage(e, null); throw e; } }); // speed-up oracle connection timeout (JV-3538) DriverManager.setLoginTimeout(3); } { // This sample uses JViews Maps features. When deploying an // application that includes this code, you need to be in possession // of a JViews Maps Deployment license. IlvProductUtil.DeploymentLicenseRequired(IlvProductUtil.JViews_Maps_Deployment); // It can also use JViews Maps for Defense features. If you need those, // when deploying an application that includes this code, you need to be // in possession of a JViews Maps for Defense Deployment license. IlvProductUtil.DeploymentLicenseRequired(IlvProductUtil.JViews_Maps_for_Defense_Deployment); // This sample uses JViews Charts features (through the Charts palette). // When deploying an application that includes this code, you need to // be in possession of a JViews Charts Deployment license. IlvProductUtil.DeploymentLicenseRequired(IlvProductUtil.JViews_Charts_Deployment); } // Listener on manager properties to detect if map structure has changed private JButton preview = new JButton(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.PrintPreview")); //$NON-NLS-1$ private JButton setup = new JButton(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.PageSetup")); //$NON-NLS-1$ private JButton print = new JButton(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.Print")); //$NON-NLS-1$ /** * @return the print button */ public JButton getPrintButton() { return print; } /** * @return the print setup button */ public JButton getSetupButton() { return setup; } /** * @return the print preview button */ public JButton getPreviewButton() { return preview; } private static IlvMapDataSource findDataSource(IlvMapLayer mapLayer) { IlvMapDataSource dataSource = mapLayer.getDataSource(); if (dataSource == null) { IlvMapLayer parentLayer = null; try { parentLayer = mapLayer.getParent(); } catch (ClassCastException e) { // Workaround for exception sometimes thrown by getParent() ... } if (parentLayer != null) { dataSource = findDataSource(parentLayer); } } return dataSource; } static boolean removeSelection(IlvManager manager) { boolean removed = false; IlvGraphicEnumeration en = manager.getSelectedObjects(); Vector<IlvGraphic> selected = new Vector<IlvGraphic>(); while (en.hasMoreElements()) { IlvGraphic obj = en.nextElement(); if (obj != null) { selected.add(obj); } } if (selected.size() > 0) { IlvMapLabelerProperty p = (IlvMapLabelerProperty) manager.getNamedProperty(IlvMapLabelerProperty.NAME); for (int i = 0; i < selected.size(); i++) { IlvGraphic obj = (IlvGraphic) selected.get(i); // select it if (obj != null) { IlvMapLayer ml = IlvMapLayer.get(obj); manager.removeObject(obj, true); if (ml != null) { IlvMapDataSource ds = findDataSource(ml); if (ds instanceof IlvGraphicLayerDataSource) { IlvGraphicLayerDataSource gds = (IlvGraphicLayerDataSource) ds; gds.remove(obj); // JV-2949 remove the layer it it becomes empty if (gds.size() == 0) { IlvMapLayer toRemove = ds.getInsertionLayer(); IlvMapLayerTreeModel model = IlvMapLayerTreeProperty.GetMapLayerTreeModel(manager); model.removeChild(toRemove); } } else if (ds != null) { ds.setForceUsingBackupDataSource(true); IlvGraphicLayerDataSource srcs[] = ds.getBackupDataSources(); if (srcs != null) { int nobj = 0; for (int is = 0; is < srcs.length; is++) { srcs[is].remove(obj); nobj += srcs[is].size(); } // remove the layer it it becomes empty if (nobj == 0) { IlvMapLayer toRemove = ds.getInsertionLayer(); IlvMapLayerTreeModel model = IlvMapLayerTreeProperty.GetMapLayerTreeModel(manager); model.removeChild(toRemove); } } ds.setSaveBackupDataSources(true); if (p != null) { IlvMapLabeler labeler = p.getMapLabeler(); if (labeler != null) { labeler.performLabeling(); } } removed = true; } else if (manager instanceof IlvGrapher) { // JV-2887: remove // symbols from the // engine. IlvSDMEngine e = IlvSDMEngine.getSDMEngine((IlvGrapher) manager); if (e != null) { Object modelObject = e.getObject(obj); if (modelObject != null) { e.getModel().removeObject(modelObject); } } } } } } } return removed; } private final class PopInteractorKeyListener extends KeyAdapter { /** * Manage ESCAPE key. * * @see java.awt.event.KeyAdapter#keyPressed(java.awt.event.KeyEvent) */ Override public void keyPressed(KeyEvent e) { if (e.getKeyChar() == KeyEvent.VK_ESCAPE) { view.popInteractor(); } } } private class FileOpenButton extends JMenuItem implements ActionListener { FileOpenButton(String fileName) { super(fileName); addActionListener(this); } /** * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ Override public void actionPerformed(ActionEvent e) { File f = new File(getText()); if (f.exists()) { IvlFileManager.LoadIvlActionListener loader = new IvlFileManager.LoadIvlActionListener(BaseDemo.this); loader.doLoad(f); } } } static private int lastFilesCount = 4; private Properties bundle = new Properties(); /** * @return the stored properties. */ public Properties getPreferences() { return bundle; } /** * @return Returns the maximum number of files in the last files menu. */ public static int getLastFilesCount() { return lastFilesCount; } private static final String lastFileTag = "LastFile"; //$NON-NLS-1$ /** * Sets last opened file * * @param fileName * file path and name */ public void setCurrentFile(String fileName) { currentFile = fileName; saveBtn.setEnabled(currentFile != null); if (fileName == null) return; fileName = fileName.replace('\\', '/'); Vector<String> names = new Vector<String>(); int i; for (i = 0; i < getLastFilesCount(); i++) { String last = bundle.getProperty(lastFileTag + i); if (last != null) names.add(last); } names.removeElement(fileName); names.insertElementAt(fileName, 0); for (i = 0; i < names.size(); i++) { bundle.setProperty(lastFileTag + i, (String) names.get(i)); } for (; i < getLastFilesCount(); i++) { bundle.remove(lastFileTag + i); } savePreferences(); setupRecentFileMenu(); // JV-1782 : set the document name. if (fileName.endsWith("/")) //$NON-NLS-1$ fileName = fileName.substring(0, fileName.length() - 1); i = fileName.lastIndexOf('/'); String docName = i != -1 ? fileName.substring(i + 1) : fileName; getPrintingController().getDocument().setName(docName); } /** * @return Returns the current File. */ public String getCurrentFile() { return currentFile; } private void setupRecentFileMenu() { lastFilesMenu.removeAll(); for (int i = 0; i < getLastFilesCount(); i++) { String fileName = bundle.getProperty("LastFile" + i);//$NON-NLS-1$ if (fileName != null) { lastFilesMenu.add(new FileOpenButton(fileName)); } } lastFilesMenu.setEnabled(lastFilesMenu.getMenuComponentCount() != 0); } /** * Add additional preferences (for subclasses) * * @param pbundle * properties to load. */ protected void loadAddditionalPreferences(Properties pbundle) { pbundle.setProperty("BaseDemo.SimplifiedDefaultMap", Boolean.toString(useSimplifiedDefaultMap)); //$NON-NLS-1$ } /** * Save additional preferences (for subclasses) * * @param pbundle * properties to load. */ protected void saveAddditionalPreferences(Properties pbundle) { /* ignore */ } /** * the splash windows that shows when map builder starts. */ protected static SplashWindow splashWindow; /** * Creates and shows the splash screen. */ protected static void showSplashScreen() { String iconFile = IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SplashIconURL"); //$NON-NLS-1$ splashWindow = new SplashWindow(new JFrame(), findURL(iconFile)); splashWindow.showMessage(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SplashInitalizing")); //$NON-NLS-1$ splashWindow.start(); } private int fps = 0; // // COMPONENTS // -------------------------------------------------------------------- /** Map view */ protected IlvManagerView view; /** Map Overview */ protected IlvJOverview overview; /** Map Toolbar */ protected IlvJMapsManagerViewControlBar toolbar; /** Coordinate viewer */ protected IlvJMouseCoordinateViewer coordViewer; /** Scale control panel */ protected IlvJMapScaleControl scaleControl; /** Graphic scale visualizer */ protected IlvJAutomaticScaleBar graphicScale; /** Layer Tree Panel */ protected IlvLayerTreePanel layerTreePanel; /** Data Source List */ protected IlvDataSourcePanel dataSourcePanel; /** Advanced zooming slider */ protected IlvJAdvancedZoomControl zoomer; /** Continuous zoom and pan interactor */ protected IlvContinuousZoomInteractor continuousZoomer; /** IlvMapManager list */ protected IlvJMapLegend _managerLayersLegend; /** IlvMapManager list */ protected JPanel managerLayersPanel; /** New Legend */ protected IlvMapLegendPanel mapLayersLegend; /** coordinate system panel */ protected JPanel csMainPanel; /** coordinate system editor */ protected IlvJCoordinateSystemEditorPanel csPanel; /** preference Editor panel */ protected IlvJDisplayPreferencesEditorPanel prefsPanel; /** Symbol edition panel */ protected JPanel simpleSymbologyPanel; /** Symbol edition panel */ protected IlvJAreaOfInterestPanel areaPanel; /** file menu */ protected JMenu fileMenu; /** options menu */ protected JMenu optionMenu; /** Help menu * */ protected JMenu helpMenu; /** last files opened sub-menu */ protected JMenu lastFilesMenu = new JMenu(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.Recent")); //$NON-NLS-1$ /** Coordinate system selection dialog */ protected CoordinateSystemDictionaryManager csdialog; /** Symbology management */ protected SymbologyManager symbologyManager; /** Scale panel */ protected JPanel scalePanel; /** View Popup menu */ protected JPopupMenu viewPopupMenu = new JPopupMenu(); /** Location where popup menu was last displayed */ protected Point lastPopupLocation = new Point(); /** Annotations toolbar */ protected IlvMapAnnotationToolBar annotations; // protected JDialog generateTiles; // // CONTAINERS // -------------------------------------------------------------------- /** editor tabbed panes */ private AdvancedTabbedPane bottomLeftPanel; private AdvancedTabbedPane additionalViewPanel; private JDialog additionalViewDialog; /** * Returns a tabbed pane to place unused views into. * * @return Returns a tabbed pane to place unused views into. */ protected AdvancedTabbedPane getAdditionalViewsPanel() { if (additionalViewPanel == null) { additionalViewPanel = new AdvancedTabbedPane(); } return additionalViewPanel; } private AdvancedTabbedPane bottomRightPanel; private AdvancedTabbedPane topLeftPanel; /** panel containing the status */ protected JPanel statusPanel; /** panel monitoring background tasks */ protected IlvThreadedActivityMonitorPanel monitorPanel; /** view scroll */ private IlvJScrollManagerView viewScroll; /** left hand side panel */ protected JSplitPane leftSplitPane; /** right hand side panel */ protected JSplitPane rightSplitPane; /** main split between overview & view */ protected JSplitPane mainSplit; /** Print panel */ protected JPanel printPanel; /** Continuous Zoom configuration panel */ protected ZoomConfigurationPanel zoomConfigPanel; /** advanced panel */ protected JPanel advancedPanel; /** grid setting panel */ protected JPanel gridPanel; // JPanel prefPanel; /** panel containing overview and zoom control */ protected JPanel overviewAndZoomPanel; // private JDialog additionalViewFrame; /** * Button to change triple buffer state */ protected MBCheckBoxMenuItem tripleBuffered; /** * Button to change antialiasing state */ protected MBCheckBoxMenuItem antiAliased; /** * Button to change map tooltip state */ protected MBCheckBoxMenuItem showToolTips; /** * Button to change triple buffer state */ protected MBCheckBoxMenuItem showGUIToolTips; /** * Button to change advanced properties state */ protected MBCheckBoxMenuItem advancedProperties; /** * Button to select coordinate systems */ protected MBMenuItem selectSystem; /** * Button to show additional views */ protected MBMenuItem additionalViews; /** * Button to save map */ protected MBMenuItem saveBtn = new MBMenuItem("BaseDemo.SaveMap", true); //$NON-NLS-1$ /** * Button to save map as */ protected MBMenuItem saveAsBtn = new MBMenuItem("BaseDemo.SaveAs", true); //$NON-NLS-1$ /** * Button to load map */ protected MBMenuItem loadBtn = new MBMenuItem("BaseDemo.OpenMap", true); //$NON-NLS-1$ /** * Button to clear map */ protected MBMenuItem clearBtn = new MBMenuItem("BaseDemo.ClearMap", true); //$NON-NLS-1$ /** * Button to exit */ protected MBMenuItem exitBtn = new MBMenuItem("BaseDemo.Exit", true); //$NON-NLS-1$ /** * * Button to show print dialog Not used for now */ protected MBMenuItem printButton = new MBMenuItem("BaseDemo.Print", true); //$NON-NLS-1$ /** * Button to export */ protected MBMenuItem exportBtn = new MBMenuItem("BaseDemo.Export", true); //$NON-NLS-1$ /** * Button to export */ protected MBMenuItem tilingButton = new MBMenuItem("BaseDemo.ThinClientParameters", true); //$NON-NLS-1$ /** * Generate tiles. */ // protected MBMenuItem generateTilesButton = new // MBMenuItem("BaseDemo.GenerateTiles", true); //$NON-NLS-1$ /** * Button to change projection center */ protected MBToggleButton centerInteractorBtn; /** * Button to zoom to layer */ protected MBButton zoomToLayer = new MBButton("BaseDemo.ZoomToLayer", false); //$NON-NLS-1$ /** * Menu Item to zoom to layer */ protected MBMenuItem miZoomToLayer = new MBMenuItem("BaseDemo.ZoomToLayer", true); //$NON-NLS-1$ /** * Menu Item to select an object */ protected MBMenuItem miSelectObject = new MBMenuItem("BaseDemo.SelectObject", true); //$NON-NLS-1$ /** * Menu Item to edit the metadata of an object */ protected MBMenuItem miEditDataObject = new MBMenuItem("BaseDemo.EditObjectData", true); //$NON-NLS-1$ /** * Menu Item to remove an object */ protected MBMenuItem miRemoveObject = new MBMenuItem("BaseDemo.RemoveObject", true); //$NON-NLS-1$ /** * Menu Item to zoom to selection */ protected MBMenuItem miZoomToObject = new MBMenuItem("BaseDemo.ZoomToObject", true); //$NON-NLS-1$ /** * Menu Item to center on selection */ protected MBMenuItem miCenterOnObject = new MBMenuItem("BaseDemo.CenterOnObject", true); //$NON-NLS-1$ /** * Menu Item to cancel popup menu */ protected MBMenuItem miCancel = new MBMenuItem("BaseDemo.CancelPopupMenu", true); //$NON-NLS-1$ private JTree layerTree; private GridManager gridManager; private Map<String, AdvancedTabbedPane> panes; private String currentFile; IlvSeeThroughInteractor seeThrough; /** * JButton that manages icon resource. */ static public class MBButton extends JButton { /** * Creates a new <code>MBButton</code>. * * @param ressourceName * resource name to find icon,label and tooltip * @param showIconAndText * indicates if both icon and text should be visible */ public MBButton(String ressourceName, boolean showIconAndText) { this(BaseDemo.class, ressourceName, showIconAndText); } /** * Creates a new <code>MBButton</code>. * * @param loader * class to use to find resource file. * @param ressourceName * resource name to find icon,label and tooltip * @param showIconAndText * indicates if both icon and text should be visible */ public MBButton(Class<?> loader, String ressourceName, boolean showIconAndText) { try { String iconURL = IlvMapUtil.getString(loader, ressourceName + "Icon"); //$NON-NLS-1$ Image image = IlvImageUtil.getImageFromFile(loader, iconURL); setIcon(new ImageIcon(image)); if (showIconAndText) { setText(IlvMapUtil.getString(loader, ressourceName)); } } catch (IOException e1) { setText(IlvMapUtil.getString(loader, ressourceName)); } setToolTipText(wrapToolTipText(IlvMapUtil.getString(loader, ressourceName + "Tip"))); //$NON-NLS-1$ setMargin(new Insets(2, 2, 2, 2)); } } /** * JToggleButton that manages icon resource. */ static public class MBToggleButton extends JToggleButton { /** * Creates a new <code>MBToggleButton</code>. * * @param ressourceName * resource name to find icon,label and tooltip * @param showIconAndText * indicates if both icon and text should be visible */ public MBToggleButton(String ressourceName, boolean showIconAndText) { this(BaseDemo.class, ressourceName, showIconAndText); } /** * Creates a new <code>MBToggleButton</code>. * * @param loader * class to use to find resource file. * @param ressourceName * resource name to find icon,label and tooltip * @param showIconAndText * indicates if both icon and text should be visible */ public MBToggleButton(Class<?> loader, String ressourceName, boolean showIconAndText) { try { String iconURL = IlvMapUtil.getString(loader, ressourceName + "Icon"); //$NON-NLS-1$ Image image = IlvImageUtil.getImageFromFile(loader, iconURL); setIcon(new ImageIcon(image)); if (showIconAndText) { setText(IlvMapUtil.getString(loader, ressourceName)); } } catch (IOException e1) { setText(IlvMapUtil.getString(loader, ressourceName)); } setToolTipText(wrapToolTipText(IlvMapUtil.getString(loader, ressourceName + "Tip"))); //$NON-NLS-1$ setMargin(new Insets(2, 2, 2, 2)); } } /** * about ... */ protected MBMenuItem about = new MBMenuItem("BaseDemo.Help.About", false); //$NON-NLS-1$ /** * MapBuilder help ... */ protected MBMenuItem mapBuilder = new MBMenuItem("BaseDemo.Help.MapBuilder", false); //$NON-NLS-1$ /** * Menu item that manages accelerator resource. */ static public class MBMenuItem extends JMenuItem { /** * Creates a new <code>MBMenuItem</code>. * * @param ressourceName * resource name to find icon,label and tooltip * @param showIconAndText * indicates if both icon and text should be visible */ public MBMenuItem(String ressourceName, boolean showIconAndText) { this(BaseDemo.class, ressourceName, showIconAndText); } /** * Creates a new <code>MBMenuItem</code>. * * @param loader * @param ressourceName * resource name to find icon,label and tooltip * @param showIconAndText * indicates if both icon and text should be visible */ public MBMenuItem(Class<?> loader, String ressourceName, boolean showIconAndText) { String accelerator = IlvMapUtil.getString(loader, ressourceName + "Accelerator"); //$NON-NLS-1$ if (accelerator != null) { setAccelerator(KeyStroke.getKeyStroke(accelerator)); } try { String iconURL = IlvMapUtil.getString(loader, ressourceName + "Icon"); //$NON-NLS-1$ Image image = IlvImageUtil.getImageFromFile(loader, iconURL); setIcon(new ImageIcon(image)); if (showIconAndText) { setText(IlvMapUtil.getString(loader, ressourceName)); } } catch (IOException e1) { setText(IlvMapUtil.getString(loader, ressourceName)); } } } /** * Menu item that manages accelerator resource. */ static public class MBCheckBoxMenuItem extends JCheckBoxMenuItem { /** * Creates a new <code>MBCheckBoxMenuItem</code>. * * @param ressourceName * @param status */ public MBCheckBoxMenuItem(String ressourceName, boolean status) { this(BaseDemo.class, ressourceName, status); } /** * Creates a new <code>MBCheckBoxMenuItem</code>. * * @param loader * @param ressourceName * @param status */ public MBCheckBoxMenuItem(Class<?> loader, String ressourceName, boolean status) { super(IlvMapUtil.getString(loader, ressourceName), status); String accelerator = IlvMapUtil.getString(loader, ressourceName + "Accelerator"); //$NON-NLS-1$ if (accelerator != null) { setAccelerator(KeyStroke.getKeyStroke(accelerator)); } } } /** * List of additional views; Comment for <code>views</code> */ protected JComponent views[]; /** Engine used to display symbols */ protected IlvSDMEngine engine; private IlvMapExportDialog exportDialog; JDialog printDialog; /** Dialog to manage tile pyramid parameter (for thin client use) * */ JDialog tilingDialog = null; private IlvJCompass compass; /** * Adds a named tabbed pane for view management. * * @param pane */ protected void addTabbedPane(AdvancedTabbedPane pane) { panes.put(pane.getName(), pane); } /** * Sets the default names of the different views and builds the {@link #views} * table. */ protected void initViews() { bottomLeftPanel.setName("BottomLeft"); //$NON-NLS-1$ getAdditionalViewsPanel().setName("AdditionalViews");//$NON-NLS-1$ bottomRightPanel.setName("BottomRight");//$NON-NLS-1$ topLeftPanel.setName("TopLeft");//$NON-NLS-1$ panes = new HashMap<String, AdvancedTabbedPane>(); addTabbedPane(bottomLeftPanel); addTabbedPane(bottomRightPanel); addTabbedPane(getAdditionalViewsPanel()); addTabbedPane(topLeftPanel); advancedPanel.setName("BaseDemo.AdvancedSettings");//$NON-NLS-1$ managerLayersPanel.setName("BaseDemo.ManagerLayers");//$NON-NLS-1$ mapLayersLegend.setName("BaseDemo.NewLegend");//$NON-NLS-1$ compass.setName("BaseDemo.Compass");//$NON-NLS-1$ dataSourcePanel.setName("BaseDemo.DataSources");//$NON-NLS-1$ printPanel.setName("BaseDemo.Printing");//$NON-NLS-1$ zoomConfigPanel.setName("BaseDemo.ZoomConfigPanel"); //$NON-NLS-1$ gridPanel.setName("BaseDemo.Grids");//$NON-NLS-1$ layerTreePanel.setName("BaseDemo.MapLayers");//$NON-NLS-1$ csMainPanel.setName("BaseDemo.DisplayOptions");//$NON-NLS-1$ prefsPanel.setName("BaseDemo.Preferences");//$NON-NLS-1$ simpleSymbologyPanel.setName("BaseDemo.SymbologyTab");//$NON-NLS-1$ overviewAndZoomPanel.setName("BaseDemo.Overview");//$NON-NLS-1$ areaPanel.setName("BaseDemo.Areas");//$NON-NLS-1$ views = new JComponent[] { layerTreePanel, advancedPanel, managerLayersPanel, mapLayersLegend, compass, dataSourcePanel, printPanel, zoomConfigPanel, gridPanel, prefsPanel, csMainPanel, simpleSymbologyPanel, overviewAndZoomPanel, areaPanel }; } /** * @return the name of the preference file. */ protected String getPreferenceFileName() { return IlvMapUtil.getString(BaseDemo.class, "BaseDemo.PreferencesFile"); //$NON-NLS-1$ } /** * Saves the preference file to setup views organisation. */ protected void savePreferences() { for (int i = 0; i < views.length; i++) { String parentName = null; if (views[i].getParent() != null) { parentName = views[i].getParent().getName(); } if (parentName != null) { bundle.setProperty(views[i].getName(), parentName); } } saveAddditionalPreferences(bundle); FileOutputStream out; try { out = new FileOutputStream(getPreferenceFileName()); bundle.store(out, ""); //$NON-NLS-1$ out.close(); } catch (IOException e) { e.printStackTrace(); } catch (SecurityException e) { // Applet -> do not save prefs } } /** * Loads the preference file to setup views organisation. */ protected void loadPreferences() { InputStream preferences; try { preferences = new FileInputStream(getPreferenceFileName()); } catch (FileNotFoundException e1) { preferences = BaseDemo.class.getResourceAsStream(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.DefaultLayout")); //$NON-NLS-1$ } catch (AccessControlException e) { // applet preferences = BaseDemo.class.getResourceAsStream(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.DefaultLayout")); //$NON-NLS-1$ } try { try { bundle.load(preferences); } finally { preferences.close(); } for (int i = 0; i < views.length; i++) { String paneName = bundle.getProperty(views[i].getName()); AdvancedTabbedPane pane = getTabbedPane(paneName); if (pane == null && views[i].getParent() == null) { pane = getAdditionalViewsPanel(); } if (pane != null) { pane.addView(IlvMapUtil.getString(BaseDemo.class, views[i].getName()), views[i], false); } } setupRecentFileMenu(); String s = null; try { s = System.getProperty("BaseDemo.SimplifiedDefaultMap"); //$NON-NLS-1$ } catch (SecurityException e) { // s == null; } if (s != null) useSimplifiedDefaultMap = (Boolean.valueOf(s) == Boolean.TRUE); else { String last = bundle.getProperty("BaseDemo.SimplifiedDefaultMap"); //$NON-NLS-1$ if (last != null) useSimplifiedDefaultMap = (Boolean.valueOf(last) == Boolean.TRUE); } loadAddditionalPreferences(bundle); } catch (Exception e) { e.printStackTrace(); } } /** * Returns the tabbed pane with the name passed. * * @param paneName * name of the tabbed pane. * @return a tabbed pane or null. */ protected AdvancedTabbedPane getTabbedPane(String paneName) { return (AdvancedTabbedPane) panes.get(paneName); } private void createBeans() { /** Map view */ IlvGrapher manager = new IlvGrapher(0/* , Integer.MAX_VALUE */); manager.addNamedPropertyListener(getModificationListener()); if (splashWindow != null) { splashWindow.showMessage(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SplashInitJViews")); //$NON-NLS-1$ } // if (IlvManagerView.class == null) { // do nothing, just for initializing the class. It can take some time so // we change the message. // } if (splashWindow != null) { splashWindow.showMessage(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SplashCreatingView")); //$NON-NLS-1$ } view = new IlvManagerView(manager, null) { Override public void paint(Graphics g) { super.paint(g); fps++;// count frames per second. } }; // view.setRepaintSkipThreshold(100); /** Map Overview */ overview = new IlvJOverview(); /** Map Toolbar */ toolbar = new IlvJMapsManagerViewControlBar(); /** Coordinate viewer */ coordViewer = new IlvJMouseCoordinateViewer(); /** Scale control panel */ scaleControl = new IlvJMapScaleControl(); /** Graphic scale visualizer */ graphicScale = new IlvJAutomaticScaleBar(); compass = new IlvJCompass() { Override public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; Object k = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); super.paint(g); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, k); } }; compass.setCartographicNeedleStyle(IlvCompass.NEEDLE_STYLE_COMPASS_ROSE); compass.setGeographicNeedleStyle(IlvCompass.NEEDLE_STYLE_COMPASS); compass.setDecorationBackground(null); /** Layer Tree Panel */ layerTreePanel = new IlvLayerTreePanel(); ToolTipManager.sharedInstance().registerComponent(layerTreePanel.getLayerTree()); layerTreePanel.getStylePropertySheet().addTargetPropertyChangeListener(getModificationListener()); /** Data Source List */ dataSourcePanel = new IlvDataSourcePanel(); dataSourcePanel.setLayerTree(layerTreePanel.getLayerTree()); /** Advanced zooming slider */ zoomer = new IlvJAdvancedZoomControl(); /** * IlvMapManager list: do not create it unless user needs it: it consumes * lots of CPU when layers are changed */ managerLayersPanel = new JPanel(new BorderLayout()); JButton showLayers = new JButton(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ShowLayers")); //$NON-NLS-1$ showLayers.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { _managerLayersLegend = new IlvJMapLegend(); _managerLayersLegend.setLayerGlobalVisibilityMode(true); _managerLayersLegend.setView(view); managerLayersPanel.removeAll(); managerLayersPanel.add(_managerLayersLegend, BorderLayout.CENTER); managerLayersPanel.invalidate(); managerLayersPanel.validate(); } }); managerLayersPanel.add(showLayers, BorderLayout.CENTER); /** New Legend */ mapLayersLegend = new IlvMapLegendPanel(); /** coordinate system panel */ csMainPanel = new JPanel(new BorderLayout()); /** coordinate system editor */ csPanel = new IlvJCoordinateSystemEditorPanel(); csMainPanel.add(csPanel, BorderLayout.CENTER); // JV-3495 /** control of re projection */ JPanel delayedReprojectionPanel = new JPanel(); delayedReprojectionPanel .setBorder(new TitledBorder(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ReprojectPolicyTitle"))); //$NON-NLS-1$ final JCheckBox toggleAutomatic = new JCheckBox( IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ReprojectAutoLabel")); //$NON-NLS-1$ toggleAutomatic.setToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ReprojectAutoToolTip")); //$NON-NLS-1$ final JButton buttonNow = new JButton(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ReprojectNowLabel")); //$NON-NLS-1$ buttonNow.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { reprojectNow(csPanel.getCoordinateSystem(), IlvJCoordinateSystemEditorPanel.PROJECTION_CHANGED); } }); toggleAutomatic.setToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ReprojectNowTooltip")); //$NON-NLS-1$ toggleAutomatic.addChangeListener(new ChangeListener() { Override public void stateChanged(ChangeEvent e) { autoReprojection = toggleAutomatic.isSelected(); buttonNow.setEnabled(!autoReprojection); } }); toggleAutomatic.setSelected(true); delayedReprojectionPanel.add(toggleAutomatic); delayedReprojectionPanel.add(buttonNow); csMainPanel.add(delayedReprojectionPanel, BorderLayout.SOUTH); /** preference Editor panel */ prefsPanel = new IlvJDisplayPreferencesEditorPanel(); /** Symbol edition panel */ simpleSymbologyPanel = new JPanel(new BorderLayout()); /** Area of interest panel */ areaPanel = new IlvJAreaOfInterestPanel(view, true, true, true); // // CONTAINERS // -------------------------------------------------------------------- /** editor tabbed panes */ bottomLeftPanel = new AdvancedTabbedPane(); bottomRightPanel = new AdvancedTabbedPane(); topLeftPanel = new AdvancedTabbedPane(); /** panel containing the status */ statusPanel = new JPanel(); MySpringLayout springLayout = new MySpringLayout(); statusPanel.setLayout(springLayout); /** view scroll */ viewScroll = new IlvJScrollManagerView(view) { Override public String getToolTipText(MouseEvent event) { Point pt = SwingUtilities.convertPoint(this, event.getPoint(), view); // Find component located at point pt IlvGraphic o = view.getManager().getObject(new IlvPoint(pt.x, pt.y), view); if (o != null) { IlvFeatureAttributeProperty p = (IlvFeatureAttributeProperty) o.getNamedProperty(IlvAttributeProperty.NAME); if (p != null) { IlvStringAttribute att = null; try { att = (IlvStringAttribute) p.getValue(IlvMapAnnotationToolBar.EXT_ANNOTATION_PROPERTY_NAME); } catch (IllegalArgumentException e) { att = null; } if (att != null) { String v = att.getString(); if (v != null && !"".equals(v) && !"__null__".equals(v)) //$NON-NLS-1$ //$NON-NLS-2$ return getFormatedExtendedText(v); } } return getToolTip(o, pt); } return null; } }; /** left hand side panel */ leftSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topLeftPanel, bottomLeftPanel); leftSplitPane.setOneTouchExpandable(true); /** right hand side panel */ rightSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, viewScroll, bottomRightPanel); rightSplitPane.setOneTouchExpandable(true); new DragDropSupport(this); } /** * Return a HTML formated text when argument contains new lines. This method * is used when displaying tooltips. * * @param s * The string to format. * @return The HTML formated string. */ String getFormatedExtendedText(String s) { if (BasicHTML.isHTMLString(s)) return s; String sp[] = s.split("\n"); //$NON-NLS-1$ if (sp.length <= 1) return s; s = "<html> "; //$NON-NLS-1$ for (int i = 0; i < sp.length; i++) { if (i > 0) s += " <br> "; //$NON-NLS-1$ s += "\n" + sp[i]; //$NON-NLS-1$ } s += "\n </html> "; //$NON-NLS-1$ return s; } private void showAdditionalTooltips(boolean tipsOn) { if (tipsOn) { overview.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.OverviewTip"))); //$NON-NLS-1$ zoomer.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.InteractiveZoomTip"))); //$NON-NLS-1$ coordViewer.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.CoordinateViewerTip"))); //$NON-NLS-1$ graphicScale.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ScaleTip"))); //$NON-NLS-1$ compass.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.CompassTip"))); //$NON-NLS-1$ scaleControl.getScaleField() .setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ScaleControlTip"))); //$NON-NLS-1$ tripleBuffered.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.TripleBufferTip"))); //$NON-NLS-1$ antiAliased.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.AntiAliasingTip"))); //$NON-NLS-1$ showToolTips.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ShowToolTipsTip"))); //$NON-NLS-1$ showGUIToolTips .setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ShowGUIToolTipsTip"))); //$NON-NLS-1$ advancedProperties .setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.AdvancedPropertiesTip"))); //$NON-NLS-1$ optionMenu.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.OptionsTip"))); //$NON-NLS-1$ fileMenu.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.FileMenuTip"))); //$NON-NLS-1$ additionalViews .setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.AdditionalViewsTip"))); //$NON-NLS-1$ selectSystem.setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SelectSystemTip"))); //$NON-NLS-1$ tilingButton .setToolTipText(wrapToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ThinClientParametersTip"))); //$NON-NLS-1$ } else { overview.setToolTipText(null); zoomer.setToolTipText(null); coordViewer.setToolTipText(null); graphicScale.setToolTipText(null); compass.setToolTipText(null); scaleControl.getScaleField().setToolTipText(null); tripleBuffered.setToolTipText(null); antiAliased.setToolTipText(null); showToolTips.setToolTipText(null); showGUIToolTips.setToolTipText(null); advancedProperties.setToolTipText(null); optionMenu.setToolTipText(null); fileMenu.setToolTipText(null); additionalViews.setToolTipText(null); selectSystem.setToolTipText(null); } } private IlvMapPrintingController controller; private IlvPrintAreaInteractor printAreaInteractor; /** * @return the printing controller */ public IlvMapPrintingController getPrintingController() { if (controller == null) { // Creates the printing controller controller = new IlvMapPrintingController(view); // final IlvManagerPrintingController controller = new // IlvManagerPrintingController(view); // Initializes the document with some parameters. final IlvPrintableDocument document = controller.getDocument(); document.setName(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.PrintDocumentName")); //$NON-NLS-1$ // JV-1782 document.setAuthor(controller.getPrinterJob().getUserName()); // JV-1783 document.setPageFormat(controller.getDefaultPageFormat()); } return controller; } private Component getTopComponent() { Container parent = BaseDemo.this; while ((parent = parent.getParent()) != null) { if (parent instanceof Frame) return parent; } return null; } /** * Listens to the contents of the attached manager and invalidates the triple * buffer if it is necessary. It is not the most efficient way to invalidate * the triple buffer. It does not work all the time, do not know why yet. Need * more time to investigate. */ private ManagerContentChangedListener managerContentListener = new ManagerContentChangedListener() { Override public void contentsChanged(ManagerContentChangedEvent evt) { if (!evt.isAdjusting()) { view.invalidateTripleBuffer(false); overview.getOverviewView().invalidateTripleBuffer(false); } } }; /** * Creates a Base Frame to display maps. */ public BaseDemo() { super(); // Make sure the swing construction is called in Swing event thread. ilog.views.util.swing.IlvSwingUtil.invokeAndWait(new Runnable() { Override public void run() { createBeans(); setJMenuBar(new JMenuBar()); IlvUtil.SetDeltaLine(10);// increase the selection margin on lines. new IlvMapPanInteractor().setView(view); view.setSize(new Dimension(900, 450)); view.setKeepingAspectRatio(true); // view.setOptimizedTranslation(false); view.setBackground(new Color(80, 180, 240)); view.setAntialiasing(false); // IlvToolTipManager.registerView(view); overview.setBackground(view.getBackground()); overview.setDrawingStyle(IlvManagerMagViewInteractor.Wire); overview.setResizingAllowed(true); overview.setSize(200, 100); overview.setPreferredSize(overview.getSize()); overview.setMinimumSize(overview.getSize()); overview.setView(view); overview.getOverviewView().setRepaintSkipThreshold(500); overview.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED)); csPanel.addCoordinateSystemChangeListener(BaseDemo.this); csPanel.setAdvancedPanelsVisible(false); // prefPanel = new JPanel(new BorderLayout()); // prefsPanel.setBorder(BorderFactory.createTitledBorder(IlvMapUtil.getString(BaseDemo.class, // "BaseDemo.Preferences"))); //$NON-NLS-1$ // prefPanel.add(prefsPanel, BorderLayout.SOUTH); // prefPanel.add(csPanel, BorderLayout.NORTH); prefsPanel.addDisplayPreferencesChangeListener(prefChangeListener); view.getManager().setNamedProperty(new IlvCoordinateSystemProperty(IlvGeographicCoordinateSystem.WGS84)); IlvMapScaleLimiter limiter = new IlvMapScaleLimiter(1, (1 / 1E9)); limiter.setView(view); layerTreePanel.setView(view); // listen to layer selection layerTreePanel.getLayerTree().addTreeSelectionListener(new TreeSelectionListener() { Override public void valueChanged(TreeSelectionEvent e) { zoomToLayer.setEnabled(e.getNewLeadSelectionPath() != null); miZoomToLayer.setEnabled(e.getNewLeadSelectionPath() != null); } }); // listen to object selection view.getManager().addManagerSelectionListener(new ManagerSelectionListener() { Override public void selectionChanged(ManagerSelectionChangedEvent event) { // JV-1830 if (!event.isAdjusting() || event.isAdjustmentEnd()) { miZoomToObject.setEnabled(event.getManager().getSelectedObjectsCount() != 0); miRemoveObject.setEnabled(event.getManager().getSelectedObjectsCount() != 0); miCenterOnObject.setEnabled(event.getManager().getSelectedObjectsCount() != 0); } } }); layerTree = layerTreePanel.getLayerTree(); mapLayersLegend.setView(view); dataSourcePanel.setManager(view.getManager()); zoomer.setOrientation(SwingConstants.VERTICAL); zoomer.setView(view); zoomer.setZoomDelay(10); zoomer.setPreferredSize(new Dimension(zoomer.getPreferredSize().width, 100)); coordViewer.setHtmlTableProperties("border=1 cellpadding=0 cellspacing=0 "); //$NON-NLS-1$ coordViewer.setBackground(Color.white); coordViewer.setOpaque(true); coordViewer.setFont(new Font("Monospaced", Font.BOLD, 14)); //$NON-NLS-1$ coordViewer.setView(view); graphicScale.setView(view); // JV-3360 graphicScale.setScaleComputation(new IlvMapScaleComputation(IlvConstants.BOTTOM, true)); compass.setView(view); graphicScale.setMarginHeight(0); scaleControl.setView(view); statusPanel.add(coordViewer/* , BorderLayout.LINE_START */); scalePanel = new JPanel(new BorderLayout(2, 0)); scalePanel.add(graphicScale, BorderLayout.CENTER); scalePanel.add(scaleControl, BorderLayout.LINE_END); statusPanel.add(scalePanel/* , BorderLayout.CENTER */); // statusPanel.add(compass); IlvThreadedActivityMonitor mon = IlvThreadedActivityMonitorProperty .GetThreadedActivityMonitor(view.getManager()); monitorPanel = new IlvThreadedActivityMonitorPanel(mon); statusPanel.add(monitorPanel/* , BorderLayout.LINE_END */); viewScroll.setPreferredSize(view.getSize()); toolbar.setView(view); tripleBuffered = new MBCheckBoxMenuItem("BaseDemo.TripleBuffer", false); //$NON-NLS-1$ tripleBuffered.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { if (tripleBuffered.isSelected()) { int count = view.getManager().getLayersCount(); view.setTripleBufferedLayerCount(count); view.invalidateTripleBuffer(true); // Activates also the triple buffer in the overview: overview.getOverviewView().setTripleBufferedLayerCount(count); overview.getOverviewView().invalidateTripleBuffer(true); view.getManager().addManagerContentChangedListener(managerContentListener); } else { view.setTripleBufferedLayerCount(0); view.repaint(); // Removes also the triple buffer in the overview: overview.getOverviewView().setTripleBufferedLayerCount(0); overview.getOverviewView().repaint(); view.getManager().removeManagerContentChangedListener(managerContentListener); } } }); antiAliased = new MBCheckBoxMenuItem("BaseDemo.AntiAliasing", false); //$NON-NLS-1$ antiAliased.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { /* * IlvMapLabelManager labelManager=null; IlvMapLabeler labeler = * IlvMapLabelerProperty.GetMapLabeler(view.getManager()); if * (labeler instanceof IlvMapDefaultLabeler) { * labelManager=((IlvMapDefaultLabeler)labeler).getLabelManager(); } */ if (antiAliased.isSelected()) { view.setAntialiasing(true); overview.getOverviewView().setAntialiasing(true); /* * uncomment this to also force antialias for labels. * if(labelManager!=null) { * labelManager.setForceLabelAntialiasing(true); } */ } else { view.setAntialiasing(false); overview.getOverviewView().setAntialiasing(false); /* * uncomment this to also remove antialias for labels. * if(labelManager!=null) { * labelManager.setForceLabelAntialiasing(false); } */ } // view.getManager().reDraw(); view.repaint(); overview.repaint(); } }); showToolTips = new MBCheckBoxMenuItem("BaseDemo.ShowToolTips", false); //$NON-NLS-1$ showToolTips.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { if (showToolTips.isSelected()) { IlvToolTipManager.registerView(view); } else { IlvToolTipManager.unregisterView(view); } } }); showGUIToolTips = new MBCheckBoxMenuItem("BaseDemo.ShowGUIToolTips", true); //$NON-NLS-1$ showGUIToolTips.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { showAdditionalTooltips(showGUIToolTips.isSelected()); } }); advancedProperties = new MBCheckBoxMenuItem("BaseDemo.AdvancedProperties", //$NON-NLS-1$ IlvMapStyleBeanInfo.isAdvancedMode()); advancedProperties.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { int sel[] = layerTreePanel.getLayerTree().getSelectionRows(); IlvMapStyleBeanInfo.setAdvancedMode(advancedProperties.isSelected()); layerTreePanel.getLayerTree().setSelectionRow(-1); layerTreePanel.getLayerTree().setSelectionRows(sel); } }); exportBtn.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { if (exportDialog == null) exportDialog = makeExportDialog(view); exportDialog.setVisible(true); } }); tilingButton.addActionListener(new ThinClientParametersPanel(view)); printButton.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { if (printDialog == null) { printDialog = new JDialog(); printDialog.getContentPane().add(printPanel); } printDialog.pack(); JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, BaseDemo.this); if (frame != null) { Dimension fSize = frame.getSize(); Point fLoc = frame.getLocation(); Dimension jSize = printDialog.getSize(); int x = (fSize.width - jSize.width) / 2 + fLoc.x; int y = (fSize.height - jSize.height) / 2 + fLoc.y; if (x < 0) x = 0; if (y < 0) y = 0; printDialog.setLocation(x, y); } printDialog.setVisible(true); } }); /* * generateTilesButton.addActionListener(new ActionListener() { public * void actionPerformed(ActionEvent e) { if(generateTiles == null) * generateTiles = new TileGenerator(view); * generateTiles.setVisible(true); } }); */ if (splashWindow != null) { splashWindow.showMessage(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SplashCreatingMenus"));//$NON-NLS-1$ } optionMenu = new JMenu(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.Options")); //$NON-NLS-1$ optionMenu.add(showGUIToolTips); optionMenu.add(showToolTips); optionMenu.add(advancedProperties); optionMenu.add(antiAliased); optionMenu.add(tripleBuffered); optionMenu.add(tilingButton); // optionMenu.add(generateTilesButton); fileMenu = new JMenu(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.FileMenu")); //$NON-NLS-1$ getJMenuBar().add(fileMenu); getJMenuBar().add(optionMenu); optionMenu.setMnemonic('o'); fileMenu.setMnemonic('f'); helpMenu = new JMenu(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.Help.Menu")); //$NON-NLS-1$ about.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { String iconFile = IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SplashIconURL"); //$NON-NLS-1$ JFrame f = new JFrame(); final SplashWindow tempSplash = new SplashWindow(f, findURL(iconFile)); f.setBounds(BaseDemo.this.getBounds()); String click = IlvMapUtil.getString(BaseDemo.class, "BaseDemo.About.ClickToClose"); //$NON-NLS-1$ tempSplash.showMessage(click); tempSplash.addMouseListener(new MouseAdapter() { Override public void mouseClicked(MouseEvent evt) { tempSplash.setVisible(false); tempSplash.dispose(); } }); Image i = tempSplash.getImage(); tempSplash.setSize(i.getWidth(null), i.getHeight(null)); placeDialog(tempSplash); tempSplash.setVisible(true); } void placeDialog(Component j) { Component top = getTopComponent(); if (top == null) return; Dimension fSize = top.getSize(); Point fLoc = getTopComponent().getLocation(); Dimension jSize = j.getSize(); int x = (fSize.width - jSize.width) / 2 + fLoc.x; int y = (fSize.height - jSize.height) / 2 + fLoc.y; if (x < 0) x = 0; if (y < 0) y = 0; j.setLocation(x, y); } }); helpMenu.add(about); mapBuilder.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { boolean popped = false; try { String doc = IlvMapUtil.getString(BaseDemo.class, "BaseDemo.Help.Documentation"); //$NON-NLS-1$ // JV-3825 if (nodefense.App6aDefLess.isAvailable()) { doc = IlvMapUtil.getString(BaseDemo.class, "BaseDemo.Help.DocumentationDefense"); //$NON-NLS-1$ } try { URL url = new URL(doc); IlvPopUserBrowser.pop(url); popped = true; } catch (MalformedURLException e1) { File f = new File(doc); boolean exists; try { exists = f.exists(); if (exists) { IlvPopUserBrowser.pop(f); popped = true; } } catch (SecurityException e2) { // } } } catch (Exception e1) { e1.printStackTrace(); } if (!popped) { String msg = IlvMapUtil.getString(BaseDemo.class, "BaseDemo.Help.DocumentationNotFound"); //$NON-NLS-1$ JLabel label = new JLabel(msg); String title = IlvMapUtil.getString(BaseDemo.class, "BaseDemo.Help.DocumentationNotFoundTitle"); //$NON-NLS-1$ JOptionPane.showMessageDialog(getView(), label, title, JOptionPane.ERROR_MESSAGE); } } }); helpMenu.add(mapBuilder); getJMenuBar().add(helpMenu); additionalViews = new MBMenuItem("BaseDemo.AdditionalViews", true); //$NON-NLS-1$ additionalViews.addActionListener(new ActionListener() { void placeDialog(JDialog j, Frame frame) { Dimension fSize = frame.getSize(); Point fLoc = frame.getLocation(); Dimension jSize = j.getSize(); int x = (fSize.width - jSize.width) / 2 + fLoc.x; int y = (fSize.height - jSize.height) / 2 + fLoc.y; if (x < 0) x = 0; if (y < 0) y = 0; j.setLocation(x, y); } Override public void actionPerformed(ActionEvent e) { if (additionalViewDialog == null) { Component c = getTopComponent(); Frame frame = null; if (c instanceof Frame) frame = (Frame) c; additionalViewDialog = new JDialog(frame); additionalViewDialog.setTitle(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.AdditionalViewsTitle")); //$NON-NLS-1$ JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); // JV-4674 panel.setToolTipText(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.AdditionalViewsLabel"));//$NON-NLS-1$ panel.add(getAdditionalViewsPanel(), BorderLayout.CENTER); JPanel buttons = new JPanel(); JButton b = new JButton(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.CloseAdditionalViewDialog")); //$NON-NLS-1$ b.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent evt) { additionalViewDialog.setVisible(false); } }); buttons.add(b); panel.add(buttons, BorderLayout.SOUTH); additionalViewDialog.getContentPane().add(panel); additionalViewDialog.pack(); additionalViewDialog.setSize(600, 400); placeDialog(additionalViewDialog, frame); } additionalViewDialog.setVisible(true); } }); selectSystem = new MBMenuItem("BaseDemo.SelectSystem", true); //$NON-NLS-1$ selectSystem.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { if (csdialog == null) { csdialog = new CoordinateSystemDictionaryManager(); } csdialog.setVisible(true); IlvCoordinateSystem cs = csdialog.getSelectedCoordinateSystem(); if (cs != null) { boolean oldAuto = autoReprojection; autoReprojection = true;// force projection in this case csPanel.setCoordinateSystem(cs); autoReprojection = oldAuto; } } }); optionMenu.add(selectSystem); optionMenu.add(additionalViews); printPanel = makePrintPanel(); continuousZoomer = new IlvContinuousZoomInteractor(); continuousZoomer.setPermanent(true); zoomConfigPanel = makeZoomConfigPanel(); zoomConfigPanel.addPropertyChangeListener(new PropertyChangeListener() { Override public void propertyChange(PropertyChangeEvent evt) { String p = evt.getPropertyName(); if (p == ZoomConfigurationPanel.ZOOM_FACTOR) { double f = ((Double) evt.getNewValue()).doubleValue(); zoomer.setMaxZoomingRatio(f); continuousZoomer.setContinuousZoomFactor(f); } else if (p == ZoomConfigurationPanel.PERIOD) { int period = ((Integer) evt.getNewValue()).intValue(); zoomer.setZoomDelay(period); continuousZoomer.setPeriod(period); } } }); zoomConfigPanel.setPeriod(zoomer.getZoomDelay()); zoomConfigPanel.setContinuousZoomFactor(zoomer.getMaxZoomingRatio()); viewPopupMenu.add(miSelectObject); viewPopupMenu.add(miEditDataObject); viewPopupMenu.add(miRemoveObject); miRemoveObject.setEnabled(false); viewPopupMenu.add(new JSeparator()); ActionListener zoomToLayerListener = new ActionListener() { Override public void actionPerformed(ActionEvent e) { IlvManagerView.FitAreaCalculator f = new IlvManagerView.FitAreaCalculator() { Override public IlvRect getAreaToFit(IlvManagerView fittedView) { IlvMapLayer ml = layerTreePanel.getSelectedLayer(); List<IlvManagerLayer> v = Arrays.asList(ml.getManagerLayers()); IlvRect bounds = null; for (int i = 0; i < v.size(); i++) { IlvManagerLayer l = (IlvManagerLayer) v.get(i); IlvRect obounds = l.computeBBox(fittedView.getTransformer()); if (obounds != null && !obounds.isEmpty()) // computeBBox // returns // new IlvRect() if // not // visible => point // 0, // 0, always // included if (bounds == null) { bounds = obounds; } else { bounds.add(obounds); } } return bounds == null ? new IlvRect() : bounds; } }; view.fitTransformerToArea(new Insets(0, 0, 0, 0), f, 4); viewScroll.adjustScrollBars(); view.repaint(); } }; toolbar.add(zoomToLayer); zoomToLayer.setEnabled(false); zoomToLayer.addActionListener(zoomToLayerListener); viewPopupMenu.add(miZoomToLayer); miZoomToLayer.setEnabled(false); miZoomToLayer.addActionListener(zoomToLayerListener); miSelectObject.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { // get the object under mouse IlvGraphic obj = view.getManager().getObject(new IlvPoint(lastPopupLocation.x, lastPopupLocation.y), view); // select it if (obj != null) { view.getManager().deSelectAll(false); view.getManager().setSelected(obj, true, true); } } }); miEditDataObject.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { // get the object under mouse IlvGraphic obj = view.getManager().getObject(new IlvPoint(lastPopupLocation.x, lastPopupLocation.y), view); // select it if (obj != null) { IlvNamedProperty p = obj.getNamedProperty(IlvAttributeProperty.NAME); if (p != null) { IlvAttributeProperty copy = (IlvAttributeProperty) p.copy(); JTable table = new JTable(new TableAttributeModel(copy)); int ans = JOptionPane.showConfirmDialog(view, new JScrollPane(table), IlvMapUtil.getString(BaseDemo.class, "BaseDemo.EditObjectDataTitle"), //$NON-NLS-1$ JOptionPane.OK_CANCEL_OPTION); if (ans == JOptionPane.OK_OPTION) { obj.setNamedProperty(copy); IlvMapLayer ml = IlvMapLayer.get(obj); if (ml != null) { IlvMapDataSource ds = findDataSource(ml); if (ds instanceof IlvGraphicLayerDataSource) { setModified(true); } else if (ds != null) { ds.setForceUsingBackupDataSource(true); ds.setSaveBackupDataSources(true); setModified(true); } } } } else { // JV-3840 if (engine != null) { Object node = engine.getObject(obj); if (node != null) {// is that a symbol ? if (symbologyManager != null) { // edit it (it is already selected) symbologyManager.getSymbologyTreePanel().performEdit(); } } } } } } }); miRemoveObject.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { IlvGraphicEnumeration en = view.getManager().getSelectedObjects(); if (en.hasMoreElements()) { int ans = JOptionPane.showConfirmDialog(view, IlvMapUtil.getString(BaseDemo.class, "BaseDemo.RemoveObjectMessage"), //$NON-NLS-1$ IlvMapUtil.getString(BaseDemo.class, "BaseDemo.RemoveObjectTitle"), //$NON-NLS-1$ JOptionPane.OK_CANCEL_OPTION); if (ans == JOptionPane.OK_OPTION) { if (removeSelection(view.getManager())) { setModified(true); } } } } }); ActionListener zoomToObjectListener = new ActionListener() { Override public void actionPerformed(ActionEvent e) { IlvManagerView.FitAreaCalculator f = new IlvManagerView.FitAreaCalculator() { Override public IlvRect getAreaToFit(IlvManagerView fittedView) { IlvRect bounds = null; IlvGraphicEnumeration en = view.getManager().getSelectedObjects(); if (en != null) { while (en.hasMoreElements()) { IlvGraphic g = en.nextElement(); IlvRect obounds = g.boundingBox(fittedView.getTransformer()); if (bounds == null) { bounds = obounds; } else { bounds.add(obounds); } } } return bounds; } }; view.fitTransformerToArea(new Insets(0, 0, 0, 0), f, 4); viewScroll.adjustScrollBars(); view.repaint(); } }; ActionListener centerOnObjectListener = new ActionListener() { Override public void actionPerformed(ActionEvent e) { IlvRect bounds = null; IlvGraphicEnumeration en = view.getManager().getSelectedObjects(); if (en != null) { while (en.hasMoreElements()) { IlvGraphic g = en.nextElement(); IlvRect obounds = g.boundingBox(); if (bounds == null) { bounds = obounds; } else { bounds.add(obounds); } } } if (bounds != null) { IlvPoint c = new IlvPoint(bounds.getCenterX(), bounds.getCenterY()); IlvTransformer t = view.getTransformer(); t.apply(c); t.translate(view.getWidth() / 2 - c.x, view.getHeight() / 2 - c.y); view.setTransformer(t); // JV-1830 viewScroll.adjustScrollBars(); view.repaint(); } } }; viewPopupMenu.add(miCenterOnObject); miCenterOnObject.setEnabled(false); miCenterOnObject.addActionListener(centerOnObjectListener); viewPopupMenu.add(miZoomToObject); miZoomToObject.setEnabled(false); miZoomToObject.addActionListener(zoomToObjectListener); viewPopupMenu.add(new JSeparator()); viewPopupMenu.add(miCancel); seeThrough = new IlvSeeThroughInteractor(); seeThrough.setPermanent(true); MBToggleButton seeThroughButton = installInteractorButton("BaseDemo.SeeThroughInteractor", seeThrough, -1); //$NON-NLS-1$ addConfigurationPanel(seeThroughButton, IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SeeThroughConfig"), //$NON-NLS-1$ new IlvSeeThroughConfigurationPanel(getView().getManager(), seeThrough), seeThrough); centerInteractorBtn = installInteractorButton("BaseDemo.CenterInteractor", new CenterInteractor(csPanel), -1); //$NON-NLS-1$ centerInteractorBtn.setEnabled(false); JComboBox<?> projList = csPanel.getProjectionList(); Container projListContainer = projList.getParent(); GridBagConstraints c = new GridBagConstraints(); c.gridy = 1; c.gridwidth = GridBagConstraints.REMAINDER; projListContainer.add(centerInteractorBtn, c); toolbar.add(new JLabel(" - ")); //$NON-NLS-1$ installInteractorButton("BaseDemo.MeasureInteractor", new IlvMakeMeasureInteractor(), -1); //$NON-NLS-1$ installInteractorButton("BaseDemo.SymbolMagnifyInteractor", InteractorsDefLess.newIlvMagnifySymbolsInteractor(), //$NON-NLS-1$ -1); toolbar.add(new JLabel(" - ")); //$NON-NLS-1$ // new IlvMakeLineOfVisibilityInteractor(bottomRightPanel)); final IlvManagerViewInteractor lineOfVisibilityInter = InteractorsDefLess .newIlvMakeLineOfVisibilityInteractor(bottomRightPanel); MBToggleButton lovButton = installInteractorButton("BaseDemo.LineOfVisibilityInteractor", //$NON-NLS-1$ lineOfVisibilityInter, -1); if (lineOfVisibilityInter != null) new SelectObjectAndSetSelectInteractor((IlvMakePolyPointsInteractor) lineOfVisibilityInter); MBToggleButton gradButton = installInteractorButton("BaseDemo.GradientInteractor", //$NON-NLS-1$ InteractorsDefLess.newIlvMakeGradientInteractor(), -1); MBToggleButton valleyButton = installInteractorButton("BaseDemo.ValleyInteractor", //$NON-NLS-1$ InteractorsDefLess.newIlvMakeValleyInteractor(), -1); MBToggleButton lakeButton = installInteractorButton("BaseDemo.LakeInteractor", //$NON-NLS-1$ InteractorsDefLess.newIlvMakeAreaOfSightInteractor(), -1); IlvManagerViewInteractor terrainCutInter = InteractorsDefLess.newIlvMakeTerrainCutInteractor(bottomRightPanel); JToggleButton terrainCutButton = installInteractorButton("BaseDemo.TerrainCutInteractor", //$NON-NLS-1$ terrainCutInter, -1); if (terrainCutInter != null) new SelectObjectAndSetSelectInteractor((IlvMakePolyPointsInteractor) terrainCutInter); JToggleButton v3dButton = installInteractorButton("BaseDemo.3DViewInteractor", //$NON-NLS-1$ InteractorsDefLess.newIlvMake3DViewInteractor(bottomRightPanel), -1); InteractorsDefLess.RegisterAccessoryComponent(bottomRightPanel, view.getManager()); JToggleButton ftButton = installInteractorButton("BaseDemo.3DFlyThroughInteractor", //$NON-NLS-1$ InteractorsDefLess.newIlvMake3DFlyThroughInteractor(), -1); listenForTerrainData(new JToggleButton[] { lovButton, gradButton, valleyButton, lakeButton, terrainCutButton, v3dButton, ftButton }); setupPopupMenu(); // Add a popup menu to split layers new SourceSplitter(layerTreePanel.getLayerTree()); // Add a popup menu to simplify layers new SourceSimplifier(layerTreePanel.getLayerTree()); // JV-4998 - customer wish // Add a popup menu to reload layers new SourceReloader(layerTreePanel.getLayerTree()); new AttributeStyler(layerTreePanel.getLayerTree()); toolbar.add(new JLabel(" - ")); //$NON-NLS-1$ annotations = new IlvMapAnnotationToolBar(); annotations.setView(getView()); annotations.setGrapherMode(true); // place all annotation toolbar buttons in the regular toolbar (to // prevent // embedded toolbar offset) Component btns[] = annotations.getComponents(); for (int i = 0; i < btns.length; i++) { toolbar.add(btns[i]); } // setup advanced panel advancedPanel = new JPanel(new GridLayout(0, 1)); final JCheckBox repaintSkipped = new JCheckBox(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.RepaintSkipped"), //$NON-NLS-1$ true); repaintSkipped.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { if (repaintSkipped.isSelected()) { overview.getOverviewView().setRepaintSkipThreshold(500); } else { overview.getOverviewView().setRepaintSkipThreshold(0); } } }); advancedPanel.add(repaintSkipped); TileCacheManager tcm = new TileCacheManager(view.getManager()); JPanel p1 = new JPanel(new BorderLayout()); p1.add(tcm.getPolicyChoiceCombo(), BorderLayout.CENTER); p1.add(tcm.getTileCacheCountSpinner(), BorderLayout.LINE_END); advancedPanel.add(p1); TileDebugManager tdm = makeTileDebugManager(view); if (tdm != null) advancedPanel.add(tdm.getDebugCheckbox()); GCManager gcManager = new GCManager(); advancedPanel.add(gcManager.getActivationCheckBox()); advancedPanel.add(gcManager.getMemoryInformationLabel()); /* allow to change the component orientation */ final ComponentOrientation vdirections[] = { ComponentOrientation.UNKNOWN, ComponentOrientation.LEFT_TO_RIGHT, ComponentOrientation.RIGHT_TO_LEFT }; String sdirections[] = { IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ComponentOrientationUnknown"), //$NON-NLS-1$ IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ComponentOrientationLTR"), //$NON-NLS-1$ IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ComponentOrientationRTL")//$NON-NLS-1$ }; JLabel labeldir = new JLabel(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ComponentOrientation"));//$NON-NLS-1$ final JComboBox<String> combodir = new JComboBox<String>(sdirections); combodir.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { int ico = combodir.getSelectedIndex(); IlvSwingUtil.updateComponentTreeOrientation(BaseDemo.this, vdirections[ico]); } }); JPanel p2 = new JPanel(new BorderLayout()); p2.add(labeldir, BorderLayout.CENTER); p2.add(combodir, BorderLayout.LINE_END); advancedPanel.add(p2); /* * uncomment this if you want to add a performance bench for your map: * it displays the view 200 times and displays the time necessary. final * JButton bench=new JButton("Bench"); bench.addActionListener(new * ActionListener() { * * public void actionPerformed(ActionEvent e) { long * t0=System.currentTimeMillis(); for (int i = 0; i < 200; i++) { * Graphics g=view.getGraphics(); g.setClip(null); * view.paint(view.getGraphics()); } * bench.setText("Bench "+(System.currentTimeMillis()-t0)); } }); * * advancedPanel.add(bench); */ final JLabel fpsLabel = new JLabel(); Timer tfps = new Timer(1000, new ActionListener() { long lastTime; Override public void actionPerformed(ActionEvent e) { if (lastTime != 0) { long time = System.currentTimeMillis(); double dt = (time - lastTime) / 1000.0; double realFPS = fps / dt; fpsLabel.setText((int) realFPS + IlvMapUtil.getString(BaseDemo.class, "BaseDemo.FPS")); //$NON-NLS-1$ } lastTime = System.currentTimeMillis(); fps = 0; } }); tfps.start(); advancedPanel.add(fpsLabel, BorderLayout.NORTH); saveAsBtn.addActionListener(new IvlFileManager.SaveIvlActionListener(BaseDemo.this, false)); saveBtn.addActionListener(new IvlFileManager.SaveIvlActionListener(BaseDemo.this, true)); saveBtn.setEnabled(false); loadBtn.addActionListener(new IvlFileManager.LoadIvlActionListener(BaseDemo.this)); clearBtn.addActionListener(new IvlFileManager.ClearManagerActionListener(BaseDemo.this, view)); exitBtn.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { exitApplication(); } }); fileMenu.add(clearBtn); fileMenu.add(loadBtn); fileMenu.add(saveBtn); fileMenu.add(saveAsBtn); fileMenu.add(exportBtn); // fileMenu.add(printButton); fileMenu.add(new JSeparator()); fileMenu.add(lastFilesMenu); fileMenu.add(new JSeparator()); fileMenu.add(exitBtn); JPanel pPanel = new JPanel(); pPanel.add(advancedPanel, BorderLayout.NORTH); advancedPanel = pPanel; gridPanel = new JPanel(new GridLayout(0, 1)); gridManager = new GridManager(view); gridPanel.add(gridManager.getGridChoice()); gridPanel.add(gridManager.getDelayedCheckBox()); pPanel = new JPanel(); pPanel.add(gridPanel, BorderLayout.LINE_START); gridPanel = pPanel; toolbar.setOrientation(SwingConstants.HORIZONTAL); toolbar.setFloatable(false); overviewAndZoomPanel = new JPanel(new BorderLayout()); overviewAndZoomPanel.add(overview, BorderLayout.CENTER); overviewAndZoomPanel.add(zoomer, BorderLayout.LINE_END); leftSplitPane.setResizeWeight(0); view.setWheelZoomingEnabled(true); viewScroll.setWheelScrollingEnabled(true); rightSplitPane.setResizeWeight(1); if (splashWindow != null) { splashWindow.showMessage(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SplashBuildingViews"));//$NON-NLS-1$ } initViews(); loadPreferences(); pPanel = new JPanel(new BorderLayout()); pPanel.add(toolbar, BorderLayout.NORTH); pPanel.add(rightSplitPane, BorderLayout.CENTER); mainSplit = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftSplitPane, pPanel); mainSplit.setOneTouchExpandable(true); getContentPane().add(mainSplit, BorderLayout.CENTER); coordViewer.addPropertyChangeListener(new PropertyChangeListener() { Override public void propertyChange(PropertyChangeEvent evt) { if ("text".equals(evt.getPropertyName())) { //$NON-NLS-1$ Dimension p = coordViewer.getPreferredSize(); Dimension m = coordViewer.getMaximumSize(); if (p.width != m.width) { coordViewer.setMaximumSize(p); coordViewer.getParent().invalidate(); } } } }); monitorPanel.setMaximumSize(monitorPanel.getPreferredSize()); coordViewer.setMaximumSize(coordViewer.getPreferredSize()); SpringLayout layout = (SpringLayout) statusPanel.getLayout(); layout.putConstraint(SpringLayout.WEST, coordViewer, 0, SpringLayout.WEST, statusPanel); layout.putConstraint(SpringLayout.NORTH, coordViewer, 0, SpringLayout.NORTH, statusPanel); layout.putConstraint(SpringLayout.WEST, scalePanel, 2, SpringLayout.EAST, coordViewer); layout.putConstraint(SpringLayout.NORTH, scalePanel, 2, SpringLayout.NORTH, statusPanel); // layout.putConstraint(SpringLayout.WEST, compass, 2, // SpringLayout.EAST, // scalePanel); // layout.putConstraint(SpringLayout.NORTH, compass, 2, // SpringLayout.NORTH, // statusPanel); // layout.putConstraint(SpringLayout.WEST, monitorPanel, 2, // SpringLayout.EAST, compass); // layout.putConstraint(SpringLayout.NORTH, monitorPanel, 2, // SpringLayout.NORTH, compass); layout.putConstraint(SpringLayout.WEST, monitorPanel, 2, SpringLayout.EAST, scalePanel); layout.putConstraint(SpringLayout.NORTH, monitorPanel, 2, SpringLayout.NORTH, statusPanel); layout.putConstraint(SpringLayout.EAST, statusPanel, 2, SpringLayout.EAST, monitorPanel); layout.putConstraint(SpringLayout.SOUTH, statusPanel, 2, SpringLayout.SOUTH, monitorPanel); getContentPane().add(statusPanel, BorderLayout.SOUTH); symbologyManager = new SymbologyManager(view, getSymbolStyleSheetURL()); JPanel symbologyView = symbologyManager.getSymbologyTreePanel(); if (symbologyView != null) { simpleSymbologyPanel.add(symbologyView); } else { if (simpleSymbologyPanel.getParent() != null) { simpleSymbologyPanel.getParent().remove(simpleSymbologyPanel); } } engine = symbologyManager.getEngine(); view.getManager().setSelectionFactory(new IlvMapSelectionFactory()); view.addKeyListener(new PopInteractorKeyListener()); showAdditionalTooltips(true); } void addConfigurationPanel(final MBToggleButton button, final String title, final JPanel panel, final IlvManagerViewInteractor inter) { final int smallSize = 9; final JButton smallButton = new JButton() { Override public void paint(Graphics g) { super.paint(g); g.drawLine(smallSize / 2, 2, smallSize / 2, smallSize - 3); g.drawLine(2, smallSize / 2, smallSize - 3, smallSize / 2); } Override public Color getBackground() { Color c = super.getBackground(); if (c == null) return c; Color ret = new Color(c.getRed(), c.getGreen(), c.getBlue(), 100); return ret; } }; Dimension small = new Dimension(smallSize, smallSize); smallButton.setSize(small); button.add(smallButton); button.setLayout(new OverlayLayout(button) { Dimension buttonDim = new Dimension(26, 26); Override public void layoutContainer(Container target) { smallButton.setLocation(target.getWidth() - smallSize - 1, target.getHeight() - smallSize - 1); } Override public Dimension maximumLayoutSize(Container target) { return buttonDim; } Override public Dimension minimumLayoutSize(Container target) { return buttonDim; } Override public Dimension preferredLayoutSize(Container target) { return buttonDim; } }); smallButton.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { JOptionPane pane = new JOptionPane(); pane.setMessage(panel); JDialog dialog = pane.createDialog(getView(), title); dialog.setResizable(true); if (panel instanceof IlvSeeThroughConfigurationPanel) // TODO ((IlvSeeThroughConfigurationPanel) panel).update(); Point p = new Point(); SwingUtilities.convertPointToScreen(p, smallButton); dialog.setLocation(p); dialog.setVisible(true); Object selectedValue = pane.getValue(); if (selectedValue == null) return; if (selectedValue instanceof Integer) { int i = ((Integer) selectedValue).intValue(); if (i == JOptionPane.OK_OPTION) getView().setInteractor(inter); } } }); } });// event thread runnable } /** * Sets up a listener to show the popup menu. */ protected void setupPopupMenu() { view.addMouseListener(new MouseAdapter() { Override public void mousePressed(MouseEvent e) { showMenu(e); } Override public void mouseReleased(MouseEvent e) { showMenu(e); } private void showMenu(MouseEvent e) { if (e.isPopupTrigger()) { lastPopupLocation.setLocation(e.getX(), e.getY()); SwingUtilities.invokeLater(new Runnable() { Override public void run() { if (view.getInteractor() instanceof IlvManagerViewRotateInteractor) { return;// right click should cancel rotation only. } IlvGraphic obj = view.getManager().getObject(new IlvPoint(lastPopupLocation.x, lastPopupLocation.y), view); if (obj != null) { if (obj.getPopupMenu() == null && obj.getPopupMenuName() == null) { miSelectObject.setEnabled(obj.isSelectable() && !view.getManager().isSelected(obj)); viewPopupMenu.show(view, (int) lastPopupLocation.getX(), (int) lastPopupLocation.getY()); } } } }); } } }); } /** * Returns the URL of a CSS stylesheet used to display APP6 symbols. * * @return Returns the URL of a CSS stylesheet used to display APP6 symbols. */ protected String getSymbolStyleSheetURL() { return IlvMapUtil.getString(SymbologyManager.class, "SymbologyManager.App6CssURL"); //$NON-NLS-1$ } /** * disable those buttons if there is no terrain data. * * @param buttons */ private void listenForTerrainData(final JToggleButton[] buttons) { for (int i = 0; i < buttons.length; i++) { if (!buttons[i].isEnabled()) {// do not enable already disabled buttons buttons[i] = null; } } /* TerrainButtonsDisabler disabler= */new TerrainButtonsDisabler(view, buttons); } /** * Hides the splash screen and loads data. * * @see java.awt.Frame#addNotify() */ Override public void addNotify() { if (splashWindow != null) { splashWindow.showMessage(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SplashLoadingData"));//$NON-NLS-1$ } loadInitialData(); super.addNotify(); if (splashWindow != null) { splashWindow.stop(); splashWindow = null; } } /** * Computes the lat/lon of the point on the map. * * @param point * location of the mouse on the view. * @return the lat/lon coordinates in radians, or null. */ protected IlvCoordinate computeCoordinates(Point point) { IlvCoordinate coord; IlvPoint pt = new IlvPoint(point.x, point.y); view.getTransformer().inverse(pt); IlvProjectionUtil.invertY(pt); try { IlvCoordinateSystem cs = IlvCoordinateSystemProperty.GetCoordinateSystem(view.getManager()); IlvCoordinateTransformation ct = IlvCoordinateTransformation.CreateTransformation(cs, IlvGeographicCoordinateSystem.KERNEL); coord = new IlvCoordinate(pt.x, pt.y); ct.transform(coord, coord); } catch (IlvCoordinateTransformationException e) { coord = null; } return coord; } /** * Returns a tooltip associated to a graphical object by making an HTML table * from its IlvAttributeProperty. * * @param graphic * Graphical object * @param point * location of the mouse on the view. * @return the string to display as a tooltip. */ protected String getToolTip(IlvGraphic graphic, Point point) { IlvDisplayPreferences pref = IlvDisplayPreferencesProperty.GetDisplayPreferences(view.getManager()); IlvCoordinate coord = computeCoordinates(point); // information for example. IlvAttributeProperty property = (IlvAttributeProperty) graphic.getNamedProperty(IlvAttributeProperty.NAME); if (property != null) { IlvAttributeInfoProperty info = property.getInfo(); int count = info.getAttributesCount(); int displayed = 0; String text = "<HTML><TABLE>"; //$NON-NLS-1$ for (int ip = 0; ip < count; ip++) { Object v = property.getValue(ip); String name = info.getAttributeName(ip); if (v == null || v == "") //$NON-NLS-1$ continue; if (v instanceof IlvAltitudeDataSource) { IlvAltitudeDataSource ads = (IlvAltitudeDataSource) v; if (coord != null) { double alt = ads.getAltitude(coord.x, coord.y, 0); if (!Double.isNaN(alt)) { v = pref.formatAltitude(alt); } else { continue; } } else { continue; } } if (v instanceof IlvAttributeArray) { IlvAttributeArray a = (IlvAttributeArray) v; String ss = "<ul>"; //$NON-NLS-1$ for (int i = 0; i < a.getSize(); i++) { IlvFeatureAttribute fa = a.getAttribute(i); ss += "<li>" + fa + "</li>"; //$NON-NLS-1$ //$NON-NLS-2$ } ss += "</ul>"; //$NON-NLS-1$ v = ss; } text += "<tr><td>" + name + "</td><td>" + v + "</td></tr>"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ displayed++; } if (displayed == 0) { return null; } text += "</TABLE></HTML>"; //$NON-NLS-1$ return text; } return null; } /** * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent) */ Override public void propertyChange(PropertyChangeEvent e) { if (loading) return; if (!autoReprojection) return; reprojectNow((IlvCoordinateSystem) e.getNewValue(), e.getPropertyName()); } private void reprojectNow(IlvCoordinateSystem system, String reason) { // keep the same area of interest IlvAreaOfInterest a = null; if (IlvJCoordinateSystemEditorPanel.PROJECTION_CHANGED.equals(reason)) { // if projection change, try keeping the same visible area a = IlvJAreaOfInterestPanel.createLocationFromView(getView(), 0, false); // stop center interactor. view.setInteractor(toolbar.getPanInteractor()); } view.getManager().setNamedProperty(new IlvCoordinateSystemProperty(system)); boolean isProj = system instanceof IlvProjectedCoordinateSystem; centerInteractorBtn.setEnabled(isProj); if (!isProj && centerInteractorBtn.isSelected()) { view.setInteractor(toolbar.getPanInteractor()); } // reloads data engine.loadData(); IlvMapLabelerProperty prop = (IlvMapLabelerProperty) getView().getManager() .getNamedProperty(IlvMapLabelerProperty.NAME); if (prop != null) { prop.getMapLabeler().performLabeling(); } getOverview().getInteractor().fitOverview(); if (a != null) { a.zoomTo(getView()); } } static Random ran = new Random(); static int ShapeLayerIndex = 0; private float ran() { return (float) (ran.nextDouble() / 2 + 0.5); } /** * Returns an url created with a resource name. * * @param resource * resource name. * @return a file name or URL. */ public static URL findURL(String resource) { URL rtnURL = null; boolean exists = false; try { exists = new File(resource).exists(); } catch (AccessControlException e) { exists = false; } if (exists) { try { rtnURL = new File(resource).toURI().toURL(); } catch (Exception e) { e.printStackTrace(); } } else { // get the resource at the base of the classpath rtnURL = BaseDemo.class.getResource("/" + resource); //$NON-NLS-1$ if (rtnURL == null) rtnURL = BaseDemo.class.getResource(resource); } return rtnURL; } /** * Method to load sample data. */ protected void loadInitialData() { ran.setSeed(13); String shapeFile = IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ShpFileURL"); //$NON-NLS-1$ URL shpFile = findURL(shapeFile); try { IlvManager manager = view.getManager(); IlvMapDataSourceModel dsm = IlvMapDataSourceProperty.GetMapDataSourceModel(manager); IlvMapLayerTreeModel ltm = IlvMapLayerTreeProperty.GetMapLayerTreeModel(manager); String formatName; if (!useSimplifiedDefaultMap) { String gifImageFile = IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ImgFileURL"); //$NON-NLS-1$ URL gifFile = findURL(gifImageFile); // create a raster reader for the gif file (necessary to create a // datasource below) IlvRasterBasicImageReader imageReader = new IlvRasterBasicImageReader(); imageReader.addMap(gifFile/* .getFile() */); // georeference this image (it covers the whole earth) imageReader.setImageBounds(0, -Math.PI, Math.PI / 2, Math.PI, -Math.PI / 2); // create main branch layer for image. formatName = IlvMapUtil.getString(ShapeLoadAction.class, "BasicImageLoadAction.FormatName"); //$NON-NLS-1$ IlvMapLayer imageParent = new IlvMapLayer(); imageParent.setName(formatName); imageParent.setStyle(new IlvMapCompositeStyle()); ltm.addChild(null, imageParent); // create a datasource for the gif file. IlvMapDataSource imageDataSource = IlvRasterDataSourceFactory.buildTiledImageDataSource(view.getManager(), imageReader, true, true, null); imageDataSource.setName(formatName + " (" + gifImageFile + ")"); //$NON-NLS-1$ //$NON-NLS-2$ dsm.insert(imageDataSource); imageDataSource.getInsertionLayer().setName(imageDataSource.getName()); imageDataSource.getInsertionLayer().getStyle().setVisibleInOverview(true); imageDataSource.getInsertionLayer().getStyle().setVisibleIn3DView(true); ltm.addChild(imageParent, imageDataSource.getInsertionLayer()); } // create main branch layer for shape file. formatName = IlvMapUtil.getString(ShapeLoadAction.class, "ShapeLoadAction.FormatName"); //$NON-NLS-1$ IlvMapLayer shapeParent = new IlvMapLayer(); shapeParent.setName(formatName); shapeParent.setStyle(new IlvMapCompositeStyle()); ltm.addChild(null, shapeParent); // read data IlvShapeDataSource shapeSource = new IlvShapeDataSource( shpFile/* .getFile() */, true); shapeSource.setName(formatName + " (" + shapeFile + ")"); //$NON-NLS-1$ //$NON-NLS-2$ shapeSource.setCoordinateSystem(IlvGeographicCoordinateSystem.WGS84); dsm.insert(shapeSource); IlvMapLayer shapeLayer = shapeSource.getInsertionLayer(); shapeLayer.setName(shapeSource.getName()); ltm.addChild(shapeParent, shapeLayer); // start reading. dsm.start(); // tweak the shape file style IlvMapStyle shapeStyle = shapeLayer.getStyle(); if (!useSimplifiedDefaultMap) { shapeStyle.setAttribute(IlvPolylineStyle.FOREGROUND, Color.white); shapeStyle.setVisibleIn3DView(true);// JV-4851 show this by default in // 3d view shapeStyle.setAttribute(IlvGraphicPathStyle.DO_FILL, Boolean.FALSE); shapeStyle.setLabelAttribute("NAME"); //$NON-NLS-1$ // Setup the label layer policy IlvMapLabeler labeler = IlvMapLabelerProperty.GetMapLabeler(view.getManager()); labeler.setView(view); labeler.getLabelLayer(shapeLayer).getStyle().setAttribute(IlvMapLabelStyle.DRAW_CENTERED, Boolean.TRUE); labeler.getLabelLayer(shapeLayer).getStyle().setAttribute(IlvMapLabelStyle.LABELLING_SMALL_AREAS, Boolean.TRUE); labeler.addLayer(shapeSource.getInsertionLayer()); } else if (shapeStyle != null) { shapeStyle.setAttribute(IlvPolylineStyle.FOREGROUND, Color.black); shapeStyle.setAttribute(IlvPolylineStyle.BACKGROUND, new Color(ran(), ran(), ran())); shapeStyle.setVisibleIn3DView(true);// JV-4851 show this by default in // 3d view shapeStyle.setVisibleInOverview(true); } layerTree.expandPath(new TreePath(layerTree.getModel().getRoot())); layerTree.setRootVisible(false); } catch (RuntimeException e1) { e1.printStackTrace(); } view.fitTransformerToContent(); SwingUtilities.invokeLater(new Runnable() { Override public void run() { view.fitTransformerToContent(); setModified(false); } }); } private PropertyChangeListener prefChangeListener = new PropertyChangeListener() { Override public void propertyChange(PropertyChangeEvent e) { if (loading) return; IlvDisplayPreferences system = (IlvDisplayPreferences) e.getNewValue(); /* * Uncomment this to activate the geodetic interpolation when geodetic * computation is activated. if(system.isUsingGeodeticComputation()){ * IlvMapCurveRenderer.setGeodeticInterpolationRendering(true); * IlvMapAreaRenderer.setGeodeticInterpolationRendering(true); } */ view.getManager().setNamedProperty(new IlvDisplayPreferencesProperty(system)); IlvMapLabelerProperty prop = (IlvMapLabelerProperty) getView().getManager() .getNamedProperty(IlvMapLabelerProperty.NAME); if (prop != null) { prop.getMapLabeler().performLabeling(); } } }; private boolean loading; /** * Adds an interactor on the toolbar. * * @param interactorResource * name of the resource, found with <code>IlvMapUtil.getString</code> * @param interactor * interactor to add on the view * @param index * -1 or the index of the interactor in the toolbar. * @see IlvImageUtil#getImageFromFile(java.lang.Class, java.lang.String) * @see IlvMapUtil#getString(java.lang.Class, java.lang.String) * @return the button created. */ protected MBToggleButton installInteractorButton(String interactorResource, final IlvManagerViewInteractor interactor, int index) { final MBToggleButton interactorButton = new MBToggleButton(interactorResource, false); if (index == -1) toolbar.add(interactorButton); else toolbar.add(interactorButton, index); if (interactor == null) { interactorButton.setEnabled(false); } else { interactorButton.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { if (interactorButton.isSelected()) { view.setInteractor(interactor); view.requestFocus(); } else if (view.getInteractor() == interactor) { view.popInteractor(); } } }); InteractorListener interactorListener = new InteractorListener() { Override public void interactorChanged(InteractorChangedEvent event) { boolean isMyInteractor = (event.getNewValue() == interactor); if (interactorButton.isSelected() != isMyInteractor) { interactorButton.setSelected(isMyInteractor); } } }; view.addInteractorListener(interactorListener); } interactorButton.setName(interactorResource); return interactorButton; } /** * Deinstalls an interactor from the toolbar. * * @param name * name of the interactor. */ protected void desinstallInteractorButton(String name) { for (int i = 0; i < toolbar.getComponentCount(); i++) { Component c = toolbar.getComponent(i); if (name.equals(c.getName())) { toolbar.remove(c); return; } } } /** * Code called when the application exits. * */ public void exitApplication() { int ans = JOptionPane.NO_OPTION; if (isModified()) { ans = JOptionPane.showConfirmDialog(view, IlvMapUtil.getString(BaseDemo.class, "BaseDemo.MessageConfirmExit"), //$NON-NLS-1$ IlvMapUtil.getString(BaseDemo.class, "BaseDemo.TitleConfirmExit"), //$NON-NLS-1$ JOptionPane.YES_NO_CANCEL_OPTION); } if (ans == JOptionPane.YES_OPTION) { IvlFileManager.SaveIvlActionListener p = new IvlFileManager.SaveIvlActionListener(this, true); p.actionPerformed(null); if (!p.isSaved()) { ans = JOptionPane.CANCEL_OPTION; } } if (ans != JOptionPane.CANCEL_OPTION) { /* normal termination */ savePreferences(); // IvlFileManager.clearManager(view, true); // dispose(); // remove the temporary files try { IlvRasterTemporaryFileManager.removeAllFiles(); System.exit(0); } catch (SecurityException e) { // Applet do not exit } } } /** * @return Returns the main map view of this application. */ public IlvManagerView getView() { return view; } /** * @return the overview of this show case. */ public IlvJOverview getOverview() { return overview; } /** * @return Returns the coordinate system editor panel. */ public IlvJCoordinateSystemEditorPanel getCoordinateSystemEditorPanel() { return csPanel; } /** * @return Returns the display preferences editor panel. */ public IlvJDisplayPreferencesEditorPanel getDisplayPreferencesEditorPanel() { return prefsPanel; } /** * @param loading * indicates the loading mode. */ public void setLoading(boolean loading) { this.loading = loading; if (loading == false) { gridManager.updateAfterLoad(); } } private boolean modified; /** * Indicates whether or not the current map has been modified. * * @return true if the map has been modified */ public boolean isModified() { return modified; } /** * Determines whether or not the current map has been modified. * * @param b * true to display the map as beeing modified. */ public void setModified(boolean b) { modified = b; } private DemoModificationListener modificationListener; private DemoModificationListener getModificationListener() { if (modificationListener == null) { modificationListener = new DemoModificationListener(this); } return modificationListener; } /** * Create the print panel. * * @return A <code>JPanel</code> containing the buttons to configure the * printing. */ protected JPanel makePrintPanel() { // Creates the interactor. JButton cleararea = new JButton(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.ClearArea")); //$NON-NLS-1$ JButton setarea = new JButton(IlvMapUtil.getString(BaseDemo.class, "BaseDemo.SetArea")); //$NON-NLS-1$ // Action to open the print preview dialog. // Action to install the print area interactor. setarea.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent ev) { if (printAreaInteractor == null) { printAreaInteractor = new IlvPrintAreaInteractor(getPrintingController()); } view.setInteractor(printAreaInteractor); } }); // Action to reset the print area to full manager size. cleararea.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent ev) { ((IlvManagerPrintableDocument) getPrintingController().getDocument()).setPrintArea(null); } }); JPanel p = new JPanel(new GridLayout(0, 1)); p.add(setup); p.add(preview); p.add(print); p.add(setarea); p.add(cleararea); JPanel pPanel = new JPanel(); pPanel.add(p, BorderLayout.NORTH); return pPanel; } /** * Creates the continuous zoom configuration panel. * * @return a new <code>ZoomConfigurationPanel</code> */ protected ZoomConfigurationPanel makeZoomConfigPanel() { return new ZoomConfigurationPanel(); } /** * Creates an <code>IlvMapExportDialog</code> and returns it. This method * registers the <code>IlvMapExporter</code> exporters needed by the * application. * * @param vview * The view * @return an <code>IlvMapExportDialog</code> object. */ protected IlvMapExportDialog makeExportDialog(IlvManagerView vview) { IlvMapExportDialog ed = new IlvMapExportDialog(vview); IlvKMLExporter kmlExport = new IlvKMLExporter(); ed.registerVectorExporter(kmlExport); ed.registerRasterExporter(kmlExport); ed.registerVectorExporter(new IlvShapeExporter()); ed.registerRasterExporter(new GeoTiffExporter()); // share connection information IlvSDOExporter sdoex = new IlvSDOExporter() { Override public void showConfigurationDialog(JDialog parent) { SDOConnectionPanel connectionPanel = getConnectionPanel(); String user = getPreferences().getProperty(SDOLoadAction.USER); if (user != null) { connectionPanel.setUser(user); } String driver = getPreferences().getProperty(SDOLoadAction.DRIVER); if (user != null) { connectionPanel.setDriver(driver); } String password = getPreferences().getProperty(SDOLoadAction.PASSWORD); if (password != null) { connectionPanel.setPassword(password); } String databaseName = getPreferences().getProperty(SDOLoadAction.DATABASE_SID); if (databaseName != null) { connectionPanel.setSid(databaseName); } String hostName = getPreferences().getProperty(SDOLoadAction.HOST_NAME); if (hostName != null) { connectionPanel.setHostName(hostName); } String hostPort = getPreferences().getProperty(SDOLoadAction.HOST_PORT); if (hostPort != null) { connectionPanel.setHostPort(hostPort); } super.showConfigurationDialog(parent); } }; ed.registerVectorExporter(sdoex); return ed; } /** * Creates an <code>TileDebugManager</code>. * * @param vview * The <code>IlvManagerView</code> to debug. * @return an <code>TileDebugManager</code>. */ protected TileDebugManager makeTileDebugManager(IlvManagerView vview) { return new TileDebugManager(vview); } static class MySpringLayout extends SpringLayout { /** * @inheritDoc */ Override public void layoutContainer(Container parent) { super.layoutContainer(parent); int height = 0; for (int i = 0; i < parent.getComponentCount(); i++) { height = Math.max(height, parent.getComponent(i).getHeight()); } int ph = parent.getHeight(); for (int i = 0; i < parent.getComponentCount(); i++) { Component c = parent.getComponent(i); int h = c.getHeight(); c.setLocation(c.getX(), (ph - h) / 2); } } } class SelectObjectAndSetSelectInteractor { IlvGraphic object; SelectObjectAndSetSelectInteractor(IlvMakePolyPointsInteractor inter) { final IlvPolyPointsObjectFactory ppof = inter.getObjectFactory(); IlvPolyPointsObjectFactory n = new IlvPolyPointsObjectFactory() { Override public IlvGraphic createObject(IlvPoint[] points) { object = ppof.createObject(points); return object; } }; inter.setObjectFactory(n); IlvManager manager = getView().getManager(); manager.addManagerContentChangedListener(new ManagerContentChangedListener() { Override public void contentsChanged(final ManagerContentChangedEvent evt) { if (object == null) return; if (evt.isAdjusting()) return; if (evt.getType() == ManagerContentChangedEvent.OBJECT_ADDED) { ObjectInsertedEvent oie = (ObjectInsertedEvent) evt; if (oie.getGraphicObject() == object) { Component c[] = toolbar.getComponents(); final AbstractButton b = (AbstractButton) c[1]; SwingUtilities.invokeLater(new Runnable() { Override public void run() { evt.getManager().setSelected(object, true, false); b.doClick(); object = null; } }); } } } }); } } static class ZoomConfigurationPanel extends JPanel { static final String PERIOD = "PERIOD"; //$NON-NLS-1$ static final String ZOOM_FACTOR = "ZOOM_FACTOR"; //$NON-NLS-1$ private final static double defaultZoomFactor = 1.06; private final static int defaultPeriod = 10; private double zoomFactor = defaultZoomFactor; private int period = defaultPeriod; JSlider cs; JSlider per; JCheckBox continuous; JCheckBox wheel; /** * Zooom Config Panel. */ public ZoomConfigurationPanel() { super(new BorderLayout()); JPanel mainPanel = new JPanel(new GridBagLayout()); JPanel contZoomFactor = new JPanel(new BorderLayout()); String title = IlvMapUtil.getString(getClass(), "BaseDemo.ContinuousZoomFactor"); //$NON-NLS-1$ contZoomFactor.setBorder(BorderFactory.createTitledBorder(title)); int csMin = 101; int csMax = 116; double zf = getContinuousZoomFactor(); cs = new JSlider(csMin, csMax, (int) (zf * 100)); Hashtable<Integer, JLabel> csLabels = new Hashtable<Integer, JLabel>(); final JLabel csMinLabel = new JLabel(IlvMapUtil.getString(getClass(), "BaseDemo.ContinuousZoomFactor.Min")); //$NON-NLS-1$ csLabels.put(Integer.valueOf(csMin), csMinLabel); final JLabel csMaxLabel = new JLabel(IlvMapUtil.getString(getClass(), "BaseDemo.ContinuousZoomFactor.Max")); //$NON-NLS-1$ csLabels.put(Integer.valueOf(csMax), csMaxLabel); cs.setLabelTable(csLabels); cs.setPaintLabels(true); cs.setMajorTickSpacing(csMax - csMin); cs.setMinorTickSpacing((csMax - csMin) / 10); cs.setPaintTicks(true); cs.setPaintTrack(true); cs.addChangeListener(new ChangeListener() { Override public void stateChanged(ChangeEvent e) { int value = cs.getValue(); if (cs.getValueIsAdjusting()) { // wait } else { setContinuousZoomFactor(value / 100.); } } }); contZoomFactor.add(cs, BorderLayout.CENTER); contZoomFactor.setAlignmentX(Component.LEFT_ALIGNMENT); int isMin = 10; int isMax = 500; JPanel pperiod = new JPanel(new BorderLayout()); String t = IlvMapUtil.getString(getClass(), "BaseDemo.Delay"); //$NON-NLS-1$ pperiod.setBorder(BorderFactory.createTitledBorder(t)); int pr = getPeriod() * 10; per = new JSlider(isMin, isMax, pr); Hashtable<Integer, JLabel> perLabels = new Hashtable<Integer, JLabel>(); final JLabel perMinLabel = new JLabel(IlvMapUtil.getString(getClass(), "BaseDemo.Delay.Min")); //$NON-NLS-1$ perLabels.put(Integer.valueOf(isMin), perMinLabel); final JLabel perMaxLabel = new JLabel(IlvMapUtil.getString(getClass(), "BaseDemo.Delay.Max")); //$NON-NLS-1$ perLabels.put(Integer.valueOf(isMax), perMaxLabel); per.setLabelTable(perLabels); per.setPaintLabels(true); per.setMajorTickSpacing(isMax - isMin); per.setMinorTickSpacing((isMax - isMin) / 10); per.setPaintTicks(true); per.setPaintTrack(true); per.addChangeListener(new ChangeListener() { Override public void stateChanged(ChangeEvent e) { int value = per.getValue(); if (per.getValueIsAdjusting()) { // } else { int v = (int) (value / 10.); if (v <= 0) { v = 1; } setPeriod(v); } } }); pperiod.add(per, BorderLayout.CENTER); pperiod.setAlignmentX(Component.LEFT_ALIGNMENT); JPanel restorePanel = new JPanel(); JButton restoreButton = new JButton(IlvMapUtil.getString(getClass(), "BaseDemo.RestoreDefaultZoomFactor")); //$NON-NLS-1$ restoreButton.addActionListener(new ActionListener() { Override public void actionPerformed(ActionEvent e) { per.setValue(defaultPeriod * 10); cs.setValue((int) (defaultZoomFactor * 100)); } }); restorePanel.add(restoreButton); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.gridy = 0; mainPanel.add(contZoomFactor, c); c.gridy = 1; mainPanel.add(pperiod, c); c.gridy = 2; mainPanel.add(restorePanel, c); add(mainPanel, BorderLayout.NORTH); } int getPeriod() { return period; } void setPeriod(int period) { this.period = period; per.setValue(period * 10); putClientProperty(PERIOD, Integer.valueOf(period)); } double getContinuousZoomFactor() { return zoomFactor; } void setContinuousZoomFactor(double zoomFactor) { this.zoomFactor = zoomFactor; cs.setValue((int) (zoomFactor * 100.)); putClientProperty(ZOOM_FACTOR, Double.valueOf(zoomFactor)); } } void dropFile(File f) { if (f.getName().toLowerCase().endsWith(IlvMapOutputStream.getFileSuffix())) { IvlFileManager.LoadIvlActionListener loader = new IvlFileManager.LoadIvlActionListener(this); loader.doLoad(f); } } static int max = 0; // JV-4677 static String wrapToolTipText(String text) { if (max == 0) { try { max = Toolkit.getDefaultToolkit().getScreenSize().width; } catch (HeadlessException he) { he.printStackTrace();// no reason to happen } } if (max > 10) { max -= 10; JToolTip test = new JToolTip(); test.setTipText(text); if (test.getPreferredSize().width > max) { return "<html><div width=\"" //$NON-NLS-1$ + max + "\" align=\"left\">" //$NON-NLS-1$ + text + "</div></html>"; //$NON-NLS-1$ } } return text; } }