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