[View INPRISE Home Page][View Product List][Search This Web Site][View Available Downloads][Join Inprise Membership][Enter Discussion Area][Send Email To Webmaster]
INPRISE Online And ZD Journals Present:



Selecting columns in source files

If you've ever tried to read someone else's Java source files, you've probably noticed that no two programmers format their source code the same way. However, most of us do try to indent nested blocks of code in a consistent manner.

To assist you in formatting your source files, a number of programming text editors--Borland's old Brief editor, for example--provide a feature called column marking. Column marking allows you to select vertical regions of text that are narrower than the editor's maximum line length. In this article, we'll show how you can use the column-marking capability of the editor that's built into the JBuilder Integrated Development Environment (IDE).

Brief review
Since Brief has been a popular product among programmers for some time, Borland decided to add Brief emulation to the JBuilder IDE. The Brief programmer's editor provides a specific method for marking columns. After you press [Alt] C, you can use the arrow keys to move the cursor, and Brief will mark the column of text beginning at the starting insertion point and ending at the new cursor location.

However, you don't have to enable Brief emulation to take advantage of column marking--it's available any time you're using the JBuilder code editor window. If you change the keystroke mapping in JBuilder using the Environment Options dialog box, you can configure JBuilder's editing window to recognize this and other Brief commands.

Mapping at the wheel
From the Environment Options dialog box's Editor Display page, you can choose from one of four keystroke-mapping options: Default, Classic, Brief, and Epsilon. When you choose a new keystroke-mapping option, the IDE will respond to a different set of shortcut keys, including the shortcuts that apply to selecting text in an editing window.

For example, if you use the Default or Classic keystroke mappings, you can press [Shift][Ctrl] and the left or right arrow key to select the previous or next word, respectively. (The Brief and Epsilon key mappings, on the other hand, don't support this style of keyboard selection.) Table A lists some of the other keystrokes you can use to select a range of text in an editing window.

Table A:
Default and Classic selection keystrokes

Keystroke Shortcut selects...
[Shift][left arrow] ...the character to the left
[Shift][right arrow] ...the character to the right
[Shift][up arrow] ...everything to the left margin on the current line and above to the right on the previous line
[Shift][down arrow] ...everything to the right margin on the current line and below to the left on the next line
[Shift][PageUp] ...everything to the left margin on the current line, one page above to the right, and all lines in between
[Shift][PageDown] ...everything to the right margin on the current line, one page down to the right, and all lines in between
[Shift][End] ...everything to the end of the line
[Shift][Home] ...everything to the beginning of the line
[Shift][Ctrl][left arrow] ...the word to the left
[Shift][Ctrl][right arrow]...the word to the right
[Shift][Ctrl][PageUp] ...everything to the left margin on the current line and back to the beginning of the file
[Shift][Ctrl][Home] (same as [Shift][Ctrl][PageUp])
[Shift][Ctrl][PageDown] ...everything to the right margin on the current line and down to the end of the file
[Shift][Ctrl][End] (same as [Shift][Ctrl][PageDown])

All of the keystrokes in Table A perform line-by-line selection. However, if you press [Alt] while using any of these keystrokes, you'll select a vertical column of text instead. The beginning point and ending point of the selection will be the same as before, but the editor will highlight only a region of text that appears between the horizontal location of the beginning and ending selection points. (If you select columns and move the cursor straight down, the selection will automatically be one character wide.)

If you've viewed the online Help for JBuilder, you may have seen some of the keyboard shortcut information we've presented so far. However, you can accomplish the same results using the mouse. Just as you can use the left mouse button to move the insertion point and select text line-by-line, you can press [Alt] as you select text using the mouse, and you'll instantly select column regions in an editing window. In addition, you can use this technique to select columns of text even if you're using the Brief or Epsilon keystroke mappings--something you can't do from the keyboard when those mappings are active.

A pillar of [Alt]
To try this technique, launch JBuilder. When the main window and AppBrowser window appear, click the mouse in the source code pane of the AppBrowser window.

Place the cursor at the beginning of line 12 (in the middle of the class declaration). If you're using the Default or Classic keystroke mappings (you're using Default unless you've changed it), press and hold [Shift][Alt] and then press the down arrow twice.

Now you'll notice that you've selected a one-character-wide column of space that indents lines 12, 13, and 14, as shown in Figure A. If you want to remove this space to shorten both lines, press [Delete].

Figure A

Figure A: You can use the keyboard to select columns of text when you're using the Default or Classic keystroke mappings.

Next, press [Alt], click at the beginning of line 12, and drag down to line 14. As before, you'll notice that you've selected a one-character-wide column of space that indents these two lines.

Conclusion
JBuilder's IDE provides a powerful editing window that you can use to change the source files of your projects. By using the editor's column-marking feature as we've shown here, you can quickly adjust indentation and perform other column-oriented tasks.


Back to Top
Back to Index of Articles

Copyright © 1997, ZD Journals, a division of Ziff-Davis Inc. ZD Journals and ZD Jounals logo are trademarks of Ziff-Davis Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Ziff-Davis is prohibited.
Trademarks & Copyright © 1998 INPRISE Corporation.