diff --git a/Makefile b/Makefile index 2555f86499229f70f501a734fbfe1b0f7ad4504b..bc985981ab1e65d7be4362008051c09a3456bbc3 100755 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ TTOOL_PATH := $(shell /bin/pwd) TTOOL_SRC = $(TTOOL_PATH)/src TTOOL_WEBCRAWLER_SRC = $(TTOOL_PATH)/src/web/crawler TTOOL_BIN = $(TTOOL_PATH)/bin -TTOOL_CLASSPATH_BINARY = $(TTOOL_BIN)/JavaPlot.jar:$(TTOOL_BIN)/commons-codec-1.10.jar:$(TTOOL_BIN)/commons-io-2.4-javadoc.jar:$(TTOOL_BIN)/commons-io-2.4.jar:$(TTOOL_BIN)/derby.jar:$(TTOOL_BIN)/derbyclient-10.9.1.0.jar:$(TTOOL_BIN)/derbynet.jar:$(TTOOL_BIN)/dom4j-1.6.1.jar:$(TTOOL_BIN)/jaxen-1.1.6.jar:$(TTOOL_BIN)/jsoup-1.8.1.jar:$(TTOOL_BIN)/opencloud.jar:$(TTOOL_BIN)/gs-core-1.3.jar:. +TTOOL_CLASSPATH_BINARY = $(TTOOL_BIN)/JavaPlot.jar:$(TTOOL_BIN)/commons-codec-1.10.jar:$(TTOOL_BIN)/commons-io-2.5-javadoc.jar:$(TTOOL_BIN)/commons-io-2.5.jar:$(TTOOL_BIN)/derby.jar:$(TTOOL_BIN)/derbyclient-10.9.1.0.jar:$(TTOOL_BIN)/derbynet.jar:$(TTOOL_BIN)/dom4j-1.6.1.jar:$(TTOOL_BIN)/jaxen-1.1.6.jar:$(TTOOL_BIN)/jsoup-1.8.1.jar:$(TTOOL_BIN)/opencloud.jar:$(TTOOL_BIN)/gs-core-1.3.jar:. TTOOL_MODELING = $(TTOOL_PATH)/modeling #TTOOL_MODELING = $(TTOOL_PATH)/figures TTOOL_EXECUTABLECODE = $(TTOOL_PATH)/executablecode diff --git a/bin/commons-io-2.5-javadoc.jar b/bin/commons-io-2.5-javadoc.jar new file mode 100644 index 0000000000000000000000000000000000000000..b9575294aea25ddb56d521a106419af723a64545 Binary files /dev/null and b/bin/commons-io-2.5-javadoc.jar differ diff --git a/bin/commons-io-2.5.jar b/bin/commons-io-2.5.jar new file mode 100644 index 0000000000000000000000000000000000000000..12349182711347e3d0b66ecfa35ec7b69a023b7e Binary files /dev/null and b/bin/commons-io-2.5.jar differ diff --git a/src/myutil/CallbackLoaderInterface.java b/src/myutil/CallbackLoaderInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..344c3c05e096f073f07c363c4be959a738eed1cc --- /dev/null +++ b/src/myutil/CallbackLoaderInterface.java @@ -0,0 +1,59 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class CallbackLoaderInterface + * Creation: 31/05/2017 + * @version 1.1 31/05/2017 + * @author Ludovic APVRILLE + * @see + */ + +package myutil; + +import java.net.*; +import java.io.*; +import java.awt.image.*; +import javax.imageio.*; + + +public interface CallbackLoaderInterface { + + public void loadDone(); + public void loadFailed(); + +} diff --git a/src/myutil/GraphicLib.java b/src/myutil/GraphicLib.java index ba28f66fc95d30863d0e3523c29a3fab24734681..b4fe6c02dda8f317a3c4f7ceb6e207a095c5ec3f 100755 --- a/src/myutil/GraphicLib.java +++ b/src/myutil/GraphicLib.java @@ -1,47 +1,47 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - -/** - * Class GraphLib - * Creation: 01/12/2003 - * @version 1.1 01/12/2003 - * @author Ludovic APVRILLE - * @see - */ + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class GraphLib + * Creation: 01/12/2003 + * @version 1.1 01/12/2003 + * @author Ludovic APVRILLE + * @see + */ package myutil; @@ -52,62 +52,68 @@ import javax.swing.*; public final class GraphicLib { - + // EPSILON private static double EPSILON = 0.00001; - - public static final int NORTH = 0; - public static final int WEST = 1; - public static final int SOUTH = 2; - public static final int EAST = 3; - - + + public static final int NORTH = 0; + public static final int WEST = 1; + public static final int SOUTH = 2; + public static final int EAST = 3; + + // Arrow // Arrow type // 0 : <--> // 1 : --> // 2 : <-- // 3 : --- - + // Arrow Head // 0 : |> // 1 : > - + private static int xPoints[] = new int[3]; private static int yPoints[] = new int[3]; public static int longueur = 10; private static double angle = 0.523598775598; - + public final static BasicStroke normalStroke = new BasicStroke(1.0f); public final static BasicStroke stroke = new BasicStroke(2.0f); public final static BasicStroke doubleStroke = new BasicStroke(4.0f); public final static BasicStroke wideStroke = new BasicStroke(8.0f); - + public static float dash1[] = {5.0f}; public static BasicStroke dashed = new BasicStroke(1.0f, - BasicStroke.CAP_BUTT, - BasicStroke.JOIN_MITER, - 10.0f, dash1, 0.0f); - + BasicStroke.CAP_BUTT, + BasicStroke.JOIN_MITER, + 10.0f, dash1, 0.0f); + public static void setNormalStroke(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(GraphicLib.normalStroke); } - + public static void setMediumStroke(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(GraphicLib.stroke); } - + public static void setHighStroke(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(GraphicLib.doubleStroke); } - + + public static void centerString(Graphics g, String s, int x, int y, int width) { + int w = g.getFontMetrics().stringWidth(s); + int posX = x + (width-w)/2; + g.drawString(s, posX, y); + } + public static void setDashed() { - + } - + public static void doubleColorRect(Graphics g, int x, int y, int width, int height, Color color1, Color color2) { g.setColor(color1); g.drawLine(x, y, x +width, y); @@ -116,72 +122,72 @@ public final class GraphicLib { g.drawLine(x, y+height, x+width, y+height); g.drawLine(x+width, y, x+width, y+height); } - + public static void dashedLine(Graphics g, int x1, int y1, int x2, int y2) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(GraphicLib.dashed); g2.draw(new Line2D.Float(x1, y1, x2, y2)); g2.setStroke(normalStroke); } - + public static void dashedRect(Graphics g, int x1, int y1, int width, int height) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(GraphicLib.dashed); g2.drawRect(x1, y1, width, height); g2.setStroke(normalStroke); } - - - public static void dashedArrowWithLine(Graphics g, int type, int head, int length, int x1, int y1, int x2, int y2, boolean full) { + + + public static void dashedArrowWithLine(Graphics g, int type, int head, int length, int x1, int y1, int x2, int y2, boolean full) { Graphics2D g2 = (Graphics2D) g; g2.setStroke(GraphicLib.dashed); g2.drawLine(x1, y1, x2, y2); g2.setStroke(normalStroke); - + // extremite 1 if ((type == 0) || (type == 2)) { drawArrow(g, x1, y1, x2, y2, head, length, full); } - + // extremite 2 if ((type == 0) || (type == 1)) { drawArrow(g, x2, y2, x1, y1, head, length, full); } - + } - - + + public static void arrowWithLine(Graphics g, int type, int head, int length, int x1, int y1, int x2, int y2, boolean full) { - + g.drawLine(x1, y1, x2, y2); - + // extremite 1 if ((type == 0) || (type == 2)) { drawArrow(g, x1, y1, x2, y2, head, length, full); } - + // extremite 2 if ((type == 0) || (type == 1)) { drawArrow(g, x2, y2, x1, y1, head, length, full); } - + } - - + + private static void drawArrow(Graphics g, int x1, int y1, int x2, int y2, int head, int length, boolean full) { // changement de repere int x = x2 - x1; int y = y2 - y1; - - + + if (length == 0) { length = longueur; } - + // passage en cds polaires - // double ro = Conversion.ro(x, y); + // double ro = Conversion.ro(x, y); double alpha = Conversion.theta(x, y); - + // tete de la fleche xPoints[0] = x1; yPoints[0] = y1; @@ -189,10 +195,10 @@ public final class GraphicLib { yPoints[1] = (int)(length*Math.sin(alpha-angle) + y1); xPoints[2] = (int)(length*Math.cos(alpha+angle) + x1); yPoints[2] = (int)(length*Math.sin(alpha+angle) + y1); - - + + if (full) { - g.fillPolygon(xPoints, yPoints, 3); + g.fillPolygon(xPoints, yPoints, 3); } else if (head == 0) { // head must be filled in white Color c = g.getColor(); @@ -200,7 +206,7 @@ public final class GraphicLib { g.fillPolygon(xPoints, yPoints, 3); g.setColor(c); } - + if (head == 0) { g.drawPolygon(xPoints, yPoints, 3); } else { @@ -208,37 +214,37 @@ public final class GraphicLib { g.drawLine(x1, y1, xPoints[2], yPoints[2]); } } - + public static boolean isSegmentInRectangle(int x1, int y1, int x2, int y2, int x, int y, int width, int height) { int x11 = Math.min(x1, x2); int y11 = Math.min(y1, y2); - + int x22 = Math.max(x1, x2); int y22 = Math.max(y1, y2); - + if ((x11 < x) || (x22 > x+width)) { return false; } - + if ((y11 < y) || (y22 > y+height)) { return false; } - + return true; - + } - - + + // Says whether the point belongs to the segment // If no point can be found, return null // If lines are parallel, returns one of the point public static boolean pointBelongsToSegment(double x1, double y1, double x3, double y3, double x4, double y4) { - + //System.out.println("Point on segment : x1=" + x1 + " y1=" + y1); //System.out.println("x3=" + x3 + " y3=" + y3 +" x4=" + x4 + " y4=" + y4); double y33 = Math.min(y3, y4); double y44 = Math.max(y3, y4); - + if (x3 == x4) { // vertical line if (Math.abs(x1 - x3) < EPSILON) { @@ -248,9 +254,9 @@ public final class GraphicLib { } return false; } - + //System.out.println("Toto121"); - + double x33 = Math.min(x3, x4); double x44 = Math.max(x3, x4); if (((x1 >= x33) && (x44 >= x1)) || (Math.abs(x1-x44)<EPSILON) || (Math.abs(x1-y33)<EPSILON)) { @@ -266,8 +272,8 @@ public final class GraphicLib { } return false; } - - + + // returns the Point intersection between two segments // If no point can be found, return null // If segments are parallel, returns one of the point @@ -276,7 +282,7 @@ public final class GraphicLib { double x, y; //System.out.println("x1=" + x1 + " y1=" + y1 +" x2=" + x2 + " y2=" + y2); //System.out.println("x3=" + x3 + " y3=" + y3 +" x4=" + x4 + " y4=" + y4); - + if (x1 == x2) { if (y1 == y2) { // only one point is provided @@ -289,8 +295,8 @@ public final class GraphicLib { // first line is vertical type1 = 1; } - - + + if (x3 == x4) { if (y3 == y4) { // only one point is provided @@ -303,12 +309,12 @@ public final class GraphicLib { // line is vertical type2 = 1; } - + double y11 = Math.min(y1, y2); double y22 = Math.max(y1, y2); double y33 = Math.min(y3, y4); double y44 = Math.max(y3, y4); - + if ((type1 == 1) && (type2 == 1)) { // Both are vertical //System.out.println("Toto11"); @@ -332,7 +338,7 @@ public final class GraphicLib { return null; } } - + // at least one of them is not vertical if ((type1 == 1) || (type2 == 1)){ //System.out.println("Toto21"); @@ -343,13 +349,13 @@ public final class GraphicLib { x= x2; y = y2; x2 = x4; y2 = y4; x4 = x; y4 = y; } - + // we are now sure the second one is vertical and not the first one y33 = Math.min(y3, y4); y44 = Math.max(y3, y4); - + // we calculate the point (x3, y) on the first segment - + y = (((y1-y2)*(x3-x1))/(x1 - x2))+y1; if ((y >= y33) && (y44 >= y)) { // the point belongs to the vertical segment @@ -362,10 +368,10 @@ public final class GraphicLib { } else { return null; } - + } - - + + //System.out.println("Toto31"); double den = ((y1-y2)/(x1-x2)) - ((y3-y4)/(x3-x4)); if (Math.abs(den) < EPSILON) { @@ -384,10 +390,10 @@ public final class GraphicLib { if (pointBelongsToSegment(x4, y4, x1, y1, x2, y2)) { return new Point((int)x4, (int)y4); } - + } else { //System.out.println("Toto34"); - + double num = y3 - y1 + (x1*(y1-y2)/(x1-x2)) - (x3*(y3-y4)/(x3-x4)); x = num / den; double ya = ((y3-y4)*(x-x3))/(x3-x4) + y3; @@ -401,28 +407,28 @@ public final class GraphicLib { } return null; } - + public static Point intersectionRectangleSegment(int x1, int y1, int width, int height, int x3, int y3, int x4, int y4) { Point p; - + // lelft //System.out.println("Left"); p = intersectionTwoSegments(x1, y1, x1, y1 + height, x3, y3, x4, y4); if (p != null) return p; - + // upper //System.out.println("Upper"); p = intersectionTwoSegments(x1, y1, x1+width, y1, x3, y3, x4, y4); if (p != null) return p; - + // right //System.out.println("Right"); p = intersectionTwoSegments(x1+width, y1, x1+width, y1+height, x3, y3, x4, y4); if (p != null) return p; - + // lower //System.out.println("Lower"); p = intersectionTwoSegments(x1, y1+height, x1+width, y1+height, x3, y3, x4, y4); @@ -430,117 +436,117 @@ public final class GraphicLib { return p; return null; } - + public static boolean isInRectangle(int x1, int y1, int x, int y, int width, int height) { return x1 >= x && - x + width >= x1 && - y1 >= y && - y + height >= y1; + x + width >= x1 && + y1 >= y && + y + height >= y1; + } + + public static Point putPointOnRectangle(int x1, int y1, int x, int y, int width, int height) { + // Compute the four distances between the point and the four segments + // Find the closer segment + // Project the point on it + // First done on x, then on y + + int d1, d2, d3, d4; // distance, nonclockwise, starting on the top + int d; // minimal distance + Point p = new Point(); // returned point + + d1 = Math.abs(y-y1); + d2 = Math.abs(x-x1); + d3 = Math.abs(y+height-y1); + d4 = Math.abs(x+width-x1); + + d = Math.min(Math.min(Math.min(d1, d2), d3), d4); + + + if (d == d1) { + p.x = x1; + p.y = y; + } else if (d == d2) { + p.x = x; + p.y = y1; + } else if (d == d3) { + p.x = x1; + p.y = y + height; + } else { + p.x = x + width; + p.y = y1; + } + + return p; + + } + + // Returns the closer segment of the rectangle, from a given point (x1, y1) + public static int getCloserOrientation (int x1, int y1, int x, int y, int width, int height) { + // Compute the four distances between the point and the four segments + // Find the closer segment + // Project the point on it + // First done on x, then on y + + int d1, d2, d3, d4; // distance, nonclockwise, starting on the top + int d; // minimal distance + int ret; // returned orientation + + d1 = Math.abs(y-y1); + d2 = Math.abs(x-x1); + d3 = Math.abs(y+height-y1); + d4 = Math.abs(x+width-x1); + + d = Math.min(Math.min(Math.min(d1, d2), d3), d4); + + if (d == d1) { + ret = NORTH; + } else if (d == d2) { + ret = WEST; + } else if (d == d3) { + ret = SOUTH; + } else { + ret = EAST; + } + + return ret; } - - public static Point putPointOnRectangle(int x1, int y1, int x, int y, int width, int height) { - // Compute the four distances between the point and the four segments - // Find the closer segment - // Project the point on it - // First done on x, then on y - - int d1, d2, d3, d4; // distance, nonclockwise, starting on the top - int d; // minimal distance - Point p = new Point(); // returned point - - d1 = Math.abs(y-y1); - d2 = Math.abs(x-x1); - d3 = Math.abs(y+height-y1); - d4 = Math.abs(x+width-x1); - - d = Math.min(Math.min(Math.min(d1, d2), d3), d4); - - - if (d == d1) { - p.x = x1; - p.y = y; - } else if (d == d2) { - p.x = x; - p.y = y1; - } else if (d == d3) { - p.x = x1; - p.y = y + height; - } else { - p.x = x + width; - p.y = y1; - } - - return p; - - } - - // Returns the closer segment of the rectangle, from a given point (x1, y1) - public static int getCloserOrientation (int x1, int y1, int x, int y, int width, int height) { - // Compute the four distances between the point and the four segments - // Find the closer segment - // Project the point on it - // First done on x, then on y - - int d1, d2, d3, d4; // distance, nonclockwise, starting on the top - int d; // minimal distance - int ret; // returned orientation - - d1 = Math.abs(y-y1); - d2 = Math.abs(x-x1); - d3 = Math.abs(y+height-y1); - d4 = Math.abs(x+width-x1); - - d = Math.min(Math.min(Math.min(d1, d2), d3), d4); - - if (d == d1) { - ret = NORTH; - } else if (d == d2) { - ret = WEST; - } else if (d == d3) { - ret = SOUTH; - } else { - ret = EAST; - } - - return ret; - } - - + + public static void centerOnScreen(Window w) { Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); w.setLocation((screen.width - w.getSize().width)/2,(screen.height - w.getSize().height)/2); } - - public static void centerOnParent( final Window window ) { - centerOnParent( window, -1, -1 ); + + public static void centerOnParent( final Window window ) { + centerOnParent( window, -1, -1 ); } - - public static void centerOnParent( final Window w, - final int width, - final int heigth ) { - if ( width > 0 && heigth > 0 ) { - Dimension screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getSize(); - w.setSize( Math.min( width, screenSize.width ), Math.min( heigth, screenSize.height ) ); - } - + + public static void centerOnParent( final Window w, + final int width, + final int heigth ) { + if ( width > 0 && heigth > 0 ) { + Dimension screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().getSize(); + w.setSize( Math.min( width, screenSize.width ), Math.min( heigth, screenSize.height ) ); + } + Window parent = w.getOwner(); if (parent == null) { centerOnScreen(w); return; } Point p = parent.getLocation(); - w.setLocation(((parent.getSize().width - w.getSize().width)/2) + p.x, ((parent.getSize().height - w.getSize().height)/2) + p.y); + w.setLocation(((parent.getSize().width - w.getSize().width)/2) + p.x, ((parent.getSize().height - w.getSize().height)/2) + p.y); } - + // Trivial sorting algorithm as there are only a few tabs // maxIndex is a non valid index - // Vector v contains elements that should be sorted the same way + // Vector v contains elements that should be sorted the same way public static void sortJTabbedPane(JTabbedPane jtp, Vector<?> v, int beginIndex, int maxIndex) { //System.out.println("Sorting from " + beginIndex + " to " + maxIndex); if (beginIndex >= maxIndex) { return; } - + String s = jtp.getTitleAt(beginIndex); int index = beginIndex; // Search for the one to move @@ -550,17 +556,17 @@ public final class GraphicLib { s = jtp.getTitleAt(i); } } - + if (index != beginIndex) { moveTabFromTo(jtp, v, index, beginIndex); } - + beginIndex ++; sortJTabbedPane(jtp, v, beginIndex, maxIndex); } - + public static void moveTabFromTo(JTabbedPane jtp, Vector v, int src, int dst) { - + // Get all the properties Component comp = jtp.getComponentAt(src); String label = jtp.getTitleAt(src); @@ -572,13 +578,13 @@ public final class GraphicLib { int mnemonicLoc = jtp.getDisplayedMnemonicIndexAt(src); Color fg = jtp.getForegroundAt(src); Color bg = jtp.getBackgroundAt(src); - + // Remove the tab jtp.remove(src); - + // Add a new tab jtp.insertTab(label, icon, comp, tooltip, dst); - + // Restore all properties jtp.setDisabledIconAt(dst, iconDis); jtp.setEnabledAt(dst, enabled); @@ -586,38 +592,38 @@ public final class GraphicLib { jtp.setDisplayedMnemonicIndexAt(dst, mnemonicLoc); jtp.setForegroundAt(dst, fg); jtp.setBackgroundAt(dst, bg); - + Object o = v.elementAt(src); v.removeElementAt(src); v.insertElementAt(o, dst); } - - public static void draw3DRoundRectangle(Graphics g, int x, int y, int width, int height, int arc, Color fillColor, Color borderColor) { - Color c = g.getColor(); - - g.setColor(fillColor); - g.fillRoundRect(x, y, width, height, arc, arc); - g.setColor(fillColor.brighter()); - g.drawLine(x+1, y+(arc/2), x+1, y+height-(arc/2)); - g.drawLine(x+(arc/2), y+1, x+width-(arc/2), y+1); - g.drawArc(x+1, y+1, arc, arc, -180, -90); - g.drawArc(x+1, y+height-arc-1, arc, arc, 180, 45); - g.drawArc(x+width-1-arc, y+1, arc, arc, 90, -45); - g.setColor(fillColor.darker()); - g.drawLine(x+width-1, y+(arc/2), x+width-1, y+height-(arc/2)); - g.drawLine(x+(arc/2), y+height-1, x+width-(arc/2), y+height-1); - g.drawArc(x+width-1-arc, y+height-1-arc, arc, arc, -90, 90); - g.drawArc(x+1, y+height-arc-1, arc, arc, -135, 45); - g.drawArc(x+width-1-arc, y+1, arc, arc, 45, -45); - g.setColor(borderColor); - g.drawRoundRect(x, y, width, height, arc, arc); - - - - g.setColor(c); - } - - public static void enableComponents(Container container, boolean enable) { + + public static void draw3DRoundRectangle(Graphics g, int x, int y, int width, int height, int arc, Color fillColor, Color borderColor) { + Color c = g.getColor(); + + g.setColor(fillColor); + g.fillRoundRect(x, y, width, height, arc, arc); + g.setColor(fillColor.brighter()); + g.drawLine(x+1, y+(arc/2), x+1, y+height-(arc/2)); + g.drawLine(x+(arc/2), y+1, x+width-(arc/2), y+1); + g.drawArc(x+1, y+1, arc, arc, -180, -90); + g.drawArc(x+1, y+height-arc-1, arc, arc, 180, 45); + g.drawArc(x+width-1-arc, y+1, arc, arc, 90, -45); + g.setColor(fillColor.darker()); + g.drawLine(x+width-1, y+(arc/2), x+width-1, y+height-(arc/2)); + g.drawLine(x+(arc/2), y+height-1, x+width-(arc/2), y+height-1); + g.drawArc(x+width-1-arc, y+height-1-arc, arc, arc, -90, 90); + g.drawArc(x+1, y+height-arc-1, arc, arc, -135, 45); + g.drawArc(x+width-1-arc, y+1, arc, arc, 45, -45); + g.setColor(borderColor); + g.drawRoundRect(x, y, width, height, arc, arc); + + + + g.setColor(c); + } + + public static void enableComponents(Container container, boolean enable) { Component[] components = container.getComponents(); for (Component component : components) { component.setEnabled(enable); @@ -626,10 +632,10 @@ public final class GraphicLib { } } } - - public static JTabbedPane createTabbedPane() { - final JTabbedPane pane = new JTabbedPane( JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT ); - - return pane; - } + + public static JTabbedPane createTabbedPane() { + final JTabbedPane pane = new JTabbedPane( JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT ); + + return pane; + } } diff --git a/src/myutil/LoaderFacilityInterface.java b/src/myutil/LoaderFacilityInterface.java new file mode 100755 index 0000000000000000000000000000000000000000..b2e596a3b0b58770c5af720642337e14706bc67c --- /dev/null +++ b/src/myutil/LoaderFacilityInterface.java @@ -0,0 +1,58 @@ +/**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille + + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class LoaderFacilityInterface + * Creation: 31/05/2017 + * @version 1.1 31/05/2017 + * @author Ludovic APVRILLE + * @see + */ + +package myutil; + +import java.net.*; +import java.io.*; +import java.awt.image.*; +import javax.imageio.*; + + +public interface LoaderFacilityInterface { + + public void load(int index); + +} diff --git a/src/myutil/URLManager.java b/src/myutil/URLManager.java index 6087cad75fa483de1e8cf6c59df2b34cfdedfba0..390169544418908d73120621b6019173527e2ba2 100755 --- a/src/myutil/URLManager.java +++ b/src/myutil/URLManager.java @@ -50,8 +50,48 @@ import java.io.*; import java.awt.image.*; import javax.imageio.*; +import org.apache.commons.io.FileUtils; -public final class URLManager { +public final class URLManager implements Runnable { + + private String url; + private boolean busy; + private String path; + private CallbackLoaderInterface callback; + + public URLManager() { + } + + public synchronized boolean downloadFile(String _path, String _url, CallbackLoaderInterface _callback) { + if (busy) { + return false; + } + busy = true; + + path = _path; + url = _url; + callback = _callback; + + Thread t = new Thread(this); + t.start(); + return true; + + } + + public void run() { + try { + String urlF = getRealURL(url); + File f = new File(path); + org.apache.commons.io.FileUtils.copyURLToFile(new URL(urlF), f); + if (callback != null) { + callback.loadDone(); + } + } catch (Exception e) { + if (callback != null) { + callback.loadFailed(); + } + } + } public static String getRealURL(String url) { try { diff --git a/src/ttool.txt b/src/ttool.txt index 44989fe76223c9a03b224f65a97b0efcb294e14f..2e56d7a9ad04fb0ecef3c719e79eb02fde23406b 100755 --- a/src/ttool.txt +++ b/src/ttool.txt @@ -1,2 +1,2 @@ Main-Class: Main -Class-Path: ./jsoup-1.8.1.jar ./commons-codec-1.10.jar ./gs-core-1.3.jar ./gs-ui-1.3.jar +Class-Path: ./jsoup-1.8.1.jar ./commons-codec-1.10.jar ./gs-core-1.3.jar ./gs-ui-1.3.jar ./commons-io-2.5.jar diff --git a/src/ui/ColorManager.java b/src/ui/ColorManager.java index 7ffb06f6edc9ab86f32c01613a0c1259ed32de0e..fe00c535fe38cdc8c877e7fa2a25e01214858236 100755 --- a/src/ui/ColorManager.java +++ b/src/ui/ColorManager.java @@ -74,6 +74,7 @@ public class ColorManager { public static final Color TEPEID = new Color(163, 5, 253); public static final Color AVATARID = new Color(163, 5, 253); public static Color SELECTED_0 = Color.blue; + public static Color SELECTED_ELEMENT = Color.green; public static final Color MOVING_0 = Color.magenta; public static final Color ADDING_0 = Color.lightGray; diff --git a/src/ui/networkmodelloader/JDialogLoadingNetworkModel.java b/src/ui/networkmodelloader/JDialogLoadingNetworkModel.java index 87c68e807d048bbcb47b39c0f6f41cd5f3625334..c7faae49790d9130a50d67cc9d1ef951f434629f 100644 --- a/src/ui/networkmodelloader/JDialogLoadingNetworkModel.java +++ b/src/ui/networkmodelloader/JDialogLoadingNetworkModel.java @@ -58,7 +58,7 @@ import java.io.*; import ui.*; import myutil.*; -public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements ActionListener, Runnable { +public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements ActionListener, Runnable, LoaderFacilityInterface, CallbackLoaderInterface { private ArrayList<NetworkModel> listOfModels; @@ -89,7 +89,7 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac /** Creates new form */ - public JDialogLoadingNetworkModel(Frame _f, MainGUI _mgui, String title, String _url) { + public JDialogLoadingNetworkModel(Frame _f, MainGUI _mgui, String title, String _url) { super(title); f = _f; @@ -124,7 +124,7 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac c.setLayout(new BorderLayout()); //setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - panel = new NetworkModelPanel(listOfModels, this); + panel = new NetworkModelPanel(this, listOfModels, this); jsp = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); c.add(jsp, BorderLayout.CENTER); @@ -155,7 +155,7 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac JPanel jp2 = new JPanel(); jp2.add(stop); - jp2.add(start); + //jp2.add(start); lowPart.add(jp2, BorderLayout.SOUTH); @@ -233,9 +233,9 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac //System.out.println(inputLine); } - jta.append("\n" + listOfModels.size() + " remote models have been detected.\nSelect one to download it locally and open it.\n"); + jta.append("\n" + listOfModels.size() + " remote models found.\nSelect a model to download it locally and open it.\n\n"); mode = LISTED; - panel.addPanelWithButtons(); + panel.preparePanel(); panel.repaint(); in.close(); @@ -275,6 +275,19 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac } } + public void load(int index) { + jta.append("Loading model: " + listOfModels.get(index).fileName); + } + + public void loadDone() { + jta.append("Model transfered, opening it in TTool\n"); + } + + public void loadFailed() { + jta.append("Model transfer failed\nPlease, select another model, or retry\n"); + panel.reactivateSelection(); + } + public void appendOut(String s) { jta.append(s); diff --git a/src/ui/networkmodelloader/NetworkModel.java b/src/ui/networkmodelloader/NetworkModel.java index 474fc192fe7b07a73ea2b211356c349cdd0d8fdb..1996051e069f0c50f336fd0a8f4b0dba355f1fa3 100644 --- a/src/ui/networkmodelloader/NetworkModel.java +++ b/src/ui/networkmodelloader/NetworkModel.java @@ -52,16 +52,19 @@ import java.io.File; import java.awt.image.*; -public class NetworkModel extends JButton { +public class NetworkModel { public String fileName; public NetworkModelType type; public String description; public String image; public BufferedImage bi; + public BufferedImage scaledImg; + + public int x, y, width, height; public NetworkModel(String _fileName) { - super(_fileName); + //super(_fileName); fileName = _fileName; } diff --git a/src/ui/networkmodelloader/NetworkModelPanel.java b/src/ui/networkmodelloader/NetworkModelPanel.java index 9dab8d06ece67668057ddd3d28684780946243e4..5abc3a966f52755b5d4e9b8a67b31cc114e1c0aa 100644 --- a/src/ui/networkmodelloader/NetworkModelPanel.java +++ b/src/ui/networkmodelloader/NetworkModelPanel.java @@ -55,10 +55,11 @@ import javax.swing.border.*; import java.util.*; import myutil.*; +import ui.*; -public class NetworkModelPanel extends JPanel { +public class NetworkModelPanel extends JPanel implements MouseListener, MouseMotionListener { private static int ImgSizeX = 220; private static int ImgSizeY = 120; @@ -68,10 +69,19 @@ public class NetworkModelPanel extends JPanel { private static int spaceBetweenButtons = 50; private static int nbOfButtonsPerColumn = 2; + private static int marginX = 20; + private static int marginY = 20; + + private int indexOfSelected = -1; + private boolean selectedModel = false; + private ArrayList<NetworkModel> listOfModels; private ActionListener listener; + + private LoaderFacilityInterface loader; - public NetworkModelPanel(ArrayList<NetworkModel> _listOfModels, ActionListener _listener) { + public NetworkModelPanel(LoaderFacilityInterface _loader, ArrayList<NetworkModel> _listOfModels, ActionListener _listener) { + loader = _loader; listOfModels = _listOfModels; listener = _listener; @@ -82,19 +92,24 @@ public class NetworkModelPanel extends JPanel { setMinimumSize(mSize); setBackground(new java.awt.Color(250, 250, 250)); setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); + + addMouseMotionListener(this); + addMouseListener(this); } - public void addPanelWithButtons() { - int cptColumn = 0; - int cptRow = 0; + public void preparePanel() { + //int cptColumn = 0; + //int cptRow = 0; for(NetworkModel button: listOfModels) { - int tmpX = cptColumn * (buttonSizeX + spaceBetweenButtons); - int tmpY = cptRow * (buttonSizeY + spaceBetweenButtons); - TraceManager.addDev("Adding button at x=" + tmpX + "& y=" + tmpY); - button.setBounds(tmpX, tmpY, buttonSizeX, buttonSizeY); - if (button.description != null) { + //Dimension d = new Dimension(buttonSizeX, buttonSizeY); + //button.setPreferredSize(d); + //int tmpX = cptColumn * (buttonSizeX + spaceBetweenButtons); + //int tmpY = cptRow * (buttonSizeY + spaceBetweenButtons); + //TraceManager.addDev("Adding button at x=" + tmpX + "& y=" + tmpY); + //button.setBounds(tmpX, tmpY, buttonSizeX, buttonSizeY); + /*if (button.description != null) { button.setToolTipText(button.description); - } + }*/ if (button.bi != null) { TraceManager.addDev("Adding image"); @@ -103,19 +118,17 @@ public class NetworkModelPanel extends JPanel { Graphics g = newImage.createGraphics(); g.drawImage(button.bi, 0, 0, ImgSizeX, ImgSizeY, null); g.dispose();*/ - button.setIcon(new ImageIcon(ImageManager.getScaledImage(button.bi, ImgSizeX, ImgSizeY))); + button.scaledImg = ImageManager.getScaledImage(button.bi, ImgSizeX, ImgSizeY); } - Dimension d = new Dimension(buttonSizeX, buttonSizeY); - button.setPreferredSize(d); //button.setBorder(BorderFactory.createEmptyBorder()); //button.setContentAreaFilled(false); - add(button); - cptColumn ++; + //add(button); + /*cptColumn ++; if (cptColumn == nbOfButtonsPerColumn) { cptRow ++; cptColumn = 0; - } + }*/ } } @@ -125,12 +138,115 @@ public class NetworkModelPanel extends JPanel { @Override public void paintComponent(Graphics g) { super.paintComponent(g); + int cptColumn = 0; + int cptRow = 0; + + int index = 0; + for(NetworkModel button: listOfModels) { + Color c = g.getColor(); + int tmpX = cptColumn * (buttonSizeX + spaceBetweenButtons) + marginX; + int tmpY = cptRow * (buttonSizeY + spaceBetweenButtons) + marginY; + if (button.scaledImg != null) { + g.drawImage(button.scaledImg, tmpX, tmpY, buttonSizeX, buttonSizeY, null); + } else { + g.setColor(ColorManager.AVATAR_BLOCK); + g.fillRect(tmpX, tmpY, buttonSizeX, buttonSizeY); + g.setColor(c); + GraphicLib.centerString(g, "No picture", tmpX, tmpY + buttonSizeY/2, buttonSizeX); + } + + GraphicLib.centerString(g, button.fileName, tmpX, tmpY + buttonSizeY + 15, buttonSizeX); + + + + cptColumn ++; + if (cptColumn == nbOfButtonsPerColumn) { + cptRow ++; + cptColumn = 0; + } + + button.x = tmpX; + button.y = tmpY; + button.width = buttonSizeX; + button.height = buttonSizeY + 15; + + // Must draw the rectangle around + if (index == indexOfSelected) { + if (selectedModel) { + g.setColor(ColorManager.SELECTED_ELEMENT); + } else { + g.setColor(ColorManager.POINTER_ON_ME_0); + } + Graphics2D g2 = (Graphics2D)g; + Stroke oldStroke = g2.getStroke(); + g2.setStroke(new BasicStroke(5)); + g2.drawRect(button.x-10, button.y-10, button.width+20, button.height+20); + g2.setStroke(oldStroke); + g.setColor(c); + } + + index ++; + } - - //g.drawString(listOfModels.size() + " model(s) available", 20, 20); //g.drawRect(200, 200, 200, 200); } + + + public void mouseDragged(MouseEvent e) { + + } + + public void mouseMoved(MouseEvent e) { + if (!selectedModel) { + int previousIndex = indexOfSelected; + boolean found = false;; + int index = 0; + for(NetworkModel button: listOfModels) { + if ((e.getX() > button.x) && (e.getX() < button.x + button.width) && (e.getY() > button.y) && (e.getY() < button.y + button.height)) { + indexOfSelected = index; + found = true; + break; + } + index ++; + } + if (!found) { + indexOfSelected = -1; + } + if (indexOfSelected != previousIndex) { + repaint(); + } + } + } + + public void mousePressed(MouseEvent e) { + } + + public void mouseReleased(MouseEvent e) { + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } + + public void mouseClicked(MouseEvent e) { + if ((indexOfSelected > -1) && (!selectedModel)) { + selectedModel = true; + repaint(); + if (loader != null) { + loader.load(indexOfSelected); + } + } + } + + public void reactivateSelection() { + indexOfSelected = -1; + selectedModel = false; + repaint(); + } + }