Skip to content
Snippets Groups Projects
Commit 73a9bc9f authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

Adding effect for patienting when waiting for AI answer

parent e79c7243
No related branches found
No related tags found
No related merge requests found
......@@ -136,7 +136,9 @@ public class AvatarSignal extends AvatarMethod {
}
return cumul;
}*/
//fin DG
//fin DG
public AvatarSignal advancedClone(AvatarStateMachineOwner _block) {
AvatarSignal as = new AvatarSignal(getName(), getInOut(), getReferenceObject());
setAdvancedClone(as, _block);
......
This diff is collapsed.
......@@ -42,6 +42,11 @@ package ui.util;
import javax.swing.*;
import java.awt.*;
import java.net.URL;
import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
/**
......@@ -1329,4 +1334,24 @@ public class IconManager {
imgic8030 = getIcon(icon8030);
}
public static ImageIcon rotateImageIcon(ImageIcon icon, double degrees) {
int w = icon.getIconWidth();
int h = icon.getIconHeight();
int type = BufferedImage.TYPE_INT_ARGB; // Other options
BufferedImage image = new BufferedImage(h, w, type);
Graphics2D g2 = image.createGraphics();
double x = (h - w)/2.0;
double y = (h - w)/2.0;
AffineTransform at = AffineTransform.getTranslateInstance(x, y);
at.rotate(Math.toRadians(degrees), w/2.0, h/2.0);
g2.setBackground(Color.white);
g2.drawImage(icon.getImage(), at, null);
g2.dispose();
icon = new ImageIcon(image);
return icon;
}
} // Class
......@@ -62,6 +62,7 @@ import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.HashMap;
/**
......@@ -102,13 +103,13 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable {
private String KNOWLEDGE_ON_JSON_FOR_BLOCKS = "JSON for block diagram is as follows: " +
"{blocks: [{ \"name\": \"Name of block\", \"attributes\": [\"name\": \"name of attribute\", \"type\": \"int or boolean\" ...}" + " same" +
"(with its parameters : int, boolean ; and its return type : nothing, int or boolean)" +
"and signals (with its list of parameters : int or boolean ; and each signal is either an output signal or an input signal), ..." +
"and signals (with its list of parameters : int or boolean, and a type (input, output)" +
" then the list of connections between block signals: \"connections\": [\n" +"{\n" + " \"sourceBlock\": \"name of block\",\n" +
" \"sourceSignal\": \"name of output signal\",\n" +
" \"destinationBlock\": \"name of destination block\",\n" +
" \"destinationSignal\": \"rechargeBattery\",\n" +
" \"communicationType\": \"synchronous (or asynchronous)\"\n" +
"},";
"}. A connection must connect one output signal of a block to one input signal of a block";
private String QUESTION_IDENTIFY_SYSTEM_BLOCKS = "From the following system specification, using the specified JSON format, identify the " +
"typical system blocks. All this in JSON.\n";
......@@ -133,7 +134,9 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable {
private boolean go = false;
private class ChatData {
private HashMap<Integer, ImageIcon> rotatedI = new HashMap<>();
private class ChatData implements Runnable {
public AIInterface aiinterface;
public boolean knowledgeOnProperties = false;
public boolean knowledgeOnBlockJSON = false;
......@@ -141,6 +144,9 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable {
public String lastAnswer = "";
public int previousKind;
public TDiagramPanel tdp;
public boolean doIconRotation = false;
private Thread t;
public ChatData() {}
......@@ -148,8 +154,49 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable {
lastAnswer = "";
answer.setText("");
}
public void startAnimation() {
doIconRotation = true;
t = new Thread(this);
t.start();
}
public void stopAnimation() {
doIconRotation = false;
if (t != null) {
t.interrupt();
}
t = null;
}
public void run() {
int angle = 0;
while( doIconRotation ) {
angle = (angle - 15) % 360;
ImageIcon rotated = rotatedI.get(angle);
if ( rotated == null ) {
rotated = IconManager.rotateImageIcon(IconManager.imgic154, angle);
rotatedI.put(angle, rotated);
}
setIcon(this, rotated);
try {
Thread.currentThread().sleep(100);
} catch (Exception e) {
TraceManager.addDev("Interrupted");
doIconRotation = false;
};
}
setIcon(this, IconManager.imgic154);
}
}
public void setIcon(ChatData _data, Icon newIcon) {
int index = chats.indexOf(_data);
answerPane.setIconAt(index, newIcon);
}
private JButton buttonClose, buttonStart, buttonApplyResponse;
......@@ -325,6 +372,9 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable {
private void close() {
for(ChatData data: chats) {
data.stopAnimation();
}
dispose();
}
......@@ -480,6 +530,8 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable {
}
public void run() {
ChatData selected = selectedChat();
selected.startAnimation();
go = true;
enableDisableActions();
......@@ -506,6 +558,7 @@ public class JFrameAI extends JFrame implements ActionListener, Runnable {
}
go = false;
selected.stopAnimation();
enableDisableActions();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment