[jsword-devel] Bug fix patch

DM Smith dmsmith555 at yahoo.com
Wed Aug 25 16:54:30 MST 2004


This patch fixes the tab/window bugs.
I also added some "bells and whistles" to the View menu.
-------------- next part --------------
Index: java/main/org/crosswire/bibledesktop/desktop/Desktop.java
===================================================================
RCS file: /cvs/jsword/bibledesktop/java/main/org/crosswire/bibledesktop/desktop/Desktop.java,v
retrieving revision 1.21
diff -u -r1.21 Desktop.java
--- java/main/org/crosswire/bibledesktop/desktop/Desktop.java	25 Aug 2004 22:55:45 -0000	1.21
+++ java/main/org/crosswire/bibledesktop/desktop/Desktop.java	25 Aug 2004 23:47:17 -0000
@@ -2,7 +2,10 @@
 
 import java.awt.BorderLayout;
 import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
 import java.awt.KeyboardFocusManager;
+import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
@@ -23,6 +26,8 @@
 
 import javax.swing.ButtonGroup;
 import javax.swing.FocusManager;
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JComponent;
 import javax.swing.JFrame;
 import javax.swing.JMenu;
 import javax.swing.JMenuBar;
@@ -31,7 +36,7 @@
 import javax.swing.JRadioButtonMenuItem;
 import javax.swing.JSplitPane;
 import javax.swing.JTextPane;
-import javax.swing.JToolBar;
+import javax.swing.SwingConstants;
 import javax.swing.WindowConstants;
 import javax.swing.event.HyperlinkEvent;
 import javax.swing.event.HyperlinkListener;
@@ -221,8 +226,57 @@
         startJob.done();
         splash.close();
 
+        // Nearly fill up the screen with BibleDesktop, but no larger than 1280x960
+        final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+
+        // Allow an extra 50x100 for window decoration.
+        if (screenSize.width - maxWidth < 50)
+        {
+            maxWidth = screenSize.width - 50;
+        }
+
+        if (screenSize.height - maxHeight < 100)
+        {
+            maxHeight = screenSize.height - 100;
+        }
+
+        final JComponent contentPane = (JComponent) frame.getContentPane();
+        contentPane.setPreferredSize(new Dimension(maxWidth, maxHeight));
+
         frame.pack();
     }
+    
+    /**
+     * @param maxHeight The maxHeight to set.
+     */
+    public static void setMaxHeight(int maxHeight)
+    {
+        Desktop.maxHeight = maxHeight;
+    }
+
+    /**
+     * @return Returns the maxHeight.
+     */
+    public static int getMaxHeight()
+    {
+        return maxHeight;
+    }
+
+    /**
+     * @return Returns the maxWidth.
+     */
+    public static int getMaxWidth()
+    {
+        return maxWidth;
+    }
+
+    /**
+     * @param maxWidth The maxWidth to set.
+     */
+    public static void setMaxWidth(int maxWidth)
+    {
+        Desktop.maxWidth = maxWidth;
+    }
 
     /**
      * Sometimes we need to make some changes to debug the GUI.
@@ -243,8 +297,8 @@
         rdoViewTdi = new JRadioButtonMenuItem(actions.getAction(DesktopActions.TAB_MODE));
         rdoViewMdi = new JRadioButtonMenuItem(actions.getAction(DesktopActions.WINDOW_MODE));
 
-        pnlTbar = new JToolBar();
         barStatus = new StatusBar();
+        pnlTbar = new ToolBar();
         //barSide = new SidebarPane();
         //barBook = new ReferencedPane();
         reference = new DictionaryPane();
@@ -292,6 +346,18 @@
         menuView.add(rdoViewMdi);
         //menuView.add(chkViewTbar);
         menuView.addSeparator();
+        JCheckBoxMenuItem toggle = new JCheckBoxMenuItem(actions.getAction(DesktopActions.TOOLBAR_TOGGLE));
+        toggle.setSelected(true);
+        menuView.add(toggle);
+		menuView.add(new JCheckBoxMenuItem(actions.getAction(DesktopActions.TOOLBAR_TEXT)));
+		menuView.add(new JCheckBoxMenuItem(actions.getAction(DesktopActions.TOOLBAR_LARGE)));
+		toggle = new JCheckBoxMenuItem(actions.getAction(DesktopActions.TOOLTIP_TOGGLE));
+        toggle.setSelected(true);
+		menuView.add(toggle);
+		toggle = new JCheckBoxMenuItem(actions.getAction(DesktopActions.STATUS_TOGGLE));
+        toggle.setSelected(true);
+		menuView.add(toggle);
+        menuView.addSeparator();
         menuView.add(actions.getAction(DesktopActions.VIEW_SOURCE)).addMouseListener(barStatus);
         menuView.setToolTipText(null);
 
@@ -318,7 +384,7 @@
         barMenu.add(menuHelp);
 
         pnlTbar.setRollover(true);
-        pnlTbar.setFloatable(false);
+        pnlTbar.setFloatable(true);
 
         pnlTbar.add(actions.getAction(DesktopActions.NEW_WINDOW)).addMouseListener(barStatus);
         pnlTbar.add(actions.getAction(DesktopActions.OPEN)).addMouseListener(barStatus);
@@ -356,11 +422,19 @@
                 actions.getAction(DesktopActions.EXIT).actionPerformed(new ActionEvent(this, 0, EMPTY_STRING));
             }
         });
+
         frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+
+        // The toolbar needs to be in the outermost container, on the border
+        // And the only other item in that container can be CENTER
         frame.getContentPane().setLayout(new BorderLayout());
         frame.getContentPane().add(pnlTbar, BorderLayout.NORTH);
-        frame.getContentPane().add(barStatus, BorderLayout.SOUTH);
-        frame.getContentPane().add(sptBooks, BorderLayout.CENTER);
+        
+        // Put everything else in its own panel
+        corePanel = new JPanel(new BorderLayout());
+        corePanel.add(barStatus, BorderLayout.SOUTH);
+        corePanel.add(sptBooks, BorderLayout.CENTER);
+        frame.getContentPane().add(corePanel, BorderLayout.CENTER);
         frame.setJMenuBar(barMenu);
 
         frame.setEnabled(true);
@@ -704,41 +778,65 @@
     }
 
     /**
-     * Returns the view_status.
-     * @return boolean
+     * Show or hide the status bar.
+     * @param show boolean
      */
-    public boolean isStatusBarVisible()
+    public void showStatusBar(boolean show)
     {
-        return viewStatus;
+        if (show)
+        {
+            corePanel.add(barStatus, BorderLayout.SOUTH);
+        }
+        else
+        {
+            corePanel.remove(barStatus);
+        }
+        getJFrame().pack(); // cause it to auto resize
     }
 
-    /**
-     * Sets the view_status.
-     * @param view_status The view_status to set
+     /**
+     * Show or hide the tool bar.
+     * @param show boolean
      */
-    public void setStatusBarVisible(boolean view_status)
+    public void showToolBar(boolean show)
     {
-        barStatus.setVisible(true);
-        this.viewStatus = view_status;
+        Container contentPane = getJFrame().getContentPane();
+        if (show)
+        {
+            // Honor the previous orientation
+            // Don't know how to honor the last location
+            if (pnlTbar.getOrientation() == SwingConstants.HORIZONTAL)
+            {
+                contentPane.add(pnlTbar, BorderLayout.NORTH);
+            }
+            else
+            {
+                contentPane.add(pnlTbar, BorderLayout.WEST);
+            }
+        }
+        else
+        {
+            contentPane.remove(pnlTbar);
+        }
+        getJFrame().pack(); // cause it to auto resize
     }
 
     /**
-     * Returns the view_tool.
-     * @return boolean
+     * Show or hide the tool bar text.
+     * @param show boolean
      */
-    public boolean isToolbarVisible()
+    public void showToolBarText(boolean show)
     {
-        return viewTool;
+        pnlTbar.showText(show);
     }
 
     /**
-     * Sets the view_tool.
-     * @param view_tool The view_tool to set
+     * Show large or small tool bar icons.
+     * @param show boolean
      */
-    public void setToolbarVisible(boolean view_tool)
+    public void showToolBarLargeIcons(boolean show)
     {
-        pnlTbar.setVisible(true);
-        this.viewTool = view_tool;
+        pnlTbar.showLargeIcons(show);
     }
 
     /**
@@ -924,21 +1022,21 @@
      * The current way the views are laid out
      */
     private LayoutType current = initial;
-
+    
     /**
-     * The list of BibleViewPanes being viewed in tdi and mdi workspaces
+     * <code>maxHeight</code> of the window
      */
-    private List views = new ArrayList();
+    private static int maxHeight = 1024;
 
     /**
-     * is the status bar visible
+     * <code>maxWidth</code> of the window
      */
-    private boolean viewStatus = true;
+    private static int maxWidth = 2048;
 
     /**
-     * is the toolbar visible
+     * The list of BibleViewPanes being viewed in tdi and mdi workspaces
      */
-    private boolean viewTool = true;
+    private List views = new ArrayList();
 
     /**
      * The last selected BookDataDisplay
@@ -959,7 +1057,8 @@
     private JRadioButtonMenuItem rdoViewMdi;
 
     private JFrame frame;
-    private JToolBar pnlTbar;
+    private JPanel corePanel;
+    private ToolBar pnlTbar;
     private StatusBar barStatus;
     //private SidebarPane barSide;
     //private ReferencedPane barBook = null;
Index: java/main/org/crosswire/bibledesktop/desktop/Desktop.properties
===================================================================
RCS file: /cvs/jsword/bibledesktop/java/main/org/crosswire/bibledesktop/desktop/Desktop.properties,v
retrieving revision 1.1
diff -u -r1.1 Desktop.properties
--- java/main/org/crosswire/bibledesktop/desktop/Desktop.properties	15 Jun 2004 07:33:02 -0000	1.1
+++ java/main/org/crosswire/bibledesktop/desktop/Desktop.properties	25 Aug 2004 23:47:17 -0000
@@ -212,6 +212,56 @@
 WindowMode.AcceleratorKey=
 WindowMode.AcceleratorKey.Modifiers=
 
+ToolBarToggle.Enabled=true
+ToolBarToggle.Name=Show Tool Bar
+ToolBarToggle.ShortDescription=Toggle the display of the tool bar
+ToolBarToggle.LongDescription=Toggle the display of the tool bar
+ToolBarToggle.SmallIcon=
+ToolBarToggle.LargeIcon=
+ToolBarToggle.MnemonicKey=B
+ToolBarToggle.AcceleratorKey=B
+ToolBarToggle.AcceleratorKey.Modifiers=
+
+ToolBarText.Enabled=true
+ToolBarText.Name=Show Tool Bar Text
+ToolBarText.ShortDescription=Toggle the display of the tool bar text
+ToolBarText.LongDescription=Toggle the display of the tool bar text
+ToolBarText.SmallIcon=
+ToolBarText.LargeIcon=
+ToolBarText.MnemonicKey=T
+ToolBarText.AcceleratorKey=T
+ToolBarText.AcceleratorKey.Modifiers=
+
+ToolBarLarge.Enabled=true
+ToolBarLarge.Name=Large Tool Bar
+ToolBarLarge.ShortDescription=Toggle size of the tool bar icons
+ToolBarLarge.LongDescription=Toggle size of the tool bar icons
+ToolBarLarge.SmallIcon=
+ToolBarLarge.LargeIcon=
+ToolBarLarge.MnemonicKey=L
+ToolBarLarge.AcceleratorKey=L
+ToolBarLarge.AcceleratorKey.Modifiers=
+
+ToolTipToggle.Enabled=true
+ToolTipToggle.Name=Show Tool Tips
+ToolTipToggle.ShortDescription=Toggle display of tool tips
+ToolTipToggle.LongDescription=Toggle display of tool tips
+ToolTipToggle.SmallIcon=
+ToolTipToggle.LargeIcon=
+ToolTipToggle.MnemonicKey=T
+ToolTipToggle.AcceleratorKey=T
+ToolTipToggle.AcceleratorKey.Modifiers=ctrl
+
+StatusToggle.Enabled=true
+StatusToggle.Name=Show the Status Area
+StatusToggle.ShortDescription=Toggle display of the status area
+StatusToggle.LongDescription=Toggle display of the status area
+StatusToggle.SmallIcon=
+StatusToggle.LargeIcon=
+StatusToggle.MnemonicKey=A
+StatusToggle.AcceleratorKey=A
+StatusToggle.AcceleratorKey.Modifiers=
+
 ViewSource.Enabled=true
 ViewSource.Name=View Source
 ViewSource.ShortDescription=View HTML and OSIS Source
Index: java/main/org/crosswire/bibledesktop/desktop/DesktopActions.java
===================================================================
RCS file: /cvs/jsword/bibledesktop/java/main/org/crosswire/bibledesktop/desktop/DesktopActions.java,v
retrieving revision 1.12
diff -u -r1.12 DesktopActions.java
--- java/main/org/crosswire/bibledesktop/desktop/DesktopActions.java	25 Aug 2004 22:55:45 -0000	1.12
+++ java/main/org/crosswire/bibledesktop/desktop/DesktopActions.java	25 Aug 2004 23:47:17 -0000
@@ -1,11 +1,14 @@
 package org.crosswire.bibledesktop.desktop;
 
+import java.awt.event.ActionEvent;
 import java.io.IOException;
 import java.net.URL;
 import java.util.Iterator;
 
 import javax.swing.Action;
+import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JOptionPane;
+import javax.swing.ToolTipManager;
 
 import org.crosswire.bibledesktop.book.BibleViewPane;
 import org.crosswire.bibledesktop.book.SitesPane;
@@ -56,7 +59,7 @@
  * @see gnu.gpl.Licence
  * @author Joe Walker [joe at eireneh dot com]
  * @author DM Smith [dmsmith555 at hotmail dot com]
- * @version $Id: DesktopActions.java,v 1.12 2004/08/25 22:55:45 joe Exp $
+ * @version $Id: DesktopActions.java,v 1.11 2004/08/16 22:09:20 joe Exp $
  */
 public class DesktopActions
 {
@@ -263,7 +266,7 @@
      */
     public void doWindowMode()
     {
-        getDesktop().setLayoutType(LayoutType.TDI);
+        getDesktop().setLayoutType(LayoutType.MDI);
     }
 
     /**
@@ -373,6 +376,51 @@
         atp.showInDialog(getDesktop().getJFrame());
     }
 
+    /**
+     * Show or hide the tool bar.
+     */
+    public void doToolBarToggle(ActionEvent ev)
+    {
+        JCheckBoxMenuItem toggle = (JCheckBoxMenuItem) ev.getSource();
+        desktop.showToolBar(toggle.isSelected());
+    }
+
+    /**
+     * Show or hide the tool bar text.
+     */
+    public void doToolBarText(ActionEvent ev)
+    {
+        JCheckBoxMenuItem toggle = (JCheckBoxMenuItem) ev.getSource();
+        desktop.showToolBarText(toggle.isSelected());
+    }
+
+    /**
+     * Show large or small tool bar icons.
+     */
+    public void doToolBarLarge(ActionEvent ev)
+    {
+        JCheckBoxMenuItem toggle = (JCheckBoxMenuItem) ev.getSource();
+        desktop.showToolBarLargeIcons(toggle.isSelected());
+    }
+
+    /**
+     * Show large or small tool bar icons.
+     */
+    public void doToolTipToggle(ActionEvent ev)
+    {
+        JCheckBoxMenuItem toggle = (JCheckBoxMenuItem) ev.getSource();
+        ToolTipManager.sharedInstance().setEnabled(toggle.isSelected());
+    }
+
+    /**
+     * Show large or small tool bar icons.
+     */
+    public void doStatusToggle(ActionEvent ev)
+    {
+        JCheckBoxMenuItem toggle = (JCheckBoxMenuItem) ev.getSource();
+        desktop.showStatusBar(toggle.isSelected());
+    }
+
     // Enumeration of all the keys to known actions
     static final String FILE = "File"; //$NON-NLS-1$
     static final String EDIT = "Edit"; //$NON-NLS-1$
@@ -390,6 +438,11 @@
     static final String COPY = "Copy"; //$NON-NLS-1$
     static final String TAB_MODE = "TabMode"; //$NON-NLS-1$
     static final String WINDOW_MODE = "WindowMode"; //$NON-NLS-1$
+    static final String TOOLBAR_TOGGLE = "ToolBarToggle"; //$NON-NLS-1$
+    static final String TOOLBAR_TEXT = "ToolBarText"; //$NON-NLS-1$
+    static final String TOOLBAR_LARGE = "ToolBarLarge"; //$NON-NLS-1$
+    static final String TOOLTIP_TOGGLE = "ToolTipToggle"; //$NON-NLS-1$
+    static final String STATUS_TOGGLE = "StatusToggle"; //$NON-NLS-1$
     static final String VIEW_SOURCE = "ViewSource"; //$NON-NLS-1$
     static final String BOOKS = "Books"; //$NON-NLS-1$
     static final String OPTIONS = "Options"; //$NON-NLS-1$
Index: resource/config.properties
===================================================================
RCS file: /cvs/jsword/bibledesktop/resource/config.properties,v
retrieving revision 1.1
diff -u -r1.1 config.properties
--- resource/config.properties	25 Jun 2004 15:01:40 -0000	1.1
+++ resource/config.properties	25 Aug 2004 23:47:17 -0000
@@ -37,6 +37,10 @@
 Application.InitialLayout.help=Do you want to start in SDI, TDI or MDI view mode
 Application.InitialLayout.alternative.0=Tabbed Document Interface
 Application.InitialLayout.alternative.1=Multiple Document Interface
+Application.MaxHeight.path=Application.Maximum Window Height
+Application.MaxHeight.help=The maximum height you want the window to be
+Application.MaxWidth.path=Application.Maximum Window Width
+Application.MaxWidth.help=The maximum width you want the window to be
 BibleDisplay.Converter.path=Bible Display.Converter
 BibleDisplay.Converter.help=The engine used to genterate the book display
 BibleDisplay.ConfigurableStylesheet.path=Bible Display.Configurable Stylesheet
Index: resource/config.xml
===================================================================
RCS file: /cvs/jsword/bibledesktop/resource/config.xml,v
retrieving revision 1.8
diff -u -r1.8 config.xml
--- resource/config.xml	25 Aug 2004 22:55:45 -0000	1.8
+++ resource/config.xml	25 Aug 2004 23:47:18 -0000
@@ -101,6 +101,14 @@
     <alternative number="1"/>
   </option>
 
+  <option key="Application.MaxWidth" type="number">
+    <introspect class="org.crosswire.bibledesktop.desktop.Desktop" property="MaxWidth"/>
+  </option>
+
+  <option key="Application.MaxHeight" type="number">
+    <introspect class="org.crosswire.bibledesktop.desktop.Desktop" property="MaxHeight"/>
+  </option>
+
   <option key="BibleDisplay.Converter" type="string-options">
     <introspect class="org.crosswire.jsword.util.ConverterFactory" property="CurrentConverterName"/>
     <map name="converters"/>
Index: java/main/org/crosswire/bibledesktop/desktop/ToolBar.java
===================================================================
RCS file: java/main/org/crosswire/bibledesktop/desktop/ToolBar.java
diff -N java/main/org/crosswire/bibledesktop/desktop/ToolBar.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ java/main/org/crosswire/bibledesktop/desktop/ToolBar.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,108 @@
+package org.crosswire.bibledesktop.desktop;
+
+import java.awt.Component;
+
+import javax.swing.Action;
+import javax.swing.Icon;
+import javax.swing.JButton;
+import javax.swing.JToolBar;
+
+import org.crosswire.common.swing.CWAction;
+
+/**
+ * This toolbar allows for<ul>
+ * <li>showing/hiding labels</li>
+ * <li>small/large icons</li>
+ * <li>showing/hiding toolbar</li>
+ * </ul>
+ * 
+ * <p><table border='1' cellPadding='3' cellSpacing='0'>
+ * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
+ *
+ * Distribution Licence:<br />
+ * JSword is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.<br />
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.<br />
+ * The License is available on the internet
+ * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA<br />
+ * The copyright to this program is held by it's authors.
+ * </font></td></tr></table>
+ * @see gnu.gpl.Licence
+ * @author DM Smith [ dmsmith555 at hotmail dot com]
+ * @version $Id$
+ */
+public class ToolBar extends JToolBar
+{
+    /**
+	 * ToolBar constructor.
+	 */
+	public ToolBar()
+	{
+	}
+
+	/**
+	 * Set the tool tip text for the buttons on the tool bar.
+	 * @param show boolean
+	 */
+	public void showText(boolean show)
+	{
+		Component c;
+		int i = 0;
+		while ((c = getComponentAtIndex(i++)) != null)
+		{
+			if (c instanceof JButton)
+			{
+				JButton button = (JButton) c;
+				if (show)
+				{
+					Action action = button.getAction();
+					button.setText((String)action.getValue(Action.SHORT_DESCRIPTION));
+				}
+				else
+				{
+					button.setText(null);
+				}
+			}
+		}
+	}
+
+	/**
+	 * Sets the size of the tool bar button images.
+	 * @param show boolean
+	 * 
+	 */
+	public void showLargeIcons(boolean show)
+	{
+		Component c;
+		int i = 0;
+		while ((c = getComponentAtIndex(i++)) != null)
+		{
+			if (c instanceof JButton)
+			{
+				JButton button = (JButton) c;
+				Action action = button.getAction();
+				if (action instanceof CWAction)
+				{
+					// Clear the button's computed disabled icon
+					// so the button can get it again.
+					button.setDisabledIcon(null);
+					if (show)
+					{
+						button.setIcon((Icon) action.getValue(CWAction.LARGE_ICON));
+					}
+					else
+					{
+						button.setIcon((Icon) action.getValue(Action.SMALL_ICON));
+					}
+				}
+			}
+		}
+	}
+
+}


More information about the jsword-devel mailing list