|
| 1 | +package com.tech.app.windows.toolbars; |
| 2 | + |
| 3 | +import javax.imageio.ImageIO; |
| 4 | +import javax.swing.*; |
| 5 | +import javax.swing.plaf.nimbus.NimbusLookAndFeel; |
| 6 | +import java.awt.*; |
| 7 | +import java.awt.event.ActionEvent; |
| 8 | +import java.io.IOException; |
| 9 | + |
| 10 | +public class DrawingToolbar extends Toolbar { |
| 11 | + |
| 12 | + /* Construction de l'interface graphique pour tester à part*/ |
| 13 | + |
| 14 | + public DrawingToolbar(JFrame frame) { |
| 15 | + super(frame); |
| 16 | + this.frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
| 17 | + } |
| 18 | + |
| 19 | + @Override |
| 20 | + public JToolBar getToolbar() { |
| 21 | + JToolBar toolbar = new JToolBar(); |
| 22 | + |
| 23 | + JButton btnNew = new JButton( new ImageIcon( "icons/new.png") ); |
| 24 | + btnNew.setToolTipText( "New File (CTRL+N)" ); |
| 25 | + btnNew.addActionListener( this::btnNewListener ); |
| 26 | + toolbar.add( btnNew ); |
| 27 | + |
| 28 | + JButton btnOpen = new JButton( new ImageIcon( "icons/open.png") ); |
| 29 | + btnNew.setToolTipText( "New File (CTRL+O)" ); |
| 30 | + btnNew.addActionListener( this::btnNewListener ); |
| 31 | + toolbar.add( btnOpen ); |
| 32 | + |
| 33 | + JButton btnSave = new JButton( new ImageIcon( "icons/save.png" ) ); |
| 34 | + btnSave.setToolTipText( "Save (CTRL+S)" ); |
| 35 | + toolbar.add( btnSave ); |
| 36 | + |
| 37 | + JButton btnSaveAs = new JButton( new ImageIcon( "icons/save_as.png" ) ); |
| 38 | + btnSaveAs.setToolTipText( "Save As..." ); |
| 39 | + toolbar.add( btnSaveAs ); |
| 40 | + |
| 41 | + toolbar.addSeparator(); |
| 42 | + |
| 43 | + JButton btnCopy = new JButton( new ImageIcon( "icons/copy.png") ); |
| 44 | + btnCopy.setToolTipText( "Copy (CTRL+C)" ); |
| 45 | + toolbar.add( btnCopy ); |
| 46 | + |
| 47 | + JButton btnCut = new JButton( new ImageIcon( "icons/cut.png") ); |
| 48 | + btnCut.setToolTipText( "Cut (CTRL+X)" ); |
| 49 | + toolbar.add( btnCut ); |
| 50 | + |
| 51 | + JButton btnPaste = new JButton( new ImageIcon( "icons/paste.png") ); |
| 52 | + btnPaste.setToolTipText( "Paste (CTRL+V)" ); |
| 53 | + toolbar.add( btnPaste ); |
| 54 | + |
| 55 | + toolbar.addSeparator(); |
| 56 | + |
| 57 | + JButton btnUndo = new JButton( new ImageIcon( "icons/undo.png") ); |
| 58 | + btnUndo.setToolTipText( "Undo (CTRL+Z)" ); |
| 59 | + toolbar.add( btnUndo ); |
| 60 | + |
| 61 | + JButton btnRedo = new JButton( new ImageIcon( "icons/redo.png") ); |
| 62 | + btnRedo.setToolTipText( "Redo" ); |
| 63 | + toolbar.add( btnRedo ); |
| 64 | + |
| 65 | + toolbar.addSeparator(); |
| 66 | + |
| 67 | + JButton btnPlace = new JButton( new ImageIcon( "icons/place.png") ); |
| 68 | + btnPlace.setToolTipText( "Place" ); |
| 69 | + toolbar.add( btnPlace ); |
| 70 | + |
| 71 | + JButton btnTransition = new JButton( new ImageIcon( "icons/transition.png") ); |
| 72 | + btnTransition.setToolTipText( "Transition" ); |
| 73 | + toolbar.add( btnTransition ); |
| 74 | + |
| 75 | + JButton btnArc = new JButton( new ImageIcon( "icons/arc.png") ); |
| 76 | + btnArc.setToolTipText( "Arc" ); |
| 77 | + toolbar.add( btnArc ); |
| 78 | + |
| 79 | + JButton btnAttributs = new JButton( new ImageIcon( "icons/attributs.png") ); |
| 80 | + btnAttributs.setToolTipText( "Attributs" ); |
| 81 | + toolbar.add( btnAttributs ); |
| 82 | + |
| 83 | + JButton btnSelect = new JButton( new ImageIcon( "icons/select.png") ); |
| 84 | + btnSelect.setToolTipText( "Select" ); |
| 85 | + toolbar.add( btnSelect ); |
| 86 | + |
| 87 | + |
| 88 | + //Gestion des icônes => améliorable ! |
| 89 | + Image imageNew = null; |
| 90 | + Image imageOpen = null; |
| 91 | + Image imageSave = null; |
| 92 | + Image imageSaveAs = null; |
| 93 | + Image imageUndo = null; |
| 94 | + Image imageRedo = null; |
| 95 | + Image imageCopy = null; |
| 96 | + Image imagePaste = null; |
| 97 | + Image imageCut = null; |
| 98 | + Image imagePlace = null; |
| 99 | + Image imageTransition = null; |
| 100 | + Image imageArc = null; |
| 101 | + Image imageAttributs = null; |
| 102 | + Image imageSelect = null; |
| 103 | + |
| 104 | + |
| 105 | + try { |
| 106 | + imageNew = ImageIO.read(getClass().getResource("/icons/new.png")); |
| 107 | + imageOpen = ImageIO.read(getClass().getResource("/icons/open.png")); |
| 108 | + imageSave = ImageIO.read(getClass().getResource("/icons/save.png")); |
| 109 | + imageSaveAs = ImageIO.read(getClass().getResource("/icons/save_as.png")); |
| 110 | + imageUndo = ImageIO.read(getClass().getResource("/icons/undo.png")); |
| 111 | + imageRedo = ImageIO.read(getClass().getResource("/icons/redo.png")); |
| 112 | + imageCopy = ImageIO.read(getClass().getResource("/icons/copy.png")); |
| 113 | + imagePaste = ImageIO.read(getClass().getResource("/icons/paste.png")); |
| 114 | + imageCut = ImageIO.read(getClass().getResource("/icons/cut.png")); |
| 115 | + imagePlace = ImageIO.read(getClass().getResource("/icons/place.png")); |
| 116 | + imageTransition = ImageIO.read(getClass().getResource("/icons/transition.png")); |
| 117 | + imageArc = ImageIO.read(getClass().getResource("/icons/arc.png")); |
| 118 | + imageAttributs = ImageIO.read(getClass().getResource("/icons/attributs.png")); |
| 119 | + imageSelect = ImageIO.read(getClass().getResource("/icons/select.png")); |
| 120 | + |
| 121 | + } catch (IOException e) { |
| 122 | + e.printStackTrace(); |
| 123 | + } |
| 124 | + assert imageNew != null; |
| 125 | + assert imageOpen != null; |
| 126 | + assert imageSave != null; |
| 127 | + assert imageSaveAs != null; |
| 128 | + assert imageUndo != null; |
| 129 | + assert imageRedo != null; |
| 130 | + assert imageCopy != null; |
| 131 | + assert imagePaste != null; |
| 132 | + assert imageCut != null; |
| 133 | + assert imagePlace != null; |
| 134 | + assert imageTransition != null; |
| 135 | + assert imageArc != null; |
| 136 | + assert imageAttributs != null; |
| 137 | + assert imageSelect != null; |
| 138 | + btnNew.setIcon(new ImageIcon(imageNew)); |
| 139 | + btnOpen.setIcon(new ImageIcon(imageOpen)); |
| 140 | + btnSave.setIcon(new ImageIcon(imageSave)); |
| 141 | + btnSaveAs.setIcon(new ImageIcon(imageSaveAs)); |
| 142 | + btnUndo.setIcon(new ImageIcon(imageUndo)); |
| 143 | + btnRedo.setIcon(new ImageIcon(imageRedo)); |
| 144 | + btnCopy.setIcon(new ImageIcon(imageCopy)); |
| 145 | + btnPaste.setIcon(new ImageIcon(imagePaste)); |
| 146 | + btnCut.setIcon(new ImageIcon(imageCut)); |
| 147 | + btnPlace.setIcon(new ImageIcon(imagePlace)); |
| 148 | + btnTransition.setIcon(new ImageIcon(imageTransition)); |
| 149 | + btnArc.setIcon(new ImageIcon(imageArc)); |
| 150 | + btnAttributs.setIcon(new ImageIcon(imageAttributs)); |
| 151 | + btnSelect.setIcon(new ImageIcon(imageSelect)); |
| 152 | + |
| 153 | + |
| 154 | + return toolbar; |
| 155 | + } |
| 156 | + |
| 157 | + private void btnNewListener( ActionEvent event ) { |
| 158 | + JOptionPane.showMessageDialog( this, "Button clicked !" ); |
| 159 | + } |
| 160 | + /* |
| 161 | + public static void main(String[] args) throws Exception { |
| 162 | + UIManager.setLookAndFeel( new NimbusLookAndFeel() ); |
| 163 | + DrawingToolbar frame = new DrawingToolbar(this); |
| 164 | + frame.setVisible( true ); |
| 165 | + } |
| 166 | + */ |
| 167 | +} |
0 commit comments