📄 rtarootview.java~1~
字号:
/*****************************************************************************/
/**
* Returns the number of views in this view. Since
* this view simply wraps the root of the view hierarchy
* it has exactly one child.
*
* @return the number of views
* @see #getView
*/
public int getViewCount() {
return 1;
}
/*****************************************************************************/
/**
* Fetches the factory to be used for building the
* various view fragments that make up the view that
* represents the model. This is what determines
* how the model will be represented. This is implemented
* to fetch the factory provided by the associated
* EditorKit unless that is null, in which case this
* simply returns the BasicTextUI itself which allows
* subclasses to implement a simple factory directly without
* creating extra objects.
*
* @return the factory
*/
public ViewFactory getViewFactory() {
EditorKit kit = ui.getEditorKit(editor);
ViewFactory f = kit.getViewFactory();
if (f != null) {
return f;
}
return ui;
}
/*****************************************************************************/
/**
* Returns the child view index representing the given position in
* the model. This is implemented to return the index of the only
* child.
*
* @param pos the position >= 0
* @return index of the view representing the given position, or
* -1 if no view represents that position
* @since 1.3
*/
public int getViewIndex(int pos, Position.Bias b) {
return 0;
}
/*****************************************************************************/
/**
* Gives notification that something was inserted into the document
* in a location that this view is responsible for.
*
* @param e the change information from the associated document
* @param a the current allocation of the view
*/
public void insertUpdate(DocumentEvent e, Shape a) {
if (view != null)
view.insertUpdate(e, a, getViewFactory());
}
/*****************************************************************************/
/**
* Provides a mapping from the document model coordinate space
* to the coordinate space of the view mapped to it.
*
* @param pos the position to convert
* @param a the allocated region to render into
* @return the bounding box of the given position
*/
public Shape modelToView(int pos, Shape a, Position.Bias b)
throws BadLocationException {
if (view != null) {
return view.modelToView(pos, a, b);
}
return null;
}
/*****************************************************************************/
/**
* Provides a mapping from the document model coordinate space
* to the coordinate space of the view mapped to it.
*
* @param p0 the position to convert >= 0
* @param b0 the bias toward the previous character or the
* next character represented by p0, in case the
* position is a boundary of two views.
* @param p1 the position to convert >= 0
* @param b1 the bias toward the previous character or the
* next character represented by p1, in case the
* position is a boundary of two views.
* @param a the allocated region to render into
* @return the bounding box of the given position is returned
* @exception BadLocationException if the given position does
* not represent a valid location in the associated document
* @exception IllegalArgumentException for an invalid bias argument
* @see View#viewToModel
*/
public Shape modelToView(int p0, Position.Bias b0,
int p1, Position.Bias b1,
Shape a) throws BadLocationException {
if (view != null)
return view.modelToView(p0, b0, p1, b1, a);
return null;
}
/*****************************************************************************/
/**
* Renders the view.
*
* @param g the graphics context
* @param allocation the region to render into
*/
public void paint(Graphics g, Shape allocation) {
if (view != null) {
Rectangle alloc = (allocation instanceof Rectangle) ?
(Rectangle)allocation : allocation.getBounds();
setSize(alloc.width, alloc.height);
view.paint(g, allocation);
}
}
/*****************************************************************************/
/**
* Specifies that a preference has changed.
* Child views can call this on the parent to indicate that
* the preference has changed. The root view routes this to
* invalidate on the hosting component.
* <p>
* This can be called on a different thread from the
* event dispatching thread and is basically unsafe to
* propagate into the component. To make this safe,
* the operation is transferred over to the event dispatching
* thread for completion. It is a design goal that all view
* methods be safe to call without concern for concurrency,
* and this behavior helps make that true.
*
* @param child the child view
* @param width true if the width preference has changed
* @param height true if the height preference has changed
*/
public void preferenceChanged(View child, boolean width, boolean height) {
editor.revalidate();
}
/*****************************************************************************/
/**
* Gives notification that something was removed from the document
* in a location that this view is responsible for.
*
* @param e the change information from the associated document
* @param a the current allocation of the view
*/
public void removeUpdate(DocumentEvent e, Shape a) {
if (view != null) {
view.removeUpdate(e, a, getViewFactory());
}
}
/*****************************************************************************/
/**
* Sets the view parent.
*
* @param parent the parent view
*/
public void setParent(View parent) {
throw new Error("Can't set parent on root view");
}
/*****************************************************************************/
/**
* Sets the view that this view displays.
*
* @param v The view.
*/
void setView(View v) {
View oldView = view;
view = null;
if (oldView != null) {
// get rid of back reference so that the old
// hierarchy can be garbage collected.
oldView.setParent(null);
}
if (v != null) {
v.setParent(this);
}
view = v;
}
/*****************************************************************************/
/**
* Provides a mapping from the view coordinate space to the logical
* coordinate space of the model.
*
* @param x x coordinate of the view location to convert
* @param y y coordinate of the view location to convert
* @param a the allocated region to render into
* @return the location within the model that best represents the
* given point in the view
*/
public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
if (view != null)
return view.viewToModel(x, y, a, bias);
return -1;
}
/*****************************************************************************/
/**
* Breaks this view on the given axis at the given length.
*
* @param axis may be either X_AXIS or Y_AXIS
* @param len specifies where a break is desired in the span
* @param the current allocation of the view
* @return the fragment of the view that represents the given span
* if the view can be broken, otherwise null
*/
public View breakView(int axis, float len, Shape a) {
throw new Error("Can't break root view");
}
/*****************************************************************************/
/**
* Determines the resizability of the view along the
* given axis. A value of 0 or less is not resizable.
*
* @param axis may be either X_AXIS or Y_AXIS
* @return the weight
*/
public int getResizeWeight(int axis) {
if (view != null) {
return view.getResizeWeight(axis);
}
return 0;
}
/*****************************************************************************/
/**
* Sets the view size.
*
* @param width the width
* @param height the height
*/
public void setSize(float width, float height) {
if (view != null) {
view.setSize(width, height);
}
}
/*****************************************************************************/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -