121 private final RepaintArea targetPaintArea; |
121 private final RepaintArea targetPaintArea; |
122 |
122 |
123 // private volatile boolean paintPending; |
123 // private volatile boolean paintPending; |
124 private volatile boolean isLayouting; |
124 private volatile boolean isLayouting; |
125 |
125 |
126 private D delegate = null; |
126 private final D delegate; |
127 private Container delegateContainer; |
127 private Container delegateContainer; |
128 private Component delegateDropTarget; |
128 private Component delegateDropTarget; |
129 private final Object dropTargetLock = new Object(); |
129 private final Object dropTargetLock = new Object(); |
130 |
130 |
131 private int fNumDropTargets = 0; |
131 private int fNumDropTargets = 0; |
132 private CDropTarget fDropTarget = null; |
132 private CDropTarget fDropTarget = null; |
133 |
133 |
134 private final PlatformComponent platformComponent; |
134 private final PlatformComponent platformComponent; |
|
135 |
|
136 /** |
|
137 * Character with reasonable value between the minimum width and maximum. |
|
138 */ |
|
139 static final char WIDE_CHAR = '0'; |
135 |
140 |
136 private final class DelegateContainer extends Container { |
141 private final class DelegateContainer extends Container { |
137 { |
142 { |
138 enableEvents(0xFFFFFFFF); |
143 enableEvents(0xFFFFFFFF); |
139 } |
144 } |
696 return font; |
699 return font; |
697 } |
700 } |
698 } |
701 } |
699 |
702 |
700 @Override |
703 @Override |
701 public FontMetrics getFontMetrics(Font f) { |
704 public FontMetrics getFontMetrics(final Font f) { |
702 // Borrow the metrics from the top-level window |
705 // Borrow the metrics from the top-level window |
703 // return getWindowPeer().getFontMetrics(f); |
706 // return getWindowPeer().getFontMetrics(f); |
704 // Obtain the metrics from the offscreen window where this peer is |
707 // Obtain the metrics from the offscreen window where this peer is |
705 // mostly drawn to. |
708 // mostly drawn to. |
706 // TODO: check for "use platform metrics" settings |
709 // TODO: check for "use platform metrics" settings |
707 Graphics g = getWindowPeer().getGraphics(); |
710 final Graphics g = getOnscreenGraphics(); |
708 try { |
711 if (g != null) { |
709 if (g != null) { |
712 try { |
710 return g.getFontMetrics(f); |
713 return g.getFontMetrics(f); |
711 } else { |
714 } finally { |
712 synchronized (getDelegateLock()) { |
|
713 return delegateContainer.getFontMetrics(f); |
|
714 } |
|
715 } |
|
716 } finally { |
|
717 if (g != null) { |
|
718 g.dispose(); |
715 g.dispose(); |
719 } |
716 } |
|
717 } |
|
718 synchronized (getDelegateLock()) { |
|
719 return delegateContainer.getFontMetrics(f); |
720 } |
720 } |
721 } |
721 } |
722 |
722 |
723 @Override |
723 @Override |
724 public void setEnabled(final boolean e) { |
724 public void setEnabled(final boolean e) { |
845 // TODO: not implemented |
845 // TODO: not implemented |
846 return false; |
846 return false; |
847 } |
847 } |
848 |
848 |
849 /** |
849 /** |
850 * Should be overridden in subclasses to forward the request |
850 * Determines the preferred size of the component. By default forwards the |
851 * to the Swing helper component, if required. |
851 * request to the Swing helper component. Should be overridden in subclasses |
|
852 * if required. |
852 */ |
853 */ |
853 @Override |
854 @Override |
854 public Dimension getPreferredSize() { |
855 public Dimension getPreferredSize() { |
855 // It looks like a default implementation for all toolkits |
856 final Dimension size; |
856 return getMinimumSize(); |
857 synchronized (getDelegateLock()) { |
857 } |
858 size = getDelegate().getPreferredSize(); |
858 |
859 } |
859 /* |
860 return validateSize(size); |
860 * Should be overridden in subclasses to forward the request |
861 } |
861 * to the Swing helper component. |
862 |
|
863 /** |
|
864 * Determines the minimum size of the component. By default forwards the |
|
865 * request to the Swing helper component. Should be overridden in subclasses |
|
866 * if required. |
862 */ |
867 */ |
863 @Override |
868 @Override |
864 public Dimension getMinimumSize() { |
869 public Dimension getMinimumSize() { |
865 D delegate = getDelegate(); |
870 final Dimension size; |
866 |
871 synchronized (getDelegateLock()) { |
867 if (delegate == null) { |
872 size = getDelegate().getMinimumSize(); |
868 // Is it a correct default value? |
873 } |
869 return getBounds().getSize(); |
874 return validateSize(size); |
870 } else { |
875 } |
871 synchronized (getDelegateLock()) { |
876 |
872 return delegate.getMinimumSize(); |
877 /** |
873 } |
878 * In some situations delegates can return empty minimum/preferred size. |
874 } |
879 * (For example: empty JLabel, etc), but awt components never should be |
|
880 * empty. In the XPeers or WPeers we use some magic constants, but here we |
|
881 * try to use something more useful, |
|
882 */ |
|
883 private Dimension validateSize(final Dimension size) { |
|
884 if (size.width == 0 || size.height == 0) { |
|
885 final FontMetrics fm = getFontMetrics(getFont()); |
|
886 size.width = fm.charWidth(WIDE_CHAR); |
|
887 size.height = fm.getHeight(); |
|
888 } |
|
889 return size; |
875 } |
890 } |
876 |
891 |
877 @Override |
892 @Override |
878 public void updateCursorImmediately() { |
893 public void updateCursorImmediately() { |
879 getLWToolkit().getCursorManager().updateCursor(); |
894 getLWToolkit().getCursorManager().updateCursor(); |