📄 rtextareaoptionpanel.java
字号:
hasUnsavedChanges = true;
firePropertyChange(ROUNDED_SELECTION_PROPERTY, !selected, selected);
}
}
/*****************************************************************************/
/**
* This doesn't get called but is here because this class implements
* <code>DocumentListener</code>.
*/
public void changedUpdate(DocumentEvent e) {
}
/*****************************************************************************/
/**
* Creates a combo box with caret choices.
*
* @param msg The resource bundle with localized caret string values.
*/
private static final JComboBox createCaretComboBox(
ResourceBundle msg) {
JComboBox combo = new JComboBox();
combo.addItem(msg.getString("CaretVerticalLine"));
combo.addItem(msg.getString("CaretUnderline"));
combo.addItem(msg.getString("CaretBlock"));
combo.addItem(msg.getString("CaretRectangle"));
return combo;
}
/*****************************************************************************/
/**
* Called when a text field in this panel gets updated.
*/
private void doDocumentUpdated(DocumentEvent e) {
hasUnsavedChanges = true;
Document modifiedDocument = e.getDocument();
if (modifiedDocument==tabSizeField.getDocument()) {
firePropertyChange(TAB_SIZE_PROPERTY,
null, tabSizeField.getText());
}
else if (modifiedDocument==marginLinePositionField.getDocument()) {
firePropertyChange(MARGIN_LINE_POS_PROPERTY,
null, marginLinePositionField.getText());
}
}
/*****************************************************************************/
/**
* Checks whether or not all input the user specified on this panel is
* valid. This should be overridden to check, for example, whether
* text fields have valid values, etc. This method will be called
* whenever the user clicks "OK" or "Apply" on the options dialog to
* ensure all input is valid. If it isn't, the component with invalid
* data will be given focus and the user will be prompted to fix it.<br>
*
*
* @return <code>null</code> if the panel has all valid inputs, or an
* <code>OptionsPanelCheckResult</code> if an input was invalid.
* This component is the one that had the error and will be
* given focus, and the string is an error message that will be
* displayed.
*/
public OptionsPanelCheckResult ensureValidInputs() {
// Ensure the tab size specified is valid.
int temp = 0;
try {
temp = Integer.parseInt(tabSizeField.getText());
if (temp<0) throw new NumberFormatException();
} catch (NumberFormatException nfe) {
OptionsPanelCheckResult result = new OptionsPanelCheckResult();
result.errorMessage = "Invalid number format for tab size;\nPlease input a tab size greater than zero.";
result.component = tabSizeField;
// Hack; without this, tabSize is still valid, so if they hit Cancel
// then brought the Options dialog back up, the invalid text would
// still be there.
tabSize = -1;
return result;
}
tabSize = temp; // Store the value the user will get.
// Ensure the margin line position specified is valid.
try {
temp = Integer.parseInt(marginLinePositionField.getText());
if (temp<0) throw new NumberFormatException();
} catch (NumberFormatException nfe) {
OptionsPanelCheckResult result = new OptionsPanelCheckResult();
result.errorMessage = "Invalid margin line position;\nPlease input a position greater than zero.";
result.component = marginLinePositionField;
// Hack; without this, marginLinePosition is still valid, so if
// they hig Cancel then brought the Options dialog back up, the
// invalid text would still be there.
marginLinePosition = -1;
return result;
}
marginLinePosition = temp; // Store the value the user will get.
// If that went okay then the entire panel is okay.
return null;
}
/*****************************************************************************/
/**
* Returns the name of the file containing the chosen background image.
* If the user selected a color for the background, this method returns
* <code>null</code>.
*
* @return The name of the file containing the chosen background image.
* @see #getBackgroundObject
* @see #setBackgroundImageFileName
*/
public String getBackgroundImageFileName() {
return bgImageFileName;
}
/*****************************************************************************/
/**
* Returns the background object (a color or an image) selected by the
* user.
*
* @return The background object.
* @see #getBackgroundImageFileName
* @see #setBackgroundObject
*/
public Object getBackgroundObject() {
return background;
}
/*****************************************************************************/
/**
* Returns the blink rate selected by the user.
*
* @return The blink rate.
* @see #setBlinkRate
*/
public int getBlinkRate() {
return ((Integer)blinkRateSpinner.getValue()).intValue();
}
/*****************************************************************************/
/**
* Returns the color the user chose for the caret.
*
* @return The caret color the user chose.
* @see #setCaretColor
*/
public Color getCaretColor() {
return (Color)generalTableModel.getValueAt(0,1);
}
/*****************************************************************************/
/**
* Returns the caret style for either the insert or overwrite caret
* that the user chose.
*
* @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) {
if (mode==RTextArea.INSERT_CARET)
return insCaretCombo.getSelectedIndex();
else // OVERWRITE_CARET
return overCaretCombo.getSelectedIndex();
}
/*****************************************************************************/
/**
* Returns the current line highlight color chosen by the user.
*
* @return The color.
* @see #setCurrentLineHighlightColor
*/
public Color getCurrentLineHighlightColor() {
return hclColorButton.getColor();
}
/*****************************************************************************/
/**
* Returns whether or not the user decided to emulate tabs.
*
* @return <code>true</code> iff the "emulate tabs with whitespace"
* checkbox was checked.
*/
public boolean getEmulateTabs() {
return emulateTabsCheckBox.isSelected();
}
/*****************************************************************************/
/**
* Returns the label used for the "Highlight current line" checkbox.
*
* @return The label used for the checkbox.
* @see #setHighlightCurrentLineCheckBoxText
*/
public final String getHighlightCurrentLineCheckBoxText() {
return highlightCurrentLineCheckBox.getText();
}
/*****************************************************************************/
/**
* Returns the "margin line" checkbox's text.
*
* @return The checkbox's text.
* @see #setMarginLineCheckboxText
*/
public String getMarginLineCheckboxText() {
return marginLineCheckBox.getText();
}
/*****************************************************************************/
/**
* Returns the color the user chose for the margin line.
*
* @return The color the user chose.
* @see #setMarginLineColor
*/
public Color getMarginLineColor() {
return marginLineColorButton.getColor();
}
/*****************************************************************************/
/**
* Returns the text label associated with the "Margin line"'s color button.
*
* @return The text of the label.
* @see #setMarginLineColorLabelText
*/
public String getMarginLineColorLabelText() {
return marginLineColorLabel.getText();
}
/*****************************************************************************/
/**
* Returns the margin line position text on this panel.
*
* @return The text in the "margin line position" text field.
* @see #setMarginLinePosition
*/
public int getMarginLinePosition() {
return marginLinePosition;
}
/*****************************************************************************/
/**
* Returns the color selected by the user for "mark all."
*
* @return The color.
* @see #setMarkAllHighlightColor
*/
public Color getMarkAllHighlightColor() {
return (Color)generalTableModel.getValueAt(2,1);
}
/*****************************************************************************/
/**
* Returns the label on the "Restore Defaults" button.
*
* @return The label on the Restore Defaults button.
* @see #setRestoreDefaultsButtonText
*/
public final String getRestoreDefaultsButtonText() {
return restoreDefaultsButton.getText();
}
/*****************************************************************************/
/**
* Returns whether the user selected to use rounded edges on selections.
*
* @return Whether rounded selection edges were selected.
* @see #setRoundedSelection
*/
public boolean getRoundedSelection() {
return roundedSelectionCheckBox.isSelected();
}
/*****************************************************************************/
/**
* Returns the color the user chose for selections.
*
* @return The selection color the user chose.
* @see #setSelectionColor
*/
public Color getSelectionColor() {
return (Color)generalTableModel.getValueAt(1,1);
}
/*****************************************************************************/
/**
* Returns the tab size selected by the user.
*
* @return The tab size selected by the user.
*/
public int getTabSize() {
return tabSize;
}
/*****************************************************************************/
/**
* Returns the <code>JComponent</code> at the "top" of this Options
* panel. This is the component that will receive focus if the user
* switches to this Options panel in the Options dialog. As an added
* bonus, if this component is a <code>JTextComponent</code>, its
* text is selected for easy changing.
*/
public JComponent getTopJComponent() {
return generalTable;
}
/*****************************************************************************/
/**
* Returns whether the user selected word wrap.
*
* @return Whether or not the word wrap checkbox is checked.
* @see #setWordWrap
*/
public boolean getWordWrap() {
return wordWrapCheckBox.isSelected();
}
/*****************************************************************************/
/**
* Called when a text field in this panel gets updated.
*/
public void insertUpdate(DocumentEvent e) {
doDocumentUpdated(e);
}
/*****************************************************************************/
/**
* Returns whether or not the current line highlight color checkbox is
* selected.
*
* @return Whether or not the checkbox is selected.
* @see #setCurrentLineHighlightCheckboxSelected
*/
public boolean isCurrentLineHighlightCheckboxSelected() {
return highlightCurrentLineCheckBox.isSelected();
}
/*****************************************************************************/
/**
* Returns whether or not the margin line stuff is enabled (i.e.,
* whether or not the "Margin line" checkbox is checked).
*
* @return Whether or not the margin line options are enabled.
* @see #setMarginLineEnabled
*/
public boolean isMarginLineEnabled() {
return marginLineCheckBox.isSelected();
}
/*****************************************************************************/
/**
* Called when a property changes in an object we're listening to.
*/
public void propertyChange(PropertyChangeEvent e) {
Object source = e.getSource();
// We need to forward this on to the options dialog, whatever it is,
// so that the "Apply" button gets updated.
if (source==hclColorButton) {
hasUnsavedChanges = true;
firePropertyChange(HCLC_PROPERTY,
e.getOldValue(), e.getNewValue());
}
else {
hasUnsavedChanges = true;
firePropertyChange(UNKNOWN_PROPERTY,
e.getOldValue(), e.getNewValue());
}
}
/*****************************************************************************/
/**
* Called when a text field in this panel gets updated.
*/
public void removeUpdate(DocumentEvent e) {
doDocumentUpdated(e);
}
/*****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -