protected int _stringWidth(String font, String text) { return getFont(font).metrics.stringWidth(text); }
protected int _getMaxAscent(String font) { return getFont(font).metrics.getMaxAscent(); }
protected int _getMaxDescent(String font) { return getFont(font).metrics.getMaxDescent(); }
+ protected boolean _supressDirtyOnResize() { return true; }
+
+ protected void postInit() {
+ if (Log.on) Log.log(Platform.class, " color depth = " +
+ Toolkit.getDefaultToolkit().getColorModel().getPixelSize() + "bpp");
+ }
+
+ protected void _criticalAbort(String message) {
+ if (Log.on) Log.log(this, message);
+ final Dialog d = new Dialog(new Frame(), "XWT Cannot Continue");
+ d.setLayout(new BorderLayout());
+ TextArea ta = new TextArea("XWT cannot continue because:\n\n" + message, 10, 80);
+ ta.setEditable(false);
+ d.add(ta, "Center");
+ Button b = new Button("OK");
+ b.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ d.dispose();
+ }
+ });
+ d.add(b, "South");
+ d.setModal(true);
+ d.pack();
+ d.show();
+ new Semaphore().block();
+ }
protected String _getClipBoard() {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
/** some platforms (cough, cough, NetscapeVM) have totally broken modifier masks; they will need to override this */
protected static int modifiersToButtonNumber(int modifiers) {
if ((modifiers & InputEvent.BUTTON1_MASK) == InputEvent.BUTTON1_MASK) return 1;
- if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) return 3;
- if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) return 2;
+ if ((modifiers & InputEvent.BUTTON2_MASK) == InputEvent.BUTTON2_MASK) {
+ // ugh, MacOSX reports the right mouse button as BUTTON2_MASK...
+ if (System.getProperty("os.name", "").startsWith("Mac OS X")) return 2;
+ return 3;
+ }
+ if ((modifiers & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) {
+ // ugh, MacOSX reports the right mouse button as BUTTON2_MASK...
+ if (System.getProperty("os.name", "").startsWith("Mac OS X")) return 3;
+ return 2;
+ }
return 0;
}
+ static class FileDialogHelper extends FileDialog implements WindowListener, ComponentListener {
+ Semaphore s;
+ public FileDialogHelper(String suggestedFileName, Semaphore s, boolean write) {
+ super(new Frame(), write ? "Save" : "Open", write ? FileDialog.SAVE : FileDialog.LOAD);
+ this.s = s;
+ addWindowListener(this);
+ addComponentListener(this);
+ if (suggestedFileName.indexOf(File.separatorChar) == -1) {
+ setFile(suggestedFileName);
+ } else {
+ setDirectory(suggestedFileName.substring(0, suggestedFileName.lastIndexOf(File.separatorChar)));
+ setFile(suggestedFileName.substring(suggestedFileName.lastIndexOf(File.separatorChar) + 1));
+ }
+ show();
+ }
+ public void windowActivated(WindowEvent e) { }
+ public void windowClosed(WindowEvent e) { s.release(); }
+ public void windowClosing(WindowEvent e) { }
+ public void windowDeactivated(WindowEvent e) { }
+ public void windowDeiconified(WindowEvent e) { }
+ public void windowIconified(WindowEvent e) { }
+ public void windowOpened(WindowEvent e) { }
+ public void componentHidden(ComponentEvent e) { s.release(); }
+ public void componentMoved(ComponentEvent e) { }
+ public void componentResized(ComponentEvent e) { }
+ public void componentShown(ComponentEvent e) { }
+ };
+
+ protected String _fileDialog(String suggestedFileName, boolean write) {
+ final Semaphore s = new Semaphore();
+ FileDialogHelper fd = new FileDialogHelper(suggestedFileName, s, write);
+ s.block();
+ return fd.getDirectory() + File.separatorChar + fd.getFile();
+ }
+
+
// Inner Classes /////////////////////////////////////////////////////////////////////////////////////
- protected static class AWTPicture implements Picture {
+ protected static class AWTPicture extends Picture {
public int getHeight() { return i.getHeight(null); }
public int getWidth() { return i.getWidth(null); }
public int[] getData() { return data; }
}
}
- protected static class AWTDoubleBuffer implements DoubleBuffer {
+ protected static class AWTDoubleBuffer extends DoubleBuffer {
protected Image i = null;
protected Graphics g = null;
// IMPORTANT: this must be called before render() to ensure
// that our peer has been created
- window.setVisible(true);
-
+ makeVisible();
}
+
+ protected void makeVisible() { window.setVisible(true); }
public void _dispose() {
window.removeMouseListener(this);
public void windowDeiconified(WindowEvent e) { dirty(0, 0, width, height); Minimized(false); }
public void windowActivated(WindowEvent e) { Focused(true); }
public void windowDeactivated(WindowEvent e) { Focused(false); }
- public void componentMoved(ComponentEvent e) { PosChange(window.getLocation().x, window.getLocation().y); }
+ public void componentMoved(ComponentEvent e) { PosChange(window.getLocation().x + insets.left, window.getLocation().y + insets.top); }
public void componentResized(ComponentEvent e) {
// we have to periodically do this; I don't know why
ourGraphics = null;
}
-
+
public void keyTyped(KeyEvent k) { }
public void keyPressed(KeyEvent k) { KeyPressed(translateKey(k)); }
public void keyReleased(KeyEvent k) { KeyReleased(translateKey(k)); }
case KeyEvent.VK_SHIFT: return "shift";
case KeyEvent.VK_TAB: return "tab";
case KeyEvent.VK_UP: return "up";
-
- // we special-case letters since (C-a).getKeyChar() != 'a'
- case KeyEvent.VK_A: return "a";
- case KeyEvent.VK_B: return "b";
- case KeyEvent.VK_C: return "c";
- case KeyEvent.VK_D: return "d";
- case KeyEvent.VK_E: return "e";
- case KeyEvent.VK_F: return "f";
- case KeyEvent.VK_G: return "g";
- case KeyEvent.VK_H: return "h";
- case KeyEvent.VK_I: return "i";
- case KeyEvent.VK_J: return "j";
- case KeyEvent.VK_K: return "k";
- case KeyEvent.VK_L: return "l";
- case KeyEvent.VK_M: return "m";
- case KeyEvent.VK_N: return "n";
- case KeyEvent.VK_O: return "o";
- case KeyEvent.VK_P: return "p";
- case KeyEvent.VK_Q: return "q";
- case KeyEvent.VK_R: return "r";
- case KeyEvent.VK_S: return "s";
- case KeyEvent.VK_T: return "t";
- case KeyEvent.VK_U: return "u";
- case KeyEvent.VK_V: return "v";
- case KeyEvent.VK_W: return "w";
- case KeyEvent.VK_X: return "x";
- case KeyEvent.VK_Y: return "y";
- case KeyEvent.VK_Z: return "z";
- default: return String.valueOf(k.getKeyChar());
+ default:
+ char c = k.getKeyChar();
+ if (c >= 1 && c <= 26) c = (char)('a' + c - 1);
+ return String.valueOf(c);
}
}
}
if (ret == null) {
pf.parse(font);
if (pf.name.equals("tty")) pf.name = "monospace";
- ret = new MetricatedFont(pf.name, (pf.bold ? Font.BOLD : 0) | (pf.italic ? Font.ITALIC : 0), pf.size);
+
+ // Java's fonts tend to be, on average, two points smaller than Win32/X11 fonts. This is most acute in
+ // the proxy password dialog on Linux
+ ret = new MetricatedFont(pf.name, (pf.bold ? Font.BOLD : 0) | (pf.italic ? Font.ITALIC : 0), pf.size + 2);
+
fontCache.put(font, ret);
}
return ret;