Search in sources :

Example 1 with ModuleTemplate

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;
}
Also used : AccessibleContext(javax.accessibility.AccessibleContext) ModuleTemplate(com.android.tools.idea.npw.ModuleTemplate) ActionEvent(java.awt.event.ActionEvent) Function(com.google.common.base.Function) DynamicWizard(com.android.tools.idea.wizard.dynamic.DynamicWizard) JBCardLayout(com.intellij.ui.JBCardLayout) Nullable(org.jetbrains.annotations.Nullable) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 2 with ModuleTemplate

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));
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ModuleTemplate(com.android.tools.idea.npw.ModuleTemplate) ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) FormFactor(com.android.tools.idea.npw.FormFactor) ModuleTemplateProvider(com.android.tools.idea.npw.ModuleTemplateProvider) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ModuleTemplate (com.android.tools.idea.npw.ModuleTemplate)2 Nullable (org.jetbrains.annotations.Nullable)2 FormFactor (com.android.tools.idea.npw.FormFactor)1 ModuleTemplateProvider (com.android.tools.idea.npw.ModuleTemplateProvider)1 DynamicWizard (com.android.tools.idea.wizard.dynamic.DynamicWizard)1 ScopedStateStore (com.android.tools.idea.wizard.dynamic.ScopedStateStore)1 Function (com.google.common.base.Function)1 ImmutableList (com.google.common.collect.ImmutableList)1 JBCardLayout (com.intellij.ui.JBCardLayout)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 ActionEvent (java.awt.event.ActionEvent)1 AccessibleContext (javax.accessibility.AccessibleContext)1