📄 rtext.java~2~
字号:
// This will cause updates to the title bar, tabbed pane, etc.
if (!textArea.isModified()) {
textArea.setModified(true);
}
}
/*****************************************************************************/
/**
* Returns whether or not the QuickSearch toolbar is visible. This
* method should be used over <code>getSearchToolBar().isVisible()</code>
* because the latter will allocate the toolbar if it isn't already
* created, but this method won't.
*
* @return Whether or not the QuickSearch toolbar is visible.
* @see #getSearchToolBar
*/
public boolean isSearchToolBarVisible() {
return searchBar == null ? false : searchBar.isVisible();
}
/*****************************************************************************/
/**
* Called whenever the user presses a key in the current text area.
*
* @param e The key event.
*/
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
switch (keyCode) {
// If they're releasing the Insert key, toggle between
// insert/overwrite mode for all editors OTHER THAN the one in
// which the key was pressed (it is done for that one already).
case KeyEvent.VK_INSERT:
StatusBar statusBar = (StatusBar) getStatusBar();
boolean isInsertMode = mainView.getTextMode() ==
RTextEditorPane.INSERT_MODE;
statusBar.setOverwriteModeIndicatorEnabled(isInsertMode);
// Toggle all of the other text areas.
mainView.setTextMode(isInsertMode ?
RTextEditorPane.OVERWRITE_MODE :
RTextEditorPane.INSERT_MODE);
break;
// If they're releasing the Caps Lock key, toggle caps lock
// in the status bar to reflect the actual state.
case KeyEvent.VK_CAPS_LOCK:
// On OS X, getLockingKeyState() is unsupported.
if (getOS() != OS_MAC_OSX) {
try {
boolean state = Toolkit.getDefaultToolkit().
getLockingKeyState(KeyEvent.VK_CAPS_LOCK);
statusBar = (StatusBar) getStatusBar();
statusBar.setCapsLockIndicatorEnabled(state);
}
catch (UnsupportedOperationException uoe) {
uoe.printStackTrace();
}
}
break;
default:
// You cannot modify a read-only document.
if (mainView.currentTextArea.isReadOnly()) {
getStatusBar().setStatusMessage(
"Document is read only!");
}
} // End of switch (keyCode).
}
// Called whenever the user releases a key in the current text area.
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
/*****************************************************************************/
/**
* Loads and validates the icon groups available to RText.
*/
private void loadPossibleIconGroups() {
iconGroupMap = IconGroupLoader.loadIconGroups(this,
getInstallLocation() +
"/icongroups/ExtraIcons.xml");
}
/*****************************************************************************/
/**
* Thanks to Java Bug ID 5026829, JMenuItems (among other Swing components)
* don't update their accelerators, etc. when the properties on which they
* were created update them. Thus, we have to do this manually. This is
* still broken as of 1.5.
*/
protected void menuItemAcceleratorWorkaround() {
menuBar.menuItemAcceleratorWorkaround();
}
/*****************************************************************************/
/**
* Opens the specified files.
*
* @param filesToOpen The files to open.
* @see #openFile
*/
public void openFiles(String[] filesToOpen) {
int count = filesToOpen == null ? 0 : filesToOpen.length;
for (int i = 0; i < count; i++) {
openFile(filesToOpen[i]);
}
}
/*****************************************************************************/
/**
* This is called in the GUI application's constructor. It is a chance
* to do initialization of stuff that will be needed before RText is
* displayed on-screen.
*
* @param prefs The preferences of the application.
* @param splashScreen The "splash screen" for this application. This
* value may be <code>null</code>.
*/
public void preDisplayInit(GUIApplicationPreferences prefs,
SplashScreen splashScreen) {
RTextPreferences properties = (RTextPreferences) prefs;
ResourceBundle msg = getResourceBundle();
getContentPane().add(mainView);
if (properties.searchToolBarVisible) {
addToolBar(getSearchToolBar(), BorderLayout.SOUTH);
searchBar.setVisible(true);
}
splashScreen.updateStatus(msg.getString("AddingFinalTouches"), 90);
// If the user clicks the "X" in the top-right of the window, do nothing.
// (We'll clean up in our window listener).
addWindowListener(new RTextWindowListener(this));
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
mainView.setLineNumbersEnabled(properties.lineNumbersVisible);
// Enable templates in text areas.
boolean enabled = RTextUtilities.enableTemplates(this, true);
System.err.println("Templates successfully enabled: " + enabled);
}
/*****************************************************************************/
/**
* This is called in the GUI application's constructor. It is a chance
* to do initialization of stuff that will be needed by the menu bar
* before it gets created.
*
* @param prefs The preferences of the application.
* @param splashScreen The "splash screen" for this application. This
* value may be <code>null</code>.
*/
protected void preMenuBarInit(GUIApplicationPreferences prefs,
SplashScreen splashScreen) {
// Install any plugins.
super.preMenuBarInit(prefs, splashScreen);
// Make the split pane positions same as last time.
RTextPreferences rtp = (RTextPreferences) prefs;
setSplitPaneDividerLocation(TOP, rtp.dividerLocations[TOP]);
setSplitPaneDividerLocation(LEFT, rtp.dividerLocations[LEFT]);
setSplitPaneDividerLocation(BOTTOM, rtp.dividerLocations[BOTTOM]);
setSplitPaneDividerLocation(RIGHT, rtp.dividerLocations[RIGHT]);
}
/*****************************************************************************/
/**
* This is called in the GUI application's constructor. It is a chance
* to do initialization of stuff that will be needed by the status bar
* bar before it gets created.
*
* @param prefs The preferences of the application.
* @param splashScreen The "splash screen" for this application. This
* value may be <code>null</code>.
*/
protected void preStatusBarInit(GUIApplicationPreferences prefs,
SplashScreen splashScreen) {
RTextPreferences properties = (RTextPreferences) prefs;
String[] filesToOpen = null;
ResourceBundle msg = getResourceBundle();
// Initialize our "new, empty text file" name.
newFileName = msg.getString("NewFileName");
splashScreen.updateStatus(msg.getString("SettingSHColors"), 10);
setSyntaxHighlightingColorScheme(properties.colorScheme);
setWorkingDirectory(properties.workingDirectory);
splashScreen.updateStatus(msg.getString("CreatingView"), 20);
// Initialize our view object.
switch (properties.mainView) {
case TABBED_VIEW:
mainViewStyle = TABBED_VIEW;
mainView = new RTextTabbedPaneView(this, filesToOpen, properties);
break;
case SPLIT_PANE_VIEW:
mainViewStyle = SPLIT_PANE_VIEW;
mainView = new RTextSplitPaneView(this, filesToOpen, properties);
break;
default:
mainViewStyle = MDI_VIEW;
mainView = new RTextMDIView(this, filesToOpen, properties);
}
splashScreen.updateStatus(msg.getString("CreatingStatusBar"), 25);
}
/*****************************************************************************/
/**
* This is called in the GUI application's constructor. It is a chance
* for to do initialization of stuff that will be needed by the toolbar
* before it gets created.
*
* @param prefs The preferences of the application.
* @param splashScreen The "splash screen" for this application. This
* value may be <code>null</code>.
*/
protected void preToolBarInit(GUIApplicationPreferences prefs,
SplashScreen splashScreen) {
RTextPreferences properties = (RTextPreferences) prefs;
ResourceBundle msg = getResourceBundle();
StatusBar statusBar = (StatusBar) getStatusBar();
mainView.addPropertyChangeListener(statusBar);
// Initialize any actions.
splashScreen.updateStatus(msg.getString("CreatingActions"), 30);
createActions(properties);
loadPossibleIconGroups();
try {
setIconGroupByName(properties.iconGroupName);
}
catch (InternalError ie) {
displayException(ie);
System.exit(0);
}
splashScreen.updateStatus(msg.getString("CreatingToolBar"), 60);
}
/*****************************************************************************/
/**
* Called whenever a property changes for a component we are registered
* as listening to.
*/
public void propertyChange(PropertyChangeEvent e) {
String propertyName = e.getPropertyName();
// If the file's path is changing (must be caused by the file being saved(?))...
if (propertyName.equals(RTextEditorPane.FULL_PATH_PROPERTY)) {
String title = "rtext - " + e.getNewValue();
setTitle(title);
}
// If the file's modification status is changing...
else if (propertyName.equals(RTextEditorPane.MODIFIED_PROPERTY)) {
boolean newValue = ( (Boolean) e.getNewValue()).booleanValue();
if (newValue == false) {
String oldTitle = getTitle();
setTitle(oldTitle.substring(0, oldTitle.length() - 1));
}
else {
setTitle(getTitle() + "*");
}
}
}
/*****************************************************************************/
/**
* Called whenever text is removed from the current text area.
*
* @param e The document event.
*/
public void removeUpdate(DocumentEvent e) {
RTextEditorPane textArea = mainView.currentTextArea;
// This will cause updates to the title bar, the tabbed pane, etc.
if (!textArea.isModified()) {
textArea.setModified(true);
}
}
/*****************************************************************************/
/**
* Makes all actions use default accelerators.
*/
void restoreDefaultAccelerators() {
int num = defaultActionAccelerators.length;
for (int i = 0; i < num; i++) {
String actionName = actionNames[i];
getAction(actionName).putValue(Action.ACCELERATOR_KEY,
defaultActionAccelerators[i]);
}
mainView.restoreDefaultAccelerators();
menuItemAcceleratorWorkaround();
}
/*****************************************************************************/
/**
* Attempts to write this RText instance's properties to wherever the OS
* writes Java Preferences stuff.
*/
public void saveRTextPreferences() {
// Save preferences for RText itself.
RTextPreferences prefs = (RTextPreferences) RTextPreferences.
generatePreferences(this);
prefs.savePreferences(this);
// Save preferences for any plugins.
Plugin[] plugins = getPlugins();
int count = plugins.length;
for (int i = 0; i < count; i++) {
plugins[i].savePreferences();
}
// Save the file chooser's properties, if it has been instantiated.
if (chooser != null) {
chooser.savePreferences();
}
}
/*****************************************************************************/
/**
* Changes the style of icons used by <code>rtext</code>.<p>
*
* This method fires a property change of type
* <code>ICON_STYLE_PROPERTY</code>.
*
* @param name The name of the icon group to use. If this name is not
* recognized, a default icon set will be used.
*/
public void setIconGroupByName(String name) {
IconGroup newGroup = (IconGroup) iconGroupMap.get(name);
if (newGroup == null) {
newGroup = (IconGroup) iconGroupMap.get(
IconGroupLoader.DEFAULT_ICON_GROUP_NAME);
}
if (newGroup == null) {
throw new InternalError("No icon groups!");
}
if (iconGroup != null && iconGroup.equals(newGroup)) {
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -