<commit_before>package org.nakedobjects.viewer.skylark;

import org.nakedobjects.NakedObjects;
import org.nakedobjects.object.ApplicationContext;
import org.nakedobjects.object.NakedObject;
import org.nakedobjects.viewer.ObjectViewingMechanismListener;
import org.nakedobjects.viewer.skylark.special.RootWorkspaceSpecification;

public class SkylarkViewer {
    private ViewUpdateNotifier updateNotifier;
    private ViewerFrame frame;
    private Viewer viewer;
    
    public SkylarkViewer() {
        frame = new ViewerFrame();
        
        viewer = new Viewer();
        viewer.setRenderingArea(frame);

        frame.setViewer(viewer);
        
        updateNotifier = new ViewUpdateNotifier();
        NakedObjects.getObjectManager().addObjectChangedListener(updateNotifier);
        
        InteractionSpy spy = new InteractionSpy();

        ViewerAssistant viewerAssistant = new ViewerAssistant();
        viewerAssistant.setViewer(viewer);
        viewerAssistant.setDebugFrame(spy);
        viewerAssistant.setUpdateNotifier(updateNotifier);

        viewer.setUpdateNotifier(updateNotifier);
        viewer.setSpy(spy);

        setShutdownListener(new ObjectViewingMechanismListener() {
            public void viewerClosing() {
                System.out.println("EXITED");
                System.exit(0);
            }
        });
        
        viewer.start();
    }
    
    public void show() {        
        frame.setBounds(10, 10, 800, 600);
        frame.show();    
        viewer.sizeChange();
    }

    public void setApplication(ApplicationContext applicationContext) {
        NakedObject rootObject = NakedObjects.getPojoAdapterFactory().createNOAdapter(applicationContext);
        RootWorkspaceSpecification spec = new RootWorkspaceSpecification();
        View view = spec.createView(new RootObject(rootObject), null);
        viewer.setRootView(view);
        
        frame.setTitle(applicationContext.name());
    }

    public void setShutdownListener(ObjectViewingMechanismListener listener) {
        viewer.setListener(listener);
    }
    
    public void setExploration(boolean inExplorationMode) {
        viewer.setExploration(inExplorationMode);
    }
}


/*
Naked Objects - a framework that exposes behaviourally complete<commit_msg>Reorganised SkylarlkViewer so the update notifer can be injected into it.  This is needed when running in C/S mode as updates need to come across the wire and the views need to be updated.<commit_after>package org.nakedobjects.viewer.skylark;

import org.nakedobjects.NakedObjects;
import org.nakedobjects.object.ApplicationContext;
import org.nakedobjects.object.NakedObject;
import org.nakedobjects.viewer.ObjectViewingMechanismListener;
import org.nakedobjects.viewer.skylark.special.RootWorkspaceSpecification;

public class SkylarkViewer {
    private ViewUpdateNotifier updateNotifier;
    private ViewerFrame frame;
    private Viewer viewer;
    private ViewerAssistant viewerAssistant;
    
    public SkylarkViewer() {
        frame = new ViewerFrame();
        
        viewer = new Viewer();
        viewer.setRenderingArea(frame);

        frame.setViewer(viewer);
        
        //updateNotifier = new ViewUpdateNotifier();
        
        InteractionSpy spy = new InteractionSpy();

        viewerAssistant = new ViewerAssistant();
        viewerAssistant.setViewer(viewer);
        viewerAssistant.setDebugFrame(spy);

        viewer.setSpy(spy);

        setShutdownListener(new ObjectViewingMechanismListener() {
            public void viewerClosing() {
                System.out.println("EXITED");
                System.exit(0);
            }
        });
        
        viewer.start();
    }
    
    public void show() {        
        NakedObjects.getObjectManager().addObjectChangedListener(updateNotifier);
        
        frame.setBounds(10, 10, 800, 600);
        frame.show();    
        viewer.sizeChange();
    }

    public void setApplication(ApplicationContext applicationContext) {
        NakedObject rootObject = NakedObjects.getPojoAdapterFactory().createNOAdapter(applicationContext);
        RootWorkspaceSpecification spec = new RootWorkspaceSpecification();
        View view = spec.createView(new RootObject(rootObject), null);
        viewer.setRootView(view);
        
        frame.setTitle(applicationContext.name());
    }

    public void setShutdownListener(ObjectViewingMechanismListener listener) {
        viewer.setListener(listener);
    }
    
    public void setExploration(boolean inExplorationMode) {
        viewer.setExploration(inExplorationMode);
    }
/*
    public DirtyObjectSet getUpdateNotifier() {
        return updateNotifier;
    }
*/    
    public void setUpdateNotifier(ViewUpdateNotifier updateNotifier) {
        this.updateNotifier = updateNotifier;

        viewerAssistant.setUpdateNotifier(updateNotifier);
        viewer.setUpdateNotifier(updateNotifier);
    }
}


/*
Naked Objects - a framework that exposes behaviourally complete
{'fraction_non_alphanumeric': 0.08063872255489021, 'fraction_numerical': 0.004391217564870259, 'mean_word_length': 2.986475735879077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2562383', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1355, 'n_words': 253}