Skip to content

Commit c935d5c

Browse files
committed
Fixed magnification for german locale and added custom separator textfield
1 parent 28deb99 commit c935d5c

5 files changed

Lines changed: 139 additions & 18 deletions

File tree

CellomicsArrayScanPuzzleHelper.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="true">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
44
<exclude-output />
55
<content url="file://$MODULE_DIR$">
66
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
77
</content>
88
<orderEntry type="inheritedJdk" />
99
<orderEntry type="sourceFolder" forTests="false" />
10-
<orderEntry type="library" name="CellomicsPuzzleHelper" level="project" />
1110
<orderEntry type="library" name="lib" level="project" />
11+
<orderEntry type="library" name="CellomicsPuzzleHelper" level="project" />
1212
</component>
1313
</module>

src/de/rub/bph/CellomicsPuzzleHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CellomicsPuzzleHelper {
1212

1313
public static final String AUTHOR = "Nils Förster";
1414
public static final String NAME = "OmniSphero Smart-Well Creator";
15-
public static final String VERSION = "1.5";
15+
public static final String VERSION = "1.6";
1616
public static PuzzleHelperGUI helperGUI;
1717

1818
public static void main(String[] args) {

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

Lines changed: 18 additions & 8 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="4" same-size-horizontally="false" 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="1186" height="586"/>
6+
<xy x="20" y="20" width="1186" height="590"/>
77
</constraints>
88
<properties/>
99
<clientProperties>
@@ -315,17 +315,17 @@
315315
</hspacer>
316316
</children>
317317
</grid>
318-
<grid id="8db69" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
318+
<grid id="8db69" layout-manager="GridLayoutManager" row-count="4" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
319319
<margin top="0" left="0" bottom="0" right="0"/>
320320
<constraints>
321-
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
321+
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
322322
</constraints>
323323
<properties/>
324324
<border type="none" title="Plating Partitions"/>
325325
<children>
326326
<tabbedpane id="62895" binding="partitionsTabbedPane">
327327
<constraints>
328-
<grid row="1" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
328+
<grid row="1" column="0" row-span="1" col-span="4" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
329329
<preferred-size width="200" height="200"/>
330330
</grid>
331331
</constraints>
@@ -335,15 +335,15 @@
335335
</tabbedpane>
336336
<component id="e5e8e" class="javax.swing.JLabel">
337337
<constraints>
338-
<grid row="2" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
338+
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
339339
</constraints>
340340
<properties>
341-
<text value="Separate your partitions with the &quot;§&quot; character."/>
341+
<text value="Partition separation indicator:"/>
342342
</properties>
343343
</component>
344344
<component id="cacd7" class="javax.swing.JLabel">
345345
<constraints>
346-
<grid row="3" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
346+
<grid row="3" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
347347
</constraints>
348348
<properties>
349349
<text value="White wells are ignored. Red wells are puzzled. Blue wells are controls."/>
@@ -365,9 +365,19 @@
365365
</component>
366366
<hspacer id="5fee3">
367367
<constraints>
368-
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
368+
<grid row="0" column="2" row-span="1" col-span="2" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
369369
</constraints>
370370
</hspacer>
371+
<component id="6a8e1" class="javax.swing.JTextField" binding="separatorTF">
372+
<constraints>
373+
<grid row="2" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
374+
<preferred-size width="150" height="-1"/>
375+
</grid>
376+
</constraints>
377+
<properties>
378+
<text value="§"/>
379+
</properties>
380+
</component>
371381
</children>
372382
</grid>
373383
</children>

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

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@
2020
import javax.xml.parsers.DocumentBuilderFactory;
2121
import javax.xml.parsers.ParserConfigurationException;
2222
import java.awt.*;
23-
import java.awt.event.ActionListener;
2423
import java.awt.event.MouseAdapter;
2524
import java.awt.event.MouseEvent;
2625
import java.io.*;
2726
import java.net.URI;
2827
import java.net.URISyntaxException;
2928
import java.text.DecimalFormat;
29+
import java.text.DecimalFormatSymbols;
3030
import java.util.ArrayList;
31-
import java.util.Arrays;
3231
import java.util.Collections;
3332
import java.util.HashMap;
34-
import java.util.regex.Matcher;
35-
import java.util.regex.Pattern;
3633

3734

3835
/**
@@ -44,6 +41,7 @@ public class PuzzleHelperGUI extends JFrame implements WellPartitionPanel.WellPa
4441

4542
public static final String INSTRUCTION_IMHEIGHT = "imheight";
4643
public static final String INSTRUCTION_IMWIDTH = "imwidth";
44+
public static final String INSTRUCTION_SEPARATOR = "separatorChar";
4745
public static final String INSTRUCTION_MAGNIFICATION = "immagni";
4846
public static final String INSTRUCTION_MIRROR_COLUMN_TILING = "pmirrorcolumntiling";
4947
public static final String INSTRUCTION_MIRROR_ROW_TILING = "pmirrorrowtiling";
@@ -82,14 +80,29 @@ public class PuzzleHelperGUI extends JFrame implements WellPartitionPanel.WellPa
8280
private JSpinner partitionsSP;
8381
private JLabel magnificationLB;
8482
private JLabel partitionsWarningLB;
83+
private JTextField separatorTF;
8584

8685
private JCheckBoxMenuItem autoUpdateCB;
8786

8887
public PuzzleHelperGUI() {
8988
exportFileFilter = new FileNameExtensionFilter("XML", "xml");
9089
imageFileFilter = new FileNameExtensionFilter("Image files", "tiff", "tif", "png", "bmp");
9190

92-
magnificationSP.setModel(new SpinnerNumberModel(1, Integer.MIN_VALUE, Integer.MAX_VALUE, 0.001));
91+
MouseAdapter mouseListenerUpdate = new MouseAdapter() {
92+
@Override
93+
public void mouseEntered(MouseEvent e) {
94+
super.mouseEntered(e);
95+
requestUpdate();
96+
}
97+
98+
@Override
99+
public void mouseExited(MouseEvent e) {
100+
super.mouseExited(e);
101+
requestUpdate();
102+
}
103+
};
104+
105+
magnificationSP.setModel(new SpinnerNumberModel(1.0, -100.0, 100.0, 0.001));
93106
pWidthSP.setModel(new SpinnerNumberModel(10, 1, Integer.MAX_VALUE, 1));
94107
pHeightSP.setModel(new SpinnerNumberModel(10, 1, Integer.MAX_VALUE, 1));
95108
imWidthSP.setModel(new SpinnerNumberModel(1000, 1, Integer.MAX_VALUE, 1));
@@ -103,6 +116,8 @@ public PuzzleHelperGUI() {
103116
imHeightSP.addChangeListener(l);
104117
partitionsSP.addChangeListener(changeEvent -> update());
105118
magnificationSP.addChangeListener(changeEvent -> update());
119+
magnificationSP.addMouseListener(mouseListenerUpdate);
120+
exportInstructionFileButton.addMouseListener(mouseListenerUpdate);
106121

107122
directionCB.addItem(PuzzleDirection.RIGHT);
108123
directionCB.addItem(PuzzleDirection.DOWN);
@@ -254,6 +269,7 @@ private void actionExportFile() throws IOException {
254269
map.put(INSTRUCTION_PFLIPROW, String.valueOf(flipRowCB.isSelected()));
255270
map.put(INSTRUCTION_PFLIPRESULT, String.valueOf(flipFinalImageCB.isSelected()));
256271
map.put(INSTRUCTION_MAGNIFICATION, String.valueOf(getMagnification()));
272+
map.put(INSTRUCTION_SEPARATOR, String.valueOf(separatorTF.getText()));
257273
map.put(INSTRUCTION_VERSION, CellomicsPuzzleHelper.VERSION);
258274

259275
FileOutputStream fout = new FileOutputStream(f);
@@ -375,6 +391,7 @@ private void actionImportFile() throws IOException, ParserConfigurationException
375391
pWidthSP.setValue(Integer.valueOf(document.getElementsByTagName(INSTRUCTION_PWIDTH).item(0).getTextContent()));
376392
magnificationSP.setValue(Double.valueOf(document.getElementsByTagName(INSTRUCTION_MAGNIFICATION).item(0).getTextContent()));
377393
pHeightSP.setValue(Integer.valueOf(document.getElementsByTagName(INSTRUCTION_PHEIGHT).item(0).getTextContent()));
394+
separatorTF.setText(String.valueOf(document.getElementsByTagName(INSTRUCTION_SEPARATOR).item(0).getTextContent()));
378395
flipFinalImageCB.setSelected(Boolean.valueOf(document.getElementsByTagName(INSTRUCTION_PFLIPRESULT).item(0).getTextContent()));
379396
flipRowCB.setSelected(Boolean.valueOf(document.getElementsByTagName(INSTRUCTION_PFLIPROW).item(0).getTextContent()));
380397
mirrorColumnTilingCB.setSelected(Boolean.valueOf(document.getElementsByTagName(INSTRUCTION_MIRROR_ROW_TILING).item(0).getTextContent()));
@@ -477,7 +494,12 @@ private void autoReadImageSize() {
477494
}
478495

479496
private void requestUpdate() {
480-
if (autoUpdateCB.isSelected()) update();
497+
try {
498+
if (autoUpdateCB.isSelected()) update();
499+
}catch (Exception e){
500+
e.printStackTrace();
501+
JOptionPane.showConfirmDialog(this,"Error while trying to update the UI:\n"+e.getMessage(),"Error: "+e.getClass().getName(),JOptionPane.ERROR_MESSAGE);
502+
}
481503
}
482504

483505
private void update() {
@@ -538,9 +560,28 @@ public boolean hasWellPartitionsWithAtLeastOneControl(){
538560
}
539561

540562
public double getMagnification(){
563+
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
564+
DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
565+
char sep=symbols.getDecimalSeparator();
541566
DecimalFormat df = new DecimalFormat("#.###");
542-
double magnification = (double) magnificationSP.getValue();
567+
568+
double magnification;
569+
// So, there is a bug within Java to round the double spinner value to the nearest integer using "getValue()"
570+
// That's why we gotta read the spinner text. Great.
571+
JSpinner.NumberEditor numEditor = (JSpinner.NumberEditor) magnificationSP.getEditor();
572+
JFormattedTextField textField = numEditor.getTextField();
573+
JFormattedTextField.AbstractFormatter formatter = textField.getFormatter();
574+
String text = textField.getText();
575+
if (sep==','){
576+
// Turns out we are on a German Locale. That means we gotta read the text field directly.
577+
text = text.replace(",",".");
578+
magnification = Double.parseDouble(text);
579+
}else{
580+
magnification=(double) magnificationSP.getValue();
581+
}
582+
543583
String formattedMagnification = df.format(magnification);
584+
formattedMagnification=formattedMagnification.replace(",",".");
544585
return Double.parseDouble(formattedMagnification);
545586
}
546587

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package de.rub.bph.ui.component;
2+
3+
import javax.swing.*;
4+
import javax.swing.event.ChangeEvent;
5+
import javax.swing.event.ChangeListener;
6+
import java.util.ArrayList;
7+
8+
public class DoubleNumberModel extends AbstractSpinnerModel {
9+
10+
private double currentValue;
11+
private double stepSize;
12+
private double min;
13+
private double max;
14+
15+
public DoubleNumberModel(double value, double min, double max,double stepSize) {
16+
super();
17+
this.stepSize = stepSize;
18+
this.min = min;
19+
this.max = max;
20+
this.currentValue=value;
21+
}
22+
23+
@Override
24+
public Object getValue() {
25+
return currentValue;
26+
}
27+
28+
@Override
29+
public void setValue(Object value) {
30+
currentValue = Double.parseDouble(value.toString());
31+
fireStateChanged();
32+
}
33+
34+
@Override
35+
public Object getNextValue() {
36+
fireStateChanged();
37+
return currentValue + stepSize;
38+
}
39+
40+
@Override
41+
public Object getPreviousValue() {
42+
fireStateChanged();
43+
return currentValue - stepSize;
44+
}
45+
46+
47+
public double getStepSize() {
48+
return stepSize;
49+
}
50+
51+
public void setStepSize(double stepSize) {
52+
this.stepSize = stepSize;
53+
}
54+
55+
public double getMin() {
56+
return min;
57+
}
58+
59+
public void setMin(double min) {
60+
this.min = min;
61+
}
62+
63+
public double getMax() {
64+
return max;
65+
}
66+
67+
public void setMax(double max) {
68+
this.max = max;
69+
}
70+
}

0 commit comments

Comments
 (0)