Skip to content

Commit 29e5e11

Browse files
author
Nils Fo
committed
Preparing Classes & GUI for tile mirroring
1 parent ca1ffb5 commit 29e5e11

File tree

6 files changed

+257
-182
lines changed

6 files changed

+257
-182
lines changed

CellomicsArrayScanPuzzleHelper.iml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="library" name="CellomicsPuzzleHelper" level="project" />
11+
<orderEntry type="library" name="lib" level="project" />
12+
</component>
13+
</module>

src/de/rub/bph/CellomicsPuzzleHelper.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,25 @@
99
*/
1010

1111
public class CellomicsPuzzleHelper {
12-
13-
public static final String NAME = "ThermoFischer SCIENTIFIC ArrayScan Cellomics Image Puzzle-Helper";
14-
public static final String VERSION = "1.1";
12+
1513
public static final String AUTHOR = "Nils Förster";
16-
14+
public static final String NAME = "ThermoFischer SCIENTIFIC ArrayScan Cellomics Image Puzzle-Helper";
15+
public static final String VERSION = "1.2";
1716
public static PuzzleHelperGUI helperGUI;
18-
17+
1918
public static void main(String[] args) {
20-
19+
2120
SwingUtilities.invokeLater(() -> {
2221
try {
2322
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
2423
} catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) {
2524
e.printStackTrace();
2625
}
27-
26+
2827
helperGUI = new PuzzleHelperGUI();
2928
});
30-
};
31-
29+
}
30+
31+
;
32+
3233
}

src/de/rub/bph/data/Puzzler.java

Lines changed: 64 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,39 @@
77
* Created by nilfoe on 12/03/2018.
88
*/
99
public class Puzzler {
10-
10+
1111
public static final int POSITION_NOT_USED = -1;
12-
12+
1313
private int w;
1414
private int h;
15+
private boolean mirrorRowTiling;
16+
private boolean mirrorColumnTiling;
1517
private PuzzleDirection direction;
16-
18+
1719
private HashMap<Integer, Point> visitedMap;
18-
19-
public Puzzler(int w, int h, PuzzleDirection direction) {
20+
21+
public Puzzler(int w, int h, boolean mirrorRowTiling, boolean mirrorColumnTiling, PuzzleDirection direction) {
2022
this.w = w;
2123
this.h = h;
2224
this.direction = direction;
25+
this.mirrorRowTiling = mirrorRowTiling;
26+
this.mirrorColumnTiling = mirrorColumnTiling;
2327
visitedMap = new HashMap<>();
2428
}
25-
29+
2630
public void puzzle() {
2731
System.out.println("Puzzling a new structure: " + getW() + "x" + getH());
28-
32+
2933
PuzzleDirection currentDirection = direction;
3034
PuzzleDirection startDirection = direction;
31-
35+
3236
int x = 0;
3337
int y = getH() - 1;
34-
38+
3539
for (int i = 0; i <= getSize(); i++) {
36-
visitedMap.put(i, new Point(x, y));
40+
visitedMap.put(i, transformPosition(x, y));
3741
System.out.println("Map: " + i + " -> " + x + "x" + y + " - " + currentDirection);
38-
42+
3943
switch (currentDirection) {
4044
case RIGHT:
4145
if (x + 1 < getW() && !hasPosition(x + 1, y)) {
@@ -92,56 +96,73 @@ public void puzzle() {
9296
}
9397
}
9498
}
95-
96-
public boolean equals(Puzzler p) {
97-
return getW() == p.getW() && getH() == p.getH() && getDirection() == p.getDirection();
99+
100+
public int getW() {
101+
return w;
98102
}
99-
100-
@Override
101-
public int hashCode() {
102-
int hash = "Nils".hashCode();
103-
104-
hash = 31 * hash + getW();
105-
hash = 31 * hash + getH();
106-
hash = 31 * hash + visitedMap.hashCode();
107-
108-
return hash;
103+
104+
public int getH() {
105+
return h;
109106
}
110-
107+
108+
public int getSize() {
109+
return getW() * getH();
110+
}
111+
112+
private Point transformPosition(int x, int y) {
113+
if (isMirrorRowTiling()) {
114+
x = getW() - x;
115+
}
116+
if (isMirrorColumnTiling()) {
117+
y = getH() - y;
118+
}
119+
return new Point(x, y);
120+
}
121+
111122
public boolean hasPosition(int x, int y) {
112123
return getPosition(x, y) != POSITION_NOT_USED;
113124
}
114-
115-
public Point getPosition(int i) {
116-
return visitedMap.get(i);
125+
126+
public boolean isMirrorRowTiling() {
127+
return mirrorRowTiling;
117128
}
118-
119-
129+
130+
public boolean isMirrorColumnTiling() {
131+
return mirrorColumnTiling;
132+
}
133+
120134
public int getPosition(int x, int y) {
121-
return getPosition(new Point(x, y));
135+
return getPosition(transformPosition(x, y));
122136
}
123-
137+
124138
public int getPosition(Point v) {
125139
for (Integer i : visitedMap.keySet()) {
126140
Point visited = getPosition(i);
127141
if (visited.equals(v)) return i;
128142
}
129143
return POSITION_NOT_USED;
130144
}
131-
132-
public int getSize() {
133-
return getW() * getH();
134-
}
135-
136-
public int getW() {
137-
return w;
145+
146+
public Point getPosition(int i) {
147+
return visitedMap.get(i);
138148
}
139-
140-
public int getH() {
141-
return h;
149+
150+
public boolean equals(Puzzler p) {
151+
return getW() == p.getW() && getH() == p.getH() && getDirection() == p.getDirection() && isMirrorColumnTiling() == p.isMirrorColumnTiling() && isMirrorRowTiling() && isMirrorRowTiling();
142152
}
143-
153+
144154
public PuzzleDirection getDirection() {
145155
return direction;
146156
}
157+
158+
@Override
159+
public int hashCode() {
160+
int hash = "Nils".hashCode();
161+
162+
hash = 31 * hash + getW();
163+
hash = 31 * hash + getH();
164+
hash = 31 * hash + visitedMap.hashCode();
165+
166+
return hash;
167+
}
147168
}

src/de/rub/bph/ui/PuzzleHelperGUI.form

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<grid id="27dc6" binding="basePanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
44
<margin top="0" left="0" bottom="0" right="0"/>
55
<constraints>
6-
<xy x="20" y="20" width="500" height="403"/>
6+
<xy x="20" y="20" width="638" height="453"/>
77
</constraints>
88
<properties/>
99
<clientProperties>
@@ -65,7 +65,7 @@
6565
</component>
6666
</children>
6767
</grid>
68-
<grid id="f29b" layout-manager="GridLayoutManager" row-count="10" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
68+
<grid id="f29b" layout-manager="GridLayoutManager" row-count="12" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
6969
<margin top="0" left="0" bottom="0" right="0"/>
7070
<constraints>
7171
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -83,7 +83,7 @@
8383
</component>
8484
<vspacer id="1fb0">
8585
<constraints>
86-
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
86+
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
8787
</constraints>
8888
</vspacer>
8989
<component id="bb32b" class="javax.swing.JLabel">
@@ -162,7 +162,7 @@
162162
</component>
163163
<component id="9f5cc" class="javax.swing.JButton" binding="autoReadImageSizesButton" default-binding="true">
164164
<constraints>
165-
<grid row="9" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
165+
<grid row="11" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
166166
</constraints>
167167
<properties>
168168
<text value="Auto read image sizes"/>
@@ -190,6 +190,22 @@
190190
</constraints>
191191
<properties/>
192192
</component>
193+
<component id="870e2" class="javax.swing.JCheckBox" binding="mirrorRowTilingCB">
194+
<constraints>
195+
<grid row="8" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
196+
</constraints>
197+
<properties>
198+
<text value="Mirror horizontal Tile position"/>
199+
</properties>
200+
</component>
201+
<component id="deaef" class="javax.swing.JCheckBox" binding="mirrorColumnTilingCB">
202+
<constraints>
203+
<grid row="9" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
204+
</constraints>
205+
<properties>
206+
<text value="Mirror vertical Tile positionBox"/>
207+
</properties>
208+
</component>
193209
</children>
194210
</grid>
195211
<grid id="c5429" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">

0 commit comments

Comments
 (0)