📄 rtext.java~2~
字号:
}
Dimension size = getSize();
IconGroup old = iconGroup;
iconGroup = newGroup;
Icon icon = iconGroup.getIcon("new");
getAction(NEW_ACTION).putValue(Action.SMALL_ICON, icon);
icon = iconGroup.getIcon("open");
getAction(OPEN_ACTION).putValue(Action.SMALL_ICON, icon);
icon = iconGroup.getIcon("save");
getAction(SAVE_ACTION).putValue(Action.SMALL_ICON, icon);
icon = iconGroup.getIcon("saveall");
getAction(SAVE_ALL_ACTION).putValue(Action.SMALL_ICON, icon);
icon = iconGroup.getIcon("openinnewwindow");
getAction(OPEN_NEWWIN_ACTION).putValue(Action.SMALL_ICON, icon);
icon = iconGroup.getIcon("saveas");
getAction(SAVE_AS_ACTION).putValue(Action.SMALL_ICON, icon);
icon = iconGroup.getIcon("options");
getAction(OPTIONS_ACTION).putValue(Action.SMALL_ICON, icon);
icon = iconGroup.getIcon("help");
getAction(HELP_ACTION).putValue(Action.SMALL_ICON, icon);
icon = iconGroup.getIcon("about");
getAction(ABOUT_ACTION).putValue(Action.SMALL_ICON, icon);
// Fix the icons for all actions owned by the tabbed pane.
mainView.refreshIcons();
// The toolbar uses the large versions of the icons, if available.
// FIXME: Make this toggle-able.
StandardToolBar toolBar = (StandardToolBar) getToolBar();
if (toolBar != null) {
toolBar.checkForLargeIcons();
// Do this because the toolbar has changed it's size.
}
pack();
setSize(size);
// Make the help dialog use appropriate "back" and "forward" icons.
if (helpDialog != null) {
helpDialog.setBackButtonIcon(iconGroup.getIcon("back"));
helpDialog.setForwardButtonIcon(iconGroup.getIcon("forward"));
}
firePropertyChange(ICON_STYLE_PROPERTY, old, iconGroup);
}
/*****************************************************************************/
/**
* Sets the main view style. This method fires a property change of type
* <code>MAIN_VIEW_STYLE_PROPERTY</code>.
*
* @param viewStyle One of <code>TABBED_VIEW</code>,
* <code>SPLIT_PANE_VIEW</code>, or <code>MDI_VIEW</code>. If this
* value is invalid, nothing happens.
* @see #getMainViewStyle
*/
public void setMainViewStyle(int viewStyle) {
// Only do the update if viewStyle is different from the current viewStyle.
if ( (viewStyle == TABBED_VIEW || viewStyle == SPLIT_PANE_VIEW ||
viewStyle == MDI_VIEW)
&& viewStyle != mainViewStyle) {
int oldMainViewStyle = mainViewStyle;
mainViewStyle = viewStyle;
AbstractMainView fromPanel = mainView;
RTextPreferences props = (RTextPreferences) RTextPreferences.
generatePreferences(this);
// Create the new view.
switch (viewStyle) {
case TABBED_VIEW:
mainView = new RTextTabbedPaneView(this, null, props);
menuBar.setWindowMenuVisible(false);
break;
case SPLIT_PANE_VIEW:
mainView = new RTextSplitPaneView(this, null, props);
menuBar.setWindowMenuVisible(false);
break;
case MDI_VIEW:
mainView = new RTextMDIView(this, null, props);
menuBar.setWindowMenuVisible(true);
break;
}
// Update property change listeners.
PropertyChangeListener[] propertyChangeListeners = fromPanel.
getPropertyChangeListeners();
int length = propertyChangeListeners.length;
for (int i = 0; i < length; i++) {
fromPanel.removePropertyChangeListener(propertyChangeListeners[i]);
mainView.addPropertyChangeListener(propertyChangeListeners[i]);
}
// Keep find/replace dialogs working, if they've been created. Make the new
// dialog listen to actions from the find/replace dialogs.
// NOTE: The find and replace dialogs will be moved to mainView in the
// copyData method below.
if (fromPanel.findDialog != null) {
fromPanel.findDialog.changeActionListener(fromPanel, mainView);
fromPanel.replaceDialog.changeActionListener(fromPanel, mainView);
fromPanel.findDialog.addPropertyChangeListener(mainView);
fromPanel.replaceDialog.addPropertyChangeListener(mainView);
fromPanel.findDialog.removePropertyChangeListener(fromPanel);
fromPanel.replaceDialog.removePropertyChangeListener(fromPanel);
}
// Make mainView have all the properties of the old panel.
mainView.copyData(fromPanel);
// If we have switched to a tabbed view, artificially
// fire stateChanged if the last document is selected,
// because it isn't fired naturally if this is so.
if ( (mainView instanceof RTextTabbedPaneView) &&
mainView.getSelectedIndex() == mainView.getNumDocuments() - 1) {
( (RTextTabbedPaneView) mainView).stateChanged(new ChangeEvent(mainView));
}
// Physically replace the old main view with the new one.
// NOTE: We need to remember previous size and restore it
// because center collapses if changed to MDI otherwise.
Dimension size = getSize();
Container contentPane = getContentPane();
contentPane.remove(fromPanel);
contentPane.add(mainView);
fromPanel = null;
//contentPane.add(mainView, BorderLayout.CENTER);
pack();
setSize(size);
// For some reason we have to reselect the currently-selected
// window to have it actually active in an MDI view.
if (mainView instanceof RTextMDIView) {
mainView.setSelectedIndex(mainView.getSelectedIndex());
}
firePropertyChange(MAIN_VIEW_STYLE_PROPERTY, oldMainViewStyle,
mainViewStyle);
} // End of if ((viewStyle==TABBED_VIEW || ...
}
/*****************************************************************************/
/**
* This method changes both the active file name in the title bar, and the
* status message in the status bar.
*
* @param fileFullPath Full path to the text file currently being edited
* (to be displayed in the window's title bar). If
* <code>null</code>, the currently displayed message
* is not changed.
* @param statusMessage The message to be displayed in the status bar.
* If <code>null</code>, the currently displayed
* message is not changed.
*
*/
public void setMessages(String fileFullPath, String statusMessage) {
if (fileFullPath != null) {
setTitle("rtext - " + fileFullPath);
}
StatusBar statusBar = (StatusBar) getStatusBar();
if (statusBar != null && statusMessage != null) {
statusBar.setStatusMessage(statusMessage);
}
}
/*****************************************************************************/
/**
* Sets whether or not the read-only indicator in the status bar is enabled.
*
* @param enabled Whether or not the read-only indicator is enabled.
*/
public void setStatusBarReadOnlyIndicatorEnabled(boolean enabled) {
( (StatusBar) getStatusBar()).setReadOnlyIndicatorEnabled(enabled);
}
/*****************************************************************************/
/**
* Sets the syntax highlighting color scheme being used.
*
* @param colorScheme The new color scheme to use. If <code>null</code>,
* nothing changes.
*/
public void setSyntaxHighlightingColorScheme(
SyntaxHighlightingColorScheme colorScheme) {
if (colorScheme != null && !colorScheme.equals(this.colorScheme)) {
// Make a deep copy for our copy. We must be careful to do this
// and pass our newly-created deep copy to mainView so that we
// do not end up with the same copy passed to us (which could be
// in the process of being edited in an options dialog).
this.colorScheme = new SyntaxHighlightingColorScheme(
colorScheme);
if (mainView != null) {
mainView.setSyntaxHighlightingColorScheme(
this.colorScheme);
}
}
}
/*****************************************************************************/
/**
* Changes whether or not tabs should be emulated with spaces
* (i.e., soft tabs).
* This simply calls <code>mainView.setTabsEmulated</code>.
*
* @param areEmulated Whether or not tabs should be emulated with spaces.
*/
public void setTabsEmulated(boolean areEmulated) {
mainView.setTabsEmulated(areEmulated);
}
/*****************************************************************************/
/**
* Sets the tab size to be used on all documents.
*
* @param newSize The tab size to use.
* @see #getTabSize
*/
public void setTabSize(int newSize) {
mainView.setTabSize(newSize);
}
/*****************************************************************************/
/**
* Sets the "working directory;" that is, the directory in which
* new, empty files are placed.
*
* @param directory The new working directory. If this directory does
* not exist, the Java property "user.dir" is used.
* @see #getWorkingDirectory
*/
public void setWorkingDirectory(String directory) {
File test = new File(directory);
if (test.isDirectory()) {
workingDirectory = directory;
}
else {
workingDirectory = System.getProperty("user.dir");
}
}
/*****************************************************************************/
/**
* Updates the look and feel for all components and windows in
* this <code>RText</code> instance. This method assumes that
* <code>UIManager.setLookAndFeel(lnf)</code> has already been called.
*
* @param lnf The new look and feel.
*/
public void updateLookAndFeel(LookAndFeel lnf) {
try {
Dimension size = this.getSize();
// Update all components in this frame.
SwingUtilities.updateComponentTreeUI(this);
this.pack();
this.setSize(size);
// So mainView knows to update it's popup menus, etc.
mainView.updateLookAndFeel();
// Update any dialogs.
if (optionsDialog != null) {
SwingUtilities.updateComponentTreeUI(optionsDialog);
optionsDialog.pack();
}
OptionsDialog pluginOptDialog = getPluginOptionsDialog(false);
if (pluginOptDialog != null) {
SwingUtilities.updateComponentTreeUI(pluginOptDialog);
pluginOptDialog.pack();
}
if (helpDialog != null) {
SwingUtilities.updateComponentTreeUI(helpDialog);
helpDialog.pack();
}
if (aboutDialogCreated) {
org.fife.ui.AboutDialog aboutDialog = getAboutDialog();
SwingUtilities.updateComponentTreeUI(aboutDialog);
aboutDialog.pack();
}
if (chooser != null) {
SwingUtilities.updateComponentTreeUI(chooser);
chooser.updateUI(); // So the popup menu gets updated.
}
}
catch (Exception f) {
displayException(f);
}
}
/*****************************************************************************/
/**
* 1.5.2004/pwy: The following two functions are called from the
* OSXAdapter and provide the hooks for the functions from the standard
* Apple application menu. The "about()" OSX hook is in
* AbstractGUIApplication.
*/
public void preferences() {
getAction(OPTIONS_ACTION).actionPerformed(new ActionEvent(this, 0, "unused"));
}
public void openFile(final String filename) {
//gets called when we receive an open event from the finder on OS X
SwingUtilities.invokeLater(new Runnable() {
public void run() {
RTextEditorPane textArea = mainView.currentTextArea;
try {
String encoding = RTextFileChooser.getDefaultEncoding();
try {
UnicodeReader reader = new UnicodeReader(filename);
encoding = reader.getEncoding();
reader.close();
}
catch (Exception e) {
displayException(e);
}
mainView.addOldTextFile(filename, encoding);
mainView.moveToTopOfCurrentDocument();
}
catch (FileNotFoundException f) {
}
}
});
}
/*****************************************************************************/
/**
* Where the program begins.
*/
public static void main(String[] args) {
// 1.5.2004/pwy: Setting this property makes the menu appear on top
// of the screen on Apple Mac OS X systems. It is ignored by all other
// other Java implementations.
System.setProperty("apple.laf.useScreenMenuBar", "true");
// 1.5.2004/pwy: Setting this property defines the standard
// Application menu name on Apple Mac OS X systems. It is ignored by
// all other Java implementations.
// NOTE: Although you can set the useScreenMenuBar property above at
// runtime, it appears that for this one, you must set it before
// (such as in your *.app definition).
//System.setProperty("com.apple.mrj.application.apple.menu.about.name", "RText");
//Create the top-level container and add contents to it.
RText rtext = new RText(args);
rtext.setVisible(true);
// For some reason, when using MDI_VIEW, the first window isn't
// selected (although it is activated)... INVESTIGATE ME!!
if (rtext.getMainViewStyle() == MDI_VIEW) {
rtext.getMainView().setSelectedIndex(0);
// We currently have one rtext "thread" running.
}
StoreKeeper.addRTextInstance(rtext);
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -