From a6b606a8ac24531810f1ac06110a4929f77a8c75 Mon Sep 17 00:00:00 2001 From: twig Date: Fri, 18 Apr 2014 09:09:25 +1000 Subject: [PATCH 1/3] added a spinner to control the preview animation delay timing (30ms was just way too fast) also removed (seemingly necessary) call to getWorkingAnimation() --- .../animation/AnimationController.java | 487 +++++++++--------- .../animation/AnimationStripPanel.java | 83 +-- 2 files changed, 293 insertions(+), 277 deletions(-) diff --git a/src/dfEditor/animation/AnimationController.java b/src/dfEditor/animation/AnimationController.java index 85b999f..2bbce8c 100644 --- a/src/dfEditor/animation/AnimationController.java +++ b/src/dfEditor/animation/AnimationController.java @@ -1,6 +1,6 @@ -/* +/* * Copyright 2009 Samuel Taylor - * + * * This file is part of darkFunction Editor * * darkFunction Editor is free software: you can redistribute it and/or modify @@ -64,7 +64,7 @@ public class AnimationController extends dfEditorPanel implements InternalFrameListener { private BufferedImage bufferedImage = null; - private AnimationCell workingCell = null; + private AnimationCell workingCell = null; private File loadedSpritesheetFile = null; private Timer spinnerStateTimer = null; ArrayList _rotatingGraphics = null; @@ -78,23 +78,23 @@ public AnimationController(CommandManager aCmdManager, boolean aNew, JLabel aHel viewPanel.addGraphicChangeListener(this); animationStripPanel.setController(this); - + animationStripPanel.setCommandManager(aCmdManager); viewPanel.setCommandManager(aCmdManager); - animationList.addListSelectionListener(this); - + animationList.addListSelectionListener(this); + spriteList.addListSelectionListener(this); spriteList.addNodeDroppedListener(this); spriteList.setDragSource(spriteTree); - - spriteTree.addTreeListener(this); + + spriteTree.addTreeListener(this); viewPanel.addNodeDroppedListener(this); viewPanel.setDragSource(spriteTree); controlPanel.addInternalFrameListener(this); spriteListControlPanel.addInternalFrameListener(this); - + setWorkingCell(null); if (aNew) @@ -105,10 +105,10 @@ public void run() { } }); } - - viewPanel.requestFocus(); - - postInit(); + + viewPanel.requestFocus(); + + postInit(); } private void showSpritesheetChooser() @@ -120,7 +120,7 @@ private void showSpritesheetChooser() chooser.resetChoosableFileFilters(); chooser.setFileFilter(filter); chooser.setDialogTitle("Select spritesheet"); - + JFrame mainFrame = dfEditorApp.getApplication().getMainFrame(); int returnVal = chooser.showOpenDialog(mainFrame); if(returnVal == JFileChooser.APPROVE_OPTION) @@ -133,7 +133,7 @@ private void setSpritesheetFile(File aFile) { SpritesheetReader reader = new SpritesheetReader(aFile); loadedSpritesheetFile = aFile; - + try { String imgPath = reader.getImagePath(); @@ -159,21 +159,21 @@ private void setSpritesheetFile(File aFile) return; } } - + private void buildAnimatedGif(String filePath) { Animation animation = this.getWorkingAnimation(); - + if (animation != null && animation.numCells() > 0) { Rectangle firstCellRect = animation.getCellAtIndex(0).getSpreadRect(); Point topLeft = new Point(firstCellRect.x, firstCellRect.y); Point bottomRight = new Point(firstCellRect.x + firstCellRect.width, firstCellRect.y + firstCellRect.height); - + for (int i=1; i bottomRight.x) bottomRight.x = r.x + r.width; if (r.y + r.height > bottomRight.y) - bottomRight.y = r.y + r.height; + bottomRight.y = r.y + r.height; } - + AnimatedGifEncoder e = new AnimatedGifEncoder(); e.setTransparent(new Color(0,0,0,0)); - e.start(filePath); + e.start(filePath); e.setRepeat(animation.getLoops()); e.setQuality(1); e.setSize(bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); - + for (int i=0; i addNodeToCell(CustomNode aNode, AnimationCell a { if (aNode == null) return null; - + if (aNode.isLeaf()) { if (aCell != null) @@ -1154,11 +1168,11 @@ private ArrayList addNodeToCell(CustomNode aNode, AnimationCell a if (aCell != null) aCell.rebuild(); - + animationStripPanel.repaint(); - + return aGraphics; - + // } @@ -1176,10 +1190,10 @@ public void nodeDropped(java.awt.Component aComponent, String aNodePath, Point a private void addAnimation(final Animation aAnimation) { boolean bExists = false; - String name = aAnimation.getName(); + String name = aAnimation.getName(); int animationNameCounter = 1; do - { + { bExists = false; for (int i=0; i= 0) { animationStripPanel.stop(); cmdManager.execute(new RemoveAnimationCommand(animationList, (Animation)animationList.getModel().getElementAt(index))); - } + } }//GEN-LAST:event_removeAnimationButtonActionPerformed private Animation getWorkingAnimation() @@ -1265,21 +1279,19 @@ private void delaySpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN- if (workingCell != null) { - int value = (Integer)spinner.getValue(); + int value = (Integer)spinner.getValue(); workingCell.setDelay(value); spinner.setValue(workingCell.getDelay()); } }//GEN-LAST:event_delaySpinnerStateChanged private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playButtonActionPerformed - Animation animation = getWorkingAnimation(); - animationStripPanel.addAnimationStripListener(this); boolean playing = animationStripPanel.isPlaying(); if (!playing) - animationStripPanel.play(); + animationStripPanel.play((Integer) previewDelaySpinner.getValue()); else animationStripPanel.stop(); @@ -1289,17 +1301,17 @@ private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI }//GEN-LAST:event_playButtonActionPerformed private void spriteTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_spriteTreeValueChanged - + int numSelected = 0; if (spriteTree.getSelectedNodes() != null) numSelected = spriteTree.getSelectedNodes().length; - + CustomNode node = (CustomNode)spriteTree.getLastSelectedPathComponent(); boolean bSelected = (node != null); - + addToFrameButton.setEnabled(bSelected); - + if (bSelected) { if (numSelected == 1 && node.isLeaf()) @@ -1311,7 +1323,7 @@ private void spriteTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {/ spritePreviewTitle.setText(node.getFullPathName()); } else if (numSelected > 1 || !node.isLeaf()) - { + { spritePreviewTitle.setHorizontalTextPosition(JLabel.CENTER); spritePreviewTitle.setText(""); spritePreviewPanel.setGraphic(null); @@ -1322,7 +1334,7 @@ else if (numSelected > 1 || !node.isLeaf()) spritePreviewTitle.setText(" "); spritePreviewPanel.setGraphic(null); } - + spritePreviewPanel.repaint(); }//GEN-LAST:event_spriteTreeValueChanged @@ -1353,9 +1365,9 @@ private void removeSpriteButtonActionPerformed(java.awt.event.ActionEvent evt) { ArrayList selectedGraphics = viewPanel.selectedGraphics(); ArrayList commands = new ArrayList(); - for (int i=0; i selectedGraphics = viewPanel.selectedGraphics(); - + cmdManager.execute(new RotateGraphicListCommand(selectedGraphics, 90.0f, viewPanel)); - + this.getWorkingCell().rebuild(); repaint(); }//GEN-LAST:event_rotateCWButtonActionPerformed private void rotateACWButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rotateACWButtonActionPerformed ArrayList selectedGraphics = viewPanel.selectedGraphics(); - + cmdManager.execute(new RotateGraphicListCommand(selectedGraphics, -90.0f, viewPanel)); - + this.getWorkingCell().rebuild(); repaint();}//GEN-LAST:event_rotateACWButtonActionPerformed private void zOrderSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_zOrderSpinnerStateChanged - + ArrayList selectedGraphics = viewPanel.selectedGraphics(); AnimationCell cell = this.getWorkingCell(); - + if (cell != null && selectedGraphics != null && selectedGraphics.size() > 0) { ArrayList commands = new ArrayList(); - + for (int i=0; i selected = null; - + if (aCell == getWorkingCell()) selected = viewPanel.selectedGraphics(); - + DefaultListModel model = (DefaultListModel)spriteList.getModel(); model.clear(); - + if (aCell != null) { ArrayList array = aCell.getGraphicList(); @@ -1448,112 +1460,112 @@ private void populateSpriteListFromCell(AnimationCell aCell) { array.get(i).setDescription(aCell.nodeForGraphic(array.get(i)).getFullPathName()); model.addElement(array.get(i)); - array.get(i).setDescription(aCell.nodeForGraphic(array.get(i)).getFullPathName()); + array.get(i).setDescription(aCell.nodeForGraphic(array.get(i)).getFullPathName()); } - + if (selected != null) { - int[] indices = new int[selected.size()]; + int[] indices = new int[selected.size()]; for (int i=0; i commands = new ArrayList(); AnimationCell cell = this.getWorkingCell(); - + if (cell != null && _rotatingGraphics != null && _rotatingGraphics.size() > 0) - { + { for (int i=0; i<_rotatingGraphics.size(); ++i) { Integer val = null; - try - { + try + { val = (Integer)angleSpinner.getValue(); } catch (NumberFormatException exc){} - if (val != null) + if (val != null) { int value = val.intValue(); GraphicObject graphic = _rotatingGraphics.get(i); if (value != graphic.getSavedAngle()) - { - commands.add(new SetGraphicAngleCommand(graphic, value, viewPanel)); + { + commands.add(new SetGraphicAngleCommand(graphic, value, viewPanel)); } } } } - + GroupedUndoableCommand groupedCommand = new GroupedUndoableCommand(commands); if (cmdManager != null) cmdManager.execute(groupedCommand); else groupedCommand.execute(); - - this.setModified(true); - + + this.setModified(true); + getWorkingCell().rebuild(); animationStripPanel.repaint(); - + _rotatingGraphics = null; } - + private void angleSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_angleSpinnerStateChanged - + if (spinnerStateTimer == null) { spinnerStateTimer = new Timer(400, this); spinnerStateTimer.setRepeats(false); spinnerStateTimer.setActionCommand(null); } - + if (!spinnerStateTimer.isRunning()) - { - spinnerStateTimer.start(); + { + spinnerStateTimer.start(); } else spinnerStateTimer.restart(); - + _rotatingGraphics = viewPanel.selectedGraphics(); - AnimationCell cell = this.getWorkingCell(); + AnimationCell cell = this.getWorkingCell(); if (cell != null && _rotatingGraphics != null && _rotatingGraphics.size() > 0) - { + { for (int i=0; i<_rotatingGraphics.size(); ++i) { Integer val = null; - - try - { + + try + { val = (Integer)angleSpinner.getValue(); } catch (NumberFormatException exc){} - - if (val != null) + + if (val != null) { int value = val.intValue(); GraphicObject graphic = _rotatingGraphics.get(i); - + if (value != graphic.getAngle()) - { + { graphic.setAngle(value); } } @@ -1563,28 +1575,28 @@ private void angleSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN- }//GEN-LAST:event_angleSpinnerStateChanged private void flipHCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flipHCheckBoxActionPerformed - ArrayList selectedGraphics = viewPanel.selectedGraphics(); - + ArrayList selectedGraphics = viewPanel.selectedGraphics(); + if (selectedGraphics != null) cmdManager.execute(new FlipSpriteListCommand(selectedGraphics, true, viewPanel)); - + AnimationCell cell = this.getWorkingCell(); if (cell != null) cell.rebuild(); - + repaint(); }//GEN-LAST:event_flipHCheckBoxActionPerformed private void flipVCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flipVCheckBoxActionPerformed - ArrayList selectedGraphics = viewPanel.selectedGraphics(); - + ArrayList selectedGraphics = viewPanel.selectedGraphics(); + if (selectedGraphics != null) cmdManager.execute(new FlipSpriteListCommand(selectedGraphics, false, viewPanel)); - + AnimationCell cell = this.getWorkingCell(); if (cell != null) cell.rebuild(); - + repaint(); }//GEN-LAST:event_flipVCheckBoxActionPerformed @@ -1598,11 +1610,11 @@ private void spriteListToggleActionPerformed(java.awt.event.ActionEvent evt) {// private void duplicateAnimationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_duplicateAnimationButtonActionPerformed Animation currentAnimation = this.getWorkingAnimation(); - + if (currentAnimation != null) { - Animation copy = currentAnimation.copy(); - this.addAnimation(copy); + Animation copy = currentAnimation.copy(); + this.addAnimation(copy); } }//GEN-LAST:event_duplicateAnimationButtonActionPerformed @@ -1611,7 +1623,7 @@ private void exportGifButtonActionPerformed(java.awt.event.ActionEvent evt) {//G }//GEN-LAST:event_exportGifButtonActionPerformed public void saveGifAs() - { + { JFileChooser chooser = fileChooser; CustomFilter filter = new CustomFilter(); @@ -1622,7 +1634,7 @@ public void saveGifAs() chooser.setApproveButtonText("Export"); chooser.setDialogTitle("Export animation as GIF"); chooser.setSelectedFile(new File(this.getWorkingAnimation().getName() + "." + CustomFilter.EXT_GIF)); - + JFrame mainFrame = dfEditorApp.getApplication().getMainFrame(); while (true) { @@ -1646,47 +1658,47 @@ public void saveGifAs() continue; } - buildAnimatedGif(f.getAbsolutePath()); + buildAnimatedGif(f.getAbsolutePath()); } break; - } + } } - + public void animatedToCell(AnimationCell aCell) { animationPanel1.setCell(aCell); } - + private void setOnionSkins(boolean bOn) { if (!bOn) { - viewPanel.setOnionSkins(null); + viewPanel.setOnionSkins(null); return; } - + Animation animation = this.getWorkingAnimation(); AnimationCell[] cells = null; - + if (animation != null) - { + { int currentIndex = animation.indexOfCell(workingCell); if (currentIndex > 0) - { + { cells = new AnimationCell[currentIndex]; for (int i=0; i animations = null; - try + try { animations = aReader.getAnimations(spriteTree, bufferedImage); } catch (Exception e) { - showParseError(); + showParseError(); } if (animations != null) @@ -1815,7 +1827,7 @@ public boolean load(AnimationSetReader aReader) return true; } - + return false; } @@ -1824,17 +1836,17 @@ public void stripIndexSelected(int aIndex) removeCellButton.setEnabled(aIndex >= 0); addCellButton.setEnabled(true); } - + private void updateControlPanel(GraphicPanel aPanel) - { + { ArrayList sprites = aPanel.selectedGraphics(); boolean bEnabled = (sprites.size() > 0); - - //try { - //controlPanel.setSelected(bEnabled); // steals focus - modifySpriteToggle.setSelected(controlPanel.isVisible()); + + //try { + //controlPanel.setSelected(bEnabled); // steals focus + modifySpriteToggle.setSelected(controlPanel.isVisible()); //} catch (java.beans.PropertyVetoException e) {} - + removeSpriteButton.setEnabled(bEnabled); rotateACWButton.setEnabled(bEnabled); rotateCWButton.setEnabled(bEnabled); @@ -1842,40 +1854,40 @@ private void updateControlPanel(GraphicPanel aPanel) angleSpinner.setEnabled(bEnabled); flipVCheckBox.setEnabled(bEnabled); flipHCheckBox.setEnabled(bEnabled); - + boolean bSetZ = true; boolean bSetA = true; - + AnimationCell cell = this.getWorkingCell(); - for (int i=0; i 0) + if (i > 0) { if ( cell.zOrderOfGraphic(sprites.get(i)) != cell.zOrderOfGraphic(sprites.get(i-1))) - { - zOrderSpinner.setValue(null); - bSetZ = false; + { + zOrderSpinner.setValue(null); + bSetZ = false; } - + if ((int)sprites.get(i).getAngle() != (int)sprites.get(i-1).getAngle()) { - bSetA = false; + bSetA = false; } } } - + //zOrderSpinner.setEnabled(bSetZ); - - for (int i=0; i aGraphics) { Animation animation = getWorkingAnimation(); AnimationCell cell = animationStripPanel.selectedCell(); - + ArrayList commands = new ArrayList(); - for (int i=0; i 0) { Animation selectedAnimation = (Animation)model.get(selectedIndices[0]); @@ -2005,7 +2017,7 @@ public void valueChanged(ListSelectionEvent e) removeAnimationButton.setEnabled(bEnabled); duplicateAnimationButton.setEnabled(bEnabled); exportGifButton.setEnabled(bEnabled); - } + } else if (list == spriteList) { DefaultListModel model = (DefaultListModel)spriteList.getModel(); @@ -2024,8 +2036,8 @@ else if (list == spriteList) { GraphicObject graphic = (GraphicObject)model.getElementAt(i); if (graphic.isSelected()) - { - viewPanel.selectGraphic(graphic, false); + { + viewPanel.selectGraphic(graphic, false); } } } @@ -2044,8 +2056,8 @@ else if (list == spriteList) // internal frame listener callbacks public void internalFrameOpened(InternalFrameEvent e) {} - public void internalFrameClosing(InternalFrameEvent e) {} - public void internalFrameClosed(InternalFrameEvent e) {} + public void internalFrameClosing(InternalFrameEvent e) {} + public void internalFrameClosed(InternalFrameEvent e) {} public void internalFrameIconified(InternalFrameEvent e) {} public void internalFrameDeiconified(InternalFrameEvent e) {} public void internalFrameActivated(InternalFrameEvent e) {} @@ -2056,78 +2068,78 @@ public void internalFrameDeactivated(InternalFrameEvent e) if (e.getSource() == spriteListControlPanel) spriteListToggle.setSelected(false); } - + private class RollOverSpinModel extends javax.swing.SpinnerNumberModel { public RollOverSpinModel(int aValue, int aMin, int aMax, int aStepSize) { super(aValue, aMin, aMax, aStepSize); } - - public Object getNextValue() + + public Object getNextValue() { Integer i = (Integer)super.getNextValue(); Integer max = (Integer)this.getMaximum(); - + if (i== null) return new Integer(this.getStepSize().intValue()); if (i.intValue() >= max.intValue()) { return new Integer(i.intValue() % max.intValue()); } - + return i; } - - public Object getPreviousValue() + + public Object getPreviousValue() { Object o = super.getPreviousValue(); if (o != null) return o; - + return new Integer (((Integer)this.getMaximum()).intValue() - this.getStepSize().intValue()); - + } } - - private class CustomSpinModel extends AbstractSpinnerModel + + private class CustomSpinModel extends AbstractSpinnerModel { protected String value = ""; - public void setValue(Object o) + public void setValue(Object o) { - if (o != null) - value = o.toString(); + if (o != null) + value = o.toString(); else - value = " "; - + value = " "; + fireStateChanged(); } - public Object getValue() { return value; } + public Object getValue() { return value; } - public Object getPreviousValue() - { + public Object getPreviousValue() + { Integer i = parse(); if (i == null) return "0"; // default to 0 from indeterminate else return "" + (i.intValue() - 1); } - public Object getNextValue() + public Object getNextValue() { Integer i = parse(); if (i == null) return "0"; // default to 0 from indeterminate else return "" + (i.intValue() + 1); } - private Integer parse() + private Integer parse() { try { return new Integer(value); } catch (NumberFormatException exc) { return null; } } } - - + + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addAnimationButton; private javax.swing.JButton addCellButton; @@ -2161,6 +2173,7 @@ private Integer parse() private javax.swing.JToggleButton modifySpriteToggle; private javax.swing.JCheckBox onionSkinsCheckBox; private javax.swing.JButton playButton; + private javax.swing.JSpinner previewDelaySpinner; private javax.swing.JButton removeAnimationButton; private javax.swing.JButton removeCellButton; private javax.swing.JButton removeSpriteButton; diff --git a/src/dfEditor/animation/AnimationStripPanel.java b/src/dfEditor/animation/AnimationStripPanel.java index 420d5ba..7c918ff 100644 --- a/src/dfEditor/animation/AnimationStripPanel.java +++ b/src/dfEditor/animation/AnimationStripPanel.java @@ -1,6 +1,6 @@ -/* +/* * Copyright 2012 Samuel Taylor - * + * * This file is part of darkFunction Editor * * darkFunction Editor is free software: you can redistribute it and/or modify @@ -46,7 +46,7 @@ * @author s4m20 */ public class AnimationStripPanel extends javax.swing.JPanel implements AnimationDataListener, MouseMotionListener, MouseListener, ActionListener -{ +{ private Animation animation = null; private ArrayList slotList = null; private AnimationController controller = null; @@ -64,7 +64,7 @@ public AnimationStripPanel() super(); slotList = new ArrayList(); - addMouseListener(this); + addMouseListener(this); addMouseMotionListener(this); Dimension d = new Dimension(0,0); @@ -104,7 +104,7 @@ public void setCommandManager(CommandManager aManager) { this.commandManager = aManager; } - + public void cellAdded(Animation aAnimation, AnimationCell aCell) { if (aAnimation == animation) @@ -120,7 +120,7 @@ public void cellRemoved(Animation aAnimation, AnimationCell aCell) setAnimation(aAnimation); // rebuilds slot positions } } - + public void cellOrderChanged(Animation aAnimation) { if (aAnimation == animation) @@ -226,7 +226,7 @@ public void paintComponent(Graphics g) for (int i=0; i= 0) { orderChanged = true; animation.moveCell(i, insertBeforeSlotIndex); - // TODO: do a command for this + // TODO: do a command for this } - } - + } + // relayout slots if (orderChanged) { @@ -551,7 +554,7 @@ public void mouseReleased(MouseEvent evt) if (orderChanged && insertBeforeSlotIndex < slotList.size()) slotList.get(insertBeforeSlotIndex).setSelected(true); - insertBeforeSlotIndex = -1; + insertBeforeSlotIndex = -1; } public void mouseExited(MouseEvent evt) @@ -576,7 +579,7 @@ private class Slot { static final int MARGIN = 3; - private AnimationCell cell; + private AnimationCell cell; private Rectangle innerRect; private boolean isSelected; private boolean isDragged; @@ -623,8 +626,8 @@ public void setDragged(boolean aDragged) { isDragged = aDragged; - if (aDragged) - dragImage = createTranslucentCopy(); + if (aDragged) + dragImage = createTranslucentCopy(); else dragImage = null; } @@ -661,25 +664,25 @@ public void draw(Graphics g) this.drawCellInRect(cell, g, innerRect); } - + // scales to fit inside rect amd centres it private void drawCellInRect(final AnimationCell aCell, final Graphics aGraphics, final Rectangle aRect) { Rectangle r = new Rectangle(aRect.x, aRect.y, aRect.width, aRect.height); - + Point size = aCell.getImageSize(); int w = size.x; int h = size.y; float aspectRatio = (float)w / (float)h; - + if (w > h) { int oldHeight = r.height; r.height /= aspectRatio; - r.y += (oldHeight - r.height)/2; + r.y += (oldHeight - r.height)/2; } else if (h > w) - { + { int oldWidth = r.width; r.width *= aspectRatio; r.x += (oldWidth - r.width)/2; @@ -696,9 +699,9 @@ private BufferedImage createTranslucentCopy() g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); this.drawCellInRect(cell, g, new Rectangle(0, 0, img.getWidth(), img.getHeight())); - + g.dispose(); - + return img; } From 74686a3d2aad7e8e8e4b9c7b8e4089b32f21304e Mon Sep 17 00:00:00 2001 From: twig Date: Fri, 18 Apr 2014 21:54:28 +1000 Subject: [PATCH 2/3] revert changes to spacing --- .../animation/AnimationController.java | 21 +++++++++++++++---- .../animation/AnimationStripPanel.java | 19 ++++++++++------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/dfEditor/animation/AnimationController.java b/src/dfEditor/animation/AnimationController.java index 85b999f..d8090ff 100644 --- a/src/dfEditor/animation/AnimationController.java +++ b/src/dfEditor/animation/AnimationController.java @@ -328,6 +328,7 @@ private void initComponents() { jPanel2 = new javax.swing.JPanel(); animationPanel1 = new dfEditor.animation.AnimationPanel(); playButton = new javax.swing.JButton(); + previewDelaySpinner = new javax.swing.JSpinner(); jPanel3 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); delaySpinner = new javax.swing.JSpinner(); @@ -512,18 +513,31 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { } }); + // Set the preview delay to something sensible (default was 30 before) + previewDelaySpinner.setValue(500); + previewDelaySpinner.setMaximumSize(new java.awt.Dimension(30, 30)); + previewDelaySpinner.setName("previewDelayspinner"); // NOI18N + previewDelaySpinner.addChangeListener(new javax.swing.event.ChangeListener() { + public void stateChanged(javax.swing.event.ChangeEvent evt) { +// TODO: loopSpinnerStateChanged(evt); + } + }); + + javax.swing.GroupLayout animationPanel1Layout = new javax.swing.GroupLayout(animationPanel1); animationPanel1.setLayout(animationPanel1Layout); animationPanel1Layout.setHorizontalGroup( animationPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, animationPanel1Layout.createSequentialGroup() .addContainerGap(131, Short.MAX_VALUE) + .addComponent(previewDelaySpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(playButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) ); animationPanel1Layout.setVerticalGroup( animationPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, animationPanel1Layout.createSequentialGroup() .addContainerGap(115, Short.MAX_VALUE) + .addComponent(previewDelaySpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(playButton, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)) ); @@ -1265,21 +1279,19 @@ private void delaySpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN- if (workingCell != null) { - int value = (Integer)spinner.getValue(); + int value = (Integer)spinner.getValue(); workingCell.setDelay(value); spinner.setValue(workingCell.getDelay()); } }//GEN-LAST:event_delaySpinnerStateChanged private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playButtonActionPerformed - Animation animation = getWorkingAnimation(); - animationStripPanel.addAnimationStripListener(this); boolean playing = animationStripPanel.isPlaying(); if (!playing) - animationStripPanel.play(); + animationStripPanel.play((Integer) previewDelaySpinner.getValue()); else animationStripPanel.stop(); @@ -2161,6 +2173,7 @@ private Integer parse() private javax.swing.JToggleButton modifySpriteToggle; private javax.swing.JCheckBox onionSkinsCheckBox; private javax.swing.JButton playButton; + private javax.swing.JSpinner previewDelaySpinner; private javax.swing.JButton removeAnimationButton; private javax.swing.JButton removeCellButton; private javax.swing.JButton removeSpriteButton; diff --git a/src/dfEditor/animation/AnimationStripPanel.java b/src/dfEditor/animation/AnimationStripPanel.java index 420d5ba..dacd6cf 100644 --- a/src/dfEditor/animation/AnimationStripPanel.java +++ b/src/dfEditor/animation/AnimationStripPanel.java @@ -333,16 +333,14 @@ private int getSelectedSlotIndex() return -1; } - public void play() + public void play(int timeout) { if (slotList.size() == 0) return; - + currentLoop = animation.getLoops(); - - if (timer == null) - timer = new Timer(30, this); + timer = new Timer(timeout, this); timer.start(); currentSlotInAnimation = getSelectedSlotIndex(); @@ -358,9 +356,11 @@ public void play() public void stop() { - if (timer != null) + if (timer != null) { timer.stop(); - + timer = null; + } + currentSlotInAnimation = -1; repaint(); @@ -400,13 +400,16 @@ private void notifyTick() { currentSlotInAnimation = 0; } - + for (int i=0; i Date: Fri, 18 Apr 2014 22:07:45 +1000 Subject: [PATCH 3/3] undo spacing trim by Eclipse --- .../animation/AnimationController.java | 466 +++++++++--------- .../animation/AnimationStripPanel.java | 64 +-- 2 files changed, 265 insertions(+), 265 deletions(-) diff --git a/src/dfEditor/animation/AnimationController.java b/src/dfEditor/animation/AnimationController.java index 2bbce8c..d8090ff 100644 --- a/src/dfEditor/animation/AnimationController.java +++ b/src/dfEditor/animation/AnimationController.java @@ -1,6 +1,6 @@ -/* +/* * Copyright 2009 Samuel Taylor - * + * * This file is part of darkFunction Editor * * darkFunction Editor is free software: you can redistribute it and/or modify @@ -64,7 +64,7 @@ public class AnimationController extends dfEditorPanel implements InternalFrameListener { private BufferedImage bufferedImage = null; - private AnimationCell workingCell = null; + private AnimationCell workingCell = null; private File loadedSpritesheetFile = null; private Timer spinnerStateTimer = null; ArrayList _rotatingGraphics = null; @@ -78,23 +78,23 @@ public AnimationController(CommandManager aCmdManager, boolean aNew, JLabel aHel viewPanel.addGraphicChangeListener(this); animationStripPanel.setController(this); - + animationStripPanel.setCommandManager(aCmdManager); viewPanel.setCommandManager(aCmdManager); - animationList.addListSelectionListener(this); - + animationList.addListSelectionListener(this); + spriteList.addListSelectionListener(this); spriteList.addNodeDroppedListener(this); spriteList.setDragSource(spriteTree); - - spriteTree.addTreeListener(this); + + spriteTree.addTreeListener(this); viewPanel.addNodeDroppedListener(this); viewPanel.setDragSource(spriteTree); controlPanel.addInternalFrameListener(this); spriteListControlPanel.addInternalFrameListener(this); - + setWorkingCell(null); if (aNew) @@ -105,10 +105,10 @@ public void run() { } }); } - - viewPanel.requestFocus(); - - postInit(); + + viewPanel.requestFocus(); + + postInit(); } private void showSpritesheetChooser() @@ -120,7 +120,7 @@ private void showSpritesheetChooser() chooser.resetChoosableFileFilters(); chooser.setFileFilter(filter); chooser.setDialogTitle("Select spritesheet"); - + JFrame mainFrame = dfEditorApp.getApplication().getMainFrame(); int returnVal = chooser.showOpenDialog(mainFrame); if(returnVal == JFileChooser.APPROVE_OPTION) @@ -133,7 +133,7 @@ private void setSpritesheetFile(File aFile) { SpritesheetReader reader = new SpritesheetReader(aFile); loadedSpritesheetFile = aFile; - + try { String imgPath = reader.getImagePath(); @@ -159,21 +159,21 @@ private void setSpritesheetFile(File aFile) return; } } - + private void buildAnimatedGif(String filePath) { Animation animation = this.getWorkingAnimation(); - + if (animation != null && animation.numCells() > 0) { Rectangle firstCellRect = animation.getCellAtIndex(0).getSpreadRect(); Point topLeft = new Point(firstCellRect.x, firstCellRect.y); Point bottomRight = new Point(firstCellRect.x + firstCellRect.width, firstCellRect.y + firstCellRect.height); - + for (int i=1; i bottomRight.x) bottomRight.x = r.x + r.width; if (r.y + r.height > bottomRight.y) - bottomRight.y = r.y + r.height; + bottomRight.y = r.y + r.height; } - + AnimatedGifEncoder e = new AnimatedGifEncoder(); e.setTransparent(new Color(0,0,0,0)); - e.start(filePath); + e.start(filePath); e.setRepeat(animation.getLoops()); e.setQuality(1); e.setSize(bottomRight.x - topLeft.x, bottomRight.y - topLeft.y); - + for (int i=0; i addNodeToCell(CustomNode aNode, AnimationCell a { if (aNode == null) return null; - + if (aNode.isLeaf()) { if (aCell != null) @@ -1168,11 +1168,11 @@ private ArrayList addNodeToCell(CustomNode aNode, AnimationCell a if (aCell != null) aCell.rebuild(); - + animationStripPanel.repaint(); - + return aGraphics; - + // } @@ -1190,10 +1190,10 @@ public void nodeDropped(java.awt.Component aComponent, String aNodePath, Point a private void addAnimation(final Animation aAnimation) { boolean bExists = false; - String name = aAnimation.getName(); + String name = aAnimation.getName(); int animationNameCounter = 1; do - { + { bExists = false; for (int i=0; i= 0) { animationStripPanel.stop(); cmdManager.execute(new RemoveAnimationCommand(animationList, (Animation)animationList.getModel().getElementAt(index))); - } + } }//GEN-LAST:event_removeAnimationButtonActionPerformed private Animation getWorkingAnimation() @@ -1301,17 +1301,17 @@ private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI }//GEN-LAST:event_playButtonActionPerformed private void spriteTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_spriteTreeValueChanged - + int numSelected = 0; if (spriteTree.getSelectedNodes() != null) numSelected = spriteTree.getSelectedNodes().length; - + CustomNode node = (CustomNode)spriteTree.getLastSelectedPathComponent(); boolean bSelected = (node != null); - + addToFrameButton.setEnabled(bSelected); - + if (bSelected) { if (numSelected == 1 && node.isLeaf()) @@ -1323,7 +1323,7 @@ private void spriteTreeValueChanged(javax.swing.event.TreeSelectionEvent evt) {/ spritePreviewTitle.setText(node.getFullPathName()); } else if (numSelected > 1 || !node.isLeaf()) - { + { spritePreviewTitle.setHorizontalTextPosition(JLabel.CENTER); spritePreviewTitle.setText(""); spritePreviewPanel.setGraphic(null); @@ -1334,7 +1334,7 @@ else if (numSelected > 1 || !node.isLeaf()) spritePreviewTitle.setText(" "); spritePreviewPanel.setGraphic(null); } - + spritePreviewPanel.repaint(); }//GEN-LAST:event_spriteTreeValueChanged @@ -1365,9 +1365,9 @@ private void removeSpriteButtonActionPerformed(java.awt.event.ActionEvent evt) { ArrayList selectedGraphics = viewPanel.selectedGraphics(); ArrayList commands = new ArrayList(); - for (int i=0; i selectedGraphics = viewPanel.selectedGraphics(); - + cmdManager.execute(new RotateGraphicListCommand(selectedGraphics, 90.0f, viewPanel)); - + this.getWorkingCell().rebuild(); repaint(); }//GEN-LAST:event_rotateCWButtonActionPerformed private void rotateACWButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rotateACWButtonActionPerformed ArrayList selectedGraphics = viewPanel.selectedGraphics(); - + cmdManager.execute(new RotateGraphicListCommand(selectedGraphics, -90.0f, viewPanel)); - + this.getWorkingCell().rebuild(); repaint();}//GEN-LAST:event_rotateACWButtonActionPerformed private void zOrderSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_zOrderSpinnerStateChanged - + ArrayList selectedGraphics = viewPanel.selectedGraphics(); AnimationCell cell = this.getWorkingCell(); - + if (cell != null && selectedGraphics != null && selectedGraphics.size() > 0) { ArrayList commands = new ArrayList(); - + for (int i=0; i selected = null; - + if (aCell == getWorkingCell()) selected = viewPanel.selectedGraphics(); - + DefaultListModel model = (DefaultListModel)spriteList.getModel(); model.clear(); - + if (aCell != null) { ArrayList array = aCell.getGraphicList(); @@ -1460,112 +1460,112 @@ private void populateSpriteListFromCell(AnimationCell aCell) { array.get(i).setDescription(aCell.nodeForGraphic(array.get(i)).getFullPathName()); model.addElement(array.get(i)); - array.get(i).setDescription(aCell.nodeForGraphic(array.get(i)).getFullPathName()); + array.get(i).setDescription(aCell.nodeForGraphic(array.get(i)).getFullPathName()); } - + if (selected != null) { - int[] indices = new int[selected.size()]; + int[] indices = new int[selected.size()]; for (int i=0; i commands = new ArrayList(); AnimationCell cell = this.getWorkingCell(); - + if (cell != null && _rotatingGraphics != null && _rotatingGraphics.size() > 0) - { + { for (int i=0; i<_rotatingGraphics.size(); ++i) { Integer val = null; - try - { + try + { val = (Integer)angleSpinner.getValue(); } catch (NumberFormatException exc){} - if (val != null) + if (val != null) { int value = val.intValue(); GraphicObject graphic = _rotatingGraphics.get(i); if (value != graphic.getSavedAngle()) - { - commands.add(new SetGraphicAngleCommand(graphic, value, viewPanel)); + { + commands.add(new SetGraphicAngleCommand(graphic, value, viewPanel)); } } } } - + GroupedUndoableCommand groupedCommand = new GroupedUndoableCommand(commands); if (cmdManager != null) cmdManager.execute(groupedCommand); else groupedCommand.execute(); - - this.setModified(true); - + + this.setModified(true); + getWorkingCell().rebuild(); animationStripPanel.repaint(); - + _rotatingGraphics = null; } - + private void angleSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_angleSpinnerStateChanged - + if (spinnerStateTimer == null) { spinnerStateTimer = new Timer(400, this); spinnerStateTimer.setRepeats(false); spinnerStateTimer.setActionCommand(null); } - + if (!spinnerStateTimer.isRunning()) - { - spinnerStateTimer.start(); + { + spinnerStateTimer.start(); } else spinnerStateTimer.restart(); - + _rotatingGraphics = viewPanel.selectedGraphics(); - AnimationCell cell = this.getWorkingCell(); + AnimationCell cell = this.getWorkingCell(); if (cell != null && _rotatingGraphics != null && _rotatingGraphics.size() > 0) - { + { for (int i=0; i<_rotatingGraphics.size(); ++i) { Integer val = null; - - try - { + + try + { val = (Integer)angleSpinner.getValue(); } catch (NumberFormatException exc){} - - if (val != null) + + if (val != null) { int value = val.intValue(); GraphicObject graphic = _rotatingGraphics.get(i); - + if (value != graphic.getAngle()) - { + { graphic.setAngle(value); } } @@ -1575,28 +1575,28 @@ private void angleSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN- }//GEN-LAST:event_angleSpinnerStateChanged private void flipHCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flipHCheckBoxActionPerformed - ArrayList selectedGraphics = viewPanel.selectedGraphics(); - + ArrayList selectedGraphics = viewPanel.selectedGraphics(); + if (selectedGraphics != null) cmdManager.execute(new FlipSpriteListCommand(selectedGraphics, true, viewPanel)); - + AnimationCell cell = this.getWorkingCell(); if (cell != null) cell.rebuild(); - + repaint(); }//GEN-LAST:event_flipHCheckBoxActionPerformed private void flipVCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flipVCheckBoxActionPerformed - ArrayList selectedGraphics = viewPanel.selectedGraphics(); - + ArrayList selectedGraphics = viewPanel.selectedGraphics(); + if (selectedGraphics != null) cmdManager.execute(new FlipSpriteListCommand(selectedGraphics, false, viewPanel)); - + AnimationCell cell = this.getWorkingCell(); if (cell != null) cell.rebuild(); - + repaint(); }//GEN-LAST:event_flipVCheckBoxActionPerformed @@ -1610,11 +1610,11 @@ private void spriteListToggleActionPerformed(java.awt.event.ActionEvent evt) {// private void duplicateAnimationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_duplicateAnimationButtonActionPerformed Animation currentAnimation = this.getWorkingAnimation(); - + if (currentAnimation != null) { - Animation copy = currentAnimation.copy(); - this.addAnimation(copy); + Animation copy = currentAnimation.copy(); + this.addAnimation(copy); } }//GEN-LAST:event_duplicateAnimationButtonActionPerformed @@ -1623,7 +1623,7 @@ private void exportGifButtonActionPerformed(java.awt.event.ActionEvent evt) {//G }//GEN-LAST:event_exportGifButtonActionPerformed public void saveGifAs() - { + { JFileChooser chooser = fileChooser; CustomFilter filter = new CustomFilter(); @@ -1634,7 +1634,7 @@ public void saveGifAs() chooser.setApproveButtonText("Export"); chooser.setDialogTitle("Export animation as GIF"); chooser.setSelectedFile(new File(this.getWorkingAnimation().getName() + "." + CustomFilter.EXT_GIF)); - + JFrame mainFrame = dfEditorApp.getApplication().getMainFrame(); while (true) { @@ -1658,47 +1658,47 @@ public void saveGifAs() continue; } - buildAnimatedGif(f.getAbsolutePath()); + buildAnimatedGif(f.getAbsolutePath()); } break; - } + } } - + public void animatedToCell(AnimationCell aCell) { animationPanel1.setCell(aCell); } - + private void setOnionSkins(boolean bOn) { if (!bOn) { - viewPanel.setOnionSkins(null); + viewPanel.setOnionSkins(null); return; } - + Animation animation = this.getWorkingAnimation(); AnimationCell[] cells = null; - + if (animation != null) - { + { int currentIndex = animation.indexOfCell(workingCell); if (currentIndex > 0) - { + { cells = new AnimationCell[currentIndex]; for (int i=0; i animations = null; - try + try { animations = aReader.getAnimations(spriteTree, bufferedImage); } catch (Exception e) { - showParseError(); + showParseError(); } if (animations != null) @@ -1827,7 +1827,7 @@ public boolean load(AnimationSetReader aReader) return true; } - + return false; } @@ -1836,17 +1836,17 @@ public void stripIndexSelected(int aIndex) removeCellButton.setEnabled(aIndex >= 0); addCellButton.setEnabled(true); } - + private void updateControlPanel(GraphicPanel aPanel) - { + { ArrayList sprites = aPanel.selectedGraphics(); boolean bEnabled = (sprites.size() > 0); - - //try { - //controlPanel.setSelected(bEnabled); // steals focus - modifySpriteToggle.setSelected(controlPanel.isVisible()); + + //try { + //controlPanel.setSelected(bEnabled); // steals focus + modifySpriteToggle.setSelected(controlPanel.isVisible()); //} catch (java.beans.PropertyVetoException e) {} - + removeSpriteButton.setEnabled(bEnabled); rotateACWButton.setEnabled(bEnabled); rotateCWButton.setEnabled(bEnabled); @@ -1854,40 +1854,40 @@ private void updateControlPanel(GraphicPanel aPanel) angleSpinner.setEnabled(bEnabled); flipVCheckBox.setEnabled(bEnabled); flipHCheckBox.setEnabled(bEnabled); - + boolean bSetZ = true; boolean bSetA = true; - + AnimationCell cell = this.getWorkingCell(); - for (int i=0; i 0) + if (i > 0) { if ( cell.zOrderOfGraphic(sprites.get(i)) != cell.zOrderOfGraphic(sprites.get(i-1))) - { - zOrderSpinner.setValue(null); - bSetZ = false; + { + zOrderSpinner.setValue(null); + bSetZ = false; } - + if ((int)sprites.get(i).getAngle() != (int)sprites.get(i-1).getAngle()) { - bSetA = false; + bSetA = false; } } } - + //zOrderSpinner.setEnabled(bSetZ); - - for (int i=0; i aGraphics) { Animation animation = getWorkingAnimation(); AnimationCell cell = animationStripPanel.selectedCell(); - + ArrayList commands = new ArrayList(); - for (int i=0; i 0) { Animation selectedAnimation = (Animation)model.get(selectedIndices[0]); @@ -2017,7 +2017,7 @@ public void valueChanged(ListSelectionEvent e) removeAnimationButton.setEnabled(bEnabled); duplicateAnimationButton.setEnabled(bEnabled); exportGifButton.setEnabled(bEnabled); - } + } else if (list == spriteList) { DefaultListModel model = (DefaultListModel)spriteList.getModel(); @@ -2036,8 +2036,8 @@ else if (list == spriteList) { GraphicObject graphic = (GraphicObject)model.getElementAt(i); if (graphic.isSelected()) - { - viewPanel.selectGraphic(graphic, false); + { + viewPanel.selectGraphic(graphic, false); } } } @@ -2056,8 +2056,8 @@ else if (list == spriteList) // internal frame listener callbacks public void internalFrameOpened(InternalFrameEvent e) {} - public void internalFrameClosing(InternalFrameEvent e) {} - public void internalFrameClosed(InternalFrameEvent e) {} + public void internalFrameClosing(InternalFrameEvent e) {} + public void internalFrameClosed(InternalFrameEvent e) {} public void internalFrameIconified(InternalFrameEvent e) {} public void internalFrameDeiconified(InternalFrameEvent e) {} public void internalFrameActivated(InternalFrameEvent e) {} @@ -2068,78 +2068,78 @@ public void internalFrameDeactivated(InternalFrameEvent e) if (e.getSource() == spriteListControlPanel) spriteListToggle.setSelected(false); } - + private class RollOverSpinModel extends javax.swing.SpinnerNumberModel { public RollOverSpinModel(int aValue, int aMin, int aMax, int aStepSize) { super(aValue, aMin, aMax, aStepSize); } - - public Object getNextValue() + + public Object getNextValue() { Integer i = (Integer)super.getNextValue(); Integer max = (Integer)this.getMaximum(); - + if (i== null) return new Integer(this.getStepSize().intValue()); if (i.intValue() >= max.intValue()) { return new Integer(i.intValue() % max.intValue()); } - + return i; } - - public Object getPreviousValue() + + public Object getPreviousValue() { Object o = super.getPreviousValue(); if (o != null) return o; - + return new Integer (((Integer)this.getMaximum()).intValue() - this.getStepSize().intValue()); - + } } - - private class CustomSpinModel extends AbstractSpinnerModel + + private class CustomSpinModel extends AbstractSpinnerModel { protected String value = ""; - public void setValue(Object o) + public void setValue(Object o) { - if (o != null) - value = o.toString(); + if (o != null) + value = o.toString(); else - value = " "; - + value = " "; + fireStateChanged(); } - public Object getValue() { return value; } + public Object getValue() { return value; } - public Object getPreviousValue() - { + public Object getPreviousValue() + { Integer i = parse(); if (i == null) return "0"; // default to 0 from indeterminate else return "" + (i.intValue() - 1); } - public Object getNextValue() + public Object getNextValue() { Integer i = parse(); if (i == null) return "0"; // default to 0 from indeterminate else return "" + (i.intValue() + 1); } - private Integer parse() + private Integer parse() { try { return new Integer(value); } catch (NumberFormatException exc) { return null; } } } - - + + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton addAnimationButton; private javax.swing.JButton addCellButton; diff --git a/src/dfEditor/animation/AnimationStripPanel.java b/src/dfEditor/animation/AnimationStripPanel.java index 7c918ff..dacd6cf 100644 --- a/src/dfEditor/animation/AnimationStripPanel.java +++ b/src/dfEditor/animation/AnimationStripPanel.java @@ -1,6 +1,6 @@ -/* +/* * Copyright 2012 Samuel Taylor - * + * * This file is part of darkFunction Editor * * darkFunction Editor is free software: you can redistribute it and/or modify @@ -46,7 +46,7 @@ * @author s4m20 */ public class AnimationStripPanel extends javax.swing.JPanel implements AnimationDataListener, MouseMotionListener, MouseListener, ActionListener -{ +{ private Animation animation = null; private ArrayList slotList = null; private AnimationController controller = null; @@ -64,7 +64,7 @@ public AnimationStripPanel() super(); slotList = new ArrayList(); - addMouseListener(this); + addMouseListener(this); addMouseMotionListener(this); Dimension d = new Dimension(0,0); @@ -104,7 +104,7 @@ public void setCommandManager(CommandManager aManager) { this.commandManager = aManager; } - + public void cellAdded(Animation aAnimation, AnimationCell aCell) { if (aAnimation == animation) @@ -120,7 +120,7 @@ public void cellRemoved(Animation aAnimation, AnimationCell aCell) setAnimation(aAnimation); // rebuilds slot positions } } - + public void cellOrderChanged(Animation aAnimation) { if (aAnimation == animation) @@ -226,7 +226,7 @@ public void paintComponent(Graphics g) for (int i=0; i= 0) { orderChanged = true; animation.moveCell(i, insertBeforeSlotIndex); - // TODO: do a command for this + // TODO: do a command for this } - } - + } + // relayout slots if (orderChanged) { @@ -554,7 +554,7 @@ public void mouseReleased(MouseEvent evt) if (orderChanged && insertBeforeSlotIndex < slotList.size()) slotList.get(insertBeforeSlotIndex).setSelected(true); - insertBeforeSlotIndex = -1; + insertBeforeSlotIndex = -1; } public void mouseExited(MouseEvent evt) @@ -579,7 +579,7 @@ private class Slot { static final int MARGIN = 3; - private AnimationCell cell; + private AnimationCell cell; private Rectangle innerRect; private boolean isSelected; private boolean isDragged; @@ -626,8 +626,8 @@ public void setDragged(boolean aDragged) { isDragged = aDragged; - if (aDragged) - dragImage = createTranslucentCopy(); + if (aDragged) + dragImage = createTranslucentCopy(); else dragImage = null; } @@ -664,25 +664,25 @@ public void draw(Graphics g) this.drawCellInRect(cell, g, innerRect); } - + // scales to fit inside rect amd centres it private void drawCellInRect(final AnimationCell aCell, final Graphics aGraphics, final Rectangle aRect) { Rectangle r = new Rectangle(aRect.x, aRect.y, aRect.width, aRect.height); - + Point size = aCell.getImageSize(); int w = size.x; int h = size.y; float aspectRatio = (float)w / (float)h; - + if (w > h) { int oldHeight = r.height; r.height /= aspectRatio; - r.y += (oldHeight - r.height)/2; + r.y += (oldHeight - r.height)/2; } else if (h > w) - { + { int oldWidth = r.width; r.width *= aspectRatio; r.x += (oldWidth - r.width)/2; @@ -699,9 +699,9 @@ private BufferedImage createTranslucentCopy() g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); this.drawCellInRect(cell, g, new Rectangle(0, 0, img.getWidth(), img.getHeight())); - + g.dispose(); - + return img; }