Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write quantities backward compatible when performing export
- Loading branch information
Showing
3 changed files
with
71 additions
and
22 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
freeplane/src/main/java/org/freeplane/core/io/BackwardCompatibleQuantityWriter.java
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.freeplane.core.io; | ||
|
||
import org.freeplane.core.ui.LengthUnits; | ||
import org.freeplane.core.util.Quantity; | ||
import org.freeplane.features.map.MapWriter; | ||
|
||
public class BackwardCompatibleQuantityWriter { | ||
|
||
final private ITreeWriter writer; | ||
final private boolean makeCompatible; | ||
|
||
static public BackwardCompatibleQuantityWriter forWriter(ITreeWriter writer){ | ||
final Object hint = writer.getHint(BackwardCompatibleQuantityWriter.class); | ||
if(Boolean.FALSE.equals(hint)){ | ||
final boolean makeCompatible = Boolean.TRUE.equals(writer.getHint(MapWriter.WriterHint.FORCE_FORMATTING)); | ||
final BackwardCompatibleQuantityWriter quantityWriter = new BackwardCompatibleQuantityWriter(writer, makeCompatible); | ||
writer.setHint(BackwardCompatibleQuantityWriter.class, quantityWriter); | ||
return quantityWriter; | ||
} | ||
return (BackwardCompatibleQuantityWriter) hint; | ||
} | ||
|
||
public BackwardCompatibleQuantityWriter(ITreeWriter writer, boolean makeCompatible) { | ||
this.writer = writer; | ||
this.makeCompatible = makeCompatible; | ||
} | ||
|
||
public void writeQuantity(String name, final Quantity<LengthUnits> value) { | ||
if(makeCompatible){ | ||
writer.addAttribute(name, value.toBaseUnitsRounded()); | ||
writer.addAttribute(name+"_QUANTITY", value.toString()); | ||
} | ||
else | ||
writer.addAttribute(name, value.toString()); | ||
} | ||
|
||
} |
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