class PreviewUIControllerImpl implements PreviewUIController {

    private final List<PropertyChangeListener> listeners;
    private final PreviewController previewController;
    private final GraphController graphController;
    private final PresetUtils presetUtils = new PresetUtils();
    private PreviewUIModelImpl model = null;
    private GraphModel graphModel = null;

    public PreviewUIControllerImpl() {
        previewController = Lookup.getDefault().lookup(PreviewController.class);
        listeners = new ArrayList<>();
        ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
        graphController = Lookup.getDefault().lookup(GraphController.class);
        pc.addWorkspaceListener(new WorkspaceListener() {
            @Override
            public void initialize(Workspace workspace) {
                PreviewModel previewModel = previewController.getModel(workspace);
                if (workspace.getLookup().lookup(PreviewUIModelImpl.class) == null) {
                    workspace.add(new PreviewUIModelImpl(previewModel));
                }
                enableRefresh();
            }

            @Override
            public void select(Workspace workspace) {
                graphModel = graphController.getGraphModel(workspace);

                PreviewModel previewModel = previewController.getModel(workspace);
                model = workspace.getLookup().lookup(PreviewUIModelImpl.class);
                if (model == null) {
                    model = new PreviewUIModelImpl(previewModel);
                    workspace.add(model);
                }
                Float visibilityRatio = previewModel.getProperties().getFloatValue(PreviewProperty.VISIBILITY_RATIO);
                model.setVisibilityRatio(visibilityRatio);
                fireEvent(SELECT, model);
            }

            @Override
            public void unselect(Workspace workspace) {
                if (graphModel != null) {
                    graphModel = null;
                }
                fireEvent(UNSELECT, model);
            }

            @Override
            public void close(Workspace workspace) {
            }

            @Override
            public void disable() {
                if (graphModel != null) {
                    graphModel = null;
                }
                fireEvent(SELECT, null);
                model = null;
            }
        });
        if (pc.getCurrentWorkspace() != null) {
            model = pc.getCurrentWorkspace().getLookup().lookup(PreviewUIModelImpl.class);
            if (model == null) {
                PreviewModel previewModel = previewController.getModel(pc.getCurrentWorkspace());
                model = new PreviewUIModelImpl(previewModel);
                pc.getCurrentWorkspace().add(model);
            }
            Float visibilityRatio =
                previewController.getModel().getProperties().getFloatValue(PreviewProperty.VISIBILITY_RATIO);
            if (visibilityRatio != null) {
                model.setVisibilityRatio(visibilityRatio);
            }
            graphModel = graphController.getGraphModel(pc.getCurrentWorkspace());
        }

        //Register editors
        //Overriding default Preview API basic editors that don't support CustomEditor
        PropertyEditorManager.registerEditor(EdgeColor.class, EdgeColorPropertyEditor.class);
        PropertyEditorManager.registerEditor(DependantOriginalColor.class, DependantOriginalColorPropertyEditor.class);
        PropertyEditorManager.registerEditor(DependantColor.class, DependantColorPropertyEditor.class);
    }

    /**
     * Refreshes the preview applet.
     */
    @Override
    public void refreshPreview() {<FILL_FUNCTION_BODY>}

    /**
     * Enables the preview refresh action.
     */
    private void enableRefresh() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                PreviewSettingsTopComponent pstc = (PreviewSettingsTopComponent) WindowManager.getDefault()
                    .findTopComponent("PreviewSettingsTopComponent");
                if (pstc != null) {
                    pstc.enableRefreshButton();
                }
            }
        });
    }

    @Override
    public void setVisibilityRatio(float visibilityRatio) {
        if (model != null) {
            model.setVisibilityRatio(visibilityRatio);
        }
    }

    @Override
    public PreviewUIModel getModel() {
        return model;
    }

    @Override
    public PreviewPreset[] getDefaultPresets() {
        return new PreviewPreset[] {new DefaultPreset(), new DefaultCurved(), new DefaultStraight(), new TextOutline(),
            new BlackBackground(), new EdgesCustomColor(), new TagCloud()};
    }

    @Override
    public PreviewPreset[] getUserPresets() {
        PreviewPreset[] presetsArray = presetUtils.getPresets();
        Arrays.sort(presetsArray);
        return presetsArray;
    }

    @Override
    public void setCurrentPreset(PreviewPreset preset) {
        if (model != null) {
            model.setCurrentPreset(preset);
            PreviewModel previewModel = previewController.getModel();
            previewModel.getProperties().applyPreset(preset);
        }
    }

    @Override
    public void addPreset(PreviewPreset preset) {
        presetUtils.savePreset(preset);
    }

    @Override
    public void savePreset(String name) {
        if (model != null) {
            PreviewModel previewModel = previewController.getModel();
            Map<String, Object> map = new HashMap<>();
            for (PreviewProperty p : previewModel.getProperties().getProperties()) {
                map.put(p.getName(), p.getValue());
            }
            for (Entry<String, Object> p : previewModel.getProperties().getSimpleValues()) {
                map.put(p.getKey(), p.getValue());
            }
            PreviewPreset preset = new PreviewPreset(name, map);
            presetUtils.savePreset(preset);
            model.setCurrentPreset(preset);
        }
    }

    @Override
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        if (!listeners.contains(listener)) {
            listeners.add(listener);
        }
    }

    @Override
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        listeners.remove(listener);
    }

    private void fireEvent(String eventName, Object data) {
        PropertyChangeEvent event = new PropertyChangeEvent(this, eventName, null, data);
        for (PropertyChangeListener l : listeners) {
            l.propertyChange(event);
        }
    }
}

        if (model != null) {
            Thread refreshThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    model.setRefreshing(true);
                    fireEvent(REFRESHING, true);

                    previewController.getModel().getProperties()
                        .putValue(PreviewProperty.VISIBILITY_RATIO, model.getVisibilityRatio());
                    previewController.refreshPreview();

                    fireEvent(REFRESHED, model);

                    model.setRefreshing(false);
                    fireEvent(REFRESHING, false);
                }
            }, "Refresh Preview");
            refreshThread.start();
        }
    
<no_super_class>