Une interface plus jolie, la capacité de désactiver les enceintes depuis
Master (NON TESTÉ !)
This commit is contained in:
parent
23c25f0e05
commit
3969b66c68
23
src/main/java/com/bernard/murder/Parametres.java
Normal file
23
src/main/java/com/bernard/murder/Parametres.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package com.bernard.murder;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.font.TextAttribute;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
|
public class Parametres {
|
||||||
|
|
||||||
|
public static Font minielTitleFont = UIManager.getFont("Label.font");
|
||||||
|
static {
|
||||||
|
Map<TextAttribute, Object> ftAttrs = new HashMap<>(minielTitleFont.getAttributes());
|
||||||
|
ftAttrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
||||||
|
minielTitleFont = minielTitleFont.deriveFont(Font.BOLD).deriveFont(ftAttrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Color textPanMinielBackgroundColor = new Color(0xFFE085);
|
||||||
|
public static Color textPanMinielTextColor = new Color(0x274290);
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,6 +15,7 @@ import java.util.Map;
|
|||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import javax.sound.sampled.AudioFormat;
|
import javax.sound.sampled.AudioFormat;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
@ -42,6 +43,7 @@ public class AudioServer {
|
|||||||
public static final byte ASK_STOP_STREAMING = 0x09;
|
public static final byte ASK_STOP_STREAMING = 0x09;
|
||||||
// Format des paquets: [commande 1, int id]
|
// Format des paquets: [commande 1, int id]
|
||||||
// -> Master demande à un micro de ne plus émettre.
|
// -> Master demande à un micro de ne plus émettre.
|
||||||
|
// -> Master annonce à une enceinte qu'il n'emmet plus le micro demandé.
|
||||||
public static final byte STOP_STREAMING = 0x08;
|
public static final byte STOP_STREAMING = 0x08;
|
||||||
// Format des paquets [commande 1, int id, ~ data]
|
// Format des paquets [commande 1, int id, ~ data]
|
||||||
public static final byte AUDIO_STREAM = 0x01;
|
public static final byte AUDIO_STREAM = 0x01;
|
||||||
@ -71,6 +73,7 @@ public class AudioServer {
|
|||||||
Map<Integer,List<Integer>> listening; // micId, List<speakerId>
|
Map<Integer,List<Integer>> listening; // micId, List<speakerId>
|
||||||
|
|
||||||
private Set<Runnable> changeListeners;
|
private Set<Runnable> changeListeners;
|
||||||
|
private Set<Consumer<Exception>> serverErrorException;
|
||||||
|
|
||||||
public AudioServer() throws SocketException, UnknownHostException {
|
public AudioServer() throws SocketException, UnknownHostException {
|
||||||
mics = new HashMap<Integer, String>();
|
mics = new HashMap<Integer, String>();
|
||||||
@ -80,6 +83,7 @@ public class AudioServer {
|
|||||||
listening = new HashMap<Integer, List<Integer>>();
|
listening = new HashMap<Integer, List<Integer>>();
|
||||||
|
|
||||||
changeListeners = new HashSet<>();
|
changeListeners = new HashSet<>();
|
||||||
|
serverErrorException = new HashSet<>();
|
||||||
|
|
||||||
initServer();
|
initServer();
|
||||||
}
|
}
|
||||||
@ -283,7 +287,7 @@ public class AudioServer {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void publishAudioList(Collection<SocketAddress> co) {
|
public void publishAudioList(Collection<SocketAddress> to) {
|
||||||
ByteBuffer out = ByteBuffer.allocate(AudioServer.packetMaxSize);
|
ByteBuffer out = ByteBuffer.allocate(AudioServer.packetMaxSize);
|
||||||
out.put(AudioServer.GIVE_AUDIO_LIST);
|
out.put(AudioServer.GIVE_AUDIO_LIST);
|
||||||
out.putInt(mics.size());
|
out.putInt(mics.size());
|
||||||
@ -292,12 +296,81 @@ public class AudioServer {
|
|||||||
BytesUtils.writeString(out, mic.getValue());
|
BytesUtils.writeString(out, mic.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
for(SocketAddress addr : to) {
|
||||||
for(SocketAddress addr : co) {
|
try {
|
||||||
serveur.sendData(out, addr);
|
serveur.sendData(out, addr);
|
||||||
|
} catch (Exception e) {
|
||||||
|
serverErrorException.forEach(c -> c.accept(e));
|
||||||
}
|
}
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int enceinteIdFromName(String name) {
|
||||||
|
for(int i:speakers.keySet()) {
|
||||||
|
if(name.equalsIgnoreCase(speakers.get(i)))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void forceSilence(int id) {
|
||||||
|
if(!speakers.containsKey(id))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int lstTo = listens(id);
|
||||||
|
if(lstTo!=-1) {
|
||||||
|
// On enlève le lien d'écoute
|
||||||
|
listening.get(lstTo).remove(id);
|
||||||
|
|
||||||
|
// Si il n'y a plus rien à écouter.
|
||||||
|
ByteBuffer out4 = ByteBuffer.allocate(AudioServer.packetMaxSize);
|
||||||
|
out4.put(AudioServer.STOP_STREAMING);
|
||||||
|
out4.putInt(lstTo);
|
||||||
|
try {
|
||||||
|
serveur.sendData(out4, speakersAddr.get(id));
|
||||||
|
} catch (Exception e1) {
|
||||||
|
serverErrorException.forEach(c -> c.accept(e1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disconnectEnceinte(int id) {
|
||||||
|
|
||||||
|
if(!speakers.containsKey(id))
|
||||||
|
return;
|
||||||
|
// On lui annonce notre déconnection, puis on la supprime des données
|
||||||
|
ByteBuffer decoBuf = ByteBuffer.allocate(AudioServer.packetMaxSize);
|
||||||
|
decoBuf.put(AudioServer.DISCONNECTING);
|
||||||
|
decoBuf.put(AudioServer.MASTER_DEVICE);
|
||||||
|
decoBuf.putInt(0);
|
||||||
|
try {
|
||||||
|
serveur.sendData(decoBuf, speakersAddr.get(id));
|
||||||
|
} catch (Exception e) {
|
||||||
|
serverErrorException.forEach(c -> c.accept(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
speakers.remove(id);
|
||||||
|
speakersAddr.remove(id);
|
||||||
|
changeListeners.forEach(Runnable::run);
|
||||||
|
|
||||||
|
int lstTo = listens(id);
|
||||||
|
if(lstTo!=-1) {
|
||||||
|
// On enlève le lien d'écoute
|
||||||
|
listening.get(lstTo).remove(id);
|
||||||
|
|
||||||
|
if(listening.get(lstTo).isEmpty()) {
|
||||||
|
// Si il n'y a plus rien à écouter.
|
||||||
|
ByteBuffer out4 = ByteBuffer.allocate(AudioServer.packetMaxSize);
|
||||||
|
out4.put(AudioServer.STOP_STREAMING);
|
||||||
|
out4.putInt(lstTo);
|
||||||
|
try {
|
||||||
|
serveur.sendData(out4, micsAddr.get(lstTo));
|
||||||
|
} catch (Exception e1) {
|
||||||
|
serverErrorException.forEach(c -> c.accept(e1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -205,6 +205,14 @@ public class SpeakerServer {
|
|||||||
System.out.println("Un appareil de type "+deviceType2+" s'est déconécté, mais je m'en fout ^^");
|
System.out.println("Un appareil de type "+deviceType2+" s'est déconécté, mais je m'en fout ^^");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case AudioServer.STOP_STREAMING:
|
||||||
|
int deviceId3 = data.getInt();
|
||||||
|
if(listeningTo==deviceId3) {
|
||||||
|
System.out.println("Le micro que l'on écoutait arêtte d'émmetre.");
|
||||||
|
listeningTo=-1;
|
||||||
|
for(Runnable toRun : brokenMicListener)
|
||||||
|
toRun.run();
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
System.out.println("Je ne devait pas recevoir cette commade !");
|
System.out.println("Je ne devait pas recevoir cette commade !");
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -57,11 +57,13 @@ public class EnceinteServeurFrame extends JFrame{
|
|||||||
|
|
||||||
InformedSourceDataline[] marray = getEnceinteList();
|
InformedSourceDataline[] marray = getEnceinteList();
|
||||||
JList<InformedSourceDataline> enceinteListe = new JList<InformedSourceDataline>(marray);
|
JList<InformedSourceDataline> enceinteListe = new JList<InformedSourceDataline>(marray);
|
||||||
|
enceinteListe.setOpaque(false);
|
||||||
|
|
||||||
JTextField masterIP = new JTextField("192.168.1.1",15);
|
JTextField masterIP = new JTextField("192.168.1.1",15);
|
||||||
JButton serverControl = new JButton("Lancer");
|
JButton serverControl = new JButton("Lancer");
|
||||||
|
|
||||||
JList<NamedMicrophone> mics = new JList<>();
|
JList<NamedMicrophone> mics = new JList<>();
|
||||||
|
mics.setOpaque(false);
|
||||||
JButton silenceButton = new JButton("Silence");
|
JButton silenceButton = new JButton("Silence");
|
||||||
|
|
||||||
serverControl.addActionListener(e->{
|
serverControl.addActionListener(e->{
|
||||||
@ -128,6 +130,8 @@ public class EnceinteServeurFrame extends JFrame{
|
|||||||
|
|
||||||
|
|
||||||
JPanel headP = new JPanel(new BorderLayout());
|
JPanel headP = new JPanel(new BorderLayout());
|
||||||
|
headP.setBorder(new EmptyBorder(3, 3, 5, 3));
|
||||||
|
|
||||||
JPanel centerP = new JPanel(new GridLayout(2, 1));
|
JPanel centerP = new JPanel(new GridLayout(2, 1));
|
||||||
|
|
||||||
headP.add(serverControl,BorderLayout.EAST);
|
headP.add(serverControl,BorderLayout.EAST);
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public class MicServeurFrame extends JFrame{
|
|||||||
|
|
||||||
InformedTargetDataline[] marray = getEnceinteList();
|
InformedTargetDataline[] marray = getEnceinteList();
|
||||||
JList<InformedTargetDataline> micListe = new JList<InformedTargetDataline>(marray);
|
JList<InformedTargetDataline> micListe = new JList<InformedTargetDataline>(marray);
|
||||||
|
micListe.setOpaque(false);
|
||||||
|
|
||||||
JPanel masterPanel = new JPanel(new BorderLayout());
|
JPanel masterPanel = new JPanel(new BorderLayout());
|
||||||
JTextField masterIP = new JTextField("192.168.1.1");
|
JTextField masterIP = new JTextField("192.168.1.1");
|
||||||
@ -90,6 +90,7 @@ public class MicServeurFrame extends JFrame{
|
|||||||
|
|
||||||
|
|
||||||
JPanel headP = new JPanel(new BorderLayout());
|
JPanel headP = new JPanel(new BorderLayout());
|
||||||
|
headP.setBorder(new EmptyBorder(3, 3, 5, 3));
|
||||||
|
|
||||||
headP.add(serverControl,BorderLayout.EAST);
|
headP.add(serverControl,BorderLayout.EAST);
|
||||||
headP.add(masterIP,BorderLayout.CENTER);
|
headP.add(masterIP,BorderLayout.CENTER);
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@ -18,6 +19,7 @@ import javax.swing.Timer;
|
|||||||
import com.amihaiemil.eoyaml.Yaml;
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
||||||
|
import com.bernard.murder.Parametres;
|
||||||
import com.bernard.murder.ParseUtils;
|
import com.bernard.murder.ParseUtils;
|
||||||
import com.bernard.murder.game.GameManager;
|
import com.bernard.murder.game.GameManager;
|
||||||
import com.bernard.murder.model.Action;
|
import com.bernard.murder.model.Action;
|
||||||
@ -71,9 +73,14 @@ public class ActionsMinel extends Minel {
|
|||||||
Timer timer = new Timer(100, e->updateTexts());
|
Timer timer = new Timer(100, e->updateTexts());
|
||||||
timer.start();
|
timer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
JScrollPane globalScroll = new JScrollPane(actionsListPan);
|
JScrollPane globalScroll = new JScrollPane(actionsListPan);
|
||||||
JLabel titleLabel = new JLabel("Actions de "+personnage.getNom());
|
|
||||||
globalPan.add(titleLabel,BorderLayout.NORTH);
|
JLabel titre = new JLabel("Actions de "+personnage.getNom(),JLabel.CENTER);
|
||||||
|
titre.setFont(Parametres.minielTitleFont);
|
||||||
|
titre.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||||
|
|
||||||
|
globalPan.add(titre,BorderLayout.NORTH);
|
||||||
globalPan.add(globalScroll,BorderLayout.CENTER);
|
globalPan.add(globalScroll,BorderLayout.CENTER);
|
||||||
|
|
||||||
updateTexts();
|
updateTexts();
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import java.awt.BorderLayout;
|
|||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
@ -13,6 +14,7 @@ import javax.swing.ListCellRenderer;
|
|||||||
import com.amihaiemil.eoyaml.Yaml;
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
||||||
|
import com.bernard.murder.Parametres;
|
||||||
import com.bernard.murder.game.GameManager;
|
import com.bernard.murder.game.GameManager;
|
||||||
import com.bernard.murder.model.Inventaire;
|
import com.bernard.murder.model.Inventaire;
|
||||||
import com.bernard.murder.model.Objet;
|
import com.bernard.murder.model.Objet;
|
||||||
@ -37,11 +39,15 @@ public class InventaireMinel extends Minel {
|
|||||||
public JPanel genContentPane() {
|
public JPanel genContentPane() {
|
||||||
JPanel globalpan = new JPanel(new BorderLayout());
|
JPanel globalpan = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
|
JLabel titre;
|
||||||
|
|
||||||
if(inv.getInventoryName()!=null) {
|
if(inv.getInventoryName()!=null)
|
||||||
JLabel invName = new JLabel(inv.getInventoryName());
|
titre = new JLabel(inv.getInventoryName(),JLabel.CENTER);
|
||||||
globalpan.add(invName, BorderLayout.NORTH);
|
else
|
||||||
}
|
titre = new JLabel("Inventaire",JLabel.CENTER);
|
||||||
|
titre.setFont(Parametres.minielTitleFont);
|
||||||
|
titre.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||||
|
globalpan.add(titre, BorderLayout.NORTH);
|
||||||
|
|
||||||
JPanel inventaire = new JPanel();
|
JPanel inventaire = new JPanel();
|
||||||
|
|
||||||
|
|||||||
@ -8,16 +8,20 @@ import java.util.Set;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
|
import javax.swing.event.DocumentListener;
|
||||||
|
|
||||||
import com.amihaiemil.eoyaml.Scalar;
|
import com.amihaiemil.eoyaml.Scalar;
|
||||||
import com.amihaiemil.eoyaml.Yaml;
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
||||||
import com.amihaiemil.eoyaml.YamlNode;
|
import com.amihaiemil.eoyaml.YamlNode;
|
||||||
|
import com.bernard.murder.Parametres;
|
||||||
import com.bernard.murder.ParseUtils;
|
import com.bernard.murder.ParseUtils;
|
||||||
import com.bernard.murder.YamlUtils;
|
import com.bernard.murder.YamlUtils;
|
||||||
import com.bernard.murder.game.GameManager;
|
import com.bernard.murder.game.GameManager;
|
||||||
@ -59,29 +63,32 @@ public class ObjetSearchMinel extends Minel {
|
|||||||
|
|
||||||
JPanel globalPan = new JPanel(new BorderLayout());
|
JPanel globalPan = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
|
JLabel titre = new JLabel("Recherche d'objets",JLabel.CENTER);
|
||||||
|
titre.setFont(Parametres.minielTitleFont);
|
||||||
|
|
||||||
|
JPanel panel = new JPanel(new BorderLayout());
|
||||||
|
panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||||
JTextField searchField = new JTextField();
|
JTextField searchField = new JTextField();
|
||||||
searchField.setToolTipText("Objet à chercher");
|
searchField.setToolTipText("Objet à chercher");
|
||||||
|
|
||||||
JList<InventorizedObject> searchResults = new JList<>();
|
JList<InventorizedObject> searchResults = new JList<>();
|
||||||
|
searchResults.setOpaque(false);
|
||||||
|
searchResults.setBorder(BorderFactory.createEmptyBorder(5,2,2,2));
|
||||||
|
|
||||||
|
DocumentListener dl = new SimpleDocumentListener() {
|
||||||
|
|
||||||
searchField.getDocument().addDocumentListener(new SimpleDocumentListener() {
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void changedUpdate(DocumentEvent e) {
|
public void changedUpdate(DocumentEvent e) {
|
||||||
System.out.println("Updated to "+e.getDocument().toString());
|
|
||||||
String searchText = searchField.getText();
|
String searchText = searchField.getText();
|
||||||
if(searchText.isBlank()) {
|
/*if(searchText.isBlank()) {
|
||||||
searchResults.setListData(new InventorizedObject[0]);
|
searchResults.setListData(new InventorizedObject[0]);
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
Set<InventorizedObject> startMatch = new HashSet<>();
|
Set<InventorizedObject> startMatch = new HashSet<>();
|
||||||
Set<InventorizedObject> anyMatch = new HashSet<>();
|
Set<InventorizedObject> anyMatch = new HashSet<>();
|
||||||
Set<InventorizedObject> subwordMatch = new HashSet<>();
|
Set<InventorizedObject> subwordMatch = new HashSet<>();
|
||||||
|
|
||||||
for(Objet o : objets.keySet()) {
|
for(Objet o : objets.keySet()) {
|
||||||
System.out.println(o+"->"+searchText);
|
|
||||||
if(o.getNom().startsWith(searchText))
|
if(o.getNom().startsWith(searchText))
|
||||||
startMatch.add(new InventorizedObject(o,objets.get(o)));
|
startMatch.add(new InventorizedObject(o,objets.get(o)));
|
||||||
else if(o.getNom().contains(searchText))
|
else if(o.getNom().contains(searchText))
|
||||||
@ -99,11 +106,18 @@ public class ObjetSearchMinel extends Minel {
|
|||||||
searchResults.setListData(results);
|
searchResults.setListData(results);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
searchField.getDocument().addDocumentListener(dl);
|
||||||
|
|
||||||
globalPan.add(searchField, BorderLayout.NORTH);
|
//Remplis la liste pour la première fois
|
||||||
globalPan.add(searchResults,BorderLayout.CENTER);
|
dl.changedUpdate(null);
|
||||||
|
|
||||||
|
|
||||||
|
panel.add(searchField, BorderLayout.NORTH);
|
||||||
|
panel.add(searchResults,BorderLayout.CENTER);
|
||||||
|
|
||||||
|
globalPan.add(titre,BorderLayout.NORTH);
|
||||||
|
globalPan.add(panel,BorderLayout.CENTER);
|
||||||
return globalPan;
|
return globalPan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,25 +3,25 @@ package com.bernard.murder.view.minel;
|
|||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.font.TextAttribute;
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.swing.BorderFactory;
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JList;
|
import javax.swing.JList;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
|
|
||||||
import com.amihaiemil.eoyaml.Yaml;
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
||||||
|
import com.bernard.murder.Parametres;
|
||||||
import com.bernard.murder.audio.AudioServer;
|
import com.bernard.murder.audio.AudioServer;
|
||||||
import com.bernard.murder.game.GameManager;
|
import com.bernard.murder.game.GameManager;
|
||||||
|
|
||||||
@ -29,6 +29,12 @@ public class ServeurMinel extends Minel {
|
|||||||
|
|
||||||
AudioServer serveur;
|
AudioServer serveur;
|
||||||
|
|
||||||
|
JList<Integer> microList;
|
||||||
|
JList<Integer> enceinteListe;
|
||||||
|
|
||||||
|
JPopupMenu microPopup;
|
||||||
|
JPopupMenu enceintePopup;
|
||||||
|
|
||||||
public ServeurMinel(GameManager manager) {
|
public ServeurMinel(GameManager manager) {
|
||||||
super(manager);
|
super(manager);
|
||||||
try {
|
try {
|
||||||
@ -52,30 +58,22 @@ public class ServeurMinel extends Minel {
|
|||||||
JPanel panel = new JPanel(new BorderLayout());
|
JPanel panel = new JPanel(new BorderLayout());
|
||||||
|
|
||||||
JLabel titre = new JLabel("Status du serveur",JLabel.CENTER);
|
JLabel titre = new JLabel("Status du serveur",JLabel.CENTER);
|
||||||
Font ft = titre.getFont();
|
titre.setFont(Parametres.minielTitleFont);
|
||||||
Map<TextAttribute, Object> ftAttrs = new HashMap<>(ft.getAttributes());
|
titre.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||||
ftAttrs.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
|
|
||||||
titre.setFont(ft.deriveFont(Font.BOLD).deriveFont(ftAttrs));
|
|
||||||
|
|
||||||
JList<String> microList = new JList<>();
|
microList = new JList<>();
|
||||||
JList<String> enceinteListe = new JList<>();
|
microList.setOpaque(false);
|
||||||
|
enceinteListe = new JList<>();
|
||||||
|
enceinteListe.setOpaque(false);
|
||||||
|
|
||||||
serveur.addChangeListener(new Runnable() {
|
EnceintePopupListener epl = new EnceintePopupListener();
|
||||||
|
enceintePopup = epl.makePopup();
|
||||||
@Override
|
enceinteListe.addMouseListener(epl);
|
||||||
public void run() {
|
|
||||||
|
serveur.addChangeListener(() -> {
|
||||||
// Updating lists content
|
// Updating lists content
|
||||||
Collection<String> micsData = serveur.getMics().values();
|
microList.setListData(new Vector<Integer>(serveur.getMics().keySet()));
|
||||||
microList.setListData(new Vector<String>(micsData));
|
enceinteListe.setListData(new Vector<Integer>(serveur.getSpeakers().keySet()));
|
||||||
|
|
||||||
Collection<String> spksData = serveur.getSpeakers().entrySet().stream()
|
|
||||||
.map(e -> e.getValue() + (
|
|
||||||
(serveur.listens(e.getKey())!=-1)
|
|
||||||
?(" <- "+serveur.getMics().get(serveur.listens(e.getKey())))
|
|
||||||
:""))
|
|
||||||
.collect(Collectors.toSet());
|
|
||||||
enceinteListe.setListData(new Vector<String>(spksData));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
JScrollPane jE = new JScrollPane(enceinteListe);
|
JScrollPane jE = new JScrollPane(enceinteListe);
|
||||||
@ -94,6 +92,49 @@ public class ServeurMinel extends Minel {
|
|||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class EnceintePopupListener extends MouseAdapter{
|
||||||
|
|
||||||
|
public final JPopupMenu makePopup() {
|
||||||
|
JPopupMenu popup = new JPopupMenu();
|
||||||
|
|
||||||
|
JLabel idText = new JLabel();
|
||||||
|
idText.setFont(idText.getFont().deriveFont(Font.ITALIC));
|
||||||
|
idText.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
|
||||||
|
enceinteListe.getSelectionModel().addListSelectionListener(e ->
|
||||||
|
idText.setText("Id: "+ (enceinteListe.getSelectedValue()!=null?enceinteListe.getSelectedValue():-1))
|
||||||
|
);
|
||||||
|
popup.add(idText);
|
||||||
|
JMenuItem jmi = new JMenuItem("Silence");
|
||||||
|
jmi.addActionListener(e -> {
|
||||||
|
serveur.forceSilence(enceinteListe.getSelectedValue());
|
||||||
|
});
|
||||||
|
popup.add(jmi);
|
||||||
|
jmi = new JMenuItem("Déconnecter");
|
||||||
|
jmi.addActionListener(e -> {
|
||||||
|
serveur.disconnectEnceinte(enceinteListe.getSelectedValue());
|
||||||
|
});
|
||||||
|
popup.add(jmi);
|
||||||
|
return popup;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
maybeShowPopup(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
maybeShowPopup(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void maybeShowPopup(MouseEvent e) {
|
||||||
|
if (e.isPopupTrigger()) {
|
||||||
|
enceinteListe.setSelectedIndex(enceinteListe.locationToIndex(e.getPoint()));
|
||||||
|
if(!enceinteListe.isSelectionEmpty())
|
||||||
|
enceintePopup.show(e.getComponent(), e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public YamlMappingBuilder saveToYaml() {
|
public YamlMappingBuilder saveToYaml() {
|
||||||
return Yaml.createYamlMappingBuilder();
|
return Yaml.createYamlMappingBuilder();
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package com.bernard.murder.view.minel;
|
|||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
@ -10,6 +12,7 @@ import javax.swing.border.EmptyBorder;
|
|||||||
import com.amihaiemil.eoyaml.Yaml;
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
import com.amihaiemil.eoyaml.YamlMappingBuilder;
|
||||||
|
import com.bernard.murder.Parametres;
|
||||||
import com.bernard.murder.game.GameManager;
|
import com.bernard.murder.game.GameManager;
|
||||||
|
|
||||||
public class TextPanMinel extends Minel {
|
public class TextPanMinel extends Minel {
|
||||||
@ -29,15 +32,20 @@ public class TextPanMinel extends Minel {
|
|||||||
@Override
|
@Override
|
||||||
public JPanel genContentPane() {
|
public JPanel genContentPane() {
|
||||||
JPanel globalPan = new JPanel(new BorderLayout());
|
JPanel globalPan = new JPanel(new BorderLayout());
|
||||||
//globalPan.setBackground(ParseUtils.randColor());
|
|
||||||
|
JLabel titre = new JLabel("Notes",JLabel.CENTER);
|
||||||
|
titre.setFont(Parametres.minielTitleFont);
|
||||||
|
titre.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
|
||||||
|
|
||||||
|
|
||||||
textArea = new JTextArea();
|
textArea = new JTextArea();
|
||||||
textArea.setBorder(new EmptyBorder(23,23,23,23));
|
textArea.setBorder(new EmptyBorder(23,23,23,23));
|
||||||
textArea.setText(initTexte);
|
textArea.setText(initTexte);
|
||||||
|
|
||||||
//Color col = ParseUtils.randColor();
|
textArea.setBackground(Parametres.textPanMinielBackgroundColor);
|
||||||
//textArea.setBackground(col);
|
textArea.setForeground(Parametres.textPanMinielTextColor);
|
||||||
//textArea.setForeground(ParseUtils.getContrastColor(col));
|
|
||||||
|
|
||||||
|
globalPan.add(titre,BorderLayout.NORTH);
|
||||||
globalPan.add(new JScrollPane(textArea),BorderLayout.CENTER);
|
globalPan.add(new JScrollPane(textArea),BorderLayout.CENTER);
|
||||||
return globalPan;
|
return globalPan;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user