Coverage Report - de.glossmaker.gui.gloss.bars.ToolBar
 
Classes in this File Line Coverage Branch Coverage Complexity
ToolBar
0%
0/119
0%
0/38
2,462
 
 1  
 package de.glossmaker.gui.gloss.bars;
 2  
 
 3  
 import java.awt.Dimension;
 4  
 import java.beans.PropertyChangeEvent;
 5  
 import java.beans.PropertyChangeListener;
 6  
 
 7  
 import javax.swing.ImageIcon;
 8  
 import javax.swing.JButton;
 9  
 import javax.swing.JToggleButton;
 10  
 import javax.swing.JToolBar;
 11  
 
 12  
 import de.glossmaker.gloss.datastructure.GlossItems;
 13  
 import de.glossmaker.gloss.language.Translation;
 14  
 import de.glossmaker.gloss.listener.CustomActionListener;
 15  
 import de.glossmaker.gloss.listener.EActionCommands;
 16  
 import de.glossmaker.gloss.observer.GlossItemsChangePublisher;
 17  
 import de.glossmaker.gloss.undo.UndoGlossStack;
 18  
 import de.glossmaker.gui.gloss.help.HelpSystem;
 19  
 import de.glossmaker.gui.gloss.main.HelpFocusListener;
 20  
 
 21  
 /**
 22  
  * 
 23  
  * 
 24  
  * @author Markus Flingelli
 25  
  */
 26  
 
 27  
 public class ToolBar extends JToolBar implements PropertyChangeListener {
 28  
         private static final long serialVersionUID = -4833900226482512781L;
 29  0
         private CustomActionListener mActionListener = null;
 30  
         
 31  0
         private JButton mNewButton = null;
 32  0
         private JButton mOpenButton = null;
 33  0
         private JButton mSaveButton = null;
 34  0
         private JToggleButton mTableButton = null;
 35  0
         private JButton mBibTeXButton = null;
 36  0
         private JButton mHelpButton = null;
 37  0
         private JButton mInfoButton = null;
 38  0
         private JButton mUndo = null;
 39  0
         private JButton mRedo = null;
 40  
         
 41  0
         private GlossItemsChangePublisher mGlossItemsChangePublisher = null;
 42  0
         private Translation mTranslation = null;
 43  
         
 44  0
         public ToolBar(GlossItems items) {
 45  0
                 mActionListener = CustomActionListener.getInstance(items);
 46  0
                 mGlossItemsChangePublisher = GlossItemsChangePublisher.getInstance(items);
 47  0
                 mGlossItemsChangePublisher.addPropertyChangeListener(this);
 48  0
                 mTranslation = Translation.getInstance();
 49  0
                 initialize();
 50  0
         }
 51  
         
 52  
 
 53  
 
 54  
         private void initialize() {
 55  0
                 this.setPreferredSize(new Dimension(30, 30));
 56  0
                 this.add(getNewButton());
 57  0
                 this.add(getOpenButton());
 58  0
                 this.add(getSaveButton());
 59  0
                 this.addSeparator();
 60  0
                 this.add(getUndoButton());
 61  0
                 this.add(getRedoButton());
 62  0
                 this.addSeparator();
 63  0
                 this.add(getTableButton());
 64  0
                 this.addSeparator();
 65  0
                 this.add(getBibTeXButton());
 66  0
                 this.addSeparator();
 67  0
                 this.add(getHelpButton());
 68  0
                 this.addSeparator();
 69  0
                 this.add(getInfoButton());
 70  0
                 changeLanguage();
 71  0
         }
 72  
         
 73  
         private JButton getNewButton() {
 74  0
                 if (mNewButton == null) {
 75  0
                         mNewButton = new JButton(new ImageIcon(ToolBar.class.getResource("/icons/new.png")));
 76  0
                         mNewButton.addActionListener(mActionListener);
 77  0
                         mNewButton.setActionCommand(EActionCommands.CREATE_NEW_FILE.toString());
 78  0
                         mNewButton.addFocusListener(new HelpFocusListener("section.new.file"));
 79  
                 }
 80  
                 
 81  0
                 return mNewButton;
 82  
         }
 83  
         
 84  
         private JButton getOpenButton() {
 85  0
                 if (mOpenButton == null) {
 86  0
                         mOpenButton = new JButton(new ImageIcon(ToolBar.class.getResource("/icons/open.png")));
 87  0
                         mOpenButton.addActionListener(mActionListener);
 88  0
                         mOpenButton.setActionCommand(EActionCommands.OPEN_FILE.toString());                        
 89  0
                         mOpenButton.addFocusListener(new HelpFocusListener("section.open.file"));
 90  
                 }
 91  
                 
 92  0
                 return mOpenButton;
 93  
         }
 94  
         
 95  
         private JButton getBibTeXButton() {
 96  0
                 if (mBibTeXButton == null) {
 97  0
                         mBibTeXButton = new JButton(new ImageIcon(ToolBar.class.getResource("/icons/bibtex.png")));
 98  0
                         mBibTeXButton.addActionListener(mActionListener);
 99  0
                         mBibTeXButton.setActionCommand(EActionCommands.SHOW_BIB_EDITOR.toString());
 100  0
                         mBibTeXButton.addFocusListener(new HelpFocusListener("section.bibtex_editor"));
 101  
                 }
 102  
                 
 103  0
                 return mBibTeXButton;
 104  
         }
 105  
         
 106  
         private JButton getSaveButton() {
 107  0
                 if (mSaveButton == null) {
 108  0
                         mSaveButton = new JButton(new ImageIcon(ToolBar.class.getResource("/icons/save.png")));
 109  0
                         mSaveButton.addActionListener(mActionListener);
 110  0
                         mSaveButton.setActionCommand(EActionCommands.SAVE_FILE.toString());                        
 111  0
                         mSaveButton.setEnabled(false);
 112  0
                         mSaveButton.addFocusListener(new HelpFocusListener("section.save.file"));
 113  
                 }
 114  
                 
 115  0
                 return mSaveButton;
 116  
         }
 117  
         
 118  
         private JButton getUndoButton() {
 119  0
                 if (mUndo == null) {
 120  0
                         mUndo = new JButton(new ImageIcon(ToolBar.class.getResource("/icons/undo.png")));
 121  0
                         mUndo.addActionListener(mActionListener);
 122  0
                         mUndo.setActionCommand(EActionCommands.UNDO.toString());                        
 123  0
                         mUndo.setEnabled(false);
 124  0
                         mUndo.addFocusListener(new HelpFocusListener("section.undo"));
 125  
                 }
 126  
                 
 127  0
                 return mUndo;
 128  
         }
 129  
         
 130  
         private JButton getRedoButton() {
 131  0
                 if (mRedo == null) {
 132  0
                         mRedo = new JButton(new ImageIcon(ToolBar.class.getResource("/icons/redo.png")));
 133  0
                         mRedo.addActionListener(mActionListener);
 134  0
                         mRedo.setActionCommand(EActionCommands.REDO.toString());                        
 135  0
                         mRedo.setEnabled(false);
 136  0
                         mRedo.addFocusListener(new HelpFocusListener("section.redo"));
 137  
                 }
 138  
                 
 139  0
                 return mRedo;
 140  
         }
 141  
         
 142  
         private JButton getHelpButton() {
 143  0
                 if (mHelpButton == null) {
 144  0
                         mHelpButton = new JButton(new ImageIcon(ToolBar.class.getResource("/icons/help.png")));
 145  0
                         mHelpButton.addActionListener(mActionListener);                        
 146  0
                         HelpSystem.getInstance().enableHelpOnButton(mHelpButton, "chapter.introduction", null);
 147  0
                         mHelpButton.addFocusListener(new HelpFocusListener("section.help_dialog"));
 148  
                 }
 149  
                 
 150  0
                 return mHelpButton;
 151  
         }
 152  
         private JButton getInfoButton() {
 153  0
                 if (mInfoButton == null) {
 154  0
                         mInfoButton = new JButton(new ImageIcon(ToolBar.class.getResource("/icons/info.png")));
 155  0
                         mInfoButton.addActionListener(mActionListener);
 156  0
                         mInfoButton.setActionCommand(EActionCommands.INFO_DIALOG.toString());                        
 157  0
                         mInfoButton.addFocusListener(new HelpFocusListener("section.info"));
 158  
                 }
 159  
                 
 160  0
                 return mInfoButton;
 161  
         }
 162  
         
 163  
         private JToggleButton getTableButton() {
 164  0
                 if (mTableButton == null) {
 165  0
                         mTableButton = new JToggleButton(new ImageIcon(ToolBar.class.getResource("/icons/table.png")));
 166  0
                         mTableButton.setActionCommand(EActionCommands.SHOW_TABLE_VIEW.toString());
 167  0
                         mTableButton.addActionListener(mActionListener);
 168  0
                         mRedo.addFocusListener(new HelpFocusListener("section.show_table"));
 169  
                 }
 170  0
                 return mTableButton;
 171  
         }
 172  
 
 173  
         private void changeLanguage() {
 174  0
                 mNewButton.setToolTipText(mTranslation.getValue("menu.file.new.tooltip"));
 175  0
                 mOpenButton.setToolTipText(mTranslation.getValue("menu.file.open.tooltip"));
 176  0
                 mSaveButton.setToolTipText(mTranslation.getValue("menu.file.save.tooltip"));
 177  0
                 mUndo.setToolTipText(mTranslation.getValue("menu.edit.undo.tooltip"));
 178  0
                 mRedo.setToolTipText(mTranslation.getValue("menu.edit.redo.tooltip"));
 179  0
                 mTableButton.setToolTipText(mTranslation.getValue("menu.show_table.tooltip"));
 180  0
                 mBibTeXButton.setToolTipText(mTranslation.getValue("menu.bibtex_editor.tooltip"));
 181  0
                 mHelpButton.setToolTipText(mTranslation.getValue("menu.help.help.tooltip"));
 182  0
                 mInfoButton.setToolTipText(mTranslation.getValue("menu.help.info.tooltip"));
 183  0
         }
 184  
         
 185  
         @Override
 186  
         public void propertyChange(PropertyChangeEvent event) {
 187  0
                 if (mGlossItemsChangePublisher.isFileOpen() && mGlossItemsChangePublisher.isFileChanged()) {
 188  0
                         mSaveButton.setEnabled(true);
 189  
                 }
 190  
                 
 191  0
                 if (UndoGlossStack.getInstance().undoSize() > 0) {
 192  0
                         mUndo.setEnabled(true);
 193  
                 } else {
 194  0
                         mUndo.setEnabled(false);
 195  
                 }
 196  
                 
 197  0
                 if (UndoGlossStack.getInstance().redoSize() > 0) {
 198  0
                         mRedo.setEnabled(true);
 199  
                 } else {
 200  0
                         mRedo.setEnabled(false);
 201  
                 }
 202  
 
 203  0
                 if (event.getPropertyName().equals(EActionCommands.CREATE_NEW_FILE.toString())) {
 204  0
                         mSaveButton.setEnabled(false);
 205  
                 }
 206  
                 
 207  0
                 if (event.getPropertyName().equals(EActionCommands.CREATE_NEW_FILE.toString()) ||
 208  
                         event.getPropertyName().equals(EActionCommands.OPEN_FILE.toString()) ||
 209  
                         event.getPropertyName().equals(EActionCommands.SAVE_FILE.toString()) ||
 210  
                         event.getPropertyName().equals(EActionCommands.SAVE_FILE_AS.toString()) ) {
 211  0
                         mUndo.setEnabled(false);
 212  0
                         mRedo.setEnabled(false);
 213  
                 }
 214  
                 
 215  0
                 if (event.getPropertyName().equals(EActionCommands.LANGUAGE_CHANGED.toString())) {
 216  0
                         changeLanguage();
 217  
                 }
 218  0
         }
 219  
 }