home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.text;
-
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.border.Border;
- import com.sun.java.swing.plaf.TextUI;
- import com.sun.java.swing.plaf.UIResource;
- import java.awt.Color;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.Shape;
- import java.beans.PropertyChangeEvent;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.Serializable;
-
- public abstract class DefaultTextUI extends TextUI implements ViewFactory, Serializable {
- private static final EditorKit defaultKit = new DefaultEditorKit();
- transient JTextComponent editor;
- transient boolean painted = false;
- transient RootView rootView = new RootView(this);
- transient UpdateHandler updateHandler = new UpdateHandler(this);
-
- protected Caret createCaret() {
- return new DefaultCaret();
- }
-
- protected Highlighter createHighlighter() {
- return new DefaultHighlighter();
- }
-
- protected abstract Keymap createKeymap();
-
- protected void propertyChange(PropertyChangeEvent var1) {
- }
-
- protected abstract String getPropertyPrefix();
-
- protected void installDefaults(JComponent var1) {
- String var2 = this.getPropertyPrefix();
- Font var3 = this.editor.getFont();
- if (var3 == null || var3 instanceof UIResource) {
- this.editor.setFont(UIManager.getFont(var2 + ".font"));
- }
-
- Color var4 = this.editor.getBackground();
- if (var4 == null || var4 instanceof UIResource) {
- this.editor.setBackground(UIManager.getColor(var2 + ".background"));
- }
-
- Color var5 = this.editor.getForeground();
- if (var5 == null || var5 instanceof UIResource) {
- this.editor.setForeground(UIManager.getColor(var2 + ".foreground"));
- }
-
- Color var6 = this.editor.getCaretColor();
- if (var6 == null || var6 instanceof UIResource) {
- this.editor.setCaretColor(UIManager.getColor(var2 + ".caretForeground"));
- }
-
- Color var7 = this.editor.getSelectionColor();
- if (var7 == null || var7 instanceof UIResource) {
- this.editor.setSelectionColor(UIManager.getColor(var2 + ".selectionBackground"));
- }
-
- Color var8 = this.editor.getSelectedTextColor();
- if (var8 == null || var8 instanceof UIResource) {
- this.editor.setSelectedTextColor(UIManager.getColor(var2 + ".selectionForeground"));
- }
-
- Color var9 = this.editor.getDisabledTextColor();
- if (var9 == null || var9 instanceof UIResource) {
- this.editor.setDisabledTextColor(UIManager.getColor(var2 + ".inactiveForeground"));
- }
-
- Border var10 = this.editor.getBorder();
- if (var10 == null || var10 instanceof UIResource) {
- this.editor.setBorder(UIManager.getBorder(var2 + ".border"));
- }
-
- Caret var11 = this.createCaret();
- this.editor.setCaret(var11);
- Object var12 = UIManager.get(var2 + ".caretBlinkRate");
- if (var12 != null && var12 instanceof Integer) {
- Integer var13 = (Integer)var12;
- var11.setBlinkRate(var13);
- }
-
- }
-
- protected void uninstallDefaults(JComponent var1) {
- if (this.editor.getCaretColor() instanceof UIResource) {
- this.editor.setCaretColor((Color)null);
- }
-
- if (this.editor.getSelectionColor() instanceof UIResource) {
- this.editor.setSelectionColor((Color)null);
- }
-
- if (this.editor.getDisabledTextColor() instanceof UIResource) {
- this.editor.setDisabledTextColor((Color)null);
- }
-
- if (this.editor.getSelectedTextColor() instanceof UIResource) {
- this.editor.setSelectedTextColor((Color)null);
- }
-
- if (this.editor.getBorder() instanceof UIResource) {
- this.editor.setBorder((Border)null);
- }
-
- this.editor.setCaret((Caret)null);
- }
-
- protected void installListeners(JComponent var1) {
- }
-
- protected void uninstallListeners(JComponent var1) {
- }
-
- protected void paintBackground(Graphics var1) {
- var1.setColor(this.editor.getBackground());
- Dimension var2 = this.editor.getSize();
- var1.fillRect(0, 0, var2.width, var2.height);
- }
-
- protected final JTextComponent getComponent() {
- return this.editor;
- }
-
- protected void modelChanged() {
- ViewFactory var1 = this.rootView.getViewFactory();
- Document var2 = this.editor.getDocument();
- Element var3 = var2.getDefaultRootElement();
- this.setView(var1.create(var3));
- }
-
- protected final void setView(View var1) {
- this.rootView.setView(var1);
- this.painted = false;
- this.editor.invalidate();
- }
-
- protected void paintSafely(Graphics var1) {
- this.painted = true;
- Highlighter var2 = this.editor.getHighlighter();
- Caret var3 = this.editor.getCaret();
- if (this.editor.isOpaque()) {
- this.paintBackground(var1);
- }
-
- if (var2 != null) {
- var2.paint(var1);
- }
-
- Rectangle var4 = this.getVisibleEditorRect();
- this.rootView.paint(var1, var4);
- if (var3 != null) {
- var3.paint(var1);
- }
-
- }
-
- public void installUI(JComponent var1) {
- if (var1 instanceof JTextComponent) {
- this.editor = (JTextComponent)var1;
- this.installDefaults(var1);
- this.editor.setOpaque(true);
- this.editor.setAutoscrolls(true);
- this.editor.setHighlighter(this.createHighlighter());
- this.editor.addPropertyChangeListener(this.updateHandler);
- Document var2 = this.editor.getDocument();
- if (var2 == null) {
- this.editor.setDocument(this.getEditorKit().createDefaultDocument());
- } else {
- var2.addDocumentListener(this.updateHandler);
- this.modelChanged();
- }
-
- this.installListeners(var1);
- this.editor.setKeymap(this.createKeymap());
- } else {
- throw new Error("TextUI needs JTextComponent");
- }
- }
-
- public void uninstallUI(JComponent var1) {
- this.editor.removePropertyChangeListener(this.updateHandler);
- this.editor.getDocument().removeDocumentListener(this.updateHandler);
- this.painted = false;
- this.uninstallDefaults(var1);
- this.editor.setHighlighter((Highlighter)null);
- this.rootView.setView((View)null);
- ((Container)var1).removeAll();
- this.editor.setKeymap((Keymap)null);
- this.uninstallListeners(var1);
- }
-
- public final void paint(Graphics var1, JComponent var2) {
- if (this.rootView.getViewCount() > 0 && this.rootView.getView(0) != null) {
- SafePainter var3 = new SafePainter(this, var1);
- Document var4 = this.editor.getDocument();
- var4.render(var3);
- }
-
- }
-
- public Dimension getPreferredSize(JComponent var1) {
- Insets var2 = var1.getInsets();
- return new Dimension((int)Math.min((long)this.rootView.getPreferredSpan(0) + (long)var2.left + (long)var2.right, 2147483647L), (int)Math.min((long)this.rootView.getPreferredSpan(1) + (long)var2.top + (long)var2.bottom, 2147483647L));
- }
-
- public Dimension getMinimumSize(JComponent var1) {
- Insets var2 = var1.getInsets();
- long var3 = this.rootView.getResizeWeight(0) > 0 ? 1L : Math.min((long)this.rootView.getPreferredSpan(0) + (long)var2.left + (long)var2.right, 2147483647L);
- long var5 = this.rootView.getResizeWeight(1) > 0 ? 1L : Math.min((long)this.rootView.getPreferredSpan(1) + (long)var2.top + (long)var2.bottom, 2147483647L);
- return new Dimension((int)var3, (int)var5);
- }
-
- public Dimension getMaximumSize(JComponent var1) {
- Insets var2 = var1.getInsets();
- long var3 = this.rootView.getResizeWeight(0) > 0 ? 2147483647L : Math.min((long)this.rootView.getPreferredSpan(0) + (long)var2.left + (long)var2.right, 2147483647L);
- long var5 = this.rootView.getResizeWeight(1) > 0 ? 2147483647L : Math.min((long)this.rootView.getPreferredSpan(1) + (long)var2.top + (long)var2.bottom, 2147483647L);
- return new Dimension((int)var3, (int)var5);
- }
-
- protected Rectangle getVisibleEditorRect() {
- Rectangle var1 = new Rectangle(this.editor.getSize());
- Insets var2 = this.editor.getInsets();
- var1.x += var2.left;
- var1.y += var2.top;
- var1.width -= var2.left + var2.right;
- var1.height -= var2.top + var2.bottom;
- return var1;
- }
-
- public Rectangle modelToView(int var1) throws BadLocationException {
- if (this.painted) {
- Rectangle var2 = this.getVisibleEditorRect();
- Shape var3 = this.rootView.modelToView(var1, var2);
- return var3.getBounds();
- } else {
- return null;
- }
- }
-
- public int viewToModel(Point var1) {
- if (this.painted) {
- Rectangle var2 = this.getVisibleEditorRect();
- return this.rootView.viewToModel((float)var1.x, (float)var1.y, var2);
- } else {
- return -1;
- }
- }
-
- public void damageRange(int var1, int var2) {
- if (this.painted) {
- Rectangle var3 = this.getVisibleEditorRect();
-
- try {
- Shape var4 = this.rootView.modelToView(var1, var3);
- Shape var5 = this.rootView.modelToView(var2, var3);
- if (var4 != null && var5 != null) {
- Rectangle var6 = var4.getBounds();
- Rectangle var7 = var5.getBounds();
- if (var6.y == var7.y) {
- this.editor.repaint(var6.x, var6.y, var7.x - var6.x + 1, var6.height);
- return;
- }
-
- this.editor.repaint(var3.x, var6.y, var3.width, var7.y - var6.y + var7.height);
- return;
- }
- } catch (BadLocationException var8) {
- return;
- }
- }
-
- }
-
- public EditorKit getEditorKit() {
- return defaultKit;
- }
-
- public View getRootView() {
- return this.rootView;
- }
-
- public Insets getDefaultMargin() {
- return new Insets(0, 0, 0, 0);
- }
-
- public View create(Element var1) {
- return null;
- }
-
- public View create(Element var1, int var2, int var3) {
- return null;
- }
-
- private void readObject(ObjectInputStream var1) throws ClassNotFoundException, IOException {
- var1.defaultReadObject();
- this.rootView = new RootView(this);
- this.updateHandler = new UpdateHandler(this);
- }
- }
-