diff --git a/Lib/src/com/yarcat/chemistrylines/view/FieldHightlights.java b/Lib/src/com/yarcat/chemistrylines/view/FieldHightlights.java index b14f891..d64d31d 100644 --- a/Lib/src/com/yarcat/chemistrylines/view/FieldHightlights.java +++ b/Lib/src/com/yarcat/chemistrylines/view/FieldHightlights.java @@ -5,14 +5,14 @@ import com.yarcat.chemistrylines.algorithms.Path; import com.yarcat.chemistrylines.field.Field; -import com.yarcat.chemistrylines.view.SelectionInView.SelectionListener; +import com.yarcat.chemistrylines.view.SelectionInView; -public class FieldHightlights implements SelectionListener { +public class FieldHightlights implements SelectionInView.Listener { // @formatter:off public enum Mark { - SelectedAsSource, - SelectedAsDestination, - ReachableFromSource, + SOURCE, + TARGET, + REACHABLE, } // @formatter:on @@ -47,24 +47,24 @@ public boolean hasMark(int n, Mark m) { @Override public void onNewSource(int n) { - setMark(n, Mark.SelectedAsSource); + setMark(n, Mark.SOURCE); markCellsReachableFrom(n); } @Override public void onNewTarget(int n) { - setMark(n, Mark.SelectedAsDestination); + setMark(n, Mark.TARGET); } @Override public void onSourceCleared(int n) { - clearMark(n, Mark.SelectedAsSource); + clearMark(n, Mark.SOURCE); clearCellsReachableFrom(n); } @Override public void onTargetCleared(int n) { - clearMark(n, Mark.SelectedAsDestination); + clearMark(n, Mark.TARGET); } private void markCellsReachableFrom(int n) { @@ -72,7 +72,7 @@ private void markCellsReachableFrom(int n) { boolean markEmpties = p.reachableCount < mField.getLength() * 2 / 3; for (int i = 0; i < mField.getLength(); ++i) { if (p.isReachable(i) && (!mField.at(i).isEmpty() || markEmpties)) { - setMark(i, Mark.ReachableFromSource); + setMark(i, Mark.REACHABLE); } } @@ -80,7 +80,7 @@ private void markCellsReachableFrom(int n) { private void clearCellsReachableFrom(int n) { for (int i = 0; i < mField.getLength(); ++i) { - clearMark(i, Mark.ReachableFromSource); + clearMark(i, Mark.REACHABLE); } } } diff --git a/Lib/src/com/yarcat/chemistrylines/view/SelectionInView.java b/Lib/src/com/yarcat/chemistrylines/view/SelectionInView.java index 85ac08c..723ff0a 100644 --- a/Lib/src/com/yarcat/chemistrylines/view/SelectionInView.java +++ b/Lib/src/com/yarcat/chemistrylines/view/SelectionInView.java @@ -3,19 +3,20 @@ import android.annotation.SuppressLint; public class SelectionInView { - public interface SelectionListener { + public interface Listener { public void onNewSource(int n); public void onNewTarget(int n); - public void onSourceCleared(int i); + public void onSourceCleared(int n); - public void onTargetCleared(int i); + public void onTargetCleared(int n); } - private SelectionListener mListener; - private final int[] mSelection = new int[] { -1, -1 }; + private Listener mListener; + private int mSource = -1; + private int mTarget = -1; public void select(int n) { if (hasSource()) { @@ -31,7 +32,7 @@ public void select(int n) { private void selectSource(int n) { clearSource(); - mSelection[0] = n; + mSource = n; if (mListener != null && hasSource()) { mListener.onNewSource(n); } @@ -39,7 +40,7 @@ private void selectSource(int n) { private void selectTarget(int n) { clearTarget(); - mSelection[1] = n; + mTarget = n; if (mListener != null && hasTarget()) { mListener.onNewTarget(n); } @@ -48,50 +49,43 @@ private void selectTarget(int n) { public void clearSource() { if (hasSource()) { if (mListener != null) { - mListener.onSourceCleared(mSelection[0]); + mListener.onSourceCleared(mSource); } - mSelection[0] = -1; + mSource = -1; } } public void clearTarget() { if (hasTarget()) { if (mListener != null) { - mListener.onTargetCleared(mSelection[1]); + mListener.onTargetCleared(mTarget); } - mSelection[1] = -1; + mTarget = -1; } } public void clear() { - if (mListener != null) { - if (hasSource()) { - mListener.onSourceCleared(mSelection[0]); - } - if (hasTarget()) { - mListener.onTargetCleared(mSelection[1]); - } - } - mSelection[0] = mSelection[1] = -1; + clearSource(); + clearTarget(); } public boolean hasSource() { - return mSelection[0] != -1; + return mSource != -1; } public int getSource() { - return mSelection[0]; + return mSource; } public boolean hasTarget() { - return mSelection[1] != -1; + return mTarget != -1; } public int getTarget() { - return mSelection[1]; + return mTarget; } - public void setListener(SelectionListener l) { + public void setListener(Listener l) { mListener = l; } @@ -99,6 +93,6 @@ public void setListener(SelectionListener l) { @Override public String toString() { return String - .format("Selection(%d, %d)", mSelection[0], mSelection[1]); + .format("Selection(%d, %d)", mSource, mTarget); } } diff --git a/Swing/src/com/yarcat/chemistrylines/swing/SwingField.java b/Swing/src/com/yarcat/chemistrylines/swing/SwingField.java index 91e55b2..6eb4205 100644 --- a/Swing/src/com/yarcat/chemistrylines/swing/SwingField.java +++ b/Swing/src/com/yarcat/chemistrylines/swing/SwingField.java @@ -35,7 +35,7 @@ boolean isEmpty() { return cell().isEmpty(); } - private boolean marked(Mark m) { + private boolean markedAs(Mark m) { return mFieldMarks.hasMark(n, m); } @@ -48,11 +48,11 @@ void updateStyle() { @Override Color getBgColor() { Color bg; - if (marked(Mark.SelectedAsSource)) { + if (markedAs(Mark.SOURCE)) { bg = Color.DARK_GRAY; - } else if (marked(Mark.SelectedAsDestination)) { + } else if (markedAs(Mark.TARGET)) { bg = Color.GRAY; - } else if (isEmpty() && marked(Mark.ReachableFromSource)) { + } else if (isEmpty() && markedAs(Mark.REACHABLE)) { bg = style.REACHABLE_BG; } else { bg = super.getBgColor(); @@ -61,7 +61,7 @@ Color getBgColor() { } private Border getEdge() { - return !isEmpty() && marked(Mark.ReachableFromSource) + return !isEmpty() && markedAs(Mark.REACHABLE) ? style.REACHABLE_BORDER : style.DEFAULT_BORDER; } } @@ -89,8 +89,8 @@ void refresh() { } } - Cell at(int i) { - return getField().at(i); + Cell at(int n) { + return getField().at(n); } Field getField() { diff --git a/Swing/src/com/yarcat/chemistrylines/swing/style.java b/Swing/src/com/yarcat/chemistrylines/swing/style.java index a2f937b..9b5376a 100644 --- a/Swing/src/com/yarcat/chemistrylines/swing/style.java +++ b/Swing/src/com/yarcat/chemistrylines/swing/style.java @@ -22,7 +22,7 @@ public class style { final static Border DEFAULT_BORDER = BorderFactory.createLineBorder(new Color(0x55, 0x44, 0x33)); final static Border REACHABLE_BORDER = - BorderFactory.createLineBorder(new Color(0x20, 0x00, 0x30), 2); + BorderFactory.createLineBorder(new Color(0x20, 0x00, 0x30), 2); // @formatter:on static Component defaultColor(Component c) {