001: /*
002: JSmooth: a VM wrapper toolkit for Windows
003: Copyright (C) 2003 Rodrigo Reyes <reyes@charabia.net>
004:
005: This program is free software; you can redistribute it and/or modify
006: it under the terms of the GNU General Public License as published by
007: the Free Software Foundation; either version 2 of the License, or
008: (at your option) any later version.
009:
010: This program is distributed in the hope that it will be useful,
011: but WITHOUT ANY WARRANTY; without even the implied warranty of
012: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: GNU General Public License for more details.
014:
015: You should have received a copy of the GNU General Public License
016: along with this program; if not, write to the Free Software
017: Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
018:
019: */
020:
021: package net.charabia.jsmoothgen.application.gui.util;
022:
023: import java.awt.*;
024: import java.awt.event.*;
025: import javax.swing.*;
026: import javax.swing.border.*;
027: import java.io.*;
028: import com.l2fprod.common.swing.*;
029:
030: /**
031: * Represents a JTextField associated with a button that pops up a
032: * file dialog selector.
033: *
034: */
035:
036: public class OptionalHelpPanel extends JPanel {
037: private JPanel m_panel = new JPanel();
038: protected boolean m_limitHeight = true;
039:
040: private HTMLPane m_helpPanel = new HTMLPane() {
041: public Dimension getPreferredSize() {
042: Dimension d = super .getPreferredSize();
043: if (OptionalHelpPanel.this .m_limitHeight) {
044: if (d.height > 180)
045: d.height = 180;
046: }
047: return d;
048: }
049: };
050:
051: private JPanel m_titlePanel = new JPanel();
052: private JLabel m_title = new JLabel();
053: private JButton m_helptoggle = new JButton("?");
054:
055: private boolean m_helpActive = false;
056:
057: public OptionalHelpPanel() {
058: setLayout(new GridBagLayout());
059:
060: m_helptoggle.addActionListener(new ActionListener() {
061: public void actionPerformed(ActionEvent e) {
062: m_helpActive = !m_helpActive;
063: toggleHelpCheck();
064: }
065: });
066:
067: setLayout(new PanelLayout());
068:
069: m_titlePanel.setLayout(new BorderLayout());
070: m_titlePanel.add(BorderLayout.CENTER, m_title);
071: m_titlePanel.add(BorderLayout.EAST, m_helptoggle);
072: m_titlePanel.setOpaque(true);
073: m_helptoggle.setOpaque(false);
074: m_helptoggle.setBorder(null);
075: m_title.setBorder(BorderFactory.createEmptyBorder(2, 10, 2, 2));
076: add(m_titlePanel);
077:
078: add(m_panel);
079: add(m_helpPanel);
080:
081: setBorder(BorderFactory.createCompoundBorder(BorderFactory
082: .createCompoundBorder(BorderFactory.createEmptyBorder(
083: 2, 2, 2, 2), BorderFactory
084: .createBevelBorder(BevelBorder.RAISED)),
085: BorderFactory.createEmptyBorder(2, 2, 2, 2)));
086:
087: java.net.URL helpimgurl = getClass().getResource(
088: "/icons/stock_help-agent.png");
089: if (helpimgurl != null) {
090: javax.swing.ImageIcon leaf = new javax.swing.ImageIcon(
091: helpimgurl);
092: m_helptoggle.setIcon(leaf);
093: m_helptoggle.setText("");
094: } else {
095: m_helptoggle.setText("(?)");
096: }
097: setLabelColor(Color.white, Color.darkGray);
098:
099: toggleHelpCheck();
100: }
101:
102: private void toggleHelpCheck() {
103: m_helpPanel.setVisible(m_helpActive);
104: validate();
105: repaint();
106: }
107:
108: public Dimension getPreferredSize() {
109: Dimension d = super .getPreferredSize();
110: d.width = 1;
111: return d;
112: }
113:
114: public JPanel getContentPane() {
115: return m_panel;
116: }
117:
118: public void setLabel(String label) {
119: label = "<html><b>" + label + "</b></hmtl>";
120: m_title.setText(label);
121: }
122:
123: public void setHelpText(String help) {
124: m_helpPanel.setText(help);
125: }
126:
127: public void setLabelColor(Color fore, Color back) {
128: m_titlePanel.setBackground(back);
129: m_title.setForeground(fore);
130: repaint();
131: }
132:
133: public void setLimitHeight(boolean b) {
134: m_limitHeight = b;
135: validate();
136: repaint();
137: }
138:
139: public static void main(String[] args) {
140: JFrame f = new JFrame("test");
141:
142: OptionalHelpPanel ohp = new OptionalHelpPanel();
143: ohp.setHelpText("This is my help text");
144: ohp.setLabel("My label1");
145: ohp.getContentPane().setLayout(new BorderLayout());
146: // ohp.getContentPane().add(BorderLayout.CENTER, new JScrollPane(new JTextArea(40,40)));
147: ohp.getContentPane().add(BorderLayout.CENTER,
148: new FileSelectionTextField());
149:
150: OptionalHelpPanel ohp2 = new OptionalHelpPanel();
151: ohp.setLabel("hop2");
152: ohp2
153: .setHelpText("<html><h1>This is my second help text</h1>le géant du logiciel va-t-il écouter et arrêter le déluge promotionel qui vise à faire connaitre les nouveautés de Office 2003 alors que les utilisateurs sont satisfaits des versions précédentes et que les responsables zieutent lourdement du coté de Linux et d'OpenOffice ?");
154: ohp2.getContentPane().setLayout(new BorderLayout());
155: ohp2.getContentPane()
156: .add(BorderLayout.CENTER, new JTextField());
157:
158: f.getContentPane().setLayout(new PanelLayout());
159: f.getContentPane().add(ohp);
160: f.getContentPane().add(ohp2);
161: f.setSize(300, 300);
162: f.setVisible(true);
163: }
164: }
|