Coverage Report - org.omegat.util.gui.DockingUI
 
Classes in this File Line Coverage Branch Coverage Complexity
DockingUI
96%
72/75
64%
9/14
2.75
 
 1  
 /**************************************************************************
 2  
  OmegaT - Computer Assisted Translation (CAT) tool 
 3  
           with fuzzy matching, translation memory, keyword search, 
 4  
           glossaries, and translation leveraging into updated projects.
 5  
 
 6  
  Copyright (C) 2000-2006 Keith Godfrey, Maxym Mykhalchuk, Henry Pijffers, 
 7  
                          Benjamin Siband, and Kim Bruning
 8  
                2007 Zoltan Bartko
 9  
                2008 Andrzej Sawula
 10  
  Portions copyright 2008 Alex Buloichik
 11  
                Home page: http://www.omegat.org/
 12  
                Support center: http://groups.yahoo.com/group/OmegaT/
 13  
 
 14  
  This program is free software; you can redistribute it and/or modify
 15  
  it under the terms of the GNU General Public License as published by
 16  
  the Free Software Foundation; either version 2 of the License, or
 17  
  (at your option) any later version.
 18  
 
 19  
  This program is distributed in the hope that it will be useful,
 20  
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 21  
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 22  
  GNU General Public License for more details.
 23  
 
 24  
  You should have received a copy of the GNU General Public License
 25  
  along with this program; if not, write to the Free Software
 26  
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 27  
  **************************************************************************/
 28  
 
 29  
 package org.omegat.util.gui;
 30  
 
 31  
 import java.awt.Dimension;
 32  
 import java.awt.Point;
 33  
 import java.awt.Window;
 34  
 
 35  
 import javax.swing.ImageIcon;
 36  
 import javax.swing.JLabel;
 37  
 import javax.swing.JPopupMenu;
 38  
 import javax.swing.JSeparator;
 39  
 import javax.swing.UIManager;
 40  
 
 41  
 import org.omegat.core.Core;
 42  
 import org.omegat.util.OStrings;
 43  
 
 44  
 import com.vlsolutions.swing.docking.ui.DockingUISettings;
 45  
 
 46  
 /**
 47  
  * Docking UI support.
 48  
  */
 49  0
 public class DockingUI {
 50  
 
 51  
     /**
 52  
      * Initialize docking subsystem.
 53  
      */
 54  
     public static void initialize() {
 55  3605
         DockingUISettings.getInstance().installUI();
 56  3605
         UIManager.put("DockViewTitleBar.minimizeButtonText", OStrings.getString("DOCKING_HINT_MINIMIZE"));
 57  3605
         UIManager.put("DockViewTitleBar.maximizeButtonText", OStrings.getString("DOCKING_HINT_MAXIMIZE"));
 58  3605
         UIManager.put("DockViewTitleBar.restoreButtonText", OStrings.getString("DOCKING_HINT_RESTORE"));
 59  3605
         UIManager.put("DockViewTitleBar.attachButtonText", OStrings.getString("DOCKING_HINT_DOCK"));
 60  3605
         UIManager.put("DockViewTitleBar.floatButtonText", OStrings.getString("DOCKING_HINT_UNDOCK"));
 61  3605
         UIManager.put("DockViewTitleBar.closeButtonText", new String());
 62  3605
         UIManager.put("DockTabbedPane.minimizeButtonText", OStrings.getString("DOCKING_HINT_MINIMIZE"));
 63  3605
         UIManager.put("DockTabbedPane.maximizeButtonText", OStrings.getString("DOCKING_HINT_MAXIMIZE"));
 64  3605
         UIManager.put("DockTabbedPane.restoreButtonText", OStrings.getString("DOCKING_HINT_RESTORE"));
 65  3605
         UIManager.put("DockTabbedPane.floatButtonText", OStrings.getString("DOCKING_HINT_UNDOCK"));
 66  3605
         UIManager.put("DockTabbedPane.closeButtonText", new String());
 67  
 
 68  3605
         UIManager.put("DockViewTitleBar.titleFont", new JLabel().getFont());
 69  
 
 70  3605
         UIManager.put("DockViewTitleBar.isCloseButtonDisplayed", Boolean.FALSE);
 71  
 
 72  3605
         UIManager.put("DockViewTitleBar.hide", getIcon("minimize.gif"));
 73  3605
         UIManager.put("DockViewTitleBar.hide.rollover", getIcon("minimize.rollover.gif"));
 74  3605
         UIManager.put("DockViewTitleBar.hide.pressed", getIcon("minimize.pressed.gif"));
 75  3605
         UIManager.put("DockViewTitleBar.maximize", getIcon("maximize.gif"));
 76  3605
         UIManager.put("DockViewTitleBar.maximize.rollover", getIcon("maximize.rollover.gif"));
 77  3605
         UIManager.put("DockViewTitleBar.maximize.pressed", getIcon("maximize.pressed.gif"));
 78  3605
         UIManager.put("DockViewTitleBar.restore", getIcon("restore.gif"));
 79  3605
         UIManager.put("DockViewTitleBar.restore.rollover", getIcon("restore.rollover.gif"));
 80  3605
         UIManager.put("DockViewTitleBar.restore.pressed", getIcon("restore.pressed.gif"));
 81  3605
         UIManager.put("DockViewTitleBar.dock", getIcon("restore.gif"));
 82  3605
         UIManager.put("DockViewTitleBar.dock.rollover", getIcon("restore.rollover.gif"));
 83  3605
         UIManager.put("DockViewTitleBar.dock.pressed", getIcon("restore.pressed.gif"));
 84  3605
         UIManager.put("DockViewTitleBar.float", getIcon("undock.gif"));
 85  3605
         UIManager.put("DockViewTitleBar.float.rollover", getIcon("undock.rollover.gif"));
 86  3605
         UIManager.put("DockViewTitleBar.float.pressed", getIcon("undock.pressed.gif"));
 87  3605
         UIManager.put("DockViewTitleBar.attach", getIcon("dock.gif"));
 88  3605
         UIManager.put("DockViewTitleBar.attach.rollover", getIcon("dock.rollover.gif"));
 89  3605
         UIManager.put("DockViewTitleBar.attach.pressed", getIcon("dock.pressed.gif"));
 90  
 
 91  3605
         UIManager.put("DockViewTitleBar.menu.hide", getIcon("minimize.gif"));
 92  3605
         UIManager.put("DockViewTitleBar.menu.maximize", getIcon("maximize.gif"));
 93  3605
         UIManager.put("DockViewTitleBar.menu.restore", getIcon("restore.gif"));
 94  3605
         UIManager.put("DockViewTitleBar.menu.dock", getIcon("restore.gif"));
 95  3605
         UIManager.put("DockViewTitleBar.menu.float", getIcon("undock.gif"));
 96  3605
         UIManager.put("DockViewTitleBar.menu.attach", getIcon("dock.gif"));
 97  
 
 98  3605
         UIManager.put("DockViewTitleBar.menu.close", getIcon("empty.gif"));
 99  3605
         UIManager.put("DockTabbedPane.close", getIcon("empty.gif"));
 100  3605
         UIManager.put("DockTabbedPane.close.rollover", getIcon("empty.gif"));
 101  3605
         UIManager.put("DockTabbedPane.close.pressed", getIcon("empty.gif"));
 102  3605
         UIManager.put("DockTabbedPane.menu.close", getIcon("empty.gif"));
 103  3605
         UIManager.put("DockTabbedPane.menu.hide", getIcon("empty.gif"));
 104  3605
         UIManager.put("DockTabbedPane.menu.maximize", getIcon("empty.gif"));
 105  3605
         UIManager.put("DockTabbedPane.menu.float", getIcon("empty.gif"));
 106  3605
         UIManager.put("DockTabbedPane.menu.closeAll", getIcon("empty.gif"));
 107  3605
         UIManager.put("DockTabbedPane.menu.closeAllOther", getIcon("empty.gif"));
 108  
 
 109  3605
         UIManager.put("DockingDesktop.closeActionAccelerator", null);
 110  3605
         UIManager.put("DockingDesktop.maximizeActionAccelerator", null);
 111  3605
         UIManager.put("DockingDesktop.dockActionAccelerator", null);
 112  3605
         UIManager.put("DockingDesktop.floatActionAccelerator", null);
 113  
 
 114  3605
         UIManager.put("DragControler.detachCursor", getIcon("undock.gif").getImage());
 115  3605
     }
 116  
 
 117  
     /**
 118  
      * Load icon from classpath.
 119  
      * 
 120  
      * @param iconName
 121  
      *            icon file name
 122  
      * @return icon instance
 123  
      */
 124  
     private static ImageIcon getIcon(final String iconName) {
 125  126175
         return ResourcesUtil.getIcon("/org/omegat/gui/resources/" + iconName);
 126  
     }
 127  
 
 128  
     /**
 129  
      * Move window to the center of main window.
 130  
      * 
 131  
      * @param window
 132  
      *            window
 133  
      */
 134  
     public static void displayCentered(final Window window) {
 135  6
         Point mLocation = Core.getMainWindow().getApplicationFrame().getLocation();
 136  6
         Dimension mSize = Core.getMainWindow().getApplicationFrame().getSize();
 137  
 
 138  6
         Point mCenter = new Point();
 139  6
         mCenter.x = mLocation.x + mSize.width / 2;
 140  6
         mCenter.y = mLocation.y + mSize.height / 2;
 141  
 
 142  6
         Dimension dSize = window.getSize();
 143  6
         Point dLocation = new Point();
 144  6
         dLocation.x = mCenter.x - dSize.width / 2;
 145  6
         dLocation.y = mCenter.y - dSize.height / 2;
 146  6
         window.setLocation(dLocation);
 147  6
     }
 148  
 
 149  
     /**
 150  
      * Removes first, last and duplicate separators from menu.
 151  
      */
 152  
     public static void removeUnusedMenuSeparators(final JPopupMenu menu) {
 153  3605
         if (menu.getComponentCount() > 0 && menu.getComponent(0) instanceof JSeparator) {
 154  
             // remove first separator
 155  0
             menu.remove(0);
 156  
         }
 157  3605
         if (menu.getComponentCount() > 0
 158  
                 && menu.getComponent(menu.getComponentCount() - 1) instanceof JSeparator) {
 159  
             // remove last separator
 160  3605
             menu.remove(menu.getComponentCount() - 1);
 161  
         }
 162  57680
         for (int i = 0; i < menu.getComponentCount() - 1; i++) {
 163  54075
             if (menu.getComponent(i) instanceof JSeparator && menu.getComponent(i + 1) instanceof JSeparator) {
 164  
                 // remove duplicate separators
 165  0
                 menu.remove(i);
 166  
             }
 167  
         }
 168  3605
     }
 169  
 }