Skip to content

Commit b4bd9eb

Browse files
author
Nils Fo
committed
Updated UI. Implemented well partitioning and export.
1 parent c935d5c commit b4bd9eb

File tree

3 files changed

+61
-31
lines changed

3 files changed

+61
-31
lines changed

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.6";
15+
public static final String VERSION = "1.8";
1616
public static PuzzleHelperGUI helperGUI;
1717

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

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,6 @@
246246
<text value="Magnification Ratio:"/>
247247
</properties>
248248
</component>
249-
<component id="e2b79" class="javax.swing.JSpinner" binding="magnificationSP">
250-
<constraints>
251-
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
252-
</constraints>
253-
<properties/>
254-
</component>
255249
<component id="e843d" class="javax.swing.JLabel" binding="magnificationLB">
256250
<constraints>
257251
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
@@ -260,6 +254,16 @@
260254
<text value="Magnifcation: ?"/>
261255
</properties>
262256
</component>
257+
<component id="45fa4" class="javax.swing.JTextField" binding="magnificationTF">
258+
<constraints>
259+
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
260+
<preferred-size width="150" height="-1"/>
261+
</grid>
262+
</constraints>
263+
<properties>
264+
<text value="1.0"/>
265+
</properties>
266+
</component>
263267
</children>
264268
</grid>
265269
</children>

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

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
import javax.swing.*;
1717
import javax.swing.event.ChangeListener;
18+
import javax.swing.event.DocumentEvent;
19+
import javax.swing.event.DocumentListener;
1820
import javax.swing.filechooser.FileNameExtensionFilter;
1921
import javax.xml.parsers.DocumentBuilder;
2022
import javax.xml.parsers.DocumentBuilderFactory;
@@ -72,7 +74,6 @@ public class PuzzleHelperGUI extends JFrame implements WellPartitionPanel.WellPa
7274
private JButton autoReadImageSizesButton;
7375
private JCheckBox flipFinalImageCB;
7476
private JButton importBT;
75-
private JSpinner magnificationSP;
7677
private JCheckBox mirrorRowTilingCB;
7778
private JCheckBox mirrorColumnTilingCB;
7879
private JCheckBox highlightPuzzleCB;
@@ -81,6 +82,7 @@ public class PuzzleHelperGUI extends JFrame implements WellPartitionPanel.WellPa
8182
private JLabel magnificationLB;
8283
private JLabel partitionsWarningLB;
8384
private JTextField separatorTF;
85+
private JTextField magnificationTF;
8486

8587
private JCheckBoxMenuItem autoUpdateCB;
8688

@@ -102,7 +104,6 @@ public void mouseExited(MouseEvent e) {
102104
}
103105
};
104106

105-
magnificationSP.setModel(new SpinnerNumberModel(1.0, -100.0, 100.0, 0.001));
106107
pWidthSP.setModel(new SpinnerNumberModel(10, 1, Integer.MAX_VALUE, 1));
107108
pHeightSP.setModel(new SpinnerNumberModel(10, 1, Integer.MAX_VALUE, 1));
108109
imWidthSP.setModel(new SpinnerNumberModel(1000, 1, Integer.MAX_VALUE, 1));
@@ -115,9 +116,23 @@ public void mouseExited(MouseEvent e) {
115116
imWidthSP.addChangeListener(l);
116117
imHeightSP.addChangeListener(l);
117118
partitionsSP.addChangeListener(changeEvent -> update());
118-
magnificationSP.addChangeListener(changeEvent -> update());
119-
magnificationSP.addMouseListener(mouseListenerUpdate);
120119
exportInstructionFileButton.addMouseListener(mouseListenerUpdate);
120+
magnificationTF.getDocument().addDocumentListener(new DocumentListener() {
121+
@Override
122+
public void insertUpdate(DocumentEvent documentEvent) {
123+
update();
124+
}
125+
126+
@Override
127+
public void removeUpdate(DocumentEvent documentEvent) {
128+
update();
129+
}
130+
131+
@Override
132+
public void changedUpdate(DocumentEvent documentEvent) {
133+
update();
134+
}
135+
});
121136

122137
directionCB.addItem(PuzzleDirection.RIGHT);
123138
directionCB.addItem(PuzzleDirection.DOWN);
@@ -258,6 +273,13 @@ private void actionExportFile() throws IOException {
258273

259274
if (!exportFileFilter.accept(f)) return;
260275

276+
double magnification = 0;
277+
try {
278+
magnification = getMagnification();
279+
}catch (Exception e){
280+
JOptionPane.showMessageDialog(this,"Cannot save the puzzle instructions:\nInvalid magnification!","Fatal Error!",JOptionPane.ERROR_MESSAGE);
281+
}
282+
261283
HashMap<String, String> map = new HashMap<String, String>();
262284
map.put(INSTRUCTION_IMWIDTH, String.valueOf(imWidthSP.getValue()));
263285
map.put(INSTRUCTION_IMHEIGHT, String.valueOf(imHeightSP.getValue()));
@@ -268,7 +290,7 @@ private void actionExportFile() throws IOException {
268290
map.put(INSTRUCTION_MIRROR_ROW_TILING, String.valueOf(mirrorRowTilingCB.isSelected()));
269291
map.put(INSTRUCTION_PFLIPROW, String.valueOf(flipRowCB.isSelected()));
270292
map.put(INSTRUCTION_PFLIPRESULT, String.valueOf(flipFinalImageCB.isSelected()));
271-
map.put(INSTRUCTION_MAGNIFICATION, String.valueOf(getMagnification()));
293+
map.put(INSTRUCTION_MAGNIFICATION, String.valueOf(magnification));
272294
map.put(INSTRUCTION_SEPARATOR, String.valueOf(separatorTF.getText()));
273295
map.put(INSTRUCTION_VERSION, CellomicsPuzzleHelper.VERSION);
274296

@@ -389,7 +411,7 @@ private void actionImportFile() throws IOException, ParserConfigurationException
389411
imWidthSP.setValue(Integer.valueOf(document.getElementsByTagName(INSTRUCTION_IMWIDTH).item(0).getTextContent()));
390412
imHeightSP.setValue(Integer.valueOf(document.getElementsByTagName(INSTRUCTION_IMHEIGHT).item(0).getTextContent()));
391413
pWidthSP.setValue(Integer.valueOf(document.getElementsByTagName(INSTRUCTION_PWIDTH).item(0).getTextContent()));
392-
magnificationSP.setValue(Double.valueOf(document.getElementsByTagName(INSTRUCTION_MAGNIFICATION).item(0).getTextContent()));
414+
magnificationTF.setText(String.valueOf(document.getElementsByTagName(INSTRUCTION_MAGNIFICATION).item(0).getTextContent()));
393415
pHeightSP.setValue(Integer.valueOf(document.getElementsByTagName(INSTRUCTION_PHEIGHT).item(0).getTextContent()));
394416
separatorTF.setText(String.valueOf(document.getElementsByTagName(INSTRUCTION_SEPARATOR).item(0).getTextContent()));
395417
flipFinalImageCB.setSelected(Boolean.valueOf(document.getElementsByTagName(INSTRUCTION_PFLIPRESULT).item(0).getTextContent()));
@@ -399,7 +421,16 @@ private void actionImportFile() throws IOException, ParserConfigurationException
399421
directionCB.setSelectedItem(PuzzleDirection.getViaString(document.getElementsByTagName(INSTRUCTION_PDIR).item(0).getTextContent()));
400422
} catch (Exception e) {
401423
e.printStackTrace();
402-
JOptionPane.showMessageDialog(this, "The file did not contain every smart well parameter required by this version and importing stopped. This may lead to unexpected behaviour.", "Error!", JOptionPane.ERROR_MESSAGE);
424+
StringBuilder builder = new StringBuilder();
425+
for (StackTraceElement element : e.getStackTrace()){
426+
builder.append("\n"+element);
427+
}
428+
String className = e.getClass().getName();
429+
430+
int answer = JOptionPane.showConfirmDialog(this, "The file did not contain every smart well parameter required by this version and importing stopped. This may lead to unexpected behaviour.\nException: "+className+": '"+e.getMessage()+"'\nDo you want to see a detailed error report?", "Error!",JOptionPane.YES_NO_OPTION, JOptionPane.ERROR_MESSAGE);
431+
if (answer==JOptionPane.YES_OPTION){
432+
JOptionPane.showMessageDialog(this,e.getMessage()+"\n"+builder.toString(),className,JOptionPane.ERROR_MESSAGE);
433+
}
403434
return;
404435
}
405436

@@ -514,8 +545,14 @@ private void update() {
514545
previewPL.update(w, h, mirrorRowTiling, mirrorColumnTiling, highlightPuzzle, direction);
515546
imagecountLB.setText("Image count per well: " + w * h + " [" + w + "x" + h + "]");
516547

517-
double magnification = getMagnification();
518-
magnificationLB.setText("Scaling factor: 1 px represents "+magnification+" \u00B5m");
548+
String magnificationText = "INVALID NUMBER!";
549+
try{
550+
double magnification = getMagnification();
551+
magnificationText="1 px represents "+magnification+" \u00B5m";
552+
}catch (Exception e){
553+
e.printStackTrace();
554+
}
555+
magnificationLB.setText("Scaling factor: "+magnificationText);
519556

520557
updateWellPartitionTabs();
521558
partitionsWarningLB.setVisible(!hasWellPartitionsWithAtLeastOneControl());
@@ -559,26 +596,15 @@ public boolean hasWellPartitionsWithAtLeastOneControl(){
559596
return true;
560597
}
561598

562-
public double getMagnification(){
599+
public double getMagnification() throws NumberFormatException{
563600
DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
564601
DecimalFormatSymbols symbols = format.getDecimalFormatSymbols();
565602
char sep=symbols.getDecimalSeparator();
566603
DecimalFormat df = new DecimalFormat("#.###");
567604

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-
}
605+
String inputMag = magnificationTF.getText();
606+
inputMag=inputMag.replace(",",".").trim().toLowerCase();
607+
double magnification = Double.parseDouble(inputMag);
582608

583609
String formattedMagnification = df.format(magnification);
584610
formattedMagnification=formattedMagnification.replace(",",".");

0 commit comments

Comments
 (0)