//Author: ^-^Veerle^-^ import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.JButton; import java.awt.event.ActionListener; public class databaseToolbar extends JPanel { private final String[] strToolbarTitles = new String[] {"Create", "Select", "Close", "Close All", "XML", "TXT", "Delete", "Exit"}; private final String[] strToolbarTips = new String[] {"Create a new table", "Select a table for editing", "Close the selected table", "Close all open tables", "Output the current table's records to XML", "Output the current table's records to TXT", "Delete a table", "Exit the application"}; private final String[] strToolbarAction = new String[]{"newTable", "databaseSelectTable", "closeTable", "closeAll", "outputXML", "outputTXT", "databaseDeleteTable", "exit"}; private final boolean[] spaceSort = new boolean[] {false, false, true, false, true, false, true, false}; private final boolean[] allowDisable = new boolean[] {false, false, true, true, true, true, false, false}; private JButton[] cmdToolbarButton; private JButton cmdCreate, cmdSelect, cmdClose, cmdCloseAll, cmdDelete, cmdExit; private JButton cmdXML, cmdTXT; public databaseToolbar (ActionListener mainApp) { cmdToolbarButton = new JButton[strToolbarTitles.length]; for (int i = 0; i < strToolbarTitles.length; i++) { cmdToolbarButton[i] = new JButton(strToolbarTitles[i]); cmdToolbarButton[i].setToolTipText(strToolbarTips[i]); cmdToolbarButton[i].addActionListener(mainApp); cmdToolbarButton[i].setActionCommand(strToolbarAction[i]); if (spaceSort[i]) { this.add(new JLabel(" ")); } this.add(cmdToolbarButton[i]); } try { for (int i = 0; i < strToolbarTitles.length; i++) { cmdToolbarButton[i].setIcon(dataManager.createImageIcon(mainApp, "images/toolbarIcon" + i + ".gif", "")); } } catch (Exception ex) { } } public void tableOpen (boolean state) { for (int i = 0; i < strToolbarTitles.length; i++) { if (allowDisable[i]) { cmdToolbarButton[i].setEnabled(state); } } } }