提交 dd55afd3 编写于 作者: S serb

8035165: Expose internal representation in sun.awt.X11

Reviewed-by: pchelko, prr
上级 ae446ae9
......@@ -43,7 +43,7 @@ import sun.awt.HeadlessToolkit;
import sun.misc.ThreadGroupUtils;
import sun.lwawt.macosx.*;
public class CFontManager extends SunFontManager {
public final class CFontManager extends SunFontManager {
private FontConfigManager fcManager = null;
private static Hashtable<String, Font2D> genericFonts = new Hashtable<String, Font2D>();
......@@ -61,20 +61,14 @@ public class CFontManager extends SunFontManager {
return new CFontConfiguration(this, preferLocaleFonts, preferPropFonts);
}
private static String[] defaultPlatformFont = null;
/*
* Returns an array of two strings. The first element is the
* name of the font. The second element is the file name.
*/
@Override
public synchronized String[] getDefaultPlatformFont() {
if (defaultPlatformFont == null) {
defaultPlatformFont = new String[2];
defaultPlatformFont[0] = "Lucida Grande";
defaultPlatformFont[1] = "/System/Library/Fonts/LucidaGrande.ttc";
}
return defaultPlatformFont;
protected String[] getDefaultPlatformFont() {
return new String[]{"Lucida Grande",
"/System/Library/Fonts/LucidaGrande.ttc"};
}
// This is a way to register any kind of Font2D, not just files and composites.
......
......@@ -3182,7 +3182,7 @@ public abstract class SunFontManager implements FontSupport, FontManagerForSGE {
* Returns an array of two strings. The first element is the
* name of the font. The second element is the file name.
*/
public abstract String[] getDefaultPlatformFont();
protected abstract String[] getDefaultPlatformFont();
// Begin: Refactored from SunGraphicsEnviroment.
......
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -40,7 +40,7 @@ import sun.util.logging.PlatformLogger;
* For now, this class manages the list of items and painting thereof, but not
* posting of Item or ActionEvents
*/
public class ListHelper implements XScrollbarClient {
final class ListHelper implements XScrollbarClient {
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.ListHelper");
private final int FOCUS_INSET = 1;
......@@ -79,24 +79,16 @@ public class ListHelper implements XScrollbarClient {
// Holds the true if mouse is dragging outside of the area of the list
// The flag is used at the moment of the dragging and releasing mouse
// See 6243382 for more information
boolean mouseDraggedOutVertically = false;
private boolean mouseDraggedOutVertically = false;
private volatile boolean vsbVisibilityChanged = false;
/*
* Comment
*/
public ListHelper(XWindow peer,
Color[] colors,
int initialSize,
boolean multiSelect,
boolean scrollVert,
boolean scrollHoriz,
Font font,
int maxVisItems,
int SPACE,
int MARGIN,
int BORDER,
int SCROLLBAR) {
ListHelper(XWindow peer, Color[] colors, int initialSize,
boolean multiSelect, boolean scrollVert, boolean scrollHoriz,
Font font, int maxVisItems, int SPACE, int MARGIN, int BORDER,
int SCROLLBAR) {
this.peer = peer;
this.colors = colors;
this.multiSelect = multiSelect;
......@@ -121,6 +113,7 @@ public class ListHelper implements XScrollbarClient {
SCROLLBAR_WIDTH = SCROLLBAR;
}
@Override
public Component getEventSource() {
return peer.getEventSource();
}
......@@ -129,36 +122,36 @@ public class ListHelper implements XScrollbarClient {
/* List management methods */
/**********************************************************************/
public void add(String item) {
void add(String item) {
items.add(item);
updateScrollbars();
}
public void add(String item, int index) {
void add(String item, int index) {
items.add(index, item);
updateScrollbars();
}
public void remove(String item) {
void remove(String item) {
// FIXME: need to clean up select list, too?
items.remove(item);
updateScrollbars();
// Is vsb visible now?
}
public void remove(int index) {
void remove(int index) {
// FIXME: need to clean up select list, too?
items.remove(index);
updateScrollbars();
// Is vsb visible now?
}
public void removeAll() {
void removeAll() {
items.removeAll(items);
updateScrollbars();
}
public void setMultiSelect(boolean ms) {
void setMultiSelect(boolean ms) {
multiSelect = ms;
}
......@@ -167,7 +160,7 @@ public class ListHelper implements XScrollbarClient {
* merely keeps internal track of which items are selected for painting
* dealing with target Components happens elsewhere
*/
public void select(int index) {
void select(int index) {
if (index > getItemCount() - 1) {
index = (isEmpty() ? -1 : 0);
}
......@@ -182,13 +175,13 @@ public class ListHelper implements XScrollbarClient {
}
/* docs */
public void deselect(int index) {
void deselect(int index) {
assert(false);
}
/* docs */
/* if called for multiselect, return -1 */
public int getSelectedIndex() {
int getSelectedIndex() {
if (!multiSelect) {
Integer val = (Integer)selected.get(0);
return val.intValue();
......@@ -202,21 +195,21 @@ public class ListHelper implements XScrollbarClient {
* A getter method for XChoicePeer.
* Returns vsbVisiblityChanged value and sets it to false.
*/
public boolean checkVsbVisibilityChangedAndReset(){
boolean checkVsbVisibilityChangedAndReset(){
boolean returnVal = vsbVisibilityChanged;
vsbVisibilityChanged = false;
return returnVal;
}
public boolean isEmpty() {
boolean isEmpty() {
return items.isEmpty();
}
public int getItemCount() {
int getItemCount() {
return items.size();
}
public String getItem(int index) {
String getItem(int index) {
return (String) items.get(index);
}
......@@ -224,15 +217,15 @@ public class ListHelper implements XScrollbarClient {
/* GUI-related methods */
/**********************************************************************/
public void setFocusedIndex(int index) {
void setFocusedIndex(int index) {
focusedIndex = index;
}
public boolean isFocusedIndex(int index) {
private boolean isFocusedIndex(int index) {
return index == focusedIndex;
}
public void setFont(Font newFont) {
void setFont(Font newFont) {
if (newFont != font) {
font = newFont;
fm = Toolkit.getDefaultToolkit().getFontMetrics(font);
......@@ -243,7 +236,7 @@ public class ListHelper implements XScrollbarClient {
/*
* Returns width of the text of the longest item
*/
public int getMaxItemWidth() {
int getMaxItemWidth() {
int m = 0;
int end = getItemCount();
for(int i = 0 ; i < end ; i++) {
......@@ -260,7 +253,7 @@ public class ListHelper implements XScrollbarClient {
return fm.getHeight() + (2*TEXT_SPACE);
}
public int y2index(int y) {
int y2index(int y) {
if (log.isLoggable(PlatformLogger.Level.FINE)) {
log.fine("y=" + y +", firstIdx=" + firstDisplayedIndex() +", itemHeight=" + getItemHeight()
+ ",item_margin=" + ITEM_MARGIN);
......@@ -275,14 +268,14 @@ public class ListHelper implements XScrollbarClient {
public int numItemsDisplayed() {}
*/
public int firstDisplayedIndex() {
int firstDisplayedIndex() {
if (vsbVis) {
return vsb.getValue();
}
return 0;
}
public int lastDisplayedIndex() {
int lastDisplayedIndex() {
// FIXME: need to account for horiz scroll bar
if (hsbVis) {
assert false : "Implement for horiz scroll bar";
......@@ -294,7 +287,7 @@ public class ListHelper implements XScrollbarClient {
/*
* If the given index is not visible in the List, scroll so that it is.
*/
public void makeVisible(int index) {
private void makeVisible(int index) {
if (vsbVis) {
if (index < firstDisplayedIndex()) {
vsb.setValue(index);
......@@ -306,7 +299,7 @@ public class ListHelper implements XScrollbarClient {
}
// FIXME: multi-select needs separate focused index
public void up() {
void up() {
int curIdx = getSelectedIndex();
int numItems = getItemCount();
int newIdx;
......@@ -323,12 +316,12 @@ public class ListHelper implements XScrollbarClient {
select(newIdx);
}
public void down() {
void down() {
int newIdx = (getSelectedIndex() + 1) % getItemCount();
select(newIdx);
}
public void pageUp() {
void pageUp() {
// FIXME: for multi-select, move the focused item, not the selected item
if (vsbVis && firstDisplayedIndex() > 0) {
if (multiSelect) {
......@@ -343,7 +336,7 @@ public class ListHelper implements XScrollbarClient {
}
}
}
public void pageDown() {
void pageDown() {
if (vsbVis && lastDisplayedIndex() < getItemCount() - 1) {
if (multiSelect) {
assert false : "Implement pageDown() for multiSelect";
......@@ -357,17 +350,17 @@ public class ListHelper implements XScrollbarClient {
}
}
}
public void home() {}
public void end() {}
void home() {}
void end() {}
public boolean isVSBVisible() { return vsbVis; }
public boolean isHSBVisible() { return hsbVis; }
boolean isVSBVisible() { return vsbVis; }
boolean isHSBVisible() { return hsbVis; }
public XVerticalScrollbar getVSB() { return vsb; }
public XHorizontalScrollbar getHSB() { return hsb; }
XVerticalScrollbar getVSB() { return vsb; }
XHorizontalScrollbar getHSB() { return hsb; }
public boolean isInVertSB(Rectangle bounds, int x, int y) {
boolean isInVertSB(Rectangle bounds, int x, int y) {
if (vsbVis) {
assert vsb != null : "Vert scrollbar is visible, yet is null?";
int sbHeight = hsbVis ? bounds.height - SCROLLBAR_WIDTH : bounds.height;
......@@ -379,7 +372,7 @@ public class ListHelper implements XScrollbarClient {
return false;
}
public boolean isInHorizSB(Rectangle bounds, int x, int y) {
boolean isInHorizSB(Rectangle bounds, int x, int y) {
if (hsbVis) {
assert hsb != null : "Horiz scrollbar is visible, yet is null?";
......@@ -392,7 +385,7 @@ public class ListHelper implements XScrollbarClient {
return false;
}
public void handleVSBEvent(MouseEvent e, Rectangle bounds, int x, int y) {
void handleVSBEvent(MouseEvent e, Rectangle bounds, int x, int y) {
int sbHeight = hsbVis ? bounds.height - SCROLLBAR_WIDTH : bounds.height;
vsb.handleMouseEvent(e.getID(),
......@@ -405,7 +398,7 @@ public class ListHelper implements XScrollbarClient {
* Called when items are added/removed.
* Update whether the scrollbar is visible or not, scrollbar values
*/
void updateScrollbars() {
private void updateScrollbars() {
boolean oldVsbVis = vsbVis;
vsbVis = vsb != null && items.size() > maxVisItems;
if (vsbVis) {
......@@ -420,10 +413,11 @@ public class ListHelper implements XScrollbarClient {
// FIXME: check if added item makes a hsb necessary (if supported, that of course)
}
public int getNumItemsDisplayed() {
private int getNumItemsDisplayed() {
return items.size() > maxVisItems ? maxVisItems : items.size();
}
@Override
public void repaintScrollbarRequest(XScrollbar sb) {
Graphics g = peer.getGraphics();
Rectangle bounds = peer.getBounds();
......@@ -436,6 +430,7 @@ public class ListHelper implements XScrollbarClient {
g.dispose();
}
@Override
public void notifyValue(XScrollbar obj, int type, int v, boolean isAdjusting) {
if (obj == vsb) {
int oldScrollValue = vsb.getValue();
......@@ -467,7 +462,7 @@ public class ListHelper implements XScrollbarClient {
}
}
public void updateColors(Color[] newColors) {
void updateColors(Color[] newColors) {
colors = newColors;
}
......@@ -481,7 +476,7 @@ public class ListHelper implements XScrollbarClient {
XVerticalScrollbar vsb,
XHorizontalScrollbar hsb) {
*/
public void paintItems(Graphics g,
void paintItems(Graphics g,
Color[] colors,
Rectangle bounds) {
// paint border
......@@ -490,17 +485,14 @@ public class ListHelper implements XScrollbarClient {
// paint focus?
}
public void paintAllItems(Graphics g,
void paintAllItems(Graphics g,
Color[] colors,
Rectangle bounds) {
paintItems(g, colors, bounds,
firstDisplayedIndex(), lastDisplayedIndex());
}
public void paintItems(Graphics g,
Color[] colors,
Rectangle bounds,
int first,
int last) {
private void paintItems(Graphics g, Color[] colors, Rectangle bounds,
int first, int last) {
peer.flush();
int x = BORDER_WIDTH + ITEM_MARGIN;
int width = bounds.width - 2*ITEM_MARGIN - 2*BORDER_WIDTH - (vsbVis ? SCROLLBAR_WIDTH : 0);
......@@ -529,12 +521,9 @@ public class ListHelper implements XScrollbarClient {
/*
* comment about what is painted (i.e. the focus rect
*/
public void paintItem(Graphics g,
Color[] colors,
String string,
int x, int y, int width, int height,
boolean selected,
boolean focused) {
private void paintItem(Graphics g, Color[] colors, String string, int x,
int y, int width, int height, boolean selected,
boolean focused) {
//System.out.println("LP.pI(): x="+x+" y="+y+" w="+width+" h="+height);
//g.setColor(colors[BACKGROUND_COLOR]);
......@@ -575,7 +564,7 @@ public class ListHelper implements XScrollbarClient {
//g.clipRect(clip.x, clip.y, clip.width, clip.height);
}
boolean isItemSelected(int index) {
private boolean isItemSelected(int index) {
Iterator itr = selected.iterator();
while (itr.hasNext()) {
Integer val = (Integer)itr.next();
......@@ -586,7 +575,7 @@ public class ListHelper implements XScrollbarClient {
return false;
}
public void paintVSB(Graphics g, Color colors[], Rectangle bounds) {
private void paintVSB(Graphics g, Color colors[], Rectangle bounds) {
int height = bounds.height - 2*BORDER_WIDTH - (hsbVis ? (SCROLLBAR_WIDTH-2) : 0);
Graphics ng = g.create();
......@@ -602,7 +591,7 @@ public class ListHelper implements XScrollbarClient {
}
}
public void paintHSB(Graphics g, Color colors[], Rectangle bounds) {
private void paintHSB(Graphics g, Color colors[], Rectangle bounds) {
}
......
/*
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -42,7 +42,7 @@ import sun.awt.datatransfer.DataTransferer;
/**
* A class which interfaces with the X11 selection service.
*/
public final class XSelection {
final class XSelection {
/* Maps atoms to XSelection instances. */
private static final Hashtable<XAtom, XSelection> table = new Hashtable<XAtom, XSelection>();
......@@ -118,11 +118,10 @@ public final class XSelection {
/**
* Creates a selection object.
*
* @param atom the selection atom.
* @param clpbrd the corresponding clipoboard
* @exception NullPointerException if atom is <code>null</code>.
* @param atom the selection atom
* @throws NullPointerException if atom is {@code null}
*/
public XSelection(XAtom atom) {
XSelection(XAtom atom) {
if (atom == null) {
throw new NullPointerException("Null atom");
}
......@@ -134,8 +133,8 @@ public final class XSelection {
return selectionAtom;
}
public synchronized boolean setOwner(Transferable contents, Map formatMap,
long[] formats, long time)
synchronized boolean setOwner(Transferable contents, Map formatMap,
long[] formats, long time)
{
long owner = XWindow.getXAWTRootWindow().getWindow();
long selection = selectionAtom.getAtom();
......@@ -433,7 +432,7 @@ public final class XSelection {
return data != null ? data : new byte[0];
}
void validateDataGetter(WindowPropertyGetter propertyGetter)
private void validateDataGetter(WindowPropertyGetter propertyGetter)
throws IOException
{
// The order of checks is important because a property getter
......
/*
* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.awt;
import java.awt.GraphicsEnvironment;
......@@ -29,7 +54,7 @@ import sun.util.logging.PlatformLogger;
/**
* The X11 implementation of {@link FontManager}.
*/
public class X11FontManager extends SunFontManager {
public final class X11FontManager extends SunFontManager {
// constants identifying XLFD and font ID fields
private static final int FOUNDRY_FIELD = 1;
......@@ -129,8 +154,6 @@ public class X11FontManager extends SunFontManager {
*/
private static String[] fontdirs = null;
private static String[] defaultPlatformFont = null;
private FontConfigManager fcManager = null;
public static X11FontManager getInstance() {
......@@ -768,11 +791,9 @@ public class X11FontManager extends SunFontManager {
return getFontPathNative(noType1Fonts);
}
public String[] getDefaultPlatformFont() {
if (defaultPlatformFont != null) {
return defaultPlatformFont;
}
String[] info = new String[2];
@Override
protected String[] getDefaultPlatformFont() {
final String[] info = new String[2];
getFontConfigManager().initFontConfigFonts(false);
FontConfigManager.FcCompFont[] fontConfigFonts =
getFontConfigManager().getFontConfigFonts();
......@@ -798,8 +819,7 @@ public class X11FontManager extends SunFontManager {
info[1] = "/dialog.ttf";
}
}
defaultPlatformFont = info;
return defaultPlatformFont;
return info;
}
public synchronized FontConfigManager getFontConfigManager() {
......
/*
* Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -37,7 +37,6 @@ import java.util.Locale;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import sun.awt.Win32GraphicsEnvironment;
import sun.awt.windows.WFontConfiguration;
import sun.font.FontManager;
import sun.font.SunFontManager;
......@@ -48,9 +47,7 @@ import sun.java2d.SunGraphicsEnvironment;
/**
* The X11 implementation of {@link FontManager}.
*/
public class Win32FontManager extends SunFontManager {
private static String[] defaultPlatformFont = null;
public final class Win32FontManager extends SunFontManager {
private static TrueTypeFont eudcFont;
......@@ -215,12 +212,8 @@ public class Win32FontManager extends SunFontManager {
protected synchronized native String getFontPath(boolean noType1Fonts);
public String[] getDefaultPlatformFont() {
if (defaultPlatformFont != null) {
return defaultPlatformFont;
}
@Override
protected String[] getDefaultPlatformFont() {
String[] info = new String[2];
info[0] = "Arial";
info[1] = "c:\\windows\\fonts";
......@@ -247,8 +240,7 @@ public class Win32FontManager extends SunFontManager {
info[1] = dirs[0];
}
info[1] = info[1] + File.separator + "arial.ttf";
defaultPlatformFont = info;
return defaultPlatformFont;
return info;
}
/* register only TrueType/OpenType fonts
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册