[Patchanim-commit] SF.net SVN: patchanim: [18] trunk/patchanim/src/com/mebigfatguy/patchanim/ gui
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-01-26 06:34:52
|
Revision: 18 http://patchanim.svn.sourceforge.net/patchanim/?rev=18&view=rev Author: dbrosius Date: 2008-01-25 22:34:57 -0800 (Fri, 25 Jan 2008) Log Message: ----------- draw ctrls in yellow so they stand out, and get the edit ctrl working Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java 2008-01-26 06:02:34 UTC (rev 17) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/IntegerDocument.java 2008-01-26 06:34:57 UTC (rev 18) @@ -30,7 +30,7 @@ { private static final long serialVersionUID = -1526356835854424028L; - private static final Pattern INTEGERPATTERN = Pattern.compile("-?(:?[1-9][0-9]*)?"); + private static final Pattern INTEGERPATTERN = Pattern.compile("-?(:?[0-9]*)?"); @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { @@ -38,13 +38,9 @@ String end = getText(offs, this.getLength() - offs); String newIntegerString = (start + str + end).trim(); - if (newIntegerString.length() == 0) - super.insertString(offs, str, a); - else { - Matcher m = INTEGERPATTERN.matcher(newIntegerString); - if (m.matches()) { - super.insertString(offs, str, a); - } + Matcher m = INTEGERPATTERN.matcher(newIntegerString); + if (m.matches()) { + super.insertString(offs, str, a); } } } \ No newline at end of file Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-26 06:02:34 UTC (rev 17) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-01-26 06:34:57 UTC (rev 18) @@ -23,7 +23,6 @@ import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; -import java.awt.image.BufferedImage; import java.util.ResourceBundle; import javax.swing.Box; @@ -32,6 +31,8 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import com.mebigfatguy.patchanim.PatchColor; import com.mebigfatguy.patchanim.main.PatchAnimBundle; @@ -46,13 +47,14 @@ private JPatchSamplePanel sample; private JLabel colorLabel; private JTextField colorField; - private int selectedU; - private int selectedV; + private ValueDocumentListener docListener = new ValueDocumentListener(); + private int selectedXPt; + private int selectedYPt; public JColorControlPatchPanel(PatchColor c) { color = c; - selectedU = 0; - selectedV = 0; + selectedXPt = 0; + selectedYPt = 0; initComponents(); initListeners(); } @@ -64,7 +66,7 @@ sample.setDecorator(this); colorLabel = new JLabel(rb.getString(PatchAnimBundle.COLOR)); - colorField = new JTextField(4); + colorField = new JTextField(new IntegerDocument(), "", 4); add(Box.createVerticalGlue()); JPanel p = new JPanel(); @@ -94,19 +96,24 @@ CombinedPatch currentPatch = apce.getActivePatch(); coords = currentPatch.getPatch(color); if (coords != null) { - setColorField(); + setColorField(false); sample.recalcImage(color, currentPatch); } } - }); + }); + colorField.getDocument().addDocumentListener(docListener); } - private void setColorField() { + private void setColorField(final boolean fireEvents) { SwingUtilities.invokeLater(new Runnable() { public void run() { - Coordinate coord = coords.getCoordinate(selectedU, selectedV); + Coordinate coord = coords.getCoordinate(selectedXPt, selectedYPt); + if (!fireEvents) + colorField.getDocument().removeDocumentListener(docListener); colorField.setText(String.valueOf(coord.getColor())); + if (!fireEvents) + colorField.getDocument().addDocumentListener(docListener); } }); } @@ -115,11 +122,11 @@ if (coords == null) return; - g.setColor(Color.black); + g.setColor(Color.yellow); for (int u = 0; u < 4; u++) { for (int v = 0; v < 4; v++) { Coordinate c = coords.getCoordinate(u, v); - if ((selectedU == u) && (selectedV == v)) { + if ((selectedXPt == u) && (selectedYPt == v)) { g.fillOval(((c.getX() * (bounds.width - 5)) / 100) + bounds.x, ((c.getY() * (bounds.height - 5)) / 100) + bounds.y, 5, 5); } else { g.drawOval(((c.getX() * (bounds.width - 5)) / 100) + bounds.x, ((c.getY() * (bounds.height - 5)) / 100) + bounds.y, 5, 5); @@ -129,13 +136,45 @@ } public void click(Point p, Rectangle bounds) { - int newSelectedU = ((((p.x - bounds.x) * 100) / bounds.width) + 16) / 33; - int newSelectedV = ((((p.y - bounds.y) * 100) / bounds.height) + 16) / 33; - if ((newSelectedU != selectedU) || (newSelectedV != selectedV)) { - selectedU = newSelectedU; - selectedV = newSelectedV; - sample.repaint(); - setColorField(); + int newSelectedXPt = ((((p.x - bounds.x) * 100) / bounds.width) + 16) / 33; + int newSelectedYPt = ((((p.y - bounds.y) * 100) / bounds.height) + 16) / 33; + if ((newSelectedXPt != selectedXPt) || (newSelectedYPt != selectedYPt)) { + selectedXPt = newSelectedXPt; + selectedYPt = newSelectedYPt; + setColorField(false); + invalidate(); + revalidate(); + repaint(); } } + + class ValueDocumentListener implements DocumentListener + { + public void changedUpdate(DocumentEvent de) { + processChange(); + } + + public void insertUpdate(DocumentEvent de) { + processChange(); + } + + public void removeUpdate(DocumentEvent de) { + processChange(); + } + + private void processChange() { + int value; + String color = colorField.getText(); + if (color.length() == 0) + value = 0; + else + value = Integer.parseInt(colorField.getText()); + + Coordinate coord = coords.getCoordinate(selectedXPt, selectedYPt); + coord.setColor(value); + coords.setCoordinate(selectedXPt, selectedYPt, coord); + PatchPanelMediator mediator = PatchPanelMediator.getMediator(); + mediator.setNewActivePatch(mediator.getActivePatch()); + } + } } Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java 2008-01-26 06:02:34 UTC (rev 17) +++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java 2008-01-26 06:34:57 UTC (rev 18) @@ -28,6 +28,7 @@ private static final PatchPanelMediator mediator = new PatchPanelMediator(); private PatchAnimDocument document; + private CombinedPatch activePatch; private Set<DocumentChangedListener> dclisteners = new HashSet<DocumentChangedListener>(); private Set<ActivePatchChangedListener> apclisteners = new HashSet<ActivePatchChangedListener>(); @@ -53,7 +54,12 @@ apclisteners.add(apcl); } + public CombinedPatch getActivePatch() { + return activePatch; + } + public void setNewActivePatch(CombinedPatch patch) { + activePatch = patch; ActivePatchChangedEvent apce = new ActivePatchChangedEvent(this, patch); for (ActivePatchChangedListener apcl : apclisteners) { apcl.activePatchChanged(apce); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |