⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractmainview.java~1~

📁 具有不同语法高亮的编辑器实例
💻 JAVA~1~
📖 第 1 页 / 共 5 页
字号:
		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();
	}


/*****************************************************************************/


	/**
	 * Notifies all registered <code>CurrentTextAreaListener</code>s of a
	 * change in the current text area.
	 *
	 * @param type The type of event to fire.
	 * @param oldValue The old value.
	 * @param newValue The new value.
	 */
	protected void fireCurrentTextAreaEvent(int type, Object oldValue,
									Object newValue) {
		// Guaranteed to return a non-null array.
		Object[] listeners = listenerList.getListenerList();
		// Process the listeners last to first, notifying
		// those that are interested in this event.
		for (int i = listeners.length-2; i>=0; i-=2) {
			if (listeners[i]==CurrentTextAreaListener.class) {
				((CurrentTextAreaListener)listeners[i+1]).
					currentTextAreaPropertyChanged(
						new CurrentTextAreaEvent(this, type,
											oldValue, newValue));
			}
		}
	}


/*****************************************************************************/


	/**
	 * Returns the requested action.
	 *
	 * @param action The action to fetch, e.g., <code>FIND_ACTION</code> or
	 *               <code>PRINT_ACTION</code>.
	 * @see #getActions
	 */
	public /*RecordableTextAction*/Action getAction(int action) {
		return actions[action];
	}


/*****************************************************************************/


	/**
	 * Returns all actions owned by this main view.
	 *
	 * @return All actions owned by this main view.
	 * @see #getAction
	 */
	public Action[] getActions() {
		return actions;
	}


/*****************************************************************************/ 


	/**
	 * Returns the alpha value used to make the background image translucent.
	 * This value does NOT change the background if no image is used (i.e., if
	 * the background is just a color).
	 *
	 * @return The alpha value used to make a background image translucent.
	 *         This value will be in the range 0.0f to 1.0f.
	 * @see #setBackgroundImageAlpha
	 */
	public float getBackgroundImageAlpha() {
		return imageAlpha;
	}


/*****************************************************************************/ 


	/**
	 * Returns the full path to the file containing the current background
	 * image.
	 *
	 * @return The path, or <code>null</code> if the current background is a
	 *         color.
	 * @see #setBackgroundImageFileName
	 */
	public String getBackgroundImageFileName() {
		return backgroundImageFileName;
	}


/*****************************************************************************/ 


	/**
	 * Returns the <code>Object</code> representing the background for all
	 * documents in this tabbed pane; either a <code>java.awt.Color</code> or a
	 * <code>java.lang.String</code>.
	 */
	public Object getBackgroundObject() {
		return backgroundObject;
	}


/*****************************************************************************/


	/**
	 * Returns the blink rate for all text areas.
	 *
	 * @return The blink rate.
	 * @see #setCaretBlinkRate
	 */
	public int getCaretBlinkRate() {
		return caretBlinkRate;
	}


/*****************************************************************************/


	/**
	 * Returns the caret style for either the insert or overwrite caret.
	 *
	 * @param mode Either <code>RTextArea.INSERT_CARET</code> or
	 *             <code>RTextArea.OVERWRITE_CARET</code>.
	 * @return The style of that caret, such as
	 *        <code>ConfigurableCaret.VERTICAL_LINE_STYLE</code>.
	 * @see #setCaretStyle
	 * @see org.fife.ui.rtextarea.ConfigurableCaret
	 */
	public int getCaretStyle(int mode) {
		return carets[mode];
	}


/*****************************************************************************/


	/**
	 * Returns the name and path of the "default file;" that is, the file that
	 * is created when the user selects "New".
	 *
	 * @return The new, empty file's name.
	 */
	private final String getDefaultFileName() {
		return owner.getWorkingDirectory() +
			System.getProperty("file.separator") + owner.getNewFileName();
	}


/*****************************************************************************/


	/**
	 * Returns the background color used in bracket matching.
	 *
	 * @return The background color used when highlighting a bracket.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -