import java.awt.*; import java.applet.*; import java.awt.event.*; import OVGraph; import Permutation; import C_component; public class AnalysisFrame extends Frame implements MouseListener { // Controll components GR_applet m_caller; DrawingPanel drawPnl = new DrawingPanel(); Button closeBtn = new Button("Close"); Button nextBtn = new Button("Next"); public AnalysisFrame(String title, GR gr, GR_applet caller) throws Exception { super(title); m_caller = caller; initForm(); showAnalysis(gr); setVisible(true); show(); this.pack(); this.setSize(500, 500); } private void initForm() { add(drawPnl); closeBtn.addMouseListener(this); nextBtn.addMouseListener(this); } public void showAnalysis(GR gr) throws Exception { drawPnl.setGR(gr); drawPnl.add(closeBtn); drawPnl.add(nextBtn); drawPnl.repaint(); } public void paint(Graphics g) { drawPnl.repaint(); } public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseClicked(MouseEvent e) { try { Component comp = e.getComponent(); if(comp.equals(closeBtn)) { dispose(); m_caller.analysisFrameClosed(); } if(comp.equals(nextBtn)) m_caller.runNextStage(); } catch(Exception e1) { System.out.println(e1.getMessage());} } class DrawingPanel extends Panel { GR m_gr; Report m_report; int m_report_min_x = 10; int m_report_min_y = 300; int m_report_space = 15; double m_alfa = 3 * java.lang.Math.PI / 4; // The angle of the arc int m_distance; int m_radius; Font m_font; int m_left_border = 40; int m_low_border = 70; int m_mikra_x = 600; int m_mikra_y = 420; public DrawingPanel() { super(); } public void setGR(GR gr) throws Exception { m_gr = gr; m_report = new Report(m_gr.getGraph()); int size = gr.getPermutation().getSize(); m_distance = 900 / size; m_radius = m_distance/3; } public void paint(Graphics graphics) { // Double buffering variables Image offscreenImage = createImage(getSize().width, getSize().height); Graphics offscreenGraphics = offscreenImage.getGraphics(); // Draw the background offscreenGraphics.setColor(Color.white); offscreenGraphics.fillRect(0, 0, getSize().width, getSize().height ); Font font = offscreenGraphics.getFont(); Font draw_font = new Font(font.getName(), font.getStyle(), 5 * m_radius / 2); try { m_report = new Report(m_gr.getGraph()); showReport(m_report.getReport(), offscreenGraphics); } catch(Exception e) { System.out.println(e.getMessage()); } if(m_gr.getPermutation().getSize() > 82) { offscreenGraphics.drawString("Can't show graph because it is too big", 10, 100); graphics.drawImage(offscreenImage, 0, 0, this); return; } OVGraph graph = m_gr.getGraph(); Permutation permutation = graph.getPermutation(); // The number of vertices in the overlap graph (include the oriented components) int vertices_number = graph.getNumOfVertices(); try { for(int i=0; i 9) g.drawString(""+index, x-(m_radius/2), y - m_radius); else g.drawString(""+index, x+(m_radius/2), y - m_radius); g.setColor(color); g.fillOval(x+1, y+1, 2*m_radius-1, 2*m_radius-1); } private void drawGrayEdge(Graphics g, int position1, int position2, boolean oriented) { int x1 = x_location(position1); int x2 = x_location(position2); int y12 = y_location(position1); int distance = x2 - x1; double radius = distance / (2 * Math.sin(m_alfa/2)); int int_radius =(int)radius; int x = ((x1 + x2) / 2); // The coordinates of the circle center int y = (int)(y12 - (radius * Math.cos(m_alfa/2))); int start_angle = (int)(270 - (180/Math.PI * (m_alfa/2))); int angle = (int)(m_alfa * (180/Math.PI)); if(oriented) g.setColor(Color.black); else g.setColor(Color.blue); g.drawArc(x - int_radius, y - int_radius, 2 * int_radius, 2 * int_radius, start_angle, angle); } private void drawBlackEdge(Graphics g, int start_position) { g.setColor(Color.black); int end_position = start_position + 1; g.drawLine(x_location(start_position) + m_radius, y_location(start_position), x_location(end_position) - m_radius, y_location(end_position)); } // Specify the center of the vertex circle private int x_location(int vertex_position) { return (this.m_left_border + m_radius + ((vertex_position-1) * m_distance)); } private int y_location(int vertex_position) { return(this.m_low_border + m_radius); } public void showReport(String[] lines, Graphics g) { g.setColor(Color.black); for(int i=0; i 0) result[next_line] = result[next_line] + ", "; result[next_line] = result[next_line] + "(" + 2*vertices_indexes[j] + "," + (2*vertices_indexes[j]+1) + ")"; } next_line++; } result[next_line++] = new String("The overlap graph has " + comps_index + " connected components:"); next_line++; if(hurdles_indexes.length == 0) result[next_line++] = "There are no hurdles. Next reversal will be according to a happy clique"; else result[next_line++] = "Next reversal will be merging of two reversals (non conscutive if possible)"; return result; } } }