file2IndexMap.put(files[i], indexes[i]);
File[] nnFiles = (File[]) file2IndexMap.keySet().toArray(new File[file2IndexMap.keySet().size()]);
if (sample.getSampleNumber().intValue() + nnFiles.length > DeviceContext.BASE_ROM_SAMPLE)
throw new CommandFailedException("Not enough user locations on or after S" + df.format(sample.getSampleNumber()) + " to load package");
String opt1;
String opt2;
try {
if (SampleContextMacros.areSampleIndexesEmpty(sample.getSampleContext(), sample.getSampleNumber(), nonNullFiles)) {
indexes = ZUtilities.fillIncrementally(new Integer[nonNullFiles], sample.getSampleNumber().intValue());
SampleContextMacros.loadSamplesToContext(nnFiles, indexes, sample.getSampleContext(), true, true);
updateIndexMap(index2IndexMap, file2IndexMap, indexes, nnFiles);
return index2IndexMap;
}
} catch (NoSuchSampleException e) {
throw new CommandFailedException("No such sample");
} catch (NoSuchContextException e) {
throw new CommandFailedException("Problem with sample context");
}
if (nonNullFiles > 1) {
opt1 = "At locations " + df.format(sample.getSampleNumber()) + " - " + df.format(sample.getSampleNumber().intValue() + nonNullFiles - 1);
opt2 = "At first " + nonNullFiles + " empty locations searching from " + df.format(sample.getSampleNumber());
} else {
opt1 = "At location " + df.format(sample.getSampleNumber());
opt2 = "At first empty location searching from " + df.format(sample.getSampleNumber());
}
int res = JOptionPane.showOptionDialog(ZoeosFrame.getInstance(), (nonNullFiles == 1 ? "Load 1 sample" : "Load " + nonNullFiles + " samples "), "Load Samples", JOptionPane.OK_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[]{opt1, opt2}, opt1);
if (res == JOptionPane.CLOSED_OPTION)
return null;
if (res == 0) {
int si = sample.getSampleNumber().intValue();
indexes = new Integer[nonNullFiles];
for (int i = 0; i < indexes.length; i++)
indexes[i] = IntPool.get(si + i);
SampleContextMacros.loadSamplesToContext(nnFiles, indexes, sample.getSampleContext(), true, true);
updateIndexMap(index2IndexMap, file2IndexMap, indexes, nnFiles);
} else if (res == 1) {
try {
List emptyList = sample.getSampleContext().findEmptySamplesInContext(nonNullFiles, sample.getSampleNumber(), IntPool.get(DeviceContext.MAX_USER_SAMPLE));
if (emptyList.size() < nonNullFiles)
throw new CommandFailedException("Could not find " + nonNullFiles + " empty user sample locations.");
indexes = (Integer[]) emptyList.toArray(new Integer[emptyList.size()]);
SampleContextMacros.loadSamplesToContext(nnFiles, indexes, sample.getSampleContext(), true, true);
updateIndexMap(index2IndexMap, file2IndexMap, indexes, nnFiles);
} catch (NoSuchContextException e) {
throw new CommandFailedException("Problem with sample context");
}
}
return index2IndexMap;
}