001: //WebOnSwing - Web Application Framework
002: //Copyright (C) 2003 Fernando Damian Petrola
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017:
018: package net.ar.webonswing.swing.components;
019:
020: import java.awt.*;
021: import java.awt.event.*;
022:
023: import javax.swing.*;
024:
025: import net.ar.webonswing.*;
026: import net.ar.webonswing.helpers.*;
027:
028: /**
029: * Componente que representa un hipervinculo
030: *
031: * @author Fernando Damian Petrola
032: */
033: public class JLink extends JComponent {
034: private boolean mouseOver;
035: private String url;
036: private RootPaneContainer rootPaneContainer;
037: private String label;
038: private Class rootPaneContainerClass;
039: private static final String uiClassID = "LinkUI";
040:
041: public JLink() {
042: }
043:
044: public JLink(String aLabel, RootPaneContainer aRootPaneContainer) {
045: label = aLabel;
046: rootPaneContainer = aRootPaneContainer;
047: init();
048: }
049:
050: public JLink(String aLabel, Class aRootPaneContainerClass) {
051: label = aLabel;
052: rootPaneContainerClass = aRootPaneContainerClass;
053: rootPaneContainer = null;
054: init();
055: }
056:
057: public JLink(String aLabel, String anUrl) {
058: label = aLabel;
059: url = anUrl;
060: init();
061: }
062:
063: protected void init() {
064: setPreferredSize(new Dimension(100, 100));
065:
066: if (!WosFramework.isActive()) {
067: addMouseListener(new MouseAdapter() {
068: public void mouseClicked(MouseEvent e) {
069: RootPaneContainer windowToShow = null;
070:
071: if (rootPaneContainerClass != null)
072: windowToShow = (RootPaneContainer) WosHelper
073: .createClassInstance(rootPaneContainerClass
074: .getName());
075: else if (rootPaneContainer != null)
076: windowToShow = rootPaneContainer;
077:
078: if (windowToShow != null) {
079: WosFramework.showAndExecute(
080: getTopLevelAncestor(), windowToShow,
081: null);
082: WosFramework.hide(getTopLevelAncestor());
083: }
084: }
085:
086: public void mouseEntered(MouseEvent e) {
087: mouseOver = true;
088: repaint();
089: }
090:
091: public void mouseExited(MouseEvent e) {
092: mouseOver = false;
093: repaint();
094: }
095: });
096: }
097: }
098:
099: protected void paintComponent(Graphics g) {
100: super .paintComponent(g);
101:
102: Font font = mouseOver ? new Font(getFont().getFontName(),
103: Font.BOLD, getFont().getSize()) : getFont();
104: g.setFont(font);
105: int textWidth = SwingUtilities.computeStringWidth(Toolkit
106: .getDefaultToolkit().getFontMetrics(font), label);
107: g.drawString(label, getWidth() / 2 - textWidth / 2,
108: getHeight() / 2);
109: }
110:
111: public String getUIClassID() {
112: return uiClassID;
113: }
114:
115: public static String getUiClassID() {
116: return uiClassID;
117: }
118:
119: public String getLabel() {
120: return label;
121: }
122:
123: public void setLabel(String aLabel) {
124: label = aLabel;
125: }
126:
127: public RootPaneContainer getRootPaneContainer() {
128: return rootPaneContainer;
129: }
130:
131: public void setRootPaneContainer(
132: RootPaneContainer aRootPaneContainer) {
133: rootPaneContainer = aRootPaneContainer;
134: }
135:
136: public Class getRootPaneContainerClass() {
137: return rootPaneContainerClass;
138: }
139:
140: public void setRootPaneContainerClass(Class aRootPaneContainerClass) {
141: rootPaneContainerClass = aRootPaneContainerClass;
142: }
143:
144: public String getUrl() {
145: return url;
146: }
147:
148: public void setUrl(String aUrl) {
149: url = aUrl;
150: }
151: }
|