private void saveButtonActionPerformed(
      java.awt.event.ActionEvent evt) { // GEN-FIRST:event_saveButtonActionPerformed
    PreviewUIController previewController = Lookup.getDefault().lookup(PreviewUIController.class);
    PreviewPreset preset = previewController.getModel().getCurrentPreset();
    boolean saved = false;
    if (isDefaultPreset(preset)) {
      NotifyDescriptor.InputLine question =
          new NotifyDescriptor.InputLine(
              NbBundle.getMessage(
                  PreviewSettingsTopComponent.class,
                  "PreviewSettingsTopComponent.savePreset.input"),
              NbBundle.getMessage(
                  PreviewSettingsTopComponent.class,
                  "PreviewSettingsTopComponent.savePreset.input.title"));
      if (DialogDisplayer.getDefault().notify(question) == NotifyDescriptor.OK_OPTION) {
        String input = question.getInputText();
        if (input != null && !input.isEmpty()) {
          previewController.savePreset(input);
          saved = true;
          StatusDisplayer.getDefault()
              .setStatusText(
                  NbBundle.getMessage(
                      PreviewSettingsTopComponent.class,
                      "PreviewSettingsTopComponent.savePreset.status",
                      input));
        }
      }
    } else {
      previewController.savePreset(preset.getName());
      saved = true;
      StatusDisplayer.getDefault()
          .setStatusText(
              NbBundle.getMessage(
                  PreviewSettingsTopComponent.class,
                  "PreviewSettingsTopComponent.savePreset.status",
                  preset.getName()));
    }

    if (saved) {
      // refresh combo
      DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
      defaultPresetLimit = 0;
      for (PreviewPreset p : previewController.getDefaultPresets()) {
        comboBoxModel.addElement(p);
        defaultPresetLimit++;
      }
      PreviewPreset[] userPresets = previewController.getUserPresets();
      if (userPresets.length > 0) {
        comboBoxModel.addElement(NO_SELECTION);
        for (PreviewPreset p : userPresets) {
          comboBoxModel.addElement(p);
        }
      }
      comboBoxModel.setSelectedItem(previewController.getModel().getCurrentPreset());
      presetComboBox.setModel(comboBoxModel);
    }
  } // GEN-LAST:event_saveButtonActionPerformed
  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);
          }
        }
      }
    }
  }
  private PreviewTopComponent() {
    initComponents();
    setName(NbBundle.getMessage(PreviewTopComponent.class, "CTL_PreviewTopComponent"));
    //        setToolTipText(NbBundle.getMessage(PreviewTopComponent.class,
    // "HINT_PreviewTopComponent"));
    setIcon(ImageUtilities.loadImage(ICON_PATH));
    if (UIUtils.isAquaLookAndFeel()) {
      previewPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
    }
    if (UIUtils.isAquaLookAndFeel()) {
      southToolbar.setBackground(UIManager.getColor("NbExplorerView.background"));
    }

    bannerPanel.setVisible(false);

    // background color
    ((JColorButton) backgroundButton)
        .addPropertyChangeListener(
            JColorButton.EVENT_COLOR,
            new PropertyChangeListener() {

              public void propertyChange(PropertyChangeEvent evt) {
                PreviewController previewController =
                    Lookup.getDefault().lookup(PreviewController.class);
                previewController
                    .getModel()
                    .getProperties()
                    .putValue(PreviewProperty.BACKGROUND_COLOR, (Color) evt.getNewValue());
                PreviewUIController previewUIController =
                    Lookup.getDefault().lookup(PreviewUIController.class);
                previewUIController.refreshPreview();
              }
            });
    southBusyLabel.setVisible(false);
    resetZoomButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            target.resetZoom();
          }
        });
    plusButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            target.zoomPlus();
          }
        });
    minusButton.addActionListener(
        new ActionListener() {

          public void actionPerformed(ActionEvent e) {
            target.zoomMinus();
          }
        });

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

    PreviewUIModel m = controller.getModel();
    if (m != null) {
      this.model = m;
      initTarget(model);
    }
  }