fixed bug relating to highlighting rows and columns.
This commit is contained in:
+56
-61
@@ -80,6 +80,53 @@ public class Board extends JPanel {
|
|||||||
setForeground(s.getTheme().getPrimaryText());
|
setForeground(s.getTheme().getPrimaryText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select the given cell and highlight all cells in the same row, column,
|
||||||
|
* and box.
|
||||||
|
*
|
||||||
|
* Intended to be used in conjunction with a MouseListener.
|
||||||
|
*
|
||||||
|
* @param cell
|
||||||
|
*/
|
||||||
|
private void select(Cell cell) {
|
||||||
|
for(int n = 0; n < 9; n++) {
|
||||||
|
int row = cell.getRow();
|
||||||
|
int col = cell.getCol();
|
||||||
|
boolean colInSameBox =
|
||||||
|
(gridGUI[n][col].cell.getBox() ==
|
||||||
|
cell.getBox());
|
||||||
|
|
||||||
|
boolean rowInSameBox =
|
||||||
|
(gridGUI[row][n].cell.getBox() ==
|
||||||
|
cell.getBox());
|
||||||
|
|
||||||
|
if(colInSameBox && !rowInSameBox) {
|
||||||
|
gridGUI[row][n].select();
|
||||||
|
continue;
|
||||||
|
} else if(!colInSameBox && rowInSameBox) {
|
||||||
|
gridGUI[n][col].select();
|
||||||
|
continue;
|
||||||
|
} else if(colInSameBox && rowInSameBox) continue;
|
||||||
|
|
||||||
|
gridGUI[n][col].select();
|
||||||
|
gridGUI[row][n].select();
|
||||||
|
}
|
||||||
|
|
||||||
|
int boxRow = cell.getRow() / 3;
|
||||||
|
int boxCol = cell.getCol() / 3;
|
||||||
|
for(int n = 0; n < 3; n++) {
|
||||||
|
for(int m = 0; m < 3; m++) {
|
||||||
|
int row = boxRow * 3 + n;
|
||||||
|
int col = boxCol * 3 + m;
|
||||||
|
|
||||||
|
// Skip the user-selected cell for clearer highlighting.
|
||||||
|
if(row == cell.getRow() && col == cell.getCol()) continue;
|
||||||
|
|
||||||
|
gridGUI[row][col].select();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the Board Panel with the appropriate cells.
|
* Create the Board Panel with the appropriate cells.
|
||||||
*/
|
*/
|
||||||
@@ -96,54 +143,10 @@ public class Board extends JPanel {
|
|||||||
);
|
);
|
||||||
cell.addMouseListener(new MouseListener() {
|
cell.addMouseListener(new MouseListener() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(java.awt.event.MouseEvent e) {
|
public void mouseClicked(java.awt.event.MouseEvent e) {
|
||||||
// If a cell is already selected, deselect it and
|
if(selected != null) select(selected.cell);
|
||||||
// the row and column.
|
select(cell.cell);
|
||||||
if(selected != null) {
|
|
||||||
int boxRow = selected.cell.getRow() / 3;
|
|
||||||
int boxCol = selected.cell.getCol() / 3;
|
|
||||||
|
|
||||||
for(int n = 0; n < 9; n++) {
|
|
||||||
int row = selected.cell.getRow();
|
|
||||||
int col = selected.cell.getCol();
|
|
||||||
|
|
||||||
if((n == selected.cell.getCol()) || (n == selected.cell.getRow()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
gridGUI[n][col].select();
|
|
||||||
gridGUI[row][n].select();
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int n = 0; n < 3; n++) {
|
|
||||||
for(int m = 0; m < 3; m++) {
|
|
||||||
int row = boxRow * 3 + n;
|
|
||||||
int col = boxCol * 3 + m;
|
|
||||||
if(row == selected.cell.getRow() || col == selected.cell.getCol()) continue;
|
|
||||||
|
|
||||||
gridGUI[row][col].select();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Graphically highlight the row and column
|
|
||||||
// of the selected cell.
|
|
||||||
for(int n = 0; n < 9; n++) {
|
|
||||||
gridGUI[n][cell.cell.getCol()].select();
|
|
||||||
gridGUI[cell.cell.getRow()][n].select();
|
|
||||||
}
|
|
||||||
|
|
||||||
selected = cell;
|
selected = cell;
|
||||||
int boxRow = selected.cell.getRow() / 3;
|
|
||||||
int boxCol = selected.cell.getCol() / 3;
|
|
||||||
for(int n = 0; n < 3; n++) {
|
|
||||||
for(int m = 0; m < 3; m++) {
|
|
||||||
int row = boxRow * 3 + n;
|
|
||||||
int col = boxCol * 3 + m;
|
|
||||||
if(row == selected.cell.getRow() || col == selected.cell.getCol()) continue;
|
|
||||||
|
|
||||||
gridGUI[row][col].select();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(java.awt.event.MouseEvent e) {}
|
public void mousePressed(java.awt.event.MouseEvent e) {}
|
||||||
@@ -193,20 +196,15 @@ public class Board extends JPanel {
|
|||||||
this.theme = theme;
|
this.theme = theme;
|
||||||
selected = false;
|
selected = false;
|
||||||
setLayout(valueLayout);
|
setLayout(valueLayout);
|
||||||
|
valueLabel = new JLabel("", SwingConstants.CENTER);
|
||||||
style();
|
style();
|
||||||
|
|
||||||
// Populate the cell with the appropriate value or notes.
|
// Populate the cell with the appropriate value or notes.
|
||||||
if(cell.getValue() == 0) {
|
if(cell.getValue() == 0) {
|
||||||
valueLabel = new JLabel("");
|
|
||||||
valueLabel.setForeground(theme.getPrimaryText());
|
|
||||||
internalPanel.setLayout(noteLayout);
|
internalPanel.setLayout(noteLayout);
|
||||||
generateNotes();
|
generateNotes();
|
||||||
} else {
|
} else {
|
||||||
valueLabel = new JLabel(
|
valueLabel.setText(Integer.toString(cell.getValue()));
|
||||||
Integer.toString(cell.getValue()),
|
|
||||||
SwingConstants.CENTER
|
|
||||||
);
|
|
||||||
valueLabel.setForeground(theme.getPrimaryText());
|
|
||||||
internalPanel.setLayout(valueLayout);
|
internalPanel.setLayout(valueLayout);
|
||||||
internalPanel.add(valueLabel);
|
internalPanel.add(valueLabel);
|
||||||
}
|
}
|
||||||
@@ -249,6 +247,7 @@ public class Board extends JPanel {
|
|||||||
*/
|
*/
|
||||||
public void addPossibleValue(int value) {
|
public void addPossibleValue(int value) {
|
||||||
cell.addPossibleValue(value);
|
cell.addPossibleValue(value);
|
||||||
|
setNoteMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -299,18 +298,13 @@ public class Board extends JPanel {
|
|||||||
selected = !selected;
|
selected = !selected;
|
||||||
|
|
||||||
if(!selected) {
|
if(!selected) {
|
||||||
setBackground(theme.getPrimaryBackground());
|
style();
|
||||||
setForeground(theme.getPrimaryText());
|
|
||||||
internalPanel.setBackground(theme.getPrimaryBackground());
|
|
||||||
internalPanel.setForeground(theme.getPrimaryText());
|
|
||||||
valueLabel.setForeground(theme.getPrimaryText());
|
|
||||||
setBorder(new LineBorder(theme.getPrimaryBorder(), 2));
|
|
||||||
} else {
|
} else {
|
||||||
setBackground(theme.getSecondaryBackground());
|
setBackground(theme.getSecondaryBackground());
|
||||||
setForeground(theme.getSecondaryText());
|
setForeground(theme.getSecondaryText());
|
||||||
internalPanel.setBackground(theme.getSecondaryBackground());
|
internalPanel.setBackground(theme.getSecondaryBackground());
|
||||||
internalPanel.setForeground(theme.getSecondaryText());
|
internalPanel.setForeground(theme.getSecondaryText());
|
||||||
valueLabel.setForeground(theme.getPrimaryText());
|
valueLabel.setForeground(theme.getSecondaryText());
|
||||||
setBorder(new LineBorder(theme.getSecondaryBorder(), 2));
|
setBorder(new LineBorder(theme.getSecondaryBorder(), 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,6 +320,7 @@ public class Board extends JPanel {
|
|||||||
setForeground(theme.getPrimaryText());
|
setForeground(theme.getPrimaryText());
|
||||||
internalPanel.setBackground(theme.getPrimaryBackground());
|
internalPanel.setBackground(theme.getPrimaryBackground());
|
||||||
internalPanel.setForeground(theme.getPrimaryText());
|
internalPanel.setForeground(theme.getPrimaryText());
|
||||||
|
valueLabel.setForeground(theme.getPrimaryText());
|
||||||
setBorder(new LineBorder(theme.getPrimaryBorder(), 2));
|
setBorder(new LineBorder(theme.getPrimaryBorder(), 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ public class Settings {
|
|||||||
cellGUIStartMode = false;
|
cellGUIStartMode = false;
|
||||||
defaultOpenState = 0;
|
defaultOpenState = 0;
|
||||||
theme = new Theme(new File(appDirectory + "default.theme"));
|
theme = new Theme(new File(appDirectory + "default.theme"));
|
||||||
autoFillNotes = true;
|
autoFillNotes = false;
|
||||||
|
|
||||||
updateSettingsFile();
|
updateSettingsFile();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user