/** * 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; }
/** * Creates a new empty gang layer control. * * @param ctyp common coordinate set type * @param autoPlot true to attempt a plot without further user interaction * @return gang control, or null if it would be useless */ private MultiFormLayerControl createGangControl(CoordsType ctyp, boolean autoPlot) { List<Plotter> plotterList = plotterMap_.get(ctyp); if (plotterList != null && plotterList.size() > 0) { PositionCoordPanel coordPanel = ctyp.createPositionCoordPanel(plotType_, plotTypeGui_); boolean autoPop = ctyp.isAutoPopulate(); MultiFormLayerControl control = new MultiFormLayerControl( coordPanel, autoPop, nextSupplier_, tcListener_, ctyp.getIcon(), plotterList.toArray(new Plotter[0]), baseConfigger_); if (autoPlot) { control.addDefaultLayer(); } return control; } else { return null; } }
/** * Constructs a new gang layer control which is capable of having a specified layer added to it. * * @param lcmd layer specification * @return new control for which <code>addLayer(lcmd)</code> will work */ private MultiFormLayerControl createGangControl(LayerCommand lcmd) throws LayerException { /* Create the control. */ int npos = lcmd.getPlotter().getCoordGroup().getPositionCount(); CoordsType ctyp = CoordsType.getInstance(lcmd.getPlotter()); MultiFormLayerControl control = createGangControl(ctyp, false); /* Set the table. */ control.setTopcatModel(lcmd.getTopcatModel()); /* Set up the positional coordinates. */ PositionCoordPanel posCoordPanel = control.getPositionCoordPanel(); Coord[] posCoords = posCoordPanel.getCoords(); Map<String, String> inputValues = lcmd.getInputValues(); for (int ic = 0; ic < posCoords.length; ic++) { Input[] inputs = posCoords[ic].getInputs(); for (int iu = 0; iu < inputs.length; iu++) { String name = LayerCommand.getInputName(inputs[iu]); String value = inputValues.get(name); if (value != null) { ColumnDataComboBoxModel colModel = posCoordPanel.getColumnSelector(ic, iu); ColumnData colData; try { colData = colModel.stringToColumnData(value); } catch (CompilationException e) { throw new LayerException("Can't compile: " + value, e); } posCoordPanel.getColumnSelector(ic, iu).setSelectedItem(colData); } } } /* Set up per-subset configuration. */ control.getSubsetManager().setConfig(lcmd.getRowSubset(), lcmd.getConfig()); /* Return. */ return control; }