diff --git a/.gitignore b/.gitignore index 2f7896d1d1365eafb0da03d9fe456fac81408487..c495c1ec3fd1e7cfe0506cc267ba6884af92410a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ target/ + +*.class \ No newline at end of file diff --git a/src/main/java/edu/mermet/tp8/Application.java b/src/main/java/edu/mermet/tp8/Application.java deleted file mode 100644 index 847fa3ddb179764b4c6a417645ed147cc006b817..0000000000000000000000000000000000000000 --- a/src/main/java/edu/mermet/tp8/Application.java +++ /dev/null @@ -1,183 +0,0 @@ -package edu.mermet.tp8; - - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JDesktopPane; -import javax.swing.JFrame; -import javax.swing.JInternalFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.KeyStroke; -import javax.swing.SwingUtilities; - -import edu.mermet.tp8.fenetres.FenetreBoutons; -import edu.mermet.tp8.fenetres.FenetreConversion; -import edu.mermet.tp8.fenetres.FenetreDiaporama; -import edu.mermet.tp8.fenetres.FenetreTexte; - -/** - * - * @author brunomermet - */ -public class Application extends JFrame { - private JInternalFrame conversion; - private JInternalFrame texte; - private JInternalFrame diaporama; - private JInternalFrame boutons; - private Action actionAfficherConversion; - private Action actionAfficherTexte; - private Action actionAfficherDiaporama; - private Action actionAfficherBoutons; - public Application() { - super("multi-fenêtres"); - this.setContentPane(new JDesktopPane()); - - // ****** Barre de menu ****** - JMenuBar barre = new JMenuBar(); - // ------ menu Fichier ------ - JMenu menuFichier = new JMenu("Fichier"); - menuFichier.setMnemonic(KeyEvent.VK_F); - JMenuItem quitter = new JMenuItem("Quitter"); - quitter.addActionListener (new ActionListener() { - @Override - public void actionPerformed(ActionEvent aev) { - System.exit(0); - } - }); - quitter.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK)); - menuFichier.add(quitter); - barre.add(menuFichier); - this.setJMenuBar(barre); - // ------ menu Applications ------ - JMenu menuApplication = new JMenu("Applications"); - menuApplication.setMnemonic(KeyEvent.VK_A); - actionAfficherConversion = new ActionAfficherConversion(); - JMenuItem itemConversion = new JMenuItem(actionAfficherConversion); - menuApplication.add(itemConversion); - actionAfficherTexte = new ActionAfficherTexte(); - JMenuItem itemTexte = new JMenuItem(actionAfficherTexte); - menuApplication.add(itemTexte); - actionAfficherDiaporama = new ActionAfficherDiaporama(); - JMenuItem itemDiaporama = new JMenuItem(actionAfficherDiaporama); - menuApplication.add(itemDiaporama); - actionAfficherBoutons = new ActionAfficherBoutons(); - JMenuItem itemBoutons = new JMenuItem(actionAfficherBoutons); - menuApplication.add(itemBoutons); - barre.add(menuApplication); - // ****** Fin barre de menu ****** - - // ****** Création des fenêtres ****** - // ------ fenêtre conversion ------ - conversion = new FenetreConversion(actionAfficherConversion); - this.add(conversion); - // ------ fenêtre texte ------ - texte = new FenetreTexte(actionAfficherTexte); - this.add(texte); - // ------ fenêtre diaporama ------ - diaporama = new FenetreDiaporama(actionAfficherDiaporama); - this.add(diaporama); - // ------ fenêtre boutons ------ - boutons = new FenetreBoutons(this,actionAfficherBoutons); - this.add(boutons); - // ****** Fin création fenêtres ****** - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setSize(600,300); - this.setLocationRelativeTo(null); - setVisible(true); - } - - 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); - } - - @Override - public void actionPerformed(ActionEvent ae) { - boutons.setVisible(true); - enableBoutons(false); - } - } - - 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); - } - - @Override - public void actionPerformed(ActionEvent ae) { - diaporama.setVisible(true); - enableDiaporama(false); - } - } - - 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); - } - - @Override - public void actionPerformed(ActionEvent ae) { - texte.setVisible(true); - enableTexte(false); - } - } - - 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); - } - - @Override - public void actionPerformed(ActionEvent ae) { - conversion.setVisible(true); - enableConversion(false); - } - } - - public void enableConversion(boolean b) { - actionAfficherConversion.setEnabled(b); - } - - public void enableTexte(boolean b) { - actionAfficherTexte.setEnabled(b); - } - - public void enableDiaporama(boolean b) { - actionAfficherDiaporama.setEnabled(b); - } - - public void enableBoutons(boolean b) { - actionAfficherBoutons.setEnabled(b); - } - - public Action getActionAfficherConversion() { - return actionAfficherConversion; - } - - public Action getActionAfficherTexte() { - return actionAfficherTexte; - } - - public Action getActionAfficherDiaporama() { - return actionAfficherDiaporama; - } - 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 deleted file mode 100644 index f10fb3246114d9dd53b123900df6c553d607642d..0000000000000000000000000000000000000000 --- a/src/main/java/edu/mermet/tp8/fenetres/AbstractFenetreInterne.java +++ /dev/null @@ -1,28 +0,0 @@ -package edu.mermet.tp8.fenetres; - -import javax.swing.Action; -import javax.swing.JInternalFrame; -import javax.swing.event.InternalFrameAdapter; -import javax.swing.event.InternalFrameEvent; - -/** - * - * @author brunomermet - */ -public abstract class AbstractFenetreInterne extends JInternalFrame { - private Action action; - 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 { - @Override - 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 deleted file mode 100644 index 13694b1808e542acb51ee01070bcbdf6fb95469f..0000000000000000000000000000000000000000 --- a/src/main/java/edu/mermet/tp8/fenetres/FenetreBoutons.java +++ /dev/null @@ -1,40 +0,0 @@ -package edu.mermet.tp8.fenetres; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.FlowLayout; -import java.awt.Font; -import java.awt.event.ActionEvent; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JInternalFrame; -import javax.swing.JPanel; -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 { - private JButton boutonTexte; - private JButton boutonDiaporama; - private JButton boutonDegres; - public FenetreBoutons(Application appli, Action action) { - super(action, "Boutons"); - setLayout(new FlowLayout()); - boutonTexte = new JButton(appli.getActionAfficherTexte()); - boutonDiaporama = new JButton(appli.getActionAfficherDiaporama()); - boutonDegres = new JButton(appli.getActionAfficherConversion()); - add(boutonDegres); - add(boutonTexte); - add(boutonDiaporama); - pack(); - } - -} diff --git a/src/main/java/edu/mermet/tp8/fenetres/FenetreConversion.java b/src/main/java/edu/mermet/tp8/fenetres/FenetreConversion.java deleted file mode 100644 index 2c134f4584194e6f5e3e038f09b040722121f4e3..0000000000000000000000000000000000000000 --- a/src/main/java/edu/mermet/tp8/fenetres/FenetreConversion.java +++ /dev/null @@ -1,116 +0,0 @@ -package edu.mermet.tp8.fenetres; - -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JInternalFrame; -import javax.swing.JLabel; -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 { - 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)); - JPanel ligneCelsius = new JPanel(); - ligneCelsius.setLayout(new FlowLayout(FlowLayout.TRAILING)); - JLabel labCelsius = new JLabel("Celsius :"); - champCelsius = new JTextField(15); - labCelsius.setLabelFor(champCelsius); - ligneCelsius.add(labCelsius); - ligneCelsius.add(champCelsius); - this.add(ligneCelsius); - celsiusAFocus = true; - champCelsius.addFocusListener(new EcouteurFocus(true)); - JPanel ligneFarenheit = new JPanel(); - ligneFarenheit.setLayout(new FlowLayout(FlowLayout.TRAILING)); - JLabel labFarenheit = new JLabel("Farenheit :"); - champFarenheit = new JTextField(15); - labFarenheit.setLabelFor(champFarenheit); - ligneFarenheit.add(labFarenheit); - ligneFarenheit.add(champFarenheit); - this.add(ligneFarenheit); - champFarenheit.addFocusListener(new EcouteurFocus(false)); - JPanel ligneValider = new JPanel(); - ligneValider.setLayout(new FlowLayout(FlowLayout.CENTER)); - actionConvertir = new ActionConvertir(); - boutonConvertir = new JButton(actionConvertir); - ligneValider.add(boutonConvertir); - this.add(ligneValider); - - pack(); - getRootPane().setDefaultButton(boutonConvertir); - } - - private class EcouteurFocus implements FocusListener { - private boolean aStocker; - - public EcouteurFocus(boolean b) { - aStocker = b; - } - - @Override - public void focusGained(FocusEvent fe) { - celsiusAFocus = aStocker; - } - - @Override - public void focusLost(FocusEvent fe) { - return; - } - } - - private class ActionConvertir extends AbstractAction { - - public ActionConvertir() { - super("Convertir"); - } - - @Override - public void actionPerformed(ActionEvent ae) { - double tempCelsius = 0; - double tempFarenheit = 0; - if (celsiusAFocus) { - try { - tempCelsius = Double.parseDouble(champCelsius.getText()); - tempFarenheit = 9./5*tempCelsius+32; - champFarenheit.setText(""+tempFarenheit); - } - catch (NumberFormatException nfe) { - champFarenheit.setText("Format incorrect"); - } - } - else { - try { - tempFarenheit = Double.parseDouble(champFarenheit.getText()); - 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 deleted file mode 100644 index 9f0f6b856f7da6f4e128dd1179836fe9009e3e31..0000000000000000000000000000000000000000 --- a/src/main/java/edu/mermet/tp8/fenetres/FenetreDiaporama.java +++ /dev/null @@ -1,93 +0,0 @@ -package edu.mermet.tp8.fenetres; - -import java.awt.BorderLayout; -import java.awt.Image; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.Action; -import javax.swing.ImageIcon; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; - -/** - * - * @author brunomermet - */ -public class FenetreDiaporama extends AbstractFenetreInterne { - ImageIcon [] images; - String[] textes; - JLabel affichage; - Defilement defilement; - private int indiceCourant = 0; - public FenetreDiaporama(Action action) { - super(action,"Diaporama"); - images = new ImageIcon[3]; - 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) { - images[0] = null; - images[1] = null; - images[2] = null; - } - - JPanel panneauTexte = new JPanel(); - /*textes = new String[3]; - textes[0] = "bonjour"; - textes[1] = "le"; - textes[2] = "monde";*/ - affichage = new JLabel(); - panneauTexte.add(affichage); - affichage.setIcon(images[0]); - // affichage.setText(textes[0]); - JScrollPane ascenseurs = new JScrollPane(affichage); - add(ascenseurs,BorderLayout.CENTER); - //add(panneauTexte,BorderLayout.CENTER); - setSize(300,300); - //pack(); - - } - class Defilement implements Runnable { - private boolean arrete; - public Defilement() { - arrete = false; - } - @Override - public void run() { - while (!arrete) { - try { - Thread.sleep(2000); - } - catch (InterruptedException iex) { - } - indiceCourant++; - indiceCourant = indiceCourant % 3; - affichage.setIcon(images[indiceCourant]); - } - } - public void arreter() { - arrete = true; - } - } - - @Override - public void setVisible(boolean b) { - super.setVisible(b); - if (b) { - defilement = new Defilement(); - Thread thread = new Thread(defilement); - thread.start(); - } - 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 deleted file mode 100644 index 6d1914590bff5efc2cfd1d13b61aea50f62274ec..0000000000000000000000000000000000000000 --- a/src/main/java/edu/mermet/tp8/fenetres/FenetreTexte.java +++ /dev/null @@ -1,111 +0,0 @@ -package edu.mermet.tp8.fenetres; - -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.beans.PropertyVetoException; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JCheckBox; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JInternalFrame; -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -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 { - private JCheckBox gras; - private JCheckBox rouge; - private Action actionGras; - private Action actionRouge; - private JTextArea texte; - public FenetreTexte(Action action) { - super(action, "Texte"); - actionGras = new ActionGras(); - gras = new JCheckBox(actionGras); - actionRouge = new ActionRouge(); - rouge = new JCheckBox(actionRouge); - JPanel panneauBouton = new JPanel(); - panneauBouton.add(gras); - panneauBouton.add(rouge); - add(panneauBouton,BorderLayout.NORTH); - texte = new JTextArea(6,20); - texte.setLineWrap(true); - texte.setWrapStyleWord(true); - JScrollPane panneauTexte = new JScrollPane(texte); - add(panneauTexte,BorderLayout.CENTER); - JMenuBar barre = new JMenuBar(); - JMenu style = new JMenu("Style"); - style.add(new JMenuItem(actionGras)); - style.add(new JCheckBoxMenuItem(actionRouge)); - barre.add(style); - this.setJMenuBar(barre); - pack(); - } - - - - private class ActionGras extends AbstractAction { - private boolean gras; - public ActionGras() { - super("gras"); - gras = 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) { - Font police = texte.getFont(); - if (!gras) { - police = police.deriveFont(Font.BOLD);//|Font.ITALIC); - //police = police.deriveFont((float)24.0); - } - else { - police = police.deriveFont(Font.PLAIN); - } - gras = !gras; - putValue(Action.SELECTED_KEY,gras); - texte.setFont(police); - } - } - - private class ActionRouge extends AbstractAction { - private boolean rouge; - public ActionRouge() { - super("rouge"); - rouge = 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) { - texte.setForeground(Color.RED); - } - else { - texte.setForeground(Color.BLACK); - } - rouge = !rouge; - //putValue(Action.SELECTED_KEY,rouge); - } - } -} diff --git a/src/tp8/Application.java b/src/tp8/Application.java new file mode 100644 index 0000000000000000000000000000000000000000..193442e508d353ceb945b257e583b0d7c172f3ac --- /dev/null +++ b/src/tp8/Application.java @@ -0,0 +1,242 @@ +package tp8; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JDesktopPane; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.KeyStroke; +import javax.swing.SwingUtilities; + +import tp8.fenetres.FenetreBoutons; +import tp8.fenetres.FenetreConversion; +import tp8.fenetres.FenetreDiaporama; +import tp8.fenetres.FenetreTexte; +import tp8.fenetres.FenetreCommentFaire; +import tp8.fenetres.FenetreConfig; + +/** + * + * @author brunomermet + */ +public class Application extends JFrame { + private JInternalFrame conversion; + private JInternalFrame texte; + private JInternalFrame diaporama; + private JInternalFrame boutons; + private JInternalFrame commentFaire; + private JInternalFrame config; + private Action actionAfficherConversion; + private Action actionAfficherTexte; + private Action actionAfficherDiaporama; + private Action actionAfficherBoutons; + private Action actionAfficherCommentFaire; + private Action actionAfficherConfig; + + public Application() { + super("multi-fenêtres"); + this.setContentPane(new JDesktopPane()); + + // ****** Barre de menu ****** + JMenuBar barre = new JMenuBar(); + // ------ menu Fichier ------ + JMenu menuFichier = new JMenu("Fichier"); + menuFichier.setMnemonic(KeyEvent.VK_F); + JMenuItem quitter = new JMenuItem("Quitter"); + quitter.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent aev) { + System.exit(0); + } + }); + quitter.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK)); + menuFichier.add(quitter); + barre.add(menuFichier); + this.setJMenuBar(barre); + // ------ menu Applications ------ + JMenu menuApplication = new JMenu("Applications"); + menuApplication.setMnemonic(KeyEvent.VK_A); + actionAfficherConversion = new ActionAfficherConversion(); + JMenuItem itemConversion = new JMenuItem(actionAfficherConversion); + menuApplication.add(itemConversion); + actionAfficherTexte = new ActionAfficherTexte(); + JMenuItem itemTexte = new JMenuItem(actionAfficherTexte); + menuApplication.add(itemTexte); + actionAfficherDiaporama = new ActionAfficherDiaporama(); + JMenuItem itemDiaporama = new JMenuItem(actionAfficherDiaporama); + menuApplication.add(itemDiaporama); + actionAfficherBoutons = new ActionAfficherBoutons(); + JMenuItem itemBoutons = new JMenuItem(actionAfficherBoutons); + menuApplication.add(itemBoutons); + barre.add(menuApplication); + + // ------ menu Aide ------ + JMenu menuAide = new JMenu("Aide"); + menuAide.setMnemonic(KeyEvent.VK_M); + actionAfficherCommentFaire = new ActionAfficherCommentFaire(); + JMenuItem itemCommentFaire = new JMenuItem(actionAfficherCommentFaire); + menuAide.add(itemCommentFaire); + actionAfficherConfig = new ActionAfficherConfig(); + JMenuItem itemConfig = new JMenuItem(actionAfficherConfig); + menuAide.add(itemConfig); + barre.add(menuAide); + // ****** Fin barre de menu ****** + + // ****** Création des fenêtres ****** + // ------ fenêtre conversion ------ + conversion = new FenetreConversion(actionAfficherConversion); + this.add(conversion); + // ------ fenêtre texte ------ + texte = new FenetreTexte(actionAfficherTexte); + this.add(texte); + // ------ fenêtre diaporama ------ + diaporama = new FenetreDiaporama(actionAfficherDiaporama); + this.add(diaporama); + // ------ fenêtre boutons ------ + boutons = new FenetreBoutons(this, actionAfficherBoutons); + this.add(boutons); + // ------ fenêtre commentFaire ------ + commentFaire = new FenetreCommentFaire(actionAfficherCommentFaire); + this.add(commentFaire); + // ------ fenêtre configuration ------ + config = new FenetreConfig(actionAfficherConfig); + this.add(config); + // ****** Fin création fenêtres ****** + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(600, 300); + this.setLocationRelativeTo(null); + setVisible(true); + } + + 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); + } + + @Override + public void actionPerformed(ActionEvent ae) { + boutons.setVisible(true); + enableBoutons(false); + } + } + + 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); + } + + @Override + public void actionPerformed(ActionEvent ae) { + diaporama.setVisible(true); + enableDiaporama(false); + } + } + + 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); + } + + @Override + public void actionPerformed(ActionEvent ae) { + texte.setVisible(true); + enableTexte(false); + } + } + + 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); + } + + @Override + public void actionPerformed(ActionEvent ae) { + conversion.setVisible(true); + enableConversion(false); + } + } + + public class ActionAfficherCommentFaire extends AbstractAction { + public ActionAfficherCommentFaire() { + super("Comment faire ?"); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_DOWN_MASK)); + putValue(Action.MNEMONIC_KEY, KeyEvent.VK_U); + } + + @Override + public void actionPerformed(ActionEvent ae) { + commentFaire.setVisible(true); + enableCommentFaire(false); + } + } + + public class ActionAfficherConfig extends AbstractAction { + public ActionAfficherConfig() { + super("Configuration des menus"); + putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_J, InputEvent.CTRL_DOWN_MASK)); + putValue(Action.MNEMONIC_KEY, KeyEvent.VK_J); + } + + @Override + public void actionPerformed(ActionEvent ae) { + config.setVisible(true); + enableConfig(false); + } + } + + public void enableConversion(boolean b) { + actionAfficherConversion.setEnabled(b); + } + + public void enableTexte(boolean b) { + actionAfficherTexte.setEnabled(b); + } + + public void enableDiaporama(boolean b) { + actionAfficherDiaporama.setEnabled(b); + } + + public void enableBoutons(boolean b) { + actionAfficherBoutons.setEnabled(b); + } + + public void enableCommentFaire(boolean b) { + actionAfficherCommentFaire.setEnabled(b); + } + + public void enableConfig(boolean b) { + actionAfficherConfig.setEnabled(b); + } + + public Action getActionAfficherConversion() { + return actionAfficherConversion; + } + + public Action getActionAfficherTexte() { + return actionAfficherTexte; + } + + public Action getActionAfficherDiaporama() { + return actionAfficherDiaporama; + } + + public static void main(String[] args) { + SwingUtilities.invokeLater(Application::new); + } + +} diff --git a/src/tp8/fenetres/AbstractFenetreInterne.java b/src/tp8/fenetres/AbstractFenetreInterne.java new file mode 100644 index 0000000000000000000000000000000000000000..6da3d9e5754a571a3bd8705158e6724a367635da --- /dev/null +++ b/src/tp8/fenetres/AbstractFenetreInterne.java @@ -0,0 +1,29 @@ +package tp8.fenetres; + +import javax.swing.Action; +import javax.swing.JInternalFrame; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; + +/** + * + * @author brunomermet + */ +public abstract class AbstractFenetreInterne extends JInternalFrame { + private Action action; + + 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 { + @Override + public void internalFrameClosing(InternalFrameEvent ife) { + action.setEnabled(true); + } + } +} diff --git a/src/tp8/fenetres/FenetreBoutons.java b/src/tp8/fenetres/FenetreBoutons.java new file mode 100644 index 0000000000000000000000000000000000000000..b2155c26dfff42671a788c45d4af318c8024d961 --- /dev/null +++ b/src/tp8/fenetres/FenetreBoutons.java @@ -0,0 +1,41 @@ +package tp8.fenetres; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.event.ActionEvent; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JInternalFrame; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; +import tp8.Application; + +/** + * + * @author brunomermet + */ +public class FenetreBoutons extends AbstractFenetreInterne { + private JButton boutonTexte; + private JButton boutonDiaporama; + private JButton boutonDegres; + + public FenetreBoutons(Application appli, Action action) { + super(action, "Boutons"); + setLayout(new FlowLayout()); + boutonTexte = new JButton(appli.getActionAfficherTexte()); + boutonDiaporama = new JButton(appli.getActionAfficherDiaporama()); + boutonDegres = new JButton(appli.getActionAfficherConversion()); + add(boutonDegres); + add(boutonTexte); + add(boutonDiaporama); + pack(); + } + +} diff --git a/src/tp8/fenetres/FenetreCommentFaire.java b/src/tp8/fenetres/FenetreCommentFaire.java new file mode 100644 index 0000000000000000000000000000000000000000..20a146acdf4157e9535b79e67f28af662cb532d9 --- /dev/null +++ b/src/tp8/fenetres/FenetreCommentFaire.java @@ -0,0 +1,110 @@ +package tp8.fenetres; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.beans.PropertyVetoException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JCheckBox; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JInternalFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.KeyStroke; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; +import tp8.Application; + +/** + * + * @author brunomermet + */ +public class FenetreCommentFaire extends AbstractFenetreInterne { + private JCheckBox gras; + private JCheckBox rouge; + private Action actionGras; + private Action actionRouge; + private JTextArea texte; + + public FenetreCommentFaire(Action action) { + super(action, "Comment faire ?"); + actionGras = new ActionGras(); + gras = new JCheckBox(actionGras); + actionRouge = new ActionRouge(); + rouge = new JCheckBox(actionRouge); + JPanel panneauBouton = new JPanel(); + panneauBouton.add(gras); + panneauBouton.add(rouge); + add(panneauBouton, BorderLayout.NORTH); + texte = new JTextArea(6, 20); + texte.setLineWrap(true); + texte.setWrapStyleWord(true); + JScrollPane panneauTexte = new JScrollPane(texte); + add(panneauTexte, BorderLayout.CENTER); + JMenuBar barre = new JMenuBar(); + JMenu style = new JMenu("Style"); + style.add(new JMenuItem(actionGras)); + style.add(new JCheckBoxMenuItem(actionRouge)); + barre.add(style); + this.setJMenuBar(barre); + pack(); + } + + private class ActionGras extends AbstractAction { + private boolean gras; + + public ActionGras() { + super("gras"); + gras = 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) { + Font police = texte.getFont(); + if (!gras) { + police = police.deriveFont(Font.BOLD);// |Font.ITALIC); + // police = police.deriveFont((float)24.0); + } else { + police = police.deriveFont(Font.PLAIN); + } + gras = !gras; + putValue(Action.SELECTED_KEY, gras); + texte.setFont(police); + } + } + + private class ActionRouge extends AbstractAction { + private boolean rouge; + + public ActionRouge() { + super("rouge"); + rouge = 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) { + texte.setForeground(Color.RED); + } else { + texte.setForeground(Color.BLACK); + } + rouge = !rouge; + // putValue(Action.SELECTED_KEY,rouge); + } + } +} diff --git a/src/tp8/fenetres/FenetreConfig.java b/src/tp8/fenetres/FenetreConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..3de5992ac448ad0323a7ee11710c4d741ebfde21 --- /dev/null +++ b/src/tp8/fenetres/FenetreConfig.java @@ -0,0 +1,144 @@ +package tp8.fenetres; + +import java.awt.BorderLayout; +import java.awt.GridLayout; +import java.awt.FlowLayout; +import java.awt.Color; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.beans.PropertyVetoException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.ButtonGroup; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.KeyStroke; +import javax.swing.SwingConstants; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; +import tp8.Application; + +/** + * + * @author brunomermet + */ +public class FenetreConfig extends AbstractFenetreInterne { + private JPanel panelLabel, panelConfig, panelButtons; + + private JLabel labelConv; + private JLabel labelSaisie; + private JLabel labelDiapo; + private JLabel labelButton; + + private ButtonGroup groupConv; + private JRadioButton autoConv, afficheConv, cacheConv; + + private ButtonGroup groupSaisie; + private JRadioButton autoSaisie, afficheSaisie, cacheSaisie; + + private ButtonGroup groupDiapo; + private JRadioButton autoDiapo, afficheDiapo, cacheDiapo; + + private ButtonGroup groupButton; + private JRadioButton autoButton, afficheButton, cacheButton; + + private JButton valider, annuler; + + public FenetreConfig(Action action) { + super(action, "Configuration des menus"); + + this.panelLabel = new JPanel( new GridLayout(4, 1) ); + this.panelConfig = new JPanel(new GridLayout(4, 3)); + this.panelButtons = new JPanel(new FlowLayout()); + + this.labelConv = new JLabel("Conversion Celsius/Farenheit"); + this.labelConv.setHorizontalAlignment(SwingConstants.TRAILING); + this.groupConv = new ButtonGroup(); + this.autoConv = new JRadioButton("Auto"); + this.afficheConv = new JRadioButton("Affiché"); + this.cacheConv = new JRadioButton("Caché"); + this.groupConv.add(this.autoConv); + this.groupConv.add(this.afficheConv); + this.groupConv.add(this.cacheConv); + + this.labelSaisie = new JLabel("Saisie de texte"); + this.labelSaisie.setHorizontalAlignment(SwingConstants.TRAILING); + this.groupSaisie = new ButtonGroup(); + this.autoSaisie = new JRadioButton("Auto"); + this.afficheSaisie = new JRadioButton("Affiché"); + this.cacheSaisie = new JRadioButton("Caché"); + this.groupSaisie.add(this.autoSaisie); + this.groupSaisie.add(this.afficheSaisie); + this.groupSaisie.add(this.cacheSaisie); + + this.labelDiapo = new JLabel("Diaporama"); + this.labelDiapo.setHorizontalAlignment(SwingConstants.TRAILING); + this.groupDiapo = new ButtonGroup(); + this.autoDiapo = new JRadioButton("Auto"); + this.afficheDiapo = new JRadioButton("Affiché"); + this.cacheDiapo = new JRadioButton("Caché"); + this.groupDiapo.add(this.autoDiapo); + this.groupDiapo.add(this.afficheDiapo); + this.groupDiapo.add(this.cacheDiapo); + + this.labelButton = new JLabel("Boutons"); + this.labelButton.setHorizontalAlignment(SwingConstants.TRAILING); + this.groupButton = new ButtonGroup(); + this.autoButton = new JRadioButton("Auto"); + this.afficheButton = new JRadioButton("Affiché"); + this.cacheButton = new JRadioButton("Caché"); + this.groupButton.add(this.autoButton); + this.groupButton.add(this.afficheButton); + this.groupButton.add(this.cacheButton); + + // this.panelConfig.add(this.groupConv); + // this.panelConfig.add(this.groupSaisie); + // this.panelConfig.add(this.groupDiapo); + // this.panelConfig.add(this.groupButton); + + this.panelLabel.add(this.labelConv); + this.panelConfig.add(this.autoConv); + this.panelConfig.add(this.afficheConv); + this.panelConfig.add(this.cacheConv); + + this.panelLabel.add(this.labelSaisie); + this.panelConfig.add(this.autoSaisie); + this.panelConfig.add(this.afficheSaisie); + this.panelConfig.add(this.cacheSaisie); + + this.panelLabel.add(this.labelDiapo); + this.panelConfig.add(this.autoDiapo); + this.panelConfig.add(this.afficheDiapo); + this.panelConfig.add(this.cacheDiapo); + + this.panelLabel.add(this.labelButton); + this.panelConfig.add(this.autoButton); + this.panelConfig.add(this.afficheButton); + this.panelConfig.add(this.cacheButton); + + this.valider = new JButton("Valider"); + this.annuler = new JButton("Annuler"); + this.panelButtons.add(this.valider); + this.panelButtons.add(this.annuler); + + this.add(this.panelLabel); + this.add(this.panelConfig, BorderLayout.EAST); + this.add(this.panelButtons, BorderLayout.SOUTH); + + pack(); + } +} diff --git a/src/tp8/fenetres/FenetreConversion.java b/src/tp8/fenetres/FenetreConversion.java new file mode 100644 index 0000000000000000000000000000000000000000..ea3a4bab1dfcfaaee2205d41434cc5d2f69f13b7 --- /dev/null +++ b/src/tp8/fenetres/FenetreConversion.java @@ -0,0 +1,114 @@ +package tp8.fenetres; + +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JButton; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; +import tp8.Application; + +/** + * + * @author brunomermet + */ +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)); + JPanel ligneCelsius = new JPanel(); + ligneCelsius.setLayout(new FlowLayout(FlowLayout.TRAILING)); + JLabel labCelsius = new JLabel("Celsius :"); + champCelsius = new JTextField(15); + labCelsius.setLabelFor(champCelsius); + ligneCelsius.add(labCelsius); + ligneCelsius.add(champCelsius); + this.add(ligneCelsius); + celsiusAFocus = true; + champCelsius.addFocusListener(new EcouteurFocus(true)); + JPanel ligneFarenheit = new JPanel(); + ligneFarenheit.setLayout(new FlowLayout(FlowLayout.TRAILING)); + JLabel labFarenheit = new JLabel("Farenheit :"); + champFarenheit = new JTextField(15); + labFarenheit.setLabelFor(champFarenheit); + ligneFarenheit.add(labFarenheit); + ligneFarenheit.add(champFarenheit); + this.add(ligneFarenheit); + champFarenheit.addFocusListener(new EcouteurFocus(false)); + JPanel ligneValider = new JPanel(); + ligneValider.setLayout(new FlowLayout(FlowLayout.CENTER)); + actionConvertir = new ActionConvertir(); + boutonConvertir = new JButton(actionConvertir); + ligneValider.add(boutonConvertir); + this.add(ligneValider); + + pack(); + getRootPane().setDefaultButton(boutonConvertir); + } + + private class EcouteurFocus implements FocusListener { + private boolean aStocker; + + public EcouteurFocus(boolean b) { + aStocker = b; + } + + @Override + public void focusGained(FocusEvent fe) { + celsiusAFocus = aStocker; + } + + @Override + public void focusLost(FocusEvent fe) { + return; + } + } + + private class ActionConvertir extends AbstractAction { + + public ActionConvertir() { + super("Convertir"); + } + + @Override + public void actionPerformed(ActionEvent ae) { + double tempCelsius = 0; + double tempFarenheit = 0; + if (celsiusAFocus) { + try { + tempCelsius = Double.parseDouble(champCelsius.getText()); + tempFarenheit = 9. / 5 * tempCelsius + 32; + champFarenheit.setText("" + tempFarenheit); + } catch (NumberFormatException nfe) { + champFarenheit.setText("Format incorrect"); + } + } else { + try { + tempFarenheit = Double.parseDouble(champFarenheit.getText()); + tempCelsius = (tempFarenheit - 32) * 5. / 9; + champCelsius.setText("" + tempCelsius); + } catch (NumberFormatException nfe) { + champCelsius.setText("Format incorrect"); + } + + } + } + } + +} diff --git a/src/tp8/fenetres/FenetreDiaporama.java b/src/tp8/fenetres/FenetreDiaporama.java new file mode 100644 index 0000000000000000000000000000000000000000..76038ef21b11b15c17e69350a18f7481614319c1 --- /dev/null +++ b/src/tp8/fenetres/FenetreDiaporama.java @@ -0,0 +1,102 @@ +package tp8.fenetres; + +import java.awt.BorderLayout; +import java.awt.Image; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.Action; +import javax.swing.ImageIcon; +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; + +/** + * + * @author brunomermet + */ +public class FenetreDiaporama extends AbstractFenetreInterne { + ImageIcon[] images; + String[] textes; + JLabel affichage; + Defilement defilement; + private int indiceCourant = 0; + + public FenetreDiaporama(Action action) { + super(action, "Diaporama"); + images = new ImageIcon[3]; + 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) { + images[0] = null; + images[1] = null; + images[2] = null; + } + + JPanel panneauTexte = new JPanel(); + /* + * textes = new String[3]; textes[0] = "bonjour"; textes[1] = "le"; textes[2] = + * "monde"; + */ + affichage = new JLabel(); + panneauTexte.add(affichage); + affichage.setIcon(images[0]); + // affichage.setText(textes[0]); + JScrollPane ascenseurs = new JScrollPane(affichage); + add(ascenseurs, BorderLayout.CENTER); + // add(panneauTexte,BorderLayout.CENTER); + setSize(300, 300); + // pack(); + + } + + class Defilement implements Runnable { + private boolean arrete; + + public Defilement() { + arrete = false; + } + + @Override + public void run() { + while (!arrete) { + try { + Thread.sleep(2000); + } catch (InterruptedException iex) { + } + indiceCourant++; + indiceCourant = indiceCourant % 3; + affichage.setIcon(images[indiceCourant]); + } + } + + public void arreter() { + arrete = true; + } + } + + @Override + public void setVisible(boolean b) { + super.setVisible(b); + if (b) { + defilement = new Defilement(); + Thread thread = new Thread(defilement); + thread.start(); + } else { + if (defilement != null) { + defilement.arreter(); + } + } + } +} diff --git a/src/tp8/fenetres/FenetreTexte.java b/src/tp8/fenetres/FenetreTexte.java new file mode 100644 index 0000000000000000000000000000000000000000..a215f8ba4498f4e3a478f0eb1f0be63cc326ccf0 --- /dev/null +++ b/src/tp8/fenetres/FenetreTexte.java @@ -0,0 +1,110 @@ +package tp8.fenetres; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.InputEvent; +import java.awt.event.KeyEvent; +import java.beans.PropertyVetoException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JCheckBox; +import javax.swing.JCheckBoxMenuItem; +import javax.swing.JInternalFrame; +import javax.swing.JMenu; +import javax.swing.JMenuBar; +import javax.swing.JMenuItem; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.KeyStroke; +import javax.swing.event.InternalFrameAdapter; +import javax.swing.event.InternalFrameEvent; +import tp8.Application; + +/** + * + * @author brunomermet + */ +public class FenetreTexte extends AbstractFenetreInterne { + private JCheckBox gras; + private JCheckBox rouge; + private Action actionGras; + private Action actionRouge; + private JTextArea texte; + + public FenetreTexte(Action action) { + super(action, "Texte"); + actionGras = new ActionGras(); + gras = new JCheckBox(actionGras); + actionRouge = new ActionRouge(); + rouge = new JCheckBox(actionRouge); + JPanel panneauBouton = new JPanel(); + panneauBouton.add(gras); + panneauBouton.add(rouge); + add(panneauBouton, BorderLayout.NORTH); + texte = new JTextArea(6, 20); + texte.setLineWrap(true); + texte.setWrapStyleWord(true); + JScrollPane panneauTexte = new JScrollPane(texte); + add(panneauTexte, BorderLayout.CENTER); + JMenuBar barre = new JMenuBar(); + JMenu style = new JMenu("Style"); + style.add(new JMenuItem(actionGras)); + style.add(new JCheckBoxMenuItem(actionRouge)); + barre.add(style); + this.setJMenuBar(barre); + pack(); + } + + private class ActionGras extends AbstractAction { + private boolean gras; + + public ActionGras() { + super("gras"); + gras = 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) { + Font police = texte.getFont(); + if (!gras) { + police = police.deriveFont(Font.BOLD);// |Font.ITALIC); + // police = police.deriveFont((float)24.0); + } else { + police = police.deriveFont(Font.PLAIN); + } + gras = !gras; + putValue(Action.SELECTED_KEY, gras); + texte.setFont(police); + } + } + + private class ActionRouge extends AbstractAction { + private boolean rouge; + + public ActionRouge() { + super("rouge"); + rouge = 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) { + texte.setForeground(Color.RED); + } else { + texte.setForeground(Color.BLACK); + } + rouge = !rouge; + // putValue(Action.SELECTED_KEY,rouge); + } + } +}