[skycastle-commits] SF.net SVN: skycastle:[593] trunk/skycastle/modules

Revision: 593
          http://skycastle.svn.sourceforge.net/skycastle/?rev=593&view=rev
Author:   zzorn
Date:     2008-09-16 14:18:04 +0000 (Tue, 16 Sep 2008)

Log Message:
-----------
Started to add sketch library view to the sketch program.

Modified Paths:
--------------
    
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/SketchController.java
    
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/model/Sketch.java
    
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/model/SketchImpl.java
    
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/library/tomesources/MemoryTomeSource.java

Modified: 
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/SketchController.java
===================================================================
--- 
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/SketchController.java
      2008-09-16 06:21:52 UTC (rev 592)
+++ 
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/SketchController.java
      2008-09-16 14:18:04 UTC (rev 593)
@@ -10,21 +10,28 @@
 import org.skycastle.scratchpad.sketch.model.Sketch;
 import org.skycastle.scratchpad.sketch.model.SketchImpl;
 import org.skycastle.scratchpad.sketch.model.group.Group;
-import org.skycastle.scratchpad.sketch.model.stroke.Stroke;
-import org.skycastle.scratchpad.sketch.model.stroke.StrokeImpl;
 import org.skycastle.scratchpad.sketch.sliders.*;
 import org.skycastle.util.ColorUtils;
+import org.skycastle.util.ImageUtils;
 import org.skycastle.util.ParameterChecker;
+import org.skycastle.util.applicationview.AbstractSidebarComponent;
 import org.skycastle.util.applicationview.ApplicationController;
 import org.skycastle.util.applicationview.SidebarEdge;
 import org.skycastle.util.applicationview.SidebarImpl;
+import org.skycastle.util.library.Library;
+import org.skycastle.util.library.LibraryImpl;
+import org.skycastle.util.library.LibraryLocationImpl;
+import org.skycastle.util.library.Tome;
+import org.skycastle.util.library.tomesources.MemoryTomeSource;
+import org.skycastle.util.library.view.DefaultTomeRenderer;
+import org.skycastle.util.library.view.ListLibraryView;
 import org.skycastle.util.sample.DataSample;
 
+import javax.swing.*;
 import java.awt.Color;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
-import java.util.Random;
 
 /**
  * A controller for the Sketch application.
@@ -41,45 +48,6 @@
 
     private final List<SliderComponent> myInputSliders = new 
ArrayList<SliderComponent>();
 
-/*
-    private final CommandAction myAddTestStrokeAction = new CommandAction( 
myCommandStack,
-                                                                           
"Test Stroke",
-                                                                           
"Add Test Stroke" )
-    {
-
-        private final Group myGroup = mySketch.getRootGroup();
-
-        {
-            ParameterChecker.checkNotNull( mySketch.getRootGroup(), "group" );
-        }
-
-        @Override
-        protected Command createCommand()
-        {
-            final Stroke stroke = createTestStroke();
-
-            return new AbstractCommand( "Stroke", true )
-            {
-
-                public void doCommand()
-                {
-                    myGroup.add( stroke );
-                }
-
-
-                @Override
-                public void undoCommand()
-                {
-                    myGroup.remove( stroke );
-                }
-
-            };
-        }
-
-    };
-*/
-
-
     private Sketch mySketch;
 
     private InputHandler myInputHandler;
@@ -88,6 +56,8 @@
     // Private Constants
 
     private static final int MAX_WIDTH = 250;
+    private final MemoryTomeSource<Sketch> myInMemorySketches = new 
MemoryTomeSource<Sketch>();
+    private final Library mySketchLibrary = new LibraryImpl<Sketch>( 
myInMemorySketches );
 
     //======================================================================
     // Public Methods
@@ -104,8 +74,10 @@
     {
         super( applicationName );
 
-// Create model
+        // Create model
         mySketch = new SketchImpl();
+
+        myInMemorySketches.addTome( mySketch, "Initial Sketch", "New Sketch 1" 
);
     }
 
     //----------------------------------------------------------------------
@@ -184,6 +156,47 @@
 
     private void initSliders( final SketchView view )
     {
+        view.addSidebar( createBrushPropertySliders() );
+
+        view.addSidebar( createSketchViews() );
+
+
+    }
+
+    private SidebarImpl createSketchViews()
+    {
+        final SidebarImpl sidebar = new SidebarImpl( SidebarEdge.LEFT, 300 );
+
+        sidebar.addSidebarComponent( new AbstractSidebarComponent()
+        {
+            protected void onEdgeChanged( final SidebarEdge edge )
+            {
+            }
+
+            protected JComponent createUi()
+            {
+                final DefaultTomeRenderer<Sketch> sketchTomeRenderer = new 
DefaultTomeRenderer<Sketch>()
+                {
+                    @Override
+                    protected Icon getPreviewIcon( final Tome<Sketch> node )
+                    {
+                        return new ImageIcon( ImageUtils.createScaledImage( 
node.getContent().getPreview(), 240, 320 ) );
+
+                    }
+                };
+
+                final ListLibraryView listLibraryView = new 
ListLibraryView<Sketch>( mySketchLibrary,
+                                                                               
      new LibraryLocationImpl(),
+                                                                               
      sketchTomeRenderer );
+                return listLibraryView.getUi();
+            }
+        } );
+
+        return sidebar;
+    }
+
+    private SidebarImpl createBrushPropertySliders()
+    {
         // TODO: Extract color selection sliders to an own composite sidebar 
component
 
 
@@ -248,12 +261,12 @@
                                                  new 
SizeSliderBackgroundRenderer() ) );
 // TODO: Make max width of slider dependent on zoom level??
 
-        final SidebarImpl leftSidebar = new SidebarImpl( SidebarEdge.LEFT, 32 
);
+        final SidebarImpl rightSidebar = new SidebarImpl( SidebarEdge.RIGHT, 
32 );
         for ( SliderComponent inputSlider : myInputSliders )
         {
-            leftSidebar.addSidebarComponent( inputSlider );
+            rightSidebar.addSidebarComponent( inputSlider );
         }
-        view.addSidebar( leftSidebar );
+        return rightSidebar;
     }
 
     private void initMenuAndToolbar( final SketchView view,
@@ -265,47 +278,10 @@
         view.addMenuAction( "File", getExitAction() );
         view.addMenuAction( "Edit", getCommandStack().getUndoAction() );
         view.addMenuAction( "Edit", getCommandStack().getRedoAction() );
-/*
-        myView.addMenuAction( "Debug", myAddTestStrokeAction );
-
-        myView.addToolbarAction( myAddTestStrokeAction );
-*/
         view.addToolbarAction( saveAsAction );
         view.addToolbarAction( getCommandStack().getUndoAction() );
         view.addToolbarAction( getCommandStack().getRedoAction() );
     }
 
-    private Stroke createTestStroke()
-    {
-        final StrokeImpl stroke = new StrokeImpl();
 
-        final Random random = new Random();
-        float x = (float) ( random.nextGaussian() * 10 );
-        float y = (float) ( random.nextGaussian() * 10 );
-        float w = (float) ( 1 );
-
-        float xv = 0;
-        float yv = 0;
-        float wv = 0;
-
-        for ( int i = 0; i < 1000; i++ )
-        {
-            xv += random.nextGaussian() * 0.1;
-            yv += random.nextGaussian() * 0.1;
-            wv += random.nextGaussian() * 0.01;
-
-            x += xv;
-            y += yv;
-            w += wv;
-
-            final DataSample strokePoint = new DataSample();
-            strokePoint.setVariable( "x", x );
-            strokePoint.setVariable( "y", y );
-            strokePoint.setVariable( "width", w );
-            stroke.addPoint( strokePoint );
-        }
-
-        return stroke;
-    }
-
 }

Modified: 
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/model/Sketch.java
===================================================================
--- 
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/model/Sketch.java
  2008-09-16 06:21:52 UTC (rev 592)
+++ 
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/model/Sketch.java
  2008-09-16 14:18:04 UTC (rev 593)
@@ -3,6 +3,7 @@
 import org.skycastle.scratchpad.sketch.model.group.Group;
 import org.skycastle.scratchpad.sketch.model.stroke.Stroke;
 
+import java.awt.image.BufferedImage;
 import java.io.Serializable;
 
 /**
@@ -22,4 +23,9 @@
      */
     Group getRootGroup();
 
+    /**
+     * @return a preview of this sketch.
+     */
+    BufferedImage getPreview();
+
 }

Modified: 
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/model/SketchImpl.java
===================================================================
--- 
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/model/SketchImpl.java
      2008-09-16 06:21:52 UTC (rev 592)
+++ 
trunk/skycastle/modules/scratchpad/src/main/java/org/skycastle/scratchpad/sketch/model/SketchImpl.java
      2008-09-16 14:18:04 UTC (rev 593)
@@ -4,6 +4,8 @@
 import org.skycastle.scratchpad.sketch.model.group.Group;
 import org.skycastle.scratchpad.sketch.model.group.GroupImpl;
 
+import java.awt.image.BufferedImage;
+
 /**
  * @author Hans Häggström
  */
@@ -13,12 +15,15 @@
 {
     private static final long serialVersionUID = 1L;
 
+
     //======================================================================
     // Private Fields
 
     @XStreamAlias( "root" )
     private final Group myRootGroup = new GroupImpl();
 
+    private transient BufferedImage myPreview = null;
+
     //======================================================================
     // Public Methods
 
@@ -40,4 +45,13 @@
         return myRootGroup;
     }
 
+    public BufferedImage getPreview()
+    {
+        return myPreview;
+    }
+
+    public void setPreview( final BufferedImage preview )
+    {
+        myPreview = preview;
+    }
 }

Modified: 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/library/tomesources/MemoryTomeSource.java
===================================================================
--- 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/library/tomesources/MemoryTomeSource.java
    2008-09-16 06:21:52 UTC (rev 592)
+++ 
trunk/skycastle/modules/utils/src/main/java/org/skycastle/util/library/tomesources/MemoryTomeSource.java
    2008-09-16 14:18:04 UTC (rev 593)
@@ -1,11 +1,10 @@
 package org.skycastle.util.library.tomesources;
 
 import org.skycastle.util.ParameterChecker;
-import org.skycastle.util.library.Library;
-import org.skycastle.util.library.LibraryLocation;
-import org.skycastle.util.library.LibraryNode;
-import org.skycastle.util.library.Tome;
+import org.skycastle.util.library.*;
 
+import java.util.Arrays;
+
 /**
  * A simple in-memory {@link Tome} storage.
  * <p/>
@@ -68,4 +67,9 @@
     }
 
 
+    public final void addTome( final T content, final String description, 
final String... path )
+    {
+        addLibraryNode( new TomeImpl<T>( new LibraryLocationImpl( 
Arrays.asList( path ) ), content, this, System.currentTimeMillis(), description 
) );
+
+    }
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

Other related posts:

  • » [skycastle-commits] SF.net SVN: skycastle:[593] trunk/skycastle/modules