Update of /cvsroot/metamorphosis/krysalis-jplugin/src/java/org/krysalis/swingx
In directory sc8-pr-cvs1:/tmp/cvs-serv24886/src/java/org/krysalis/swingx
Added Files:
AbstractLayout.java AntiAliasedDOMNodeBoundJTextArea.java
AntiAliasedDOMNodeBoundJTextBox.java CardPanel.java
ContextLayout.java EmptyIcon.java ImageUtils.java
JButtonList.java JCloseableRadioButton.java
JExceptionDialog.java JFileTree.java JFlatButton.java
JLoadProgressSplash.java JOutlookBar.java JSplash.java
JSwitcherToolBar.java JTreeFileChooser.java
LinkEnabledJEditorPane.java ListLayout.java
NoPathInToStringNameFileWrapper.java
OrderedHashtableComboBoxModel.java PatchedHTMLEditorKit.java
ScrollingPanel.java SimpleLinkListener.java
StoreEntitySelector.java TabBorder.java TabButton.java
TableMap.java TableSorter.java WaitCursorEventQueue.java
WindowUtils.java
Log Message:
refactoring swingx.swing.* packages to swingx.*
--- NEW FILE: AbstractLayout.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.LayoutManager2;
import java.io.Serializable;
/**
* Copyright by Cleverlance 2001 Author: Claude Duguay, Jan Seda Contact:
* [email protected] Website: www.cleverlance.com
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
public abstract class AbstractLayout implements LayoutManager2, Serializable {
/**
* Description of the Field
*/
protected int hgap;
/**
* Description of the Field
*/
protected int vgap;
/**
* Constructor for the AbstractLayout object
*/
public AbstractLayout() {
this(0, 0);
}
/**
* Constructor for the AbstractLayout object
*
*@param hgap Description of Parameter
*@param vgap Description of Parameter
*/
public AbstractLayout(int hgap, int vgap) {
setHgap(hgap);
setVgap(vgap);
}
/**
* Set the horizontal gap between components.
*
*@param gap The horizontal gap to be set
*/
public void setHgap(int gap) {
hgap = gap;
}
/**
* Set the vertical gap between components.
*
*@param gap The vertical gap to be set
*/
public void setVgap(int gap) {
vgap = gap;
}
/**
* Get the horizontal gap between components.
*
*@return The hgap value
*/
public int getHgap() {
return hgap;
}
/**
* Get the vertical gap between components.
*
*@return The vgap value
*/
public int getVgap() {
return vgap;
}
/**
* Returns the alignment along the x axis. This specifies how the component
* would like to be aligned relative to other components. The value should
* be a number between 0 and 1 where 0 represents alignment along the
* origin, 1 is aligned the furthest away from the origin, 0.5 is centered,
* etc.
*
*@param parent Description of Parameter
*@return The layoutAlignmentX value
*/
public float getLayoutAlignmentX(Container parent) {
return 0.5f;
}
/**
* Returns the alignment along the y axis. This specifies how the component
* would like to be aligned relative to other components. The value should
* be a number between 0 and 1 where 0 represents alignment along the
* origin, 1 is aligned the furthest away from the origin, 0.5 is centered,
* etc.
*
*@param parent Description of Parameter
*@return The layoutAlignmentY value
*/
public float getLayoutAlignmentY(Container parent) {
return 0.5f;
}
/**
* Returns the maximum dimensions for this layout given the component in
* the specified target container.
*
*@param target The component which needs to be laid out
*@return Description of the Returned Value
*/
public Dimension maximumLayoutSize(Container target) {
return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
/**
* Invalidates the layout, indicating that if the layout manager has cached
* information it should be discarded.
*
*@param target Description of Parameter
*/
public void invalidateLayout(Container target) { }
/**
* Adds the specified component with the specified name to the layout. By
* default, we call the more recent addLayoutComponent method with an
* object constraint argument. The name is passed through directly.
*
*@param name The name of the component
*@param comp The component to be added
*/
public void addLayoutComponent(String name, Component comp) {
addLayoutComponent(comp, name);
}
/**
* Add the specified component from the layout. By default, we let the
* Container handle this directly.
*
*@param comp The component to be added
*@param constraints The constraints to apply when laying out.
*/
public void addLayoutComponent(Component comp, Object constraints) { }
/**
* Removes the specified component from the layout. By default, we let the
* Container handle this directly.
*
*@param comp the component to be removed
*/
public void removeLayoutComponent(Component comp) { }
/**
* Return a string representation of the layout manager
*
*@return Description of the Returned Value
*/
public String toString() {
return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]";
}
}
--- NEW FILE: AntiAliasedDOMNodeBoundJTextArea.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Graphics;
import javax.swing.JTextArea;
import javax.swing.event.CaretEvent;
import org.krysalis.swingx.concerns.AntiAliasing;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created June 20, 2001
*@version 1.0
*/
public class AntiAliasedDOMNodeBoundJTextArea extends JTextArea {
org.w3c.dom.Node node;
/**
* Constructor for the AntiAliasedDOMNodeBoundJTextArea object
*/
public AntiAliasedDOMNodeBoundJTextArea() {
super();
}
/**
* Sets the node attribute of the AntiAliasedDOMNodeBoundJTextArea object
*
*@param node The new node value
*/
public void setNode(org.w3c.dom.Node node) {
if (node != null) {
this.node = node;
this.setText(node.getNodeValue());
this.addCaretListener(
new javax.swing.event.CaretListener() {
public void caretUpdate(CaretEvent e) {
received_caretUpdate(e);
}
}
);
this.setEnabled(true);
}
}
/**
* Description of the Method
*
*@param g1 Description of Parameter
*/
public void paint(Graphics g1) {
AntiAliasing.antialias(g1);
super.paint(g1);
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void received_caretUpdate(CaretEvent e) {
node.setNodeValue(this.getText());
}
}
--- NEW FILE: AntiAliasedDOMNodeBoundJTextBox.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Graphics;
import javax.swing.JTextField;
import javax.swing.event.CaretEvent;
import org.krysalis.swingx.concerns.AntiAliasing;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created June 20, 2001
*@version 1.0
*/
public class AntiAliasedDOMNodeBoundJTextBox extends JTextField {
org.w3c.dom.Node node;
/**
* Constructor for the AntiAliasedDOMNodeBoundJTextBox object
*/
public AntiAliasedDOMNodeBoundJTextBox() {
super();
super.setEnabled(false);
}
/**
* Constructor for the AntiAliasedDOMNodeBoundJTextBox object
*
*@param columns Description of Parameter
*/
public AntiAliasedDOMNodeBoundJTextBox(int columns) {
super(columns);
super.setEnabled(false);
}
/**
* Sets the node attribute of the AntiAliasedDOMNodeBoundJTextBox object
*
*@param node The new node value
*/
public void setNode(org.w3c.dom.Node node) {
if (node != null) {
this.node = node;
this.setText(node.getNodeValue());
this.addCaretListener(
new javax.swing.event.CaretListener() {
public void caretUpdate(CaretEvent e) {
setTextInNode();
}
}
);
this.setEnabled(true);
}
}
/**
* Description of the Method
*
*@param g1 Description of Parameter
*/
public void paint(Graphics g1) {
AntiAliasing.antialias(g1);
super.paint(g1);
}
/**
* Sets the textInNode attribute of the AntiAliasedDOMNodeBoundJTextBox
* object
*/
private void setTextInNode() {
node.setNodeValue(this.getText());
}
}
--- NEW FILE: CardPanel.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Rectangle;
import javax.swing.JPanel;
/**
* A simpler alternative to a JPanel with a CardLayout. The AWT CardLayout
* layout manager can be inconvenient to use because the special "stack of
* cards" operations it supports require a cast to use. For example to show the
* card named "myCard" given a JPanel with a CardLayout one would write: <pre>
* ((CardLayout)(myJPanel.getLayout())).show(myJPanel, "myCard");
* </pre> This doesn't work well with Swing - all of the CardLayout display
* operations, like <code>show</code> call validate directly. Swing supports
* automatic validation (see JComponent.revalidate()); this direct call to
* validate is inefficient. <p>
*
* The CardPane JPanel subclass is intended to support a layout with a modest
* number of cards, on the order of 100 or less. A cards name is it's component
* name, as in java.awt.Component.getName(), which is set when the component is
* added to the CardPanel: <pre>
* myCardPanel.add(myChild, "MyChildName");
* myChild.getName() <i>=> "MyChildName"</i> </pre> As with CardLayout, the
* first child added to a CardPanel is made visible and there's only one child
* visible at a time. The <code>showCard</code> method accepts either a childs
* name or the child itself: <pre>
* myCardPanel.show("MyChildName");
* myCardPanel.show(myChild);
* </pre> <p>
*
* The CardPanel class doesn't support the vgap/hgap CardLayout properties
* since one can add a Border, see JComponent.setBorder().
*
*@author Hans Muller
*@created 15 settembre 2001
*/
public class CardPanel extends JPanel {
/**
* Creates a CardPanel. Children, called "cards" in this API, should be
* added with add(). The first child we be made visible, subsequent
* children will be hidden. To show a card, use one of the show*Card
* methods.
*/
public CardPanel() {
super(new Layout());
}
/**
* Hide the currently visible child "card" and show the specified card. If
* the specified card isn't a child of the CardPanel then we add it here.
*
*@param card Description of Parameter
*/
public void showCard(Component card) {
if (card.getParent() != this) {
add(card);
}
int index = getVisibleChildIndex();
if (index != -1) {
getComponent(index).setVisible(false);
}
card.setVisible(true);
revalidate();
repaint();
}
/**
* Show the card with the specified name.
*
*@param name Description of Parameter
*@see java.awt.Component#getName
*/
public void showCard(String name) {
int nChildren = getComponentCount();
for (int i = 0; i < nChildren; i++) {
Component child = getComponent(i);
if (child.getName().equals(name)) {
showCard(child);
break;
}
}
}
/**
* Show the card that was added to this CardPanel after the currently
* visible card. If the currently visible card was added last, then show
* the first card.
*/
public void showNextCard() {
if (getComponentCount() <= 0) {
return;
}
int index = getVisibleChildIndex();
if (index == -1) {
showCard(getComponent(0));
} else if (index == (getComponentCount() - 1)) {
showCard(getComponent(0));
} else {
showCard(getComponent(index + 1));
}
}
/**
* Show the card that was added to this CardPanel before the currently
* visible card. If the currently visible card was added first, then show
* the last card.
*/
public void showPreviousCard() {
if (getComponentCount() <= 0) {
return;
}
int index = getVisibleChildIndex();
if (index == -1) {
showCard(getComponent(0));
} else if (index == 0) {
showCard(getComponent(getComponentCount() - 1));
} else {
showCard(getComponent(index - 1));
}
}
/**
* Show the first card that was added to this CardPanel.
*/
public void showFirstCard() {
if (getComponentCount() <= 0) {
return;
}
showCard(getComponent(0));
}
/**
* Show the last card that was added to this CardPanel.
*/
public void showLastCard() {
if (getComponentCount() <= 0) {
return;
}
showCard(getComponent(getComponentCount() - 1));
}
/**
* Return the index of the first (and one would hope - only) visible child.
* If a visible child can't be found, perhaps the caller has inexlicably
* hidden all of the children, then return -1.
*
*@return The visibleChildIndex value
*/
private int getVisibleChildIndex() {
int nChildren = getComponentCount();
for (int i = 0; i < nChildren; i++) {
Component child = getComponent(i);
if (child.isVisible()) {
return i;
}
}
return -1;
}
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
private static class Layout implements LayoutManager {
/**
* Set the childs name (if non-null) and and make it visible iff it's
* the only CardPanel child.
*
*@param name The feature to be added to the LayoutComponent
* attribute
*@param child The feature to be added to the LayoutComponent
* attribute
*@see java.awt.Component#setName
*/
public void addLayoutComponent(String name, Component child) {
if (name != null) {
child.setName(name);
}
child.setVisible(child.getParent().getComponentCount() == 1);
}
/**
* If this child was visible, then make the first remaining child
* visible.
*
*@param child Description of Parameter
*/
public void removeLayoutComponent(Component child) {
if (child.isVisible()) {
Container parent = child.getParent();
if (parent.getComponentCount() > 0) {
parent.getComponent(0).setVisible(true);
}
}
}
/**
*@param parent Description of Parameter
*@return the maximum preferred width/height + the parents
* insets
*/
public Dimension preferredLayoutSize(Container parent) {
int nChildren = parent.getComponentCount();
Insets insets = parent.getInsets();
int width = insets.left + insets.right;
int height = insets.top + insets.bottom;
for (int i = 0; i < nChildren; i++) {
Dimension d = parent.getComponent(i).getPreferredSize();
if (d.width > width) {
width = d.width;
}
if (d.height > height) {
height = d.height;
}
}
return new Dimension(width, height);
}
/**
*@param parent Description of Parameter
*@return the maximum minimum width/height + the parents insets
*/
public Dimension minimumLayoutSize(Container parent) {
int nChildren = parent.getComponentCount();
Insets insets = parent.getInsets();
int width = insets.left + insets.right;
int height = insets.top + insets.bottom;
for (int i = 0; i < nChildren; i++) {
Dimension d = parent.getComponent(i).getMinimumSize();
if (d.width > width) {
width = d.width;
}
if (d.height > height) {
height = d.height;
}
}
return new Dimension(width, height);
}
/**
* Description of the Method
*
*@param parent Description of Parameter
*/
public void layoutContainer(Container parent) {
int nChildren = parent.getComponentCount();
Insets insets = parent.getInsets();
for (int i = 0; i < nChildren; i++) {
Component child = parent.getComponent(i);
if (child.isVisible()) {
Rectangle r = parent.getBounds();
int width = r.width - insets.left + insets.right;
int height = r.height - insets.top + insets.bottom;
child.setBounds(insets.left, insets.top, width, height);
break;
}
}
}
}
}
--- NEW FILE: ContextLayout.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager2;
import java.io.Serializable;
import java.util.Vector;
/**
* Copyright by Cleverlance 2001 Author: Claude Duguay, Jan Seda Contact:
* [email protected] Website: www.cleverlance.com
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
public class ContextLayout extends AbstractLayout implements LayoutManager2,
Serializable {
/**
* Description of the Field
*/
protected Vector tabs = new Vector();
/**
* Description of the Field
*/
protected Vector panels = new Vector();
/**
* Description of the Field
*/
protected Component center;
/**
* Description of the Field
*/
protected int index = 1;
/**
* Constructs a ContextLayout with no gaps between components.
*/
public ContextLayout() {
super();
}
/**
* Constructs a ContextLayout with the specified gaps.
*
*@param hgap The horizontal gap
*@param vgap The vertical gap
*/
public ContextLayout(int hgap, int vgap) {
super(hgap, vgap);
}
/**
* Sets the index attribute of the ContextLayout object
*
*@param parent The new index value
*@param index The new index value
*/
public void setIndex(Container parent, int index) {
this.index = index;
layoutContainer(parent);
}
/**
* Adds the specified component to the layout, using the specified
* constraint object.
*
*@param tab The feature to be added to the LayoutComponent attribute
*@param panel The feature to be added to the LayoutComponent attribute
*/
public void addLayoutComponent(Component tab, Object panel) {
if (panel == null) {
return;
}
tabs.addElement(tab);
panels.addElement(panel);
}
/**
* Removes the specified component from the layout.
*
*@param comp The component to be removed
*/
public void removeLayoutComponent(Component comp) {
for (int i = 0; i < tabs.size(); i++) {
if (tabs.elementAt(i) == comp) {
tabs.removeElementAt(i);
panels.removeElementAt(i);
return;
}
}
}
/**
* Returns the minimum dimensions needed to layout the components contained
* in the specified target container.
*
*@param target The Container on which to do the layout
*@return Description of the Returned Value
*/
public Dimension minimumLayoutSize(Container target) {
Insets insets = target.getInsets();
Dimension tab = getMinimumTabSize();
int h = tab.height * (tabs.size() + 1) + (tabs.size() * hgap);
return new Dimension(tab.width + insets.left + insets.right + (hgap * 2),
h + insets.top + insets.bottom);
}
/**
* Returns the preferred dimensions for this layout given the components in
* the specified target container.
*
*@param target The component which needs to be laid out
*@return Description of the Returned Value
*/
public Dimension preferredLayoutSize(Container target) {
Insets insets = target.getInsets();
Dimension tab = getPreferredTabSize();
int h = tab.height * (tabs.size() + 1) + (tabs.size() * hgap);
return new Dimension(tab.width + insets.left + insets.right + (hgap * 2),
h + insets.top + insets.bottom);
}
/**
* Lays out the specified container. This method will actually reshape the
* components in the specified target container in order to satisfy the
* constraints of the layout object.
*
*@param target The component being laid out
*/
public void layoutContainer(Container target) {
Dimension size = getPreferredTabSize();
layoutTabs(target, index, size, target.getSize());
layoutCenter(target, index, size, target.getSize());
}
/**
* Gets the preferredTabSize attribute of the ContextLayout object
*
*@return The preferredTabSize value
*/
private Dimension getPreferredTabSize() {
int w = 0;
int h = 0;
Dimension size;
Component comp;
for (int i = 0; i < tabs.size(); i++) {
comp = (Component) tabs.elementAt(i);
size = comp.getPreferredSize();
if (size.width > w) {
w = size.width;
}
if (size.height > h) {
h = size.height;
}
}
return new Dimension(w, h);
}
/**
* Gets the minimumTabSize attribute of the ContextLayout object
*
*@return The minimumTabSize value
*/
private Dimension getMinimumTabSize() {
int w = 0;
int h = 0;
Component comp;
Dimension size;
for (int i = 0; i < tabs.size(); i++) {
comp = (Component) tabs.elementAt(i);
size = comp.getMinimumSize();
if (size.width > w) {
w = size.width;
}
if (size.height > h) {
h = size.height;
}
}
return new Dimension(w, h);
}
/**
* Description of the Method
*
*@param cont Description of Parameter
*@param index Description of Parameter
*@param size Description of Parameter
*@param parent Description of Parameter
*/
private void layoutCenter(Container cont,
int index, Dimension size, Dimension parent) {
Insets insets = cont.getInsets();
int top = size.height * index + insets.top + 1 + vgap * index + vgap;
int h = parent.height - (size.height + vgap) * tabs.size() - insets.top - insets.bottom - 2 - vgap * 2;
if (center != null) {
cont.remove(center);
}
center = (Component) panels.elementAt(index - 1);
center.setBounds(insets.left + 1 + hgap,
top,
parent.width - insets.left - insets.right - 2 - (hgap * 2),
h);
cont.add(center);
center.paintAll(center.getGraphics());
}
/**
* Description of the Method
*
*@param cont Description of Parameter
*@param index Description of Parameter
*@param size Description of Parameter
*@param parent Description of Parameter
*/
private void layoutTabs(Container cont,
int index, Dimension size, Dimension parent) {
Insets insets = cont.getInsets();
Component comp;
// Top tabs
int top = insets.top + 1 + vgap;
for (int i = 0; i < index; i++) {
comp = (Component) tabs.elementAt(i);
comp.setBounds(insets.left + 1 + hgap,
top,
parent.width - insets.left - insets.right - 2 - (hgap * 2),
size.height);
top += size.height + vgap;
}
// Bottom tabs
top = parent.height - insets.bottom - 1 - (size.height + vgap) * (tabs.size() - index);
for (int i = index; i < tabs.size(); i++) {
comp = (Component) tabs.elementAt(i);
comp.setBounds(insets.left + 1 + hgap,
top,
parent.width - insets.left - insets.right - 2 - (hgap * 2),
size.height);
top += size.height + vgap;
}
}
}
--- NEW FILE: EmptyIcon.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.Icon;
/**
* An icon having no graphical content, especially useful to align menu items.
*
* @author [email protected]
*/
final class EmptyIcon implements Icon {
/**
* Convenience objects for typical icons
*/
static final EmptyIcon I16 = new EmptyIcon(16);
static final EmptyIcon I24 = new EmptyIcon(24);
static final EmptyIcon I32 = new EmptyIcon(32);
static final EmptyIcon I48 = new EmptyIcon(48);
static final EmptyIcon I64 = new EmptyIcon(64);
static final EmptyIcon I128 = new EmptyIcon(128);
private int size;
/**
* Constructor
*
* @param aSize length of any side of the icon in pixels, must
* be in the range 1..100 (inclusive).
*/
EmptyIcon(int size) {
this.size=size;
}
/**
* Return the icon size (width is same as height).
*/
public int getIconWidth() {
return size;
}
/**
* Return the icon size (width is same as height).
*/
public int getIconHeight() {
return size;
}
/**
* Paints nothing, it's an *empty* icon
*/
public void paintIcon(Component c, Graphics g, int x, int y) {
//...
}
}
--- NEW FILE: ImageUtils.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Label;
import java.awt.image.MemoryImageSource;
import java.awt.image.PixelGrabber;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.SwingConstants;
/**
*@author $Author: nicolaken $
*@created 15 settembre 2001
*@version $Revision: 1.1 $, $Date: 2003/09/29 15:02:12 $
*/
public class ImageUtils implements SwingConstants {
/**
* Description of the Field
*/
public final static Component producer = new Label();
/**
* Description of the Field
*/
public final static int TRANSPARENT_RED = 255;
/**
* Description of the Field
*/
public final static int TRANSPARENT_GREEN = 0;
/**
* Description of the Field
*/
public final static int TRANSPARENT_BLUE = 255;
/**
* Description of the Field
*/
public final static int TRANSPARENT_PIXEL = 8388608;
/**
* Description of the Method
*
*@param anImage Description of Parameter
*@return Description of the Returned Value
*/
public static Image rotateImage(Image anImage) {
int w = anImage.getWidth(null);
int h = anImage.getHeight(null);
int[] pixels = new int[w * h];
PixelGrabber pixel = new PixelGrabber(anImage, 0, 0, w, h, pixels, 0, w);
try {
pixel.grabPixels();
} catch (Exception e) {
e.printStackTrace();
}
int[] rot = new int[h * w];
int pos = 0;
for (int i = w; i > 0; i--) {
for (int j = 0; j < h; j++) {
rot[pos] = pixels[i + (w * j) - 1];
pos++;
}
}
return convertBytesToImage(producer, rot, h, w);
}
/**
* Description of the Method
*
*@param c Description of Parameter
*@param pixels Description of Parameter
*@param w Description of Parameter
*@param h Description of Parameter
*@return Description of the Returned Value
*/
public static Image convertBytesToImage(Component c,
int[] pixels, int w, int h) {
return c.createImage(new MemoryImageSource(w, h, pixels, 0, w));
}
/**
* Description of the Method
*
*@param gr Description of Parameter
*@param start Description of Parameter
*@param end Description of Parameter
*@param x Description of Parameter
*@param y Description of Parameter
*@param w Description of Parameter
*@param h Description of Parameter
*@param n Description of Parameter
*@param direction Description of Parameter
*/
public static void fillGradient(Graphics gr, Color start, Color end,
int x,
int y, int w, int h, int n, int direction) {
int space;
if (direction == VERTICAL) {
space = (int) (w / n);
} else {
space = (int) (h / n);
}
int r = start.getRed();
int g = start.getGreen();
int b = start.getBlue();
int r2 = end.getRed();
int g2 = end.getGreen();
int b2 = end.getBlue();
int rp = (int) ((r2 - r) / n);
int gp = (int) ((g2 - g) / n);
int bp = (int) ((b2 - b) / n);
for (int i = 0; i < n; i++) {
gr.setColor(new Color(r, g, b));
r = r + rp;
g = g + gp;
b = b + bp;
if (direction == VERTICAL) {
gr.fillRect(x + space * i, y, space, h);
} else {
gr.fillRect(x, y + space * i, w, space);
}
}
if (direction == VERTICAL) {
gr.fillRect(x + space * n, y, w - x + space * n, h);
} else {
gr.fillRect(x, y + space * n, w, h - y + space * n);
}
}
/**
* Description of the Method
*
*@param c Description of Parameter
*@param g Description of Parameter
*@param icon Description of Parameter
*/
public static void paintBackground(Component c, Graphics g, Icon icon) {
if (icon == null) {
return;
}
int tw = icon.getIconWidth();
int th = icon.getIconHeight();
Dimension d = c.getSize();
int nw = (d.width / tw) + 1;
int nh = (d.height / th) + 1;
for (int i = 0; i < nw; i++) {
for (int j = 0; j < nh; j++) {
icon.paintIcon(c, g, i * tw, j * th);
}
}
}
/**
* Description of the Method
*
*@param component Description of Parameter
*@param g Description of Parameter
*@param image Description of Parameter
*/
public static void paintTile(Component component, Graphics g, Image image) {
paintTile(component,
g,
image,
0,
0,
((JComponent) component).getWidth(),
((JComponent) component).getHeight(), true);
}
/**
* Description of the Method
*
*@param component Description of Parameter
*@param g Description of Parameter
*@param image Description of Parameter
*@param alignWithParent Description of Parameter
*/
public static void paintTile(Component component,
Graphics g,
Image image, boolean alignWithParent) {
paintTile(component,
g,
image,
0,
0,
((JComponent) component).getWidth(),
((JComponent) component).getHeight(), alignWithParent);
}
/**
* Description of the Method
*
*@param component Description of Parameter
*@param g Description of Parameter
*@param image Description of Parameter
*@param x Description of Parameter
*@param y Description of Parameter
*@param width Description of Parameter
*@param height Description of Parameter
*/
public static void paintTile(Component component,
Graphics g,
Image image,
int x, int y, int width, int height) {
paintTile(component, g, image, x, y, width, height, true);
}
/**
* Description of the Method
*
*@param component Description of Parameter
*@param g Description of Parameter
*@param image Description of Parameter
*@param x Description of Parameter
*@param y Description of Parameter
*@param width Description of Parameter
*@param height Description of Parameter
*@param alignWithParent Description of Parameter
*/
public static void paintTile(Component component,
Graphics g,
Image image,
int x,
int y,
int width, int height, boolean alignWithParent) {
if (image == null) {
return;
}
java.awt.Shape shape = g.getClip();
g.setClip(x, y, width, height);
final int dx = image.getWidth(component);
final int dy = image.getHeight(component);
//work out the offset from (0,0) in the root frame.
int xoff = 0;
int yoff = 0;
if (alignWithParent) {
Component parent = component.getParent();
xoff = component.getLocation().x;
yoff = component.getLocation().y;
while (parent != null
&& (parent instanceof javax.swing.JInternalFrame == false)) {
//don't want the screen coords of the topmost container...
if (parent.getParent() != null) {
xoff += parent.getLocation().x;
yoff += parent.getLocation().y;
}
parent = parent.getParent();
}
x -= (xoff % dx);
y -= (yoff % dy);
}
int maxX = x + width + dx;
int maxY = y + height + dy;
for (; x <= maxX; x += dx) {
for (int j = y; j <= maxY; j += dy) {
g.drawImage(image, x, j, component);
}
}
g.setClip(shape);
}
/**
* Description of the Method
*
*@param image Description of Parameter
*@param x Description of Parameter
*@param y Description of Parameter
*@param width Description of Parameter
*@param height Description of Parameter
*@return Description of the Returned Value
*/
public static Image grab(Image image, int x, int y, int width, int height) {
if (width * height < 0) {
return null;
}
int[] pixels = new int[width * height];
PixelGrabber grabber = new PixelGrabber(image,
x,
y, width, height, pixels, 0, width);
try {
grabber.grabPixels();
} catch (Exception e) {
e.printStackTrace();
}
int pixel;
int alpha;
int red;
int green;
int blue;
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
pixel = pixels[j * width + i];
alpha = (pixel >> 24) & 0xff;
red = (pixel >> 16) & 0xff;
green = (pixel >> 8) & 0xff;
blue = (pixel) & 0xff;
// PENDING(fred): transparent only if Trans = 1 in Buttons/Taskbars
if ((red == TRANSPARENT_RED) &&
(green == TRANSPARENT_GREEN) &&
(blue == TRANSPARENT_BLUE)) {
pixels[j * width + i] = TRANSPARENT_PIXEL;
}
}
}
Image newImage = producer.createImage(new MemoryImageSource(width,
height,
pixels,
0, width));
resolve(newImage);
return newImage;
}
/**
* Description of the Method
*
*@param image Description of Parameter
*@param factor Description of Parameter
*@return Description of the Returned Value
*/
public static Image buildTile(Image image, int factor) {
int width = image.getWidth(producer);
int height = image.getHeight(producer);
int[] pixels = new int[width * height];
PixelGrabber grabber = new PixelGrabber(image,
0,
0, width, height, pixels, 0, width);
try {
grabber.grabPixels();
} catch (Exception e) {
e.printStackTrace();
}
// do an horizontal tiling
int[] zoomed = new int[pixels.length * factor];
for (int i = 0; i < height; i++) {
for (int j = 0; j < factor; j++) {
System.arraycopy(pixels,
width * i,
zoomed, (width * factor * i) + width * j, width);
}
}
pixels = zoomed;
// do a vertical duplication
int[] zoomed2 = new int[pixels.length * factor];
for (int i = 0; i < factor; i++) {
System.arraycopy(pixels, 0, zoomed2, i * pixels.length, pixels.length);
}
return producer.createImage(new MemoryImageSource(width * factor,
height * factor,
zoomed2,
0, width * factor));
}
/**
* Description of the Method
*
*@param image Description of Parameter
*/
private static void resolve(Image image) {
if (image != null) {
int width = image.getWidth(producer);
int height = image.getHeight(producer);
int[] pixels = new int[width * height];
PixelGrabber grabber = new PixelGrabber(image,
0,
0,
width, height, pixels, 0, width);
try {
grabber.grabPixels();
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* Description of the Method
*
*@param s Description of Parameter
*@return Description of the Returned Value
*/
private Color decodeColor(String s) {
int val = 0;
try {
if (s.startsWith("0x")) {
val = Integer.parseInt(s.substring(2), 16);
} else if (s.startsWith("#")) {
val = Integer.parseInt(s.substring(1), 16);
} else if (s.startsWith("0") && s.length() > 1) {
val = Integer.parseInt(s.substring(1), 8);
} else {
val = Integer.parseInt(s, 10);
}
return new Color(val);
} catch (NumberFormatException e) {
return null;
}
}
public static ImageIcon getDisabledImageIcon (ImageIcon JIcon) {
return new ImageIcon(javax.swing.GrayFilter.createDisabledImage(JIcon.getImage()));
}
}
--- NEW FILE: JButtonList.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.BorderLayout;
import java.util.ArrayList;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created June 20, 2001
*@version 1.0
*/
public class JButtonList extends JPanel {
Box box;
private ArrayList elements;
/**
* Constructor for the JButtonList object
*/
public JButtonList() {
super();
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Adds a feature to the Item attribute of the JButtonList object
*
*@param item The feature to be added to the Item attribute
*/
public void addItem(Object item) {
elements.add(item);
box.add(new JButton(item.toString()), null);
}
/**
* Description of the Method
*/
public void removeAll() {
elements.clear();
box.removeAll();
}
/**
* Description of the Method
*
*@exception Exception Description of Exception
*/
private void jbInit() throws Exception {
box = Box.createVerticalBox();
this.setLayout(new BorderLayout());
this.add(new JScrollPane(box), BorderLayout.CENTER);
}
}
--- NEW FILE: JCloseableRadioButton.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import javax.swing.BorderFactory;
import javax.swing.JButton;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created July 10, 2001
*@version 1.0
*/
public class JCloseableRadioButton extends JButton {
private JButton innerJButton;
/**
* Constructor for the JCloseableRadioButton object
*/
public JCloseableRadioButton() {
this.setBorder(new TabBorder());
this.setRequestFocusEnabled(false);
innerJButton = new JButton(" X ");
innerJButton.setBorder(BorderFactory.createEmptyBorder());
innerJButton.setFont(new Font("SansSerif", Font.PLAIN, 12));
innerJButton.setRequestFocusEnabled(false);
innerJButton.setAlignmentX((float) 1);
innerJButton.setAlignmentY((float) 0);
this.add(innerJButton);
}
/**
* Sets the text attribute of the JCloseableRadioButton object
*
*@param newText The new text value
*/
public void setText(String newText) {
super.setText(newText);
FontMetrics fm = this.getFontMetrics(this.getFont());
this.setPreferredSize(new Dimension(fm.stringWidth(this.getText()) + fm.stringWidth("X") + 20, fm.getHeight() + 12));
this.setMinimumSize(new Dimension(fm.stringWidth(this.getText()) + fm.stringWidth("X") + 20, fm.getHeight() + 12));
this.setMaximumSize(new Dimension(fm.stringWidth(this.getText()) + fm.stringWidth("X") + 20, fm.getHeight() + 12));
}
/**
* Gets the innerJButton attribute of the JCloseableRadioButton object
*
*@return The innerJButton value
*/
public JButton getInnerJButton() {
return innerJButton;
}
}
--- NEW FILE: JExceptionDialog.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;
import java.io.PrintWriter;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
//Copyright: Copyright (c) 1998
//Author: Nicola Ken Barozzi
//Company: AISA S.p.A. www.aisaindustries.it
//Description: swing enhancement
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created 1998
*@version 1.0
*/
public class JExceptionDialog extends JOptionPane {
BorderLayout borderLayout1 = new BorderLayout();
/**
* Constructor for the JExceptionDialog object
*/
public JExceptionDialog() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Description of the Method
*
*@param ParentComponent Description of Parameter
*@param Exception Description of Parameter
*/
public static void showExceptionDialog
(
Component ParentComponent,
Throwable Exception
) {
showExceptionDialog(ParentComponent,
"Java Exception occurred.", Exception, "Java Exception");
}
/**
* Description of the Method
*
*@param ParentComponent Description of Parameter
*@param Message Description of Parameter
*@param Exception Description of Parameter
*/
public static void showExceptionDialog
(
Component ParentComponent,
Object Message,
Throwable Exception
) {
showExceptionDialog(ParentComponent, Message, Exception, "Java Exception");
}
/**
* Description of the Method
*
*@param ParentComponent Description of Parameter
*@param Message Description of Parameter
*@param Exception Description of Parameter
*@param Title Description of Parameter
*/
public static void showExceptionDialog
(
Component ParentComponent,
Object Message,
Throwable Exception,
String Title
) {
Exception.printStackTrace();
final Throwable CurrentException = Exception;
JTabbedPane jExceptionTabbedPane = new JTabbedPane();
jExceptionTabbedPane.setMinimumSize(new Dimension(500, 220));
jExceptionTabbedPane.setPreferredSize(new Dimension(500, 220));
JScrollPane jToStringScrollPane = new JScrollPane();
JScrollPane jGetMessageScrollPane = new JScrollPane();
JScrollPane jStackTraceScrollPane = new JScrollPane();
JTextArea jToStringTextArea = new JTextArea();
JTextArea jGetMessageTextArea = new JTextArea();
JTextArea jStackTraceTextArea = new JTextArea();
jToStringTextArea.setFont(new Font("SansSerif", Font.PLAIN, 14));
jGetMessageTextArea.setFont(new Font("SansSerif", Font.PLAIN, 14));
jStackTraceTextArea.setFont(new Font("SansSerif", Font.PLAIN, 10));
jToStringTextArea.setLineWrap(true);
jGetMessageTextArea.setLineWrap(true);
jExceptionTabbedPane.addTab("Exception", jToStringScrollPane);
jToStringScrollPane.getViewport().add(jToStringTextArea, null);
jExceptionTabbedPane.addTab("Exception message", jGetMessageScrollPane);
jGetMessageScrollPane.getViewport().add(jGetMessageTextArea, null);
jExceptionTabbedPane.addTab("Stack trace", jStackTraceScrollPane);
jStackTraceScrollPane.getViewport().add(jStackTraceTextArea, null);
jToStringTextArea.append(Exception.toString());
jGetMessageTextArea.append(Exception.getMessage());
Object[] CurrentMessages = new Object[2];
CurrentMessages[0] = Message;
CurrentMessages[1] = jExceptionTabbedPane;
try {
PipedWriter CurrentPipedWriter = new PipedWriter();
PrintWriter CurrentWriter = new PrintWriter(CurrentPipedWriter);
PipedReader CurrentPipedReader = new PipedReader(CurrentPipedWriter);
BufferedReader CurrentReader = new BufferedReader(CurrentPipedReader);
Thread CurrentWriteThread = new WriteThread(CurrentReader,
jStackTraceTextArea);
Thread CurrentReadThread = new ReadThread(CurrentWriter,
CurrentException);
CurrentWriteThread.start();
CurrentReadThread.start();
/*
* for(int i=0;i<2;i++)//do//
* {
* CurrentString = CurrentReader.readLine();
* jStackTraceTextArea.append(CurrentString+"\n");
* }
* /while(CurrentString!=null);
* jStackTraceTextArea.append("Mostra solo due righe.");
*/
} catch (IOException ioe) {
jStackTraceTextArea.append("\n\nError in printing Stack trace.\nCheck console.");
}
JOptionPane.showMessageDialog(ParentComponent,
CurrentMessages,
Title, JOptionPane.ERROR_MESSAGE);
}
/**
* The main program for the JExceptionDialog class
*
*@param args The command line arguments
*/
public static void main(String[] args) {
Frame CurrentFrame = new Frame();
showExceptionDialog
(CurrentFrame,
"Exception message di prova.",
new Exception("Exception di prova."),
"Titolo di prova"
);
System.exit(0);
}
/**
* Description of the Method
*
*@exception Exception Description of Exception
*/
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
}
}
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
class ReadThread extends Thread {
PrintWriter CurrentWriter;
Throwable CurrentException;
/**
* Constructor for the ReadThread object
*
*@param CurrentWriter Description of Parameter
*@param CurrentException Description of Parameter
*/
ReadThread(PrintWriter CurrentWriter, Throwable CurrentException) {
this.CurrentWriter = CurrentWriter;
this.CurrentException = CurrentException;
}
/**
* Main processing method for the ReadThread object
*/
public void run() {
CurrentException.printStackTrace(CurrentWriter);
}
}
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
class WriteThread extends Thread {
BufferedReader CurrentReader;
JTextArea jStackTraceTextArea;
/**
* Constructor for the WriteThread object
*
*@param CurrentReader Description of Parameter
*@param jStackTraceTextArea Description of Parameter
*/
WriteThread(BufferedReader CurrentReader, JTextArea jStackTraceTextArea) {
this.CurrentReader = CurrentReader;
this.jStackTraceTextArea = jStackTraceTextArea;
}
/**
* Main processing method for the WriteThread object
*/
public void run() {
String CurrentString;
do {
try {
CurrentString = CurrentReader.readLine();
jStackTraceTextArea.append(CurrentString + "\n");
} catch (Throwable t) {
CurrentString = null;
}
} while (CurrentString != null);
}
//end run
}
--- NEW FILE: JFileTree.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.io.File;
import javax.swing.JTree;
import javax.swing.event.TreeModelListener;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 16 settembre 2001
*/
public class JFileTree extends JTree {
DefaultTreeCellRenderer OnlyDirsCellRenderer = new DefaultTreeCellRenderer();
/**
* Constructor for the JFileTree object
*/
public JFileTree() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Description of the Method
*
*@exception Exception Description of Exception
*/
private void jbInit() throws Exception {
this.setAutoscrolls(true);
this.setDoubleBuffered(true);
this.setShowsRootHandles(true);
this.setModel(new JTreeFileChooserModel());
this.setRootVisible(false);
OnlyDirsCellRenderer.setLeafIcon(OnlyDirsCellRenderer.getClosedIcon());
this.setCellRenderer(OnlyDirsCellRenderer);
}
}
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 16 settembre 2001
*/
class JTreeFileChooserModel implements TreeModel {
private java.io.FileFilter CurrentFileFilter;
private FileSystemView FSV = FileSystemView.getFileSystemView();
//private Vector Listeners = new Vector();
/**
* Constructor for the JTreeFileChooserModel object
*/
public JTreeFileChooserModel() {
CurrentFileFilter = new DirOnlyFileFilter();
}
/**
* Sets the fileFilter attribute of the JTreeFileChooserModel object
*
*@param newFileFilter The new fileFilter value
*/
public void setFileFilter(java.io.FileFilter newFileFilter) {
this.CurrentFileFilter = newFileFilter;
}
//Returns the child of parent at index index in the parent's child array.
/**
* Gets the child attribute of the JTreeFileChooserModel object
*
*@param parent Description of Parameter
*@param index Description of Parameter
*@return The child value
*/
public Object getChild(Object parent, int index) {
if ((parent instanceof String)) {
File[] TempFiles = File.listRoots();
return new NoPathInToStringNameFileWrapper(TempFiles[index]);
} else {
File TempFile = ((NoPathInToStringNameFileWrapper) parent).getFile();
File[] TempFiles = TempFile.listFiles(CurrentFileFilter);
return new NoPathInToStringNameFileWrapper(TempFiles[index]);
}
}
//Returns the number of children of parent.
/**
* Gets the childCount attribute of the JTreeFileChooserModel object
*
*@param parent Description of Parameter
*@return The childCount value
*/
public int getChildCount(Object parent) {
if ((parent instanceof String)) {
File[] TempFiles = File.listRoots();
return TempFiles.length;
} else {
File TempFile = ((NoPathInToStringNameFileWrapper) parent).getFile();
File[] TempFiles = TempFile.listFiles(CurrentFileFilter);
return TempFiles.length;
}
}
//Returns the index of child in parent.
/**
* Gets the indexOfChild attribute of the JTreeFileChooserModel object
*
*@param parent Description of Parameter
*@param child Description of Parameter
*@return The indexOfChild value
*/
public int getIndexOfChild(Object parent, Object child) {
if ((parent instanceof String)) {
File[] TempFiles = File.listRoots();
for (int i = 0; i < TempFiles.length; i++) {
if (TempFiles[i].compareTo(((NoPathInToStringNameFileWrapper) child).getFile()) == 0) {
return i;
}
}
return 0;
} else {
File TempFile = ((NoPathInToStringNameFileWrapper) parent).getFile();
File[] TempFiles = TempFile.listFiles(CurrentFileFilter);
for (int i = 0; i < TempFiles.length; i++) {
if (TempFiles[i].compareTo(((NoPathInToStringNameFileWrapper) child).getFile()) == 0) {
return i;
}
}
return 0;
}
}
//Returns the root of the tree.
/**
* Gets the root attribute of the JTreeFileChooserModel object
*
*@return The root value
*/
public Object getRoot() {
return new String("filesystem");
}
//Returns true if node is a leaf.
/**
* Gets the leaf attribute of the JTreeFileChooserModel object
*
*@param node Description of Parameter
*@return The leaf value
*/
public boolean isLeaf(Object node) {
if ((node instanceof String)) {
return false;
} else if (FSV.isRoot(((NoPathInToStringNameFileWrapper) node).getFile())) {
return false;
} else {
File TempFile = ((NoPathInToStringNameFileWrapper) node).getFile();
try {
if (TempFile.isDirectory()) {
File[] TempFiles = TempFile.listFiles(CurrentFileFilter);
if (TempFiles.length < 1) {
return true;
} else {
return false;
}
} else {
return true;
}
} catch (Exception e) {
return true;
}
}
}
// Adds a listener for the TreeModelEvent posted after the tree changes.
/**
* Adds a feature to the TreeModelListener attribute of the
* JTreeFileChooserModel object
*
*@param l The feature to be added to the TreeModelListener attribute
*/
public void addTreeModelListener(TreeModelListener l) { }
//Removes a listener previously added with addTreeModelListener().       Â
/**
* Description of the Method
*
*@param l Description of Parameter
*/
public void removeTreeModelListener(TreeModelListener l) { }
//Messaged when the user has altered the value for the item identified by path to newValue.
/**
* Description of the Method
*
*@param path Description of Parameter
*@param newValue Description of Parameter
*/
public void valueForPathChanged(TreePath path, Object newValue) { }
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 16 settembre 2001
*/
class DirOnlyFileFilter implements java.io.FileFilter {
/**
* Description of the Method
*
*@param pathname Description of Parameter
*@return Description of the Returned Value
*/
public boolean accept(File pathname) {
if (pathname.isDirectory()) {
return true;
} else {
return false;
}
}
}
}
--- NEW FILE: JFlatButton.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import org.krysalis.swingx.concerns.AntiAliasing;
//Copyright: Copyright (c) 1998
//Author: Nicola Ken Barozzi
//Company: AISA S.p.A. www.aisaindustries.it
//Description: swing enhancement
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created 1998
*@version 1.0
*/
public class JFlatButton extends JButton {
Border DefaultBorder;
BevelBorder LoweredBorder = new BevelBorder(BevelBorder.LOWERED);
/**
* Constructor for the JFlatButton object
*/
public JFlatButton() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Constructor for the JFlatButton object
*
*@param name Description of Parameter
*/
public JFlatButton(String name) {
try {
jbInit();
this.setText(name);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Sets the borderPainted attribute of the JFlatButton object
*
*@param parm1 The new borderPainted value
*/
public void setBorderPainted(boolean parm1) { }
/**
* Sets the focusPainted attribute of the JFlatButton object
*
*@param parm1 The new focusPainted value
*/
public void setFocusPainted(boolean parm1) { }
/**
* Description of the Method
*
*@param g1 Description of Parameter
*/
public void paint(Graphics g1) {
AntiAliasing.antialias(g1);
super.paint(g1);
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void this_mouseEntered(MouseEvent e) {
super.setBorderPainted(true);
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void this_mouseExited(MouseEvent e) {
super.setBorderPainted(false);
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void this_mousePressed(MouseEvent e) {
this.setBorder(LoweredBorder);
super.setBorderPainted(true);
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void this_mouseReleased(MouseEvent e) {
this.setBorder(DefaultBorder);
super.setBorderPainted(true);
}
/**
* Description of the Method
*
*@exception Exception Description of Exception
*/
private void jbInit() throws Exception {
DefaultBorder = super.getBorder();
this.setText("text");
this.setBorderPainted(false);
this.setToolTipText("no info avaiable");
this.setDoubleBuffered(true);
super.setFocusPainted(false);
super.setBorderPainted(false);
this.addMouseListener(
new java.awt.event.MouseAdapter() {
public void mouseEntered(MouseEvent e) {
this_mouseEntered(e);
}
public void mouseExited(MouseEvent e) {
this_mouseExited(e);
}
/*
* public void mousePressed(MouseEvent e)
* {
* this_mousePressed(e);
* }
* public void mouseReleased(MouseEvent e)
* {
* this_mouseReleased(e);
* }
*/
}
);
}
}
--- NEW FILE: JLoadProgressSplash.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.io.File;
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
public class JLoadProgressSplash extends JSplash {
private JProgressBar jProgressBar;
private int increment;
/**
* Constructor for the JLoadProgressSplash object
*
*@param image Description of Parameter
*@param parent Description of Parameter
*@param numOfIncrements Description of Parameter
*@param timeout Description of Parameter
*/
public JLoadProgressSplash(ImageIcon image, JFrame parent, int numOfIncrements, int timeout) {
super(image, parent, timeout);
jProgressBar = new JProgressBar(0, 100);
jProgressBar.setBorderPainted(true);
jProgressBar.setStringPainted(true);
jProgressBar.setString("loading...");
this.increment = 100 / numOfIncrements;
super.getContentPane().add(jProgressBar, BorderLayout.SOUTH);
super.pack();
}
/**
* The main program for the JLoadProgressSplash class
*
*@param args The command line arguments
*/
public static void main(String[] args) {
try {
//start splash
JLoadProgressSplash splash = new JLoadProgressSplash(new ImageIcon(new File("./resources/icons/monarchWP.gif").toURL()),
new JFrame(), 20, 20000);
splash.show();
splash.increment("a");
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Description of the Method
*
*@param actionInProgress Description of Parameter
*/
public void increment(String actionInProgress) {
if (jProgressBar.getValue() == 100) {
return;
}
int remaining = (100 - jProgressBar.getValue());
if (remaining < increment) {
jProgressBar.setValue(100);
} else {
jProgressBar.setValue(jProgressBar.getValue() + increment);
}
jProgressBar.setString(actionInProgress + " - " + String.valueOf((int) (jProgressBar.getPercentComplete() * 100)) + "%");
}
}
--- NEW FILE: JOutlookBar.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JPanel;
import org.krysalis.swingx.concerns.AntiAliasing;
/**
*@author Claude Duguay
*@author Jan Seda
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created 2001
*/
public class JOutlookBar extends JPanel
implements ActionListener {
/**
* Description of the Field
*/
protected Vector buttons = new Vector();
/**
* Description of the Field
*/
protected Vector names = new Vector();
/**
* Description of the Field
*/
protected Vector views = new Vector();
/**
* Description of the Field
*/
protected Vector components = new Vector();
/**
* Constructor for the JOutlookBar object
*/
public JOutlookBar() {
setLayout(new ContextLayout());
setPreferredSize(new Dimension(80, 80));
}
/**
* Sets the index attribute of the JOutlookBar object
*
*@param index The new index value
*/
public void setIndex(int index) {
((ContextLayout) getLayout()).setIndex(this, index);
}
/**
* Gets the empty attribute of the JOutlookBar object
*
*@return The empty value
*/
public boolean isEmpty() {
return views.isEmpty();
}
/**
* Class AppFrame implements interface ActionListener. Reference to that
* class is then inserted to outlook buttons and here is the code that is
* called when button is pressed. param context - its forder (some call it
* context) name param btnText - text for button param image - button image
* URL param action - ActionListener called by button when pressed
*
*@param context The feature to be added to the Component attribute
*@param child The feature to be added to the Component attribute
*/
public void addComponent(String context, JComponent child) {
int index;
JPanel view;
components.add(child);
if ((index = names.indexOf(context)) > -1) {
view = (JPanel) views.elementAt(index);
} else {
view = new JPanel();
//view.setLayout(new ListLayout());
view.setLayout(new BorderLayout());
//view.setBackground(Color.blue);
names.addElement(context);
views.addElement(view);
addTab(context, view);
}
view.add(child);
doLayout();
}
/**
* Adds a feature to the Component attribute of the JOutlookBar object
*
*@param context The feature to be added to the Component attribute
*@param icon The feature to be added to the Component attribute
*@param child The feature to be added to the Component attribute
*/
public void addComponent(String context, ImageIcon icon, JComponent child) {
int index;
JPanel view;
components.add(child);
if ((index = names.indexOf(context)) > -1) {
view = (JPanel) views.elementAt(index);
} else {
view = new JPanel();
view.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(0,
2, 0, 2), BorderFactory.createLoweredBevelBorder()));
//view.setLayout(new ListLayout());
view.setLayout(new BorderLayout());
//view.setBackground(Color.blue);
names.addElement(context);
views.addElement(view);
addTab(context, icon, view);
}
view.add(child);
doLayout();
}
/**
* Description of the Method
*
*@param button Description of Parameter
*/
public void removeTab(JButton button) {
button.removeActionListener(this);
buttons.removeElement(button);
remove(button);
}
/**
* Description of the Method
*
*@param component Description of Parameter
*/
public synchronized void removeComponent(JComponent component) {
if (components.contains(component)) {
int indexToRemove = components.indexOf(component);
JButton currentButton = (JButton) buttons.get(indexToRemove);
buttons.remove(indexToRemove);
names.remove(indexToRemove);
views.remove(indexToRemove);
components.remove(indexToRemove);
remove(currentButton);
currentButton.removeActionListener(this);
this.setIndex(1);
doLayout();
}
}
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void actionPerformed(ActionEvent event) {
Object source = event.getSource();
for (int i = 0; i < buttons.size(); i++) {
if (source == buttons.elementAt(i)) {
setIndex(i + 1);
return;
}
}
}
/**
* Description of the Method
*
*@param g1 Description of Parameter
*/
public void paint(Graphics g1) {
AntiAliasing.antialias(g1);
super.paint(g1);
}
/**
* Adds a feature to the Tab attribute of the JOutlookBar object
*
*@param name The feature to be added to the Tab attribute
*@param comp The feature to be added to the Tab attribute
*/
private void addTab(String name, Component comp) {
JButton button = new TabButton(name);
add(button, comp);
buttons.addElement(button);
button.addActionListener(this);
}
/**
* Adds a feature to the Tab attribute of the JOutlookBar object
*
*@param name The feature to be added to the Tab attribute
*@param icon The feature to be added to the Tab attribute
*@param comp The feature to be added to the Tab attribute
*/
private void addTab(String name, ImageIcon icon, Component comp) {
JButton button = (JButton)new TabButton(name, icon);
add(button, comp);
buttons.addElement(button);
button.addActionListener(this);
}
}
--- NEW FILE: JSplash.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JWindow;
import javax.swing.Timer;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created June 20, 2001
*@version 1.0
*/
public class JSplash extends JWindow
implements KeyListener, MouseListener, ActionListener {
/**
* Constructor for the JSplash object
*
*@param image Description of Parameter
*@param parent Description of Parameter
*@param timeout Description of Parameter
*/
public JSplash(ImageIcon image, JFrame parent, int timeout) {
super(parent);
int w = image.getIconWidth();
int h = image.getIconHeight();
Dimension screen =
Toolkit.getDefaultToolkit().getScreenSize();
int x = (screen.width - w) / 2;
int y = (screen.height - h) / 2;
setBounds(x, y, w, h);
getContentPane().setLayout(new BorderLayout());
JLabel picture = new JLabel(image);
getContentPane().add(picture, BorderLayout.CENTER);
picture.setBorder(BorderFactory.createEmptyBorder());
// Listen for key strokes
addKeyListener(this);
// Listen for mouse events from here and parent
addMouseListener(this);
parent.addMouseListener(this);
// Timeout after a while
Timer timer = new Timer(0, this);
timer.setRepeats(false);
timer.setInitialDelay(timeout);
timer.start();
}
/**
* Description of the Method
*/
public void block() {
while (isVisible()) {
}
}
// Dismiss the window on a key press
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void keyTyped(KeyEvent event) { }
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void keyReleased(KeyEvent event) { }
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void keyPressed(KeyEvent event) {
setVisible(false);
dispose();
}
// Dismiss the window on a mouse click
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void mousePressed(MouseEvent event) { }
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void mouseReleased(MouseEvent event) { }
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void mouseEntered(MouseEvent event) { }
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void mouseExited(MouseEvent event) { }
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void mouseClicked(MouseEvent event) {
setVisible(false);
dispose();
}
// Dismiss the window on a timeout
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void actionPerformed(ActionEvent event) {
setVisible(false);
dispose();
}
}
--- NEW FILE: JSwitcherToolBar.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JToolBar;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.krysalis.swingx.resources.ResourceFactory;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created June 20, 2001
*@version 1.0
*/
public class JSwitcherToolBar extends JToolBar implements Component, Composable,
Initializable {
ButtonGroup buttonGroup = new ButtonGroup();
ImageIcon icon;
ImageIcon selectedJIcon;
ImageIcon disabledJIcon;
ImageIcon disabledSelectedJIcon;
private ResourceFactory resourceFactory;
/**
* Constructor for the JSwitcherToolBar object
*/
public JSwitcherToolBar() {
super();
}
/**
* Description of the Method
*
*@param cm Description of Parameter
*@exception ComponentException Description of Exception
*/
public void compose(ComponentManager cm) throws ComponentException {
resourceFactory = (ResourceFactory) cm.lookup("ResourceFactory");
}
/**
* Description of the Method
*/
public void initialize() {
super.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
}
/**
* Description of the Method
*
*@param component Description of Parameter
*/
public void add(JComponent component) {
if (component instanceof AbstractButton) {
if (buttonGroup.getButtonCount() == 0) {
((AbstractButton) component).setSelected(true);
}
((AbstractButton) component).setIcon(icon);
((AbstractButton) component).setSelectedIcon(selectedJIcon);
((AbstractButton) component).setDisabledIcon(disabledJIcon);
((AbstractButton) component).setDisabledSelectedIcon(disabledSelectedJIcon);
buttonGroup.add((AbstractButton) component);
super.add((AbstractButton) component);
}
}
/**
* Description of the Method
*/
public void removeAll() {
buttonGroup = new ButtonGroup();
super.removeAll();
}
/**
* Description of the Method
*
*@param component Description of Parameter
*/
public void remove(JComponent component) {
if (component instanceof AbstractButton) {
buttonGroup.remove((AbstractButton) component);
super.remove((AbstractButton) component);
}
}
}
--- NEW FILE: JTreeFileChooser.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 16 settembre 2001
*/
public class JTreeFileChooser extends JDialog {
/**
* Description of the Field
*/
public int APPROVE_OPTION = JFileChooser.APPROVE_OPTION;
/**
* Description of the Field
*/
public int CANCEL_OPTION = JFileChooser.CANCEL_OPTION;
File SelectedFile;
int selectedOption = CANCEL_OPTION;
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
TitledBorder titledBorder1;
Border border1;
JButton jCancelButton = new JButton();
JButton jOkButton = new JButton();
JScrollPane jScrollPane1 = new JScrollPane();
JFileTree jFileTree1 = new JFileTree();
/**
* Constructor for the JTreeFileChooser object
*/
public JTreeFileChooser() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Constructor for the JTreeFileChooser object
*
*@param owner Description of Parameter
*/
public JTreeFileChooser(Frame owner) {
super(owner, true);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Gets the selectedFile attribute of the JTreeFileChooser object
*
*@return The selectedFile value
*/
public File getSelectedFile() {
return SelectedFile;
}
/**
* Description of the Method
*
*@return Description of the Returned Value
*/
public int showSelectDirectoryDialog() {
jFileTree1.addTreeSelectionListener(new CurrentSelectionListener());
this.setSize(300, 350);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension DSize = this.getSize();
if (DSize.height > screenSize.height) {
DSize.height = screenSize.height;
}
if (DSize.width > screenSize.width) {
DSize.width = screenSize.width;
}
this.setLocation((screenSize.width - DSize.width) / 2,
(screenSize.height - DSize.height) / 2);
this.setTitle("Scegli una directory");
this.setVisible(true);
return selectedOption;
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void jOkButton_actionPerformed(ActionEvent e) {
selectedOption = this.APPROVE_OPTION;
this.setVisible(false);
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void jCancelButton_actionPerformed(ActionEvent e) {
selectedOption = this.CANCEL_OPTION;
this.setVisible(false);
}
/**
* Description of the Method
*
*@exception Exception Description of Exception
*/
private void jbInit() throws Exception {
titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, new Color(142, 142, 142)), "Scegli una directory");
border1 = BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(Color.white, new Color(142, 142, 142)), BorderFactory.createEmptyBorder(5, 5, 5, 5));
jPanel1.setLayout(borderLayout1);
jPanel1.setBorder(border1);
jCancelButton.setToolTipText("");
jCancelButton.setActionCommand("jCancelButton");
jCancelButton.setSelected(true);
jCancelButton.setText("Annulla");
jCancelButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jCancelButton_actionPerformed(e);
}
});
jOkButton.setMaximumSize(new Dimension(61, 27));
jOkButton.setMinimumSize(new Dimension(61, 27));
jOkButton.setPreferredSize(new Dimension(61, 27));
jOkButton.setToolTipText("");
jOkButton.setActionCommand("jOkButton");
jOkButton.setText("Ok");
jOkButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jOkButton_actionPerformed(e);
}
});
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jFileTree1, null);
this.getContentPane().add(jPanel2, BorderLayout.SOUTH);
jPanel2.add(jOkButton, null);
jPanel2.add(jCancelButton, null);
}
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 16 settembre 2001
*/
class CurrentSelectionListener implements javax.swing.event.TreeSelectionListener {
/**
* Description of the Method
*
*@param e Description of Parameter
*/
public void valueChanged(TreeSelectionEvent e) {
SelectedFile = ((NoPathInToStringNameFileWrapper) (e.getNewLeadSelectionPath().getLastPathComponent())).getFile();
//debug
System.out.println(SelectedFile.getPath());
}
}
}
--- NEW FILE: LinkEnabledJEditorPane.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Graphics;
import java.io.IOException;
import java.net.URL;
import javax.swing.JEditorPane;
import javax.swing.JOptionPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import org.krysalis.swingx.concerns.AntiAliasing;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created June 20, 2001
*@version 1.0
*/
public class LinkEnabledJEditorPane extends JEditorPane {
/**
* Constructor for the LinkEnabledJEditorPane object
*/
public LinkEnabledJEditorPane() {
super();
}
/**
* Constructor for the LinkEnabledJEditorPane object
*
*@param documentURL Description of Parameter
*@exception IOException Description of Exception
*/
public LinkEnabledJEditorPane(URL documentURL) throws IOException {
super(documentURL);
this.setEditable(false);
this.addHyperlinkListener(
new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
try {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
LinkEnabledJEditorPane.this.setPage(e.getURL());
}
} catch (IOException ex) {
JOptionPane.showMessageDialog(LinkEnabledJEditorPane.this,
ex.getMessage());
}
}
}
);
}
/**
* Description of the Method
*
*@param g1 Description of Parameter
*/
public void paint(Graphics g1) {
AntiAliasing.antialias(g1);
super.paint(g1);
}
}
/*
* void jLogoButton_actionPerformed (ActionEvent e) {
* EditorPanel.removeAll();
* try {
* final JEditorPane bibopEditorPane = new JEditorPane();
* bibopEditorPane.setEditable(false);
* bibopEditorPane.setEditorKitForContentType("text/html",
* new PatchedHTMLEditorKit());
* EditorPanel.setLayout(new BorderLayout());
* EditorPanel.add(new JScrollPane(bibopEditorPane), BorderLayout.CENTER);
* bibopEditorPane.setPage(new URL("http://opensource.bibop.it/"));
* bibopEditorPane.addHyperlinkListener(new SimpleLinkListener(bibopEditorPane,
* null, null));
* EditorPanel.revalidate();
* }
* catch (IOException ioe) {
* JOptionPane.showMessageDialog(this, "Visit opensource.bibop.it.");
* }
* }
*/
--- NEW FILE: ListLayout.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager2;
import java.io.Serializable;
import java.util.Vector;
/**
* Copyright by Cleverlance 2001 Author: Claude Duguay, Jan Seda Contact:
* [email protected] Website: www.cleverlance.com
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
/**
* Copyright by Cleverlance 2001 Author: Claude Duguay, Jan Seda Contact:
* [email protected] Website: www.cleverlance.com
*
* A list layout puts elements in a vertical list, based on their vertical
* preferred size. The width is expanded automatically.
*
*@author Luca Jun Barozzi
*@author Claude Duguay
*@created 15 settembre 2001
*@version 1.0
*/
public class ListLayout extends AbstractLayout implements LayoutManager2,
Serializable {
/**
* Description of the Field
*/
public final static int CENTER = 0;
/**
* Description of the Field
*/
public final static int LEFT = 1;
/**
* Description of the Field
*/
public final static int RIGHT = 2;
/**
* Description of the Field
*/
public final static int BOTH = 3;
/**
* Description of the Field
*/
protected Vector tabs = new Vector();
/**
* Description of the Field
*/
protected Vector panels = new Vector();
/**
* Description of the Field
*/
protected Component center;
/**
* Description of the Field
*/
protected int index = 1;
/**
* Description of the Field
*/
protected int alignment = BOTH;
/**
* Constructs a ContextLayout with no gaps between components.
*/
public ListLayout() {
super();
}
/**
* Constructs a ContextLayout with no gaps between components and the
* specified alignment.
*
*@param alignment The LEFT, RIGHT, CENTER or BOTH alignment
*/
public ListLayout(int alignment) {
super();
this.alignment = alignment;
}
/**
* Constructs a ContextLayout with the specified gaps.
*
*@param hgap The horizontal gap
*@param vgap The vertical gap
*/
public ListLayout(int hgap, int vgap) {
super(hgap, vgap);
}
/**
* Constructs a ContextLayout with the specified gaps.
*
*@param hgap The horizontal gap
*@param vgap The vertical gap
*@param alignment The LEFT, RIGHT, CENTER or BOTH alignment
*/
public ListLayout(int hgap, int vgap, int alignment) {
super(hgap, vgap);
this.alignment = alignment;
}
/**
* Returns the minimum dimensions needed to layout the components contained
* in the specified target container.
*
*@param target The Container on which to do the layout
*@return Description of the Returned Value
*/
public Dimension minimumLayoutSize(Container target) {
Insets insets = target.getInsets();
int w = 0;
int h = 0;
Dimension size;
int ncomponents = target.getComponentCount();
for (int i = 0; i < ncomponents; i++) {
size = target.getComponent(i).getMinimumSize();
if (size.width > w) {
w = size.width;
}
if (size.height > h) {
h = size.height;
}
}
h = ((h + vgap) * ncomponents) - hgap;
return new Dimension(w + (hgap * 2), h);
}
/**
* Returns the preferred dimensions for this layout given the components in
* the specified target container.
*
*@param target The component which needs to be laid out
*@return Description of the Returned Value
*/
public Dimension preferredLayoutSize(Container target) {
Insets insets = target.getInsets();
int w = 0;
int h = 0;
Dimension size;
int ncomponents = target.getComponentCount();
for (int i = 0; i < ncomponents; i++) {
size = target.getComponent(i).getPreferredSize();
if (size.width > w) {
w = size.width;
}
if (size.height > h) {
h = size.height;
}
}
h = ((h + vgap) * ncomponents) - hgap;
return new Dimension(w + (hgap * 2), h);
}
/**
* Lays out the specified container. This method will actually reshape the
* components in the specified target container in order to satisfy the
* constraints of the layout object.
*
*@param parent Description of Parameter
*/
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
int w = parent.getSize().width;
Component comp;
Dimension size;
int position = insets.top;
int ncomponents = parent.getComponentCount();
for (int i = 0; i < ncomponents; i++) {
comp = parent.getComponent(i);
size = comp.getPreferredSize();
int h = size.height - insets.top - insets.bottom;
switch (alignment) {
case CENTER:
{
int l = (w - size.width) / 2;
comp.setBounds(insets.left + hgap + l, position,
size.width - insets.left - insets.right - (hgap * 2),
h);
break;
}
case LEFT:
{
comp.setBounds(insets.left + hgap, position,
size.width - insets.left - insets.right - (hgap * 2),
h);
break;
}
case RIGHT:
{
int l = w - size.width;
comp.setBounds(insets.left + hgap + l, position,
size.width - insets.left - insets.right - (hgap * 2),
h);
break;
}
default:
{
comp.setBounds(insets.left + hgap, position,
w - insets.left - insets.right - (hgap * 2), h);
break;
}
}
position += h + vgap;
}
}
}
--- NEW FILE: NoPathInToStringNameFileWrapper.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.io.*;
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 16 settembre 2001
*/
public class NoPathInToStringNameFileWrapper {
File CurrentFile;
String CurrentFileName;
/**
* Constructor for the NoPathInToStringNameFileWrapper object
*
*@param CurrentFile Description of Parameter
*/
public NoPathInToStringNameFileWrapper(File CurrentFile) {
this.CurrentFile = CurrentFile;
this.CurrentFileName = getName();
}
/**
* Gets the file attribute of the NoPathInToStringNameFileWrapper object
*
*@return The file value
*/
public File getFile() {
return CurrentFile;
}
/**
* Description of the Method
*
*@return Description of the Returned Value
*/
public String toString() {
return this.CurrentFileName;
}
/**
* Gets the name attribute of the NoPathInToStringNameFileWrapper object
*
*@return The name value
*/
private String getName() {
if (CurrentFile.getParent() == null) {
return this.CurrentFile.getPath();
} else {
return this.CurrentFile.getName();
}
}
}
--- NEW FILE: OrderedHashtableComboBoxModel.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import javax.swing.event.ListDataListener;
import javax.swing.ComboBoxModel;
import java.util.*;
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 16 settembre 2001
*/
public class OrderedHashtableComboBoxModel implements ComboBoxModel {
private Vector ElementsHashTable = new Vector();
/**
* Constructor for the OrderedHashtableComboBoxModel object
*/
public OrderedHashtableComboBoxModel() { }
/**
* Sets the selectedItem attribute of the OrderedHashtableComboBoxModel
* object
*
*@param anItem The new selectedItem value
*/
public void setSelectedItem(Object anItem) { }
/**
* Gets the selectedItem attribute of the OrderedHashtableComboBoxModel
* object
*
*@return The selectedItem value
*/
public Object getSelectedItem() {
//TODO: implement this com.sun.java.swing.ComboBoxModel method;
return new String();
}
/**
* Gets the size attribute of the OrderedHashtableComboBoxModel object
*
*@return The size value
*/
public int getSize() {
//TODO: implement this com.sun.java.swing.ListModel method;
return 1;
}
/**
* Gets the elementAt attribute of the OrderedHashtableComboBoxModel object
*
*@param index Description of Parameter
*@return The elementAt value
*/
public Object getElementAt(int index) {
//TODO: implement this com.sun.java.swing.ListModel method;
return new String();
}
/**
* Adds a feature to the ListDataListener attribute of the
* OrderedHashtableComboBoxModel object
*
*@param l The feature to be added to the ListDataListener attribute
*/
public void addListDataListener(ListDataListener l) { }
/**
* Description of the Method
*
*@param l Description of Parameter
*/
public void removeListDataListener(ListDataListener l) { }
}
--- NEW FILE: PatchedHTMLEditorKit.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JEditorPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.MouseInputAdapter;
import javax.swing.text.AttributeSet;
import javax.swing.text.Document;
import javax.swing.text.Element;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
/*
* PatchedHTMLEditorKit.java
* A simple extension of the HTMLEditor kit that fires Enter/Exit
* hyperlink events.
*
* from www.javaworld.com
*/
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
public class PatchedHTMLEditorKit extends HTMLEditorKit {
// Since we only have two mouse events to listen to, we'll use the same
// method to generate the appropriate hyperlinks and distinguish
// between them when we react to the mouse events.
/**
* Description of the Field
*/
public final static int JUMP = 0;
/**
* Description of the Field
*/
public final static int MOVE = 1;
LinkController myController = new LinkController();
/**
* Description of the Method
*
*@param c Description of Parameter
*/
public void install(JEditorPane c) {
c.addMouseListener(myController);
c.addMouseMotionListener(myController);
}
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
public static class LinkController extends MouseInputAdapter
implements Serializable {
URL currentUrl = null;
// here's the mouseClicked event similar to the one in
// the regular HTMLEditorKit, updated to indicate this is
// a "jump" event
/**
* Description of the Method
*
*@param e Description of Parameter
*/
public void mouseClicked(MouseEvent e) {
JEditorPane editor = (JEditorPane) e.getSource();
if (!editor.isEditable()) {
Point pt = new Point(e.getX(), e.getY());
int pos = editor.viewToModel(pt);
if (pos >= 0) {
activateLink(pos, editor, JUMP);
}
}
}
// And here's our addition. Now the mouseMove events will
// also call activateLink, but with a "move" type
/**
* Description of the Method
*
*@param e Description of Parameter
*/
public void mouseMoved(MouseEvent e) {
JEditorPane editor = (JEditorPane) e.getSource();
if (!editor.isEditable()) {
Point pt = new Point(e.getX(), e.getY());
int pos = editor.viewToModel(pt);
if (pos >= 0) {
activateLink(pos, editor, MOVE);
}
}
}
// activateLink has now been updated to decide which hyperlink
// event to generate, based on the event type and status of the
// currentUrl field. Rather than have two handlers (one for
// enter/exit, one for active) we do all the work here. This
// saves us the effort of duplicating the href location code.
// But that's really minor point. You could certainly provide
// two handlers if that makes more sense to you.
/**
* Description of the Method
*
*@param pos Description of Parameter
*@param html Description of Parameter
*@param type Description of Parameter
*/
protected void activateLink(int pos, JEditorPane html, int type) {
Document doc = html.getDocument();
if (doc instanceof HTMLDocument) {
HTMLDocument hdoc = (HTMLDocument) doc;
Element e = hdoc.getCharacterElement(pos);
AttributeSet a = e.getAttributes();
AttributeSet anchor = (AttributeSet) a.getAttribute(HTML.Tag.A);
String href = (anchor != null) ?
(String) anchor.getAttribute(HTML.Attribute.HREF) : null;
boolean shouldExit = false;
HyperlinkEvent linkEvent = null;
if (href != null) {
URL u;
try {
u = new URL(hdoc.getBase(), href);
} catch (MalformedURLException m) {
u = null;
}
if ((type == MOVE) && (!u.equals(currentUrl))) {
linkEvent = new HyperlinkEvent(html,
HyperlinkEvent.EventType.ENTERED,
u, href);
currentUrl = u;
} else if (type == JUMP) {
linkEvent = new HyperlinkEvent(html,
HyperlinkEvent.EventType.ACTIVATED,
u, href);
shouldExit = true;
} else {
return;
}
html.fireHyperlinkUpdate(linkEvent);
} else if (currentUrl != null) {
shouldExit = true;
}
if (shouldExit) {
linkEvent = new HyperlinkEvent(html,
HyperlinkEvent.EventType.EXITED,
currentUrl, null);
html.fireHyperlinkUpdate(linkEvent);
currentUrl = null;
}
}
}
}
}
--- NEW FILE: ScrollingPanel.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JViewport;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.plaf.basic.BasicArrowButton;
/**
* Copyright by Cleverlance 2001 Author: Claude Duguay, Jan Seda Contact:
* [email protected] Website: www.cleverlance.com
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
public class ScrollingPanel extends JPanel implements ActionListener {
/**
* Description of the Field
*/
protected JButton north, south;
/**
* Description of the Field
*/
protected JViewport viewport;
/**
* Description of the Field
*/
protected int incr = 64;
/**
* Constructor for the ScrollingPanel object
*
*@param component Description of Parameter
*/
public ScrollingPanel(Component component) {
setLayout(new BorderLayout());
north = new BasicArrowButton(BasicArrowButton.NORTH);
south = new BasicArrowButton(BasicArrowButton.SOUTH);
viewport = new JViewport();
add("Center", viewport);
viewport.setView(component);
north.addActionListener(this);
south.addActionListener(this);
}
/**
* Sets the bounds attribute of the ScrollingPanel object
*
*@param x The new bounds value
*@param y The new bounds value
*@param w The new bounds value
*@param h The new bounds value
*/
public void setBounds(int x, int y, int w, int h) {
super.setBounds(x, y, w, h);
Dimension view = new Dimension(w, h);
Dimension pane = viewport.getView().getPreferredSize();
viewport.setViewPosition(new Point(0, 0));
remove(north);
if (pane.height >= view.height) {
add("South", south);
} else {
remove(south);
}
doLayout();
}
/**
* Description of the Method
*
*@param event Description of Parameter
*/
public void actionPerformed(ActionEvent event) {
Dimension view = getSize();
Dimension pane = viewport.getView().getPreferredSize();
Point top = viewport.getViewPosition();
if (event.getSource() == north) {
if (pane.height > view.height) {
add("South", south);
}
if (top.y < incr) {
viewport.setViewPosition(new Point(0, 0));
remove(north);
} else {
viewport.setViewPosition(new Point(0, top.y - incr));
}
doLayout();
}
if (event.getSource() == south) {
if (pane.height > view.height) {
add("North", north);
}
int max = pane.height - view.height;
if (top.y > (max - incr)) {
remove(south);
doLayout();
view = viewport.getExtentSize();
max = pane.height - view.height;
viewport.setViewPosition(new Point(0, max));
} else {
viewport.setViewPosition(new Point(0, top.y + incr));
}
doLayout();
}
}
}
--- NEW FILE: SimpleLinkListener.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Cursor;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
/*
* SimpleLinkListener.java
* A hyperlink listener for use with JEditorPane. This
* listener will change the cursor over hotspots based on enter/exit
* events and also load a new page when a valid hyperlink is clicked.
*/
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
public class SimpleLinkListener implements HyperlinkListener {
private JEditorPane pane;
// The pane we're using to display HTML
private JTextField urlField;
// An optional textfield for showing
// the current URL being displayed
private JLabel statusBar;
// An option label for showing where
// a link would take you
/**
* Constructor for the SimpleLinkListener object
*
*@param jep Description of Parameter
*@param jtf Description of Parameter
*@param jl Description of Parameter
*/
public SimpleLinkListener(JEditorPane jep, JTextField jtf, JLabel jl) {
pane = jep;
urlField = jtf;
statusBar = jl;
}
/**
* Constructor for the SimpleLinkListener object
*
*@param jep Description of Parameter
*/
public SimpleLinkListener(JEditorPane jep) {
this(jep, null, null);
}
/**
* Description of the Method
*
*@param he Description of Parameter
*/
public void hyperlinkUpdate(HyperlinkEvent he) {
// We'll keep some basic debuggin information in here so you can
// verify our new editor kit is working.
System.out.print("Hyperlink event started...");
HyperlinkEvent.EventType type = he.getEventType();
// Ok. Decide which event we got...
if (type == HyperlinkEvent.EventType.ENTERED) {
// Enter event. Go the the "hand" cursor and fill in the status bar
System.out.println("entered");
pane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
statusBar.setText(he.getURL().toString());
} else if (type == HyperlinkEvent.EventType.EXITED) {
// Exit event. Go back to the default cursor and clear the status bar
System.out.println("exited");
pane.setCursor(Cursor.getDefaultCursor());
statusBar.setText(" ");
} else {
// Jump event. Get the url, and if it's not null, switch to that
// page in the main editor pane and update the "site url" label.
System.out.println("activated");
try {
pane.setPage(he.getURL());
if (urlField != null) {
urlField.setText(he.getURL().toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
--- NEW FILE: StoreEntitySelector.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreePath;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.component.Composable;
import org.krysalis.jplugin.components.sheets.stores.StoresTreeSheet;
import org.krysalis.jplugin.framework.services.activation.Activator;
import org.krysalis.swingx.icons.IconFactory;
import org.krysalis.swingx.resources.ResourceFactory;
import org.krysalis.jplugin.framework.services.storage.Storage;
import org.krysalis.jplugin.framework.storage.StoreEntity;
import org.krysalis.swingx.concerns.AntiAliasing;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created June 20, 2001
*@version 1.0
*/
public class StoreEntitySelector extends JDialog implements Composable {
private static boolean selectionDone = false;
JPanel jPanel1 = new JPanel();
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
JSplitPane jSplitPane1 = new JSplitPane();
BorderLayout borderLayout2 = new BorderLayout();
StoresTreeSheet storesTreeSheet;
JLabel jLabel2 = new JLabel();
JPanel jPanel4 = new JPanel();
JButton jSelectButton = new JButton();
JButton jCancelButton = new JButton();
BorderLayout borderLayout3 = new BorderLayout();
JPanel jPreviewPanel = new JPanel();
JLabel jPreviewLabel = new JLabel();
BorderLayout borderLayout4 = new BorderLayout();
JCheckBox jEnablePreviewCheckBox = new JCheckBox();
Border border1;
JPanel jPanel5 = new JPanel();
JPanel jPanel6 = new JPanel();
JTextField jSelectedTextField = new JTextField(16);
BorderLayout borderLayout5 = new BorderLayout();
BorderLayout borderLayout6 = new BorderLayout();
Border border2;
JLabel jLabel1 = new JLabel();
private URL selectedURI = null;
private boolean createURIFromString = true;
private Storage rootStore;
private ResourceFactory resourceFactory;
private IconFactory iconFactory;
private Activator activator;
/**
* Constructor for the StoreEntitySelector object
*
*@param rootStore Description of Parameter
*/
private StoreEntitySelector(Storage rootStore) {
super();
try {
//storesTreeSheet = (StoresTreeSheet) Lifecycle.getInstance().setup(new StoresTreeSheet(false));
storesTreeSheet.addTreeSelectionListener(new CurrentSelectionListener());
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Description of the Method
*
*@param rootStore Description of Parameter
*@return Description of the Returned Value
*/
public static URL showSelector(Storage rootStore) {
StoreEntitySelector selector = new StoreEntitySelector(rootStore);
selector.pack();
WindowUtils.sizeTo(selector, 0.7, 0.7);
WindowUtils.centerOnScreen(selector);
selector.show();
return selector.getSelectedURI();
}
/**
* Gets the selectedURI attribute of the StoreEntitySelector object
*
*@return The selectedURI value
*/
public URL getSelectedURI() {
return this.selectedURI;
}
/**
* Description of the Method
*
*@param cm Description of Parameter
*@exception ComponentException Description of Exception
*/
public void compose(ComponentManager cm) throws ComponentException {
rootStore = (Storage) cm.lookup("Storage");
resourceFactory = (ResourceFactory) cm.lookup("ResourceFactory");
iconFactory = (IconFactory) cm.lookup("IconFactory");
activator = (Activator) cm.lookup("Activator");
}
/**
* Description of the Method
*
*@param g1 Description of Parameter
*/
public void paint(Graphics g1) {
AntiAliasing.antialias(g1);
super.paint(g1);
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void jSelectButton_actionPerformed(ActionEvent e) {
done(true);
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void jCancelButton_actionPerformed(ActionEvent e) {
selectedURI = null;
done(false);
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void jSelectedTextField_keyTyped(KeyEvent e) {
createURIFromString = true;
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void jSelectedTextField_keyPressed(KeyEvent e) { }
/**
* Description of the Method
*
*@param e Description of Parameter
*/
void jSelectedTextField_keyReleased(KeyEvent e) { }
/**
* Description of the Method
*
*@exception Exception Description of Exception
*/
private void jbInit() throws Exception {
border2 = BorderFactory.createEmptyBorder(4, 4, 4, 4);
jPanel1.setLayout(borderLayout1);
jPanel2.setLayout(borderLayout2);
jLabel2.setText("jLabel2");
jSelectButton.setEnabled(false);
jSelectButton.setText("Select");
jSelectButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jSelectButton_actionPerformed(e);
}
}
);
jCancelButton.setToolTipText("");
jCancelButton.setText("Cancel");
jCancelButton.addActionListener(
new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jCancelButton_actionPerformed(e);
}
}
);
jPanel3.setLayout(borderLayout3);
jPreviewLabel.setHorizontalAlignment(SwingConstants.CENTER);
jPreviewLabel.setHorizontalTextPosition(SwingConstants.CENTER);
jPreviewLabel.setText("preview");
jPreviewPanel.setLayout(borderLayout4);
jEnablePreviewCheckBox.setSelected(true);
jEnablePreviewCheckBox.setText("enable preview");
jEnablePreviewCheckBox.setHorizontalAlignment(SwingConstants.RIGHT);
jSelectedTextField.addKeyListener(
new java.awt.event.KeyAdapter() {
public void keyTyped(KeyEvent e) {
jSelectedTextField_keyTyped(e);
}
}
);
jPanel5.setLayout(borderLayout5);
jPanel6.setLayout(borderLayout6);
jPanel6.setBorder(border2);
jLabel1.setText("selected: ");
this.getContentPane().add(jPanel1, BorderLayout.CENTER);
jPanel1.add(jPanel2, BorderLayout.CENTER);
jPanel2.add(jSplitPane1, BorderLayout.CENTER);
jSplitPane1.add(storesTreeSheet, JSplitPane.TOP);
jSplitPane1.add(jPreviewPanel, JSplitPane.BOTTOM);
jPreviewPanel.add(jPreviewLabel, BorderLayout.CENTER);
jPanel1.add(jPanel3, BorderLayout.SOUTH);
jPanel3.add(jPanel4, BorderLayout.EAST);
jPanel4.add(jCancelButton, null);
jPanel4.add(jSelectButton, null);
jPanel3.add(jPanel5, BorderLayout.NORTH);
jPanel5.add(jPanel6, BorderLayout.CENTER);
jPanel6.add(jSelectedTextField, BorderLayout.CENTER);
jPanel6.add(jLabel1, BorderLayout.WEST);
jPanel5.add(jEnablePreviewCheckBox, BorderLayout.EAST);
jSplitPane1.setDividerLocation(220);
}
/**
* Description of the Method
*
*@param checkURI Description of Parameter
*/
private void done(boolean checkURI) {
try {
if (createURIFromString && checkURI) {
URL newURI = new URL(jSelectedTextField.getText().trim());
this.selectedURI = newURI;
}
selectionDone = true;
this.dispose();
} catch (MalformedURLException mue) {
WindowUtils.warnOnError("The URI is not valid. Please correct it.", mue);
}
}
/**
* Description of the Method
*
*@param selectedObject Description of Parameter
*/
private void objectSelected(Object selectedObject) {
createURIFromString = false;
StoreEntity selectedEntity = (StoreEntity) selectedObject;
selectedURI = selectedEntity.getURL();
jSelectedTextField.setText(selectedURI.toString());
jSelectButton.setEnabled(true);
if (jEnablePreviewCheckBox.isSelected()) {
java.awt.Component viewer = activator.getDefaultViewer(selectedEntity);
jPreviewPanel.removeAll();
jPreviewPanel.add((java.awt.Component) viewer, BorderLayout.CENTER);
} else {
jPreviewPanel.removeAll();
jPreviewPanel.add(new JLabel("preview disabled"));
}
jPreviewPanel.revalidate();
}
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
class CurrentSelectionListener
implements javax.swing.event.TreeSelectionListener {
/**
* Description of the Method
*
*@param e Description of Parameter
*/
public void valueChanged(TreeSelectionEvent e) {
TreePath lastPath = e.getNewLeadSelectionPath();
if (lastPath == null) {
return;
}
Object selectedObject = (lastPath.getLastPathComponent());
if (selectedObject == null) {
return;
} else {
objectSelected(selectedObject);
}
}
}
}
--- NEW FILE: TabBorder.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.border.AbstractBorder;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created July 11, 2001
*@version 1.0
*/
public class TabBorder extends AbstractBorder {
/**
* Constructor for the TabBorder object
*/
public TabBorder() { }
/**
* Description of the Method
*
*@param c Description of Parameter
*@param g Description of Parameter
*@param x Description of Parameter
*@param y Description of Parameter
*@param width Description of Parameter
*@param height Description of Parameter
*/
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.drawRoundRect(x, y, width - 1, height - 1, 5, 5);
}
}
--- NEW FILE: TabButton.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import org.krysalis.swingx.concerns.AntiAliasing;
/**
* Copyright by Cleverlance 2001 Author: Claude Duguay, Jan Seda Contact:
* [email protected] Website: www.cleverlance.com
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
public class TabButton extends JButton {
/**
* Constructor for the TabButton object
*
*@param name Description of Parameter
*/
public TabButton(String name) {
super(name);
setOpaque(true);
setFocusPainted(false);
setMargin(new Insets(2, 2, 2, 2));
setMinimumSize(new Dimension(20, 20));
setPreferredSize(new Dimension(20, 20));
}
/**
* Constructor for the TabButton object
*
*@param name Description of Parameter
*@param icon Description of Parameter
*/
public TabButton(String name, ImageIcon icon) {
super(name);
super.setIcon(icon);
setOpaque(true);
setFocusPainted(false);
int iconHeight = icon.getIconHeight();
if (iconHeight < 20) {
this.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
this.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
}
setMargin(new Insets(2, 2, 2, 2));
setMinimumSize(new Dimension(20, 22));
setPreferredSize(new Dimension(20, 22));
}
/**
* Gets the focusTraversable attribute of the TabButton object
*
*@return The focusTraversable value
*/
public boolean isFocusTraversable() {
return false;
}
/**
* Gets the defaultButton attribute of the TabButton object
*
*@return The defaultButton value
*/
public boolean isDefaultButton() {
return false;
}
/**
* Description of the Method
*
*@param g1 Description of Parameter
*/
public void paint(Graphics g1) {
AntiAliasing.antialias(g1);
super.paint(g1);
}
}
--- NEW FILE: TableMap.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 16 settembre 2001
*/
public class TableMap extends AbstractTableModel
implements TableModelListener {
/**
* Description of the Field
*/
protected TableModel model;
/**
* Sets the model attribute of the TableMap object
*
*@param model The new model value
*/
public void setModel(TableModel model) {
this.model = model;
model.addTableModelListener(this);
}
/**
* Sets the valueAt attribute of the TableMap object
*
*@param aValue The new valueAt value
*@param aRow The new valueAt value
*@param aColumn The new valueAt value
*/
public void setValueAt(Object aValue, int aRow, int aColumn) {
model.setValueAt(aValue, aRow, aColumn);
}
/**
* Gets the model attribute of the TableMap object
*
*@return The model value
*/
public TableModel getModel() {
return model;
}
// By default, implement TableModel by forwarding all messages
// to the model.
/**
* Gets the valueAt attribute of the TableMap object
*
*@param aRow Description of Parameter
*@param aColumn Description of Parameter
*@return The valueAt value
*/
public Object getValueAt(int aRow, int aColumn) {
return model.getValueAt(aRow, aColumn);
}
/**
* Gets the rowCount attribute of the TableMap object
*
*@return The rowCount value
*/
public int getRowCount() {
return (model == null) ? 0 : model.getRowCount();
}
/**
* Gets the columnCount attribute of the TableMap object
*
*@return The columnCount value
*/
public int getColumnCount() {
return (model == null) ? 0 : model.getColumnCount();
}
/**
* Gets the columnName attribute of the TableMap object
*
*@param aColumn Description of Parameter
*@return The columnName value
*/
public String getColumnName(int aColumn) {
return model.getColumnName(aColumn);
}
/**
* Gets the columnClass attribute of the TableMap object
*
*@param aColumn Description of Parameter
*@return The columnClass value
*/
public Class getColumnClass(int aColumn) {
return model.getColumnClass(aColumn);
}
/**
* Gets the cellEditable attribute of the TableMap object
*
*@param row Description of Parameter
*@param column Description of Parameter
*@return The cellEditable value
*/
public boolean isCellEditable(int row, int column) {
return model.isCellEditable(row, column);
}
//
// Implementation of the TableModelListener interface,
//
// By default forward all events to all the listeners.
/**
* Description of the Method
*
*@param e Description of Parameter
*/
public void tableChanged(TableModelEvent e) {
fireTableChanged(e);
}
}
--- NEW FILE: TableSorter.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.util.*;
import javax.swing.table.TableModel;
import javax.swing.event.TableModelEvent;
// Imports for picking up mouse events from the JTable.
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.InputEvent;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 16 settembre 2001
*/
public class TableSorter extends TableMap {
int indexes[];
Vector sortingColumns = new Vector();
boolean ascending = true;
int compares;
/**
* Constructor for the TableSorter object
*/
public TableSorter() {
indexes = new int[0];
// for consistency
}
/**
* Constructor for the TableSorter object
*
*@param model Description of Parameter
*/
public TableSorter(TableModel model) {
setModel(model);
}
/**
* Sets the model attribute of the TableSorter object
*
*@param model The new model value
*/
public void setModel(TableModel model) {
super.setModel(model);
reallocateIndexes();
}
/**
* Sets the valueAt attribute of the TableSorter object
*
*@param aValue The new valueAt value
*@param aRow The new valueAt value
*@param aColumn The new valueAt value
*/
public void setValueAt(Object aValue, int aRow, int aColumn) {
checkModel();
model.setValueAt(aValue, indexes[aRow], aColumn);
}
// The mapping only affects the contents of the data rows.
// Pass all requests to these rows through the mapping array: "indexes".
/**
* Gets the valueAt attribute of the TableSorter object
*
*@param aRow Description of Parameter
*@param aColumn Description of Parameter
*@return The valueAt value
*/
public Object getValueAt(int aRow, int aColumn) {
checkModel();
return model.getValueAt(indexes[aRow], aColumn);
}
/**
* Description of the Method
*
*@param row1 Description of Parameter
*@param row2 Description of Parameter
*@param column Description of Parameter
*@return Description of the Returned Value
*/
public int compareRowsByColumn(int row1, int row2, int column) {
Class type = model.getColumnClass(column);
TableModel data = model;
// Check for nulls.
Object o1 = data.getValueAt(row1, column);
Object o2 = data.getValueAt(row2, column);
// If both values are null, return 0.
if (o1 == null && o2 == null) {
return 0;
} else if (o1 == null) {
// Define null less than everything.
return -1;
} else if (o2 == null) {
return 1;
}
/*
* We copy all returned values from the getValue call in case
* an optimised model is reusing one object to return many
* values. The Number subclasses in the JDK are immutable and
* so will not be used in this way but other subclasses of
* Number might want to do this to save space and avoid
* unnecessary heap allocation.
*/
if (type.getSuperclass() == java.lang.Number.class) {
Number n1 = (Number) data.getValueAt(row1, column);
double d1 = n1.doubleValue();
Number n2 = (Number) data.getValueAt(row2, column);
double d2 = n2.doubleValue();
if (d1 < d2) {
return -1;
} else if (d1 > d2) {
return 1;
} else {
return 0;
}
} else if (type == java.util.Date.class) {
Date d1 = (Date) data.getValueAt(row1, column);
long n1 = d1.getTime();
Date d2 = (Date) data.getValueAt(row2, column);
long n2 = d2.getTime();
if (n1 < n2) {
return -1;
} else if (n1 > n2) {
return 1;
} else {
return 0;
}
} else if (type == String.class) {
String s1 = (String) data.getValueAt(row1, column);
String s2 = (String) data.getValueAt(row2, column);
int result = s1.compareTo(s2);
if (result < 0) {
return -1;
} else if (result > 0) {
return 1;
} else {
return 0;
}
} else if (type == Boolean.class) {
Boolean bool1 = (Boolean) data.getValueAt(row1, column);
boolean b1 = bool1.booleanValue();
Boolean bool2 = (Boolean) data.getValueAt(row2, column);
boolean b2 = bool2.booleanValue();
if (b1 == b2) {
return 0;
} else if (b1) {
// Define false < true
return 1;
} else {
return -1;
}
} else {
Object v1 = data.getValueAt(row1, column);
String s1 = v1.toString();
Object v2 = data.getValueAt(row2, column);
String s2 = v2.toString();
int result = s1.compareTo(s2);
if (result < 0) {
return -1;
} else if (result > 0) {
return 1;
} else {
return 0;
}
}
}
/**
* Description of the Method
*
*@param row1 Description of Parameter
*@param row2 Description of Parameter
*@return Description of the Returned Value
*/
public int compare(int row1, int row2) {
compares++;
for (int level = 0; level < sortingColumns.size(); level++) {
Integer column = (Integer) sortingColumns.elementAt(level);
int result = compareRowsByColumn(row1, row2, column.intValue());
if (result != 0) {
return ascending ? result : -result;
}
}
return 0;
}
/**
* Description of the Method
*/
public void reallocateIndexes() {
int rowCount = model.getRowCount();
// Set up a new array of indexes with the right number of elements
// for the new data model.
indexes = new int[rowCount];
// Initialise with the identity mapping.
for (int row = 0; row < rowCount; row++) {
indexes[row] = row;
}
}
/**
* Description of the Method
*
*@param e Description of Parameter
*/
public void tableChanged(TableModelEvent e) {
//System.out.println("Sorter: tableChanged");
reallocateIndexes();
super.tableChanged(e);
}
/**
* Description of the Method
*/
public void checkModel() {
if (indexes.length != model.getRowCount()) {
System.err.println("Sorter not informed of a change in model.");
}
}
/**
* Description of the Method
*
*@param sender Description of Parameter
*/
public void sort(Object sender) {
checkModel();
compares = 0;
// n2sort();
// qsort(0, indexes.length-1);
shuttlesort((int[]) indexes.clone(), indexes, 0, indexes.length);
//System.out.println("Compares: "+compares);
}
/**
* Description of the Method
*/
public void n2sort() {
for (int i = 0; i < getRowCount(); i++) {
for (int j = i + 1; j < getRowCount(); j++) {
if (compare(indexes[i], indexes[j]) == -1) {
swap(i, j);
}
}
}
}
// This is a home-grown implementation which we have not had time
// to research - it may perform poorly in some circumstances. It
// requires twice the space of an in-place algorithm and makes
// NlogN assigments shuttling the values between the two
// arrays. The number of compares appears to vary between N-1 and
// NlogN depending on the initial order but the main reason for
// using it here is that, unlike qsort, it is stable.
/**
* Description of the Method
*
*@param from Description of Parameter
*@param to Description of Parameter
*@param low Description of Parameter
*@param high Description of Parameter
*/
public void shuttlesort(int from[], int to[], int low, int high) {
if (high - low < 2) {
return;
}
int middle = (low + high) / 2;
shuttlesort(to, from, low, middle);
shuttlesort(to, from, middle, high);
int p = low;
int q = middle;
/*
* This is an optional short-cut; at each recursive call,
* check to see if the elements in this subset are already
* ordered. If so, no further comparisons are needed; the
* sub-array can just be copied. The array must be copied rather
* than assigned otherwise sister calls in the recursion might
* get out of sinc. When the number of elements is three they
* are partitioned so that the first set, [low, mid), has one
* element and and the second, [mid, high), has two. We skip the
* optimisation when the number of elements is three or less as
* the first compare in the normal merge will produce the same
* sequence of steps. This optimisation seems to be worthwhile
* for partially ordered lists but some analysis is needed to
* find out how the performance drops to Nlog(N) as the initial
* order diminishes - it may drop very quickly.
*/
if (high - low >= 4 && compare(from[middle - 1], from[middle]) <= 0) {
for (int i = low; i < high; i++) {
to[i] = from[i];
}
return;
}
// A normal merge.
for (int i = low; i < high; i++) {
if (q >= high || (p < middle && compare(from[p], from[q]) <= 0)) {
to[i] = from[p++];
} else {
to[i] = from[q++];
}
}
}
/**
* Description of the Method
*
*@param i Description of Parameter
*@param j Description of Parameter
*/
public void swap(int i, int j) {
int tmp = indexes[i];
indexes[i] = indexes[j];
indexes[j] = tmp;
}
/**
* Description of the Method
*
*@param column Description of Parameter
*/
public void sortByColumn(int column) {
sortByColumn(column, true);
}
/**
* Description of the Method
*
*@param column Description of Parameter
*@param ascending Description of Parameter
*/
public void sortByColumn(int column, boolean ascending) {
this.ascending = ascending;
sortingColumns.removeAllElements();
sortingColumns.addElement(new Integer(column));
sort(this);
super.tableChanged(new TableModelEvent(this));
}
// There is no-where else to put this.
// Add a mouse listener to the Table to trigger a table sort
// when a column heading is clicked in the JTable.
/**
* Adds a feature to the MouseListenerToHeaderInTable attribute of the
* TableSorter object
*
*@param table The feature to be added to the MouseListenerToHeaderInTable
* attribute
*/
public void addMouseListenerToHeaderInTable(JTable table) {
final TableSorter sorter = this;
final JTable tableView = table;
tableView.setColumnSelectionAllowed(false);
MouseAdapter listMouseListener =
new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
TableColumnModel columnModel = tableView.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = tableView.convertColumnIndexToModel(viewColumn);
if (e.getClickCount() == 1 && column != -1) {
//System.out.println("Sorting ...");
int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
boolean ascending = (shiftPressed == 0);
sorter.sortByColumn(column, ascending);
}
}
};
JTableHeader th = tableView.getTableHeader();
th.addMouseListener(listMouseListener);
}
}
--- NEW FILE: WaitCursorEventQueue.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.AWTEvent;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.EventQueue;
import java.awt.MenuComponent;
import java.awt.MenuContainer;
import javax.swing.SwingUtilities;
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
public class WaitCursorEventQueue extends EventQueue {
private int delay;
private WaitCursorTimer waitTimer;
/**
* Constructor for the WaitCursorEventQueue object
*
*@param delay Description of Parameter
*/
public WaitCursorEventQueue(int delay) {
this.delay = delay;
waitTimer = new WaitCursorTimer();
waitTimer.setDaemon(true);
waitTimer.start();
}
/**
* Description of the Method
*
*@param event Description of Parameter
*/
protected void dispatchEvent(AWTEvent event) {
waitTimer.startTimer(event.getSource());
try {
super.dispatchEvent(event);
} finally {
waitTimer.stopTimer();
}
}
/**
* Description of the Class
*
*@author Luca Jun Barozzi
*@created 15 settembre 2001
*/
private class WaitCursorTimer extends Thread {
private Object source;
private Component parent;
/**
* Main processing method for the WaitCursorTimer object
*/
public synchronized void run() {
while (true) {
try {
//wait for notification from startTimer()
wait();
//wait for event processing to reach the threshold, or
//interruption from stopTimer()
wait(delay);
if (source instanceof Component) {
parent = SwingUtilities.getRoot((Component) source);
} else if (source instanceof MenuComponent) {
MenuContainer mParent =
((MenuComponent) source).getParent();
if (mParent instanceof Component) {
parent = SwingUtilities.getRoot(
(Component) mParent);
}
}
if (parent != null && parent.isShowing()) {
parent.setCursor(
Cursor.getPredefinedCursor(
Cursor.WAIT_CURSOR));
}
} catch (InterruptedException ie) {
}
}
}
/**
* Description of the Method
*
*@param source Description of Parameter
*/
synchronized void startTimer(Object source) {
this.source = source;
notify();
}
/**
* Description of the Method
*/
synchronized void stopTimer() {
if (parent == null) {
interrupt();
} else {
parent.setCursor(null);
parent = null;
}
}
}
}
--- NEW FILE: WindowUtils.java ---
/*****************************************************************************
* Copyright (C) The Krysalis project. All rights reserved. *
* ------------------------------------------------------------------------- *
* This software is published under the terms of the Krysalis Software *
* License version 1.1_01, a copy of which has been included with this *
* distribution in the LICENSE file. *
*****************************************************************************/
package org.krysalis.swingx;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Toolkit;
import java.awt.Window;
import javax.swing.JFrame;
import javax.swing.LookAndFeel;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;
import org.apache.avalon.framework.configuration.Configuration;
import org.krysalis.swingx.resources.ResourceFactory;
import org.krysalis.swingx.concerns.Logging;
import org.krysalis.swingx.laf.metal.SimpleMetalTheme;
import com.l2fprod.gui.plaf.skin.Skin;
import com.l2fprod.gui.plaf.skin.SkinLookAndFeel;
/**
*@author <a href="mailto:[email protected]">Nicola Ken Barozzi</a>
*@created June 20, 2001
*@version 1.0
*/
public class WindowUtils {
private final static org.apache.log4j.Category c = org.apache.log4j.Category.getInstance(org.krysalis.swingx.WindowUtils.class);
private static JFrame defaultFrame = new JFrame();
/**
* Sets the defaultFrame attribute of the WindowUtils class
*
*@param defaultFrame The new defaultFrame value
*/
public static void setDefaultFrame(JFrame defaultFrame) {
WindowUtils.defaultFrame = defaultFrame;
}
/**
* Description of the Method
*
*@param lookandfeelConf Description of Parameter
*@param rf Description of Parameter
*@exception Exception Description of Exception
*/
public static void configureLookandFeel(Configuration lookandfeelConf,
ResourceFactory rf) throws Exception {
final ResourceFactory resourceFactory = rf;
String lafString = lookandfeelConf.getAttribute("class").trim();
LookAndFeel lookAndFeel = (LookAndFeel) Class.forName(lafString).newInstance();
if (lookAndFeel instanceof javax.swing.plaf.metal.MetalLookAndFeel) {
MetalLookAndFeel metalLookAndFeel = (MetalLookAndFeel) lookAndFeel;
Configuration colorsConf = lookandfeelConf.getChild("colors");
SimpleMetalTheme simpleMetalTheme = new SimpleMetalTheme();
simpleMetalTheme.setPrimary1(colorsConf.getAttribute("primary1",
simpleMetalTheme.getPrimary1().toString()));
simpleMetalTheme.setPrimary2(colorsConf.getAttribute("primary2",
simpleMetalTheme.getPrimary2().toString()));
simpleMetalTheme.setPrimary3(colorsConf.getAttribute("primary3",
simpleMetalTheme.getPrimary3().toString()));
simpleMetalTheme.setSecondary1(colorsConf.getAttribute("secondary1",
simpleMetalTheme.getSecondary1().toString()));
simpleMetalTheme.setSecondary2(colorsConf.getAttribute("secondary2",
simpleMetalTheme.getSecondary2().toString()));
simpleMetalTheme.setSecondary3(colorsConf.getAttribute("secondary3",
simpleMetalTheme.getSecondary3().toString()));
metalLookAndFeel.setCurrentTheme(simpleMetalTheme);
UIManager.setLookAndFeel(metalLookAndFeel);
} else if (lookAndFeel instanceof com.l2fprod.gui.plaf.skin.SkinLookAndFeel) {
/*
* Configuration skinlfConf = lookandfeelConf.getChild("skinlf-themepack");
* final Configuration[] propertyConfs = skinlfConf.getChildren("property");
* for (int i = 0; i < propertyConfs.length; i++) {
* UIManager.put(propertyConfs[i].getAttribute("name"),
* propertyConfs[i].getAttribute("value").equals("true") ?
* Boolean.TRUE : null);
* }
* Configuration[] iconConfs = skinlfConf.getChildren("icon");
* for (int i = 0; i < iconConfs.length; i++) {
* final String currentValue = iconConfs[i].getAttribute("value");
* UIManager.put(iconConfs[i].getAttribute("name"),
* new UIDefaults.LazyValue() {
* public Object createValue (UIDefaults table) {
* return new ImageIcon(resourceFactory.getPlainResource(currentValue));
* }
* }
* );
* }
* UIManager.put("Tree.line", new UIDefaults.LazyValue() {
* public Object createValue (UIDefaults table) {
* return Color.lightGray;
* }
* }
* );
* UIManager.put("Tree.hash", new UIDefaults.LazyValue() {
* public Object createValue (UIDefaults table) {
* return Color.lightGray;
* }
* }
* );
* UIManager.put("Tree.rowHeight", new UIDefaults.LazyValue() {
* public Object createValue (UIDefaults table) {
* return new Integer(16);
* }
* }
* );
* Configuration skinsContConf = skinlfConf.getChild("skin");
* Configuration skinsConf[] = skinsContConf.getChildren("skin");
* SkinLookAndFeel laf = new SkinLookAndFeel();
* if (x._c)
* c.debug(resourceFactory);
* if (x._c)
* c.debug("---");
* if (resourceFactory == null && x._c)
* c.debug("IS NULL");
* Skin skin1 = laf.loadSkin(resourceFactory.getPlainResource(skinsConf[0].getAttribute("url")));
* Skin skin2 = laf.loadSkin(resourceFactory.getPlainResource(skinsConf[1].getAttribute("url")));
* Skin skin = new CompoundSkin(skin1, skin2);
* SkinLookAndFeel.setSkin(skin);
* UIManager.setLookAndFeel(laf);
*/
UIManager.put("Tree.line",
new UIDefaults.LazyValue() {
public Object createValue(UIDefaults table) {
return Color.lightGray;
}
}
);
UIManager.put("Tree.hash",
new UIDefaults.LazyValue() {
public Object createValue(UIDefaults table) {
return Color.lightGray;
}
}
);
UIManager.put("Tree.rowHeight",
new UIDefaults.LazyValue() {
public Object createValue(UIDefaults table) {
return new Integer(16);
}
}
);
String skinlfThemepackUrlString = lookandfeelConf.getChild("themepack").getAttribute("path");
java.net.URL skinlfThemepackUrl = resourceFactory.getPlainResource(skinlfThemepackUrlString);
Skin skin = SkinLookAndFeel.loadThemePack(skinlfThemepackUrl);
SkinLookAndFeel laf = new SkinLookAndFeel();
SkinLookAndFeel.setSkin(skin);
UIManager.setLookAndFeel(laf);
} else {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
}
/**
* Description of the Method
*/
public static void forceFrameRepaint() {
defaultFrame.getContentPane().repaint();
}
/**
* Description of the Method
*
*@param w Description of Parameter
*/
public static void centerOnScreen(Window w) {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension size = w.getSize();
w.setLocation((screenSize.width - size.width) / 2,
(screenSize.height - size.height) / 2);
}
/**
* Description of the Method
*
*@param w Description of Parameter
*@param x Description of Parameter
*@param y Description of Parameter
*/
public static void sizeTo(Window w, double x, double y) {
Dimension size = Toolkit.getDefaultToolkit().getScreenSize();
w.setSize((int) (size.width * x), (int) (size.height * y));
}
/**
* Description of the Method
*/
public static void tryToSetAutoCursor() {
try {
EventQueue waitQueue = new WaitCursorEventQueue(500);
Toolkit.getDefaultToolkit().getSystemEventQueue().push(waitQueue);
} catch (Exception ex) {
Logging.warn(c,"Automatic wait cursor not set.", ex);
}
}
/**
* Description of the Method
*
*@param message Description of Parameter
*@param t Description of Parameter
*/
public static void alertOnError(String message, Throwable t) {
JExceptionDialog.showExceptionDialog(defaultFrame, message, t, "alert");
}
/**
* Description of the Method
*
*@param message Description of Parameter
*@param t Description of Parameter
*/
public static void warnOnError(String message, Throwable t) {
JExceptionDialog.showExceptionDialog(defaultFrame, message, t, "Error");
}
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.