[Patchanim-commit] SF.net SVN: patchanim: [87] trunk/patchanim
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-02-03 00:10:30
|
Revision: 87 http://patchanim.svn.sourceforge.net/patchanim/?rev=87&view=rev Author: dbrosius Date: 2008-02-02 16:10:34 -0800 (Sat, 02 Feb 2008) Log Message: ----------- add up down controls for patch list Modified Paths: -------------- trunk/patchanim/build.xml trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchListModel.java Added Paths: ----------- trunk/patchanim/src/com/mebigfatguy/patchanim/down.gif trunk/patchanim/src/com/mebigfatguy/patchanim/up.gif Modified: trunk/patchanim/build.xml =================================================================== --- trunk/patchanim/build.xml 2008-02-02 23:36:35 UTC (rev 86) +++ trunk/patchanim/build.xml 2008-02-03 00:10:34 UTC (rev 87) @@ -63,6 +63,7 @@ <copy todir="${classes.dir}"> <fileset dir="${src.dir}"> <include name="**/*.properties"/> + <include name="**/*.gif"/> </fileset> </copy> </target> Added: trunk/patchanim/src/com/mebigfatguy/patchanim/down.gif =================================================================== (Binary files differ) Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/down.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-02 23:36:35 UTC (rev 86) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchListPanel.java 2008-02-03 00:10:34 UTC (rev 87) @@ -26,6 +26,7 @@ import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JList; @@ -42,12 +43,16 @@ import com.mebigfatguy.patchanim.surface.CombinedPatch; public class JPatchListPanel extends JPanel { - private static final long serialVersionUID = -6673383252840039387L; + private static final long serialVersionUID = -5365174588964238457L; + private static final String UPBUTTON = "/com/mebigfatguy/patchanim/up.gif"; + private static final String DOWNBUTTON = "/com/mebigfatguy/patchanim/down.gif"; private JList patchList; private PatchListModel patchListModel; private JButton addButton; private JButton removeButton; + private JButton upButton; + private JButton downButton; public JPatchListPanel() { initComponents(); @@ -76,7 +81,21 @@ modCtrls.add(Box.createHorizontalStrut(10)); modCtrls.add(removeButton); modCtrls.add(Box.createHorizontalGlue()); - add(modCtrls, BorderLayout.SOUTH); + add(modCtrls, BorderLayout.SOUTH); + + JPanel moveCtrls = new JPanel(); + upButton = new JButton(new ImageIcon(getClass().getResource(UPBUTTON))); + downButton = new JButton(new ImageIcon(getClass().getResource(DOWNBUTTON))); + upButton.setEnabled(false); + downButton.setEnabled(false); + Utils.sizeUniformly(new JComponent[] {upButton, downButton}, Utils.Sizing.Both); + moveCtrls.setLayout(new BoxLayout(moveCtrls, BoxLayout.Y_AXIS)); + moveCtrls.add(Box.createVerticalGlue()); + moveCtrls.add(upButton); + moveCtrls.add(Box.createVerticalStrut(10)); + moveCtrls.add(downButton); + moveCtrls.add(Box.createVerticalGlue()); + add(moveCtrls, BorderLayout.EAST); } private void initListeners() { @@ -89,6 +108,7 @@ patchListModel = new PatchListModel(dce.getDocument()); patchList.setModel(patchListModel); mediator.setNewActivePatch((CombinedPatch)patchListModel.getElementAt(0)); + enabledMovementCtrls(); } }); } @@ -106,6 +126,7 @@ patchListModel.add(selIndex, newPatch); patchList.setSelectedIndex(selIndex); removeButton.setEnabled(patchListModel.getSize() > 1); + enabledMovementCtrls(); } }); @@ -121,10 +142,40 @@ PatchPanelMediator mediator = PatchPanelMediator.getMediator(); mediator.setNewActivePatch((CombinedPatch)patchListModel.getElementAt(selIndex)); removeButton.setEnabled(patchListModel.getSize() > 1); + enabledMovementCtrls(); } } }); + + upButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + int selIndex = patchList.getSelectedIndex(); + if (selIndex > 0) { + CombinedPatch patch = (CombinedPatch) patchListModel.getElementAt(selIndex); + patchListModel.remove(selIndex); + selIndex--; + patchListModel.add(selIndex, patch); + patchList.setSelectedIndex(selIndex); + enabledMovementCtrls(); + } + } + }); + + downButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent ae) { + int selIndex = patchList.getSelectedIndex(); + if ((selIndex >= 0) && (selIndex < (patchListModel.getSize() - 1))) { + CombinedPatch patch = (CombinedPatch) patchListModel.getElementAt(selIndex); + patchListModel.remove(selIndex); + selIndex++; + patchListModel.add(selIndex, patch); + patchList.setSelectedIndex(selIndex); + enabledMovementCtrls(); + } + } + }); + patchList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { @@ -133,9 +184,23 @@ CombinedPatch newPatch = (CombinedPatch)patchListModel.getElementAt(selIndex); PatchPanelMediator mediator = PatchPanelMediator.getMediator(); mediator.setNewActivePatch(newPatch); + enabledMovementCtrls(); } } } }); } + + private void enabledMovementCtrls() { + int selIndex = patchList.getSelectedIndex(); + int lastIndex = patchListModel.getSize() - 1; + + if ((lastIndex <= 0) || (selIndex < 0)) { + upButton.setEnabled(false); + downButton.setEnabled(false); + } else { + upButton.setEnabled(selIndex > 0); + downButton.setEnabled(selIndex < lastIndex); + } + } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchListModel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchListModel.java 2008-02-02 23:36:35 UTC (rev 86) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchListModel.java 2008-02-03 00:10:34 UTC (rev 87) @@ -44,7 +44,7 @@ return; List<CombinedPatch> patches = doc.getPatches(); - patches.add(patch); + patches.add(pos, patch); doc.setDirty(true); fireIntervalAdded(this, pos, pos); } Added: trunk/patchanim/src/com/mebigfatguy/patchanim/up.gif =================================================================== (Binary files differ) Property changes on: trunk/patchanim/src/com/mebigfatguy/patchanim/up.gif ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |