Skip to content

Commit

Permalink
0.7.5 Fix1
Browse files Browse the repository at this point in the history
Task #77 - 0.7.5 création d'équipe impossible
  • Loading branch information
Bojo committed Oct 6, 2015
1 parent af24d7f commit 8293caf
Show file tree
Hide file tree
Showing 12 changed files with 239 additions and 118 deletions.
17 changes: 5 additions & 12 deletions tourma/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Perso/Tourma/src/tourma/utils/TourmaProtocol.java</file>
<file>file:/C:/Perso/Tourma/src/tourma/data/Team.java</file>
<file>file:/C:/Perso/Tourma/src/tourma/data/Round.java</file>
<file>file:/C:/Perso/Tourma/src/tourma/data/Coach.java</file>
<file>file:/C:/Perso/Tourma/src/tourma/views/fullscreen/JFullScreenMatchs.java</file>
<file>file:/C:/Perso/Tourma/src/tourma/data/RosterType.java</file>
<file>file:/C:/Perso/Tourma/src/tourma/data/Tournament.java</file>
<file>file:/C:/Perso/Tourma/src/teamma/data/Player.java</file>
<file>file:/C:/Perso/Tourma/src/tourma/utils/TServerThread.java</file>
<file>file:/C:/Perso/Tourma/src/tourma/data/TeamMatch.java</file>
<file>file:/C:/Perso/Tourma/src/teamma/data/Roster.java</file>
<file>file:/C:/Perso/Tourma/src/tourma/views/system/JdgAbout.java</file>
<file>file:/C:/Perso/tourma/tourma/src/tourma/JdgTeam.java</file>
<file>file:/C:/Perso/tourma/tourma/src/tourma/views/fullscreen/JFullScreenMatchs.java</file>
<file>file:/C:/Perso/tourma/tourma/src/tourma/views/fullscreen/JFullScreen.java</file>
<file>file:/C:/Perso/tourma/tourma/src/tourma/JdgCoach.java</file>
<file>file:/C:/Perso/tourma/tourma/src/tourma/views/parameters/JPNParamClan.java</file>
</group>
</open-files>
</project-private>
155 changes: 110 additions & 45 deletions tourma/src/tourma/JdgCoach.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@
*/
package tourma;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.awt.BorderLayout;
import java.awt.DisplayMode;
import java.awt.Graphics;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
Expand Down Expand Up @@ -176,7 +183,7 @@ public JdgCoach(final java.awt.Frame parent, final boolean modal, final Team tea
jcbRoster.setModel(RosterType.getRostersNamesModel());
if (mCoach.getPicture() == null) {
try {
mCoach.setPicture(ImageIO.read(getClass().getResource("/tourma/images/avatar/60001.gif")));
mCoach.setPicture(ImageIO.read(getClass().getResource("/tourma/images/avatar/60001.png")));
} catch (IOException ex) {
Logger.getLogger(JdgCoach.class.getName()).log(Level.SEVERE, null, ex);
}
Expand Down Expand Up @@ -270,7 +277,7 @@ public JdgCoach(final java.awt.Frame parent, final boolean modal, final Coach co

if (coach.getPicture() == null) {
try {
coach.setPicture(ImageIO.read(getClass().getResource("/tourma/images/avatar/60001.gif")));
coach.setPicture(ImageIO.read(getClass().getResource("/tourma/images/avatar/60001.png")));
} catch (IOException ex) {
Logger.getLogger(JdgCoach.class.getName()).log(Level.SEVERE, null, ex);
}
Expand All @@ -285,7 +292,7 @@ public JdgCoach(final java.awt.Frame parent, final boolean modal, final Coach co
* regenerated by the Form Editor.
*/
@SuppressWarnings({"unchecked", "PMD"})
@SuppressFBWarnings({"SIC", "Generated Code"})

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

Expand Down Expand Up @@ -597,7 +604,6 @@ private void jbtOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:e
//c.setPicture(mCoach.getPicture());
}


if (!error) {
this.setVisible(false);
}
Expand Down Expand Up @@ -661,7 +667,7 @@ private void updatelist() {

private void jbtAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAddActionPerformed

String input = (String) JOptionPane.showInputDialog(this,
String input = (String) JOptionPane.showInputDialog(this,
java.util.ResourceBundle.getBundle("tourma/languages/language").getString("ChooseRoster"), java.util.ResourceBundle.getBundle("tourma/languages/language").getString("Roster's Choice"), JOptionPane.INFORMATION_MESSAGE,
null, RosterType.getRostersNames(), "Amazons");
teamma.data.RosterType rt = teamma.data.LRB.getLRB().getRosterType(input);
Expand All @@ -684,59 +690,118 @@ private void jbtDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:
}
}//GEN-LAST:event_jbtDelActionPerformed

private void jbtAvatarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAvatarActionPerformed
File folder;
folder = new File(getClass().getResource("/tourma/images/avatar").getFile());
File[] listOfFiles = folder.listFiles();

Object[] objects = new Object[listOfFiles.length + 1];
public List<ImageIcon> getImagesResources(final String path) throws IOException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
ArrayList<ImageIcon> list = new ArrayList<>();
final File jarFile = new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
if (jarFile == null) {
System.out.println("Jarfile is null: " + getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
} else {
System.out.println("Open JAR File: " + getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
}

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
String path = listOfFiles[i].getAbsolutePath();
ImageIcon icon = new ImageIcon(path);
objects[i] = ImageTreatment.resize(icon, 80, 80);
} else if (listOfFiles[i].isDirectory()) {
LOG.log(Level.INFO, "{0} {1}", new Object[]{java.util.ResourceBundle.getBundle("tourma/languages/language").getString("DIRECTORY"), listOfFiles[i].getName()});
if (jarFile.isFile()) { // Run with JAR file
final JarFile jar = new JarFile(jarFile);
final Enumeration<JarEntry> entries = jar.entries(); //gives ALL entries in jar
while (entries.hasMoreElements()) {
final String name = entries.nextElement().getName();
//System.out.println("Open JAR File: "+name);
String pathToTest;
if (path.startsWith("/")) {
pathToTest = path.subSequence(1, path.length()).toString();
} else {
pathToTest = path;
}
// System.out.println("Tests "+name+" starts with "+pathToTest);
if (name.startsWith(pathToTest + "/")) { //filter according to the path
BufferedImage bi = ImageIO.read(getClass().getResource("/tourma/images/flags/Country France.png"));
bi = ImageIO.read(getClass().getResource("/" + name));
if (bi == null) {
System.out.println("/" + name + " returns a null image");
} else {
ImageIcon ii = new ImageIcon(bi);
list.add(ii);
}
}
}
jar.close();
} else { // Run with IDE
try {
final URL url = getClass().getResource(path).toURI().toURL();
if (url != null) {
try {
final File apps = new File(url.toURI());
for (File app : apps.listFiles()) {
ImageIcon icon = new ImageIcon(app.getAbsolutePath());
list.add(icon);
}
} catch (URISyntaxException ex) {
// never happens
}
}
} catch (URISyntaxException ex) {
LOG.log(Level.WARNING, ex.getLocalizedMessage());
}
}
return list;
}

ImageIcon empty = new ImageIcon();
objects[listOfFiles.length] = empty;

JComboBox combo = new JComboBox(objects);
JPanel panel = new JPanel(new BorderLayout());
JLabel l = new JLabel(("Select picture"));
panel.add(l, BorderLayout.NORTH);
panel.add(combo, BorderLayout.CENTER);
private ImageIcon resize(ImageIcon image, int heigth, int width) {
Image img = image.getImage();
Image newimg = img.getScaledInstance(width, heigth, java.awt.Image.SCALE_SMOOTH);
return new ImageIcon(newimg);
}

combo.setSelectedItem(empty);
private void jbtAvatarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAvatarActionPerformed
try {
List<ImageIcon> listOfFiles = getImagesResources("/tourma/images/avatar");

JOptionPane.showConfirmDialog(null, panel, null, JOptionPane.YES_OPTION);
Object[] objects = new Object[listOfFiles.size() + 1];
for (int i = 0; i < listOfFiles.size(); i++) {
if (listOfFiles.get(i) != null) {
objects[i] = resize(listOfFiles.get(i), 80, 80);
}
}

if (combo.getSelectedItem() == empty) {
final JFileChooser jfc = new JFileChooser();
final FileFilter filter1 = new ExtensionFileFilter(java.util.ResourceBundle.getBundle("tourma/languages/language").getString("Picture"), new String[]{"PNG", "png", "JPG", "jpg", "GIF", "gif"});
jfc.setFileFilter(filter1);
if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
ImageIcon icon = new ImageIcon(jfc.getSelectedFile().getAbsolutePath());
icon = ImageTreatment.resize(icon, 80, 80);
ImageIcon empty = new ImageIcon();
objects[listOfFiles.size()] = empty;

JComboBox combo = new JComboBox(objects);
JPanel panel = new JPanel(new BorderLayout());
JLabel l = new JLabel(("Select picture"));
panel.add(l, BorderLayout.NORTH);
panel.add(combo, BorderLayout.CENTER);

combo.setSelectedItem(empty);

JOptionPane.showConfirmDialog(null, panel, null, JOptionPane.YES_OPTION);

if (combo.getSelectedItem() == empty) {
final JFileChooser jfc = new JFileChooser();
final FileFilter filter1 = new ExtensionFileFilter(java.util.ResourceBundle.getBundle("tourma/languages/language").getString("Picture"), new String[]{"PNG", "png", "JPG", "jpg", "GIF", "gif"});
jfc.setFileFilter(filter1);
if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
ImageIcon icon = new ImageIcon(jfc.getSelectedFile().getAbsolutePath());
icon = ImageTreatment.resize(icon, 80, 80);
this.mCoach.setPicture(new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB));
Graphics g = this.mCoach.getPicture().createGraphics();
// paint the Icon to the BufferedImage.
icon.paintIcon(null, g, 0, 0);
g.dispose();
}
} else {
ImageIcon icon = (ImageIcon) combo.getSelectedItem();
this.mCoach.setPicture(new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB));
Graphics g = this.mCoach.getPicture().createGraphics();
// paint the Icon to the BufferedImage.
icon.paintIcon(null, g, 0, 0);
g.dispose();
}
} else {
ImageIcon icon = (ImageIcon) combo.getSelectedItem();
this.mCoach.setPicture(new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB));
Graphics g = this.mCoach.getPicture().createGraphics();
// paint the Icon to the BufferedImage.
icon.paintIcon(null, g, 0, 0);
g.dispose();
}

jbtAvatar.setIcon(new ImageIcon(mCoach.getPicture()));
jbtAvatar.setIcon(new ImageIcon(mCoach.getPicture()));
} catch (IOException ex) {
LOG.log(Level.WARNING,ex.getLocalizedMessage());
}
}//GEN-LAST:event_jbtAvatarActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1;
Expand Down
4 changes: 2 additions & 2 deletions tourma/src/tourma/JdgRosters.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
package tourma;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
Expand Down Expand Up @@ -66,7 +66,7 @@ private void update() {
* regenerated by the Form Editor.
*/
@SuppressWarnings({"unchecked", "PMD"})
@SuppressFBWarnings({"SIC","Generated Code"})

// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

Expand Down
Loading

0 comments on commit 8293caf

Please sign in to comment.