Code formatting

This commit is contained in:
Jindra Petk
2012-12-25 11:33:41 +01:00
parent 24a6b82a94
commit 14ae8e435c
643 changed files with 26017 additions and 27040 deletions

View File

@@ -14,7 +14,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.jpexs.asdec.abc.gui;
import com.jpexs.asdec.abc.avm2.flowgraph.Graph;
@@ -33,89 +32,92 @@ import javax.swing.JScrollPane;
*/
public class GraphFrame extends JFrame {
private class GraphPanel extends JPanel {
private class GraphPanel extends JPanel {
private static final int SPACE_VERTICAL=10;
private static final int SPACE_HORIZONTAL=10;
private static final int BLOCK_WIDTH=100;
private static final int BLOCK_HEIGHT=20;
private static final int SPACE_VERTICAL = 10;
private static final int SPACE_HORIZONTAL = 10;
private static final int BLOCK_WIDTH = 100;
private static final int BLOCK_HEIGHT = 20;
private Graph graph;
private Graph graph;
public GraphPanel(Graph graph) {
this.graph = graph;
setPreferredSize(new Dimension((BLOCK_WIDTH + SPACE_HORIZONTAL) * getPartWidth(graph.head, new ArrayList<GraphPart>()), (BLOCK_HEIGHT + SPACE_VERTICAL) * getPartHeight(graph.head, new ArrayList<GraphPart>())));
}
public GraphPanel(Graph graph) {
this.graph = graph;
setPreferredSize(new Dimension((BLOCK_WIDTH+SPACE_HORIZONTAL)*getPartWidth(graph.head, new ArrayList<GraphPart>()), (BLOCK_HEIGHT+SPACE_VERTICAL)*getPartHeight(graph.head, new ArrayList<GraphPart>())));
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.black);
paintPart(g, graph.head, 0, getPartWidth(graph.head, new ArrayList<GraphPart>()) * (BLOCK_WIDTH + SPACE_HORIZONTAL) / 2, new ArrayList<GraphPart>());
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.black);
paintPart(g,graph.head,0,getPartWidth(graph.head,new ArrayList<GraphPart>())*(BLOCK_WIDTH+SPACE_HORIZONTAL)/2,new ArrayList<GraphPart>());
}
private void paintPart(Graphics g, GraphPart part, int y, int x, List<GraphPart> used) {
List<GraphPart> l = new ArrayList<GraphPart>();
l.addAll(used);
int totalWidthParts = getPartWidth(part, l);
int totalWidth = totalWidthParts * (BLOCK_WIDTH + SPACE_HORIZONTAL);
g.drawRect(x - BLOCK_WIDTH / 2 - SPACE_HORIZONTAL / 2, y, BLOCK_WIDTH, BLOCK_HEIGHT);
g.drawString(part.toString(), x - BLOCK_WIDTH / 2, y + BLOCK_HEIGHT);
if (used.contains(part)) {
return;
}
used.add(part);
if (part.nextParts.size() > 0) {
int cx = x - totalWidth / 2;
for (int p = 0; p < part.nextParts.size(); p++) {
l = new ArrayList<GraphPart>();
l.addAll(used);
int cellWidth = getPartWidth(part.nextParts.get(p), l) * (BLOCK_WIDTH + SPACE_HORIZONTAL);
g.setColor(Color.black);
g.drawLine(x, y + BLOCK_HEIGHT, cx + cellWidth / 2, y + BLOCK_HEIGHT + SPACE_VERTICAL);
paintPart(g, part.nextParts.get(p), y + BLOCK_HEIGHT + SPACE_VERTICAL, cx + cellWidth / 2, used);
cx += cellWidth;
private void paintPart(Graphics g,GraphPart part,int y,int x,List<GraphPart> used){
List<GraphPart> l=new ArrayList<GraphPart>();
l.addAll(used);
int totalWidthParts=getPartWidth(part,l);
int totalWidth=totalWidthParts*(BLOCK_WIDTH+SPACE_HORIZONTAL);
g.drawRect(x-BLOCK_WIDTH/2-SPACE_HORIZONTAL/2, y, BLOCK_WIDTH, BLOCK_HEIGHT);
g.drawString(part.toString(), x-BLOCK_WIDTH/2, y+BLOCK_HEIGHT);
if(used.contains(part)) return;
used.add(part);
if(part.nextParts.size()>0){
int cx=x-totalWidth/2;
for(int p=0;p<part.nextParts.size();p++){
l=new ArrayList<GraphPart>();
l.addAll(used);
int cellWidth=getPartWidth(part.nextParts.get(p),l)*(BLOCK_WIDTH+SPACE_HORIZONTAL);
g.setColor(Color.black);
g.drawLine(x, y+BLOCK_HEIGHT, cx+cellWidth/2, y+BLOCK_HEIGHT+SPACE_VERTICAL);
paintPart(g,part.nextParts.get(p),y+BLOCK_HEIGHT+SPACE_VERTICAL,cx+cellWidth/2,used);
cx+=cellWidth;
}
}
}
}
}
private int getPartHeight(GraphPart part,List<GraphPart> used){
if (used.contains(part)) {
return 1;
}
used.add(part);
int maxH=0;
for(int p=0;p<part.nextParts.size();p++){
int h=getPartHeight(part.nextParts.get(p),used);
if(h>maxH) maxH=h;
}
return 1+maxH;
}
private int getPartWidth(GraphPart part, List<GraphPart> used) {
if (used.contains(part)) {
return 1;
private int getPartHeight(GraphPart part, List<GraphPart> used) {
if (used.contains(part)) {
return 1;
}
used.add(part);
int maxH = 0;
for (int p = 0; p < part.nextParts.size(); p++) {
int h = getPartHeight(part.nextParts.get(p), used);
if (h > maxH) {
maxH = h;
}
used.add(part);
if (part.nextParts.size() == 0) {
return 1;
}
int w = 0;
for (GraphPart subpart : part.nextParts) {
w += getPartWidth(subpart, used);
}
return w;
}
}
}
return 1 + maxH;
}
public GraphFrame(Graph graph,String name) {
setSize(500, 500);
Container cnt = getContentPane();
cnt.setLayout(new BorderLayout());
cnt.add(new JScrollPane(new GraphPanel(graph)));
setTitle("Graph "+name);
View.setWindowIcon(this);
View.centerScreen(this);
}
private int getPartWidth(GraphPart part, List<GraphPart> used) {
if (used.contains(part)) {
return 1;
}
used.add(part);
if (part.nextParts.size() == 0) {
return 1;
}
int w = 0;
for (GraphPart subpart : part.nextParts) {
w += getPartWidth(subpart, used);
}
return w;
}
}
public GraphFrame(Graph graph, String name) {
setSize(500, 500);
Container cnt = getContentPane();
cnt.setLayout(new BorderLayout());
cnt.add(new JScrollPane(new GraphPanel(graph)));
setTitle("Graph " + name);
View.setWindowIcon(this);
View.centerScreen(this);
}
}