Example #1
0
  /**
   * Determines whether a given control can have a specified layer added to it.
   *
   * @param control existing control
   * @param lcmd specifies layer to add
   * @return true iff <code>control.addLayer(lcmd)</code> will work
   */
  private static boolean isCompatible(MultiFormLayerControl control, LayerCommand lcmd) {

    /* Note the implementation of this method is closely tied to the
     * implementation of MultiFormLayerControl.addLayer. */

    /* Must have the same table data. */
    if (lcmd.getTopcatModel() != control.getTopcatModel()) {
      return false;
    }

    /* Must have the same positional coordinates.
     * This test currently requires all the coordinates to be the same,
     * I think that could be relaxed to just the positional ones. */
    if (!lcmd.getInputValues()
        .equals(GuiCoordContent.getInputValues(control.getPositionCoordPanel().getContents()))) {
      return false;
    }

    /* Must have the same, single, subset.  It could be possible
     * under some circumstances to add to a gang control with
     * multiple subsets, but the logic is tricky, so this is not
     * currently supported by addLayer. */
    RowSubset rset = lcmd.getRowSubset();
    SubsetStack subStack = control.getSubsetStack();
    if (!Arrays.equals(subStack.getSelectedSubsets(), new RowSubset[] {rset})) {
      return false;
    }

    /* Any config options specified for the new layer must not conflict
     * with config options (probably colour) currently in force for
     * the new layer's subset. */
    SubsetConfigManager subManager = control.getSubsetManager();
    if (subManager.hasConfigger(rset)) {
      ConfigMap ctrlConfig = subManager.getConfigger(rset).getConfig();
      ConfigMap cmdConfig = lcmd.getConfig();
      for (ConfigKey<?> key : cmdConfig.keySet()) {
        if (ctrlConfig.keySet().contains(key)
            && !PlotUtil.equals(ctrlConfig.get(key), cmdConfig.get(key))) {
          return false;
        }
      }
    }

    /* If it passes all those tests, it's compatible. */
    return true;
  }