1 /* |
1 /* |
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
46 |
46 |
47 abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent> |
47 abstract class LWTextComponentPeer<T extends TextComponent, D extends JComponent> |
48 extends LWComponentPeer<T, D> |
48 extends LWComponentPeer<T, D> |
49 implements DocumentListener, TextComponentPeer, InputMethodListener { |
49 implements DocumentListener, TextComponentPeer, InputMethodListener { |
50 |
50 |
51 /** |
51 |
52 * Character with reasonable value between the minimum width and maximum. |
|
53 */ |
|
54 protected static final char WIDE_CHAR = 'w'; |
|
55 private volatile boolean firstChangeSkipped; |
52 private volatile boolean firstChangeSkipped; |
56 |
53 |
57 LWTextComponentPeer(final T target, |
54 LWTextComponentPeer(final T target, |
58 final PlatformComponent platformComponent) { |
55 final PlatformComponent platformComponent) { |
59 super(target, platformComponent); |
56 super(target, platformComponent); |
93 /** |
90 /** |
94 * This method should be called under getDelegateLock(). |
91 * This method should be called under getDelegateLock(). |
95 */ |
92 */ |
96 abstract JTextComponent getTextComponent(); |
93 abstract JTextComponent getTextComponent(); |
97 |
94 |
98 public Dimension getPreferredSize(final int rows, final int columns) { |
95 public Dimension getMinimumSize(final int rows, final int columns) { |
99 final Insets insets; |
96 final Insets insets; |
100 synchronized (getDelegateLock()) { |
97 synchronized (getDelegateLock()) { |
101 insets = getDelegate().getInsets(); |
98 insets = getTextComponent().getInsets(); |
102 } |
99 } |
103 final int borderHeight = insets.top + insets.bottom; |
100 final int borderHeight = insets.top + insets.bottom; |
104 final int borderWidth = insets.left + insets.right; |
101 final int borderWidth = insets.left + insets.right; |
105 final FontMetrics fm = getFontMetrics(getFont()); |
102 final FontMetrics fm = getFontMetrics(getFont()); |
106 final int charWidth = (fm != null) ? fm.charWidth(WIDE_CHAR) : 10; |
103 return new Dimension(fm.charWidth(WIDE_CHAR) * columns + borderWidth, |
107 final int itemHeight = (fm != null) ? fm.getHeight() : 10; |
104 fm.getHeight() * rows + borderHeight); |
108 return new Dimension(columns * charWidth + borderWidth, |
|
109 rows * itemHeight + borderHeight); |
|
110 } |
105 } |
111 |
106 |
112 @Override |
107 @Override |
113 public final void setEditable(final boolean editable) { |
108 public final void setEditable(final boolean editable) { |
114 synchronized (getDelegateLock()) { |
109 synchronized (getDelegateLock()) { |