001: /*
002: * This program is free software; you can redistribute it and/or
003: * modify it under the terms of the GNU General Public License
004: * as published by the Free Software Foundation; either version 2
005: * of the License, or (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011:
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015: */
016: package net.sf.jftp.gui.base;
017:
018: import net.sf.jftp.*;
019: import net.sf.jftp.config.Settings;
020: import net.sf.jftp.gui.framework.*;
021:
022: import java.awt.*;
023:
024: import javax.swing.*;
025:
026: public class StatusCanvas extends JPanel {
027: JLabel host = new JLabel("");
028: JLabel separator = new JLabel(" ");
029: JLabel text = new JLabel(Settings.greeting);
030: String drawText = "";
031: int pos = 0;
032: Image image;
033: Graphics offg;
034: boolean slide = false;
035: int interval = 3;
036: boolean fwd = false;
037:
038: public StatusCanvas() {
039: setMinimumSize(new Dimension(200, 25));
040: setPreferredSize(new Dimension(320, 25));
041: setLayout(null);
042:
043: //setLayout(new FlowLayout(FlowLayout.LEFT));
044: //add(host);
045: //add(separator);
046: //add(text);
047: setVisible(true);
048: }
049:
050: public void setInterval(int x) {
051: interval = x;
052: }
053:
054: public void forward() {
055: fwd = true;
056: }
057:
058: public void setText(String msg) {
059: if (false) {
060: text.setText(msg);
061: } else {
062: text.setText("");
063: drawText = msg;
064: slide = false;
065:
066: if (AppMenuBar.fadeMenu.getState()) {
067: SwingUtilities.invokeLater(new Runnable() {
068: public void run() {
069: for (pos = 30; pos > 0; pos -= 1) {
070: paintImmediately(0, 0, getSize().width,
071: getSize().height);
072: net.sf.jftp.system.LocalIO.pause(interval);
073: }
074: }
075: });
076: } else {
077: repaint();
078: }
079: }
080:
081: validate();
082: }
083:
084: public void scrollText(String msg) {
085: if (false) {
086: text.setText(msg);
087: } else {
088: text.setText("");
089: drawText = msg;
090: slide = true;
091:
092: if (AppMenuBar.fadeMenu.getState()) {
093: for (pos = 700; pos > (msg.length() * -6); pos -= 1) {
094: if (fwd) {
095: break;
096: }
097:
098: //paintImmediately(0, 0, getSize().width, getSize().height);
099: repaint();
100: net.sf.jftp.system.LocalIO.pause(interval);
101:
102: //JFtp.statusP.jftp.validate();
103: }
104: } else {
105: repaint();
106: }
107:
108: fwd = false;
109: }
110:
111: validate();
112: }
113:
114: public void setHost(String h) {
115: host.setText(h);
116: validate();
117: }
118:
119: public String getHost() {
120: return host.getText();
121: }
122:
123: public void paintComponent(Graphics g) {
124: if (image == null) {
125: image = createImage(getWidth(), getHeight());
126: }
127:
128: if (offg == null) {
129: offg = image.getGraphics();
130: }
131:
132: offg.setColor(GUIDefaults.light);
133: offg.setFont(GUIDefaults.status);
134: offg.fillRect(0, 0, getSize().width, getSize().height);
135: offg.setColor(new Color(125, 125, 175));
136:
137: if (!slide) {
138: offg.drawString(drawText, 10, 15 + pos);
139: } else {
140: offg.drawString(drawText, 10 + pos, 15);
141: }
142:
143: offg.setColor(GUIDefaults.front);
144: offg.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
145: offg.drawRect(0, 0, getSize().width - 2, getSize().height - 2);
146: g.drawImage(image, 0, 0, this );
147: }
148:
149: public void update(Graphics g) {
150: paintComponent(g);
151: }
152: }
|