package graphStructure;
import java.util.*;
import java.awt.*;
import java.io.*;
import java.awt.geom.*;
import dataStructure.DoublyLinkedList;
import graphStructure.mementos.*;
/**
* This class represents the model of the graph object, that stores all the data
* that makes up the structure of the graph, and methods to perform operations
* on this data such as saving to and loading from a file, adding nodes or edges
* etc...
*
* @author Jon Harris
*/
public class Graph
{
private String label;
private Vector nodes;
private boolean drawSelected;
private Color drawColor;
private String filePath;
private DoublyLinkedList mementos;
private MementoGrouper currentMemento;
private boolean showCoords;
private boolean showLabels;
private boolean trackUndos;
private boolean hasChangedSinceLastSave;
private boolean hasChangedSinceLastDraw;
private boolean logChangedSinceLastDraw;
private Vector logEntries;
private LogEntry currentLogEntry;
private Graph parent;
private boolean drawGrid;
private int gridRows;
private int gridCols;
private int gridColWidth;
private int gridRowHeight;
/**
* Constructor for class Graph.
*/
public Graph()
{
label = "";
nodes = new Vector();
drawColor = null;
drawSelected = true;
filePath = "";
mementos = new DoublyLinkedList();
currentMemento = null;
trackUndos = true;
hasChangedSinceLastSave = false;
hasChangedSinceLastDraw = true;
showCoords = false;
showLabels = true;
logEntries = new Vector();
currentLogEntry = null;
parent = null;
drawGrid = false;
gridRows = -1;
gridCols = -1;
}
/**
* Constructor for class Graph that assigns a label to the Graph.
*
* @param String aLabel: The label to assign to the Graph.
*/
public Graph(String aLabel)
{
this();
label = aLabel;
}
/**
* Constructor for class Graph that assigns a label to the Graph and
* provides the initial node set for the Graph.
*
* @param String aLabel: The label to assign to the Graph.
* @param Vector initialNodes: A Vector containing the initial Nodes for the Graph.
*/
public Graph(String aLabel, Vector initialNodes)
{
this();
label = aLabel;
nodes = initialNodes;
}
public Graph(Graph aGraph)
{
parent = aGraph;
label = new String(aGraph.label);
drawSelected = aGraph.drawSelected;
trackUndos = aGraph.trackUndos;
hasChangedSinceLastSave = aGraph.hasChangedSinceLastSave;
hasChangedSinceLastDraw = true;
if ( aGraph.drawColor == null )
{
drawColor = null;
}
else
{
drawColor = new Color(aGraph.drawColor.getRGB());
}
filePath = new String(aGraph.filePath);
nodes = new Vector();
mementos = new DoublyLinkedList();
currentMemento = null;
showCoords = aGraph.showCoords;
showLabels = aGraph.showLabels;
logEntries = new Vector();
currentLogEntry = null;
}
public String getShowString()
{
if ( showCoords )
{
return "Show Coordinates";
}
else
{
if ( showLabels )
{
return "Show Labels";
}
else
{
return "Show Nothing";
}
}
}
public void shareMementos(Graph aGraph) { mementos = aGraph.mementos; }
public void setTrackUndos(boolean tu) { trackUndos = tu; initUndo(); }
private void initUndo()
{
mementos = new DoublyLinkedList();
currentMemento = null;
}
public boolean getTrackUndos() { return trackUndos; }
public void setDrawSelected(boolean draw) { drawSelected = draw; }
public boolean getDrawSelected() { return drawSelected; }
public void setDrawColor(Color aColor) { drawColor = aColor; }
public Color getDrawColor() { return drawColor; }
public void setShowCoords(boolean c)
{
showCoords = c;
hasChangedSinceLastDraw = true;
}
public boolean getShowCoords() { return showCoords; }
public void setShowLabels(boolean l)
{
showLabels = l;
hasChangedSinceLastDraw = true;
}
public boolean getShowLabels() { return showLabels; }
public String getFilePath() { return filePath; }
public String getFileName()
{
if ( filePath.indexOf('\\') == -1 )
{
return filePath.substring( 0, filePath.lastIndexOf('.') );
}
else
{
return filePath.substring( filePath.lastIndexOf('\\')+1, filePath.lastIndexOf('.') );
}
}
public void setFilePath(String fp) { filePath = fp; }
public boolean hasChangedSinceLastSave() { return hasChangedSinceLastSave; }
public boolean hasChangedSinceLastDraw() { return hasChangedSinceLastDraw; }
public boolean logChangedSinceLastDraw() { return logChangedSinceLastDraw; }
public void markForRepaint() { hasChangedSinceLastDraw = true; }
private int getRowHeight(int numRows, int height)
{
return height / (numRows-1);
}
private int getColWidth(int numCols, int width)
{
return width / (numCols-1);
}
public void setGrid(int numRows, int rowHeight, int numCols, int colWidth,
boolean addMemento)
{
if ( addMemento && currentMemento != null && trackUndos )
{
currentMemento.addMemento(GridSizeMemento.createGridSizeMemento(this));
}
gridRows = numRows;
gridRowHeight = rowHeight;
gridCols = numCols;
gridColWidth = colWidth;
}
public void setGridArea(int numRows, int height, int numCols, int width,
boolean addMemento)
{
if ( addMemento && currentMemento != null && trackUndos )
{
currentMemento.addMemento(GridSizeMemento.createGridSizeMemento(this));
}
if ( numRows <= 1 )
{
numRows = 2;
}
gridRows = numRows;
gridRowHeight = getRowHeight(numRows, height);
if ( numCols <= 1 )
{
numCols = 2;
}
gridCols = numCols;
gridColWidth = getColWidth(numCols, width);
}
public int getGridRows() { return gridRows; }
public int getGridCols() { return gridCols; }
public int getGridColWidth() { return gridColWidth; }
public int getGridRowHeight() { return gridRowHeight; }
public void setDrawGrid(boolean draw) { drawGrid = draw; }
public boolean getDrawGrid() { return drawGrid && gridRows >= 2 && gridCols >= 2; }
public int getGridHeight() { return (gridRows-1)*gridRowHeight; }
public int getGridWidth() { return (gridCols-1)*gridColWidth; }
public void drawGrid(Graphics2D g2, int xOffset, int yOffset)
{
int x = 0 + xOffset;
int y = 0 + yOffset;
g2.setColor(Color.gray);
for ( int i=0; i<gridRows; i++ )
{
y = i*gridRowHeight + yOffset;
g2.drawLine(xOffset, y, gridColWidth*(gridCols-1) + xOffset, y);
}
for ( int i=0; i<gridCols; i++ )
{
x = i*gridColWidth + xOffset;
g2.drawLine(x, yOffset, x, gridRowHeight*(gridRows-1) + yOffset);
}
}
public Location getClosestGridLocation(Location location)
{
int row = (int)Math.round(location.doubleY() / gridRowHeight);
int col = (int)Math.round(location.doubleX() / gridColWidth);
if ( row > gridRows-1 )
{
row = gridRows-1;
}
if ( col > gridCols-1 )
{
col = gridCols-1;
}
return new Location( col*gridColWidth, row*gridRowHeight);
}
public boolean isOnGrid(Location location)
{
return location.intX() % gridColWidth == 0 &&
location.intY() % gridRowHeight == 0;
}
public void newMemento(String title)
{
hasChangedSinceLastSave = true;
hasChangedSinceLastDraw = true;
if ( trackUndos )
{
if ( currentMemento != null )
{
mementos.enqueueAfterCurrent(currentMemento)
没有合适的资源?快使用搜索试试~ 我知道了~
Java 绘图框架 JGraphEd.7z
共169个文件
java:109个
gif:50个
htm:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 14 浏览量
2022-07-06
10:24:28
上传
评论
收藏 181KB 7Z 举报
温馨提示
Java 绘图框架 JGraphEd.7z
资源推荐
资源详情
资源评论
收起资源包目录
Java 绘图框架 JGraphEd.7z (169个子文件)
Help.gif 1KB
Info.gif 1KB
New.gif 778B
Open.gif 462B
Forward.gif 434B
Up.gif 429B
Back.gif 422B
Save.gif 266B
Delete.gif 249B
Redo.gif 243B
Preferences.gif 240B
Undo.gif 239B
Log.gif 199B
RotateCursor.gif 188B
Grid.gif 175B
NormalDisplay.gif 168B
CanonicalDisplay.gif 162B
STDisplay.gif 159B
MakeBiconnected.gif 156B
Resize.gif 153B
DisableUndos.gif 153B
MakeConnected.gif 152B
Embed.gif 150B
MSTDisplay.gif 146B
DFSDisplay.gif 146B
SPDisplay.gif 146B
BiconnectedDisplay.gif 145B
TestBiconnectivity.gif 144B
TestConnectivity.gif 139B
Edit.gif 137B
EnableUndos.gif 137B
RemoveSelected.gif 132B
Rotate.gif 132B
MakeMaximal.gif 131B
UnselectAll.gif 129B
StraightLineEmbed.gif 125B
ShowLabels.gif 122B
TestPlanarity.gif 121B
ShowCoords.gif 121B
RemoveAll.gif 120B
Move.gif 120B
DefaultDisplay.gif 114B
ChanTreeDisplay.gif 111B
ShowNothing.gif 111B
RemoveGenerated.gif 107B
ToggleUndos.gif 107B
PreserveGenerated.gif 104B
CreateRandom.gif 98B
BidirectionalArrow.gif 94B
Blank.gif 49B
commands.htm 12KB
edit.htm 6KB
preferences.htm 2KB
modes.htm 1KB
resize.htm 883B
rotate.htm 667B
move.htm 560B
index.htm 449B
using.htm 400B
about.htm 358B
Graph.java 72KB
PQNode.java 65KB
EditListener.java 53KB
GraphController.java 44KB
PQTree.java 36KB
Edge.java 35KB
Node.java 25KB
GraphEditor.java 24KB
GIFOutputStream.java 23KB
MenuAndToolBar.java 21KB
BiconnectivityOperation.java 18KB
GridListener.java 16KB
ChanTreeDrawOperation.java 14KB
SchnyderEmbeddingOperation.java 13KB
EmbedOperation.java 12KB
CanonicalOrderOperation.java 11KB
GraphEditorHelpWindow.java 11KB
STNumberOperation.java 8KB
GraphEditorListener.java 8KB
NormalLabelOperation.java 7KB
BinaryHeap.java 7KB
ButtonChooser.java 6KB
GraphEditorInfoWindow.java 6KB
DepthFirstSearchOperation.java 6KB
GraphWindow.java 5KB
GraphEditorPreferencesWindow.java 5KB
PlanarityOperation.java 5KB
NodeExtender.java 5KB
DijkstraShortestPathOperation.java 5KB
ChanDialog.java 5KB
RotateListener.java 5KB
ConnectivityOperation.java 5KB
EdgeExtender.java 4KB
ResizeListener.java 4KB
SchnyderDialog.java 4KB
MakeMaximalOperation.java 4KB
MoveListener.java 4KB
DoublyLinkedList.java 4KB
InternalSplitNode.java 4KB
LogEntry.java 4KB
共 169 条
- 1
- 2
资源评论
BryanDing
- 粉丝: 299
- 资源: 5582
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Multisim14.0多谐振荡器预置数仿真
- Gmail API如何实现OAuth授权
- 基于STM32的通用Fitolamp控制器
- 超级玛丽小游戏的源码(仅作为参考)
- 小程序版基于图像分类算法对大白菜是否腐烂识别-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版python语言pytorch框架的图像分类AI生成的斑马和真实斑马识别-不含数据集图片-含逐行注释和说明文档.zip
- 科来网络分析系统 11 技术交流版
- 小程序版python语言pytorch框架的图像分类汉字写的是否工整识别-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版python训练识别鸡蛋是否完好-不含数据集图片-含逐行注释和说明文档.zip
- 小程序版基于深度学习AI算法对毛毛虫类别识别-不含数据集图片-含逐行注释和说明文档.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功