mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-22 04:55:10 +00:00
commit
6fe22da334
@ -5,9 +5,13 @@ root = true
|
|||||||
charset = utf-8
|
charset = utf-8
|
||||||
end_of_line = lf
|
end_of_line = lf
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
indent_style = space
|
indent_style = tab
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
max_line_length = off
|
max_line_length = off
|
||||||
trim_trailing_whitespace = false
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[pom.xml, *.yml]
|
||||||
|
indent_style = space
|
||||||
|
|
||||||
|
@ -23,14 +23,14 @@ import ext.plantuml.com.ctreber.acearth.util.Polygon;
|
|||||||
* obtained by adding [dx,dy,dz] onto the previous [x,y,z] values. - the curves
|
* obtained by adding [dx,dy,dz] onto the previous [x,y,z] values. - the curves
|
||||||
* are [must be!] non-self-intersecting and traced in a counter-clockwise
|
* are [must be!] non-self-intersecting and traced in a counter-clockwise
|
||||||
* direction
|
* direction
|
||||||
*
|
*
|
||||||
* the curves are sampled at a (roughly) a 20 mile resolution.
|
* the curves are sampled at a (roughly) a 20 mile resolution.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>
|
||||||
* © 2002 Christian Treber, ct@ctreber.com
|
* © 2002 Christian Treber, ct@ctreber.com
|
||||||
*
|
*
|
||||||
* @author Christian Treber, ct@ctreber.com
|
* @author Christian Treber, ct@ctreber.com
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class MapDataReader {
|
public class MapDataReader {
|
||||||
/** Point value scale (devide value by this number). */
|
/** Point value scale (devide value by this number). */
|
||||||
@ -43,17 +43,17 @@ public class MapDataReader {
|
|||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Read map data.
|
* Read map data.
|
||||||
*
|
*
|
||||||
* @return Array of map polygons.
|
* @return Array of map polygons.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static Polygon[] readMapData() throws IOException {
|
public static Polygon[] readMapData() throws IOException {
|
||||||
final List lines = new MapData().getLines();
|
final List lines = new MapData().getLines();
|
||||||
|
|
||||||
fData = new ArrayList();
|
fData = new ArrayList();
|
||||||
for (Iterator it = lines.iterator(); it.hasNext(); ) {
|
for (Iterator it = lines.iterator(); it.hasNext(); ) {
|
||||||
String lLine = (String) it.next();
|
String lLine = (String) it.next();
|
||||||
if (lLine.indexOf("/*") != -1) {
|
if (lLine.contains("/*")) {
|
||||||
// Filter out comments.
|
// Filter out comments.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ public class MapDataReader {
|
|||||||
StringTokenizer lST = new StringTokenizer(lLine, ", ");
|
StringTokenizer lST = new StringTokenizer(lLine, ", ");
|
||||||
while (lST.hasMoreTokens()) {
|
while (lST.hasMoreTokens()) {
|
||||||
String lToken = lST.nextToken();
|
String lToken = lST.nextToken();
|
||||||
final Integer lValue = new Integer(lToken);
|
final Integer lValue = Integer.valueOf(lToken);
|
||||||
fData.add(lValue);
|
fData.add(lValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ public class MapDataReader {
|
|||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Get value of raw data at specified point.
|
* Get value of raw data at specified point.
|
||||||
*
|
*
|
||||||
* @param pIndex
|
* @param pIndex
|
||||||
* Index of value.
|
* Index of value.
|
||||||
* @return Value of raw data at specified point.
|
* @return Value of raw data at specified point.
|
||||||
|
@ -119,7 +119,7 @@ class ScanBuf
|
|||||||
// Record the x value for every line (y).
|
// Record the x value for every line (y).
|
||||||
for(int lLineNo = lYFrom; lLineNo <= lYTo; lLineNo++)
|
for(int lLineNo = lYFrom; lLineNo <= lYTo; lLineNo++)
|
||||||
{
|
{
|
||||||
fScanbuf[lLineNo].add(new Double(lX));
|
fScanbuf[lLineNo].add(Double.valueOf(lX));
|
||||||
lX += lDx;
|
lX += lDx;
|
||||||
}
|
}
|
||||||
fScanBufsAdded = true;
|
fScanBufsAdded = true;
|
||||||
@ -152,10 +152,10 @@ class ScanBuf
|
|||||||
{
|
{
|
||||||
// Round lLineFrom (but .5 is handled oddly)
|
// Round lLineFrom (but .5 is handled oddly)
|
||||||
// 1.5001 - 2.5 -> 1.0001 - 2.0 -> 2
|
// 1.5001 - 2.5 -> 1.0001 - 2.0 -> 2
|
||||||
int lXLo = (int)Math.ceil(lScanLine[n].doubleValue() - 0.5);
|
int lXLo = (int)Math.ceil(lScanLine[n] - 0.5);
|
||||||
// Round lLineTo, substract 1
|
// Round lLineTo, substract 1
|
||||||
// 1.5 - 2.4999 -> 1.0 - 1.9999 -> 1
|
// 1.5 - 2.4999 -> 1.0 - 1.9999 -> 1
|
||||||
int lXHi = (int)Math.floor(lScanLine[n + 1].doubleValue() - 0.5);
|
int lXHi = (int)Math.floor(lScanLine[n + 1] - 0.5);
|
||||||
|
|
||||||
// Limit low and high x to image dimensions
|
// Limit low and high x to image dimensions
|
||||||
if(lXLo < 0)
|
if(lXLo < 0)
|
||||||
|
@ -67,13 +67,13 @@ public final class CharacterSetECI extends ECI {
|
|||||||
|
|
||||||
private static void addCharacterSet(int value, String encodingName) {
|
private static void addCharacterSet(int value, String encodingName) {
|
||||||
CharacterSetECI eci = new CharacterSetECI(value, encodingName);
|
CharacterSetECI eci = new CharacterSetECI(value, encodingName);
|
||||||
VALUE_TO_ECI.put(new Integer(value), eci); // can't use valueOf
|
VALUE_TO_ECI.put(value, eci); // can't use valueOf
|
||||||
NAME_TO_ECI.put(encodingName, eci);
|
NAME_TO_ECI.put(encodingName, eci);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addCharacterSet(int value, String[] encodingNames) {
|
private static void addCharacterSet(int value, String[] encodingNames) {
|
||||||
CharacterSetECI eci = new CharacterSetECI(value, encodingNames[0]);
|
CharacterSetECI eci = new CharacterSetECI(value, encodingNames[0]);
|
||||||
VALUE_TO_ECI.put(new Integer(value), eci); // can't use valueOf
|
VALUE_TO_ECI.put(value, eci); // can't use valueOf
|
||||||
for (int i = 0; i < encodingNames.length; i++) {
|
for (int i = 0; i < encodingNames.length; i++) {
|
||||||
NAME_TO_ECI.put(encodingNames[i], eci);
|
NAME_TO_ECI.put(encodingNames[i], eci);
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ public final class CharacterSetECI extends ECI {
|
|||||||
if (value < 0 || value >= 900) {
|
if (value < 0 || value >= 900) {
|
||||||
throw new IllegalArgumentException("Bad ECI value: " + value);
|
throw new IllegalArgumentException("Bad ECI value: " + value);
|
||||||
}
|
}
|
||||||
return (CharacterSetECI) VALUE_TO_ECI.get(new Integer(value));
|
return (CharacterSetECI) VALUE_TO_ECI.get(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,7 @@ import jcckit.util.ConfigParameters;
|
|||||||
import jcckit.util.Factory;
|
import jcckit.util.Factory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A plot is determined by a {@link CoordinateSystem}, {@link Curve Curves},
|
* A plot is determined by a {@link CoordinateSystem}, {@link Curve Curves},
|
||||||
* an optional annotation layer and an optional {@link Legend}. When rendered
|
* an optional annotation layer and an optional {@link Legend}. When rendered
|
||||||
* these components are draw in this order.
|
* these components are draw in this order.
|
||||||
* <p>
|
* <p>
|
||||||
@ -45,8 +45,8 @@ import jcckit.util.Factory;
|
|||||||
* This is done with the method {@link #connect connect()} which registrates
|
* This is done with the method {@link #connect connect()} which registrates
|
||||||
* this <tt>Plot</tt> instance as
|
* this <tt>Plot</tt> instance as
|
||||||
* a {@link DataListener} at the connected <tt>DataPlot</tt>.
|
* a {@link DataListener} at the connected <tt>DataPlot</tt>.
|
||||||
* After an received {@link DataEvent DataEvents} has been handled
|
* After an received {@link DataEvent DataEvents} has been handled
|
||||||
* the registrated <tt>PlotListeners</tt> will receive a
|
* the registrated <tt>PlotListeners</tt> will receive a
|
||||||
* {@link PlotEvent} of the type {@link PlotEventType#DATA_PLOT_CHANGED}.
|
* {@link PlotEvent} of the type {@link PlotEventType#DATA_PLOT_CHANGED}.
|
||||||
*
|
*
|
||||||
* @author Franz-Josef Elmer
|
* @author Franz-Josef Elmer
|
||||||
@ -113,10 +113,10 @@ public class Plot implements DataListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the coordinate system. All curves will be regenerated and a
|
* Sets the coordinate system. All curves will be regenerated and a
|
||||||
* {@link PlotEvent} of type {@link PlotEventType#COODINATE_SYSTEM_CHANGED}
|
* {@link PlotEvent} of type {@link PlotEventType#COODINATE_SYSTEM_CHANGED}
|
||||||
* will be fired.
|
* will be fired.
|
||||||
*
|
*
|
||||||
* @param coordinateSystem New coordinate system.
|
* @param coordinateSystem New coordinate system.
|
||||||
*/
|
*/
|
||||||
public void setCoordinateSystem(CoordinateSystem coordinateSystem)
|
public void setCoordinateSystem(CoordinateSystem coordinateSystem)
|
||||||
@ -150,8 +150,8 @@ public class Plot implements DataListener {
|
|||||||
_plotListeners.removeElement(listener);
|
_plotListeners.removeElement(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends all registrated {@link PlotListener PlotListeners}
|
* Sends all registrated {@link PlotListener PlotListeners}
|
||||||
* the specified event.
|
* the specified event.
|
||||||
*/
|
*/
|
||||||
protected void notifyListeners(PlotEvent event) {
|
protected void notifyListeners(PlotEvent event) {
|
||||||
@ -163,7 +163,7 @@ public class Plot implements DataListener {
|
|||||||
/**
|
/**
|
||||||
* Connect the specified {@link DataPlot} with this instance.
|
* Connect the specified {@link DataPlot} with this instance.
|
||||||
* <p>
|
* <p>
|
||||||
* If this <tt>Plot</tt> instance is already connected with a
|
* If this <tt>Plot</tt> instance is already connected with a
|
||||||
* <tt>DataPlot</tt> the connection will be released and a
|
* <tt>DataPlot</tt> the connection will be released and a
|
||||||
* {@link PlotEvent} of the type {@link PlotEventType#DATA_PLOT_DISCONNECTED}
|
* {@link PlotEvent} of the type {@link PlotEventType#DATA_PLOT_DISCONNECTED}
|
||||||
* will be sent to all registrated {@link PlotListener PlotListeners}.
|
* will be sent to all registrated {@link PlotListener PlotListeners}.
|
||||||
@ -192,7 +192,7 @@ public class Plot implements DataListener {
|
|||||||
_dataPlot));
|
_dataPlot));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transforms a point from device-independent coordinates into
|
* Transforms a point from device-independent coordinates into
|
||||||
* data coordinates.
|
* data coordinates.
|
||||||
@ -239,7 +239,7 @@ public class Plot implements DataListener {
|
|||||||
return curves;
|
return curves;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the annotation layer.
|
* Returns the annotation layer.
|
||||||
* @return <tt>null</tt> if no annotation layer.
|
* @return <tt>null</tt> if no annotation layer.
|
||||||
@ -248,11 +248,11 @@ public class Plot implements DataListener {
|
|||||||
{
|
{
|
||||||
return _annotation;
|
return _annotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the annotation layer.
|
* Sets the annotation layer.
|
||||||
* @param annotation Any kind of graphics which will be drawn on the
|
* @param annotation Any kind of graphics which will be drawn on the
|
||||||
* top of the curves but may be covered by the legend.
|
* top of the curves but may be covered by the legend.
|
||||||
* Can be <tt>null</tt>.
|
* Can be <tt>null</tt>.
|
||||||
*/
|
*/
|
||||||
public void setAnnotation(GraphicalElement annotation)
|
public void setAnnotation(GraphicalElement annotation)
|
||||||
@ -260,7 +260,7 @@ public class Plot implements DataListener {
|
|||||||
_annotation = annotation;
|
_annotation = annotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns <tt>true</tt> if the legend is visible. */
|
/** Returns <tt>true</tt> if the legend is visible. */
|
||||||
public boolean isLegendVisible() {
|
public boolean isLegendVisible() {
|
||||||
return _legendVisibility;
|
return _legendVisibility;
|
||||||
}
|
}
|
||||||
@ -271,7 +271,7 @@ public class Plot implements DataListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the received {@link DataEvent} and notifies
|
* Handles the received {@link DataEvent} and notifies
|
||||||
* {@link PlotListener PlotListeners} by an event of the type
|
* {@link PlotListener PlotListeners} by an event of the type
|
||||||
* {@link PlotEventType#DATA_CURVE_CHANGED} or
|
* {@link PlotEventType#DATA_CURVE_CHANGED} or
|
||||||
* {@link PlotEventType#DATA_PLOT_CHANGED}. The following table shows what
|
* {@link PlotEventType#DATA_PLOT_CHANGED}. The following table shows what
|
||||||
@ -291,23 +291,23 @@ public class Plot implements DataListener {
|
|||||||
* </table>
|
* </table>
|
||||||
*/
|
*/
|
||||||
public void dataChanged(DataEvent event) {
|
public void dataChanged(DataEvent event) {
|
||||||
Integer index = new Integer(0);
|
int index = 0;
|
||||||
PlotEventType type = PlotEventType.DATA_PLOT_CHANGED;
|
PlotEventType type = PlotEventType.DATA_PLOT_CHANGED;
|
||||||
synchronized (_curves) {
|
synchronized (_curves) {
|
||||||
int numberOfCurves = _curves.size();
|
int numberOfCurves = _curves.size();
|
||||||
if (event.getContainer() instanceof DataCurve
|
if (event.getContainer() instanceof DataCurve
|
||||||
&& numberOfCurves == _dataPlot.getNumberOfElements()) {
|
&& numberOfCurves == _dataPlot.getNumberOfElements()) {
|
||||||
DataCurve curve = (DataCurve) event.getContainer();
|
DataCurve curve = (DataCurve) event.getContainer();
|
||||||
index = new Integer(curve.getContainer().getIndexOf(curve));
|
index = curve.getContainer().getIndexOf(curve);
|
||||||
type = PlotEventType.DATA_CURVE_CHANGED;
|
type = PlotEventType.DATA_CURVE_CHANGED;
|
||||||
fillCurve(index.intValue(), curve);
|
fillCurve(index, curve);
|
||||||
if (index.intValue() < numberOfCurves - 1) {
|
if (index < numberOfCurves - 1) {
|
||||||
Vector curveHints
|
Vector curveHints
|
||||||
= (Vector) _nextCurveHints.elementAt(index.intValue());
|
= (Vector) _nextCurveHints.elementAt(index);
|
||||||
for (int i = 0, n = curveHints.size(); i < n; i++) {
|
for (int i = 0, n = curveHints.size(); i < n; i++) {
|
||||||
if (curveHints.elementAt(i) != null) {
|
if (curveHints.elementAt(i) != null) {
|
||||||
type = PlotEventType.DATA_PLOT_CHANGED;
|
type = PlotEventType.DATA_PLOT_CHANGED;
|
||||||
for (int j = index.intValue()+1; j < numberOfCurves; j++) {
|
for (int j = index +1; j < numberOfCurves; j++) {
|
||||||
fillCurve(j, (DataCurve) _dataPlot.getElement(j));
|
fillCurve(j, (DataCurve) _dataPlot.getElement(j));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -319,7 +319,7 @@ public class Plot implements DataListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifyListeners(new PlotEvent(Plot.this, type, index));
|
notifyListeners(new PlotEvent(Plot.this, type, index));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates all curves based on the specified data.
|
* Generates all curves based on the specified data.
|
||||||
@ -349,13 +349,13 @@ public class Plot implements DataListener {
|
|||||||
Curve curve = (Curve) _curves.elementAt(curveIndex);
|
Curve curve = (Curve) _curves.elementAt(curveIndex);
|
||||||
curve.removeAllPoints();
|
curve.removeAllPoints();
|
||||||
for (int i = 0, n = dataCurve.getNumberOfElements(); i < n; i++) {
|
for (int i = 0, n = dataCurve.getNumberOfElements(); i < n; i++) {
|
||||||
setHintForNextCurve(curveHints, i,
|
setHintForNextCurve(curveHints, i,
|
||||||
curve.addPoint(_transformation.transformToGraph(
|
curve.addPoint(_transformation.transformToGraph(
|
||||||
(DataPoint) dataCurve.getElement(i)),
|
(DataPoint) dataCurve.getElement(i)),
|
||||||
getHintForNextCurve(curveIndex - 1, i)));
|
getHintForNextCurve(curveIndex - 1, i)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Hint getHintForNextCurve(int curveIndex, int pointIndex) {
|
private Hint getHintForNextCurve(int curveIndex, int pointIndex) {
|
||||||
Hint result = _initialHintForNextCurve;
|
Hint result = _initialHintForNextCurve;
|
||||||
if (curveIndex >= 0) {
|
if (curveIndex >= 0) {
|
||||||
@ -366,8 +366,8 @@ public class Plot implements DataListener {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setHintForNextCurve(Vector curveHints, int pointIndex,
|
private void setHintForNextCurve(Vector curveHints, int pointIndex,
|
||||||
Hint hint) {
|
Hint hint) {
|
||||||
while (curveHints.size() <= pointIndex) {
|
while (curveHints.size() <= pointIndex) {
|
||||||
curveHints.addElement(_initialHintForNextCurve);
|
curveHints.addElement(_initialHintForNextCurve);
|
||||||
|
@ -51,15 +51,15 @@ import jcckit.util.TicLabelFormat;
|
|||||||
* <p>
|
* <p>
|
||||||
* Examples:
|
* Examples:
|
||||||
* <pre><tt>
|
* <pre><tt>
|
||||||
* 1=monday;2=tuesday;3=wednesday;4=thursday;5=friday;6=saturday;7=sunday
|
* 1=monday;2=tuesday;3=wednesday;4=thursday;5=friday;6=saturday;7=sunday
|
||||||
* 0.5:1.5=I; 1.5:2.5 = II; 2.5:3.5 = III; the rest
|
* 0.5:1.5=I; 1.5:2.5 = II; 2.5:3.5 = III; the rest
|
||||||
* </tt></pre>
|
* </tt></pre>
|
||||||
*
|
*
|
||||||
* @author Franz-Josef Elmer
|
* @author Franz-Josef Elmer
|
||||||
*/
|
*/
|
||||||
public class TicLabelMap implements TicLabelFormat {
|
public class TicLabelMap implements TicLabelFormat {
|
||||||
public static final String MAP_KEY = "map";
|
public static final String MAP_KEY = "map";
|
||||||
|
|
||||||
private static class MapItem {
|
private static class MapItem {
|
||||||
private double _min = Double.MIN_VALUE;
|
private double _min = Double.MIN_VALUE;
|
||||||
private double _max = Double.MAX_VALUE;
|
private double _max = Double.MAX_VALUE;
|
||||||
@ -73,7 +73,7 @@ public class TicLabelMap implements TicLabelFormat {
|
|||||||
item = item.substring(0, index).trim();
|
item = item.substring(0, index).trim();
|
||||||
index = item.indexOf(':');
|
index = item.indexOf(':');
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
_min = new Double(item).doubleValue();
|
_min = Double.parseDouble(item);
|
||||||
_max = _min == 0 ? Double.MIN_VALUE : _min * 1.000001d;
|
_max = _min == 0 ? Double.MIN_VALUE : _min * 1.000001d;
|
||||||
_min = _min * 0.999999d;
|
_min = _min * 0.999999d;
|
||||||
if (_min > _max) {
|
if (_min > _max) {
|
||||||
@ -82,18 +82,18 @@ public class TicLabelMap implements TicLabelFormat {
|
|||||||
_max = z;
|
_max = z;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_min = new Double(item.substring(0, index)).doubleValue();
|
_min = Double.parseDouble(item.substring(0, index));
|
||||||
_max = new Double(item.substring(index + 1)).doubleValue();
|
_max = Double.parseDouble(item.substring(index + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public boolean isInside(double value) {
|
public boolean isInside(double value) {
|
||||||
return value >= _min && value < _max;
|
return value >= _min && value < _max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final MapItem[] _map;
|
private final MapItem[] _map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance from the specified configuration parameters.
|
* Creates an instance from the specified configuration parameters.
|
||||||
* <table border=1 cellpadding=5>
|
* <table border=1 cellpadding=5>
|
||||||
@ -113,12 +113,12 @@ public class TicLabelMap implements TicLabelFormat {
|
|||||||
try {
|
try {
|
||||||
_map[i] = new MapItem(item.trim());
|
_map[i] = new MapItem(item.trim());
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new NumberFormatException("Item '" + item + "' of "
|
throw new NumberFormatException("Item '" + item + "' of "
|
||||||
+ config.getFullKey(MAP_KEY) + " has an invalid number.");
|
+ config.getFullKey(MAP_KEY) + " has an invalid number.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps the specified tic value onto a text label in accordance
|
* Maps the specified tic value onto a text label in accordance
|
||||||
* with the map description.
|
* with the map description.
|
||||||
|
@ -79,7 +79,7 @@ public class ConfigParameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the string value associated with the specified key or
|
* Returns the string value associated with the specified key or
|
||||||
* <tt>defaultValue</tt> if undefined.
|
* <tt>defaultValue</tt> if undefined.
|
||||||
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
||||||
* @param defaultValue The default value. Can be <tt>null</tt>.
|
* @param defaultValue The default value. Can be <tt>null</tt>.
|
||||||
@ -104,7 +104,7 @@ public class ConfigParameters {
|
|||||||
public boolean getBoolean(String key) {
|
public boolean getBoolean(String key) {
|
||||||
return parseBoolean(get(key), key);
|
return parseBoolean(get(key), key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the boolean associated with the specified key.
|
* Returns the boolean associated with the specified key.
|
||||||
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
||||||
@ -116,7 +116,7 @@ public class ConfigParameters {
|
|||||||
String value = _configData.get(key);
|
String value = _configData.get(key);
|
||||||
return value == null ? defaultValue : parseBoolean(value, key);
|
return value == null ? defaultValue : parseBoolean(value, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean parseBoolean(String value, String key) {
|
private boolean parseBoolean(String value, String key) {
|
||||||
if (value.equals("true")) {
|
if (value.equals("true")) {
|
||||||
return true;
|
return true;
|
||||||
@ -126,19 +126,19 @@ public class ConfigParameters {
|
|||||||
throw createNumberFormatException("boolean", value, key);
|
throw createNumberFormatException("boolean", value, key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private NumberFormatException createNumberFormatException(String text,
|
private NumberFormatException createNumberFormatException(String text,
|
||||||
String value,
|
String value,
|
||||||
String key) {
|
String key) {
|
||||||
return new NumberFormatException("Not a " + text + ": " + getFullKey(key)
|
return new NumberFormatException("Not a " + text + ": " + getFullKey(key)
|
||||||
+ " = " + value);
|
+ " = " + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the integer associated with the specified key.
|
* Returns the integer associated with the specified key.
|
||||||
* The value can be either
|
* The value can be either
|
||||||
* <ul><li>a decimal number (starting with a non-zero digit),
|
* <ul><li>a decimal number (starting with a non-zero digit),
|
||||||
* <li>a hexadecimal number (starting with <tt>0x</tt>), or
|
* <li>a hexadecimal number (starting with <tt>0x</tt>), or
|
||||||
* <li>an octal number (starting with zero).
|
* <li>an octal number (starting with zero).
|
||||||
* </ul>
|
* </ul>
|
||||||
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
||||||
@ -153,11 +153,11 @@ public class ConfigParameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the integer associated with the specified key or
|
* Returns the integer associated with the specified key or
|
||||||
* <tt>defaultValue</tt> if no key-value pair exists for the specified key.
|
* <tt>defaultValue</tt> if no key-value pair exists for the specified key.
|
||||||
* The value can be either
|
* The value can be either
|
||||||
* <ul><li>a decimal number (starting with a non-zero digit),
|
* <ul><li>a decimal number (starting with a non-zero digit),
|
||||||
* <li>a hexadecimal number (starting with <tt>0x</tt>), or
|
* <li>a hexadecimal number (starting with <tt>0x</tt>), or
|
||||||
* <li>an octal number (starting with zero).
|
* <li>an octal number (starting with zero).
|
||||||
* </ul>
|
* </ul>
|
||||||
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
||||||
@ -193,12 +193,12 @@ public class ConfigParameters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the double associated with the specified key or
|
* Returns the double associated with the specified key or
|
||||||
* <tt>defaultValue</tt> if no key-value pair exists for the specified key.
|
* <tt>defaultValue</tt> if no key-value pair exists for the specified key.
|
||||||
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
||||||
* @param defaultValue The default value. Can be <tt>null</tt>.
|
* @param defaultValue The default value. Can be <tt>null</tt>.
|
||||||
* @return the double value.
|
* @return the double value.
|
||||||
* @throws NumberFormatException if the value exists but is not a valid
|
* @throws NumberFormatException if the value exists but is not a valid
|
||||||
* number.
|
* number.
|
||||||
* The exception message contains the full key and the invalid value.
|
* The exception message contains the full key and the invalid value.
|
||||||
*/
|
*/
|
||||||
@ -209,7 +209,7 @@ public class ConfigParameters {
|
|||||||
|
|
||||||
private double parseDouble(String value, String key) {
|
private double parseDouble(String value, String key) {
|
||||||
try {
|
try {
|
||||||
return new Double(value).doubleValue();
|
return Double.parseDouble(value);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw createNumberFormatException("number", value, key);
|
throw createNumberFormatException("number", value, key);
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ public class ConfigParameters {
|
|||||||
StringTokenizer tokenizer = new StringTokenizer(value);
|
StringTokenizer tokenizer = new StringTokenizer(value);
|
||||||
double[] result = new double[tokenizer.countTokens()];
|
double[] result = new double[tokenizer.countTokens()];
|
||||||
for (int i = 0; i < result.length; i++) {
|
for (int i = 0; i < result.length; i++) {
|
||||||
result[i] = new Double(tokenizer.nextToken()).doubleValue();
|
result[i] = Double.parseDouble(tokenizer.nextToken());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
@ -261,9 +261,9 @@ public class ConfigParameters {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the color associated with the specified key.
|
* Returns the color associated with the specified key.
|
||||||
* The color is coded as
|
* The color is coded as
|
||||||
* <ul><li>a decimal number (starting with a non-zero digit),
|
* <ul><li>a decimal number (starting with a non-zero digit),
|
||||||
* <li>a hexadecimal number (starting with <tt>0x</tt>), or
|
* <li>a hexadecimal number (starting with <tt>0x</tt>), or
|
||||||
* <li>an octal number (starting with zero).
|
* <li>an octal number (starting with zero).
|
||||||
* </ul>
|
* </ul>
|
||||||
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
||||||
@ -278,9 +278,9 @@ public class ConfigParameters {
|
|||||||
/**
|
/**
|
||||||
* Returns the color associated with the specified key or the specified
|
* Returns the color associated with the specified key or the specified
|
||||||
* default value if no key-value pair exists for the specified key.
|
* default value if no key-value pair exists for the specified key.
|
||||||
* The color is coded as
|
* The color is coded as
|
||||||
* <ul><li>a decimal number (starting with a non-zero digit),
|
* <ul><li>a decimal number (starting with a non-zero digit),
|
||||||
* <li>a hexadecimal number (starting with <tt>0x</tt>), or
|
* <li>a hexadecimal number (starting with <tt>0x</tt>), or
|
||||||
* <li>an octal number (starting with zero).
|
* <li>an octal number (starting with zero).
|
||||||
* </ul>
|
* </ul>
|
||||||
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
* @param key The (relative) key. <tt>null</tt> is not allowed.
|
||||||
@ -313,7 +313,7 @@ private Color decodeInternal(String value) {
|
|||||||
}
|
}
|
||||||
return Color.decode(value);
|
return Color.decode(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the child node associated with the specified key.
|
* Returns the child node associated with the specified key.
|
||||||
* This method returns in any case a non-<tt>null</tt> result.
|
* This method returns in any case a non-<tt>null</tt> result.
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2020, Arnaud Roques
|
* (C) Copyright 2009-2020, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: http://plantuml.com
|
* Project Info: http://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* http://plantuml.com/patreon (only 1$ per month!)
|
* http://plantuml.com/patreon (only 1$ per month!)
|
||||||
* http://plantuml.com/paypal
|
* http://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.eggs;
|
package net.sourceforge.plantuml.eggs;
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2020, Arnaud Roques
|
* (C) Copyright 2009-2020, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: http://plantuml.com
|
* Project Info: http://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* http://plantuml.com/patreon (only 1$ per month!)
|
* http://plantuml.com/patreon (only 1$ per month!)
|
||||||
* http://plantuml.com/paypal
|
* http://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.graphic;
|
package net.sourceforge.plantuml.graphic;
|
||||||
@ -61,7 +61,7 @@ class ColorAndSizeChange implements FontChange {
|
|||||||
}
|
}
|
||||||
final Matcher2 matcherSize = sizePattern.matcher(s);
|
final Matcher2 matcherSize = sizePattern.matcher(s);
|
||||||
if (matcherSize.find()) {
|
if (matcherSize.find()) {
|
||||||
size = new Integer(matcherSize.group(1));
|
size = Integer.valueOf(matcherSize.group(1));
|
||||||
} else {
|
} else {
|
||||||
size = null;
|
size = null;
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2020, Arnaud Roques
|
* (C) Copyright 2009-2020, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: http://plantuml.com
|
* Project Info: http://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* http://plantuml.com/patreon (only 1$ per month!)
|
* http://plantuml.com/patreon (only 1$ per month!)
|
||||||
* http://plantuml.com/paypal
|
* http://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.graphic;
|
package net.sourceforge.plantuml.graphic;
|
||||||
@ -50,7 +50,7 @@ class SizeChange implements FontChange {
|
|||||||
if (matcherSize.find() == false) {
|
if (matcherSize.find() == false) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
size = new Integer(matcherSize.group(1));
|
size = Integer.valueOf(matcherSize.group(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer getSize() {
|
Integer getSize() {
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2020, Arnaud Roques
|
* (C) Copyright 2009-2020, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: http://plantuml.com
|
* Project Info: http://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* http://plantuml.com/patreon (only 1$ per month!)
|
* http://plantuml.com/patreon (only 1$ per month!)
|
||||||
* http://plantuml.com/paypal
|
* http://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.logo;
|
package net.sourceforge.plantuml.logo;
|
||||||
@ -45,29 +45,29 @@ class LogoScanner {
|
|||||||
private int i;
|
private int i;
|
||||||
|
|
||||||
public LogoScanner() {
|
public LogoScanner() {
|
||||||
keywordTable.put("forward", new Integer(LogoToken.FORWARD));
|
keywordTable.put("forward", LogoToken.FORWARD);
|
||||||
keywordTable.put("fd", new Integer(LogoToken.FORWARD));
|
keywordTable.put("fd", LogoToken.FORWARD);
|
||||||
keywordTable.put("back", new Integer(LogoToken.BACK));
|
keywordTable.put("back", LogoToken.BACK);
|
||||||
keywordTable.put("bk", new Integer(LogoToken.BACK));
|
keywordTable.put("bk", LogoToken.BACK);
|
||||||
keywordTable.put("right", new Integer(LogoToken.RIGHT));
|
keywordTable.put("right", LogoToken.RIGHT);
|
||||||
keywordTable.put("rt", new Integer(LogoToken.RIGHT));
|
keywordTable.put("rt", LogoToken.RIGHT);
|
||||||
keywordTable.put("left", new Integer(LogoToken.LEFT));
|
keywordTable.put("left", LogoToken.LEFT);
|
||||||
keywordTable.put("lt", new Integer(LogoToken.LEFT));
|
keywordTable.put("lt", LogoToken.LEFT);
|
||||||
keywordTable.put("penup", new Integer(LogoToken.PENUP));
|
keywordTable.put("penup", LogoToken.PENUP);
|
||||||
keywordTable.put("pu", new Integer(LogoToken.PENUP));
|
keywordTable.put("pu", LogoToken.PENUP);
|
||||||
keywordTable.put("pendown", new Integer(LogoToken.PENDOWN));
|
keywordTable.put("pendown", LogoToken.PENDOWN);
|
||||||
keywordTable.put("pd", new Integer(LogoToken.PENDOWN));
|
keywordTable.put("pd", LogoToken.PENDOWN);
|
||||||
keywordTable.put("hideturtle", new Integer(LogoToken.HIDETURTLE));
|
keywordTable.put("hideturtle", LogoToken.HIDETURTLE);
|
||||||
keywordTable.put("ht", new Integer(LogoToken.HIDETURTLE));
|
keywordTable.put("ht", LogoToken.HIDETURTLE);
|
||||||
keywordTable.put("showturtle", new Integer(LogoToken.SHOWTURTLE));
|
keywordTable.put("showturtle", LogoToken.SHOWTURTLE);
|
||||||
keywordTable.put("st", new Integer(LogoToken.SHOWTURTLE));
|
keywordTable.put("st", LogoToken.SHOWTURTLE);
|
||||||
keywordTable.put("clearscreen", new Integer(LogoToken.CLEARSCREEN));
|
keywordTable.put("clearscreen", LogoToken.CLEARSCREEN);
|
||||||
keywordTable.put("cs", new Integer(LogoToken.CLEARSCREEN));
|
keywordTable.put("cs", LogoToken.CLEARSCREEN);
|
||||||
keywordTable.put("repeat", new Integer(LogoToken.REPEAT));
|
keywordTable.put("repeat", LogoToken.REPEAT);
|
||||||
keywordTable.put("rep", new Integer(LogoToken.REPEAT));
|
keywordTable.put("rep", LogoToken.REPEAT);
|
||||||
keywordTable.put("to", new Integer(LogoToken.TO));
|
keywordTable.put("to", LogoToken.TO);
|
||||||
keywordTable.put("setpc", new Integer(LogoToken.SETPC));
|
keywordTable.put("setpc", LogoToken.SETPC);
|
||||||
keywordTable.put("pc", new Integer(LogoToken.SETPC));
|
keywordTable.put("pc", LogoToken.SETPC);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPosition() {
|
public int getPosition() {
|
||||||
@ -134,7 +134,7 @@ class LogoScanner {
|
|||||||
token.kind = LogoToken.IDENTIFIER;
|
token.kind = LogoToken.IDENTIFIER;
|
||||||
final Integer keyword = keywordTable.get(token.lexeme);
|
final Integer keyword = keywordTable.get(token.lexeme);
|
||||||
if (keyword != null) {
|
if (keyword != null) {
|
||||||
token.kind = keyword.intValue();
|
token.kind = keyword;
|
||||||
}
|
}
|
||||||
} else if (c >= '0' && c <= '9') {
|
} else if (c >= '0' && c <= '9') {
|
||||||
do {
|
do {
|
||||||
@ -151,12 +151,12 @@ class LogoScanner {
|
|||||||
}
|
}
|
||||||
i--;
|
i--;
|
||||||
token.lexeme = lexeme.toString();
|
token.lexeme = lexeme.toString();
|
||||||
token.value = Float.valueOf(token.lexeme).floatValue();
|
token.value = Float.parseFloat(token.lexeme);
|
||||||
if (hasDecimalPart) {
|
if (hasDecimalPart) {
|
||||||
token.kind = LogoToken.FLOAT;
|
token.kind = LogoToken.FLOAT;
|
||||||
} else {
|
} else {
|
||||||
token.kind = LogoToken.INTEGER;
|
token.kind = LogoToken.INTEGER;
|
||||||
token.intValue = Integer.valueOf(token.lexeme).intValue();
|
token.intValue = Integer.parseInt(token.lexeme);
|
||||||
}
|
}
|
||||||
} else if (c == 0) {
|
} else if (c == 0) {
|
||||||
i--;
|
i--;
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2020, Arnaud Roques
|
* (C) Copyright 2009-2020, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: http://plantuml.com
|
* Project Info: http://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* http://plantuml.com/patreon (only 1$ per month!)
|
* http://plantuml.com/patreon (only 1$ per month!)
|
||||||
* http://plantuml.com/paypal
|
* http://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.project.time;
|
package net.sourceforge.plantuml.project.time;
|
||||||
@ -68,7 +68,7 @@ public class Instant implements Comparable<Instant>, Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Long toLong() {
|
private Long toLong() {
|
||||||
return new Long(ms);
|
return Long.valueOf(ms);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
* (C) Copyright 2009-2020, Arnaud Roques
|
* (C) Copyright 2009-2020, Arnaud Roques
|
||||||
*
|
*
|
||||||
* Project Info: http://plantuml.com
|
* Project Info: http://plantuml.com
|
||||||
*
|
*
|
||||||
* If you like this project or if you find it useful, you can support us at:
|
* If you like this project or if you find it useful, you can support us at:
|
||||||
*
|
*
|
||||||
* http://plantuml.com/patreon (only 1$ per month!)
|
* http://plantuml.com/patreon (only 1$ per month!)
|
||||||
* http://plantuml.com/paypal
|
* http://plantuml.com/paypal
|
||||||
*
|
*
|
||||||
* This file is part of PlantUML.
|
* This file is part of PlantUML.
|
||||||
*
|
*
|
||||||
* PlantUML is free software; you can redistribute it and/or modify it
|
* PlantUML is free software; you can redistribute it and/or modify it
|
||||||
@ -30,7 +30,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Original Author: Arnaud Roques
|
* Original Author: Arnaud Roques
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.sequencediagram.graphic;
|
package net.sourceforge.plantuml.sequencediagram.graphic;
|
||||||
@ -62,7 +62,7 @@ public class Segment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return new Double(pos1).hashCode() + new Double(pos2).hashCode();
|
return Double.valueOf(pos1).hashCode() + Double.valueOf(pos2).hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
final public boolean contains(double y) {
|
final public boolean contains(double y) {
|
||||||
@ -113,8 +113,7 @@ public class Segment {
|
|||||||
return Collections.unmodifiableCollection(result2);
|
return Collections.unmodifiableCollection(result2);
|
||||||
}
|
}
|
||||||
if (this.contains(pause)) {
|
if (this.contains(pause)) {
|
||||||
if (pendingStart < pause.pos1)
|
result2.add(new Segment(pendingStart, pause.pos1));
|
||||||
result2.add(new Segment(pendingStart, pause.pos1));
|
|
||||||
pendingStart = pause.pos2;
|
pendingStart = pause.pos2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* DiTAA - Diagrams Through Ascii Art
|
* DiTAA - Diagrams Through Ascii Art
|
||||||
*
|
*
|
||||||
* Copyright (C) 2004 Efstathios Sideris
|
* Copyright (C) 2004 Efstathios Sideris
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
@ -16,7 +16,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.stathissideris.ascii2image.graphics;
|
package org.stathissideris.ascii2image.graphics;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ import org.stathissideris.ascii2image.text.CellSet;
|
|||||||
import org.stathissideris.ascii2image.text.TextGrid;
|
import org.stathissideris.ascii2image.text.TextGrid;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Efstathios Sideris
|
* @author Efstathios Sideris
|
||||||
*/
|
*/
|
||||||
public class Diagram {
|
public class Diagram {
|
||||||
@ -44,17 +44,17 @@ public class Diagram {
|
|||||||
private ArrayList shapes = new ArrayList();
|
private ArrayList shapes = new ArrayList();
|
||||||
private ArrayList compositeShapes = new ArrayList();
|
private ArrayList compositeShapes = new ArrayList();
|
||||||
private ArrayList textObjects = new ArrayList();
|
private ArrayList textObjects = new ArrayList();
|
||||||
|
|
||||||
private int width, height;
|
private int width, height;
|
||||||
private int cellWidth, cellHeight;
|
private int cellWidth, cellHeight;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* <p>An outline of the inner workings of this very important (and monstrous)
|
* <p>An outline of the inner workings of this very important (and monstrous)
|
||||||
* constructor is presented here. Boundary processing is the first step
|
* constructor is presented here. Boundary processing is the first step
|
||||||
* of the process:</p>
|
* of the process:</p>
|
||||||
*
|
*
|
||||||
* <ol>
|
* <ol>
|
||||||
* <li>Copy the grid into a work grid and remove all type-on-line
|
* <li>Copy the grid into a work grid and remove all type-on-line
|
||||||
* and point markers from the work grid</li>
|
* and point markers from the work grid</li>
|
||||||
@ -84,10 +84,10 @@ public class Diagram {
|
|||||||
* <li>If we had to eliminate any mixed shapes, we seperate the found
|
* <li>If we had to eliminate any mixed shapes, we seperate the found
|
||||||
* boundary sets again to open, closed or mixed.</li>
|
* boundary sets again to open, closed or mixed.</li>
|
||||||
* </ol>
|
* </ol>
|
||||||
*
|
*
|
||||||
* <p>At this stage, the boundary processing is all complete and we
|
* <p>At this stage, the boundary processing is all complete and we
|
||||||
* proceed with using those boundaries to create the shapes:</p>
|
* proceed with using those boundaries to create the shapes:</p>
|
||||||
*
|
*
|
||||||
* <ol>
|
* <ol>
|
||||||
* <li>Create closed shapes.</li>
|
* <li>Create closed shapes.</li>
|
||||||
* <li>Create open shapes. That's when the line end corrections are
|
* <li>Create open shapes. That's when the line end corrections are
|
||||||
@ -99,34 +99,34 @@ public class Diagram {
|
|||||||
* <li>Create arrowheads.</p>
|
* <li>Create arrowheads.</p>
|
||||||
* <li>Create point markers.</p>
|
* <li>Create point markers.</p>
|
||||||
* </ol>
|
* </ol>
|
||||||
*
|
*
|
||||||
* <p>Finally, the text processing occurs: [pending]</p>
|
* <p>Finally, the text processing occurs: [pending]</p>
|
||||||
*
|
*
|
||||||
* @param grid
|
* @param grid
|
||||||
* @param options
|
* @param options
|
||||||
* @param processingOptions
|
* @param processingOptions
|
||||||
*/
|
*/
|
||||||
public Diagram(TextGrid grid, ConversionOptions options, ProcessingOptions processingOptions) {
|
public Diagram(TextGrid grid, ConversionOptions options, ProcessingOptions processingOptions) {
|
||||||
|
|
||||||
this.cellWidth = options.renderingOptions.getCellWidth();
|
this.cellWidth = options.renderingOptions.getCellWidth();
|
||||||
this.cellHeight = options.renderingOptions.getCellHeight();
|
this.cellHeight = options.renderingOptions.getCellHeight();
|
||||||
|
|
||||||
width = grid.getWidth() * cellWidth;
|
width = grid.getWidth() * cellWidth;
|
||||||
height = grid.getHeight() * cellHeight;
|
height = grid.getHeight() * cellHeight;
|
||||||
|
|
||||||
TextGrid workGrid = new TextGrid(grid);
|
TextGrid workGrid = new TextGrid(grid);
|
||||||
workGrid.replaceTypeOnLine();
|
workGrid.replaceTypeOnLine();
|
||||||
workGrid.replacePointMarkersOnLine();
|
workGrid.replacePointMarkersOnLine();
|
||||||
if(DEBUG) workGrid.printDebug();
|
if(DEBUG) workGrid.printDebug();
|
||||||
|
|
||||||
int width = grid.getWidth();
|
int width = grid.getWidth();
|
||||||
int height = grid.getHeight();
|
int height = grid.getHeight();
|
||||||
|
|
||||||
|
|
||||||
//split distinct shapes using AbstractionGrid
|
//split distinct shapes using AbstractionGrid
|
||||||
AbstractionGrid temp = new AbstractionGrid(workGrid, workGrid.getAllBoundaries());
|
AbstractionGrid temp = new AbstractionGrid(workGrid, workGrid.getAllBoundaries());
|
||||||
ArrayList boundarySetsStep1 = temp.getDistinctShapes();
|
ArrayList boundarySetsStep1 = temp.getDistinctShapes();
|
||||||
|
|
||||||
if(DEBUG){
|
if(DEBUG){
|
||||||
System.out.println("******* Distinct shapes found using AbstractionGrid *******");
|
System.out.println("******* Distinct shapes found using AbstractionGrid *******");
|
||||||
Iterator dit = boundarySetsStep1.iterator();
|
Iterator dit = boundarySetsStep1.iterator();
|
||||||
@ -136,23 +136,23 @@ public class Diagram {
|
|||||||
}
|
}
|
||||||
System.out.println("******* Same set of shapes after processing them by filling *******");
|
System.out.println("******* Same set of shapes after processing them by filling *******");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Find all the boundaries by using the special version of the filling method
|
//Find all the boundaries by using the special version of the filling method
|
||||||
//(fills in a different buffer than the buffer it reads from)
|
//(fills in a different buffer than the buffer it reads from)
|
||||||
ArrayList boundarySetsStep2 = new ArrayList();
|
ArrayList boundarySetsStep2 = new ArrayList();
|
||||||
Iterator boundarySetIt = boundarySetsStep1.iterator();
|
Iterator boundarySetIt = boundarySetsStep1.iterator();
|
||||||
while (boundarySetIt.hasNext()) {
|
while (boundarySetIt.hasNext()) {
|
||||||
CellSet set = (CellSet) boundarySetIt.next();
|
CellSet set = (CellSet) boundarySetIt.next();
|
||||||
|
|
||||||
//the fill buffer keeps track of which cells have been
|
//the fill buffer keeps track of which cells have been
|
||||||
//filled already
|
//filled already
|
||||||
TextGrid fillBuffer = new TextGrid(width * 3, height * 3);
|
TextGrid fillBuffer = new TextGrid(width * 3, height * 3);
|
||||||
|
|
||||||
for(int yi = 0; yi < height * 3; yi++){
|
for(int yi = 0; yi < height * 3; yi++){
|
||||||
for(int xi = 0; xi < width * 3; xi++){
|
for(int xi = 0; xi < width * 3; xi++){
|
||||||
if(fillBuffer.isBlank(xi, yi)){
|
if(fillBuffer.isBlank(xi, yi)){
|
||||||
|
|
||||||
TextGrid copyGrid = new AbstractionGrid(workGrid, set).getCopyOfInternalBuffer();
|
TextGrid copyGrid = new AbstractionGrid(workGrid, set).getCopyOfInternalBuffer();
|
||||||
|
|
||||||
CellSet boundaries =
|
CellSet boundaries =
|
||||||
@ -160,21 +160,21 @@ public class Diagram {
|
|||||||
.findBoundariesExpandingFrom(copyGrid.new Cell(xi, yi));
|
.findBoundariesExpandingFrom(copyGrid.new Cell(xi, yi));
|
||||||
if(boundaries.size() == 0) continue; //i'm not sure why these occur
|
if(boundaries.size() == 0) continue; //i'm not sure why these occur
|
||||||
boundarySetsStep2.add(boundaries.makeScaledOneThirdEquivalent());
|
boundarySetsStep2.add(boundaries.makeScaledOneThirdEquivalent());
|
||||||
|
|
||||||
copyGrid = new AbstractionGrid(workGrid, set).getCopyOfInternalBuffer();
|
copyGrid = new AbstractionGrid(workGrid, set).getCopyOfInternalBuffer();
|
||||||
CellSet filled =
|
CellSet filled =
|
||||||
copyGrid
|
copyGrid
|
||||||
.fillContinuousArea(copyGrid.new Cell(xi, yi), '*');
|
.fillContinuousArea(copyGrid.new Cell(xi, yi), '*');
|
||||||
fillBuffer.fillCellsWith(filled, '*');
|
fillBuffer.fillCellsWith(filled, '*');
|
||||||
fillBuffer.fillCellsWith(boundaries, '-');
|
fillBuffer.fillCellsWith(boundaries, '-');
|
||||||
|
|
||||||
if(DEBUG){
|
if(DEBUG){
|
||||||
//System.out.println("Fill buffer:");
|
//System.out.println("Fill buffer:");
|
||||||
//fillBuffer.printDebug();
|
//fillBuffer.printDebug();
|
||||||
boundaries.makeScaledOneThirdEquivalent().printAsGrid();
|
boundaries.makeScaledOneThirdEquivalent().printAsGrid();
|
||||||
System.out.println("-----------------------------------");
|
System.out.println("-----------------------------------");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -193,7 +193,7 @@ public class Diagram {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int originalSize = boundarySetsStep2.size();
|
int originalSize = boundarySetsStep2.size();
|
||||||
boundarySetsStep2 = CellSet.removeDuplicateSets(boundarySetsStep2);
|
boundarySetsStep2 = CellSet.removeDuplicateSets(boundarySetsStep2);
|
||||||
if(DEBUG) {
|
if(DEBUG) {
|
||||||
System.out.println(
|
System.out.println(
|
||||||
@ -201,18 +201,18 @@ public class Diagram {
|
|||||||
+originalSize
|
+originalSize
|
||||||
+" shapes and now there are "
|
+" shapes and now there are "
|
||||||
+boundarySetsStep2.size());
|
+boundarySetsStep2.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//split boundaries to open, closed and mixed
|
//split boundaries to open, closed and mixed
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println("******* First evaluation of openess *******");
|
System.out.println("******* First evaluation of openess *******");
|
||||||
|
|
||||||
ArrayList open = new ArrayList();
|
ArrayList open = new ArrayList();
|
||||||
ArrayList closed = new ArrayList();
|
ArrayList closed = new ArrayList();
|
||||||
ArrayList mixed = new ArrayList();
|
ArrayList mixed = new ArrayList();
|
||||||
|
|
||||||
Iterator sets = boundarySetsStep2.iterator();
|
Iterator sets = boundarySetsStep2.iterator();
|
||||||
while(sets.hasNext()){
|
while(sets.hasNext()){
|
||||||
CellSet set = (CellSet) sets.next();
|
CellSet set = (CellSet) sets.next();
|
||||||
@ -227,17 +227,17 @@ public class Diagram {
|
|||||||
set.printAsGrid();
|
set.printAsGrid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hadToEliminateMixed = false;
|
boolean hadToEliminateMixed = false;
|
||||||
|
|
||||||
if(mixed.size() > 0 && closed.size() > 0) {
|
if(mixed.size() > 0 && closed.size() > 0) {
|
||||||
// mixed shapes can be eliminated by
|
// mixed shapes can be eliminated by
|
||||||
// subtracting all the closed shapes from them
|
// subtracting all the closed shapes from them
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println("******* Eliminating mixed shapes (basic algorithm) *******");
|
System.out.println("******* Eliminating mixed shapes (basic algorithm) *******");
|
||||||
|
|
||||||
hadToEliminateMixed = true;
|
hadToEliminateMixed = true;
|
||||||
|
|
||||||
//subtract from each of the mixed sets all the closed sets
|
//subtract from each of the mixed sets all the closed sets
|
||||||
sets = mixed.iterator();
|
sets = mixed.iterator();
|
||||||
while(sets.hasNext()){
|
while(sets.hasNext()){
|
||||||
@ -258,7 +258,7 @@ public class Diagram {
|
|||||||
|
|
||||||
} else if(mixed.size() > 0 && closed.size() == 0) {
|
} else if(mixed.size() > 0 && closed.size() == 0) {
|
||||||
// no closed shape exists, will have to
|
// no closed shape exists, will have to
|
||||||
// handle mixed shape on its own
|
// handle mixed shape on its own
|
||||||
// an example of this case is the following:
|
// an example of this case is the following:
|
||||||
// +-----+
|
// +-----+
|
||||||
// | A |C B
|
// | A |C B
|
||||||
@ -270,7 +270,7 @@ public class Diagram {
|
|||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println("******* Eliminating mixed shapes (advanced algorithm for truly mixed shapes) *******");
|
System.out.println("******* Eliminating mixed shapes (advanced algorithm for truly mixed shapes) *******");
|
||||||
|
|
||||||
sets = mixed.iterator();
|
sets = mixed.iterator();
|
||||||
while(sets.hasNext()){
|
while(sets.hasNext()){
|
||||||
CellSet set = (CellSet) sets.next();
|
CellSet set = (CellSet) sets.next();
|
||||||
@ -282,17 +282,17 @@ public class Diagram {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println("No mixed shapes found. Skipped mixed shape elimination step");
|
System.out.println("No mixed shapes found. Skipped mixed shape elimination step");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(hadToEliminateMixed){
|
if(hadToEliminateMixed){
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println("******* Second evaluation of openess *******");
|
System.out.println("******* Second evaluation of openess *******");
|
||||||
|
|
||||||
//split boundaries again to open, closed and mixed
|
//split boundaries again to open, closed and mixed
|
||||||
open = new ArrayList();
|
open = new ArrayList();
|
||||||
closed = new ArrayList();
|
closed = new ArrayList();
|
||||||
mixed = new ArrayList();
|
mixed = new ArrayList();
|
||||||
|
|
||||||
sets = boundarySetsStep2.iterator();
|
sets = boundarySetsStep2.iterator();
|
||||||
while(sets.hasNext()){
|
while(sets.hasNext()){
|
||||||
CellSet set = (CellSet) sets.next();
|
CellSet set = (CellSet) sets.next();
|
||||||
@ -310,17 +310,17 @@ public class Diagram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean removedAnyObsolete = removeObsoleteShapes(workGrid, closed);
|
boolean removedAnyObsolete = removeObsoleteShapes(workGrid, closed);
|
||||||
|
|
||||||
boolean allCornersRound = false;
|
boolean allCornersRound = false;
|
||||||
if(processingOptions.areAllCornersRound()) allCornersRound = true;
|
if(processingOptions.areAllCornersRound()) allCornersRound = true;
|
||||||
|
|
||||||
//make shapes from the boundary sets
|
//make shapes from the boundary sets
|
||||||
//make closed shapes
|
//make closed shapes
|
||||||
ArrayList closedShapes = new ArrayList();
|
ArrayList closedShapes = new ArrayList();
|
||||||
sets = closed.iterator();
|
sets = closed.iterator();
|
||||||
while(sets.hasNext()){
|
while(sets.hasNext()){
|
||||||
CellSet set = (CellSet) sets.next();
|
CellSet set = (CellSet) sets.next();
|
||||||
DiagramComponent shape = DiagramComponent.createClosedFromBoundaryCells(workGrid, set, cellWidth, cellHeight, allCornersRound);
|
DiagramComponent shape = DiagramComponent.createClosedFromBoundaryCells(workGrid, set, cellWidth, cellHeight, allCornersRound);
|
||||||
if(shape != null){
|
if(shape != null){
|
||||||
if(shape instanceof DiagramShape){
|
if(shape instanceof DiagramShape){
|
||||||
addToShapes((DiagramShape) shape);
|
addToShapes((DiagramShape) shape);
|
||||||
@ -339,10 +339,10 @@ public class Diagram {
|
|||||||
CellSet set = (CellSet) sets.next();
|
CellSet set = (CellSet) sets.next();
|
||||||
if(set.size() == 1){ //single cell "shape"
|
if(set.size() == 1){ //single cell "shape"
|
||||||
TextGrid.Cell cell = (TextGrid.Cell) set.getFirst();
|
TextGrid.Cell cell = (TextGrid.Cell) set.getFirst();
|
||||||
if(!grid.cellContainsDashedLineChar(cell)) {
|
if(!grid.cellContainsDashedLineChar(cell)) {
|
||||||
DiagramShape shape = DiagramShape.createSmallLine(workGrid, cell, cellWidth, cellHeight);
|
DiagramShape shape = DiagramShape.createSmallLine(workGrid, cell, cellWidth, cellHeight);
|
||||||
if(shape != null) {
|
if(shape != null) {
|
||||||
addToShapes(shape);
|
addToShapes(shape);
|
||||||
shape.connectEndsToAnchors(workGrid, this);
|
shape.connectEndsToAnchors(workGrid, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,14 +362,14 @@ public class Diagram {
|
|||||||
((DiagramShape) shape).moveEndsToCellEdges(grid, this);
|
((DiagramShape) shape).moveEndsToCellEdges(grid, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//assign color codes to shapes
|
//assign color codes to shapes
|
||||||
//TODO: text on line should not change its color
|
//TODO: text on line should not change its color
|
||||||
//TODO: each color tag should be assigned to the smallest containing shape (like shape tags)
|
//TODO: each color tag should be assigned to the smallest containing shape (like shape tags)
|
||||||
|
|
||||||
Iterator cellColorPairs = grid.findColorCodes().iterator();
|
Iterator cellColorPairs = grid.findColorCodes().iterator();
|
||||||
while(cellColorPairs.hasNext()){
|
while(cellColorPairs.hasNext()){
|
||||||
TextGrid.CellColorPair pair =
|
TextGrid.CellColorPair pair =
|
||||||
@ -379,7 +379,7 @@ public class Diagram {
|
|||||||
Iterator shapes = getShapes().iterator();
|
Iterator shapes = getShapes().iterator();
|
||||||
while(shapes.hasNext()){
|
while(shapes.hasNext()){
|
||||||
DiagramShape shape = (DiagramShape) shapes.next();
|
DiagramShape shape = (DiagramShape) shapes.next();
|
||||||
if(shape.contains(point)) shape.setFillColor(pair.color);
|
if(shape.contains(point)) shape.setFillColor(pair.color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,10 +406,10 @@ public class Diagram {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//this tag is not within a shape, skip
|
//this tag is not within a shape, skip
|
||||||
if(containingShape == null) continue;
|
if(containingShape == null) continue;
|
||||||
|
|
||||||
//TODO: the code below could be a lot more concise
|
//TODO: the code below could be a lot more concise
|
||||||
if(pair.tag.equals("d")){
|
if(pair.tag.equals("d")){
|
||||||
CustomShapeDefinition def =
|
CustomShapeDefinition def =
|
||||||
@ -478,10 +478,10 @@ public class Diagram {
|
|||||||
CustomShapeDefinition def =
|
CustomShapeDefinition def =
|
||||||
processingOptions.getFromCustomShapes(pair.tag);
|
processingOptions.getFromCustomShapes(pair.tag);
|
||||||
containingShape.setType(DiagramShape.TYPE_CUSTOM);
|
containingShape.setType(DiagramShape.TYPE_CUSTOM);
|
||||||
containingShape.setDefinition(def);
|
containingShape.setDefinition(def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//make arrowheads
|
//make arrowheads
|
||||||
Iterator arrowheadCells = workGrid.findArrowheads().iterator();
|
Iterator arrowheadCells = workGrid.findArrowheads().iterator();
|
||||||
while(arrowheadCells.hasNext()){
|
while(arrowheadCells.hasNext()){
|
||||||
@ -490,7 +490,7 @@ public class Diagram {
|
|||||||
if(arrowhead != null) addToShapes(arrowhead);
|
if(arrowhead != null) addToShapes(arrowhead);
|
||||||
else System.err.println("Could not create arrowhead shape. Unexpected error.");
|
else System.err.println("Could not create arrowhead shape. Unexpected error.");
|
||||||
}
|
}
|
||||||
|
|
||||||
//make point markers
|
//make point markers
|
||||||
Iterator markersIt = grid.getPointMarkersOnLine().iterator();
|
Iterator markersIt = grid.getPointMarkersOnLine().iterator();
|
||||||
while (markersIt.hasNext()) {
|
while (markersIt.hasNext()) {
|
||||||
@ -507,15 +507,15 @@ public class Diagram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeDuplicateShapes();
|
removeDuplicateShapes();
|
||||||
|
|
||||||
if(DEBUG) System.out.println("Shape count: "+shapes.size());
|
if(DEBUG) System.out.println("Shape count: "+shapes.size());
|
||||||
if(DEBUG) System.out.println("Composite shape count: "+compositeShapes.size());
|
if(DEBUG) System.out.println("Composite shape count: "+compositeShapes.size());
|
||||||
|
|
||||||
//copy again
|
//copy again
|
||||||
workGrid = new TextGrid(grid);
|
workGrid = new TextGrid(grid);
|
||||||
workGrid.removeNonText();
|
workGrid.removeNonText();
|
||||||
|
|
||||||
|
|
||||||
// ****** handle text *******
|
// ****** handle text *******
|
||||||
//break up text into groups
|
//break up text into groups
|
||||||
TextGrid textGroupGrid = new TextGrid(workGrid);
|
TextGrid textGroupGrid = new TextGrid(workGrid);
|
||||||
@ -525,16 +525,16 @@ public class Diagram {
|
|||||||
CellSet nonBlank = textGroupGrid.getAllNonBlank();
|
CellSet nonBlank = textGroupGrid.getAllNonBlank();
|
||||||
ArrayList textGroups = nonBlank.breakIntoDistinctBoundaries();
|
ArrayList textGroups = nonBlank.breakIntoDistinctBoundaries();
|
||||||
if(DEBUG) System.out.println(textGroups.size()+" text groups found");
|
if(DEBUG) System.out.println(textGroups.size()+" text groups found");
|
||||||
|
|
||||||
Font font = FontMeasurer.instance().getFontFor(cellHeight);
|
Font font = FontMeasurer.instance().getFontFor(cellHeight);
|
||||||
|
|
||||||
Iterator textGroupIt = textGroups.iterator();
|
Iterator textGroupIt = textGroups.iterator();
|
||||||
while(textGroupIt.hasNext()){
|
while(textGroupIt.hasNext()){
|
||||||
CellSet textGroupCellSet = (CellSet) textGroupIt.next();
|
CellSet textGroupCellSet = (CellSet) textGroupIt.next();
|
||||||
|
|
||||||
TextGrid isolationGrid = new TextGrid(width, height);
|
TextGrid isolationGrid = new TextGrid(width, height);
|
||||||
workGrid.copyCellsTo(textGroupCellSet, isolationGrid);
|
workGrid.copyCellsTo(textGroupCellSet, isolationGrid);
|
||||||
|
|
||||||
ArrayList strings = isolationGrid.findStrings();
|
ArrayList strings = isolationGrid.findStrings();
|
||||||
Iterator it = strings.iterator();
|
Iterator it = strings.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
@ -544,21 +544,21 @@ public class Diagram {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println("Found string "+string);
|
System.out.println("Found string "+string);
|
||||||
TextGrid.Cell lastCell = isolationGrid.new Cell(cell.x + string.length() - 1, cell.y);
|
TextGrid.Cell lastCell = isolationGrid.new Cell(cell.x + string.length() - 1, cell.y);
|
||||||
|
|
||||||
int minX = getCellMinX(cell);
|
int minX = getCellMinX(cell);
|
||||||
int y = getCellMaxY(cell);
|
int y = getCellMaxY(cell);
|
||||||
int maxX = getCellMaxX(lastCell);
|
int maxX = getCellMaxX(lastCell);
|
||||||
|
|
||||||
DiagramText textObject;
|
DiagramText textObject;
|
||||||
if(FontMeasurer.instance().getWidthFor(string, font) > maxX - minX){ //does not fit horizontally
|
if(FontMeasurer.instance().getWidthFor(string, font) > maxX - minX){ //does not fit horizontally
|
||||||
Font lessWideFont = FontMeasurer.instance().getFontFor(maxX - minX, string);
|
Font lessWideFont = FontMeasurer.instance().getFontFor(maxX - minX, string);
|
||||||
textObject = new DiagramText(minX, y, string, lessWideFont);
|
textObject = new DiagramText(minX, y, string, lessWideFont);
|
||||||
} else textObject = new DiagramText(minX, y, string, font);
|
} else textObject = new DiagramText(minX, y, string, font);
|
||||||
|
|
||||||
textObject.centerVerticallyBetween(getCellMinY(cell), getCellMaxY(cell));
|
textObject.centerVerticallyBetween(getCellMinY(cell), getCellMaxY(cell));
|
||||||
|
|
||||||
//TODO: if the strings start with bullets they should be aligned to the left
|
//TODO: if the strings start with bullets they should be aligned to the left
|
||||||
|
|
||||||
//position text correctly
|
//position text correctly
|
||||||
int otherStart = isolationGrid.otherStringsStartInTheSameColumn(cell);
|
int otherStart = isolationGrid.otherStringsStartInTheSameColumn(cell);
|
||||||
int otherEnd = isolationGrid.otherStringsEndInTheSameColumn(lastCell);
|
int otherEnd = isolationGrid.otherStringsEndInTheSameColumn(lastCell);
|
||||||
@ -573,14 +573,14 @@ public class Diagram {
|
|||||||
textObject.centerHorizontallyBetween(minX, maxX);
|
textObject.centerHorizontallyBetween(minX, maxX);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addToTextObjects(textObject);
|
addToTextObjects(textObject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println("Positioned text");
|
System.out.println("Positioned text");
|
||||||
|
|
||||||
//correct the color of the text objects according
|
//correct the color of the text objects according
|
||||||
//to the underlying color
|
//to the underlying color
|
||||||
Iterator shapes = this.getAllDiagramShapes().iterator();
|
Iterator shapes = this.getAllDiagramShapes().iterator();
|
||||||
@ -614,43 +614,43 @@ public class Diagram {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println("Corrected color of text according to underlying color");
|
System.out.println("Corrected color of text according to underlying color");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all DiagramShapes in the Diagram, including
|
* Returns a list of all DiagramShapes in the Diagram, including
|
||||||
* the ones within CompositeDiagramShapes
|
* the ones within CompositeDiagramShapes
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ArrayList getAllDiagramShapes(){
|
public ArrayList getAllDiagramShapes(){
|
||||||
ArrayList shapes = new ArrayList();
|
ArrayList shapes = new ArrayList();
|
||||||
shapes.addAll(this.getShapes());
|
shapes.addAll(this.getShapes());
|
||||||
|
|
||||||
Iterator shapesIt = this.getCompositeShapes().iterator();
|
Iterator shapesIt = this.getCompositeShapes().iterator();
|
||||||
while(shapesIt.hasNext()){
|
while(shapesIt.hasNext()){
|
||||||
CompositeDiagramShape compShape = (CompositeDiagramShape) shapesIt.next();
|
CompositeDiagramShape compShape = (CompositeDiagramShape) shapesIt.next();
|
||||||
shapes.addAll(compShape.getShapes());
|
shapes.addAll(compShape.getShapes());
|
||||||
}
|
}
|
||||||
return shapes;
|
return shapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the sets from <code>sets</code>that are the sum of their parts
|
* Removes the sets from <code>sets</code>that are the sum of their parts
|
||||||
* when plotted as filled shapes.
|
* when plotted as filled shapes.
|
||||||
*
|
*
|
||||||
* @return true if it removed any obsolete.
|
* @return true if it removed any obsolete.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private boolean removeObsoleteShapes(TextGrid grid, ArrayList<CellSet> sets){
|
private boolean removeObsoleteShapes(TextGrid grid, ArrayList<CellSet> sets){
|
||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
System.out.println("******* Removing obsolete shapes *******");
|
System.out.println("******* Removing obsolete shapes *******");
|
||||||
|
|
||||||
boolean removedAny = false;
|
boolean removedAny = false;
|
||||||
|
|
||||||
ArrayList<CellSet> filledSets = new ArrayList<CellSet>();
|
ArrayList<CellSet> filledSets = new ArrayList<CellSet>();
|
||||||
|
|
||||||
Iterator it;
|
Iterator it;
|
||||||
@ -673,17 +673,17 @@ public class Diagram {
|
|||||||
return false;
|
return false;
|
||||||
} else filledSets.add(set);
|
} else filledSets.add(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<Integer> toBeRemovedIndices = new ArrayList<Integer>();
|
ArrayList<Integer> toBeRemovedIndices = new ArrayList<Integer>();
|
||||||
it = filledSets.iterator();
|
it = filledSets.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
CellSet set = (CellSet) it.next();
|
CellSet set = (CellSet) it.next();
|
||||||
|
|
||||||
if(VERBOSE_DEBUG){
|
if(VERBOSE_DEBUG){
|
||||||
System.out.println("*** Deciding if the following should be removed:");
|
System.out.println("*** Deciding if the following should be removed:");
|
||||||
set.printAsGrid();
|
set.printAsGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
//find the other sets that have common cells with set
|
//find the other sets that have common cells with set
|
||||||
ArrayList<CellSet> common = new ArrayList<CellSet>();
|
ArrayList<CellSet> common = new ArrayList<CellSet>();
|
||||||
common.add(set);
|
common.add(set);
|
||||||
@ -696,7 +696,7 @@ public class Diagram {
|
|||||||
}
|
}
|
||||||
//it only makes sense for more than 2 sets
|
//it only makes sense for more than 2 sets
|
||||||
if(common.size() == 2) continue;
|
if(common.size() == 2) continue;
|
||||||
|
|
||||||
//find largest set
|
//find largest set
|
||||||
CellSet largest = set;
|
CellSet largest = set;
|
||||||
it2 = common.iterator();
|
it2 = common.iterator();
|
||||||
@ -706,7 +706,7 @@ public class Diagram {
|
|||||||
largest = set2;
|
largest = set2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(VERBOSE_DEBUG){
|
if(VERBOSE_DEBUG){
|
||||||
System.out.println("Largest:");
|
System.out.println("Largest:");
|
||||||
largest.printAsGrid();
|
largest.printAsGrid();
|
||||||
@ -736,8 +736,8 @@ public class Diagram {
|
|||||||
|
|
||||||
int index = filledSets.indexOf(largest);
|
int index = filledSets.indexOf(largest);
|
||||||
if(gridLargest.equals(gridOfSmalls)
|
if(gridLargest.equals(gridOfSmalls)
|
||||||
&& !toBeRemovedIndices.contains(new Integer(index))) {
|
&& !toBeRemovedIndices.contains(index)) {
|
||||||
toBeRemovedIndices.add(new Integer(index));
|
toBeRemovedIndices.add(index);
|
||||||
if (DEBUG){
|
if (DEBUG){
|
||||||
System.out.println("Decided to remove set:");
|
System.out.println("Decided to remove set:");
|
||||||
largest.printAsGrid();
|
largest.printAsGrid();
|
||||||
@ -748,21 +748,21 @@ public class Diagram {
|
|||||||
}
|
}
|
||||||
//if(gridLargest.equals(gridOfSmalls)) toBeRemovedIndices.add(new Integer(index));
|
//if(gridLargest.equals(gridOfSmalls)) toBeRemovedIndices.add(new Integer(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<CellSet> setsToBeRemoved = new ArrayList<CellSet>();
|
ArrayList<CellSet> setsToBeRemoved = new ArrayList<CellSet>();
|
||||||
it = toBeRemovedIndices.iterator();
|
it = toBeRemovedIndices.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
int i = ((Integer) it.next()).intValue();
|
int i = ((Integer) it.next()).intValue();
|
||||||
setsToBeRemoved.add(sets.get(i));
|
setsToBeRemoved.add(sets.get(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
it = setsToBeRemoved.iterator();
|
it = setsToBeRemoved.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
CellSet set = (CellSet) it.next();
|
CellSet set = (CellSet) it.next();
|
||||||
removedAny = true;
|
removedAny = true;
|
||||||
sets.remove(set);
|
sets.remove(set);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(VERBOSE_DEBUG) {
|
if(VERBOSE_DEBUG) {
|
||||||
System.out.println("******* Sets after *******");
|
System.out.println("******* Sets after *******");
|
||||||
it = sets.iterator();
|
it = sets.iterator();
|
||||||
@ -771,14 +771,14 @@ public class Diagram {
|
|||||||
set.printAsGrid();
|
set.printAsGrid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return removedAny;
|
return removedAny;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getMinimumOfCellDimension(){
|
public float getMinimumOfCellDimension(){
|
||||||
return Math.min(getCellWidth(), getCellHeight());
|
return Math.min(getCellWidth(), getCellHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void separateCommonEdges(ArrayList shapes){
|
private void separateCommonEdges(ArrayList shapes){
|
||||||
|
|
||||||
float offset = getMinimumOfCellDimension() / 5;
|
float offset = getMinimumOfCellDimension() / 5;
|
||||||
@ -791,29 +791,29 @@ public class Diagram {
|
|||||||
DiagramShape shape = (DiagramShape) it.next();
|
DiagramShape shape = (DiagramShape) it.next();
|
||||||
edges.addAll(shape.getEdges());
|
edges.addAll(shape.getEdges());
|
||||||
}
|
}
|
||||||
|
|
||||||
//group edges into pairs of touching edges
|
//group edges into pairs of touching edges
|
||||||
ArrayList<Pair<ShapeEdge, ShapeEdge>> listOfPairs = new ArrayList<Pair<ShapeEdge, ShapeEdge>>();
|
ArrayList<Pair<ShapeEdge, ShapeEdge>> listOfPairs = new ArrayList<Pair<ShapeEdge, ShapeEdge>>();
|
||||||
it = edges.iterator();
|
it = edges.iterator();
|
||||||
|
|
||||||
//all-against-all touching test for the edges
|
//all-against-all touching test for the edges
|
||||||
int startIndex = 1; //skip some to avoid duplicate comparisons and self-to-self comparisons
|
int startIndex = 1; //skip some to avoid duplicate comparisons and self-to-self comparisons
|
||||||
|
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
ShapeEdge edge1 = (ShapeEdge) it.next();
|
ShapeEdge edge1 = (ShapeEdge) it.next();
|
||||||
|
|
||||||
for(int k = startIndex; k < edges.size(); k++) {
|
for(int k = startIndex; k < edges.size(); k++) {
|
||||||
ShapeEdge edge2 = edges.get(k);
|
ShapeEdge edge2 = edges.get(k);
|
||||||
|
|
||||||
if(edge1.touchesWith(edge2)) {
|
if(edge1.touchesWith(edge2)) {
|
||||||
listOfPairs.add(new Pair<ShapeEdge, ShapeEdge>(edge1, edge2));
|
listOfPairs.add(new Pair<ShapeEdge, ShapeEdge>(edge1, edge2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startIndex++;
|
startIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<ShapeEdge> movedEdges = new ArrayList<ShapeEdge>();
|
ArrayList<ShapeEdge> movedEdges = new ArrayList<ShapeEdge>();
|
||||||
|
|
||||||
//move equivalent edges inwards
|
//move equivalent edges inwards
|
||||||
it = listOfPairs.iterator();
|
it = listOfPairs.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
@ -829,8 +829,8 @@ public class Diagram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO: removes more than it should
|
//TODO: removes more than it should
|
||||||
private void removeDuplicateShapes() {
|
private void removeDuplicateShapes() {
|
||||||
ArrayList originalShapes = new ArrayList();
|
ArrayList originalShapes = new ArrayList();
|
||||||
@ -852,7 +852,7 @@ public class Diagram {
|
|||||||
shapes.clear();
|
shapes.clear();
|
||||||
shapes.addAll(originalShapes);
|
shapes.addAll(originalShapes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToTextObjects(DiagramText shape){
|
private void addToTextObjects(DiagramText shape){
|
||||||
textObjects.add(shape);
|
textObjects.add(shape);
|
||||||
}
|
}
|
||||||
@ -861,14 +861,14 @@ public class Diagram {
|
|||||||
compositeShapes.add(shape);
|
compositeShapes.add(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addToShapes(DiagramShape shape){
|
private void addToShapes(DiagramShape shape){
|
||||||
shapes.add(shape);
|
shapes.add(shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator getShapesIterator(){
|
public Iterator getShapesIterator(){
|
||||||
return shapes.iterator();
|
return shapes.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
@ -911,7 +911,7 @@ public class Diagram {
|
|||||||
public ArrayList getShapes() {
|
public ArrayList getShapes() {
|
||||||
return shapes;
|
return shapes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCellMinX(TextGrid.Cell cell){
|
public int getCellMinX(TextGrid.Cell cell){
|
||||||
return getCellMinX(cell, cellWidth);
|
return getCellMinX(cell, cellWidth);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* DiTAA - Diagrams Through Ascii Art
|
* DiTAA - Diagrams Through Ascii Art
|
||||||
*
|
*
|
||||||
* Copyright (C) 2004 Efstathios Sideris
|
* Copyright (C) 2004 Efstathios Sideris
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
@ -16,7 +16,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.stathissideris.ascii2image.text;
|
package org.stathissideris.ascii2image.text;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ import org.stathissideris.ascii2image.core.ProcessingOptions;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Efstathios Sideris
|
* @author Efstathios Sideris
|
||||||
*/
|
*/
|
||||||
public class TextGrid {
|
public class TextGrid {
|
||||||
@ -52,7 +52,7 @@ public class TextGrid {
|
|||||||
private static char[] cornerChars = {'\\', '/', '+'};
|
private static char[] cornerChars = {'\\', '/', '+'};
|
||||||
private static char[] pointMarkers = {'*'};
|
private static char[] pointMarkers = {'*'};
|
||||||
private static char[] dashedLines = {':', '~', '='};
|
private static char[] dashedLines = {':', '~', '='};
|
||||||
|
|
||||||
private static char[] entryPoints1 = {'\\'};
|
private static char[] entryPoints1 = {'\\'};
|
||||||
private static char[] entryPoints2 = {'|', ':', '+', '\\', '/'};
|
private static char[] entryPoints2 = {'|', ':', '+', '\\', '/'};
|
||||||
private static char[] entryPoints3 = {'/'};
|
private static char[] entryPoints3 = {'/'};
|
||||||
@ -72,7 +72,7 @@ public class TextGrid {
|
|||||||
humanColorCodes.put("RED", "E32");
|
humanColorCodes.put("RED", "E32");
|
||||||
humanColorCodes.put("YEL", "FF3");
|
humanColorCodes.put("YEL", "FF3");
|
||||||
humanColorCodes.put("BLK", "000");
|
humanColorCodes.put("BLK", "000");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HashSet<String> markupTags =
|
private static HashSet<String> markupTags =
|
||||||
@ -91,13 +91,13 @@ public class TextGrid {
|
|||||||
public void addToMarkupTags(Collection<String> tags){
|
public void addToMarkupTags(Collection<String> tags){
|
||||||
markupTags.addAll(tags);
|
markupTags.addAll(tags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public TextGrid(){
|
public TextGrid(){
|
||||||
rows = new ArrayList<StringBuffer>();
|
rows = new ArrayList<StringBuffer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextGrid(int width, int height){
|
public TextGrid(int width, int height){
|
||||||
String space = StringUtils.repeatString(" ", width);
|
String space = StringUtils.repeatString(" ", width);
|
||||||
rows = new ArrayList<StringBuffer>();
|
rows = new ArrayList<StringBuffer>();
|
||||||
@ -114,7 +114,7 @@ public class TextGrid {
|
|||||||
rows = new ArrayList<StringBuffer>();
|
rows = new ArrayList<StringBuffer>();
|
||||||
for(StringBuffer row : otherGrid.getRows()) {
|
for(StringBuffer row : otherGrid.getRows()) {
|
||||||
rows.add(new StringBuffer(row));
|
rows.add(new StringBuffer(row));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear(){
|
public void clear(){
|
||||||
@ -122,7 +122,7 @@ public class TextGrid {
|
|||||||
int height = getHeight();
|
int height = getHeight();
|
||||||
rows.clear();
|
rows.clear();
|
||||||
for(int i = 0; i < height; i++)
|
for(int i = 0; i < height; i++)
|
||||||
rows.add(new StringBuffer(blank));
|
rows.add(new StringBuffer(blank));
|
||||||
}
|
}
|
||||||
|
|
||||||
// duplicated code due to lots of hits to this function
|
// duplicated code due to lots of hits to this function
|
||||||
@ -142,7 +142,7 @@ public class TextGrid {
|
|||||||
|| cell.y < 0) return 0;
|
|| cell.y < 0) return 0;
|
||||||
return rows.get(cell.y).charAt(cell.x);
|
return rows.get(cell.y).charAt(cell.x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringBuffer getRow(int y){
|
public StringBuffer getRow(int y){
|
||||||
return rows.get(y);
|
return rows.get(y);
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ public class TextGrid {
|
|||||||
|| y > getHeight() - 1
|
|| y > getHeight() - 1
|
||||||
|| x < 0
|
|| x < 0
|
||||||
|| y < 0) return null;
|
|| y < 0) return null;
|
||||||
return rows.get(y).substring(x, x + length);
|
return rows.get(y).substring(x, x + length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public char getNorthOf(int x, int y){ return get(x, y - 1); }
|
public char getNorthOf(int x, int y){ return get(x, y - 1); }
|
||||||
@ -202,7 +202,7 @@ public class TextGrid {
|
|||||||
StringBuffer row = rows.get(y);
|
StringBuffer row = rows.get(y);
|
||||||
row.setCharAt(x, c);
|
row.setCharAt(x, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRow(int y, String row){
|
public void setRow(int y, String row){
|
||||||
if(y > getHeight() || row.length() != getWidth())
|
if(y > getHeight() || row.length() != getWidth())
|
||||||
throw new IllegalArgumentException("setRow out of bounds or string wrong size");
|
throw new IllegalArgumentException("setRow out of bounds or string wrong size");
|
||||||
@ -214,7 +214,7 @@ public class TextGrid {
|
|||||||
throw new IllegalArgumentException("setRow out of bounds or string wrong size");
|
throw new IllegalArgumentException("setRow out of bounds or string wrong size");
|
||||||
rows.set(y, row);
|
rows.set(y, row);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth(){
|
public int getWidth(){
|
||||||
if(rows.size() == 0) return 0; //empty buffer
|
if(rows.size() == 0) return 0; //empty buffer
|
||||||
return rows.get(0).length();
|
return rows.get(0).length();
|
||||||
@ -232,10 +232,10 @@ public class TextGrid {
|
|||||||
+StringUtils.repeatString("0123456789", (int) Math.floor(getWidth()/10)+1));
|
+StringUtils.repeatString("0123456789", (int) Math.floor(getWidth()/10)+1));
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
String row = it.next().toString();
|
String row = it.next().toString();
|
||||||
String index = new Integer(i).toString();
|
String index = Integer.valueOf(i).toString();
|
||||||
if(i < 10) index = " "+index;
|
if(i < 10) index = " "+index;
|
||||||
System.out.println(index+" ("+row+")");
|
System.out.println(index+" ("+row+")");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,12 +248,12 @@ public class TextGrid {
|
|||||||
+StringUtils.repeatString("0123456789", (int) Math.floor(getWidth()/10)+1)+"\n");
|
+StringUtils.repeatString("0123456789", (int) Math.floor(getWidth()/10)+1)+"\n");
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
String row = it.next().toString();
|
String row = it.next().toString();
|
||||||
String index = new Integer(i).toString();
|
String index = Integer.valueOf(i).toString();
|
||||||
if(i < 10) index = " "+index;
|
if(i < 10) index = " "+index;
|
||||||
row = row.replaceAll("\n", "\\\\n");
|
row = row.replaceAll("\n", "\\\\n");
|
||||||
row = row.replaceAll("\r", "\\\\r");
|
row = row.replaceAll("\r", "\\\\r");
|
||||||
buffer.append(index+" ("+row+")\n");
|
buffer.append(index+" ("+row+")\n");
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
@ -264,9 +264,9 @@ public class TextGrid {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds grid to this. Space characters in this grid
|
* Adds grid to this. Space characters in this grid
|
||||||
* are replaced with the corresponding contents of
|
* are replaced with the corresponding contents of
|
||||||
* grid, otherwise the contents are unchanged.
|
* grid, otherwise the contents are unchanged.
|
||||||
*
|
*
|
||||||
* @param grid
|
* @param grid
|
||||||
* @return false if the grids are of different size
|
* @return false if the grids are of different size
|
||||||
*/
|
*/
|
||||||
@ -297,7 +297,7 @@ public class TextGrid {
|
|||||||
char c = get(xi, yi);
|
char c = get(xi, yi);
|
||||||
if(Character.isLetterOrDigit(c)) {
|
if(Character.isLetterOrDigit(c)) {
|
||||||
boolean isOnHorizontalLine = isOnHorizontalLine(xi, yi);
|
boolean isOnHorizontalLine = isOnHorizontalLine(xi, yi);
|
||||||
boolean isOnVerticalLine = isOnVerticalLine(xi, yi);
|
boolean isOnVerticalLine = isOnVerticalLine(xi, yi);
|
||||||
if(isOnHorizontalLine && isOnVerticalLine){
|
if(isOnHorizontalLine && isOnVerticalLine){
|
||||||
set(xi, yi, '+');
|
set(xi, yi, '+');
|
||||||
if(DEBUG) System.out.println("replaced type on line '"+c+"' with +");
|
if(DEBUG) System.out.println("replaced type on line '"+c+"' with +");
|
||||||
@ -310,7 +310,7 @@ public class TextGrid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replacePointMarkersOnLine(){
|
public void replacePointMarkersOnLine(){
|
||||||
@ -322,7 +322,7 @@ public class TextGrid {
|
|||||||
Cell cell = new Cell(xi, yi);
|
Cell cell = new Cell(xi, yi);
|
||||||
if(StringUtils.isOneOf(c, pointMarkers)
|
if(StringUtils.isOneOf(c, pointMarkers)
|
||||||
&& isStarOnLine(cell)){
|
&& isStarOnLine(cell)){
|
||||||
|
|
||||||
boolean isOnHorizontalLine = false;
|
boolean isOnHorizontalLine = false;
|
||||||
if(StringUtils.isOneOf(get(cell.getEast()), horizontalLines))
|
if(StringUtils.isOneOf(get(cell.getEast()), horizontalLines))
|
||||||
isOnHorizontalLine = true;
|
isOnHorizontalLine = true;
|
||||||
@ -334,7 +334,7 @@ public class TextGrid {
|
|||||||
isOnVerticalLine = true;
|
isOnVerticalLine = true;
|
||||||
if(StringUtils.isOneOf(get(cell.getSouth()), verticalLines))
|
if(StringUtils.isOneOf(get(cell.getSouth()), verticalLines))
|
||||||
isOnVerticalLine = true;
|
isOnVerticalLine = true;
|
||||||
|
|
||||||
if(isOnHorizontalLine && isOnVerticalLine){
|
if(isOnHorizontalLine && isOnVerticalLine){
|
||||||
set(xi, yi, '+');
|
set(xi, yi, '+');
|
||||||
if(DEBUG) System.out.println("replaced marker on line '"+c+"' with +");
|
if(DEBUG) System.out.println("replaced marker on line '"+c+"' with +");
|
||||||
@ -347,7 +347,7 @@ public class TextGrid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CellSet getPointMarkersOnLine(){
|
public CellSet getPointMarkersOnLine(){
|
||||||
@ -383,13 +383,13 @@ public class TextGrid {
|
|||||||
row = rows.get(y).toString();
|
row = rows.get(y).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace all occurences of c1 with c2
|
* Replace all occurences of c1 with c2
|
||||||
*
|
*
|
||||||
* @param c1
|
* @param c1
|
||||||
* @param c2
|
* @param c2
|
||||||
*/
|
*/
|
||||||
@ -401,7 +401,7 @@ public class TextGrid {
|
|||||||
char c = get(xi, yi);
|
char c = get(xi, yi);
|
||||||
if(c == c1) set(xi, yi, c2);
|
if(c == c1) set(xi, yi, c2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBlankCells(){
|
public boolean hasBlankCells(){
|
||||||
@ -465,7 +465,7 @@ public class TextGrid {
|
|||||||
* in the grid. Used on buffers that contain only
|
* in the grid. Used on buffers that contain only
|
||||||
* type, in order to find the positions and the
|
* type, in order to find the positions and the
|
||||||
* contents of the strings.
|
* contents of the strings.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public ArrayList<CellStringPair> findStrings(){
|
public ArrayList<CellStringPair> findStrings(){
|
||||||
@ -497,7 +497,7 @@ public class TextGrid {
|
|||||||
/**
|
/**
|
||||||
* This is done in a bit of a messy way, should be impossible
|
* This is done in a bit of a messy way, should be impossible
|
||||||
* to go out of sync with corresponding GridPatternGroup.
|
* to go out of sync with corresponding GridPatternGroup.
|
||||||
*
|
*
|
||||||
* @param cell
|
* @param cell
|
||||||
* @param entryPointId
|
* @param entryPointId
|
||||||
* @return
|
* @return
|
||||||
@ -507,7 +507,7 @@ public class TextGrid {
|
|||||||
char c = get(cell);
|
char c = get(cell);
|
||||||
if(entryPointId == 1) {
|
if(entryPointId == 1) {
|
||||||
return StringUtils.isOneOf(c, entryPoints1);
|
return StringUtils.isOneOf(c, entryPoints1);
|
||||||
|
|
||||||
} else if(entryPointId == 2) {
|
} else if(entryPointId == 2) {
|
||||||
return StringUtils.isOneOf(c, entryPoints2);
|
return StringUtils.isOneOf(c, entryPoints2);
|
||||||
|
|
||||||
@ -535,7 +535,7 @@ public class TextGrid {
|
|||||||
/**
|
/**
|
||||||
* true if cell is blank and the east and west cells are not
|
* true if cell is blank and the east and west cells are not
|
||||||
* (used to find gaps between words)
|
* (used to find gaps between words)
|
||||||
*
|
*
|
||||||
* @param cell
|
* @param cell
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -567,7 +567,7 @@ public class TextGrid {
|
|||||||
Cell cell = new Cell(xi, yi);
|
Cell cell = new Cell(xi, yi);
|
||||||
if(isArrowhead(cell)) set(cell, ' ');
|
if(isArrowhead(cell)) set(cell, ' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeColorCodes(){
|
public void removeColorCodes(){
|
||||||
@ -592,10 +592,10 @@ public class TextGrid {
|
|||||||
if(isBoundary(cell)) toBeRemoved.add(cell);
|
if(isBoundary(cell)) toBeRemoved.add(cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove in two stages, because decision of
|
//remove in two stages, because decision of
|
||||||
//isBoundary depends on contants of surrounding
|
//isBoundary depends on contants of surrounding
|
||||||
//cells
|
//cells
|
||||||
Iterator it = toBeRemoved.iterator();
|
Iterator it = toBeRemoved.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
Cell cell = (Cell) it.next();
|
Cell cell = (Cell) it.next();
|
||||||
@ -632,9 +632,9 @@ public class TextGrid {
|
|||||||
char cR = s.charAt(1);
|
char cR = s.charAt(1);
|
||||||
char cG = s.charAt(2);
|
char cG = s.charAt(2);
|
||||||
char cB = s.charAt(3);
|
char cB = s.charAt(3);
|
||||||
int r = Integer.valueOf(String.valueOf(cR), 16).intValue() * 17;
|
int r = Integer.valueOf(String.valueOf(cR), 16) * 17;
|
||||||
int g = Integer.valueOf(String.valueOf(cG), 16).intValue() * 17;
|
int g = Integer.valueOf(String.valueOf(cG), 16) * 17;
|
||||||
int b = Integer.valueOf(String.valueOf(cB), 16).intValue() * 17;
|
int b = Integer.valueOf(String.valueOf(cB), 16) * 17;
|
||||||
result.add(new CellColorPair(cell, new Color(r, g, b)));
|
result.add(new CellColorPair(cell, new Color(r, g, b)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -668,7 +668,7 @@ public class TextGrid {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMarkupTags(){
|
public void removeMarkupTags(){
|
||||||
Iterator it = findMarkupTags().iterator();
|
Iterator it = findMarkupTags().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@ -679,7 +679,7 @@ public class TextGrid {
|
|||||||
writeStringTo(pair.cell, StringUtils.repeatString(" ", length));
|
writeStringTo(pair.cell, StringUtils.repeatString(" ", length));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean matchesAny(GridPatternGroup criteria){
|
public boolean matchesAny(GridPatternGroup criteria){
|
||||||
@ -722,9 +722,9 @@ public class TextGrid {
|
|||||||
if('+' == c || '\\' == c || '/' == c){
|
if('+' == c || '\\' == c || '/' == c){
|
||||||
// System.out.print("");
|
// System.out.print("");
|
||||||
if(
|
if(
|
||||||
isIntersection(cell)
|
isIntersection(cell)
|
||||||
|| isCorner(cell)
|
|| isCorner(cell)
|
||||||
|| isStub(cell)
|
|| isStub(cell)
|
||||||
|| isCrossOnLine(cell)){
|
|| isCrossOnLine(cell)){
|
||||||
return true;
|
return true;
|
||||||
} else return false;
|
} else return false;
|
||||||
@ -763,10 +763,10 @@ public class TextGrid {
|
|||||||
public boolean isLinesEnd(int x, int y){
|
public boolean isLinesEnd(int x, int y){
|
||||||
return isLinesEnd(new Cell(x, y));
|
return isLinesEnd(new Cell(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stubs are also considered end of lines
|
* Stubs are also considered end of lines
|
||||||
*
|
*
|
||||||
* @param cell
|
* @param cell
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -811,16 +811,16 @@ public class TextGrid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* A stub looks like that:
|
* A stub looks like that:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
*
|
*
|
||||||
* +- or -+ or + or + or /- or -/ or / (you get the point)
|
* +- or -+ or + or + or /- or -/ or / (you get the point)
|
||||||
* | | |
|
* | | |
|
||||||
*
|
*
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param cell
|
* @param cell
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -864,7 +864,7 @@ public class TextGrid {
|
|||||||
|| isWestArrowhead(cell)
|
|| isWestArrowhead(cell)
|
||||||
|| isEastArrowhead(cell));
|
|| isEastArrowhead(cell));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNorthArrowhead(Cell cell){
|
public boolean isNorthArrowhead(Cell cell){
|
||||||
return get(cell) == '^';
|
return get(cell) == '^';
|
||||||
}
|
}
|
||||||
@ -881,8 +881,8 @@ public class TextGrid {
|
|||||||
return (get(cell) == 'v' || get(cell) == 'V')
|
return (get(cell) == 'v' || get(cell) == 'V')
|
||||||
&& isVerticalLine(cell.getNorth());
|
&& isVerticalLine(cell.getNorth());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// unicode for bullets
|
// unicode for bullets
|
||||||
//
|
//
|
||||||
// 2022 bullet
|
// 2022 bullet
|
||||||
@ -897,7 +897,7 @@ public class TextGrid {
|
|||||||
public boolean isBullet(int x, int y){
|
public boolean isBullet(int x, int y){
|
||||||
return isBullet(new Cell(x, y));
|
return isBullet(new Cell(x, y));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBullet(Cell cell){
|
public boolean isBullet(Cell cell){
|
||||||
char c = get(cell);
|
char c = get(cell);
|
||||||
if((c == 'o' || c == '*')
|
if((c == 'o' || c == '*')
|
||||||
@ -907,7 +907,7 @@ public class TextGrid {
|
|||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void replaceBullets(){
|
public void replaceBullets(){
|
||||||
int width = getWidth();
|
int width = getWidth();
|
||||||
int height = getHeight();
|
int height = getHeight();
|
||||||
@ -921,11 +921,11 @@ public class TextGrid {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* true if the cell is not blank
|
* true if the cell is not blank
|
||||||
* but the previous (west) is
|
* but the previous (west) is
|
||||||
*
|
*
|
||||||
* @param cell
|
* @param cell
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -936,7 +936,7 @@ public class TextGrid {
|
|||||||
/**
|
/**
|
||||||
* true if the cell is not blank
|
* true if the cell is not blank
|
||||||
* but the next (east) is
|
* but the next (east) is
|
||||||
*
|
*
|
||||||
* @param cell
|
* @param cell
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -1007,7 +1007,7 @@ public class TextGrid {
|
|||||||
/**
|
/**
|
||||||
* Returns the neighbours of a line-cell that are boundaries
|
* Returns the neighbours of a line-cell that are boundaries
|
||||||
* (0 to 2 cells are returned)
|
* (0 to 2 cells are returned)
|
||||||
*
|
*
|
||||||
* @param cell
|
* @param cell
|
||||||
* @return null if the cell is not a line
|
* @return null if the cell is not a line
|
||||||
*/
|
*/
|
||||||
@ -1021,7 +1021,7 @@ public class TextGrid {
|
|||||||
CellSet result = new CellSet();
|
CellSet result = new CellSet();
|
||||||
if(isBoundary(cell.getNorth())) result.add(cell.getNorth());
|
if(isBoundary(cell.getNorth())) result.add(cell.getNorth());
|
||||||
if(isBoundary(cell.getSouth())) result.add(cell.getSouth());
|
if(isBoundary(cell.getSouth())) result.add(cell.getSouth());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -1103,11 +1103,11 @@ public class TextGrid {
|
|||||||
if(result.contains(blocked)) result.remove(blocked);
|
if(result.contains(blocked)) result.remove(blocked);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CellSet followCell(Cell cell){
|
public CellSet followCell(Cell cell){
|
||||||
return followCell(cell, null);
|
return followCell(cell, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CellSet followCell(Cell cell, Cell blocked){
|
public CellSet followCell(Cell cell, Cell blocked){
|
||||||
if(isIntersection(cell)) return followIntersection(cell, blocked);
|
if(isIntersection(cell)) return followIntersection(cell, blocked);
|
||||||
if(isCorner(cell)) return followCorner(cell, blocked);
|
if(isCorner(cell)) return followCorner(cell, blocked);
|
||||||
@ -1135,7 +1135,7 @@ public class TextGrid {
|
|||||||
return "unrecognisable type";
|
return "unrecognisable type";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CellSet followCrossOnLine(Cell cell, Cell blocked){
|
public CellSet followCrossOnLine(Cell cell, Cell blocked){
|
||||||
CellSet result = new CellSet();
|
CellSet result = new CellSet();
|
||||||
if(isHorizontalCrossOnLine(cell)){
|
if(isHorizontalCrossOnLine(cell)){
|
||||||
@ -1187,7 +1187,7 @@ public class TextGrid {
|
|||||||
TextGrid subGrid = getTestingSubGrid(cell);
|
TextGrid subGrid = getTestingSubGrid(cell);
|
||||||
return subGrid.matchesAny(criteria);
|
return subGrid.matchesAny(criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCorner1(Cell cell){
|
public boolean isCorner1(Cell cell){
|
||||||
return matchesAny(cell, GridPatternGroup.corner1Criteria);
|
return matchesAny(cell, GridPatternGroup.corner1Criteria);
|
||||||
}
|
}
|
||||||
@ -1253,7 +1253,7 @@ public class TextGrid {
|
|||||||
grid.set(cell, this.get(cell));
|
grid.set(cell, this.get(cell));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(TextGrid grid){
|
public boolean equals(TextGrid grid){
|
||||||
if(grid.getHeight() != this.getHeight()
|
if(grid.getHeight() != this.getHeight()
|
||||||
|| grid.getWidth() != this.getWidth()
|
|| grid.getWidth() != this.getWidth()
|
||||||
@ -1268,7 +1268,7 @@ public class TextGrid {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public int hashCode() {
|
// public int hashCode() {
|
||||||
// int h = 0;
|
// int h = 0;
|
||||||
@ -1277,10 +1277,10 @@ public class TextGrid {
|
|||||||
// }
|
// }
|
||||||
// return h;
|
// return h;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills all the cells in <code>cells</code> with <code>c</code>
|
* Fills all the cells in <code>cells</code> with <code>c</code>
|
||||||
*
|
*
|
||||||
* @param cells
|
* @param cells
|
||||||
* @param c
|
* @param c
|
||||||
*/
|
*/
|
||||||
@ -1293,10 +1293,10 @@ public class TextGrid {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
* Fills the continuous area with if c1 characters with c2,
|
* Fills the continuous area with if c1 characters with c2,
|
||||||
* flooding from cell x, y
|
* flooding from cell x, y
|
||||||
*
|
*
|
||||||
* @param x
|
* @param x
|
||||||
* @param y
|
* @param y
|
||||||
* @param c1 the character to replace
|
* @param c1 the character to replace
|
||||||
@ -1322,17 +1322,17 @@ public class TextGrid {
|
|||||||
private CellSet seedFill(Cell seed, char newChar){
|
private CellSet seedFill(Cell seed, char newChar){
|
||||||
CellSet cellsFilled = new CellSet();
|
CellSet cellsFilled = new CellSet();
|
||||||
char oldChar = get(seed);
|
char oldChar = get(seed);
|
||||||
|
|
||||||
if(oldChar == newChar) return cellsFilled;
|
if(oldChar == newChar) return cellsFilled;
|
||||||
if(isOutOfBounds(seed)) return cellsFilled;
|
if(isOutOfBounds(seed)) return cellsFilled;
|
||||||
|
|
||||||
Stack<Cell> stack = new Stack<Cell>();
|
Stack<Cell> stack = new Stack<Cell>();
|
||||||
|
|
||||||
stack.push(seed);
|
stack.push(seed);
|
||||||
|
|
||||||
while(!stack.isEmpty()){
|
while(!stack.isEmpty()){
|
||||||
Cell cell = (Cell) stack.pop();
|
Cell cell = (Cell) stack.pop();
|
||||||
|
|
||||||
//set(cell, newChar);
|
//set(cell, newChar);
|
||||||
cellsFilled.add(cell);
|
cellsFilled.add(cell);
|
||||||
|
|
||||||
@ -1340,30 +1340,30 @@ public class TextGrid {
|
|||||||
Cell sCell = cell.getSouth();
|
Cell sCell = cell.getSouth();
|
||||||
Cell eCell = cell.getEast();
|
Cell eCell = cell.getEast();
|
||||||
Cell wCell = cell.getWest();
|
Cell wCell = cell.getWest();
|
||||||
|
|
||||||
if(get(nCell) == oldChar && !cellsFilled.contains(nCell)) stack.push(nCell);
|
if(get(nCell) == oldChar && !cellsFilled.contains(nCell)) stack.push(nCell);
|
||||||
if(get(sCell) == oldChar && !cellsFilled.contains(sCell)) stack.push(sCell);
|
if(get(sCell) == oldChar && !cellsFilled.contains(sCell)) stack.push(sCell);
|
||||||
if(get(eCell) == oldChar && !cellsFilled.contains(eCell)) stack.push(eCell);
|
if(get(eCell) == oldChar && !cellsFilled.contains(eCell)) stack.push(eCell);
|
||||||
if(get(wCell) == oldChar && !cellsFilled.contains(wCell)) stack.push(wCell);
|
if(get(wCell) == oldChar && !cellsFilled.contains(wCell)) stack.push(wCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cellsFilled;
|
return cellsFilled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CellSet seedFillOld(Cell seed, char newChar){
|
private CellSet seedFillOld(Cell seed, char newChar){
|
||||||
CellSet cellsFilled = new CellSet();
|
CellSet cellsFilled = new CellSet();
|
||||||
char oldChar = get(seed);
|
char oldChar = get(seed);
|
||||||
|
|
||||||
if(oldChar == newChar) return cellsFilled;
|
if(oldChar == newChar) return cellsFilled;
|
||||||
if(isOutOfBounds(seed)) return cellsFilled;
|
if(isOutOfBounds(seed)) return cellsFilled;
|
||||||
|
|
||||||
Stack<Cell> stack = new Stack<Cell>();
|
Stack<Cell> stack = new Stack<Cell>();
|
||||||
|
|
||||||
stack.push(seed);
|
stack.push(seed);
|
||||||
|
|
||||||
while(!stack.isEmpty()){
|
while(!stack.isEmpty()){
|
||||||
Cell cell = (Cell) stack.pop();
|
Cell cell = (Cell) stack.pop();
|
||||||
|
|
||||||
set(cell, newChar);
|
set(cell, newChar);
|
||||||
cellsFilled.add(cell);
|
cellsFilled.add(cell);
|
||||||
|
|
||||||
@ -1371,22 +1371,22 @@ public class TextGrid {
|
|||||||
Cell sCell = cell.getSouth();
|
Cell sCell = cell.getSouth();
|
||||||
Cell eCell = cell.getEast();
|
Cell eCell = cell.getEast();
|
||||||
Cell wCell = cell.getWest();
|
Cell wCell = cell.getWest();
|
||||||
|
|
||||||
if(get(nCell) == oldChar) stack.push(nCell);
|
if(get(nCell) == oldChar) stack.push(nCell);
|
||||||
if(get(sCell) == oldChar) stack.push(sCell);
|
if(get(sCell) == oldChar) stack.push(sCell);
|
||||||
if(get(eCell) == oldChar) stack.push(eCell);
|
if(get(eCell) == oldChar) stack.push(eCell);
|
||||||
if(get(wCell) == oldChar) stack.push(wCell);
|
if(get(wCell) == oldChar) stack.push(wCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cellsFilled;
|
return cellsFilled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Locates and returns the '*' boundaries that we would
|
* Locates and returns the '*' boundaries that we would
|
||||||
* encounter if we did a flood-fill at <code>seed</code>.
|
* encounter if we did a flood-fill at <code>seed</code>.
|
||||||
*
|
*
|
||||||
* @param seed
|
* @param seed
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -1401,48 +1401,48 @@ public class TextGrid {
|
|||||||
Stack<Cell> stack = new Stack<Cell>();
|
Stack<Cell> stack = new Stack<Cell>();
|
||||||
|
|
||||||
stack.push(seed);
|
stack.push(seed);
|
||||||
|
|
||||||
while(!stack.isEmpty()){
|
while(!stack.isEmpty()){
|
||||||
Cell cell = (Cell) stack.pop();
|
Cell cell = (Cell) stack.pop();
|
||||||
|
|
||||||
set(cell, newChar);
|
set(cell, newChar);
|
||||||
|
|
||||||
Cell nCell = cell.getNorth();
|
Cell nCell = cell.getNorth();
|
||||||
Cell sCell = cell.getSouth();
|
Cell sCell = cell.getSouth();
|
||||||
Cell eCell = cell.getEast();
|
Cell eCell = cell.getEast();
|
||||||
Cell wCell = cell.getWest();
|
Cell wCell = cell.getWest();
|
||||||
|
|
||||||
if(get(nCell) == oldChar) stack.push(nCell);
|
if(get(nCell) == oldChar) stack.push(nCell);
|
||||||
else if(get(nCell) == '*') boundaries.add(nCell);
|
else if(get(nCell) == '*') boundaries.add(nCell);
|
||||||
|
|
||||||
if(get(sCell) == oldChar) stack.push(sCell);
|
if(get(sCell) == oldChar) stack.push(sCell);
|
||||||
else if(get(sCell) == '*') boundaries.add(sCell);
|
else if(get(sCell) == '*') boundaries.add(sCell);
|
||||||
|
|
||||||
if(get(eCell) == oldChar) stack.push(eCell);
|
if(get(eCell) == oldChar) stack.push(eCell);
|
||||||
else if(get(eCell) == '*') boundaries.add(eCell);
|
else if(get(eCell) == '*') boundaries.add(eCell);
|
||||||
|
|
||||||
if(get(wCell) == oldChar) stack.push(wCell);
|
if(get(wCell) == oldChar) stack.push(wCell);
|
||||||
else if(get(wCell) == '*') boundaries.add(wCell);
|
else if(get(wCell) == '*') boundaries.add(wCell);
|
||||||
}
|
}
|
||||||
|
|
||||||
return boundaries;
|
return boundaries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//TODO: incomplete method seedFillLine()
|
//TODO: incomplete method seedFillLine()
|
||||||
private CellSet seedFillLine(Cell cell, char newChar){
|
private CellSet seedFillLine(Cell cell, char newChar){
|
||||||
CellSet cellsFilled = new CellSet();
|
CellSet cellsFilled = new CellSet();
|
||||||
|
|
||||||
Stack stack = new Stack();
|
Stack stack = new Stack();
|
||||||
|
|
||||||
char oldChar = get(cell);
|
char oldChar = get(cell);
|
||||||
|
|
||||||
if(oldChar == newChar) return cellsFilled;
|
if(oldChar == newChar) return cellsFilled;
|
||||||
if(isOutOfBounds(cell)) return cellsFilled;
|
if(isOutOfBounds(cell)) return cellsFilled;
|
||||||
|
|
||||||
stack.push(new LineSegment(cell.x, cell.x, cell.y, 1));
|
stack.push(new LineSegment(cell.x, cell.x, cell.y, 1));
|
||||||
stack.push(new LineSegment(cell.x, cell.x, cell.y + 1, -1));
|
stack.push(new LineSegment(cell.x, cell.x, cell.y + 1, -1));
|
||||||
|
|
||||||
int left;
|
int left;
|
||||||
while(!stack.isEmpty()){
|
while(!stack.isEmpty()){
|
||||||
LineSegment segment = (LineSegment) stack.pop();
|
LineSegment segment = (LineSegment) stack.pop();
|
||||||
@ -1455,9 +1455,9 @@ public class TextGrid {
|
|||||||
set(x, segment.y, newChar);
|
set(x, segment.y, newChar);
|
||||||
cellsFilled.add(new Cell(x, segment.y));
|
cellsFilled.add(new Cell(x, segment.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
left = cell.getEast().x;
|
left = cell.getEast().x;
|
||||||
boolean skip = (x > segment.x1)? true : false;
|
boolean skip = (x > segment.x1)? true : false;
|
||||||
|
|
||||||
if(left < segment.x1){ //leak on left?
|
if(left < segment.x1){ //leak on left?
|
||||||
//TODO: i think the first param should be x
|
//TODO: i think the first param should be x
|
||||||
@ -1473,13 +1473,13 @@ public class TextGrid {
|
|||||||
set(x, segment.y, newChar);
|
set(x, segment.y, newChar);
|
||||||
cellsFilled.add(new Cell(x, segment.y));
|
cellsFilled.add(new Cell(x, segment.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.push(new LineSegment(left, x - 1, segment.y, segment.dy));
|
stack.push(new LineSegment(left, x - 1, segment.y, segment.dy));
|
||||||
if(x > segment.x2 + 1) //leak on right?
|
if(x > segment.x2 + 1) //leak on right?
|
||||||
stack.push(new LineSegment(segment.x2 + 1, x - 1, segment.y, -segment.dy));
|
stack.push(new LineSegment(segment.x2 + 1, x - 1, segment.y, -segment.dy));
|
||||||
}
|
}
|
||||||
skip = false; //skip only once
|
skip = false; //skip only once
|
||||||
|
|
||||||
for(++x; x <= segment.x2 && get(x, segment.y) != oldChar; ++x){;}
|
for(++x; x <= segment.x2 && get(x, segment.y) != oldChar; ++x){;}
|
||||||
left = x;
|
left = x;
|
||||||
} while( x < segment.x2);
|
} while( x < segment.x2);
|
||||||
@ -1487,7 +1487,7 @@ public class TextGrid {
|
|||||||
|
|
||||||
return cellsFilled;
|
return cellsFilled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cellContainsDashedLineChar(Cell cell){
|
public boolean cellContainsDashedLineChar(Cell cell){
|
||||||
char c = get(cell);
|
char c = get(cell);
|
||||||
return StringUtils.isOneOf(c, dashedLines);
|
return StringUtils.isOneOf(c, dashedLines);
|
||||||
@ -1522,15 +1522,15 @@ public class TextGrid {
|
|||||||
// make all lines of equal length
|
// make all lines of equal length
|
||||||
// add blank outline around the buffer to prevent fill glitch
|
// add blank outline around the buffer to prevent fill glitch
|
||||||
// convert tabs to spaces (or remove them if setting is 0)
|
// convert tabs to spaces (or remove them if setting is 0)
|
||||||
|
|
||||||
int blankBorderSize = 2;
|
int blankBorderSize = 2;
|
||||||
|
|
||||||
int maxLength = 0;
|
int maxLength = 0;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
String encoding = null;
|
String encoding = null;
|
||||||
//if(options != null) encoding = options.getCharacterEncoding();
|
//if(options != null) encoding = options.getCharacterEncoding();
|
||||||
|
|
||||||
Iterator<StringBuffer> it = rows.iterator();
|
Iterator<StringBuffer> it = rows.iterator();
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
String row = it.next().toString();
|
String row = it.next().toString();
|
||||||
@ -1546,24 +1546,24 @@ public class TextGrid {
|
|||||||
it = rows.iterator();
|
it = rows.iterator();
|
||||||
ArrayList<StringBuffer> newRows = new ArrayList<StringBuffer>();
|
ArrayList<StringBuffer> newRows = new ArrayList<StringBuffer>();
|
||||||
//TODO: make the following depend on blankBorderSize
|
//TODO: make the following depend on blankBorderSize
|
||||||
|
|
||||||
StringBuffer topBottomRow =
|
StringBuffer topBottomRow =
|
||||||
new StringBuffer(StringUtils.repeatString(" ", maxLength + blankBorderSize * 2));
|
new StringBuffer(StringUtils.repeatString(" ", maxLength + blankBorderSize * 2));
|
||||||
|
|
||||||
newRows.add(topBottomRow);
|
newRows.add(topBottomRow);
|
||||||
newRows.add(topBottomRow);
|
newRows.add(topBottomRow);
|
||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
StringBuffer row = it.next();
|
StringBuffer row = it.next();
|
||||||
|
|
||||||
if(row.length() < maxLength) {
|
if(row.length() < maxLength) {
|
||||||
String borderString = StringUtils.repeatString(" ", blankBorderSize);
|
String borderString = StringUtils.repeatString(" ", blankBorderSize);
|
||||||
StringBuffer newRow = new StringBuffer();
|
StringBuffer newRow = new StringBuffer();
|
||||||
|
|
||||||
newRow.append(borderString);
|
newRow.append(borderString);
|
||||||
newRow.append(row);
|
newRow.append(row);
|
||||||
newRow.append(StringUtils.repeatString(" ", maxLength - row.length()));
|
newRow.append(StringUtils.repeatString(" ", maxLength - row.length()));
|
||||||
newRow.append(borderString);
|
newRow.append(borderString);
|
||||||
|
|
||||||
newRows.add(newRow);
|
newRows.add(newRow);
|
||||||
} else { //TODO: why is the following line like that?
|
} else { //TODO: why is the following line like that?
|
||||||
newRows.add(new StringBuffer(" ").append(row).append(" "));
|
newRows.add(new StringBuffer(" ").append(row).append(" "));
|
||||||
@ -1573,13 +1573,13 @@ public class TextGrid {
|
|||||||
newRows.add(topBottomRow);
|
newRows.add(topBottomRow);
|
||||||
newRows.add(topBottomRow);
|
newRows.add(topBottomRow);
|
||||||
rows = newRows;
|
rows = newRows;
|
||||||
|
|
||||||
replaceBullets();
|
replaceBullets();
|
||||||
replaceHumanColorCodes();
|
replaceHumanColorCodes();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fixTabs(int tabSize){
|
private void fixTabs(int tabSize){
|
||||||
|
|
||||||
int rowIndex = 0;
|
int rowIndex = 0;
|
||||||
@ -1588,7 +1588,7 @@ public class TextGrid {
|
|||||||
while(it.hasNext()){
|
while(it.hasNext()){
|
||||||
String row = it.next().toString();
|
String row = it.next().toString();
|
||||||
StringBuffer newRow = new StringBuffer();
|
StringBuffer newRow = new StringBuffer();
|
||||||
|
|
||||||
char[] chars = row.toCharArray();
|
char[] chars = row.toCharArray();
|
||||||
for(int i = 0; i < chars.length; i++){
|
for(int i = 0; i < chars.length; i++){
|
||||||
if(chars[i] == '\t'){
|
if(chars[i] == '\t'){
|
||||||
@ -1607,14 +1607,14 @@ public class TextGrid {
|
|||||||
rowIndex++;
|
rowIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected ArrayList<StringBuffer> getRows() {
|
protected ArrayList<StringBuffer> getRows() {
|
||||||
return rows;
|
return rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CellColorPair{
|
public class CellColorPair{
|
||||||
public CellColorPair(Cell cell, Color color){
|
public CellColorPair(Cell cell, Color color){
|
||||||
this.cell = cell;
|
this.cell = cell;
|
||||||
@ -1642,20 +1642,20 @@ public class TextGrid {
|
|||||||
public String tag;
|
public String tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class Cell{
|
public class Cell{
|
||||||
|
|
||||||
public int x, y;
|
public int x, y;
|
||||||
|
|
||||||
public Cell(Cell cell){
|
public Cell(Cell cell){
|
||||||
this(cell.x, cell.y);
|
this(cell.x, cell.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cell(int x, int y){
|
public Cell(int x, int y){
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cell getNorth(){ return new Cell(x, y - 1); }
|
public Cell getNorth(){ return new Cell(x, y - 1); }
|
||||||
public Cell getSouth(){ return new Cell(x, y + 1); }
|
public Cell getSouth(){ return new Cell(x, y + 1); }
|
||||||
public Cell getEast(){ return new Cell(x + 1, y); }
|
public Cell getEast(){ return new Cell(x + 1, y); }
|
||||||
@ -1721,32 +1721,32 @@ public class TextGrid {
|
|||||||
if(x == cell.x && y == cell.y) return true;
|
if(x == cell.x && y == cell.y) return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (x << 16) | y;
|
return (x << 16) | y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNextTo(int x2, int y2){
|
public boolean isNextTo(int x2, int y2){
|
||||||
if(Math.abs(x2 - x) == 1 && Math.abs(y2 - y) == 1) return false;
|
if(Math.abs(x2 - x) == 1 && Math.abs(y2 - y) == 1) return false;
|
||||||
if(Math.abs(x2 - x) == 1 && y2 == y) return true;
|
if(Math.abs(x2 - x) == 1 && y2 == y) return true;
|
||||||
if(Math.abs(y2 - y) == 1 && x2 == x) return true;
|
if(Math.abs(y2 - y) == 1 && x2 == x) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNextTo(Cell cell){
|
public boolean isNextTo(Cell cell){
|
||||||
if(cell == null) throw new IllegalArgumentException("cell cannot be null");
|
if(cell == null) throw new IllegalArgumentException("cell cannot be null");
|
||||||
return this.isNextTo(cell.x, cell.y);
|
return this.isNextTo(cell.x, cell.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return "("+x+", "+y+")";
|
return "("+x+", "+y+")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void scale(int s){
|
public void scale(int s){
|
||||||
x = x * s;
|
x = x * s;
|
||||||
y = y * s;
|
y = y * s;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class LineSegment{
|
private class LineSegment{
|
||||||
|
Loading…
Reference in New Issue
Block a user