PageRenderTime 29ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/StatusBar.java

#
Java | 833 lines | 586 code | 126 blank | 121 comment | 95 complexity | ac18e0bbc18e83cd85079a1b5a35d461 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /*
  2. * StatusBar.java - The status bar displayed at the bottom of views
  3. * :tabSize=8:indentSize=8:noTabs=false:
  4. * :folding=explicit:collapseFolds=1:
  5. *
  6. * Copyright (C) 2001, 2004 Slava Pestov
  7. * Portions copyright (C) 2001 mike dillon
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. package org.gjt.sp.jedit.gui;
  24. //{{{ Imports
  25. import javax.swing.border.*;
  26. import javax.swing.text.Segment;
  27. import javax.swing.*;
  28. import java.awt.event.*;
  29. import java.awt.font.*;
  30. import java.awt.geom.*;
  31. import java.awt.*;
  32. import java.text.*;
  33. import java.util.Date;
  34. import org.gjt.sp.jedit.io.*;
  35. import org.gjt.sp.jedit.textarea.*;
  36. import org.gjt.sp.jedit.*;
  37. import org.gjt.sp.util.*;
  38. //}}}
  39. /**
  40. * The status bar used to display various information to the user.<p>
  41. *
  42. * Currently, it is used for the following:
  43. * <ul>
  44. * <li>Displaying caret position information
  45. * <li>Displaying {@link InputHandler#readNextChar(String,String)} prompts
  46. * <li>Displaying {@link #setMessage(String)} messages
  47. * <li>Displaying I/O progress
  48. * <li>Displaying various editor settings
  49. * <li>Displaying memory status
  50. * </ul>
  51. *
  52. * @version $Id: StatusBar.java 5485 2006-06-23 22:04:58Z kpouer $
  53. * @author Slava Pestov
  54. * @since jEdit 3.2pre2
  55. */
  56. public class StatusBar extends JPanel implements WorkThreadProgressListener
  57. {
  58. //{{{ StatusBar constructor
  59. public StatusBar(View view)
  60. {
  61. super(new BorderLayout());
  62. setBorder(new CompoundBorder(new EmptyBorder(4,0,0,
  63. (OperatingSystem.isMacOS() ? 18 : 0)),
  64. UIManager.getBorder("TextField.border")));
  65. this.view = view;
  66. panel = new JPanel(new BorderLayout());
  67. box = new Box(BoxLayout.X_AXIS);
  68. panel.add(BorderLayout.EAST,box);
  69. add(BorderLayout.CENTER,panel);
  70. MouseHandler mouseHandler = new MouseHandler();
  71. caretStatus = new ToolTipLabel();
  72. caretStatus.setToolTipText(jEdit.getProperty("view.status.caret-tooltip"));
  73. caretStatus.addMouseListener(mouseHandler);
  74. message = new JLabel(" ");
  75. setMessageComponent(message);
  76. mode = new ToolTipLabel();
  77. mode.setToolTipText(jEdit.getProperty("view.status.mode-tooltip"));
  78. mode.addMouseListener(mouseHandler);
  79. wrap = new ToolTipLabel();
  80. wrap.setHorizontalAlignment(SwingConstants.CENTER);
  81. wrap.setToolTipText(jEdit.getProperty("view.status.wrap-tooltip"));
  82. wrap.addMouseListener(mouseHandler);
  83. multiSelect = new ToolTipLabel();
  84. multiSelect.setHorizontalAlignment(SwingConstants.CENTER);
  85. multiSelect.setToolTipText(jEdit.getProperty("view.status.multi-tooltip"));
  86. multiSelect.addMouseListener(mouseHandler);
  87. rectSelect = new ToolTipLabel();
  88. rectSelect.setHorizontalAlignment(SwingConstants.CENTER);
  89. rectSelect.setToolTipText(jEdit.getProperty("view.status.rect-tooltip"));
  90. rectSelect.addMouseListener(mouseHandler);
  91. overwrite = new ToolTipLabel();
  92. overwrite.setHorizontalAlignment(SwingConstants.CENTER);
  93. overwrite.setToolTipText(jEdit.getProperty("view.status.overwrite-tooltip"));
  94. overwrite.addMouseListener(mouseHandler);
  95. lineSep = new ToolTipLabel();
  96. lineSep.setHorizontalAlignment(SwingConstants.CENTER);
  97. lineSep.setToolTipText(jEdit.getProperty("view.status.linesep-tooltip"));
  98. lineSep.addMouseListener(mouseHandler);
  99. } //}}}
  100. //{{{ propertiesChanged() method
  101. public void propertiesChanged()
  102. {
  103. Color fg = jEdit.getColorProperty("view.status.foreground");
  104. Color bg = jEdit.getColorProperty("view.status.background");
  105. showCaretStatus = jEdit.getBooleanProperty("view.status.show-caret-status");
  106. showEditMode = jEdit.getBooleanProperty("view.status.show-edit-mode");
  107. showFoldMode = jEdit.getBooleanProperty("view.status.show-fold-mode");
  108. showEncoding = jEdit.getBooleanProperty("view.status.show-encoding");
  109. showWrap = jEdit.getBooleanProperty("view.status.show-wrap");
  110. showMultiSelect = jEdit.getBooleanProperty("view.status.show-multi-select");
  111. showRectSelect = jEdit.getBooleanProperty("view.status.show-rect-select");
  112. showOverwrite = jEdit.getBooleanProperty("view.status.show-overwrite");
  113. showLineSeperator = jEdit.getBooleanProperty("view.status.show-line-seperator");
  114. boolean showMemory = jEdit.getBooleanProperty("view.status.show-memory");
  115. boolean showClock = jEdit.getBooleanProperty("view.status.show-clock");
  116. panel.setBackground(bg);
  117. panel.setForeground(fg);
  118. caretStatus.setBackground(bg);
  119. caretStatus.setForeground(fg);
  120. message.setBackground(bg);
  121. message.setForeground(fg);
  122. mode.setBackground(bg);
  123. mode.setForeground(fg);
  124. wrap.setBackground(bg);
  125. wrap.setForeground(fg);
  126. multiSelect.setBackground(bg);
  127. multiSelect.setForeground(fg);
  128. rectSelect.setBackground(bg);
  129. rectSelect.setForeground(fg);
  130. overwrite.setBackground(bg);
  131. overwrite.setForeground(fg);
  132. lineSep.setBackground(bg);
  133. lineSep.setForeground(fg);
  134. // retarded GTK look and feel!
  135. Font font = new JLabel().getFont();
  136. //UIManager.getFont("Label.font");
  137. FontMetrics fm = getFontMetrics(font);
  138. Dimension dim = null;
  139. if (showCaretStatus)
  140. {
  141. panel.add(BorderLayout.WEST,caretStatus);
  142. caretStatus.setFont(font);
  143. dim = new Dimension(fm.stringWidth(caretTestStr),
  144. fm.getHeight());
  145. caretStatus.setPreferredSize(dim);
  146. }
  147. else
  148. panel.remove(caretStatus);
  149. box.removeAll();
  150. if (showEncoding || showEditMode || showFoldMode)
  151. box.add(mode);
  152. if (showWrap)
  153. {
  154. dim = new Dimension(Math.max(
  155. Math.max(fm.charWidth('-'),fm.charWidth('H')),
  156. fm.charWidth('S')) + 1,fm.getHeight());
  157. wrap.setPreferredSize(dim);
  158. wrap.setMaximumSize(dim);
  159. box.add(wrap);
  160. }
  161. if (showMultiSelect)
  162. {
  163. dim = new Dimension(
  164. Math.max(fm.charWidth('-'),fm.charWidth('M')) + 1,
  165. fm.getHeight());
  166. multiSelect.setPreferredSize(dim);
  167. multiSelect.setMaximumSize(dim);
  168. box.add(multiSelect);
  169. }
  170. if (showRectSelect)
  171. {
  172. dim = new Dimension(
  173. Math.max(fm.charWidth('-'),fm.charWidth('R')) + 1,
  174. fm.getHeight());
  175. rectSelect.setPreferredSize(dim);
  176. rectSelect.setMaximumSize(dim);
  177. box.add(rectSelect);
  178. }
  179. if (showOverwrite)
  180. {
  181. dim = new Dimension(
  182. Math.max(fm.charWidth('-'),fm.charWidth('O')) + 1,
  183. fm.getHeight());
  184. overwrite.setPreferredSize(dim);
  185. overwrite.setMaximumSize(dim);
  186. box.add(overwrite);
  187. }
  188. if (showLineSeperator)
  189. {
  190. dim = new Dimension(Math.max(
  191. Math.max(fm.charWidth('U'),
  192. fm.charWidth('W')),
  193. fm.charWidth('M')) + 1,
  194. fm.getHeight());
  195. lineSep.setPreferredSize(dim);
  196. lineSep.setMaximumSize(dim);
  197. box.add(lineSep);
  198. }
  199. if (showMemory)
  200. box.add(new MemoryStatus());
  201. if (showClock)
  202. box.add(new Clock());
  203. updateBufferStatus();
  204. updateMiscStatus();
  205. } //}}}
  206. //{{{ addNotify() method
  207. public void addNotify()
  208. {
  209. super.addNotify();
  210. VFSManager.getIOThreadPool().addProgressListener(this);
  211. } //}}}
  212. //{{{ removeNotify() method
  213. public void removeNotify()
  214. {
  215. super.removeNotify();
  216. VFSManager.getIOThreadPool().removeProgressListener(this);
  217. } //}}}
  218. //{{{ WorkThreadListener implementation
  219. //{{{ statusUpdate() method
  220. public void statusUpdate(final WorkThreadPool threadPool, int threadIndex)
  221. {
  222. SwingUtilities.invokeLater(new Runnable()
  223. {
  224. public void run()
  225. {
  226. // don't obscure existing message
  227. if(message != null && !"".equals(message.getText().trim())
  228. && !currentMessageIsIO)
  229. return;
  230. int requestCount = threadPool.getRequestCount();
  231. if(requestCount == 0)
  232. {
  233. setMessageAndClear(jEdit.getProperty(
  234. "view.status.io.done"));
  235. currentMessageIsIO = true;
  236. }
  237. else if(requestCount == 1)
  238. {
  239. setMessage(jEdit.getProperty(
  240. "view.status.io-1"));
  241. currentMessageIsIO = true;
  242. }
  243. else
  244. {
  245. Object[] args = { new Integer(requestCount) };
  246. setMessage(jEdit.getProperty(
  247. "view.status.io",args));
  248. currentMessageIsIO = true;
  249. }
  250. }
  251. });
  252. } //}}}
  253. //{{{ progressUpdate() method
  254. public void progressUpdate(WorkThreadPool threadPool, int threadIndex)
  255. {
  256. } //}}}
  257. //}}}
  258. //{{{ setMessageAndClear() method
  259. /**
  260. * Show a message for a short period of time.
  261. * @param message The message
  262. * @since jEdit 3.2pre5
  263. */
  264. public void setMessageAndClear(String message)
  265. {
  266. setMessage(message);
  267. tempTimer = new Timer(0,new ActionListener()
  268. {
  269. public void actionPerformed(ActionEvent evt)
  270. {
  271. // so if view is closed in the meantime...
  272. if(isShowing())
  273. setMessage(null);
  274. }
  275. });
  276. tempTimer.setInitialDelay(10000);
  277. tempTimer.setRepeats(false);
  278. tempTimer.start();
  279. } //}}}
  280. //{{{ setMessage() method
  281. /**
  282. * Displays a status message.
  283. */
  284. public void setMessage(String message)
  285. {
  286. if(tempTimer != null)
  287. {
  288. tempTimer.stop();
  289. tempTimer = null;
  290. }
  291. setMessageComponent(this.message);
  292. if(message == null)
  293. {
  294. if(view.getMacroRecorder() != null)
  295. this.message.setText(jEdit.getProperty("view.status.recording"));
  296. else
  297. this.message.setText(" ");
  298. }
  299. else
  300. this.message.setText(message);
  301. } //}}}
  302. //{{{ setMessageComponent() method
  303. public void setMessageComponent(Component comp)
  304. {
  305. currentMessageIsIO = false;
  306. if (comp == null || messageComp == comp)
  307. {
  308. return;
  309. }
  310. messageComp = comp;
  311. panel.add(BorderLayout.CENTER, messageComp);
  312. } //}}}
  313. //{{{ updateCaretStatus() method
  314. public void updateCaretStatus()
  315. {
  316. //if(!isShowing())
  317. // return;
  318. if (showCaretStatus)
  319. {
  320. Buffer buffer = view.getBuffer();
  321. if(!buffer.isLoaded() ||
  322. /* can happen when switching buffers sometimes */
  323. buffer != view.getTextArea().getBuffer())
  324. {
  325. caretStatus.setText(" ");
  326. return;
  327. }
  328. JEditTextArea textArea = view.getTextArea();
  329. int currLine = textArea.getCaretLine();
  330. // there must be a better way of fixing this...
  331. // the problem is that this method can sometimes
  332. // be called as a result of a text area scroll
  333. // event, in which case the caret position has
  334. // not been updated yet.
  335. if(currLine >= buffer.getLineCount())
  336. return; // hopefully another caret update will come?
  337. int start = textArea.getLineStartOffset(currLine);
  338. int dot = textArea.getCaretPosition() - start;
  339. // see above
  340. if(dot < 0)
  341. return;
  342. buffer.getText(start,dot,seg);
  343. int virtualPosition = StandardUtilities.getVirtualWidth(seg,
  344. buffer.getTabSize());
  345. buf.setLength(0);
  346. buf.append(Integer.toString(currLine + 1));
  347. buf.append(',');
  348. buf.append(Integer.toString(dot + 1));
  349. if (virtualPosition != dot)
  350. {
  351. buf.append('-');
  352. buf.append(Integer.toString(virtualPosition + 1));
  353. }
  354. buf.append(' ');
  355. int firstLine = textArea.getFirstLine();
  356. int visible = textArea.getVisibleLines();
  357. int lineCount = textArea.getDisplayManager().getScrollLineCount();
  358. if (visible >= lineCount)
  359. {
  360. buf.append("All");
  361. }
  362. else if (firstLine == 0)
  363. {
  364. buf.append("Top");
  365. }
  366. else if (firstLine + visible >= lineCount)
  367. {
  368. buf.append("Bot");
  369. }
  370. else
  371. {
  372. float percent = (float)firstLine / (float)lineCount
  373. * 100.0f;
  374. buf.append(Integer.toString((int)percent));
  375. buf.append('%');
  376. }
  377. caretStatus.setText(buf.toString());
  378. }
  379. } //}}}
  380. //{{{ updateBufferStatus() method
  381. public void updateBufferStatus()
  382. {
  383. //if(!isShowing())
  384. // return;
  385. Buffer buffer = view.getBuffer();
  386. if (showWrap)
  387. {
  388. String wrap = buffer.getStringProperty("wrap");
  389. if(wrap.equals("none"))
  390. this.wrap.setText("-");
  391. else if(wrap.equals("hard"))
  392. this.wrap.setText("H");
  393. else if(wrap.equals("soft"))
  394. this.wrap.setText("S");
  395. }
  396. if (showLineSeperator)
  397. {
  398. String lineSep = buffer.getStringProperty("lineSeparator");
  399. if("\n".equals(lineSep))
  400. this.lineSep.setText("U");
  401. else if("\r\n".equals(lineSep))
  402. this.lineSep.setText("W");
  403. else if("\r".equals(lineSep))
  404. this.lineSep.setText("M");
  405. }
  406. if (showEditMode || showFoldMode || showEncoding)
  407. {
  408. /* This doesn't look pretty and mode line should
  409. * probably be split up into seperate
  410. * components/strings
  411. */
  412. buf.setLength(0);
  413. if (buffer.isLoaded())
  414. {
  415. if (showEditMode)
  416. buf.append(buffer.getMode().getName());
  417. if (showFoldMode)
  418. {
  419. if (showEditMode)
  420. buf.append(",");
  421. buf.append((String)view.getBuffer().getProperty("folding"));
  422. }
  423. if (showEncoding)
  424. {
  425. if (showEditMode || showFoldMode)
  426. buf.append(",");
  427. buf.append(buffer.getStringProperty("encoding"));
  428. }
  429. }
  430. mode.setText("(" + buf.toString() + ")");
  431. }
  432. } //}}}
  433. //{{{ updateMiscStatus() method
  434. public void updateMiscStatus()
  435. {
  436. //if(!isShowing())
  437. // return;
  438. JEditTextArea textArea = view.getTextArea();
  439. if (showMultiSelect)
  440. multiSelect.setText(textArea.isMultipleSelectionEnabled()
  441. ? "M" : "-");
  442. if (showRectSelect)
  443. rectSelect.setText(textArea.isRectangularSelectionEnabled()
  444. ? "R" : "-");
  445. if (showOverwrite)
  446. overwrite.setText(textArea.isOverwriteEnabled()
  447. ? "O" : "-");
  448. } //}}}
  449. //{{{ Private members
  450. private View view;
  451. private JPanel panel;
  452. private Box box;
  453. private ToolTipLabel caretStatus;
  454. private Component messageComp;
  455. private JLabel message;
  456. private JLabel mode;
  457. private JLabel wrap;
  458. private JLabel multiSelect;
  459. private JLabel rectSelect;
  460. private JLabel overwrite;
  461. private JLabel lineSep;
  462. /* package-private for speed */ StringBuffer buf = new StringBuffer();
  463. private Timer tempTimer;
  464. private boolean currentMessageIsIO;
  465. private Segment seg = new Segment();
  466. private boolean showCaretStatus;
  467. private boolean showEditMode;
  468. private boolean showFoldMode;
  469. private boolean showEncoding;
  470. private boolean showWrap;
  471. private boolean showMultiSelect;
  472. private boolean showRectSelect;
  473. private boolean showOverwrite;
  474. private boolean showLineSeperator;
  475. //}}}
  476. static final String caretTestStr = "9999,999-999 99%";
  477. //{{{ MouseHandler class
  478. class MouseHandler extends MouseAdapter
  479. {
  480. public void mouseClicked(MouseEvent evt)
  481. {
  482. Buffer buffer = view.getBuffer();
  483. Object source = evt.getSource();
  484. if(source == caretStatus)
  485. {
  486. if(evt.getClickCount() == 2)
  487. view.getTextArea().showGoToLineDialog();
  488. }
  489. else if(source == mode)
  490. {
  491. if(evt.getClickCount() == 2)
  492. new BufferOptions(view,view.getBuffer());
  493. }
  494. else if(source == wrap)
  495. buffer.toggleWordWrap(view);
  496. else if(source == multiSelect)
  497. view.getTextArea().toggleMultipleSelectionEnabled();
  498. else if(source == rectSelect)
  499. view.getTextArea().toggleRectangularSelectionEnabled();
  500. else if(source == overwrite)
  501. view.getTextArea().toggleOverwriteEnabled();
  502. else if(source == lineSep)
  503. buffer.toggleLineSeparator(view);
  504. }
  505. } //}}}
  506. //{{{ ToolTipLabel class
  507. class ToolTipLabel extends JLabel
  508. {
  509. //{{{ getToolTipLocation() method
  510. public Point getToolTipLocation(MouseEvent event)
  511. {
  512. return new Point(event.getX(),-20);
  513. } //}}}
  514. } //}}}
  515. //{{{ MemoryStatus class
  516. class MemoryStatus extends JComponent implements ActionListener
  517. {
  518. //{{{ MemoryStatus constructor
  519. public MemoryStatus()
  520. {
  521. // fucking GTK look and feel
  522. Font font = new JLabel().getFont();
  523. //Font font = UIManager.getFont("Label.font");
  524. MemoryStatus.this.setFont(font);
  525. FontRenderContext frc = new FontRenderContext(
  526. null,false,false);
  527. Rectangle2D bounds = font.getStringBounds(
  528. memoryTestStr,frc);
  529. Dimension dim = new Dimension((int)bounds.getWidth(),
  530. (int)bounds.getHeight());
  531. setPreferredSize(dim);
  532. setMaximumSize(dim);
  533. lm = font.getLineMetrics(memoryTestStr,frc);
  534. setForeground(jEdit.getColorProperty("view.status.foreground"));
  535. setBackground(jEdit.getColorProperty("view.status.background"));
  536. progressForeground = jEdit.getColorProperty(
  537. "view.status.memory.foreground");
  538. progressBackground = jEdit.getColorProperty(
  539. "view.status.memory.background");
  540. addMouseListener(new MouseHandler());
  541. } //}}}
  542. //{{{ addNotify() method
  543. public void addNotify()
  544. {
  545. super.addNotify();
  546. timer = new Timer(2000,this);
  547. timer.start();
  548. ToolTipManager.sharedInstance().registerComponent(this);
  549. } //}}}
  550. //{{{ removeNotify() method
  551. public void removeNotify()
  552. {
  553. timer.stop();
  554. ToolTipManager.sharedInstance().unregisterComponent(this);
  555. super.removeNotify();
  556. } //}}}
  557. //{{{ getToolTipText() method
  558. public String getToolTipText()
  559. {
  560. Runtime runtime = Runtime.getRuntime();
  561. int freeMemory = (int)(runtime.freeMemory() / 1024);
  562. int totalMemory = (int)(runtime.maxMemory() / 1024);
  563. int usedMemory = (totalMemory - freeMemory);
  564. Integer[] args = { new Integer(usedMemory),
  565. new Integer(totalMemory) };
  566. return jEdit.getProperty("view.status.memory-tooltip",args);
  567. } //}}}
  568. //{{{ getToolTipLocation() method
  569. public Point getToolTipLocation(MouseEvent event)
  570. {
  571. return new Point(event.getX(),-20);
  572. } //}}}
  573. //{{{ actionPerformed() method
  574. public void actionPerformed(ActionEvent evt)
  575. {
  576. MemoryStatus.this.repaint();
  577. } //}}}
  578. //{{{ paintComponent() method
  579. public void paintComponent(Graphics g)
  580. {
  581. Insets insets = new Insets(0,0,0,0);//MemoryStatus.this.getBorder().getBorderInsets(this);
  582. Runtime runtime = Runtime.getRuntime();
  583. int freeMemory = (int)(runtime.freeMemory() / 1024);
  584. int totalMemory = (int)(runtime.totalMemory() / 1024);
  585. int usedMemory = (totalMemory - freeMemory);
  586. int width = MemoryStatus.this.getWidth()
  587. - insets.left - insets.right;
  588. int height = MemoryStatus.this.getHeight()
  589. - insets.top - insets.bottom - 1;
  590. float fraction = ((float)usedMemory) / totalMemory;
  591. g.setColor(progressBackground);
  592. g.fillRect(insets.left,insets.top,
  593. (int)(width * fraction),
  594. height);
  595. String str = (usedMemory / 1024) + "/"
  596. + (totalMemory / 1024) + "Mb";
  597. FontRenderContext frc = new FontRenderContext(null,false,false);
  598. Rectangle2D bounds = g.getFont().getStringBounds(str,frc);
  599. Graphics g2 = g.create();
  600. g2.setClip(insets.left,insets.top,
  601. (int)(width * fraction),
  602. height);
  603. g2.setColor(progressForeground);
  604. g2.drawString(str,
  605. insets.left + (int)(width - bounds.getWidth()) / 2,
  606. (int)(insets.top + lm.getAscent()));
  607. g2.dispose();
  608. g2 = g.create();
  609. g2.setClip(insets.left + (int)(width * fraction),
  610. insets.top,MemoryStatus.this.getWidth()
  611. - insets.left - (int)(width * fraction),
  612. height);
  613. g2.setColor(MemoryStatus.this.getForeground());
  614. g2.drawString(str,
  615. insets.left + (int)(width - bounds.getWidth()) / 2,
  616. (int)(insets.top + lm.getAscent()));
  617. g2.dispose();
  618. } //}}}
  619. //{{{ Private members
  620. private static final String memoryTestStr = "999/999Mb";
  621. private LineMetrics lm;
  622. private Color progressForeground;
  623. private Color progressBackground;
  624. private Timer timer;
  625. //}}}
  626. //{{{ MouseHandler class
  627. class MouseHandler extends MouseAdapter
  628. {
  629. public void mousePressed(MouseEvent evt)
  630. {
  631. if(evt.getClickCount() == 2)
  632. {
  633. jEdit.showMemoryDialog(view);
  634. repaint();
  635. }
  636. }
  637. } //}}}
  638. } //}}}
  639. //{{{ Clock class
  640. class Clock extends JLabel implements ActionListener
  641. {
  642. //{{{ Clock constructor
  643. public Clock()
  644. {
  645. /* FontRenderContext frc = new FontRenderContext(
  646. null,false,false);
  647. Rectangle2D bounds = getFont()
  648. .getStringBounds(getTime(),frc);
  649. Dimension dim = new Dimension((int)bounds.getWidth(),
  650. (int)bounds.getHeight());
  651. setPreferredSize(dim);
  652. setMaximumSize(dim); */
  653. setForeground(jEdit.getColorProperty("view.status.foreground"));
  654. setBackground(jEdit.getColorProperty("view.status.background"));
  655. } //}}}
  656. //{{{ addNotify() method
  657. public void addNotify()
  658. {
  659. super.addNotify();
  660. update();
  661. int millisecondsPerMinute = 1000 * 60;
  662. timer = new Timer(millisecondsPerMinute,this);
  663. timer.setInitialDelay((int)(
  664. millisecondsPerMinute
  665. - System.currentTimeMillis()
  666. % millisecondsPerMinute) + 500);
  667. timer.start();
  668. ToolTipManager.sharedInstance().registerComponent(this);
  669. } //}}}
  670. //{{{ removeNotify() method
  671. public void removeNotify()
  672. {
  673. timer.stop();
  674. ToolTipManager.sharedInstance().unregisterComponent(this);
  675. super.removeNotify();
  676. } //}}}
  677. //{{{ getToolTipText() method
  678. public String getToolTipText()
  679. {
  680. return new Date().toString();
  681. } //}}}
  682. //{{{ getToolTipLocation() method
  683. public Point getToolTipLocation(MouseEvent event)
  684. {
  685. return new Point(event.getX(),-20);
  686. } //}}}
  687. //{{{ actionPerformed() method
  688. public void actionPerformed(ActionEvent evt)
  689. {
  690. update();
  691. } //}}}
  692. //{{{ Private members
  693. private Timer timer;
  694. //{{{ getTime() method
  695. private String getTime()
  696. {
  697. return DateFormat.getTimeInstance(
  698. DateFormat.SHORT).format(new Date());
  699. } //}}}
  700. //{{{ update() method
  701. private void update()
  702. {
  703. setText(getTime());
  704. } //}}}
  705. //}}}
  706. } //}}}
  707. }