📄 abstractmainview.java~1~
字号:
/**
* Returns the syntax filters being used to open documents (i.e., to decide
* what syntax highlighting color scheme, if any, to use when opening
* documents).
*
* @return The filters being used.
*/
public SyntaxFilters getSyntaxFilters() {
return syntaxFilters;
}
/*****************************************************************************/
/**
* Returns the size of a tab, in spaces.
*
* @return The tab size (in spaces) currently being used by all documents
* in this tabbed pane.
*/
public int getTabSize() {
return tabSize;
}
/*****************************************************************************/
/**
* Returns the text mode we're in.
*
* @return <code>RTextEditorPane.INSERT_MODE</code>
* or <code>RTextEditorPane.OVERWRITE_MODE</code>.
* @see #setTextMode
*/
public int getTextMode() {
return textMode;
}
/*****************************************************************************/
/**
* Returns a translucent version of a given <code>java.awt.Image</code>.
*
* @param image The <code>java.awt.Image</code> on which to apply the alpha
* filter.
* @param alpha The alpha value to use when defining how translucent you
* want the image to be. This should be in the range 0.0f to
* 1.0f.
*/
private BufferedImage getTranslucentImage(Image image, float alpha) {
BufferedImage buffer = null;
int width = image.getWidth(null);
int height = image.getHeight(null);
MediaTracker tracker = new MediaTracker(this);
buffer = new BufferedImage(width,height, BufferedImage.TYPE_INT_ARGB_PRE);
tracker.addImage(buffer, 0);
Graphics2D g2d = buffer.createGraphics();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
g2d.drawImage(image, 0,0, null);
try {
tracker.waitForID(0);
} catch (InterruptedException e) {
JOptionPane.showMessageDialog(this,
"Exception caught in AbstractMainView.getTranslucentImage:\n" + e,
owner.getResourceBundle().getString("ErrorDialogTitle"),
JOptionPane.ERROR_MESSAGE);
}
tracker.removeImage(buffer, 0);
g2d.dispose();
return buffer;
}
/*****************************************************************************/
/**
* Returns whether this panel is highlighting modified documents' display
* names with a different color.
*
* @see #setHighlightModifiedDocumentDisplayNames
* @see #getModifiedDocumentDisplayNamesColor
* @see #setModifiedDocumentDisplayNamesColor
*/
public boolean highlightModifiedDocumentDisplayNames() {
return highlightModifiedDocumentDisplayNames;
}
/*****************************************************************************/
/**
* Initializes this component.
*
* @param owner The <code>RText</code> that this tabbed pane sits in.
* @param filesToOpen Array of strings representing files to open. If
* this parameter is null, a single file with a default name is
* opened.
* @param prefs A properties object used to initialize some fields on
* this main view.
*/
protected void initialize(RText owner, String[] filesToOpen,
RTextPreferences prefs) {
// Remember the owner of this tabbed pane.
this.owner = owner;
// Initialize some stuff from prefs.
printFont = prefs.printFont;
tabSize = prefs.tabSize;
textMode = prefs.textMode;
emulateTabsWithWhitespace = prefs.emulateTabsWithSpaces;
setDocumentSelectionPlacement(prefs.tabPlacement);
lineNumbersEnabled = prefs.lineNumbersVisible;
setBackgroundImageAlpha(prefs.imageAlpha);
Object prefsBackgroundObject = prefs.backgroundObject;
if (prefsBackgroundObject instanceof String) {
Image image = RTextUtilities.getImageFromFile(
(String)prefsBackgroundObject);
if (image!=null) {
setBackgroundObject(image);
setBackgroundImageFileName((String)prefsBackgroundObject);
}
else { // This is when the file passed in no longer exists.
setBackgroundObject(Color.WHITE);
setBackgroundImageFileName(null);
}
}
else { // It must be a color here.
setBackgroundObject(prefsBackgroundObject);
setBackgroundImageFileName(null);
}
setCaretColor(prefs.caretColor);
setSelectionColor(prefs.selectionColor);
setLineWrap(prefs.wordWrap);
setCurrentLineHighlightEnabled(prefs.currentLineHighlightEnabled);
setCurrentLineHighlightColor(prefs.currentLineHighlightColor);
setBracketMatchingEnabled(prefs.bracketMatchingEnabled);
setMatchedBracketBGColor(prefs.matchedBracketBGColor);
setMatchedBracketBorderColor(prefs.matchedBracketBorderColor);
setMarginLineEnabled(prefs.marginLineEnabled);
setMarginLinePosition(prefs.marginLinePosition);
setMarginLineColor(prefs.marginLineColor);
syntaxFilters = new SyntaxFilters(prefs.syntaxFiltersString);
searchStrings = new Vector(0);
searchingForward = true; // Default to searching forward.
searchMatchCase = false; // Default is don't match case.
searchWholeWord = false; // Default is not whole word.
searchMarkAll = false; // Default is not to mark all.
// 1.5.2004/pwy: The default modifier key in Windows and others is
// Command but for Mac's it is the Apple key. We get the default from
// the toolkit to make sure it works on all platforms the way the
// user expects it.
int defaultModifier = java.awt.Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
// Initialize this main view's actions.
createActions(prefs);
setHighlightModifiedDocumentDisplayNames(prefs.highlightModifiedDocNames);
setModifiedDocumentDisplayNamesColor(prefs.modifiedDocumentNamesColor);
setWhitespaceVisible(prefs.visibleWhitespace);
setSmoothTextEnabled(prefs.smoothTextEnabled);
setFractionalFontMetricsEnabled(prefs.fractionalMetricsEnabled);
setMarkAllHighlightColor(prefs.markAllHighlightColor);
setRoundedSelectionEdges(prefs.roundedSelectionEdges);
carets = new int[2];
setCaretStyle(RTextArea.INSERT_CARET, prefs.carets[0]);
setCaretStyle(RTextArea.OVERWRITE_CARET, prefs.carets[1]);
setCaretBlinkRate(prefs.caretBlinkRate);
// Start us out with whatever files they passed in.
if (filesToOpen==null)
addNewEmptyUntitledTextFile();
else {
for (int i=0; i<filesToOpen.length; i++) {
try {
// FIXME: We really should use a UnicodeReader to
// check the encoding of these files instead of
// assuming they're the default.
addOldTextFile(filesToOpen[i],
RTextFileChooser.getDefaultEncoding());
} catch (FileNotFoundException e) { }
}
}
setSelectedIndex(0);
// Update the title of the RText window.
owner.setMessages(currentTextArea.getFileFullPath(), null);
}
/*****************************************************************************/
/**
* Returns whether or not bracket matching is enabled.
*
* @return <code>true</code> iff bracket matching is enabled.
* @see #setBracketMatchingEnabled
*/
public boolean isBracketMatchingEnabled() {
return bracketMatchingEnabled;
}
/*****************************************************************************/
/**
* Returns whether or not the current line is highlighted.
*
* @return Whether or the current line is highlighted.
* @see #setCurrentLineHighlightEnabled
* @see #getCurrentLineHighlightColor
* @see #setCurrentLineHighlightColor
*/
public boolean isCurrentLineHighlightEnabled() {
return highlightCurrentLine;
}
/*****************************************************************************/
/**
* Returns whether fractional fontmetrics is enabled.
*
* @return Whether fractional fontmetrics is enabled.
* @see #isSmoothTextEnabled
* @see #setFractionalFontMetricsEnabled
*/
public boolean isFractionalFontMetricsEnabled() {
return fractionalMetricsEnabled;
}
/*****************************************************************************/
/**
* Returns whether or not the margin line is enabled
*
* @return Whether or not the margin line is enabled.
* @see #setMarginLineEnabled
*/
public boolean isMarginLineEnabled() {
return marginLineEnabled;
}
/*****************************************************************************/
/**
* Returns whether smooth text (antialiasing) is enabled.
*
* @return Whether smooth text is enabled.
* @see #isFractionalFontMetricsEnabled
* @see #setSmoothTextEnabled
*/
public boolean isSmoothTextEnabled() {
return smoothTextEnabled;
}
/*****************************************************************************/
/**
* Returns whether whitespace is visible in the text areas in this panel.
*
* @return Whether whitespace is visible.
* @see #setWhitespaceVisible
*/
public boolean isWhitespaceVisible() {
return whitespaceVisible;
}
/*****************************************************************************/
/**
* Loads a macro. This macro will be loaded into all currently-open
* <code>RTextEditorPane</code>s, as well as all editor panes opened
* afterward, until a new macro is loaded.
*
* @param file The file containing the macro to load. If this file does
* not exist or is otherwise invalid, no macro is loaded.
*/
public void loadMacro(File file) {
try {
RTextEditorPane.loadMacro(new Macro(file));
} catch (Exception e) {
owner.displayException(e);
}
}
/*****************************************************************************/
/**
* Scrolls to the top of the current document, and places the cursor there.
*/
public void moveToTopOfCurrentDocument() {
currentTextArea.setCaretPosition(0);
}
/*****************************************************************************/
/**
* Called whenever a property changes on a component we're 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)) {
setDocumentDisplayNameAt(getSelectedIndex(), currentTextArea.getFileName());
fireCurrentTextAreaEvent(CurrentTextAreaEvent.FILE_NAME_CHANGED,
e.getOldValue(), e.getNewValue());
}
// If the file's modification status is changing...
else if (propertyName.equals(RTextEditorPane.MODIFIED_PROPERTY)) {
int selectedIndex = getSelectedIndex();
String oldTitle = getDocumentDisplayNameAt(selectedIndex);
if ( ((Boolean)e.getNewValue()).booleanValue()==true )
setDocumentDisplayNameAt(selectedIndex, oldTitle+"*");
else
setDocumentDisplayNameAt(selectedIndex, oldTitle.substring(0,oldTitle.length()-1)); // Get rid of the "*".
fireCurrentTextAreaEvent(
CurrentTextAreaEvent.IS_MODIFIED_CHANGED,
e.getOldValue(), e.getNewValue());
}
// If the user changed any search options via a search dialog...
else if (propertyName.equals(FindDialog.MATCH_CASE_PROPERTY)) {
searchMatchCase = ((Boolean)e.getNewValue()).booleanValue();
}
else if (propertyName.equals(FindDialog.MATCH_WHOLE_WORD_PROPERTY)) {
searchWholeWord = ((Boolean)e.getNewValue()).booleanValue();
}
else if (propertyName.equals(FindDialog.USE_REG_EX_PROPERTY)) {
searchRegExpression = ((Boolean)e.getNewValue()).booleanValue();
}
else if (propertyName.equals(FindDialog.SEARCH_DOWNWARD_PROPERTY)) {
searchingForward = ((Boolean)e.getNewValue()).booleanValue();
}
else if (propertyName.equals(FindDialog.MARK_ALL_PROPERTY)) {
currentTextArea.clearMarkAllHighlights();
searchMarkAll = ((Boolean)e.getNewValue()).booleanValue();
}
// This is exclusive to the FindInFilesDialog.
else if (propertyName.equals(FindInFilesDialog.SEARCH_STRINGS_PROPERTY)) {
searchStrings = findInFilesDialog.getSearchStrings();
}
}
/*****************************************************************************/
/**
* Repaints the display names for open documents.
*/
public abstract void refreshDisplayNames();
/***************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -