Skip to content

Commit

Permalink
Merge pull request #852 from vorth/reverse-scenes
Browse files Browse the repository at this point in the history
Added option for adding to the start of the scenes list
  • Loading branch information
vorth authored Apr 5, 2024
2 parents 54f0cb2 + b541f8e commit a09136a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
26 changes: 24 additions & 2 deletions core/src/main/java/com/vzome/core/editor/LessonModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public class LessonModel implements Iterable<PageModel>

private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport( this );

private boolean reverse = false;

public boolean isReverse()
{
return this.reverse;
}

public void toggleReverse()
{
this.reverse = !this.reverse;
}

public void addPropertyChangeListener( PropertyChangeListener listener )
{
propertyChangeSupport .addPropertyChangeListener( listener );
Expand Down Expand Up @@ -143,7 +155,7 @@ public void goToPage( final int newPageNum )

public void duplicatePage( Camera view )
{
int newPageNum = pageNum + 1;
int newPageNum = this.reverse ? pageNum : pageNum + 1;
PageModel page = pages .get( pageNum );
int snap = page .getSnapshot();
page = new PageModel( "", "", view, snap );
Expand All @@ -155,7 +167,7 @@ public void duplicatePage( Camera view )

public void newSnapshotPage( int snapshotId, Camera view )
{
int newPageNum = pages .size();
int newPageNum = this.reverse ? 0 : pages .size();
PageModel pc = new PageModel( "", "", view, snapshotId );
pages .add( newPageNum, pc );

Expand Down Expand Up @@ -269,6 +281,16 @@ public void setView( Camera view )
firePropertyChange( "thumbnailChanged", -1, pageNum );
}

public void setViewAll( Camera view )
{
for (int i = 0; i < pages.size(); i++) {
PageModel page = pages .get( i );
page .setView( view );
page .setThumbnailCurrent( false );
firePropertyChange( "thumbnailChanged", -1, i );
}
}

public void refresh()
{
if ( pageNum >= 0 )
Expand Down
12 changes: 12 additions & 0 deletions desktop/src/main/java/com/vzome/desktop/awt/LessonController.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ else if ( "deletePage" .equals( action ) )
model .deletePage();
setProperty( "edited", "true" );
}
else if ( "toggleReverse" .equals( action ) )
{
model .toggleReverse();
}
else if ( action .startsWith( "elementSelected-" ) )
{
// action defined by ListPanel
Expand Down Expand Up @@ -142,6 +146,11 @@ else if ( "setView" .equals( action ) )
model .setView( vpm .getView() );
setProperty( "edited", "true" );
}
else if ( "setViewAll" .equals( action ) )
{
model .setViewAll( vpm .getView() );
setProperty( "edited", "true" );
}
else if ( action .startsWith( "usePageView-" ) )
{
String pageStr = action .substring( "usePageView-".length() );
Expand Down Expand Up @@ -224,6 +233,9 @@ public String getProperty( String propName )
// This should not be called for UI creation, so we can do that concurrently with model loading
return Boolean .toString( ! model .isEmpty() );

if ( "reverse" .equals( propName ) )
return Boolean .toString( model .isReverse() );

if ( "onFirstPage" .equals( propName ) )
return Boolean .toString( model .onFirstPage() );

Expand Down
17 changes: 14 additions & 3 deletions desktop/src/main/java/org/vorthmann/zome/ui/PagelistPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenuItem;
Expand Down Expand Up @@ -195,12 +196,15 @@ public PagelistPanel( final GraphicsController controller )
pageviewPopupMenu .setLightWeightPopupEnabled( false );
if ( this .isEditor )
{
JMenuItem menuItem = createMenuItem( "Save Current View to Page", "setView" );
JMenuItem menuItem = createMenuItem( "Save current view to page", "setView" );
menuItem .addActionListener( actionListener );
pageviewPopupMenu .add( menuItem );
menuItem = createMenuItem( "Save current view to ALL", "setViewAll" );
menuItem .addActionListener( actionListener );
pageviewPopupMenu .add( menuItem );
}

JMenuItem menuItem = createMenuItem( "Show This Page's View", "usePageView" );
JMenuItem menuItem = createMenuItem( "Show this page's view", "usePageView" );
menuItem .addActionListener( new ActionListener()
{
@Override
Expand All @@ -211,7 +215,7 @@ public void actionPerformed( ActionEvent ae )
} );
pageviewPopupMenu .add( menuItem );

menuItem = createMenuItem( "Copy This Page's View", "copyPageView" );
menuItem = createMenuItem( "Copy this page's view", "copyPageView" );
menuItem .addActionListener( new ActionListener()
{
@Override
Expand Down Expand Up @@ -264,6 +268,12 @@ public void mouseClicked( MouseEvent e )

if ( this.isEditor )
{
JCheckBox reverseCheckBox = new JCheckBox( "add before" );
reverseCheckBox.setActionCommand( "toggleReverse" );
reverseCheckBox.addActionListener( actionListener );
reverseCheckBox.setEnabled( true );
reverseCheckBox .setSelected( controller .propertyIsTrue( "reverse" ) );

addButton = new JButton( dupeString );
addButton.setActionCommand( "duplicatePage" );
addButton.addActionListener( actionListener );
Expand All @@ -277,6 +287,7 @@ public void mouseClicked( MouseEvent e )
// Create a panel that uses BoxLayout.
JPanel buttonPane = new JPanel();
buttonPane .setLayout( new BoxLayout( buttonPane, BoxLayout.PAGE_AXIS ) );
buttonPane .add( reverseCheckBox );
buttonPane .add( addButton );
buttonPane .add( removeButton );
buttonPane .setBorder( BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) );
Expand Down

0 comments on commit a09136a

Please sign in to comment.