private void updateProperties(final AssetKey key) {
   if (key == null) {
     ps.setNodes(new Node[] {});
   } else {
     ps.setNodes(new Node[] {new ImportKeyNode(key)});
   }
 }
 /** Creates new form ModelImporterVisualPanel1 */
 public ModelImporterVisualPanel1(ModelImporterWizardPanel1 panel) {
   initComponents();
   this.panel = panel;
   ps = new PropertySheet();
   ps.setNodes(new Node[] {});
   ps.setDescriptionAreaVisible(false);
   jPanel2.add(ps);
 }
  public State mouseReleased(Widget widget, WidgetMouseEvent event) {
    if (mEditNode == null) {
      return State.REJECTED;
    }
    if (widget instanceof ImageWidget) {
      ((ImageWidget) widget).setPaintAsDisabled(false);
    }
    final PropertySheet propertySheetPanel = new PropertySheet();
    final Node editNodeRef = mEditNode;
    mEditNode = null;

    propertySheetPanel.setNodes(new Node[] {editNodeRef});
    final Object[] options = new Object[] {Constants.CLOSE};
    final DialogDescriptor descriptor =
        new DialogDescriptor(
            propertySheetPanel,
            NbBundle.getMessage(getClass(), "STR_PROPERTIES", editNodeRef.getDisplayName()),
            true,
            options,
            null,
            DialogDescriptor.DEFAULT_ALIGN,
            null,
            null);
    descriptor.setClosingOptions(options);

    final Dialog dlg = DialogDisplayer.getDefault().createDialog(descriptor);

    // The dialog is modal, allow the action chain to continue while
    // we open the dialog later.
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            dlg.setVisible(true);
          }
        });

    return State.CONSUMED;
  }
  private PreviewSettingsTopComponent() {
    initComponents();
    setName(
        NbBundle.getMessage(PreviewSettingsTopComponent.class, "CTL_PreviewSettingsTopComponent"));
    //        setToolTipText(NbBundle.getMessage(PreviewSettingsTopComponent.class,
    // "HINT_PreviewSettingsTopComponent"));
    setIcon(ImageUtilities.loadImage(ICON_PATH));
    if (UIUtils.isAquaLookAndFeel()) {
      mainPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
    }

    // property sheet
    propertySheet = new PropertySheet();
    propertySheet.setNodes(new Node[] {new PreviewNode(propertySheet)});
    propertySheet.setDescriptionAreaVisible(false);

    // Tabs and PreviewUI
    PreviewUI[] previewUIs =
        Lookup.getDefault().lookupAll(PreviewUI.class).toArray(new PreviewUI[0]);
    if (previewUIs.length > 0) {
      tabbedPane = new JTabbedPane();
      tabbedPane.addTab(
          NbBundle.getMessage(
              PreviewSettingsTopComponent.class, "PreviewSettingsTopComponent.propertySheetTab"),
          propertySheet);
      propertiesPanel.add(tabbedPane, BorderLayout.CENTER);
    } else {
      propertiesPanel.add(propertySheet, BorderLayout.CENTER);
    }

    // Ratio
    ratioSlider.addChangeListener(
        new ChangeListener() {

          NumberFormat formatter = NumberFormat.getPercentInstance();

          public void stateChanged(ChangeEvent e) {
            float val = ratioSlider.getValue() / 100f;
            if (val == 0f) {
              ratioLabel.setText(
                  NbBundle.getMessage(
                      PreviewSettingsTopComponent.class,
                      "PreviewSettingsTopComponent.ratio.minimum"));
            } else {
              ratioLabel.setText(formatter.format(val));
            }
            PreviewUIController puic = Lookup.getDefault().lookup(PreviewUIController.class);
            puic.setVisibilityRatio(getVisibilityRatio());
          }
        });

    // Presets
    presetComboBox.addItemListener(
        new ItemListener() {

          public void itemStateChanged(ItemEvent e) {
            PreviewUIController pc = Lookup.getDefault().lookup(PreviewUIController.class);
            PreviewUIModel previewModel = pc.getModel();
            if (previewModel != null && presetComboBox.getSelectedItem() instanceof PreviewPreset) {
              if (previewModel.getCurrentPreset() != presetComboBox.getSelectedItem()) {
                pc.setCurrentPreset((PreviewPreset) presetComboBox.getSelectedItem());
                propertySheet.setNodes(new Node[] {new PreviewNode(propertySheet)});
              }
            }
          }
        });

    // Export
    svgExportButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            VectorialFileExporterUI ui = Lookup.getDefault().lookup(VectorialFileExporterUI.class);
            ui.action();
          }
        });
    setup(null);

    PreviewUIController controller = Lookup.getDefault().lookup(PreviewUIController.class);
    controller.addPropertyChangeListener(this);

    PreviewUIModel m = controller.getModel();
    if (m != null) {
      setup(m);
      enableRefreshButton();
    }
  }
  public void setup(PreviewUIModel previewModel) {
    propertySheet.setNodes(new Node[] {new PreviewNode(propertySheet)});
    PreviewUIController previewUIController = Lookup.getDefault().lookup(PreviewUIController.class);
    if (previewModel != null) {
      ratioSlider.setValue((int) (previewModel.getVisibilityRatio() * 100));
    }

    // Presets
    if (previewModel == null) {
      saveButton.setEnabled(false);
      labelPreset.setEnabled(false);
      presetComboBox.setEnabled(false);
      presetComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] {"---"}));
    } else {
      saveButton.setEnabled(true);
      labelPreset.setEnabled(true);
      presetComboBox.setEnabled(true);
      DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
      defaultPresetLimit = 0;
      for (PreviewPreset preset : previewUIController.getDefaultPresets()) {
        comboBoxModel.addElement(preset);
        defaultPresetLimit++;
      }
      PreviewPreset[] userPresets = previewUIController.getUserPresets();
      if (userPresets.length > 0) {
        comboBoxModel.addElement(NO_SELECTION);
        for (PreviewPreset preset : userPresets) {
          comboBoxModel.addElement(preset);
        }
      }
      presetComboBox.setSelectedItem(previewModel.getCurrentPreset());
      presetComboBox.setModel(comboBoxModel);
    }

    // Refresh tabs
    if (tabbedPane != null) {
      int tabCount = tabbedPane.getTabCount();
      for (int i = 1; i < tabCount; i++) {
        tabbedPane.removeTabAt(i);
      }
      for (PreviewUI pui : Lookup.getDefault().lookupAll(PreviewUI.class)) {
        pui.unsetup();
      }
      if (previewModel != null) {
        PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
        PreviewModel pModel = previewController.getModel();
        // Add new tabs
        for (PreviewUI pui : Lookup.getDefault().lookupAll(PreviewUI.class)) {
          pui.setup(pModel);
          JPanel pluginPanel = pui.getPanel();
          if (UIUtils.isAquaLookAndFeel()) {
            pluginPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
          }
          if (pui.getIcon() != null) {
            tabbedPane.addTab(pui.getPanelTitle(), pui.getIcon(), pluginPanel);
          } else {
            tabbedPane.addTab(pui.getPanelTitle(), pluginPanel);
          }
        }
      }
    }
  }