Skip to content
Snippets Groups Projects
Commit 2884c90d authored by PIQUEREZ Corentin's avatar PIQUEREZ Corentin
Browse files

actionlistener sur les boutons fonctionnel, mais pas complet

parent 17fcf14c
No related branches found
No related tags found
No related merge requests found
1 2
220708 230519
...@@ -37,7 +37,7 @@ public class Shukan ...@@ -37,7 +37,7 @@ public class Shukan
JFrame frame = new JFrame ("SHUKAN 1.6"); JFrame frame = new JFrame ("SHUKAN 1.6");
JPanel global = new JPanel(new BorderLayout()); JPanel global = new JPanel(new BorderLayout());
ShukanView canvas = new ShukanView (data, io); ShukanView canvas = new ShukanView (data, io);
ShukanViewBar barre = new ShukanViewBar(io, data, 90); ShukanViewBar mytoolbar = new ShukanViewBar(90);
// Getting the display size // Getting the display size
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment (); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment ();
...@@ -45,14 +45,15 @@ public class Shukan ...@@ -45,14 +45,15 @@ public class Shukan
GraphicsConfiguration[] gc = gd.getConfigurations (); GraphicsConfiguration[] gc = gd.getConfigurations ();
Rectangle gcBounds = gc[0].getBounds (); Rectangle gcBounds = gc[0].getBounds ();
canvas.restrictSize ((int) (gcBounds.getWidth ()) - LEFT_MARGIN, canvas.restrictSize ((int) (gcBounds.getWidth ()) - LEFT_MARGIN,
(int) (gcBounds.getHeight ()) - TOP_MARGIN - barre.getHeight()); (int) (gcBounds.getHeight ()) - TOP_MARGIN - mytoolbar.getHeight());
barre.setSize(new Dimension((int) (gcBounds.getWidth ()) - LEFT_MARGIN, barre.getHeight())); mytoolbar.setSize(new Dimension((int) (gcBounds.getWidth ()) - LEFT_MARGIN, mytoolbar.getHeight()));
// Adding a openGL input handler (controller) // Adding a openGL input handler (controller)
ShukanController myController = new ShukanController (canvas, data); ShukanController myController = new ShukanController (canvas, mytoolbar, data);
canvas.addKeyListener (myController); canvas.addKeyListener (myController);
canvas.addMouseListener (myController); canvas.addMouseListener (myController);
//canvas.addMouseMotionListener (myController); mytoolbar.addActionListener(myController);
// Preparing the window closing button // Preparing the window closing button
frame.addWindowListener ( frame.addWindowListener (
...@@ -67,12 +68,12 @@ public class Shukan ...@@ -67,12 +68,12 @@ public class Shukan
// Setting the window geometry // Setting the window geometry
global.add(barre, BorderLayout.NORTH); global.add(mytoolbar, BorderLayout.NORTH);
global.add (canvas, BorderLayout.CENTER); global.add (canvas, BorderLayout.CENTER);
frame.add(global); frame.add(global);
Insets ins = frame.getInsets (); Insets ins = frame.getInsets ();
frame.setSize (canvas.displayWidth () + ins.left + ins.right, frame.setSize (canvas.displayWidth () + ins.left + ins.right,
canvas.displayHeight ()+ barre.getHeight()+ ins.top + ins.bottom); canvas.displayHeight ()+ mytoolbar.getHeight()+ ins.top + ins.bottom);
frame.setLocation (LEFT_MARGIN, 0); frame.setLocation (LEFT_MARGIN, 0);
frame.setBackground (Color.white); frame.setBackground (Color.white);
frame.setVisible (true); frame.setVisible (true);
......
...@@ -18,9 +18,10 @@ public class ShukanController ...@@ -18,9 +18,10 @@ public class ShukanController
* @param canvas display area. * @param canvas display area.
* @param myView OpenGL context. * @param myView OpenGL context.
*/ */
public ShukanController (ShukanView canvas, ShukanData data) public ShukanController (ShukanView canvas, ShukanViewBar bar, ShukanData data)
{ {
this.canvas = canvas; this.canvas = canvas;
this.bar = bar;
this.data = data; this.data = data;
} }
...@@ -203,29 +204,20 @@ public class ShukanController ...@@ -203,29 +204,20 @@ public class ShukanController
public void actionPerformed(ActionEvent e){ public void actionPerformed(ActionEvent e){
if (e.getSource()== bar.buttons[0]) if (e.getSource()== bar.buttons[0])
System.out.println("save"); System.out.println("save");
else if (e.getSource()== bar.buttons[1])
/**case bar.buttons[1]:
System.out.println("back"); System.out.println("back");
break; else if (e.getSource()==bar.buttons[2])
case bar.buttons[2]:
System.out.println("plus"); System.out.println("plus");
break; else if (e.getSource()==bar.buttons[3])
case bar.buttons[3]:
System.out.println("delete"); System.out.println("delete");
break; else if (e.getSource()==bar.buttons[4])
case bar.buttons[4]:
System.out.println("left"); System.out.println("left");
break; else if (e.getSource()==bar.buttons[5])
case bar.buttons[5]:
System.out.println("right"); System.out.println("right");
break; else if (e.getSource()==bar.buttons[6])
case bar.buttons[6]:
System.out.println("export"); System.out.println("export");
break; else if (e.getSource()==bar.buttons[7])
case bar.buttons[7]:
System.out.println("parameter"); System.out.println("parameter");
break;*/
} }
} }
...@@ -4,10 +4,7 @@ import javax.swing.*; ...@@ -4,10 +4,7 @@ import javax.swing.*;
import java.awt.*; import java.awt.*;
public class ShukanViewBar extends JPanel { public class ShukanViewBar extends JPanel {
/** File manager */
private ShukanIO myIO = null;
/** Displayed data */
private ShukanData data = null;
/** Name of the images files for the buttons of the toolbar */ /** Name of the images files for the buttons of the toolbar */
private String[] imagesName = {"save", "back", "plus", "delete", "left", "right", "export", "parameter"}; private String[] imagesName = {"save", "back", "plus", "delete", "left", "right", "export", "parameter"};
/** Buttons of the toolbar */ /** Buttons of the toolbar */
...@@ -17,20 +14,22 @@ public class ShukanViewBar extends JPanel { ...@@ -17,20 +14,22 @@ public class ShukanViewBar extends JPanel {
/** height in pixel of the toolbar */ /** height in pixel of the toolbar */
private int height; private int height;
public ShukanViewBar(ShukanIO myIO, ShukanData data, int height){ public ShukanViewBar(int height){
this.myIO = myIO;
this.data = data;
this.height = height; this.height = height;
for(int i = 0; i<imagesName.length;i++){ for(int i = 0; i<imagesName.length;i++){
buttons[i] = new JButton("", new ImageIcon("data/images/"+imagesName[i]+imagesExtension)); buttons[i] = new JButton("", new ImageIcon("data/images/"+imagesName[i]+imagesExtension));
buttons[i].setPreferredSize(new Dimension(80,80)); buttons[i].setPreferredSize(new Dimension(80,80));
//buttons[i].addActionListener(...);
add(buttons[i]); add(buttons[i]);
} }
} }
public int getHeight(){return height;} public int getHeight(){return height;}
public void addActionListener(ShukanController controller){
for(int i =0; i<imagesName.length; i++){
buttons[i].addActionListener(controller);
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment