-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#75] Selection highligh moved to SwingField.FieldSelection.
- Loading branch information
Showing
5 changed files
with
123 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,59 @@ | ||
package com.yarcat.chemistrylines.view; | ||
|
||
public class SelectionInView { | ||
public interface SelectionListener { | ||
This comment has been minimized.
Sorry, something went wrong.
yarcat
Owner
|
||
|
||
public void onNewSource(int n); | ||
This comment has been minimized.
Sorry, something went wrong.
yarcat
Owner
|
||
|
||
public void onNewTarget(int n); | ||
|
||
public void onSourceCleared(int i); | ||
|
||
public void onTargetCleared(int i); | ||
} | ||
|
||
private SelectionListener mListener; | ||
private int[] mSelection = new int[] { -1, -1 }; | ||
This comment has been minimized.
Sorry, something went wrong.
yarcat
Owner
|
||
|
||
public void select(int n) { | ||
if (mSelection[0] == -1) { | ||
mSelection[0] = n; | ||
if (hasSource()) { | ||
if (getSource() != n) { | ||
selectTarget(n); | ||
} | ||
} else { | ||
mSelection[1] = n; | ||
selectSource(n); | ||
} | ||
} | ||
|
||
private void selectSource(int n) { | ||
if (mListener != null && hasSource()) { | ||
mListener.onSourceCleared(mSelection[0]); | ||
} | ||
mSelection[0] = n; | ||
if (mListener != null && hasSource()) { | ||
mListener.onNewSource(n); | ||
} | ||
} | ||
|
||
private void selectTarget(int n) { | ||
if (mListener != null && hasDestination()) { | ||
mListener.onTargetCleared(mSelection[1]); | ||
} | ||
mSelection[1] = n; | ||
if (mListener != null && hasDestination()) { | ||
mListener.onNewTarget(n); | ||
} | ||
} | ||
|
||
public void clear() { | ||
if (mListener != null) { | ||
if (hasSource()) { | ||
mListener.onSourceCleared(mSelection[0]); | ||
} | ||
if (hasDestination()) { | ||
mListener.onTargetCleared(mSelection[1]); | ||
} | ||
} | ||
mSelection[0] = mSelection[1] = -1; | ||
} | ||
|
||
|
@@ -30,4 +72,8 @@ public boolean hasDestination() { | |
public int getDestination() { | ||
return mSelection[1]; | ||
} | ||
|
||
public void setListener(SelectionListener l) { | ||
mListener = l; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Enums are classes and should follow the conventions for classes. Instances of an enum are constants and should follow the conventions for constants.