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

📄 rtextareaoptionpanel.java

📁 具有不同语法高亮的编辑器实例
💻 JAVA
📖 第 1 页 / 共 3 页
字号:

	/**
	 * Sets the name of the file containing the background image.  If the
	 * initial background object is a color, you should pass <code>null</code>
	 * to this method.
	 *
	 * @param name The name of the file containing the background image.
	 * @see #getBackgroundImageFileName
	 * @see #setBackgroundObject
	 */
	public void setBackgroundImageFileName(String name) {
		bgImageFileName = name;
		if (bgImageFileName!=null)
			backgroundField.setText(bgImageFileName);
	}


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


	/**
	 * Sets the background object displayed in this options panel.
	 *
	 * @param background The background object.
	 * @see #getBackgroundObject
	 */
	public void setBackgroundObject(Object background) {
		if (background instanceof Color) {
			String s = background.toString();
			backgroundField.setText(s.substring(s.indexOf('[')));
		}
		else if (background instanceof Image) {
			// backgroundField taken care of by setBackgroundImageFileName.
		}
		else {
			throw new IllegalArgumentException("Background must be either " +
				"a Color or an Image");
		}
		this.background = background;
	}


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


	/**
	 * Sets the blink rate displayed.
	 *
	 * @param blinkRate The blink rate to display.
	 * @see #getBlinkRate
	 */
	public void setBlinkRate(int blinkRate) {
		blinkRateSpinner.setValue(new Integer(blinkRate));
	}


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


	/**
	 * Sets the caret color displayed in this panel.
	 *
	 * @param color The caret color to display.  If <code>null</code> is
	 *              passed in, <code>Color.BLACK</code> is used.
	 * @see #getCaretColor
	 */
	public void setCaretColor(final Color color) {
		if (color==null)
			generalTableModel.setValueAt(Color.BLACK, 0,1);
		else
			generalTableModel.setValueAt(color, 0,1);
	}


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


	/**
	 * Sets the caret style for either the insert or overwrite caret, as
	 * displayed in this option panel.
	 *
	 * @param mode Either <code>RTextArea.INSERT_CARET</code> or
	 *             <code>RTextArea.OVERWRITE_CARET</code>.
	 * @param style The style for the specified caret, such as
	 *              <code>ConfigurableCaret.VERTICAL_LINE_STYLE</code>.
	 * @see #getCaretStyle
	 */
	public void setCaretStyle(int mode, int style) {
		switch (mode) {
			case RTextArea.INSERT_CARET:
				insCaretCombo.setSelectedIndex(style);
				break;
			case RTextArea.OVERWRITE_CARET:
				overCaretCombo.setSelectedIndex(style);
				break;
			default:
				throw new IllegalArgumentException("mode must be " +
					RTextArea.INSERT_CARET + " or " +
					RTextArea.OVERWRITE_CARET);
		}
	}


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


	/**
	 * Sets the current line highlight color displayed by this dialog.
	 *
	 * @param color The color to display for the current line highlight color.
	 *        If this parameter is <code>null</code>, <code>Color.BLACK</code>
	 *        is used (??).
	 * @see #getCurrentLineHighlightColor
	 */
	public void setCurrentLineHighlightColor(Color color) {
		hclColorButton.setColor(color);
	}


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


	/**
	 * Sets whether or not the current line highlight color checkbox is
	 * selected.
	 *
	 * @param selected Whether or not the checkbox is selected.
	 * @see #isCurrentLineHighlightCheckboxSelected
	 */
	public void setCurrentLineHighlightCheckboxSelected(boolean selected) {
		highlightCurrentLineCheckBox.setSelected(selected);
		hclColorButton.setEnabled(selected);
	}


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


	/**
	 * Sets the status of the "emulate tabs with whitespace" check box.
	 *
	 * @param areEmulated Whether or not the check box is checked.
	 */
	public void setEmulateTabs(boolean areEmulated) {
		emulateTabsCheckBox.setSelected(areEmulated);
	}


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


	/**
	 * Sets the text for the "emulate tabs with whitespace" checkbox.
	 *
	 * @param text The new text for the "emulate tabs" checkbox.
	 */
	public void setEmulateTabsCheckBoxText(String text) {
		emulateTabsCheckBox.setText(text);
	}


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


	/**
	 * Sets the title of the border around the "General" stuff.
	 *
	 * @param title The new title.
	 */
	public void setGeneralPanelBorderTitle(String title) {
		generalPanel.setBorder(BorderFactory.createCompoundBorder(
						BorderFactory.createEmptyBorder(0,0,5,0),
						new OptionPanelBorder(title)));
	}


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


	/**
	 * Sets the column header text for the two columns in the "General" table.
	 *
	 * @param propertyHeader The header for the first column.
	 * @param colorHeader The header for the second column.
	 */
	public void setGeneralTableHeaderNames(String propertyHeader,
									String colorHeader) {
		generalTableModel.setColumnNames(propertyHeader, colorHeader);
	}


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


	/**
	 * Sets the label used for the "Highlight current line" checkbox.
	 *
	 * @param text The new label for the checkbox.
	 * @see #getHighlightCurrentLineCheckBoxText
	 */
	public void setHighlightCurrentLineCheckBoxText(String text) {
		highlightCurrentLineCheckBox.setText(text);
	}


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


	/**
	 * Sets the text associated with the "Margin line" checkbox.
	 *
	 * @param text The new text for the checkbox.
	 * @see #getMarginLineCheckboxText
	 */
	public void setMarginLineCheckboxText(String text) {
		marginLineCheckBox.setText(text);
	}


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


	/**
	 * Sets the margin line color displayed by this dialog.
	 *
	 * @param color The color to display for the margin line color.
	 * @see #getMarginLineColor
	 */
	public void setMarginLineColor(Color color) {
		marginLineColorButton.setColor(color);
	}


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


	/**
	 * Sets the label associated with the margin line's color.
	 *
	 * @param text The new text for the label.
	 * @see #getMarginLineColorLabelText
	 */
	public void setMarginLineColorLabelText(String text) {
		marginLineColorLabel.setText(text);
	}


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


	/**
	 * Sets whether or not the margin line stuff is enabled (i.e.,
	 * whether or not the "Margin line" checkbox is checked).
	 *
	 * @param enabled Whether or not the margin line options should be
	 *                enabled.
	 * @see #isMarginLineEnabled
	 */
	public void setMarginLineEnabled(boolean enabled) {
		marginLineCheckBox.setSelected(enabled);
		marginLinePositionField.setEnabled(enabled);
		marginLineColorButton.setEnabled(enabled);
	}


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


	/**
	 * Returns the margin line position currently being displayed.
	 *
	 * @param position The margin line position to display.
	 * @see #getMarginLinePosition
	 */
	public void setMarginLinePosition(int position) {
		if (marginLinePosition!=position && position>0) {
			marginLinePosition = position;
		}
		// We do this not in the if-condition above because the user could
		// have typed in a bad value, then hit "Cancel" previously, and we
		// need to clear this out.
		marginLinePositionField.setText(Integer.toString(marginLinePosition));
	}


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


	/**
	 * Sets the color selected for "mark all."
	 *
	 * @param color The color to have selected.
	 * @see #getMarkAllHighlightColor
	 */
	public void setMarkAllHighlightColor(Color color) {
		if (color!=null)
			generalTableModel.setValueAt(color, 2,1);
	}


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


	/**
	 * Sets the label on the "Restore Defaults" button.
	 *
	 * @param text The label on the Restore Defaults button.
	 * @see #getRestoreDefaultsButtonText
	 */
	public void setRestoreDefaultsButtonText(String text) {
		restoreDefaultsButton.setText(text);
	}


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


	/**
	 * Sets whether the rounded selection checkbox is selected.
	 *
	 * @param selected Whether the checkbox is selected.
	 * @see #getRoundedSelection
	 */
	public void setRoundedSelection(boolean selected) {
		roundedSelectionCheckBox.setSelected(selected);
	}


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


	/**
	 * Sets the selection color displayed in this panel.
	 *
	 * @param color The selection color to display.  If <code>null</code> is
	 *              passed in, nothing happens.
	 * @see #getSelectionColor
	 */
	public void setSelectionColor(final Color color) {
		if (color!=null)
			generalTableModel.setValueAt(color, 1,1);
	}


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


	/**
	 * Sets the tab size currently being displayed.
	 *
	 * @param tabSize The tab size to display.
	 */
	public void setTabSize(int tabSize) {
		if (this.tabSize!=tabSize && tabSize>0) {
			this.tabSize = tabSize;
		}
		// We do this not in the if-condition above because the user could
		// have typed in a bad value, then hit "Cancel" previously, and we
		// need to clear this out.
		tabSizeField.setText(Integer.toString(tabSize));
	}


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


	/**
	 * Sets the label beside the tab size text field.
	 *
	 * @param text The new label for the "tab size" text field.
	 */
	public void setTabSizeLabelText(String text) {
		tabSizeLabel.setText(text);
	}


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


	/**
	 * Sets whether the word wrap checkbox is checked.
	 *
	 * @param enabled Whether or not to check the word wrap checkbox.
	 * @see #getWordWrap
	 */
	public void setWordWrap(boolean enabled) {
		wordWrapCheckBox.setSelected(enabled);
	}


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


	/**
	 * Called when the user changes the caret blink rate spinner value.
	 *
	 * @param e The change event.
	 */
	public void stateChanged(ChangeEvent e) {
		hasUnsavedChanges = true;
		firePropertyChange(CARET_BLINK_RATE_PROPERTY,
							null, blinkRateSpinner.getValue());
	}


/*****************************************************************************/
/********************* PRIVATE INNER CLASSES *********************************/
/*****************************************************************************/

	/**
	 * Table data for the "General" table.
	 */
	class GeneralTableModel extends AbstractTableModel {

		public String[] columnNames;

		public Object[][] data = {
				{ "Caret",		null },
				{ "Selection", 	null },
				{ "Mark All",		null }
		};

		public GeneralTableModel(String propertyHeader, String colorHeader,
							String caretRow, String selectionRow,
							String markAllRow) {
			super();
			columnNames = new String[2];
			columnNames[0] = propertyHeader;
			columnNames[1] = colorHeader;
			data[0][0] = caretRow;
			data[1][0] = selectionRow;
			data[2][0] = markAllRow;
		}

		public Class getColumnClass(int columnIndex) {
			return data[0][columnIndex].getClass();
		}

		public int getColumnCount() {
			return columnNames.length;
		}

		public String getColumnName(int column) {
			return columnNames[column];
		}

		public int getRowCount() {
			return data.length;
		}

		public Object getValueAt(int row, int column) {
			return data[row][column];
		}

		public boolean isCellEditable(int row, int column) {
			return(column==1); // Only the colors are editable.
		}

		public void setColumnNames(String propertyHeader, String colorHeader) {
			columnNames[0] = propertyHeader;
			columnNames[1] = colorHeader;
			fireTableStructureChanged();
		}

		public void setValueAt(Object value, int row, int column) {
			hasUnsavedChanges = true;
			firePropertyChange(GENERAL_COLOR_PROPERTY,
							data[row][column], value);
			data[row][column] = value;
			fireTableCellUpdated(row, column);
		}

	}


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

}

⌨️ 快捷键说明

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