Lines 17-28
Link Here
|
17 |
import java.awt.datatransfer.Transferable; |
17 |
import java.awt.datatransfer.Transferable; |
18 |
import java.awt.dnd.DropTarget; |
18 |
import java.awt.dnd.DropTarget; |
19 |
import java.awt.event.InputEvent; |
19 |
import java.awt.event.InputEvent; |
|
|
20 |
import java.awt.Font; |
21 |
import java.awt.FontMetrics; |
22 |
import java.awt.Rectangle; |
20 |
import javax.swing.Icon; |
23 |
import javax.swing.Icon; |
21 |
import javax.swing.JComponent; |
24 |
import javax.swing.JComponent; |
22 |
import javax.swing.JEditorPane; |
25 |
import javax.swing.JEditorPane; |
23 |
import javax.swing.TransferHandler; |
26 |
import javax.swing.TransferHandler; |
|
|
27 |
import javax.swing.SwingConstants; |
24 |
import javax.swing.plaf.UIResource; |
28 |
import javax.swing.plaf.UIResource; |
25 |
import javax.swing.text.*; |
29 |
import javax.swing.text.*; |
|
|
30 |
import java.beans.PropertyChangeListener; |
31 |
import java.beans.PropertyChangeEvent; |
26 |
|
32 |
|
27 |
|
33 |
|
28 |
/** performance trick - 18% of time saved during open of an editor |
34 |
/** performance trick - 18% of time saved during open of an editor |
Lines 42-47
Link Here
|
42 |
/** is firing of events enabled? */ |
48 |
/** is firing of events enabled? */ |
43 |
int working = FIRE; // [Mila] firing since begining, otherwise doesn't work well |
49 |
int working = FIRE; // [Mila] firing since begining, otherwise doesn't work well |
44 |
|
50 |
|
|
|
51 |
/** determines scroll unit */ |
52 |
private int fontHeight; |
53 |
private int charWidth; |
54 |
|
55 |
/** |
56 |
* consturctor sets the initial values for horizontal |
57 |
* and vertical scroll units. |
58 |
* also listenes for font changes. |
59 |
*/ |
60 |
public QuietEditorPane() { |
61 |
setFontHeightWidth(getFont()); |
62 |
addPropertyChangeListener("font",new PropertyChangeListener() { |
63 |
public void propertyChange(PropertyChangeEvent evt) { |
64 |
Object val=evt.getNewValue(); |
65 |
if (val instanceof Font) { |
66 |
setFontHeightWidth((Font)val); |
67 |
} |
68 |
} |
69 |
}); |
70 |
} |
71 |
|
72 |
private void setFontHeightWidth(Font font) { |
73 |
FontMetrics metrics=getFontMetrics(font); |
74 |
fontHeight=metrics.getHeight(); |
75 |
charWidth=metrics.charWidth('m'); |
76 |
} |
77 |
|
78 |
/** |
79 |
* fix for #38139. |
80 |
* returns height of a line for vertical scroll unit |
81 |
* or width of a widest char for a horizontal scroll unit |
82 |
*/ |
83 |
public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { |
84 |
switch (orientation) { |
85 |
case SwingConstants.VERTICAL: |
86 |
return fontHeight; |
87 |
case SwingConstants.HORIZONTAL: |
88 |
return charWidth; |
89 |
default: |
90 |
throw new IllegalArgumentException("Invalid orientation: " +orientation); |
91 |
} |
92 |
} |
45 |
|
93 |
|
46 |
public void setDocument(Document doc) { |
94 |
public void setDocument(Document doc) { |
47 |
super.setDocument(doc); |
95 |
super.setDocument(doc); |