From 2621e77449e7bbbddf5bd881535479fff849f882 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 22 Mar 2019 09:44:39 +0100 Subject: [PATCH 1/2] Formatage --- src/main/java/edu/mermet/tp8/Application.java | 101 +++++++++++------- .../tp8/fenetres/AbstractFenetreInterne.java | 18 ++-- .../mermet/tp8/fenetres/FenetreBoutons.java | 9 +- .../tp8/fenetres/FenetreConversion.java | 71 +++++++----- .../mermet/tp8/fenetres/FenetreDiaporama.java | 69 +++++++----- .../edu/mermet/tp8/fenetres/FenetreTexte.java | 60 ++++++----- 6 files changed, 201 insertions(+), 127 deletions(-) diff --git a/src/main/java/edu/mermet/tp8/Application.java b/src/main/java/edu/mermet/tp8/Application.java index 847fa3d..3ca3e1b 100644 --- a/src/main/java/edu/mermet/tp8/Application.java +++ b/src/main/java/edu/mermet/tp8/Application.java @@ -22,10 +22,10 @@ import edu.mermet.tp8.fenetres.FenetreDiaporama; import edu.mermet.tp8.fenetres.FenetreTexte; /** - * * @author brunomermet */ -public class Application extends JFrame { +public class Application extends JFrame +{ private JInternalFrame conversion; private JInternalFrame texte; private JInternalFrame diaporama; @@ -34,7 +34,9 @@ public class Application extends JFrame { private Action actionAfficherTexte; private Action actionAfficherDiaporama; private Action actionAfficherBoutons; - public Application() { + + public Application() + { super("multi-fenêtres"); this.setContentPane(new JDesktopPane()); @@ -44,9 +46,11 @@ public class Application extends JFrame { JMenu menuFichier = new JMenu("Fichier"); menuFichier.setMnemonic(KeyEvent.VK_F); JMenuItem quitter = new JMenuItem("Quitter"); - quitter.addActionListener (new ActionListener() { + quitter.addActionListener(new ActionListener() + { @Override - public void actionPerformed(ActionEvent aev) { + public void actionPerformed(ActionEvent aev) + { System.exit(0); } }); @@ -71,7 +75,7 @@ public class Application extends JFrame { menuApplication.add(itemBoutons); barre.add(menuApplication); // ****** Fin barre de menu ****** - + // ****** Création des fenêtres ****** // ------ fenêtre conversion ------ conversion = new FenetreConversion(actionAfficherConversion); @@ -83,101 +87,122 @@ public class Application extends JFrame { diaporama = new FenetreDiaporama(actionAfficherDiaporama); this.add(diaporama); // ------ fenêtre boutons ------ - boutons = new FenetreBoutons(this,actionAfficherBoutons); + boutons = new FenetreBoutons(this, actionAfficherBoutons); this.add(boutons); // ****** Fin création fenêtres ****** setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setSize(600,300); + setSize(600, 300); this.setLocationRelativeTo(null); setVisible(true); } - private class ActionAfficherBoutons extends AbstractAction { - public ActionAfficherBoutons() { + private class ActionAfficherBoutons extends AbstractAction + { + public ActionAfficherBoutons() + { super("Boutons"); - putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK)); - putValue(Action.MNEMONIC_KEY,KeyEvent.VK_B); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_B, InputEvent.CTRL_DOWN_MASK)); + putValue(Action.MNEMONIC_KEY, KeyEvent.VK_B); } @Override - public void actionPerformed(ActionEvent ae) { + public void actionPerformed(ActionEvent ae) + { boutons.setVisible(true); enableBoutons(false); } } - private class ActionAfficherDiaporama extends AbstractAction { - public ActionAfficherDiaporama() { + private class ActionAfficherDiaporama extends AbstractAction + { + public ActionAfficherDiaporama() + { super("Diaporama"); - putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK)); - putValue(Action.MNEMONIC_KEY,KeyEvent.VK_D); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK)); + putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D); } @Override - public void actionPerformed(ActionEvent ae) { + public void actionPerformed(ActionEvent ae) + { diaporama.setVisible(true); enableDiaporama(false); } } - private class ActionAfficherTexte extends AbstractAction { - public ActionAfficherTexte() { + private class ActionAfficherTexte extends AbstractAction + { + public ActionAfficherTexte() + { super("Saisie de texte"); - putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK)); - putValue(Action.MNEMONIC_KEY,KeyEvent.VK_T); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.CTRL_DOWN_MASK)); + putValue(Action.MNEMONIC_KEY, KeyEvent.VK_T); } @Override - public void actionPerformed(ActionEvent ae) { + public void actionPerformed(ActionEvent ae) + { texte.setVisible(true); enableTexte(false); } } - - public class ActionAfficherConversion extends AbstractAction { - public ActionAfficherConversion() { + + public class ActionAfficherConversion extends AbstractAction + { + public ActionAfficherConversion() + { super("Conversion Celsius/Farenheit"); - putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK)); - putValue(Action.MNEMONIC_KEY,KeyEvent.VK_C); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK)); + putValue(Action.MNEMONIC_KEY, KeyEvent.VK_C); } @Override - public void actionPerformed(ActionEvent ae) { + public void actionPerformed(ActionEvent ae) + { conversion.setVisible(true); enableConversion(false); } } - public void enableConversion(boolean b) { + public void enableConversion(boolean b) + { actionAfficherConversion.setEnabled(b); } - public void enableTexte(boolean b) { + public void enableTexte(boolean b) + { actionAfficherTexte.setEnabled(b); } - public void enableDiaporama(boolean b) { + public void enableDiaporama(boolean b) + { actionAfficherDiaporama.setEnabled(b); } - public void enableBoutons(boolean b) { + public void enableBoutons(boolean b) + { actionAfficherBoutons.setEnabled(b); } - public Action getActionAfficherConversion() { + public Action getActionAfficherConversion() + { return actionAfficherConversion; } - public Action getActionAfficherTexte() { + public Action getActionAfficherTexte() + { return actionAfficherTexte; } - public Action getActionAfficherDiaporama() { + public Action getActionAfficherDiaporama() + { return actionAfficherDiaporama; } - public static void main(String[] args) { + + public static void main(String[] args) + { SwingUtilities.invokeLater(Application::new); } - + } diff --git a/src/main/java/edu/mermet/tp8/fenetres/AbstractFenetreInterne.java b/src/main/java/edu/mermet/tp8/fenetres/AbstractFenetreInterne.java index f10fb32..bf7b570 100644 --- a/src/main/java/edu/mermet/tp8/fenetres/AbstractFenetreInterne.java +++ b/src/main/java/edu/mermet/tp8/fenetres/AbstractFenetreInterne.java @@ -6,22 +6,26 @@ import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; /** - * * @author brunomermet */ -public abstract class AbstractFenetreInterne extends JInternalFrame { +public abstract class AbstractFenetreInterne extends JInternalFrame +{ private Action action; - public AbstractFenetreInterne(Action monAction, String nom) { - super(nom, true,true,true,true); + + public AbstractFenetreInterne(Action monAction, String nom) + { + super(nom, true, true, true, true); action = monAction; this.setDefaultCloseOperation(HIDE_ON_CLOSE); this.addInternalFrameListener(new EcouteurFenetre()); } - - private class EcouteurFenetre extends InternalFrameAdapter { + + private class EcouteurFenetre extends InternalFrameAdapter + { @Override - public void internalFrameClosing(InternalFrameEvent ife) { + public void internalFrameClosing(InternalFrameEvent ife) + { action.setEnabled(true); } } diff --git a/src/main/java/edu/mermet/tp8/fenetres/FenetreBoutons.java b/src/main/java/edu/mermet/tp8/fenetres/FenetreBoutons.java index 13694b1..e500e53 100644 --- a/src/main/java/edu/mermet/tp8/fenetres/FenetreBoutons.java +++ b/src/main/java/edu/mermet/tp8/fenetres/FenetreBoutons.java @@ -15,17 +15,20 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; + import edu.mermet.tp8.Application; /** - * * @author brunomermet */ -public class FenetreBoutons extends AbstractFenetreInterne { +public class FenetreBoutons extends AbstractFenetreInterne +{ private JButton boutonTexte; private JButton boutonDiaporama; private JButton boutonDegres; - public FenetreBoutons(Application appli, Action action) { + + public FenetreBoutons(Application appli, Action action) + { super(action, "Boutons"); setLayout(new FlowLayout()); boutonTexte = new JButton(appli.getActionAfficherTexte()); diff --git a/src/main/java/edu/mermet/tp8/fenetres/FenetreConversion.java b/src/main/java/edu/mermet/tp8/fenetres/FenetreConversion.java index 2c134f4..0df1edb 100644 --- a/src/main/java/edu/mermet/tp8/fenetres/FenetreConversion.java +++ b/src/main/java/edu/mermet/tp8/fenetres/FenetreConversion.java @@ -15,22 +15,25 @@ import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; + import edu.mermet.tp8.Application; /** - * * @author brunomermet */ -public class FenetreConversion extends AbstractFenetreInterne { +public class FenetreConversion extends AbstractFenetreInterne +{ private JTextField champCelsius; private JTextField champFarenheit; private JButton boutonConvertir; private Action actionConvertir; private boolean celsiusAFocus; - public FenetreConversion(Action action) { - super(action,"Conversion celsius/Farenheit"); - this.setSize(new Dimension(100,50)); - this.setLayout(new GridLayout(3,1)); + + public FenetreConversion(Action action) + { + super(action, "Conversion celsius/Farenheit"); + this.setSize(new Dimension(100, 50)); + this.setLayout(new GridLayout(3, 1)); JPanel ligneCelsius = new JPanel(); ligneCelsius.setLayout(new FlowLayout(FlowLayout.TRAILING)); JLabel labCelsius = new JLabel("Celsius :"); @@ -56,61 +59,71 @@ public class FenetreConversion extends AbstractFenetreInterne { boutonConvertir = new JButton(actionConvertir); ligneValider.add(boutonConvertir); this.add(ligneValider); - + pack(); getRootPane().setDefaultButton(boutonConvertir); } - private class EcouteurFocus implements FocusListener { + private class EcouteurFocus implements FocusListener + { private boolean aStocker; - public EcouteurFocus(boolean b) { + public EcouteurFocus(boolean b) + { aStocker = b; } @Override - public void focusGained(FocusEvent fe) { + public void focusGained(FocusEvent fe) + { celsiusAFocus = aStocker; } @Override - public void focusLost(FocusEvent fe) { + public void focusLost(FocusEvent fe) + { return; } } - private class ActionConvertir extends AbstractAction { + private class ActionConvertir extends AbstractAction + { - public ActionConvertir() { + public ActionConvertir() + { super("Convertir"); } @Override - public void actionPerformed(ActionEvent ae) { + public void actionPerformed(ActionEvent ae) + { double tempCelsius = 0; double tempFarenheit = 0; - if (celsiusAFocus) { - try { + if (celsiusAFocus) + { + try + { tempCelsius = Double.parseDouble(champCelsius.getText()); - tempFarenheit = 9./5*tempCelsius+32; - champFarenheit.setText(""+tempFarenheit); - } - catch (NumberFormatException nfe) { + tempFarenheit = 9. / 5 * tempCelsius + 32; + champFarenheit.setText("" + tempFarenheit); + } catch (NumberFormatException nfe) + { champFarenheit.setText("Format incorrect"); } - } - else { - try { + } else + { + try + { tempFarenheit = Double.parseDouble(champFarenheit.getText()); - tempCelsius = (tempFarenheit - 32) *5./9; - champCelsius.setText(""+tempCelsius); - } - catch (NumberFormatException nfe) { + tempCelsius = (tempFarenheit - 32) * 5. / 9; + champCelsius.setText("" + tempCelsius); + } catch (NumberFormatException nfe) + { champCelsius.setText("Format incorrect"); } - + } } } - + } diff --git a/src/main/java/edu/mermet/tp8/fenetres/FenetreDiaporama.java b/src/main/java/edu/mermet/tp8/fenetres/FenetreDiaporama.java index 9f0f6b8..ea10ae1 100644 --- a/src/main/java/edu/mermet/tp8/fenetres/FenetreDiaporama.java +++ b/src/main/java/edu/mermet/tp8/fenetres/FenetreDiaporama.java @@ -15,28 +15,32 @@ import javax.swing.JScrollPane; import javax.swing.JTextArea; /** - * * @author brunomermet */ -public class FenetreDiaporama extends AbstractFenetreInterne { - ImageIcon [] images; +public class FenetreDiaporama extends AbstractFenetreInterne +{ + ImageIcon[] images; String[] textes; JLabel affichage; Defilement defilement; private int indiceCourant = 0; - public FenetreDiaporama(Action action) { - super(action,"Diaporama"); + + public FenetreDiaporama(Action action) + { + super(action, "Diaporama"); images = new ImageIcon[3]; - try { + try + { images[0] = new ImageIcon(new ImageIcon(new URL("http://bruno.mermet.pagesperso-orange.fr/Personnel/Anes/Randos/TourDeLaHague/10bocage.jpg")).getImage().getScaledInstance(300, -1, Image.SCALE_DEFAULT)); images[1] = new ImageIcon(new ImageIcon(new URL("http://bruno.mermet.pagesperso-orange.fr/Personnel/Anes/Randos/TourDeLaHague/12baieEcalgrain.jpg")).getImage().getScaledInstance(300, -1, Image.SCALE_DEFAULT)); images[2] = new ImageIcon(new ImageIcon(new URL("http://bruno.mermet.pagesperso-orange.fr/Personnel/Anes/Randos/TourDeLaHague/15cote.jpg")).getImage().getScaledInstance(300, -1, Image.SCALE_DEFAULT)); - } catch (MalformedURLException ex) { + } catch (MalformedURLException ex) + { images[0] = null; images[1] = null; images[2] = null; } - + JPanel panneauTexte = new JPanel(); /*textes = new String[3]; textes[0] = "bonjour"; @@ -45,47 +49,60 @@ public class FenetreDiaporama extends AbstractFenetreInterne { affichage = new JLabel(); panneauTexte.add(affichage); affichage.setIcon(images[0]); - // affichage.setText(textes[0]); + // affichage.setText(textes[0]); JScrollPane ascenseurs = new JScrollPane(affichage); - add(ascenseurs,BorderLayout.CENTER); + add(ascenseurs, BorderLayout.CENTER); //add(panneauTexte,BorderLayout.CENTER); - setSize(300,300); + setSize(300, 300); //pack(); - + } - class Defilement implements Runnable { + + class Defilement implements Runnable + { private boolean arrete; - public Defilement() { + + public Defilement() + { arrete = false; } + @Override - public void run() { - while (!arrete) { - try { + public void run() + { + while (!arrete) + { + try + { Thread.sleep(2000); - } - catch (InterruptedException iex) { + } catch (InterruptedException iex) + { } indiceCourant++; indiceCourant = indiceCourant % 3; affichage.setIcon(images[indiceCourant]); } } - public void arreter() { + + public void arreter() + { arrete = true; } } - + @Override - public void setVisible(boolean b) { + public void setVisible(boolean b) + { super.setVisible(b); - if (b) { + if (b) + { defilement = new Defilement(); Thread thread = new Thread(defilement); thread.start(); - } - else { - if (defilement != null) { + } else + { + if (defilement != null) + { defilement.arreter(); } } diff --git a/src/main/java/edu/mermet/tp8/fenetres/FenetreTexte.java b/src/main/java/edu/mermet/tp8/fenetres/FenetreTexte.java index 6d19145..4ea2f1c 100644 --- a/src/main/java/edu/mermet/tp8/fenetres/FenetreTexte.java +++ b/src/main/java/edu/mermet/tp8/fenetres/FenetreTexte.java @@ -23,19 +23,22 @@ import javax.swing.JTextArea; import javax.swing.KeyStroke; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; + import edu.mermet.tp8.Application; /** - * * @author brunomermet */ -public class FenetreTexte extends AbstractFenetreInterne { +public class FenetreTexte extends AbstractFenetreInterne +{ private JCheckBox gras; private JCheckBox rouge; private Action actionGras; private Action actionRouge; private JTextArea texte; - public FenetreTexte(Action action) { + + public FenetreTexte(Action action) + { super(action, "Texte"); actionGras = new ActionGras(); gras = new JCheckBox(actionGras); @@ -44,12 +47,12 @@ public class FenetreTexte extends AbstractFenetreInterne { JPanel panneauBouton = new JPanel(); panneauBouton.add(gras); panneauBouton.add(rouge); - add(panneauBouton,BorderLayout.NORTH); - texte = new JTextArea(6,20); + add(panneauBouton, BorderLayout.NORTH); + texte = new JTextArea(6, 20); texte.setLineWrap(true); texte.setWrapStyleWord(true); JScrollPane panneauTexte = new JScrollPane(texte); - add(panneauTexte,BorderLayout.CENTER); + add(panneauTexte, BorderLayout.CENTER); JMenuBar barre = new JMenuBar(); JMenu style = new JMenu("Style"); style.add(new JMenuItem(actionGras)); @@ -59,49 +62,58 @@ public class FenetreTexte extends AbstractFenetreInterne { pack(); } - - private class ActionGras extends AbstractAction { + private class ActionGras extends AbstractAction + { private boolean gras; - public ActionGras() { + + public ActionGras() + { super("gras"); gras = false; - putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK)); - putValue(Action.SELECTED_KEY,false); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK)); + putValue(Action.SELECTED_KEY, false); } @Override - public void actionPerformed(ActionEvent ae) { + public void actionPerformed(ActionEvent ae) + { Font police = texte.getFont(); - if (!gras) { + if (!gras) + { police = police.deriveFont(Font.BOLD);//|Font.ITALIC); //police = police.deriveFont((float)24.0); - } - else { + } else + { police = police.deriveFont(Font.PLAIN); } gras = !gras; - putValue(Action.SELECTED_KEY,gras); + putValue(Action.SELECTED_KEY, gras); texte.setFont(police); } } - private class ActionRouge extends AbstractAction { + private class ActionRouge extends AbstractAction + { private boolean rouge; - public ActionRouge() { + + public ActionRouge() + { super("rouge"); rouge = false; - putValue(Action.ACCELERATOR_KEY,KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK)); - putValue(Action.SELECTED_KEY,false); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK)); + putValue(Action.SELECTED_KEY, false); } @Override - public void actionPerformed(ActionEvent ae) { - if (!rouge) { + public void actionPerformed(ActionEvent ae) + { + if (!rouge) + { texte.setForeground(Color.RED); - } - else { + } else + { texte.setForeground(Color.BLACK); } rouge = !rouge; -- GitLab From 8c80388bc57cbbe920d9c6438f677030429a8589 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 22 Mar 2019 09:54:26 +0100 Subject: [PATCH 2/2] Ajout du menu d'aide --- .gitignore | 1 + src/main/java/edu/mermet/tp8/Application.java | 7 +++++++ tp8ihm.iml | 15 +++++++++++++++ 3 files changed, 23 insertions(+) create mode 100755 tp8ihm.iml diff --git a/.gitignore b/.gitignore index 2f7896d..96ef862 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ target/ +.idea/ diff --git a/src/main/java/edu/mermet/tp8/Application.java b/src/main/java/edu/mermet/tp8/Application.java index 3ca3e1b..1df564d 100644 --- a/src/main/java/edu/mermet/tp8/Application.java +++ b/src/main/java/edu/mermet/tp8/Application.java @@ -74,6 +74,13 @@ public class Application extends JFrame JMenuItem itemBoutons = new JMenuItem(actionAfficherBoutons); menuApplication.add(itemBoutons); barre.add(menuApplication); + // ------ menu Aide ------ + JMenu menuAide = new JMenu("Aide"); + JMenuItem itemHowTo = new JMenuItem("Comment Faire ?"); + JMenuItem itemConfig = new JMenuItem("Configuration des menus"); + menuAide.add(itemHowTo); + menuAide.add(itemConfig); + barre.add(menuAide); // ****** Fin barre de menu ****** // ****** Création des fenêtres ****** diff --git a/tp8ihm.iml b/tp8ihm.iml new file mode 100755 index 0000000..650f2be --- /dev/null +++ b/tp8ihm.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file -- GitLab