📄 abstractmainview.java~2~
字号:
* <code>false</code> if they weren't (i.e., the user hit cancel).
*/
public boolean closeAllDocuments() {
// Cycle through each document, one by one.
int numDocuments = getNumDocuments();
for (int i = numDocuments - 1; i >= 0; i--) {
// Try to close the document.
int rc = closeCurrentDocument();
// If the user cancels out of it, quit the whole schibang.
if (rc == JOptionPane.CANCEL_OPTION) {
// If the newly-active file is read-only, say so in the status bar.
owner.setStatusBarReadOnlyIndicatorEnabled(
currentTextArea == null ? false
: currentTextArea.isReadOnly());
return false;
}
} // End of for (int i=tabCount-1; i>=0; i--).
// If we got this far, then all documents were closed.
// We'll just have an empty default-named file out there.
return true;
}
/*****************************************************************************/
/**
* Attempts to close the current document. Any implementation of this
* method <i>must be synchronized</i> so it doesn't interfere with the
* thread checking for files being modified outside of the editor.
*
* @return JOptionPane.YES_OPTION/NO_OPTION/CANCEL_OPTION, depending on
* what the user does.
*/
public abstract int closeCurrentDocument();
/*****************************************************************************/
/**
* Converts all instances of a number of spaces equal to a tab in all open
* documents into tabs.
*
* @see #convertOpenFilesTabsToSpaces
*/
public void convertOpenFilesSpacesToTabs() {
int numDocuments = getNumDocuments();
for (int i = 0; i < numDocuments; i++) {
getRTextEditorPaneAt(i).convertSpacesToTabs();
}
}
/*****************************************************************************/
/**
* Converts all tabs in all open documents into an equivalent number of
* spaces.
*
* @see #convertOpenFilesSpacesToTabs
*/
public void convertOpenFilesTabsToSpaces() {
int numDocuments = getNumDocuments();
for (int i = 0; i < numDocuments; i++) {
getRTextEditorPaneAt(i).convertTabsToSpaces();
}
}
/*****************************************************************************/
public void copyData(AbstractMainView fromPanel) {
currentTextArea = fromPanel.currentTextArea;
for (int i = 0; i < NUM_ACTIONS; i++) {
actions[i] = fromPanel.getAction(i);
}
findDialog = fromPanel.findDialog;
replaceDialog = fromPanel.replaceDialog;
searchStrings = fromPanel.searchStrings;
searchingForward = fromPanel.searchingForward;
searchMatchCase = fromPanel.searchMatchCase;
searchWholeWord = fromPanel.searchWholeWord;
searchRegExpression = fromPanel.searchRegExpression;
searchMarkAll = fromPanel.searchMarkAll;
lineNumbersEnabled = fromPanel.lineNumbersEnabled;
lineWrapEnabled = fromPanel.lineWrapEnabled;
findInFilesDialog = fromPanel.findInFilesDialog;
if (findInFilesDialog != null) {
findInFilesDialog.removeFindInFilesListener(fromPanel);
findInFilesDialog.addFindInFilesListener(this);
}
goToDialog = fromPanel.goToDialog;
textMode = fromPanel.textMode;
tabSize = fromPanel.tabSize;
emulateTabsWithWhitespace = fromPanel.emulateTabsWithWhitespace;
printFont = fromPanel.printFont;
caretColor = fromPanel.caretColor;
selectionColor = fromPanel.selectionColor;
backgroundObject = fromPanel.backgroundObject;
imageAlpha = fromPanel.imageAlpha;
backgroundImageFileName = fromPanel.backgroundImageFileName;
owner = fromPanel.owner;
syntaxFilters = fromPanel.syntaxFilters;
setPreferredSize(fromPanel.getPreferredSize());
int numDocuments = fromPanel.getNumDocuments();
int fromSelectedIndex = fromPanel.getSelectedIndex();
ArrayList scrollPanes = new ArrayList(numDocuments);
for (int i = 0; i < numDocuments; i++) {
scrollPanes.add(fromPanel.getRTextScrollPaneAt(0));
fromPanel.removeComponentAt(0);
}
for (int i = 0; i < numDocuments; i++) {
RTextScrollPane scrollPane = (RTextScrollPane) scrollPanes.get(i);
RTextEditorPane editorPane = (RTextEditorPane) scrollPane.textArea;
addDocument(editorPane.getFileName(), scrollPane,
editorPane.getFileFullPath());
editorPane.removePropertyChangeListener(fromPanel);
editorPane.addPropertyChangeListener(this);
}
removeComponentAt(0); // Remove the default-named file.
renumberDisplayNames(); // In case the same document is opened multiple times.
setSelectedIndex(fromSelectedIndex);
// "Move over" all current text area listeners.
// Remember "listeners" is guaranteed to be non-null.
Object[] listeners = fromPanel.listenerList.getListenerList();
Class ctalClass = CurrentTextAreaListener.class;
for (int i = 0; i < listeners.length; i += 2) {
if (listeners[i] == ctalClass) {
CurrentTextAreaListener l =
(CurrentTextAreaListener) listeners[i + 1];
fromPanel.listenerList.remove(ctalClass, l);
listenerList.add(ctalClass, l);
}
}
}
/*****************************************************************************/
/**
* Creates the array of actions used by this RText.
*
* @param properties The RText properties for this RText instance.
*/
private void createActions(RTextPreferences properties) {
ResourceBundle msg = ResourceBundle.getBundle(
"org.fife.rtext.MainPanelActions");
String commonIconPath = "org/fife/rtext/graphics/common_icons/";
ClassLoader cl = this.getClass().getClassLoader();
actions = new Action[NUM_ACTIONS];
String temp = msg.getString("CloseActionName");
actions[CLOSE_ACTION] = new CloseAction(temp, null, temp,
new Integer(msg.getString(
"CloseActionMnemonic").charAt(0)),
properties.
mainViewActionAccelerators[
CLOSE_ACTION], owner);
temp = msg.getString("FindActionName");
actions[FIND_ACTION] = new FindAction(temp, null, temp,
new Integer(msg.getString(
"FindActionMnemonic").charAt(0)),
properties.mainViewActionAccelerators[
FIND_ACTION], owner);
temp = msg.getString("FNActionName");
actions[FIND_NEXT_ACTION] = new FindNextAction(temp, null, temp,
new Integer(msg.getString("FNActionMnemonic").charAt(0)),
properties.mainViewActionAccelerators[FIND_NEXT_ACTION], owner);
temp = msg.getString("RepActionName");
actions[REPLACE_ACTION] = new ReplaceAction(temp, null, temp,
new Integer(msg.getString(
"RepActionMnemonic").charAt(0)),
properties.
mainViewActionAccelerators[
REPLACE_ACTION], owner);
temp = msg.getString("RNActionName");
actions[REPLACE_NEXT_ACTION] = new ReplaceNextAction(temp, null, temp,
new Integer(msg.getString("RNActionMnemonic").charAt(0)),
properties.mainViewActionAccelerators[REPLACE_NEXT_ACTION], owner);
temp = msg.getString("RAActionName");
actions[REPLACE_ALL_ACTION] = new ReplaceAllAction(temp, null, temp,
new Integer(msg.getString("RAActionMnemonic").charAt(0)),
properties.mainViewActionAccelerators[REPLACE_ALL_ACTION], owner);
temp = msg.getString("FIFActionName");
actions[FIND_IN_FILES_ACTION] = new FindInFilesAction(temp, null, temp,
new Integer(msg.getString("FIFActionMnemonic").charAt(0)),
properties.mainViewActionAccelerators[FIND_IN_FILES_ACTION], owner);
temp = msg.getString("PrintActionName");
actions[PRINT_ACTION] = new PrintAction(temp, null, temp,
new Integer(msg.getString(
"PrintActionMnemonic").charAt(0)),
properties.
mainViewActionAccelerators[
PRINT_ACTION], owner);
temp = msg.getString("PPActionName");
actions[PRINT_PREVIEW_ACTION] = new PrintPreviewAction(temp, null, temp, null,
properties.mainViewActionAccelerators[PRINT_PREVIEW_ACTION], owner);
temp = msg.getString("GoToActionName");
actions[GOTO_ACTION] = new GoToAction(temp,
new ImageIcon(cl.getResource(
commonIconPath + "goto16.gif")), temp,
new Integer(msg.getString(
"GoToActionMnemonic").charAt(0)),
properties.mainViewActionAccelerators[
GOTO_ACTION], owner);
temp = msg.getString("CAActionName");
actions[CLOSE_ALL_ACTION] = new CloseAllAction(temp, null, temp, null,
properties.mainViewActionAccelerators[CLOSE_ALL_ACTION], owner);
msg = null; // May help with GC.
}
/*****************************************************************************/
/**
* Returns an editor pane to add to this main view.
*
* @param fileName The name of the file to add.
* @param syntaxStyle The syntax style for this editor to use.
* @param encoding The encoding of the file.
* @return An editor pane.
*/
private RTextEditorPane createRTextEditorPane(String fileName,
int syntaxStyle,
String encoding) {
RTextEditorPane pane = new RTextEditorPane(owner, lineWrapEnabled,
textMode, fileName);
// Set some properties.
pane.setBackgroundObject(backgroundObject);
pane.setTabSize(tabSize);
pane.setCurrentLineHighlightEnabled(highlightCurrentLine);
pane.setCurrentLineHighlightColor(currentLineColor);
pane.setMarginLineEnabled(marginLineEnabled);
pane.setMarginLinePosition(marginLinePosition);
pane.setMarginLineColor(marginLineColor);
pane.setMarkAllHighlightColor(markAllHighlightColor);
pane.setSyntaxEditingStyle(syntaxStyle);
pane.setBracketMatchingEnabled(bracketMatchingEnabled);
pane.setMatchedBracketBGColor(matchedBracketBGColor);
pane.setMatchedBracketBorderColor(matchedBracketBorderColor);
pane.setEncoding(encoding);
pane.setWhitespaceVisible(whitespaceVisible);
pane.setCaretColor(caretColor);
pane.setSelectionColor(selectionColor);
pane.setSyntaxHighlightingColorScheme(
owner.getSyntaxHighlightingColorScheme());
pane.setRoundedSelectionEdges(roundedSelectionEdges);
pane.setCaretStyle(RTextEditorPane.INSERT_MODE,
carets[RTextEditorPane.INSERT_MODE]);
pane.setCaretStyle(RTextEditorPane.OVERWRITE_MODE,
carets[RTextEditorPane.OVERWRITE_MODE]);
pane.getCaret().setBlinkRate(caretBlinkRate);
//pane.setFadeCurrentLineHighlight(fadeCurrentLineHighlight);
// If we're in the middle of recording a macro, make the cursor
// appropriate on this guy.
if (RTextEditorPane.isRecordingMacro()) {
pane.setCursor(getMacroCursor());
// Other properties.
}
pane.setTabsEmulated(emulateTabsWithWhitespace);
pane.setAntiAliasEnabled(isSmoothTextEnabled());
pane.setFractionalFontMetricsEnabled(isFractionalFontMetricsEnabled());
// Listeners.
pane.addPropertyChangeListener(owner);
pane.addPropertyChangeListener( (StatusBar) owner.getStatusBar());
pane.addPropertyChangeListener(this);
// Return him.
return pane;
}
/*****************************************************************************/
/**
* Called when the user selects a file in a listened-to find-in-files
* dialog.
*
* @param e The event received from the <code>FindInFilesDialog</code>.
*/
public void findInFilesFileSelected(FindInFilesEvent e) {
ResourceBundle msg = owner.getResourceBundle();
String fileName = e.getFileName();
try {
// FIXME: Might not be default encoding; need to check this.
addOldTextFile(fileName, RTextFileChooser.getDefaultEncoding());
}
catch (FileNotFoundException fnfe) {
JOptionPane.showMessageDialog(findInFilesDialog,
msg.getString("ErrorReloadFNF"),
msg.getString("ErrorDialogTitle"),
JOptionPane.ERROR_MESSAGE);
return;
}
findInFilesDialog.setStatusText("File '" + fileName + "' opened in RText.");
int line = e.getLine();
if (line != -1) {
try {
// currentTextArea is updated here. Highlight the searched-for
// text.
int start = currentTextArea.getLineStartOffset(line - 1);
int end = currentTextArea.getLineEndOffset(line - 1) - 1;
currentTextArea.setCaretPosition(end);
currentTextArea.moveCaretPosition(start);
currentTextArea.getCaret().setSelectionVisible(true);
}
catch (Exception exc) {
owner.displayException(exc);
moveToTopOfCurrentDocument();
}
}
else {
moveToTopOfCurrentDocument();
}
}
/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -