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

📄 rtextpreferences.java~3~

📁 具有不同语法高亮的编辑器实例
💻 JAVA~3~
📖 第 1 页 / 共 2 页
字号:
			props.dividerLocations[RText.TOP]	= prefs.getInt("pluginDividerLocation.top", props.dividerLocations[RText.TOP]);
			props.dividerLocations[RText.LEFT] = prefs.getInt("pluginDividerLocation.left", props.dividerLocations[RText.LEFT]);
			props.dividerLocations[RText.BOTTOM] = prefs.getInt("pluginDividerLocation.bottom", props.dividerLocations[RText.BOTTOM]);
			props.dividerLocations[RText.RIGHT]= prefs.getInt("pluginDividerLocation.right", props.dividerLocations[RText.RIGHT]);

			// Get all properties associated with the MainPanel class.
			prefs = Preferences.userNodeForPackage(AbstractMainView.class);
			props.bracketMatchingEnabled		= prefs.getBoolean("bracketMatchingEnabled", props.bracketMatchingEnabled);
			props.currentLineHighlightEnabled	= prefs.getBoolean("currentLineHighlightEnabled", props.currentLineHighlightEnabled);
			props.emulateTabsWithSpaces		= prefs.getBoolean("emulateTabs", props.emulateTabsWithSpaces);
			props.highlightModifiedDocNames	= prefs.getBoolean("highlightModifiedDocNames", props.highlightModifiedDocNames);
			props.imageAlpha				= prefs.getFloat("imageAlpha", props.imageAlpha);
			props.marginLineEnabled			= prefs.getBoolean("marginLineEnabled", props.marginLineEnabled);
			props.marginLinePosition			= prefs.getInt("marginLinePosition", props.marginLinePosition);
			props.syntaxFiltersString		= prefs.get("syntaxFilters", props.syntaxFiltersString);
			props.textMode					= prefs.getInt("textMode", props.textMode);
			props.tabPlacement				= prefs.getInt("tabPlacement", props.tabPlacement);
			props.wordWrap					= prefs.getBoolean("wordWrap", props.wordWrap);
			temp						= prefs.get("printFont", null);
			if (temp!=null) {
				StringTokenizer t2 = new StringTokenizer(temp, ",");
				String fontName = t2.nextToken();
				if (fontName.equals("null"))
					props.printFont = null;
				else {
					int fontSize = Integer.parseInt(t2.nextToken());
					boolean isBold = Boolean.valueOf(t2.nextToken()).booleanValue();
					boolean isItalic = Boolean.valueOf(t2.nextToken()).booleanValue();
					int fontStyle = Font.PLAIN;
					if (isBold) {
						if (isItalic)
							fontStyle = Font.BOLD | Font.ITALIC;
						else
							fontStyle = Font.BOLD;
					}
					else if (isItalic)
						fontStyle = Font.ITALIC;
					props.printFont = new Font(fontName, fontStyle, fontSize);
				}
			}
			temp						= prefs.get("backgroundObject", null);
			if (temp!=null) {
				StringTokenizer t2 = new StringTokenizer(temp, ",");
				String temp2 = t2.nextToken();
				if (temp2.equals("color"))
					props.backgroundObject = RUtilities.getColorFromPacked(
						Integer.parseInt(temp.substring(temp.indexOf(',')+1)));
				else if (temp2.equals("image"))
					props.backgroundObject = t2.nextToken();
				else
					props.backgroundObject = Color.WHITE;
			}
			props.caretColor = RUtilities.getColorFromPacked(
				prefs.getInt("caretColor", RUtilities.getPackedColor(props.caretColor)));
			props.selectionColor = RUtilities.getColorFromPacked(
				prefs.getInt("selectionColor", RUtilities.getPackedColor(props.selectionColor)));
			props.currentLineHighlightColor = RUtilities.getColorFromPacked(
				prefs.getInt("currentLineHighlightColor", RUtilities.getPackedColor(props.currentLineHighlightColor)));
			props.modifiedDocumentNamesColor = RUtilities.getColorFromPacked(
				prefs.getInt("modifiedDocumentNamesColor", RUtilities.getPackedColor(props.modifiedDocumentNamesColor)));
			props.matchedBracketBGColor = RUtilities.getColorFromPacked(
				prefs.getInt("matchedBracketBGColor", RUtilities.getPackedColor(props.matchedBracketBGColor)));
			props.matchedBracketBorderColor = RUtilities.getColorFromPacked(
				prefs.getInt("matchedBracketBorderColor", RUtilities.getPackedColor(props.matchedBracketBorderColor)));
			props.marginLineColor = RUtilities.getColorFromPacked(
				prefs.getInt("marginLineColor", RUtilities.getPackedColor(props.marginLineColor)));
			props.visibleWhitespace			= prefs.getBoolean("visibleWhitespace", props.visibleWhitespace);
			props.smoothTextEnabled			= prefs.getBoolean("smoothText", props.smoothTextEnabled);
			props.fractionalMetricsEnabled	= prefs.getBoolean("fractionalMetrics", props.fractionalMetricsEnabled);
			props.markAllHighlightColor = RUtilities.getColorFromPacked(
				prefs.getInt("markAllHighlightColor", RUtilities.getPackedColor(props.markAllHighlightColor)));
			props.roundedSelectionEdges	= prefs.getBoolean("roundedSelectionEdges", props.roundedSelectionEdges);
			props.carets[RTextArea.INSERT_MODE]= prefs.getInt("insertCaretStyle", props.carets[RTextArea.INSERT_MODE]);
			props.carets[RTextArea.OVERWRITE_MODE]= prefs.getInt("overwriteCaretStyle", props.carets[RTextArea.OVERWRITE_MODE]);
			props.caretBlinkRate		= prefs.getInt("caretBlinkRate", props.caretBlinkRate);

			// Get all properties associated with the RTextMenuBar class.
			prefs = Preferences.userNodeForPackage(RTextMenuBar.class);
			props.fileHistoryString		= prefs.get("fileHistoryString", props.fileHistoryString);
			props.maxFileHistorySize		= prefs.getInt("maxFileHistorySize", props.maxFileHistorySize);

			// Get the accelerators for all RText actions.
			for (int i=0; i<RText.actionNames.length; i++) {
				String actionName = RText.actionNames[i];
				temp = prefs.get(actionName, null);
				if (temp!=null)
					props.accelerators.put(actionName,
								getKeyStrokeFromString(temp));
			}

			// Get the accelerators for all AbstractMainView actions.
			for (int i=0; i<AbstractMainView.NUM_ACTIONS; i++) {
				temp = prefs.get(mainViewAcceleratorKeys[i], null);
				if (temp!=null)
					props.mainViewActionAccelerators[i] = getKeyStrokeFromString(temp);
			}


		// If anything at all goes wrong, just use default property values.
		} catch (Exception e) {
			e.printStackTrace();
			props.setDefaults();
		}

		return props;

	}


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


	/**
	 * Saves this preferences instance via the Java Preferences API.
	 *
	 * @param rtext The rtext instance for which you are saving preferences.
	 */
	public void savePreferences(Object rtext) {

		// Save all properties related to the RText class.
		Preferences prefs = Preferences.userNodeForPackage(RText.class);
		saveCommonPreferences(prefs);
		prefs.put("colorScheme",						colorScheme.toCommaSeparatedString());
		prefs.put("iconGroupName",					iconGroupName);
		prefs.putBoolean("lineNumbersVisible",			lineNumbersVisible);
		prefs.putInt("mainView",						mainView);
		prefs.putInt("statusBarStyle",				statusBarStyle);
		prefs.put("workingDirectory",				workingDirectory);
		prefs.putBoolean("searchToolBarVisible",		searchToolBarVisible);
		prefs.putInt("pluginDividerLocation.top",		dividerLocations[RText.TOP]);
		prefs.putInt("pluginDividerLocation.left",		dividerLocations[RText.LEFT]);
		prefs.putInt("pluginDividerLocation.bottom",		dividerLocations[RText.BOTTOM]);
		prefs.putInt("pluginDividerLocation.right",		dividerLocations[RText.RIGHT]);

		// Save all properties related to the AbstractMainView class.
		prefs = Preferences.userNodeForPackage(AbstractMainView.class);
		prefs.putBoolean("bracketMatchingEnabled",		bracketMatchingEnabled);
		prefs.putInt("caretColor",				RUtilities.getPackedColor(caretColor));
		prefs.putInt("currentLineHighlightColor",	RUtilities.getPackedColor(currentLineHighlightColor));
		prefs.putBoolean("currentLineHighlightEnabled",	currentLineHighlightEnabled);
		prefs.putBoolean("emulateTabs",				emulateTabsWithSpaces);
		prefs.putBoolean("highlightModifiedDocNames",highlightModifiedDocNames);
		prefs.putFloat("imageAlpha",					imageAlpha);
		prefs.putInt("marginLineColor",				RUtilities.getPackedColor(marginLineColor));
		prefs.putBoolean("marginLineEnabled",			marginLineEnabled);
		prefs.putInt("marginLinePosition",				marginLinePosition);
		prefs.putInt("matchedBracketBGColor",		RUtilities.getPackedColor(matchedBracketBGColor));
		prefs.putInt("matchedBracketBorderColor",		RUtilities.getPackedColor(matchedBracketBorderColor));
		prefs.putInt("modifiedDocumentNamesColor",	RUtilities.getPackedColor(modifiedDocumentNamesColor));
		prefs.put("printFont",						printFont==null ? "null" : printFont.getFontName() + ","
													+ printFont.getSize() + "," + printFont.isBold() +
													"," + printFont.isItalic());
		prefs.putInt("selectionColor",				RUtilities.getPackedColor(selectionColor));
		prefs.put("syntaxFilters",					syntaxFiltersString);
		prefs.putInt("tabSize",						tabSize);
		prefs.putInt("tabPlacement",					tabPlacement);
		prefs.putInt("textMode",						textMode);
		prefs.putBoolean("wordWrap",					wordWrap);
		if (backgroundObject instanceof Color) {
			Color c = (Color)backgroundObject;
			prefs.put("backgroundObject",				"color," + RUtilities.getPackedColor(c));
		}
		else if (backgroundObject instanceof Image) {
			prefs.put("backgroundObject",				"image," + ((RText)rtext).getMainView().getBackgroundImageFileName());
		}
		prefs.putBoolean("visibleWhitespace",			visibleWhitespace);
		prefs.putBoolean("smoothText",				smoothTextEnabled);
		prefs.putBoolean("fractionalMetrics",			fractionalMetricsEnabled);
		prefs.putInt("markAllHighlightColor",			RUtilities.getPackedColor(markAllHighlightColor));
		prefs.putBoolean("roundedSelectionEdges",		roundedSelectionEdges);
		prefs.putInt("insertCaretStyle",				carets[RTextArea.INSERT_MODE]);
		prefs.putInt("overwriteCaretStyle",			carets[RTextArea.OVERWRITE_MODE]);
		prefs.putInt("caretBlinkRate",				caretBlinkRate);

		// Save all properties related to the RTextMenuBar class.
		prefs = Preferences.userNodeForPackage(RTextMenuBar.class);
		prefs.put("fileHistoryString",				(fileHistoryString==null ? "-" : fileHistoryString));
		prefs.putInt("maxFileHistorySize",				maxFileHistorySize);


		// Save all accelerators from RText.
		for (int i=0; i<RText.actionNames.length; i++) {
			String actionName = RText.actionNames[i];
			prefs.put(actionName,
				getKeyStrokeString(getAccelerator(actionName)));
		}


		// Save all accelerators from the AbstractMainView.
		for (int i=0; i<AbstractMainView.NUM_ACTIONS; i++) {
			prefs.put(mainViewAcceleratorKeys[i],
					getKeyStrokeString(mainViewActionAccelerators[i]));
		}


		//prefs.flush();
		prefs = null;

	}


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


	/**
	 * Sets this preferences instance to contain all default values.
	 */
	protected void setDefaults() {
		location = new Point(0,0);
		size = new Dimension(650,500);
		lookAndFeel = UIManager.getSystemLookAndFeelClassName(); //1.5.2004/pwy: use the system default
		iconGroupName = IconGroupLoader.DEFAULT_ICON_GROUP_NAME;
		toolbarVisible = true;
		statusBarVisible = true;
		lineNumbersVisible = false;
		tabSize = 5;
		emulateTabsWithSpaces = false;
		textMode = RTextArea.INSERT_MODE;
		tabPlacement = JTabbedPane.TOP;
		printFont = null;	// i.e., use RText's font.
		backgroundObject = Color.WHITE;
		imageAlpha = 0.3f;	// Arbitrary initial value.
		wordWrap = false;
		caretColor = Color.BLACK;
		selectionColor = new Color(200,200,255);
		colorScheme = new SyntaxHighlightingColorScheme(true);
		SyntaxFilters syntaxFilters = new SyntaxFilters();
		syntaxFilters.restoreDefaultFileFilters();
		syntaxFiltersString = syntaxFilters.toString();
		maxFileHistorySize = 5;
		fileHistoryString = null;
		currentLineHighlightEnabled = true;
		currentLineHighlightColor = RTextArea.getDefaultCurrentLineHighlightColor();
		mainView = RText.TABBED_VIEW;
		highlightModifiedDocNames = true;
		modifiedDocumentNamesColor = Color.RED;
		language = "en";	// Default to English.
		bracketMatchingEnabled = true;
		matchedBracketBGColor = RSyntaxTextArea.getDefaultBracketMatchBGColor();
		matchedBracketBorderColor = RSyntaxTextArea.getDefaultBracketMatchBorderColor();
		marginLineEnabled = true;
		marginLinePosition = RTextArea.getDefaultMarginLinePosition();
		marginLineColor = RTextArea.getDefaultMarginLineColor();
		visibleWhitespace = false;
		smoothTextEnabled = false;
		fractionalMetricsEnabled = false;
		markAllHighlightColor = RTextArea.getDefaultMarkAllHighlightColor();
		statusBarStyle = StatusBar.WINDOWS_XP_STYLE;
		roundedSelectionEdges = false;
		workingDirectory = System.getProperty("user.dir");
		carets = new int[2];
		carets[RTextArea.INSERT_MODE] = ConfigurableCaret.VERTICAL_LINE_STYLE;
		carets[RTextArea.OVERWRITE_MODE] = ConfigurableCaret.BLOCK_STYLE;
		caretBlinkRate	= 500;
		searchToolBarVisible = false;
		dividerLocations = new int[4];
		for (int i=0; i<4; i++)
			dividerLocations[i] = -1; // negative => left components preferred size.

		accelerators = new HashMap();
		for (int i=0; i<RText.actionNames.length; i++) {
			String actionName = RText.actionNames[i];
			accelerators.put(actionName, defaultActionAccelerators[i]);
		}

		mainViewActionAccelerators = new KeyStroke[AbstractMainView.NUM_ACTIONS];
		for (int i=0; i<AbstractMainView.NUM_ACTIONS; i++) {
			mainViewActionAccelerators[i] = defaultMainViewActionAccelerators[i];
		}

	}


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


	/**
	 * Returns a <code>String</code> containing the value of all members of
	 * this object.
	 */
	public String toString() {
		return "[Class: RTextPreferences]";
	}


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

}

⌨️ 快捷键说明

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