/** * Add an action to the toolbar. If the tool tip is null, use the "tooltip" property already in * the action, otherwise add the property to the action. The new button is added to the action as * the "toolButton" property. If either an icon or a text string are specified (non-null), they * are added. */ public static JButton addToolBarButton( JToolBar toolbar, Action action, String tooltip, Icon icon, String lbl, boolean isEnabled) { if (tooltip == null) { tooltip = (String) action.getValue("tooltip"); } else { action.putValue("tooltip", tooltip); } JButton button = toolbar.add(action); button.setToolTipText(tooltip); button.setText(null); button.setRequestFocusEnabled(false); if (icon != null) { button.setIcon(icon); } if (lbl != null) { button.setText(lbl); } Icon rolloverIcon = (Icon) action.getValue(ROLLOVER_ICON); if (rolloverIcon != null) { button.setRolloverIcon(rolloverIcon); } Icon rolloverSelectedIcon = (Icon) action.getValue(ROLLOVER_SELECTED_ICON); if (rolloverSelectedIcon != null) { button.setRolloverSelectedIcon(rolloverSelectedIcon); } Icon selectedIcon = (Icon) action.getValue(SELECTED_ICON); if (selectedIcon != null) { button.setSelectedIcon(selectedIcon); } button.setMargin(new Insets(0, 0, 0, 0)); // button.setBorderPainted(false); button.setBorderPainted(true); button.setEnabled(isEnabled); action.putValue("toolBarButton", button); return button; }
public SplashScreen(Image image) { this.icon = new ImageIcon(image); Container container = getContentPane(); container.setLayout(null); // Redraw the image to fix the alpha channel BufferedImage alphaImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = alphaImage.createGraphics(); g.drawImage(image, 0, 0, icon.getIconWidth(), icon.getIconHeight(), null); g.dispose(); // Draw the image JButton background = new JButton(new ImageIcon(alphaImage)); background.setBounds(0, 0, icon.getIconWidth(), icon.getIconHeight()); background.setRolloverEnabled(true); background.setRolloverIcon(background.getIcon()); background.setSelectedIcon(background.getIcon()); background.setDisabledIcon(background.getIcon()); background.setPressedIcon(background.getIcon()); background.setFocusable(false); background.setContentAreaFilled(false); background.setBorderPainted(false); background.setOpaque(false); container.add(background); // Finalize setSize(icon.getIconWidth(), icon.getIconHeight() + 20); try { // Not always supported... this.setBackground(new Color(0, 0, 0, 0)); } catch (UnsupportedOperationException e) { this.setBackground(new Color(0, 0, 0)); } setLocationRelativeTo(null); }
public diaAddRirView(Frame arg0, String arg1, boolean arg2) throws ParseException { super(arg0, arg1, arg2); // TODO Auto-generated constructor stub this.setSize(800, 640); this.setLocationRelativeTo(arg0); getContentPane().setLayout(new BorderLayout(0, 0)); m_tabbed = new JTabbedPane(JTabbedPane.TOP); getContentPane().add(m_tabbed, BorderLayout.CENTER); m_panelMetaData = new JPanel(); m_panelMetaData.setBorder( new TitledBorder( null, "Meta Donn\u00E9es et Import Pdf", TitledBorder.LEADING, TitledBorder.TOP, null, null)); JPanel m_pInfo = new JPanel(); m_panelRirInfo = new JPanel(); m_panelRirInfo.setToolTipText(""); m_tabbed.addTab("Informations (Partie 01)", null, m_panelRirInfo, null); m_panelRirInfo.setLayout(new BorderLayout(0, 0)); m_panelRirInfo02 = new JPanel(); m_tabbed.addTab("Informations (Partie 02)", null, m_panelRirInfo02, null); m_panelRirInfo02.setLayout(null); m_pMtp = new JPanel(); m_pMtp.setLayout(null); m_pMtp.setBorder( new TitledBorder( UIManager.getBorder("TitledBorder.border"), "Mtp", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); m_pMtp.setBounds(10, 11, 759, 123); m_panelRirInfo02.add(m_pMtp); m_lMarque = new JLabel("Marque:"); m_lMarque.setBounds(10, 17, 110, 14); m_pMtp.add(m_lMarque); m_lImmatriculation = new JLabel("Immatriculation:"); m_lImmatriculation.setBounds(10, 42, 110, 14); m_pMtp.add(m_lImmatriculation); m_lCouleur = new JLabel("Couleur:"); m_lCouleur.setBounds(10, 98, 110, 14); m_pMtp.add(m_lCouleur); m_tMarque = new JTextField(); m_tMarque.setColumns(10); m_tMarque.setBounds(120, 14, 110, 20); m_pMtp.add(m_tMarque); m_tImmatriculation = new JTextField(); m_tImmatriculation.setColumns(10); m_tImmatriculation.setBounds(120, 39, 110, 20); m_pMtp.add(m_tImmatriculation); m_bAddMtp = new JButton(""); m_bAddMtp.setIcon(new ImageIcon(diaAddRirView.class.getResource("/Textures/add.png"))); m_bAddMtp.setAlignmentX(0.5f); m_bAddMtp.setBounds(250, 31, 65, 50); m_pMtp.add(m_bAddMtp); m_listMtp = new JList(); DefaultListModel mmtp = new DefaultListModel(); m_listMtp.setModel(mmtp); scrollPane_4 = new JScrollPane(m_listMtp); scrollPane_4.setBounds(379, 28, 370, 50); m_pMtp.add(scrollPane_4); m_cCouleurs = new comboCouleur(); m_cCouleurs.setBounds(120, 95, 110, 20); m_pMtp.add(m_cCouleurs); JLabel m_lType = new JLabel("Type:"); m_lType.setBounds(10, 73, 80, 14); m_pMtp.add(m_lType); m_cTypeMtp = new comboTypeMtp(); m_cTypeMtp.setBounds(120, 67, 110, 20); m_pMtp.add(m_cTypeMtp); JPanel m_pContact = new JPanel(); m_pContact.setBorder( new TitledBorder( null, "Contact", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); m_pContact.setBounds(10, 145, 759, 85); m_panelRirInfo02.add(m_pContact); m_pContact.setLayout(null); m_tContact = new JTextField(); m_tContact.setBounds(47, 35, 160, 20); m_pContact.add(m_tContact); m_tContact.setColumns(10); m_bAddContact = new JButton(""); m_bAddContact.setIcon(new ImageIcon(diaAddRirView.class.getResource("/Textures/add.png"))); m_bAddContact.setAlignmentX(0.5f); m_bAddContact.setBounds(250, 21, 65, 50); m_pContact.add(m_bAddContact); m_listContact = new JList(); DefaultListModel mc = new DefaultListModel(); m_listContact.setModel(mc); JScrollPane scrollPane_5 = new JScrollPane(m_listContact); scrollPane_5.setBounds(379, 21, 370, 50); m_pContact.add(scrollPane_5); m_tabbed.addTab("Données à ajouter", null, m_panelMetaData, null); m_panelMetaData.setLayout(new BorderLayout(0, 0)); m_pMeta = new JPanel(); m_panelMetaData.add(m_pMeta, BorderLayout.CENTER); m_pMeta.setLayout(new BorderLayout(0, 0)); m_editorMeta = new JEditorPane(); scrollPane_6 = new JScrollPane(m_editorMeta); m_pMeta.add(scrollPane_6, BorderLayout.CENTER); m_pPdf = new JPanel(); m_pPdf.setBorder( new TitledBorder(null, "Doc Pdf", TitledBorder.LEADING, TitledBorder.TOP, null, null)); m_panelMetaData.add(m_pPdf, BorderLayout.SOUTH); GridBagLayout gbl_m_pPdf = new GridBagLayout(); gbl_m_pPdf.columnWidths = new int[] {171, 0, 0}; gbl_m_pPdf.rowHeights = new int[] {23, 0}; gbl_m_pPdf.columnWeights = new double[] {0.0, 0.0, Double.MIN_VALUE}; gbl_m_pPdf.rowWeights = new double[] {0.0, Double.MIN_VALUE}; m_pPdf.setLayout(gbl_m_pPdf); m_bLoadPdf = new JButton("Pdf"); GridBagConstraints gbc_m_bLoadPdf = new GridBagConstraints(); gbc_m_bLoadPdf.insets = new Insets(0, 0, 0, 5); gbc_m_bLoadPdf.fill = GridBagConstraints.BOTH; gbc_m_bLoadPdf.gridx = 0; gbc_m_bLoadPdf.gridy = 0; m_pPdf.add(m_bLoadPdf, gbc_m_bLoadPdf); m_lPdf = new JLabel(""); GridBagConstraints gbc_m_lPdf = new GridBagConstraints(); gbc_m_lPdf.gridx = 1; gbc_m_lPdf.gridy = 0; m_pPdf.add(m_lPdf, gbc_m_lPdf); m_pInfo.setBackground(Color.GRAY); m_pInfo.setBorder( new TitledBorder(null, "Information", TitledBorder.LEADING, TitledBorder.TOP, null, null)); m_panelRirInfo.add(m_pInfo, BorderLayout.NORTH); GridBagLayout gbl_m_pInfo = new GridBagLayout(); gbl_m_pInfo.columnWidths = new int[] {122, 151, 0, 0, 202, 0}; gbl_m_pInfo.rowHeights = new int[] {0, 0, 0}; gbl_m_pInfo.columnWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; gbl_m_pInfo.rowWeights = new double[] {0.0, 0.0, Double.MIN_VALUE}; m_pInfo.setLayout(gbl_m_pInfo); JLabel m_lNumero = new JLabel("Num\u00E9ro:"); GridBagConstraints gbc_m_lNumero = new GridBagConstraints(); gbc_m_lNumero.anchor = GridBagConstraints.WEST; gbc_m_lNumero.insets = new Insets(0, 0, 5, 5); gbc_m_lNumero.gridx = 0; gbc_m_lNumero.gridy = 0; m_pInfo.add(m_lNumero, gbc_m_lNumero); m_tNumero = new JFormattedTextField(new MaskFormatter(" ######/####")); m_tNumero.setFont(new Font("Tahoma", Font.BOLD, 12)); GridBagConstraints gbc_m_tNumero = new GridBagConstraints(); gbc_m_tNumero.fill = GridBagConstraints.HORIZONTAL; gbc_m_tNumero.insets = new Insets(0, 0, 5, 5); gbc_m_tNumero.gridx = 1; gbc_m_tNumero.gridy = 0; m_pInfo.add(m_tNumero, gbc_m_tNumero); m_tNumero.setColumns(10); JLabel m_lSource = new JLabel("Source:"); GridBagConstraints gbc_m_lSource = new GridBagConstraints(); gbc_m_lSource.anchor = GridBagConstraints.WEST; gbc_m_lSource.insets = new Insets(0, 0, 5, 5); gbc_m_lSource.gridx = 2; gbc_m_lSource.gridy = 0; m_pInfo.add(m_lSource, gbc_m_lSource); m_cSource = new comboSources(); GridBagConstraints gbc_m_cSource = new GridBagConstraints(); gbc_m_cSource.insets = new Insets(0, 0, 5, 0); gbc_m_cSource.fill = GridBagConstraints.HORIZONTAL; gbc_m_cSource.gridx = 4; gbc_m_cSource.gridy = 0; m_pInfo.add(m_cSource, gbc_m_cSource); JLabel m_lDate = new JLabel("Date:"); GridBagConstraints gbc_m_lDate = new GridBagConstraints(); gbc_m_lDate.anchor = GridBagConstraints.WEST; gbc_m_lDate.insets = new Insets(0, 0, 0, 5); gbc_m_lDate.gridx = 0; gbc_m_lDate.gridy = 1; m_pInfo.add(m_lDate, gbc_m_lDate); m_tDateRir = new JFormattedTextField(new MaskFormatter(" ##/##/####")); m_tDateRir.setFont(new Font("Tahoma", Font.BOLD, 12)); GridBagConstraints gbc_m_tDateRir = new GridBagConstraints(); gbc_m_tDateRir.insets = new Insets(0, 0, 0, 5); gbc_m_tDateRir.fill = GridBagConstraints.HORIZONTAL; gbc_m_tDateRir.gridx = 1; gbc_m_tDateRir.gridy = 1; m_pInfo.add(m_tDateRir, gbc_m_tDateRir); m_tDateRir.setColumns(10); JPanel m_pData = new JPanel(); m_panelRirInfo.add(m_pData, BorderLayout.CENTER); m_pData.setLayout(null); JPanel m_pQuartier = new JPanel(); m_pQuartier.setBorder( new TitledBorder( UIManager.getBorder("TitledBorder.border"), "Quartier", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); m_pQuartier.setBounds(10, 11, 759, 72); m_pData.add(m_pQuartier); m_pQuartier.setLayout(null); m_bAddQuartier = new JButton(""); m_bAddQuartier.setIcon(new ImageIcon(diaAddRirView.class.getResource("/Textures/add.png"))); m_bAddQuartier.setBounds(250, 11, 65, 50); m_bAddQuartier.setAlignmentX(Component.CENTER_ALIGNMENT); m_pQuartier.add(m_bAddQuartier); m_listQuartier = new JList(); DefaultListModel ml = new DefaultListModel(); m_listQuartier.setModel(ml); JScrollPane scrollPane = new JScrollPane(m_listQuartier); scrollPane.setBounds(379, 11, 370, 50); m_pQuartier.add(scrollPane); m_comboQuartiers = new comboQuartiers(); m_comboQuartiers.setBounds(10, 24, 183, 20); m_pQuartier.add(m_comboQuartiers); m_pDrogue = new JPanel(); m_pDrogue.setBorder( new TitledBorder(null, "Drogue", TitledBorder.LEADING, TitledBorder.TOP, null, null)); m_pDrogue.setBounds(10, 97, 759, 72); m_pData.add(m_pDrogue); m_pDrogue.setLayout(null); m_comboDrogues = new comboDrogues(); m_comboDrogues.setBounds(10, 26, 183, 20); m_pDrogue.add(m_comboDrogues); m_bAddDrogue = new JButton(""); m_bAddDrogue.setIcon(new ImageIcon(diaAddRirView.class.getResource("/Textures/add.png"))); m_bAddDrogue.setAlignmentX(0.5f); m_bAddDrogue.setBounds(250, 11, 65, 50); m_pDrogue.add(m_bAddDrogue); m_listDrogue = new JList(); DefaultListModel dl = new DefaultListModel(); m_listDrogue.setModel(dl); JScrollPane scrollPane_1 = new JScrollPane(m_listDrogue); scrollPane_1.setBounds(379, 11, 370, 50); m_pDrogue.add(scrollPane_1); m_pMethode = new JPanel(); m_pMethode.setLayout(null); m_pMethode.setBorder( new TitledBorder( UIManager.getBorder("TitledBorder.border"), "Methode", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); m_pMethode.setBounds(10, 180, 759, 72); m_pData.add(m_pMethode); m_bAddMethode = new JButton(""); m_bAddMethode.setIcon(new ImageIcon(diaAddRirView.class.getResource("/Textures/add.png"))); m_bAddMethode.setSelectedIcon( new ImageIcon(diaAddRirView.class.getResource("/Textures/add.png"))); m_bAddMethode.setAlignmentX(0.5f); m_bAddMethode.setBounds(250, 11, 65, 50); m_pMethode.add(m_bAddMethode); m_listMethode = new JList(); DefaultListModel dlm = new DefaultListModel(); m_listMethode.setModel(dlm); scrollPane_2 = new JScrollPane(m_listMethode); scrollPane_2.setBounds(379, 11, 370, 50); m_pMethode.add(scrollPane_2); m_comboMethodes = new comboMethodes(); m_comboMethodes.setBounds(10, 27, 183, 20); m_pMethode.add(m_comboMethodes); m_pPersonne = new JPanel(); m_pPersonne.setBorder( new TitledBorder(null, "Personne", TitledBorder.LEADING, TitledBorder.TOP, null, null)); m_pPersonne.setBounds(10, 263, 759, 123); m_pData.add(m_pPersonne); m_pPersonne.setLayout(null); JLabel m_lNom = new JLabel("Nom:"); m_lNom.setBounds(10, 17, 110, 14); m_pPersonne.add(m_lNom); JLabel m_lPrenom = new JLabel("Prenom:"); m_lPrenom.setBounds(10, 42, 110, 14); m_pPersonne.add(m_lPrenom); JLabel m_lSurnom = new JLabel("Surnom:"); m_lSurnom.setBounds(10, 67, 110, 14); m_pPersonne.add(m_lSurnom); JLabel m_lDateNaissance = new JLabel("Date de naissance:"); m_lDateNaissance.setBounds(10, 92, 110, 14); m_pPersonne.add(m_lDateNaissance); m_tNom = new JTextField(); m_tNom.setBounds(130, 17, 110, 20); m_pPersonne.add(m_tNom); m_tNom.setColumns(10); m_tPrenom = new JTextField(); m_tPrenom.setBounds(130, 42, 110, 20); m_pPersonne.add(m_tPrenom); m_tPrenom.setColumns(10); m_tSurnom = new JTextField(); m_tSurnom.setBounds(130, 67, 110, 20); m_pPersonne.add(m_tSurnom); m_tSurnom.setColumns(10); m_tDateNaissance = new JFormattedTextField(new MaskFormatter(" ## / ## / ####")); m_tDateNaissance.setBounds(130, 95, 110, 20); m_pPersonne.add(m_tDateNaissance); m_tDateNaissance.setColumns(10); m_bAddPersonne = new JButton(""); m_bAddPersonne.setIcon(new ImageIcon(diaAddRirView.class.getResource("/Textures/add.png"))); m_bAddPersonne.setAlignmentX(0.5f); m_bAddPersonne.setBounds(250, 31, 65, 50); m_pPersonne.add(m_bAddPersonne); m_listPersonne = new JList(); DefaultListModel dlp = new DefaultListModel(); m_listPersonne.setModel(dlp); JScrollPane scrollPane_3 = new JScrollPane(m_listPersonne); scrollPane_3.setBounds(379, 28, 370, 50); m_pPersonne.add(scrollPane_3); m_pButton = new JPanel(); getContentPane().add(m_pButton, BorderLayout.SOUTH); m_pButton.setLayout(new FlowLayout(FlowLayout.RIGHT, 5, 5)); m_bWriteRir = new JButton("Enregistrer"); m_bWriteRir.setBackground(Color.GREEN); m_pButton.add(m_bWriteRir); m_bAnnuler = new JButton("Annuler"); m_bAnnuler.setBackground(Color.CYAN); m_pButton.add(m_bAnnuler); // model try { model = new diaAddRirModel(); controller = new diaAddRirControl(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void init() { initCanvas(); WindowEventListener listener = new WindowEventListener(); this.addWindowFocusListener(listener); this.addWindowListener(listener); this.addWindowStateListener(listener); JPanel wrapper = new JPanel(); wrapper.setLayout(new BoxLayout(wrapper, BoxLayout.Y_AXIS)); wrapper.add(Box.createVerticalGlue()); JPanel top = new JPanel(); top.setPreferredSize(new Dimension(800, 40)); top.setBorder(BorderFactory.createLineBorder(Color.BLACK)); top.setLayout(new BoxLayout(top, BoxLayout.X_AXIS)); ImageIcon pointerIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/pointer.png")) .getImage() .getScaledInstance(40, 40, Image.SCALE_SMOOTH)); JButton pointerButton = new JButton(pointerIcon); pointerButton.setMaximumSize(new Dimension(40, 30)); pointerButton.setBorder(null); pointerButton.setOpaque(false); // pointerButton.setContentAreaFilled(false); pointerButton.setBorderPainted(false); pointerButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { canvas.removeAllHighlights(); canvas.removeDrags(); canvas.repaint(); } }); JLabel stroke = new JLabel("Stroke: "); JButton strokeButton = new JButton(""); strokeButton.setPreferredSize(new Dimension(30, 25)); strokeButton.setMinimumSize(new Dimension(30, 25)); strokeButton.setMaximumSize(new Dimension(30, 25)); JLabel fill = new JLabel("Fill: "); JButton fillButton = new JButton(""); fillButton.setPreferredSize(new Dimension(30, 25)); fillButton.setMinimumSize(new Dimension(30, 25)); fillButton.setMaximumSize(new Dimension(30, 25)); JLabel zoom = new JLabel("Zoom: "); JSlider slider = new JSlider(0, 100, 50); slider.setMaximumSize(new Dimension(200, 30)); JButton minusMagnifier = new JButton("-"); JButton plusMagnifier = new JButton("+"); top.add(Box.createHorizontalGlue()); top.add(stroke); top.add(strokeButton); top.add(Box.createRigidArea(new Dimension(50, 40))); top.add(fill); top.add(fillButton); top.add(Box.createRigidArea(new Dimension(100, 40))); top.add(zoom); top.add(slider); top.add(minusMagnifier); top.add(plusMagnifier); top.add(Box.createRigidArea(new Dimension(50, 40))); top.add(pointerButton); top.add(Box.createRigidArea(new Dimension(100, 400))); top.add(Box.createHorizontalGlue()); wrapper.add(top); JPanel middle = new JPanel(); middle.setLayout(new BorderLayout()); JPanel left = new JPanel(); left.setPreferredSize(new Dimension(200, 600)); left.setBorder(BorderFactory.createLineBorder(Color.BLACK)); JPanel right = new JPanel(); right.setPreferredSize(new Dimension(600, 600)); right.setBorder(BorderFactory.createLineBorder(Color.BLACK)); middle.add(left, BorderLayout.WEST); middle.add(right, BorderLayout.EAST); wrapper.add(middle); JPanel bottom = new JPanel(); bottom.setPreferredSize(new Dimension(800, 25)); bottom.setBorder(BorderFactory.createLineBorder(Color.BLACK)); wrapper.add(bottom); add(wrapper); JLabel f1 = new JLabel(" Press F1 for help"); f1.setPreferredSize(new Dimension(197, 25)); JLabel view = new JLabel(" View"); view.setPreferredSize(new Dimension(55, 25)); JLabel dimensions = new JLabel(CANVAS_WIDTH + " x " + CANVAS_HEIGHT); dimensions.setPreferredSize(new Dimension(75, 25)); coordinates = new JLabel("Coordinates: (" + xCord + ", " + yCord + ")"); coordinates.setPreferredSize(new Dimension(150, 25)); bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS)); JSeparator separator = new JSeparator(JSeparator.VERTICAL); JSeparator separator2 = new JSeparator(JSeparator.VERTICAL); JSeparator separator3 = new JSeparator(JSeparator.VERTICAL); bottom.add(Box.createHorizontalGlue()); bottom.add(f1); bottom.add(separator); bottom.add(view); bottom.add(Box.createRigidArea(new Dimension(100, 25))); bottom.add(separator2); bottom.add(dimensions); bottom.add(separator3); bottom.add(Box.createRigidArea(new Dimension(100, 25))); bottom.add(coordinates); bottom.add(Box.createHorizontalGlue()); right.setLayout(new BorderLayout()); JPanel template = new JPanel(); template.setPreferredSize(new Dimension(580, 580)); template.setLayout(new BoxLayout(template, BoxLayout.Y_AXIS)); template.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); right.add(template, BorderLayout.CENTER); JPanel titlePanel = new JPanel(); titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.X_AXIS)); titlePanel.setPreferredSize(new Dimension(580, 25)); titlePanel.setBackground(new Color(13, 16, 59)); title = new JLabel("Untitled"); title.setForeground(new Color(242, 245, 230)); // ImageIcon deleteIcon = new ImageIcon(new // ImageIcon(getClass().getResource("/resources/deleteIcon.png")).getImage().getScaledInstance(10, 10, Image.SCALE_SMOOTH)); ImageIcon deletehIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/deletehIcon.png")) .getImage() .getScaledInstance(10, 10, Image.SCALE_SMOOTH)); JButton closeButton = new JButton(deletehIcon); closeButton.setBorder(null); closeButton.setBackground(new Color(13, 16, 59)); closeButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (changesMade != 0) { requestClose(); } else { restartCanvas(); } } }); // closeButton.setRolloverIcon(deletehIcon); titlePanel.add(Box.createHorizontalGlue()); titlePanel.add(Box.createRigidArea(new Dimension(275, 25))); titlePanel.add(title); titlePanel.add(Box.createRigidArea(new Dimension(235, 25))); titlePanel.add(closeButton); titlePanel.add(Box.createRigidArea(new Dimension(15, 25))); titlePanel.add(Box.createHorizontalGlue()); canvasCover = new JPanel(); canvasCover.setBackground(new Color(26, 103, 150, 50)); canvasCover.setLayout(new GridBagLayout()); canvasCover.setPreferredSize(new Dimension(580, 580)); canvas.setMaximumSize(new Dimension(560, 540)); canvas.setPreferredSize(new Dimension(560, 540)); canvas.setMinimumSize(new Dimension(560, 540)); canvas.setBackground(Color.WHITE); canvas.requestFocus(); canvasCover.add(canvas); template.add(Box.createVerticalGlue()); template.add(titlePanel); template.add(canvasCover); template.add(Box.createVerticalGlue()); // Create the Menu JMenuBar menubar = new JMenuBar(); // Menu Names JMenu file = new JMenu("File"); file.setMnemonic(KeyEvent.VK_F); JMenu help = new JMenu("Help"); help.setMnemonic(KeyEvent.VK_H); JMenu edit = new JMenu("Edit"); edit.setMnemonic(KeyEvent.VK_E); // Menu Items and Listeners ImageIcon closeIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/closeIcon.png")) .getImage() .getScaledInstance(20, 20, Image.SCALE_SMOOTH)); ImageIcon exitIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/exitIcon.png")) .getImage() .getScaledInstance(20, 20, Image.SCALE_SMOOTH)); ImageIcon newIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/newIcon.png")) .getImage() .getScaledInstance(20, 20, Image.SCALE_SMOOTH)); ImageIcon saveIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/saveIcon.png")) .getImage() .getScaledInstance(20, 20, Image.SCALE_SMOOTH)); ImageIcon openIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/openIcon.png")) .getImage() .getScaledInstance(20, 20, Image.SCALE_SMOOTH)); ImageIcon printIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/printIcon.png")) .getImage() .getScaledInstance(20, 20, Image.SCALE_SMOOTH)); JMenuItem closeMenuItem = new JMenuItem("Close", closeIcon); closeMenuItem.setMnemonic(KeyEvent.VK_W); closeMenuItem.setToolTipText("Close current window"); closeMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK)); closeMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (changesMade != 0) { requestClose(); } else { restartCanvas(); } } }); JMenuItem exitMenuItem = new JMenuItem("Exit", exitIcon); exitMenuItem.setToolTipText("Exit Application"); exitMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { System.exit(0); } }); JMenuItem newMenuItem = new JMenuItem("New", newIcon); newMenuItem.setMnemonic(KeyEvent.VK_N); newMenuItem.setToolTipText("Start a new file"); newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); newMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { restartCanvas(); title.setText("Untitled"); } }); JMenuItem openMenuItem = new JMenuItem("Open File...", openIcon); openMenuItem.setMnemonic(KeyEvent.VK_O); openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); openMenuItem.setToolTipText("New"); openMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { open(); } }); JMenuItem saveAsMenuItem = new JMenuItem("Save As...", saveIcon); saveAsMenuItem.setMnemonic(KeyEvent.VK_S); saveAsMenuItem.setToolTipText("Save As"); saveAsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); saveAsMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) { save(); } }); JMenuItem printMenuItem = new JMenuItem("Print", printIcon); printMenuItem.setMnemonic(KeyEvent.VK_P); printMenuItem.setToolTipText("Print Current Window"); printMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); printMenuItem.addActionListener(new PrintJob()); JMenuItem aboutMenuItem = new JMenuItem("About"); aboutMenuItem.setMnemonic(KeyEvent.VK_A); aboutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); aboutMenuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent event) {} }); JMenuItem helpMenuItem = new JMenuItem("Help"); helpMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0)); // Add Items to Menus file.add(newMenuItem); file.add(openMenuItem); file.addSeparator(); file.add(closeMenuItem); file.addSeparator(); file.add(saveAsMenuItem); file.addSeparator(); file.add(printMenuItem); file.addSeparator(); file.add(exitMenuItem); help.add(aboutMenuItem); help.add(helpMenuItem); // Add Menus menubar.add(file); menubar.add(edit); menubar.add(help); // Add Menu Bar setJMenuBar(menubar); // Side Panel JPanel shapePanel = new JPanel(); shapePanel.setLayout(new BorderLayout()); JLabel shapesLabel = new JLabel("Shapes", JLabel.CENTER); shapesLabel.setFont(new Font("Georgia", Font.BOLD, 14)); shapesLabel.setBorder(new EmptyBorder(new Insets(10, 0, 10, 20))); JPanel shapeArea = new JPanel(); shapeArea.setLayout(new GridLayout(2, 2, 2, 0)); // Create the shape buttons and their icons squareIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/square.png")) .getImage() .getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH)); triangleIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/triangle.png")) .getImage() .getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH)); rectangleIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/rectangle.png")) .getImage() .getScaledInstance(45, 30, java.awt.Image.SCALE_SMOOTH)); hexagonIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/hexagon.png")) .getImage() .getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH)); squarehIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/squareh.png")) .getImage() .getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH)); trianglehIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/triangleh.png")) .getImage() .getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH)); rectanglehIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/rectangleh.png")) .getImage() .getScaledInstance(45, 30, java.awt.Image.SCALE_SMOOTH)); hexagonhIcon = new ImageIcon( new ImageIcon(getClass().getResource("/resources/hexagonh.png")) .getImage() .getScaledInstance(30, 30, java.awt.Image.SCALE_SMOOTH)); squareButton = new JButton(squarehIcon); squareButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); squareButton.setContentAreaFilled(false); squareButton.setPressedIcon(squarehIcon); squareButton.setSelectedIcon(squarehIcon); squareButton.setRolloverIcon(squarehIcon); squareButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub clearButtons(); shapePressed = SQUARE; squareButton.setIcon(squarehIcon); } }); triangleButton = new JButton(triangleIcon); triangleButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); triangleButton.setContentAreaFilled(false); triangleButton.setPressedIcon(trianglehIcon); triangleButton.setSelectedIcon(trianglehIcon); triangleButton.setRolloverIcon(trianglehIcon); triangleButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub clearButtons(); shapePressed = TRIANGLE; triangleButton.setIcon(trianglehIcon); } }); rectangleButton = new JButton(rectangleIcon); rectangleButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); rectangleButton.setContentAreaFilled(false); rectangleButton.setPressedIcon(rectanglehIcon); rectangleButton.setSelectedIcon(rectanglehIcon); rectangleButton.setRolloverIcon(rectanglehIcon); rectangleButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub clearButtons(); shapePressed = RECTANGLE; rectangleButton.setIcon(rectanglehIcon); } }); hexagonButton = new JButton(hexagonIcon); hexagonButton.setCursor(new Cursor(Cursor.HAND_CURSOR)); hexagonButton.setContentAreaFilled(false); hexagonButton.setPressedIcon(hexagonhIcon); hexagonButton.setSelectedIcon(hexagonhIcon); hexagonButton.setRolloverIcon(hexagonhIcon); hexagonButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub clearButtons(); shapePressed = HEXAGON; hexagonButton.setIcon(hexagonhIcon); } }); shapeArea.add(squareButton); shapeArea.add(triangleButton); shapeArea.add(rectangleButton); shapeArea.add(hexagonButton); shapePanel.add(shapesLabel, BorderLayout.NORTH); shapePanel.add(shapeArea); shapePanel.setBorder(BorderFactory.createBevelBorder(NORMAL, Color.BLACK, Color.BLACK)); left.setLayout(new GridBagLayout()); // left.add(Box.createVerticalGlue()); left.add(shapePanel); // left.add(Box.createVerticalGlue()); setResizable(false); // setSize(new Dimension(816, 726)); // setMinimumSize(new Dimension(816, 726)); // setMaximumSize(new Dimension(816, 726)); // setPreferredSize(new Dimension(816, 726)); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("Fold"); pack(); setLocationRelativeTo(null); // pack all the components in the JFrame setVisible(true); // show it requestFocus(); }