2 * Jexer - Java Text User Interface
4 * The MIT License (MIT)
6 * Copyright (C) 2017 Kevin Lamonte
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
26 * @author Kevin Lamonte [kevin.lamonte@gmail.com]
31 import java
.awt
.Color
;
32 import java
.awt
.Cursor
;
34 import java
.awt
.FontMetrics
;
35 import java
.awt
.Graphics
;
36 import java
.awt
.Graphics2D
;
37 import java
.awt
.Insets
;
38 import java
.awt
.Point
;
39 import java
.awt
.Rectangle
;
40 import java
.awt
.Toolkit
;
41 import java
.awt
.geom
.Rectangle2D
;
42 import java
.awt
.image
.BufferedImage
;
43 import java
.awt
.image
.BufferStrategy
;
44 import java
.io
.InputStream
;
45 import java
.util
.Date
;
46 import java
.util
.HashMap
;
47 import javax
.swing
.JFrame
;
48 import javax
.swing
.SwingUtilities
;
50 import jexer
.bits
.Cell
;
51 import jexer
.bits
.CellAttributes
;
52 import jexer
.session
.SwingSessionInfo
;
55 * This Screen implementation draws to a Java Swing JFrame.
57 public final class SwingScreen
extends Screen
{
60 * If true, use triple buffering thread.
62 private static boolean tripleBuffer
= true;
65 * Cursor style to draw.
67 public enum CursorStyle
{
69 * Use an underscore for the cursor.
74 * Use a solid block for the cursor.
79 * Use an outlined block for the cursor.
84 private static Color MYBLACK
;
85 private static Color MYRED
;
86 private static Color MYGREEN
;
87 private static Color MYYELLOW
;
88 private static Color MYBLUE
;
89 private static Color MYMAGENTA
;
90 private static Color MYCYAN
;
91 private static Color MYWHITE
;
93 private static Color MYBOLD_BLACK
;
94 private static Color MYBOLD_RED
;
95 private static Color MYBOLD_GREEN
;
96 private static Color MYBOLD_YELLOW
;
97 private static Color MYBOLD_BLUE
;
98 private static Color MYBOLD_MAGENTA
;
99 private static Color MYBOLD_CYAN
;
100 private static Color MYBOLD_WHITE
;
102 private static boolean dosColors
= false;
105 * Setup Swing colors to match DOS color palette.
107 private static void setDOSColors() {
111 MYBLACK
= new Color(0x00, 0x00, 0x00);
112 MYRED
= new Color(0xa8, 0x00, 0x00);
113 MYGREEN
= new Color(0x00, 0xa8, 0x00);
114 MYYELLOW
= new Color(0xa8, 0x54, 0x00);
115 MYBLUE
= new Color(0x00, 0x00, 0xa8);
116 MYMAGENTA
= new Color(0xa8, 0x00, 0xa8);
117 MYCYAN
= new Color(0x00, 0xa8, 0xa8);
118 MYWHITE
= new Color(0xa8, 0xa8, 0xa8);
119 MYBOLD_BLACK
= new Color(0x54, 0x54, 0x54);
120 MYBOLD_RED
= new Color(0xfc, 0x54, 0x54);
121 MYBOLD_GREEN
= new Color(0x54, 0xfc, 0x54);
122 MYBOLD_YELLOW
= new Color(0xfc, 0xfc, 0x54);
123 MYBOLD_BLUE
= new Color(0x54, 0x54, 0xfc);
124 MYBOLD_MAGENTA
= new Color(0xfc, 0x54, 0xfc);
125 MYBOLD_CYAN
= new Color(0x54, 0xfc, 0xfc);
126 MYBOLD_WHITE
= new Color(0xfc, 0xfc, 0xfc);
132 * SwingFrame is our top-level hook into the Swing system.
134 class SwingFrame
extends JFrame
{
137 * Serializable version.
139 private static final long serialVersionUID
= 1;
142 * The terminus font resource filename.
144 private static final String FONTFILE
= "terminus-ttf-4.39/TerminusTTF-Bold-4.39.ttf";
147 * The BufferStrategy object needed for triple-buffering.
149 private BufferStrategy bufferStrategy
;
152 * A cache of previously-rendered glyphs for blinking text, when it
155 private HashMap
<Cell
, BufferedImage
> glyphCacheBlink
;
158 * A cache of previously-rendered glyphs for non-blinking, or
159 * blinking-and-visible, text.
161 private HashMap
<Cell
, BufferedImage
> glyphCache
;
164 * The TUI Screen data.
169 * If true, we were successful getting Terminus.
171 private boolean gotTerminus
= false;
174 * Width of a character cell.
176 private int textWidth
= 1;
179 * Height of a character cell.
181 private int textHeight
= 1;
184 * Descent of a character cell.
186 private int maxDescent
= 0;
189 * System-dependent Y adjustment for text in the character cell.
191 private int textAdjustY
= 0;
194 * System-dependent X adjustment for text in the character cell.
196 private int textAdjustX
= 0;
199 * Top pixel absolute location.
201 private int top
= 30;
204 * Left pixel absolute location.
206 private int left
= 30;
209 * The cursor style to draw.
211 private CursorStyle cursorStyle
= CursorStyle
.UNDERLINE
;
214 * The number of millis to wait before switching the blink from
215 * visible to invisible.
217 private long blinkMillis
= 500;
220 * If true, the cursor should be visible right now based on the blink
223 private boolean cursorBlinkVisible
= true;
226 * The time that the blink last flipped from visible to invisible or
227 * from invisible to visible.
229 private long lastBlinkTime
= 0;
232 * Convert a CellAttributes foreground color to an Swing Color.
234 * @param attr the text attributes
235 * @return the Swing Color
237 private Color
attrToForegroundColor(final CellAttributes attr
) {
239 if (attr
.getForeColor().equals(jexer
.bits
.Color
.BLACK
)) {
241 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.RED
)) {
243 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.BLUE
)) {
245 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.GREEN
)) {
247 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.YELLOW
)) {
248 return MYBOLD_YELLOW
;
249 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.CYAN
)) {
251 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.MAGENTA
)) {
252 return MYBOLD_MAGENTA
;
253 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.WHITE
)) {
257 if (attr
.getForeColor().equals(jexer
.bits
.Color
.BLACK
)) {
259 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.RED
)) {
261 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.BLUE
)) {
263 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.GREEN
)) {
265 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.YELLOW
)) {
267 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.CYAN
)) {
269 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.MAGENTA
)) {
271 } else if (attr
.getForeColor().equals(jexer
.bits
.Color
.WHITE
)) {
275 throw new IllegalArgumentException("Invalid color: " +
276 attr
.getForeColor().getValue());
280 * Convert a CellAttributes background color to an Swing Color.
282 * @param attr the text attributes
283 * @return the Swing Color
285 private Color
attrToBackgroundColor(final CellAttributes attr
) {
286 if (attr
.getBackColor().equals(jexer
.bits
.Color
.BLACK
)) {
288 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.RED
)) {
290 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.BLUE
)) {
292 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.GREEN
)) {
294 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.YELLOW
)) {
296 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.CYAN
)) {
298 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.MAGENTA
)) {
300 } else if (attr
.getBackColor().equals(jexer
.bits
.Color
.WHITE
)) {
303 throw new IllegalArgumentException("Invalid color: " +
304 attr
.getBackColor().getValue());
308 * Public constructor.
310 * @param screen the Screen that Backend talks to
312 public SwingFrame(final SwingScreen screen
) {
313 this.screen
= screen
;
316 // Figure out my cursor style
317 String cursorStyleString
= System
.getProperty(
318 "jexer.Swing.cursorStyle", "underline").toLowerCase();
320 if (cursorStyleString
.equals("underline")) {
321 cursorStyle
= CursorStyle
.UNDERLINE
;
322 } else if (cursorStyleString
.equals("outline")) {
323 cursorStyle
= CursorStyle
.OUTLINE
;
324 } else if (cursorStyleString
.equals("block")) {
325 cursorStyle
= CursorStyle
.BLOCK
;
328 if (System
.getProperty("jexer.Swing.tripleBuffer").
331 SwingScreen
.tripleBuffer
= false;
334 setTitle("Jexer Application");
335 setBackground(Color
.black
);
338 // Always try to use Terminus, the one decent font.
339 ClassLoader loader
= Thread
.currentThread().
340 getContextClassLoader();
341 InputStream in
= loader
.getResourceAsStream(FONTFILE
);
342 Font terminusRoot
= Font
.createFont(Font
.TRUETYPE_FONT
, in
);
343 Font terminus
= terminusRoot
.deriveFont(Font
.PLAIN
, 20);
346 } catch (Exception e
) {
348 // setFont(new Font("Liberation Mono", Font.PLAIN, 24));
349 setFont(new Font(Font
.MONOSPACED
, Font
.PLAIN
, 24));
353 // Kill the X11 cursor
354 // Transparent 16 x 16 pixel cursor image.
355 BufferedImage cursorImg
= new BufferedImage(16, 16,
356 BufferedImage
.TYPE_INT_ARGB
);
357 // Create a new blank cursor.
358 Cursor blankCursor
= Toolkit
.getDefaultToolkit().createCustomCursor(
359 cursorImg
, new Point(0, 0), "blank cursor");
360 setCursor(blankCursor
);
362 // Be capable of seeing Tab / Shift-Tab
363 setFocusTraversalKeysEnabled(false);
365 // Save the text cell width/height
368 // Cache glyphs as they are rendered
369 glyphCacheBlink
= new HashMap
<Cell
, BufferedImage
>();
370 glyphCache
= new HashMap
<Cell
, BufferedImage
>();
372 // Setup triple-buffering
373 if (SwingScreen
.tripleBuffer
) {
374 setIgnoreRepaint(true);
375 createBufferStrategy(3);
376 bufferStrategy
= getBufferStrategy();
381 * Figure out my font dimensions.
383 private void getFontDimensions() {
384 Graphics gr
= getGraphics();
385 FontMetrics fm
= gr
.getFontMetrics();
386 maxDescent
= fm
.getMaxDescent();
387 Rectangle2D bounds
= fm
.getMaxCharBounds(gr
);
388 int leading
= fm
.getLeading();
389 textWidth
= (int)Math
.round(bounds
.getWidth());
390 // textHeight = (int)Math.round(bounds.getHeight()) - maxDescent;
392 // This produces the same number, but works better for ugly
394 textHeight
= fm
.getMaxAscent() + maxDescent
- leading
;
396 if (gotTerminus
== true) {
400 if (System
.getProperty("os.name").startsWith("Windows")) {
404 if (System
.getProperty("os.name").startsWith("Mac")) {
411 * Resize to font dimensions.
413 public void resizeToScreen() {
414 // Figure out the thickness of borders and use that to set the
416 Insets insets
= getInsets();
420 setSize(textWidth
* screen
.width
+ insets
.left
+ insets
.right
,
421 textHeight
* screen
.height
+ insets
.top
+ insets
.bottom
);
425 * Update redraws the whole screen.
427 * @param gr the Swing Graphics context
430 public void update(final Graphics gr
) {
431 // The default update clears the area. Don't do that, instead
432 // just paint it directly.
437 * Draw one glyph to the screen.
439 * @param gr the Swing Graphics context
440 * @param cell the Cell to draw
441 * @param xPixel the x-coordinate to render to. 0 means the
442 * left-most pixel column.
443 * @param yPixel the y-coordinate to render to. 0 means the top-most
446 private void drawGlyph(final Graphics gr
, final Cell cell
,
447 final int xPixel
, final int yPixel
) {
449 BufferedImage image
= null;
450 if (cell
.isBlink() && !cursorBlinkVisible
) {
451 image
= glyphCacheBlink
.get(cell
);
453 image
= glyphCache
.get(cell
);
456 gr
.drawImage(image
, xPixel
, yPixel
, this);
460 // Generate glyph and draw it.
461 Graphics2D gr2
= null;
465 image
= new BufferedImage(textWidth
, textHeight
,
466 BufferedImage
.TYPE_INT_ARGB
);
467 gr2
= image
.createGraphics();
468 gr2
.setFont(getFont());
472 gr2
= (Graphics2D
) gr
;
475 Cell cellColor
= new Cell();
476 cellColor
.setTo(cell
);
479 if (cell
.isReverse()) {
480 cellColor
.setForeColor(cell
.getBackColor());
481 cellColor
.setBackColor(cell
.getForeColor());
484 // Draw the background rectangle, then the foreground character.
485 gr2
.setColor(attrToBackgroundColor(cellColor
));
486 gr2
.fillRect(gr2x
, gr2y
, textWidth
, textHeight
);
488 // Handle blink and underline
490 || (cell
.isBlink() && cursorBlinkVisible
)
492 gr2
.setColor(attrToForegroundColor(cellColor
));
493 char [] chars
= new char[1];
494 chars
[0] = cell
.getChar();
495 gr2
.drawChars(chars
, 0, 1, gr2x
+ textAdjustX
,
496 gr2y
+ textHeight
- maxDescent
+ textAdjustY
);
498 if (cell
.isUnderline()) {
499 gr2
.fillRect(gr2x
, gr2y
+ textHeight
- 2, textWidth
, 2);
506 // We need a new key that will not be mutated by
508 Cell key
= new Cell();
510 if (cell
.isBlink() && !cursorBlinkVisible
) {
511 glyphCacheBlink
.put(key
, image
);
513 glyphCache
.put(key
, image
);
516 gr
.drawImage(image
, xPixel
, yPixel
, this);
522 * Check if the cursor is visible, and if so draw it.
524 * @param gr the Swing Graphics context
526 private void drawCursor(final Graphics gr
) {
529 && (cursorY
<= screen
.height
- 1)
530 && (cursorX
<= screen
.width
- 1)
531 && cursorBlinkVisible
533 int xPixel
= cursorX
* textWidth
+ left
;
534 int yPixel
= cursorY
* textHeight
+ top
;
535 Cell lCell
= screen
.logical
[cursorX
][cursorY
];
536 gr
.setColor(attrToForegroundColor(lCell
));
537 switch (cursorStyle
) {
541 gr
.fillRect(xPixel
, yPixel
+ textHeight
- 2, textWidth
, 2);
544 gr
.fillRect(xPixel
, yPixel
, textWidth
, textHeight
);
547 gr
.drawRect(xPixel
, yPixel
, textWidth
- 1, textHeight
- 1);
554 * Paint redraws the whole screen.
556 * @param gr the Swing Graphics context
559 public void paint(final Graphics gr
) {
560 // Do nothing until the screen reference has been set.
561 if (screen
== null) {
564 if (screen
.frame
== null) {
568 // See if it is time to flip the blink time.
569 long nowTime
= (new Date()).getTime();
570 if (nowTime
> blinkMillis
+ lastBlinkTime
) {
571 lastBlinkTime
= nowTime
;
572 cursorBlinkVisible
= !cursorBlinkVisible
;
576 int xCellMax
= screen
.width
;
578 int yCellMax
= screen
.height
;
580 Rectangle bounds
= gr
.getClipBounds();
581 if (bounds
!= null) {
582 // Only update what is in the bounds
583 xCellMin
= screen
.textColumn(bounds
.x
);
584 xCellMax
= screen
.textColumn(bounds
.x
+ bounds
.width
);
585 if (xCellMax
> screen
.width
) {
586 xCellMax
= screen
.width
;
588 if (xCellMin
>= xCellMax
) {
589 xCellMin
= xCellMax
- 2;
594 yCellMin
= screen
.textRow(bounds
.y
);
595 yCellMax
= screen
.textRow(bounds
.y
+ bounds
.height
);
596 if (yCellMax
> screen
.height
) {
597 yCellMax
= screen
.height
;
599 if (yCellMin
>= yCellMax
) {
600 yCellMin
= yCellMax
- 2;
606 // We need a total repaint
607 reallyCleared
= true;
610 // Prevent updates to the screen's data from the TApplication
612 synchronized (screen
) {
614 System.err.printf("bounds %s X %d %d Y %d %d\n",
615 bounds, xCellMin, xCellMax, yCellMin, yCellMax);
618 for (int y
= yCellMin
; y
< yCellMax
; y
++) {
619 for (int x
= xCellMin
; x
< xCellMax
; x
++) {
621 int xPixel
= x
* textWidth
+ left
;
622 int yPixel
= y
* textHeight
+ top
;
624 Cell lCell
= screen
.logical
[x
][y
];
625 Cell pCell
= screen
.physical
[x
][y
];
627 if (!lCell
.equals(pCell
)
631 drawGlyph(gr
, lCell
, xPixel
, yPixel
);
633 // Physical is always updated
634 physical
[x
][y
].setTo(lCell
);
641 reallyCleared
= false;
642 } // synchronized (screen)
645 } // class SwingFrame
648 * The raw Swing JFrame. Note package private access.
653 * Restore terminal to normal state.
655 public void shutdown() {
660 * Public constructor.
662 public SwingScreen() {
664 SwingUtilities
.invokeAndWait(new Runnable() {
666 SwingScreen
.this.frame
= new SwingFrame(SwingScreen
.this);
667 SwingScreen
.this.sessionInfo
=
668 new SwingSessionInfo(SwingScreen
.this.frame
,
672 SwingScreen
.this.setDimensions(sessionInfo
.getWindowWidth(),
673 sessionInfo
.getWindowHeight());
675 SwingScreen
.this.frame
.resizeToScreen();
676 SwingScreen
.this.frame
.setVisible(true);
679 } catch (Exception e
) {
687 private SwingSessionInfo sessionInfo
;
690 * Create the SwingSessionInfo. Note package private access.
692 * @return the sessionInfo
694 SwingSessionInfo
getSessionInfo() {
699 * Push the logical screen to the physical device.
702 public void flushPhysical() {
705 System.err.printf("flushPhysical(): reallyCleared %s dirty %s\n",
706 reallyCleared, dirty);
709 // If reallyCleared is set, we have to draw everything.
710 if ((frame
.bufferStrategy
!= null) && (reallyCleared
== true)) {
711 // Triple-buffering: we have to redraw everything on this thread.
712 Graphics gr
= frame
.bufferStrategy
.getDrawGraphics();
715 frame
.bufferStrategy
.show();
716 // sync() doesn't seem to help the tearing for me.
717 // Toolkit.getDefaultToolkit().sync();
719 } else if ((frame
.bufferStrategy
== null) && (reallyCleared
== true)) {
720 // Repaint everything on the Swing thread.
725 // Do nothing if nothing happened.
730 if (frame
.bufferStrategy
!= null) {
731 // See if it is time to flip the blink time.
732 long nowTime
= (new Date()).getTime();
733 if (nowTime
> frame
.blinkMillis
+ frame
.lastBlinkTime
) {
734 frame
.lastBlinkTime
= nowTime
;
735 frame
.cursorBlinkVisible
= !frame
.cursorBlinkVisible
;
738 Graphics gr
= frame
.bufferStrategy
.getDrawGraphics();
740 synchronized (this) {
741 for (int y
= 0; y
< height
; y
++) {
742 for (int x
= 0; x
< width
; x
++) {
743 Cell lCell
= logical
[x
][y
];
744 Cell pCell
= physical
[x
][y
];
746 int xPixel
= x
* frame
.textWidth
+ frame
.left
;
747 int yPixel
= y
* frame
.textHeight
+ frame
.top
;
749 if (!lCell
.equals(pCell
)
755 frame
.drawGlyph(gr
, lCell
, xPixel
, yPixel
);
756 physical
[x
][y
].setTo(lCell
);
760 frame
.drawCursor(gr
);
761 } // synchronized (this)
764 frame
.bufferStrategy
.show();
765 // sync() doesn't seem to help the tearing for me.
766 // Toolkit.getDefaultToolkit().sync();
770 // Swing thread version: request a repaint, but limit it to the area
773 // Find the minimum-size damaged region.
774 int xMin
= frame
.getWidth();
776 int yMin
= frame
.getHeight();
779 synchronized (this) {
780 for (int y
= 0; y
< height
; y
++) {
781 for (int x
= 0; x
< width
; x
++) {
782 Cell lCell
= logical
[x
][y
];
783 Cell pCell
= physical
[x
][y
];
785 int xPixel
= x
* frame
.textWidth
+ frame
.left
;
786 int yPixel
= y
* frame
.textHeight
+ frame
.top
;
788 if (!lCell
.equals(pCell
)
797 if (xPixel
+ frame
.textWidth
> xMax
) {
798 xMax
= xPixel
+ frame
.textWidth
;
803 if (yPixel
+ frame
.textHeight
> yMax
) {
804 yMax
= yPixel
+ frame
.textHeight
;
810 if (xMin
+ frame
.textWidth
>= xMax
) {
811 xMax
+= frame
.textWidth
;
813 if (yMin
+ frame
.textHeight
>= yMax
) {
814 yMax
+= frame
.textHeight
;
817 // Repaint the desired area
819 System.err.printf("REPAINT X %d %d Y %d %d\n", xMin, xMax,
822 if (frame
.bufferStrategy
!= null) {
823 // This path should never be taken, but is left here for
825 Graphics gr
= frame
.bufferStrategy
.getDrawGraphics();
826 Rectangle bounds
= new Rectangle(xMin
, yMin
, xMax
- xMin
,
831 frame
.bufferStrategy
.show();
832 // sync() doesn't seem to help the tearing for me.
833 // Toolkit.getDefaultToolkit().sync();
835 // Repaint on the Swing thread.
836 frame
.repaint(xMin
, yMin
, xMax
- xMin
, yMax
- yMin
);
841 * Put the cursor at (x,y).
843 * @param visible if true, the cursor should be visible
844 * @param x column coordinate to put the cursor on
845 * @param y row coordinate to put the cursor on
848 public void putCursor(final boolean visible
, final int x
, final int y
) {
850 if ((visible
== cursorVisible
) && ((x
== cursorX
) && (y
== cursorY
))) {
851 // See if it is time to flip the blink time.
852 long nowTime
= (new Date()).getTime();
853 if (nowTime
< frame
.blinkMillis
+ frame
.lastBlinkTime
) {
854 // Nothing has changed, so don't do anything.
860 && (cursorY
<= height
- 1)
861 && (cursorX
<= width
- 1)
863 // Make the current cursor position dirty
864 if (physical
[cursorX
][cursorY
].getChar() == 'Q') {
865 physical
[cursorX
][cursorY
].setChar('X');
867 physical
[cursorX
][cursorY
].setChar('Q');
871 super.putCursor(visible
, x
, y
);
875 * Convert pixel column position to text cell column position.
877 * @param x pixel column position
878 * @return text cell column position
880 public int textColumn(final int x
) {
881 return ((x
- frame
.left
) / frame
.textWidth
);
885 * Convert pixel row position to text cell row position.
887 * @param y pixel row position
888 * @return text cell row position
890 public int textRow(final int y
) {
891 return ((y
- frame
.top
) / frame
.textHeight
);
895 * Set the window title.
897 * @param title the new title
899 public void setTitle(final String title
) {
900 frame
.setTitle(title
);