Update of /cvsroot/squirrel-sql/mavenize/thirdparty-non-maven/toniclf-1.0.5/src/com/digitprop/tonic
In directory sfp-cvsdas-3.v30.ch3.sourceforge.com:/tmp/cvs-serv25311/thirdparty-non-maven/toniclf-1.0.5/src/com/digitprop/tonic
Added Files:
MenuUI.java ScrollPaneUI.java ToolBarMarginBorder.java
ToggleButtonUI.java ScrollButton.java CheckBoxMenuItemUI.java
OptionalMatteBorder.java ProgressBarUI.java TabbedPaneUI.java
ButtonUI.java TableHeaderUI.java SpinnerUI.java
VerticalFlowLayout.java TonicBumps.java
TonicDropTargetListener.java ComboBoxUI.java LabelUI.java
PopupMenuSeparatorUI.java ButtonBorder.java GrayedIcon.java
MenuItemUI.java RadioButtonMenuItemUI.java TonicUtils.java
RadioButtonUI.java IntelligentLineBorder.java
TonicDragGestureRecognizer.java TonicTransferable.java
ToolBarUI.java RootPaneUI.java SliderUI.java SplitPaneUI.java
SplitPaneContentBorder.java CheckBoxUI.java
TonicLookAndFeel.java Borders.java SeparatorUI.java
ToolButtonUI.java ArrowButton.java OptionPaneUI.java
ScrollBarUI.java VariableGridLayout.java TitlePane.java
TableUI.java TonicScrollPaneLayout.java ToolButton.java
InternalFrameUI.java ComboBoxButton.java FileChooserUI.java
MenuBarUI.java InternalFrameBorder.java DesktopIconUI.java
SplitPaneDivider.java ToolBarBorder.java
InternalFrameTitlePane.java
Log Message:
source for thirdparty dependency.
--- NEW FILE: TonicDropTargetListener.java ---
package com.digitprop.tonic;
import java.awt.*;
import java.awt.dnd.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.UIResource;
import javax.swing.Timer;
/** The Swing DropTarget implementation supports multicast notification
* to listeners, so this implementation is used as an additional
* listener that extends the primary drop target functionality
* (i.e. linkage to the TransferHandler) to include autoscroll and
* establish an insertion point for the drop. This is used by the ComponentUI
* of components supporting a selection mechanism, which have a
* way of indicating a location within their model.<p>
*
* The autoscroll functionality is based upon the Swing scrolling mechanism
* of the Scrollable interface. The unit scroll increment is used to as
* the scroll amount, and the scrolling is based upon JComponent.getVisibleRect
* and JComponent.scrollRectToVisible. The band of area around the visible
* rectangle used to invoke autoscroll is based upon the unit scroll increment
* as that is assumed to represent the last possible item in the visible region.<p>
*
* The subclasses are expected to implement the following methods to manage the
* insertion location via the components selection mechanism.
*
* <ul>
* <li>saveComponentState
* <li>restoreComponentState
* <li>restoreComponentStateForDrop
* <li>updateInsertionLocation
* </ul>
*
* @author Markus Fischer
*
* <p>This software is under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank">GNU Lesser General Public License</a>
*/
/*
* ------------------------------------------------------------------------
* Copyright (C) 2004 Markus Fischer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* You can contact the author at:
* Markus Fischer
* www.digitprop.com
* in...@di...
* ------------------------------------------------------------------------
*/
class TonicDropTargetListener implements DropTargetListener, UIResource, ActionListener
{
/**
* construct a DropTargetAutoScroller
* <P>
* @param c the <code>Component</code>
* @param p the <code>Point</code>
*/
protected TonicDropTargetListener()
{
}
/**
* called to save the state of a component in case it needs to
* be restored because a drop is not performed.
*/
protected void saveComponentState(JComponent c)
{
}
/**
* called to restore the state of a component in case a drop
* is not performed.
*/
protected void restoreComponentState(JComponent c)
{
}
/**
* called to restore the state of a component in case a drop
* is performed.
*/
protected void restoreComponentStateForDrop(JComponent c)
{
}
/**
* called to set the insertion location to match the current
* mouse pointer coordinates.
*/
protected void updateInsertionLocation(JComponent c, Point p)
{
}
/**
* Update the geometry of the autoscroll region. The geometry is
* maintained as a pair of rectangles. The region can cause
* a scroll if the pointer sits inside it for the duration of the
* timer. The region that causes the timer countdown is the area
* between the two rectangles.
* <p>
* This is implemented to use the visible area of the component
* as the outer rectangle and the insets are based upon the
* Scrollable information (if any). If the Scrollable is
* scrollable along an axis, the step increment is used as
* the autoscroll inset. If the component is not scrollable,
* the insets will be zero (i.e. autoscroll will not happen).
*/
void updateAutoscrollRegion(JComponent c)
{
// compute the outer
Rectangle visible= c.getVisibleRect();
outer.reshape(visible.x, visible.y, visible.width, visible.height);
// compute the insets
// TBD - the thing with the scrollable
Insets i= new Insets(0, 0, 0, 0);
if (c instanceof Scrollable)
{
Scrollable s= (Scrollable) c;
i.left=
s.getScrollableUnitIncrement(visible, SwingConstants.HORIZONTAL, 1);
i.top=
s.getScrollableUnitIncrement(visible, SwingConstants.VERTICAL, 1);
i.right=
s.getScrollableUnitIncrement(
visible,
SwingConstants.HORIZONTAL,
-1);
i.bottom=
s.getScrollableUnitIncrement(visible, SwingConstants.VERTICAL, -1);
}
// set the inner from the insets
inner.reshape(
visible.x + i.left,
visible.y + i.top,
visible.width - (i.left + i.right),
visible.height - (i.top + i.bottom));
}
/**
* Perform an autoscroll operation. This is implemented to scroll by the
* unit increment of the Scrollable using scrollRectToVisible. If the
* cursor is in a corner of the autoscroll region, more than one axis will
* scroll.
*/
void autoscroll(JComponent c, Point pos)
{
if (c instanceof Scrollable)
{
Scrollable s= (Scrollable) c;
if (pos.y < inner.y)
{
// scroll top downward
int dy=
s.getScrollableUnitIncrement(outer, SwingConstants.VERTICAL, 1);
Rectangle r= new Rectangle(inner.x, outer.y - dy, inner.width, dy);
c.scrollRectToVisible(r);
}
else if (pos.y > (inner.y + inner.height))
{
// scroll bottom upward
int dy=
s.getScrollableUnitIncrement(outer, SwingConstants.VERTICAL, -1);
Rectangle r=
new Rectangle(inner.x, outer.y + outer.height, inner.width, dy);
c.scrollRectToVisible(r);
}
if (pos.x < inner.x)
{
// scroll left side to the right
int dx=
s.getScrollableUnitIncrement(
outer,
SwingConstants.HORIZONTAL,
1);
Rectangle r= new Rectangle(outer.x - dx, inner.y, dx, inner.height);
c.scrollRectToVisible(r);
}
else if (pos.x > (inner.x + inner.width))
{
// scroll right side to the left
int dx=
s.getScrollableUnitIncrement(
outer,
SwingConstants.HORIZONTAL,
-1);
Rectangle r=
new Rectangle(outer.x + outer.width, inner.y, dx, inner.height);
c.scrollRectToVisible(r);
}
}
}
/**
* Initializes the internal properties if they haven't been already
* inited. This is done lazily to avoid loading of desktop properties.
*/
private void initPropertiesIfNecessary()
{
if (timer == null)
{
Toolkit t= Toolkit.getDefaultToolkit();
Integer initial= new Integer(100);
Integer interval= new Integer(100);
try
{
initial=
(Integer) t.getDesktopProperty("DnD.Autoscroll.initialDelay");
}
catch (Exception e)
{
// ignore
}
try
{
interval= (Integer) t.getDesktopProperty("DnD.Autoscroll.interval");
}
catch (Exception e)
{
// ignore
}
timer= new Timer(interval.intValue(), this);
timer.setCoalesce(true);
timer.setInitialDelay(initial.intValue());
try
{
hysteresis=
((Integer) t
.getDesktopProperty("DnD.Autoscroll.cursorHysteresis"))
.intValue();
}
catch (Exception e)
{
// ignore
}
}
}
static JComponent getComponent(DropTargetEvent e)
{
DropTargetContext context= e.getDropTargetContext();
return (JComponent) context.getComponent();
}
// --- ActionListener methods --------------------------------------
/**
* The timer fired, perform autoscroll if the pointer is within the
* autoscroll region.
* <P>
* @param e the <code>ActionEvent</code>
*/
public synchronized void actionPerformed(ActionEvent e)
{
updateAutoscrollRegion(component);
if (outer.contains(lastPosition) && !inner.contains(lastPosition))
{
autoscroll(component, lastPosition);
}
}
// --- DropTargetListener methods -----------------------------------
public void dragEnter(DropTargetDragEvent e)
{
component= getComponent(e);
TransferHandler th= component.getTransferHandler();
canImport= th.canImport(component, e.getCurrentDataFlavors());
if (canImport)
{
saveComponentState(component);
lastPosition= e.getLocation();
updateAutoscrollRegion(component);
initPropertiesIfNecessary();
}
}
public void dragOver(DropTargetDragEvent e)
{
if (canImport)
{
Point p= e.getLocation();
updateInsertionLocation(component, p);
// check autoscroll
synchronized (this)
{
if (Math.abs(p.x - lastPosition.x) > hysteresis
|| Math.abs(p.y - lastPosition.y) > hysteresis)
{
// no autoscroll
if (timer.isRunning())
timer.stop();
}
else
{
if (!timer.isRunning())
timer.start();
}
lastPosition= p;
}
}
}
public void dragExit(DropTargetEvent e)
{
if (canImport)
{
restoreComponentState(component);
}
cleanup();
}
public void drop(DropTargetDropEvent e)
{
if (canImport)
{
restoreComponentStateForDrop(component);
}
cleanup();
}
public void dropActionChanged(DropTargetDragEvent e)
{
}
/**
* Cleans up internal state after the drop has finished (either succeeded
* or failed).
*/
private void cleanup()
{
if (timer != null)
{
timer.stop();
}
component= null;
lastPosition= null;
}
// --- fields --------------------------------------------------
private Timer timer;
private Point lastPosition;
private Rectangle outer= new Rectangle();
private Rectangle inner= new Rectangle();
private int hysteresis= 10;
private boolean canImport;
/**
* The current component. The value is cached from the drop events and used
* by the timer. When a drag exits or a drop occurs, this value is cleared.
*/
private JComponent component;
}
--- NEW FILE: SplitPaneContentBorder.java ---
package com.digitprop.tonic;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
/** Border which can be used for the two components nested inside a JSplitPane.
* This border has a shadowed left and bottom edge, making the components contained
* in the JSplitPane appear to be raised.
*
* @author Markus Fischer
*
* <p>This software is under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank">GNU Lesser General Public License</a>
*/
/*
* ------------------------------------------------------------------------
* Copyright (C) 2004 Markus Fischer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* You can contact the author at:
* Markus Fischer
* www.digitprop.com
* in...@di...
* ------------------------------------------------------------------------
*/
public class SplitPaneContentBorder implements Border
{
/** The first color for the shadow gradient */
private Color fromColor;
/** The second color for the shadow gradient */
private Color toColor;
/** The background color */
private Color bg;
/** If true, draws a line around the bordered component */
private boolean drawBoundaryLine;
/** Creates an instance. The colors will be the default colors provided
* by the Tonic Look and Feel, and there will be no additional single-pixel
* line drawn around the enclosed component.
*/
public SplitPaneContentBorder()
{
this(null, null, null, false);
}
/** Creates an instance. The colors will be the default colors provided
* by the Tonic Look and Feel.
*
* @param drawBoundaryLine If true, there will be an additional
* single-pixel line drawn around the
* enclosed component.
*/
public SplitPaneContentBorder(boolean drawBoundaryLine)
{
this(null, null, null, drawBoundaryLine);
}
/** Creates an instance. There will be no additional single-pixel
* line drawn around the enclosed component.
*
* @param bg Background color of the JSplitPane
* @param fromColor First (dark) shadow gradient color
* @param toColor Second (light) shadow gradient color
*/
public SplitPaneContentBorder(Color bg, Color fromColor, Color toColor)
{
this(bg, fromColor, toColor, false);
}
/** Creates an instance.
*
* @param bg Background color of the JSplitPane
* @param fromColor First (dark) shadow gradient color
* @param toColor Second (light) shadow gradient color
* @param drawBoundaryLine If true, there will be an additional
* single-pixel line drawn around the
* enclosed component.
*/
public SplitPaneContentBorder(Color bg, Color fromColor, Color toColor, boolean drawBoundaryLine)
{
this.drawBoundaryLine=drawBoundaryLine;
if(bg!=null)
this.bg=bg;
else
this.bg=UIManager.getColor("Button.borderColor");
if(fromColor!=null)
this.fromColor=fromColor;
else
this.fromColor=UIManager.getColor("Button.borderColor");
if(toColor!=null)
this.toColor=toColor;
else
this.toColor=UIManager.getColor("control");
}
/** Returns the insets of this border */
public Insets getBorderInsets(Component c)
{
int leftTop=(drawBoundaryLine ? 1 : 0);
int rightBottom=(drawBoundaryLine ? 4 : 3);
return new Insets(leftTop, leftTop, rightBottom, rightBottom);
}
/** Returns true if this border is opaque */
public boolean isBorderOpaque()
{
return false;
}
/** Paints this border.
*
* @param c The component for which to draw the border
* @param g The graphics context into which to paint
* @param x The left edge of the border
* @param y The top edge of the border
* @param width The width of the border
* @param height The height of the border
*/
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
{
g.setColor(toColor);
g.fillRect(x, y+height-3, 3, 3);
g.fillRect(x+width-3, y, 3, 3);
for(int i=0; i<3; i++)
{
g.setColor(blendColors(fromColor, toColor, (double)(i+2)/(double)4));
g.drawLine(x+width-3+i, y+i+1, x+width-3+i, y+height-3+i);
g.drawLine(x+i+1, y+height-3+i, x+width-3+i, y+height-3+i);
}
if(drawBoundaryLine)
{
g.setColor(bg);
g.drawRect(x, y, x+width-4, y+height-4);
}
}
/** Blends two colors.
*
* @param c1 The first color
* @param c2 The second color
* @param factor The ratio between the first and second color. If this is 0.0,
* the result will be c1, if it is 1.0, the result will be c2.
*
* @return A color resulting from blending c1 and c2
*/
private Color blendColors(Color c1, Color c2, double factor)
{
if(c1==null || c2==null)
{
if(c1!=null)
return c1;
else if(c2!=null)
return c2;
else
return Color.BLACK;
}
int r=(int)(c2.getRed()*factor+c1.getRed()*(1.0-factor));
int g=(int)(c2.getGreen()*factor+c1.getGreen()*(1.0-factor));
int b=(int)(c2.getBlue()*factor+c1.getBlue()*(1.0-factor));
return new Color(r,g,b);
}
}
--- NEW FILE: RadioButtonMenuItemUI.java ---
package com.digitprop.tonic;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.*;
/** UI delegate for the JRadioButtonMenuItem.
*
* @author Markus Fischer
*
* <p>This software is under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank">GNU Lesser General Public License</a>
*/
/*
* ------------------------------------------------------------------------
* Copyright (C) 2004 Markus Fischer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* You can contact the author at:
* Markus Fischer
* www.digitprop.com
* in...@di...
* ------------------------------------------------------------------------
*/
public class RadioButtonMenuItemUI extends com.digitprop.tonic.MenuItemUI
{
/** Creates and returns a UI delegate for the specified component */
public static ComponentUI createUI(JComponent component)
{
return new com.digitprop.tonic.RadioButtonMenuItemUI();
}
/** Returns the property prefix for RadioButtonMenuItems */
protected String getPropertyPrefix()
{
return "RadioButtonMenuItem";
}
/** Processes a mouse event for the associated JRadioButtonMenuItem.
*
* @param item The item for which to process the event
* @param e The mouse event
* @param path The menu tree path to this item
* @param manager The menu selection manager
*/
public void processMouseEvent(JMenuItem item, MouseEvent e, MenuElement path[], MenuSelectionManager manager)
{
Point p= e.getPoint();
if (p.x >= 0
&& p.x < item.getWidth()
&& p.y >= 0
&& p.y < item.getHeight())
{
if (e.getID() == MouseEvent.MOUSE_RELEASED)
{
manager.clearSelectedPath();
item.doClick(0);
item.setArmed(false);
}
else
manager.setSelectedPath(path);
}
else if (item.getModel().isArmed())
{
MenuElement newPath[]= new MenuElement[path.length - 1];
int i, c;
for (i= 0, c= path.length - 1; i < c; i++)
newPath[i]= path[i];
manager.setSelectedPath(newPath);
}
}
}
--- NEW FILE: SplitPaneDivider.java ---
package com.digitprop.tonic;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.basic.*;
/** Divider for JSplitPanes.
*
* @author Markus Fischer
*
* <p>This software is under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank">GNU Lesser General Public License</a>
*/
/*
* ------------------------------------------------------------------------
* Copyright (C) 2004 Markus Fischer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* You can contact the author at:
* Markus Fischer
* www.digitprop.com
* in...@di...
* ------------------------------------------------------------------------
*/
class SplitPaneDivider extends BasicSplitPaneDivider
{
private int inset=2;
private Color controlColor=TonicLookAndFeel.getControl();
private Color primaryControlColor=TonicLookAndFeel.getPrimaryControl();
private BasicSplitPaneUI ui;
private int oneTouchSize;
private int standardSize;
public SplitPaneDivider(BasicSplitPaneUI ui)
{
super(ui);
this.ui=ui;
standardSize=UIManager.getInt("SplitPane.dividerSize");
oneTouchSize=UIManager.getInt("SplitPane.oneTouchDividerSize");
setLayout(new MetalDividerLayout());
}
protected void oneTouchExpandableChanged()
{
super.oneTouchExpandableChanged();
if(ui.getSplitPane()!=null && ui.getSplitPane().isOneTouchExpandable())
setDividerSize(oneTouchSize);
else
setDividerSize(standardSize);
}
public void paint(Graphics g)
{
g.setColor(UIManager.getColor("SplitPane.background"));
g.fillRect(0, 0, getWidth(), getHeight());
// if(splitPane.hasFocus())
// {
// g.setColor(primaryControlColor);
// }
// else
// {
// g.setColor(controlColor);
// }
// Rectangle clip=g.getClipBounds();
// Insets insets=getInsets();
// g.fillRect(clip.x, clip.y, clip.width, clip.height);
// Dimension size=getSize();
// size.width-=inset*2;
// size.height-=inset*2;
// int drawX=inset;
// int drawY=inset;
// if(insets!=null)
// {
// size.width-=(insets.left+insets.right);
// size.height-=(insets.top+insets.bottom);
// drawX+=insets.left;
// drawY+=insets.top;
// }
// super.paint(g);
paintComponents(g);
}
/**
* Creates and return an instance of JButton that can be used to
* collapse the left component in the metal split pane.
*/
protected JButton createLeftOneTouchButton()
{
JButton b=new JButton()
{
// Sprite buffer for the arrow image of the left button
int buffer[][]=
{
{ 0, 0, 0, 2, 2, 0, 0, 0, 0 },
{ 0, 0, 2, 1, 1, 1, 0, 0, 0 },
{ 0, 2, 1, 1, 1, 1, 1, 0, 0 },
{ 2, 1, 1, 1, 1, 1, 1, 1, 0 },
{ 0, 3, 3, 3, 3, 3, 3, 3, 3 }
};
public void setBorder(Border b) {}
public void paint(Graphics g)
{
JSplitPane splitPane=getSplitPaneFromSuper();
if(splitPane!=null)
{
int oneTouchSize=getOneTouchSizeFromSuper();
int orientation=getOrientationFromSuper();
int blockSize=Math.min(getDividerSize(), oneTouchSize);
// Initialize the color array
Color colors[]={ this.getBackground(), TonicLookAndFeel
.getPrimaryControlDarkShadow(), TonicLookAndFeel
.getPrimaryControlInfo(), TonicLookAndFeel
.getPrimaryControlHighlight() };
// Fill the background first ...
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(), this.getHeight());
// ... then draw the arrow.
if(getModel().isPressed())
{
// Adjust color mapping for pressed button state
colors[1]=colors[2];
}
if(orientation==JSplitPane.VERTICAL_SPLIT)
{
// Draw the image for a vertical split
for(int i=1; i<=buffer[0].length; i++)
{
for(int j=1; j<blockSize; j++)
{
if(buffer[j-1][i-1]==0)
{
continue;
}
else
{
g.setColor(colors[buffer[j-1][i-1]]);
}
g.drawLine(i, j, i, j);
}
}
}
else
{
// Draw the image for a horizontal split
// by simply swaping the i and j axis.
// Except the drawLine() call this code is
// identical to the code block above. This was done
// in order to remove the additional orientation
// check for each pixel.
for(int i=1; i<=buffer[0].length; i++)
{
for(int j=1; j<blockSize; j++)
{
if(buffer[j-1][i-1]==0)
{
// Nothing needs
// to be drawn
continue;
}
else
{
// Set the color from the
// color map
g.setColor(colors[buffer[j-1][i-1]]);
}
// Draw a pixel
g.drawLine(j, i, j, i);
}
}
}
}
}
// Don't want the button to participate in focus traversable.
public boolean isFocusTraversable()
{
return false;
}
};
b.setRequestFocusEnabled(false);
b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
b.setFocusPainted(false);
b.setBorderPainted(false);
return b;
}
/**
* Creates and return an instance of JButton that can be used to
* collapse the right component in the metal split pane.
*/
protected JButton createRightOneTouchButton()
{
JButton b=new JButton()
{
// Sprite buffer for the arrow image of the right button
int buffer[][]=
{
{ 2, 2, 2, 2, 2, 2, 2, 2 },
{ 0, 1, 1, 1, 1, 1, 1, 3 },
{ 0, 0, 1, 1, 1, 1, 3, 0 },
{ 0, 0, 0, 1, 1, 3, 0, 0 },
{ 0, 0, 0, 0, 3, 0, 0, 0 }
};
public void setBorder(Border border) {}
public void paint(Graphics g)
{
JSplitPane splitPane=getSplitPaneFromSuper();
if(splitPane!=null)
{
int oneTouchSize=getOneTouchSizeFromSuper();
int orientation=getOrientationFromSuper();
int blockSize=Math.min(getDividerSize(), oneTouchSize);
// Initialize the color array
Color colors[]={ this.getBackground(), TonicLookAndFeel
.getPrimaryControlDarkShadow(), TonicLookAndFeel
.getPrimaryControlInfo(), TonicLookAndFeel
.getPrimaryControlHighlight() };
// Fill the background first ...
g.setColor(this.getBackground());
g.fillRect(0, 0, this.getWidth(), this.getHeight());
// ... then draw the arrow.
if(getModel().isPressed())
{
// Adjust color mapping for pressed button state
colors[1]=colors[2];
}
if(orientation==JSplitPane.VERTICAL_SPLIT)
{
// Draw the image for a vertical split
for(int i=1; i<=buffer[0].length; i++)
{
for(int j=1; j<blockSize; j++)
{
if(buffer[j-1][i-1]==0)
{
continue;
}
else
{
g.setColor(colors[buffer[j-1][i-1]]);
}
g.drawLine(i, j, i, j);
}
}
}
else
{
// Draw the image for a horizontal split
// by simply swaping the i and j axis.
// Except the drawLine() call this code is
// identical to the code block above. This was done
// in order to remove the additional orientation
// check for each pixel.
for(int i=1; i<=buffer[0].length; i++)
{
for(int j=1; j<blockSize; j++)
{
if(buffer[j-1][i-1]==0)
{
// Nothing needs
// to be drawn
continue;
}
else
{
// Set the color from the
// color map
g.setColor(colors[buffer[j-1][i-1]]);
}
// Draw a pixel
g.drawLine(j, i, j, i);
}
}
}
}
}
// Don't want the button to participate in focus traversable.
public boolean isFocusTraversable()
{
return false;
}
};
b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
b.setFocusPainted(false);
b.setBorderPainted(false);
b.setRequestFocusEnabled(false);
return b;
}
/*
* The following methods only exist in order to be able to access protected
* members in the superclass, because these are otherwise not available
* in any inner class.
*/
int getOneTouchSizeFromSuper()
{
return super.ONE_TOUCH_SIZE;
}
int getOneTouchOffsetFromSuper()
{
return super.ONE_TOUCH_OFFSET;
}
int getOrientationFromSuper()
{
return super.orientation;
}
JSplitPane getSplitPaneFromSuper()
{
return super.splitPane;
}
JButton getLeftButtonFromSuper()
{
return super.leftButton;
}
JButton getRightButtonFromSuper()
{
return super.rightButton;
}
/**
* Used to layout a MetalSplitPaneDivider. Layout for the divider
* involves appropriately moving the left/right buttons around.
* <p>
* This inner class is marked "public" due to a compiler bug.
* This class should be treated as a "protected" inner class.
* Instantiate it only within subclasses of MetalSplitPaneDivider.
*/
public class MetalDividerLayout implements LayoutManager
{
public void layoutContainer(Container c)
{
JButton leftButton=getLeftButtonFromSuper();
JButton rightButton=getRightButtonFromSuper();
JSplitPane splitPane=getSplitPaneFromSuper();
int orientation=getOrientationFromSuper();
int oneTouchSize=getOneTouchSizeFromSuper();
int oneTouchOffset=getOneTouchOffsetFromSuper();
Insets insets=getInsets();
// This layout differs from the one used in BasicSplitPaneDivider.
// It does not center justify the oneTouchExpadable buttons.
// This was necessary in order to meet the spec of the Metal
// splitpane divider.
if(leftButton!=null && rightButton!=null && c==SplitPaneDivider.this)
{
if(splitPane.isOneTouchExpandable())
{
if(orientation==JSplitPane.VERTICAL_SPLIT)
{
int extraY=(insets!=null) ? insets.top : 0;
int blockSize=getDividerSize();
if(insets!=null)
{
blockSize-=(insets.top+insets.bottom);
}
blockSize=Math.min(blockSize, oneTouchSize);
leftButton.setBounds(oneTouchOffset, extraY, blockSize*2,
blockSize);
rightButton.setBounds(oneTouchOffset+oneTouchSize*2, extraY,
blockSize*2, blockSize);
}
else
{
int blockSize=getDividerSize();
int extraX=(insets!=null) ? insets.left : 0;
if(insets!=null)
{
blockSize-=(insets.left+insets.right);
}
blockSize=Math.min(blockSize, oneTouchSize);
leftButton.setBounds(extraX, oneTouchOffset, blockSize,
blockSize*2);
rightButton.setBounds(extraX, oneTouchOffset+oneTouchSize*2,
blockSize, blockSize*2);
}
}
else
{
leftButton.setBounds(-5, -5, 1, 1);
rightButton.setBounds(-5, -5, 1, 1);
}
}
}
public Dimension minimumLayoutSize(Container c)
{
return new Dimension(0, 0);
}
public Dimension preferredLayoutSize(Container c)
{
return new Dimension(0, 0);
}
public void removeLayoutComponent(Component c) {}
public void addLayoutComponent(String string, Component c) {}
}
}
--- NEW FILE: ToolBarBorder.java ---
package com.digitprop.tonic;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.*;
import javax.swing.border.*;
/** Border for tool bars.
*
* @author Markus Fischer
*
* <p>This software is under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank">GNU Lesser General Public License</a>
*/
/*
* ------------------------------------------------------------------------
* Copyright (C) 2004 Markus Fischer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* You can contact the author at:
* Markus Fischer
* www.digitprop.com
* in...@di...
* ------------------------------------------------------------------------
*/
public class ToolBarBorder implements Border
{
/** Returns the insets for the specified component */
public Insets getBorderInsets(Component c)
{
return new Insets(1,1,1,1);
}
/** Returns true if this border is opaque */
public boolean isBorderOpaque()
{
return true;
}
/** Paints this border for the specified component.
*
* @param c The component for which to paint the border
* @param g The graphics context into which to paint
* @param x The left edge of the border
* @param y The top edge of the border
* @param width The width of the border
* @param height The height of the border
*/
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
{
if(c instanceof AbstractButton)
{
AbstractButton b=(AbstractButton)c;
if(b.getModel().isPressed() || ((c instanceof JToggleButton) && ((JToggleButton)c).isSelected()))
{
g.setColor(UIManager.getColor("ToolButton.activeBorder"));
g.drawLine(x, y, x+width-1, y);
g.drawLine(x, y, x, y+height-1);
g.drawLine(x, y+height-1, x+width-1, y+height-1);
g.drawLine(x+width-1, y, x+width-1, y+height-1);
}
else if(b.getModel().isRollover())
{
g.setColor(UIManager.getColor("ToolButton.activeBorder"));
g.drawLine(x, y, x+width-1, y);
g.drawLine(x, y, x, y+height-1);
g.drawLine(x, y+height-1, x+width-1, y+height-1);
g.drawLine(x+width-1, y, x+width-1, y+height-1);
}
}
}
}
--- NEW FILE: ProgressBarUI.java ---
package com.digitprop.tonic;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
/** UI delegate for JProgressBars.
*
* @author Markus Fischer
[...1549 lines suppressed...]
int newPercent;
int oldPercent=getCachedPercent();
if(newRange>0)
{
newPercent=(int)((100*(long)model.getValue())/newRange);
}
else
{
newPercent=0;
}
if(newPercent!=oldPercent)
{
setCachedPercent(newPercent);
progressBar.repaint();
}
}
}
}
--- NEW FILE: ButtonUI.java ---
package com.digitprop.tonic;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import javax.swing.plaf.metal.*;
/** The look and feel of AbstractButtons.
*
* @author Markus Fischer
*
* <p>This software is under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank">GNU Lesser General Public License</a>
*/
/*
* ------------------------------------------------------------------------
* Copyright (C) 2004 Markus Fischer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* You can contact the author at:
* Markus Fischer
* www.digitprop.com
* in...@di...
* ------------------------------------------------------------------------
*/
public class ButtonUI extends MetalButtonUI
{
/** The default border for this button */
private final static BorderUIResource defaultBorder =new BorderUIResource(Borders.getButtonBorder());
/** Keeps track of the previous opacity settings for buttons */
private static Hashtable opaqueTable=new Hashtable();
private Color highlightColor;
private Color focusColor;
/** Creates the UI delegate for the specified component. If the
* component is not an instance of JButton, this call is handled
* by the MetalButtonUI class to return the default delegate.
*/
public static ComponentUI createUI(JComponent c)
{
if(c instanceof JButton)
return new ButtonUI();
else
return MetalButtonUI.createUI(c);
}
public ButtonUI()
{
highlightColor=UIManager.getColor("Button.highlight");
focusColor=UIManager.getColor("Button.focusBorderColor");
}
/** Returns the appropriate listener for the specified button */
protected BasicButtonListener createButtonListener(AbstractButton b)
{
return new BasicButtonListener(b);
}
/** Returns the shift offset for the button text */
protected int getTextShiftOffset()
{
return 1;
}
/** Installs the UI delegate for the specified component */
public void installUI(JComponent c)
{
super.installUI(c);
if(c.getBorder()==null || (c.getBorder() instanceof UIResource))
c.setBorder(defaultBorder);
if(opaqueTable.get(c)==null)
opaqueTable.put(c, new Boolean(c.isOpaque()));
c.setOpaque(false);
}
/** Uninstalls the UI settings for the specified component */
public void uninstallUI(JComponent c)
{
super.uninstallUI(c);
Boolean isOpaque=(Boolean)opaqueTable.get(c);
if(isOpaque!=null)
c.setOpaque(isOpaque.booleanValue());
}
/** Paints the specified button.
*
* @param g Graphics context into which to paint
* @param c The button which is to be painted
*/
public void paint(Graphics g, JComponent c)
{
g.setColor(c.getBackground());
Insets insets=c.getInsets();
g.fillRect(insets.left, insets.top, c.getWidth()-insets.left-insets.right, c.getHeight()-insets.top-insets.bottom);
if(c instanceof AbstractButton)
{
AbstractButton button=(AbstractButton)c;
if(!button.getModel().isPressed() && button.isEnabled() && !button.isSelected())
{
Border border=button.getBorder();
if(border==null || !(border instanceof ToolBarBorder))
{
g.setColor(highlightColor);
g.drawLine(insets.left, insets.top, c.getWidth()-insets.left-insets.right, insets.top);
g.drawLine(insets.left, insets.top, insets.left, c.getHeight()-insets.top-insets.bottom);
}
}
else if(button.isSelected())
paintButtonPressed(g, button);
}
super.paint(g, c);
}
/** Returns the preferred size for the specified component. */
public Dimension getPreferredSize(JComponent c)
{
Dimension result=super.getPreferredSize(c);
if(c.getBorder()!=null && (c.getBorder() instanceof ToolBarBorder))
{
result.width+=4;
result.height+=4;
}
else
{
result.width+=4;
result.height+=6;
if(c instanceof JButton)
{
Insets m=((JButton)c).getMargin();
if(m!=null)
{
result.width+=m.left+m.right;
result.height+=m.top+m.bottom;
}
}
// if(result.width<75)
// {
// if(c instanceof JButton)
// {
// JButton b=(JButton)c;
//
// if(b.getText()!=null && b.getText().length()>0 && b.getIcon()==null)
// result.width=75;
// }
// }
}
return result;
}
/** Paints the specified button in the pressed state.
*
* @param g Graphics context into which to paint
* @param c The button which is to be painted
*/
protected void paintButtonPressed(Graphics g, AbstractButton b)
{
Border border=b.getBorder();
if(border==null || !(border instanceof ToolBarBorder))
{
Insets insets=b.getInsets();
g.setColor(highlightColor);
g.drawLine(insets.left, b.getHeight()-insets.top-insets.bottom, b.getWidth()-insets.left-insets.right, b.getHeight()-insets.top-insets.bottom);
g.drawLine(b.getWidth()-insets.left-insets.right, insets.top, b.getWidth()-insets.left-insets.right, b.getHeight()-insets.top-insets.bottom);
}
}
/** Paints the focus for the specified button
*
* @param g Graphics context into which to paint
* @param b Button for which to paint the focus
* @param viewRect Rectangle of the button view
* @param textRect Rectangle of the button text
* @param iconRect Rectangle of the button icon
*/
protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect)
{
// Overridden to prevent superclass from painting anything
if(!b.getModel().isPressed())
{
Border border=b.getBorder();
if(border==null || !(border instanceof ToolBarBorder))
{
Insets insets=b.getInsets();
int left=insets.left+2;
int top=insets.top+2;
int right=b.getWidth()-insets.left-insets.right-2;
int bottom=b.getHeight()-insets.top-insets.bottom-2;
g.setColor(focusColor);
BasicGraphicsUtils.drawDashedRect(g, left, top, right-left+1, bottom-top+1);
}
}
}
/** Paints the text for the specified component, IF that component
* is an instance of AbstractButton. Otherwise, this method will do
* nothing.
*
* @param g Graphics context into which to paint
* @param c The component for which to draw text
* @param textRect The rectangle enclosing the text
* @param text The text to be drawn
*/
protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text)
{
if(c instanceof AbstractButton)
paintText(g, (AbstractButton)c, textRect, text);
}
/** Paints the text for the specified button.
*
* @param g Graphics context into which to paint
* @param b The button for which to draw text
* @param textRect The rectangle enclosing the text
* @param text The text to be drawn
*/
protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text)
{
ButtonModel model = b.getModel();
FontMetrics fm = g.getFontMetrics();
int mnemIndex = b.getDisplayedMnemonicIndex();
if(model.isPressed())
{
textRect.x+=getTextShiftOffset();
textRect.y+=getTextShiftOffset();
}
// Draw the text
if(model.isEnabled())
{
// Pain the text normally
g.setColor(b.getForeground());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
else
{
// Paint the text disabled
g.setColor(Color.WHITE);
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemIndex, textRect.x+1, textRect.y + fm.getAscent() +1);
g.setColor(getDisabledTextColor());
BasicGraphicsUtils.drawStringUnderlineCharAt(g,text,mnemIndex, textRect.x, textRect.y + fm.getAscent());
}
}
public static void main(String args[])
{
try
{
UIManager.setLookAndFeel(new TonicLookAndFeel());
}
catch(UnsupportedLookAndFeelException e)
{
e.printStackTrace();
}
JWindow win=new JWindow();
win.getContentPane().setLayout(new FlowLayout());
win.setBounds(10, 10, 300, 300);
Icon icon=TonicLookAndFeel.getTonicIcon("open.gif");
JButton button=new JButton(icon);
button.setEnabled(false);
win.getContentPane().add(button);
win.setVisible(true);
}
}
--- NEW FILE: InternalFrameBorder.java ---
package com.digitprop.tonic;
import java.awt.*;
import javax.swing.*;
/** Used as a border for JInternalFrames.
*
* @author Markus Fischer
*
* <p>This software is under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank">GNU Lesser General Public License</a>
*/
/*
* ------------------------------------------------------------------------
* Copyright (C) 2004 Markus Fischer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* You can contact the author at:
* Markus Fischer
* www.digitprop.com
* in...@di...
* ------------------------------------------------------------------------
*/
public class InternalFrameBorder extends IntelligentLineBorder
{
/** The color of the border for inactive JInternalFrames */
private Color inactiveColor;
/** The color of the border for active JInternalFrames */
private Color activeColor;
/** The color of the border's 1-pixel lines */
private Color borderColor;
/** Creates an instance.
*
* @param borderColor The border line color
* @param inactiveColor The fill color for inactive JInternalFrames
* @param activeColor The fill color for active JInternalFrames
*/
public InternalFrameBorder(Color borderColor, Color inactiveColor, Color activeColor)
{
this.borderColor=borderColor;
this.inactiveColor=inactiveColor;
this.activeColor=activeColor;
}
/** Returns the insets for the specified component */
public Insets getBorderInsets(Component c)
{
return new Insets(3, 3, 3, 3);
}
/** Returns true if this border is opaque */
public boolean isBorderOpaque()
{
return true;
}
/** Paints this border for the specified component.
*
* @param c The component for which to paint the border
* @param g The graphics context into which to paint
* @param x The left edge of the border
* @param y The right edge of the border
* @param width The width of the border
* @param height The height of the border
*/
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
{
boolean isActive=false;
if(c instanceof JInternalFrame)
{
JInternalFrame f=(JInternalFrame)c;
if(f.isSelected())
isActive=true;
}
g.setColor(borderColor);
g.drawRect(x, y, width-1, height-1);
g.drawRect(x+2, y+2, width-5, height-5);
if(isActive)
g.setColor(activeColor);
else
g.setColor(inactiveColor);
g.drawRect(x+1, y+1, width-3, height-3);
}
}
--- NEW FILE: ToolBarMarginBorder.java ---
package com.digitprop.tonic;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.border.*;
/** A border which is like a Margin border but it will only honor the margin
if the margin has been explicitly set by the developer.
*/
class ToolBarMarginBorder extends EmptyBorder
{
public ToolBarMarginBorder()
{
super(3, 3, 3, 3); // hardcoded margin for JLF requirements.
}
public Insets getBorderInsets(Component c)
{
return getBorderInsets(c, new Insets(0, 0, 0, 0));
}
public Insets getBorderInsets(Component c, Insets insets)
{
Insets margin= null;
if (c instanceof AbstractButton)
{
margin= ((AbstractButton) c).getMargin();
}
if (margin == null || margin instanceof UIResource)
{
// default margin so replace
insets.left= left;
insets.top= top;
insets.right= right;
insets.bottom= bottom;
}
else
{
// Margin which has been explicitly set by the user.
insets.left= margin.left;
insets.top= margin.top;
insets.right= margin.right;
insets.bottom= margin.bottom;
}
return insets;
}
}
--- NEW FILE: MenuBarUI.java ---
package com.digitprop.tonic;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
/** UI delegate for JMenuBars.
*
* @author Markus Fischer
*
* <p>This software is under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank">GNU Lesser General Public License</a>
*/
/*
* ------------------------------------------------------------------------
* Copyright (C) 2004 Markus Fischer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* You can contact the author at:
* Markus Fischer
* www.digitprop.com
* in...@di...
* ------------------------------------------------------------------------
*/
public class MenuBarUI extends BasicMenuBarUI
{
/** The underlying menu bar */
protected JMenuBar menuBar= null;
/** The container listener registered with the menu bar */
protected ContainerListener containerListener;
/** The change listener registered with the menu bar */
protected ChangeListener changeListener;
/** The property change listener registered with the menu bar */
private PropertyChangeListener propertyChangeListener;
/** Creates and returns the UI delegate for the specified component */
public static ComponentUI createUI(JComponent x)
{
return new MenuBarUI();
}
/** Installs the UI delegate for the specified component */
public void installUI(JComponent c)
{
menuBar= (JMenuBar) c;
installDefaults();
installListeners();
installKeyboardActions();
}
/** Installs the default settings for the associated menu bar */
protected void installDefaults()
{
if (menuBar.getLayout() == null
|| menuBar.getLayout() instanceof UIResource)
{
if (TonicUtils.isLeftToRight(menuBar))
{
menuBar.setLayout(new DefaultMenuLayout(menuBar, BoxLayout.X_AXIS));
}
else
{
menuBar.setLayout(new RightToLeftMenuLayout());
}
}
menuBar.setOpaque(true);
LookAndFeel.installBorder(menuBar, "MenuBar.border");
LookAndFeel.installColorsAndFont(menuBar, "MenuBar.background", "MenuBar.foreground", "MenuBar.font");
}
/** Installs listeners for the associated menu bar */
protected void installListeners()
{
containerListener= createContainerListener();
changeListener= createChangeListener();
propertyChangeListener= createPropertyChangeListener();
for (int i= 0; i < menuBar.getMenuCount(); i++)
{
JMenu menu= menuBar.getMenu(i);
if (menu != null)
menu.getModel().addChangeListener(changeListener);
}
menuBar.addContainerListener(containerListener);
menuBar.addPropertyChangeListener(propertyChangeListener);
}
/** Installs the keyboard actions for the associated menu bar */
protected void installKeyboardActions()
{
InputMap inputMap= getMyInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
SwingUtilities.replaceUIInputMap(
menuBar,
JComponent.WHEN_IN_FOCUSED_WINDOW,
inputMap);
ActionMap actionMap= getMyActionMap();
SwingUtilities.replaceUIActionMap(menuBar, actionMap);
}
/** Returns the input map for the specified condition, for the
* associated menu bar.
*
* @param condition This must be one of the constants
* defined in JComponent
*/
public InputMap getMyInputMap(int condition)
{
if (condition == JComponent.WHEN_IN_FOCUSED_WINDOW)
{
Object[] bindings= (Object[]) UIManager.get("MenuBar.windowBindings");
if (bindings != null)
{
return LookAndFeel.makeComponentInputMap(menuBar, bindings);
}
}
return null;
}
/** Returns the action map for the menu bar */
ActionMap getMyActionMap()
{
ActionMap map= (ActionMap) UIManager.get("MenuBar.actionMap");
if (map == null)
{
map= createMyActionMap();
if (map != null)
{
UIManager.getLookAndFeelDefaults().put("MenuBar.actionMap", map);
}
}
return map;
}
/** Creates an action map for the associated menu bar */
ActionMap createMyActionMap()
{
ActionMap map= new ActionMapUIResource();
map.put("takeFocus", new TakeFocus());
return map;
}
/** Uninstalls the UI delegate for the specified component */
public void uninstallUI(JComponent c)
{
uninstallDefaults();
uninstallListeners();
uninstallKeyboardActions();
menuBar= null;
}
/** Uninstalls the defaults for the associated menu bar */
protected void uninstallDefaults()
{
if (menuBar != null)
{
LookAndFeel.uninstallBorder(menuBar);
}
}
/** Uninstalls any registered listeners for the associated menu bar */
protected void uninstallListeners()
{
menuBar.removeContainerListener(containerListener);
menuBar.removePropertyChangeListener(propertyChangeListener);
for (int i= 0; i < menuBar.getMenuCount(); i++)
{
JMenu menu= menuBar.getMenu(i);
if (menu != null)
menu.getModel().removeChangeListener(changeListener);
}
containerListener= null;
changeListener= null;
propertyChangeListener= null;
}
/** Uninstalls any keyboard actions for the associated menu bar */
protected void uninstallKeyboardActions()
{
SwingUtilities.replaceUIInputMap(
menuBar,
JComponent.WHEN_IN_FOCUSED_WINDOW,
null);
SwingUtilities.replaceUIActionMap(menuBar, null);
}
/** Creates and returns a container listener for the associated menu bar */
protected ContainerListener createContainerListener()
{
return new ContainerHandler();
}
/** Creates and returns a change listener for the associated menu bar */
protected ChangeListener createChangeListener()
{
return new ChangeHandler();
}
/** Creates and returns a property listener for the associated menu bar */
private PropertyChangeListener createPropertyChangeListener()
{
return new PropertyChangeHandler();
}
/** The change listener for associated menu bars */
private class ChangeHandler implements ChangeListener
{
public void stateChanged(ChangeEvent e)
{
int i, c;
for (i= 0, c= menuBar.getMenuCount(); i < c; i++)
{
JMenu menu= menuBar.getMenu(i);
if (menu != null && menu.isSelected())
{
menuBar.getSelectionModel().setSelectedIndex(i);
break;
}
}
}
}
/*** This PropertyChangeListener is used to adjust the default layout
* manger when the menuBar is given a right-to-left ComponentOrientation.
* This is a hack to work around the fact that the DefaultMenuLayout
* (BoxLayout) isn't aware of ComponentOrientation. When BoxLayout is
* made aware of ComponentOrientation, this listener will no longer be
* necessary.
*/
private class PropertyChangeHandler implements PropertyChangeListener
{
public void propertyChange(PropertyChangeEvent e)
{
String name= e.getPropertyName();
if (name.equals("componentOrientation")
&& (menuBar.getLayout() instanceof UIResource))
{
if (TonicUtils.isLeftToRight(menuBar))
{
menuBar.setLayout(
new DefaultMenuLayout(menuBar, BoxLayout.X_AXIS));
}
else
{
menuBar.setLayout(new RightToLeftMenuLayout());
}
}
}
}
/** Returns the preferred size for the specified component */
public Dimension getPreferredSize(JComponent c)
{
return null;
}
/** Returns the minimum size for the specified component */
public Dimension getMinimumSize(JComponent c)
{
return null;
}
/** Returns the maximum size for the specified component */
public Dimension getMaximumSize(JComponent c)
{
return null;
}
/** A container listener for associated menu bars */
private class ContainerHandler implements ContainerListener
{
public void componentAdded(ContainerEvent e)
{
Component c= e.getChild();
if (c instanceof JMenu)
((JMenu) c).getModel().addChangeListener(changeListener);
}
public void componentRemoved(ContainerEvent e)
{
Component c= e.getChild();
if (c instanceof JMenu)
((JMenu) c).getModel().removeChangeListener(changeListener);
}
}
private static class TakeFocus extends AbstractAction
{
TakeFocus()
{
}
public void actionPerformed(ActionEvent e)
{
JMenuBar menuBar= (JMenuBar) e.getSource();
MenuSelectionManager defaultManager=
MenuSelectionManager.defaultManager();
MenuElement me[];
MenuElement subElements[];
JMenu menu= menuBar.getMenu(0);
if (menu != null)
{
me= new MenuElement[3];
me[0]= (MenuElement) menuBar;
me[1]= (MenuElement) menu;
me[2]= (MenuElement) menu.getPopupMenu();
defaultManager.setSelectedPath(me);
}
}
}
private static class RightToLeftMenuLayout
extends FlowLayout
implements UIResource
{
private RightToLeftMenuLayout()
{
super(3 /*FlowLayout.LEADING*/
, 0, 0);
}
}
}
--- NEW FILE: ComboBoxUI.java ---
package com.digitprop.tonic;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import javax.swing.*;
import javax.swing.plaf.basic.*;
import javax.accessibility.*;
import javax.swing.plaf.*;
import javax.swing.event.*;
import sun.awt.AppContext;
/** UI delegate for combo boxes.
*
[...1700 lines suppressed...]
comboBox.actionPerformed(
new ActionEvent(
editor,
0,
"",
EventQueue.getMostRecentEventTime(),
0));
}
}
}
/** Convenience function for determining ComponentOrientation. Helps us
* avoid having Munge directives throughout the code.
*/
static boolean isLeftToRight(Component c)
{
return c.getComponentOrientation().isLeftToRight();
}
}
--- NEW FILE: SliderUI.java ---
package com.digitprop.tonic;
import java.awt.*;
import java.beans.*;
import javax.swing.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.BasicSliderUI;
/** UI delegate for JSliders
*
* @author Markus Fischer
*
* <p>This software is under the <a href="http://www.gnu.org/copyleft/lesser.html" target="_blank">GNU Lesser General Public License</a>
*/
/*
* ------------------------------------------------------------------------
* Copyright (C) 2004 Markus Fischer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1 as published by the Free Software Foundation.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
* You can contact the author at:
* Markus Fischer
* www.digitprop.com
* in...@di...
* ------------------------------------------------------------------------
*/
public class SliderUI extends BasicSliderUI
{
protected static Color thumbColor;
protected static Color highlightColor;
protected static Color darkShadowColor;
protected static int trackWidth;
protected static int tickLength;
protected static Icon horizThumbIcon;
protected static Icon vertThumbIcon;
protected final int TICK_BUFFER=4;
protected boolean filledSlider=false;
protected final String SLIDER_FILL="JSlider.isFilled";
/** Creates an instance */
public SliderUI()
{
super(null);
}
/** Creates and returns a UI delegate for the specified component */
public static ComponentU...
[truncated message content] |