PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/gui/StatusBar.java

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