use of com.android.tools.idea.npw.ModuleTemplate in project android by JetBrains.
the class ChooseModuleTypeStep method createGallery.
private JPanel createGallery() {
Dimension thumbnailSize = DEFAULT_GALLERY_THUMBNAIL_SIZE;
myFormFactorGallery = new ASGallery<ModuleTemplate>(JBList.createDefaultListModel(), new Function<ModuleTemplate, Image>() {
@Override
public Image apply(ModuleTemplate input) {
return IconUtil.toImage(input.getIcon());
}
}, new Function<ModuleTemplate, String>() {
@Override
public String apply(@Nullable ModuleTemplate input) {
return input == null ? "<none>" : input.getName();
}
}, thumbnailSize, new AbstractAction() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
DynamicWizard wizard = getWizard();
assert wizard != null;
getWizard().doNextAction();
}
}) {
@Override
public Dimension getPreferredScrollableViewportSize() {
Dimension preferred = getPreferredSize();
int heightInsets = getInsets().top + getInsets().bottom;
// Don't want to show an exact number of rows, since then it's not obvious there's another row available.
return new Dimension(preferred.width, (int) (computeCellSize().height * 2.2) + heightInsets);
}
};
myFormFactorGallery.setMinimumSize(new Dimension(thumbnailSize.width * 2 + 1, thumbnailSize.height));
myFormFactorGallery.setBorder(BorderFactory.createLineBorder(JBColor.border()));
AccessibleContext accessibleContext = myFormFactorGallery.getAccessibleContext();
if (accessibleContext != null) {
accessibleContext.setAccessibleDescription(getStepTitle());
}
JPanel panel = new JPanel(new JBCardLayout());
panel.add("only card", new JBScrollPane(myFormFactorGallery));
return panel;
}
use of com.android.tools.idea.npw.ModuleTemplate in project android by JetBrains.
the class ChooseModuleTypeStep method init.
@Override
public void init() {
super.init();
ImmutableList.Builder<ModuleTemplate> deviceTemplates = ImmutableList.builder();
ImmutableList.Builder<ModuleTemplate> extrasTemplates = ImmutableList.builder();
Set<FormFactor> formFactorSet = Sets.newHashSet();
// Android device templates are shown first, with less important templates following
for (ModuleTemplateProvider provider : myModuleTypesProviders) {
for (ModuleTemplate moduleTemplate : provider.getModuleTemplates()) {
FormFactor formFactor = moduleTemplate.getFormFactor();
if (formFactor != null) {
if (formFactor == FormFactor.GLASS && !AndroidSdkUtils.isGlassInstalled()) {
// Hidden if not installed
continue;
}
if (formFactor != FormFactor.CAR) {
// Auto is not a standalone module (but rather a modification to a mobile module):
deviceTemplates.add(moduleTemplate);
formFactorSet.add(formFactor);
}
} else {
extrasTemplates.add(moduleTemplate);
}
}
}
for (final FormFactor formFactor : formFactorSet) {
registerValueDeriver(FormFactorUtils.getInclusionKey(formFactor), new ValueDeriver<Boolean>() {
@Nullable
@Override
public Boolean deriveValue(@NotNull ScopedStateStore state, @Nullable ScopedStateStore.Key changedKey, @Nullable Boolean currentValue) {
ModuleTemplate moduleTemplate = myState.get(SELECTED_MODULE_TYPE_KEY);
return moduleTemplate != null && Objects.equal(formFactor, moduleTemplate.getFormFactor());
}
});
}
List<ModuleTemplate> galleryTemplatesList = deviceTemplates.build();
List<ModuleTemplate> extrasTemplatesList = extrasTemplates.build();
Iterable<ModuleTemplate> allTemplates = Iterables.concat(galleryTemplatesList, extrasTemplatesList);
myFormFactorGallery.setModel(JBList.createDefaultListModel(Iterables.toArray(allTemplates, ModuleTemplate.class)));
ModuleTypeBinding binding = new ModuleTypeBinding();
register(SELECTED_MODULE_TYPE_KEY, myPanel, binding);
myFormFactorGallery.addListSelectionListener(new ModuleTypeSelectionListener());
if (!galleryTemplatesList.isEmpty()) {
myState.put(SELECTED_MODULE_TYPE_KEY, galleryTemplatesList.get(0));
}
}
Aggregations