/*
 *    Debrief - the Open Source Maritime Analysis Application
 *    http://debrief.info
 *
 *    (C) 2000-2018, Deep Blue C Technology Ltd
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the Eclipse Public License v1.0
 *    (http://www.eclipse.org/legal/epl-v10.html)
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
package Debrief.Tools.Palette;

import javax.swing.JComboBox;
import javax.swing.JOptionPane;

import MWC.GUI.BaseLayer;
import MWC.GUI.Layer;
import MWC.GUI.Layers;
import MWC.GUI.ToolParent;
import MWC.GUI.Tools.PlainTool;
import MWC.GenericData.WorldArea;

/**
 * @author Ayesha <ayesha.ma@gmail.com>
 *
 */
public abstract class CoreCreateShape extends PlainTool
{
  
  public static final String USER_SELECTED_LAYER_COMMAND = "User-selected Layer";
  
  /** the layers we are going to drop this shape into
   */
  protected Layers _theData;
  
  protected JComboBox<String> selectedLayerSource;
  
  protected final BoundsProvider _theBounds;

  /////////////////////////////////////////////////////////////
  // constructor
  ////////////////////////////////////////////////////////////
  public CoreCreateShape(final ToolParent theParent,
      final String theName,
      final String theImage,
      final Layers theData,
      final BoundsProvider bounds)
  {
    super(theParent, theName, theImage);
    _theData = theData;
    _theBounds = bounds;
  }


  /////////////////////////////////////////////////////////////
  // member functions
  ////////////////////////////////////////////////////////////
  /** get the current visible data area
   * 
   */
  final protected WorldArea getBounds()
  {
    return _theBounds.getViewport();
  }
  
  //used in debrief lite, to get the select layer from ribbon tab
  public final void setSelectedLayerSource(JComboBox<String> jCombo) {
    selectedLayerSource = jCombo;
  }
  
  
  protected final String getSelectedLayer() {
    if(selectedLayerSource!=null) {
      return (String)selectedLayerSource.getSelectedItem();
    }
    return null;
  }
  /**
   * @return
   */
  protected String getLayerName()
  {
    String res = null;
    // ok, are we auto-deciding?

    // get the non-track layers
    final Layers theLayers = _theData;
    final String[] ourLayers = theLayers.trimmedLayers();
    ListLayersDialog listDialog = new ListLayersDialog(ourLayers);
    listDialog.setSize(350,300);
    listDialog.setLocationRelativeTo(null);
    listDialog.setModal(true);
    listDialog.setVisible(true);
    String selection = listDialog.getSelectedItem();
    // did user say yes?
    if (selection != null)
    {
      // hmm, is it our add layer command?
      if (selection.equals(Layers.NEW_LAYER_COMMAND))
      {
        // better create one. Ask the user

        // create input box dialog
        String txt = JOptionPane.showInputDialog(null, "Enter name for new layer","New Layer");
        // check there's something there
        if (txt!=null && !txt.isEmpty())
        {
          res = txt;
          // create base layer
          final Layer newLayer = new BaseLayer();
          newLayer.setName(res);
          // add to layers object
          theLayers.addThisLayer(newLayer);
        }
        else
        {
          res = null;
        }
      }
      else {
        res = selection;
      }
    }

    return res;
  }
}

@@ -929,18 +929,16 @@
 ool%0D%0A%7B%0D%0A
-  
 %0D%0A  publ
@@ -989,16 +989,23 @@
 OMMAND =
+%0D%0A     
  %22User-s
@@ -1025,17 +1025,21 @@
 %22;%0D%0A
-  
 %0D%0A  /**
+%0D%0A   *
  the
@@ -1121,18 +1121,16 @@
 eData;%0D%0A
-  
 %0D%0A  prot
@@ -1175,18 +1175,16 @@
 ource;%0D%0A
-  
 %0D%0A  prot
@@ -1424,23 +1424,16 @@
 eParent,
-%0D%0A     
  final S
@@ -1476,23 +1476,16 @@
 heImage,
-%0D%0A     
  final L
@@ -1498,23 +1498,16 @@
 theData,
-%0D%0A     
  final B
@@ -1634,18 +1634,16 @@
 %0A  %7D%0D%0A%0D%0A
-%0D%0A
   //////
@@ -1791,16 +1791,22 @@
 /%0D%0A  /**
+%0D%0A   *
  get the
@@ -1940,16 +1940,22 @@
  %7D%0D%0A
-  
+%0D%0A  /**
 %0D%0A  
-//
+ * 
 used
@@ -2013,16 +2013,50 @@
 on tab%0D%0A
+   * %0D%0A   * @param jCombo%0D%0A   */%0D%0A
   public
@@ -2115,16 +2115,19 @@
  jCombo)
+%0D%0A 
  %7B%0D%0A    
@@ -2162,22 +2162,16 @@
 ;%0D%0A  %7D%0D%0A
-  %0D%0A  
 %0D%0A  prot
@@ -2207,16 +2207,19 @@
 dLayer()
+%0D%0A 
  %7B%0D%0A    
@@ -2220,16 +2220,17 @@
 %0D%0A    if
+ 
 (selecte
@@ -2245,15 +2245,22 @@
 urce
+ 
 !=
+ 
 null)
+%0D%0A   
  %7B%0D%0A
@@ -2280,16 +2280,17 @@
 (String)
+ 
 selected
@@ -2351,16 +2351,18 @@
 ;%0D%0A  %7D%0D%0A
+%0D%0A
   /**%0D%0A 
@@ -2449,44 +2449,8 @@
 l;%0D%0A
-    // ok, are we auto-deciding?%0D%0A%0D%0A
     
@@ -2672,16 +2672,17 @@
 ize(350,
+ 
 300);%0D%0A 
@@ -3061,46 +3061,8 @@
 ser%0D
-%0A%0D%0A        // create input box dialog%0D
 %0A   
@@ -3112,16 +3112,29 @@
 og(null,
+%0D%0A           
  %22Enter 
@@ -3153,16 +3153,17 @@
  layer%22,
+ 
 %22New Lay
@@ -3226,18 +3226,20 @@
  if (txt
+ 
 !=
+ 
 null && 
@@ -3574,16 +3574,23 @@
     else
+%0D%0A     
  %7B%0D%0A    
@@ -3627,18 +3627,16 @@
 %0A    %7D%0D%0A
-%0D%0A
     retu

apply project formatting