選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Dialog.java 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. //
  19. // This Dialog class implements a pop-up dialog. This is needed because
  20. // apparently you can't use the standard AWT Dialog from within an applet. The
  21. // dialog can be made visible by calling its showDialog() method. Dialogs can
  22. // be modal or non-modal. For a modal dialog box, the showDialog() method must
  23. // be called from a thread other than the GUI thread, and it only returns when
  24. // the dialog box has been dismissed. For a non-modal dialog box, the
  25. // showDialog() method returns immediately.
  26. package com.tigervnc.vncviewer;
  27. import java.io.*;
  28. import java.net.*;
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. import java.awt.image.*;
  32. import javax.swing.*;
  33. import javax.swing.filechooser.*;
  34. //class Dialog extends JFrame implements WindowListener {
  35. class Dialog extends JFrame {
  36. protected boolean ok, done;
  37. boolean modal;
  38. public Dialog(boolean modal_) {
  39. modal = modal_;
  40. //addWindowListener(this);
  41. }
  42. public boolean showDialog() {
  43. ok = false;
  44. done = false;
  45. initDialog();
  46. Dimension dpySize = getToolkit().getScreenSize();
  47. Dimension mySize = getSize();
  48. int x = (dpySize.width - mySize.width) / 2;
  49. int y = (dpySize.height - mySize.height) / 2;
  50. setLocation(x, y);
  51. ClassLoader cl = this.getClass().getClassLoader();
  52. ImageIcon icon = new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.ico"));
  53. setIconImage(icon.getImage());
  54. //setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  55. //setFont(new Font("SansSerif", Font.PLAIN, 11));
  56. setVisible(true);
  57. setFocusable(true);
  58. if (!modal) return true;
  59. synchronized(this) {
  60. try {
  61. while (!done)
  62. wait();
  63. } catch (InterruptedException e) {
  64. }
  65. }
  66. return ok;
  67. }
  68. public void endDialog() {
  69. done = true;
  70. setVisible(false);
  71. setFocusable(false);
  72. if (modal) {
  73. synchronized (this) {
  74. notify();
  75. }
  76. }
  77. }
  78. // initDialog() can be overridden in a derived class. Typically it is used
  79. // to make sure that checkboxes have the right state, etc.
  80. public void initDialog() {
  81. }
  82. //------------------------------------------------------------------
  83. // implemented blank methods
  84. //public void windowClosed(WindowEvent event){}
  85. //public void windowDeiconified(WindowEvent event){}
  86. //public void windowIconified(WindowEvent event){}
  87. //public void windowActivated(WindowEvent event){}
  88. //public void windowDeactivated(WindowEvent event){}
  89. //public void windowOpened(WindowEvent event){}
  90. //------------------------------------------------------------------
  91. // method to check which window was closing
  92. //public void windowClosing(WindowEvent event) {
  93. // ok = false;
  94. // endDialog();
  95. //}
  96. public void addGBComponent(JComponent c, JComponent cp,
  97. int gx, int gy,
  98. int gw, int gh,
  99. int gipx, int gipy,
  100. double gwx, double gwy,
  101. int fill, int anchor,
  102. Insets insets)
  103. {
  104. GridBagConstraints gbc = new GridBagConstraints();
  105. gbc.anchor = anchor;
  106. gbc.fill = fill;
  107. gbc.gridx = gx;
  108. gbc.gridy = gy;
  109. gbc.gridwidth = gw;
  110. gbc.gridheight = gh;
  111. gbc.insets = insets;
  112. gbc.ipadx = gipx;
  113. gbc.ipady = gipy;
  114. gbc.weightx = gwx;
  115. gbc.weighty = gwy;
  116. cp.add(c, gbc);
  117. }
  118. final public String getFileSeperator() {
  119. String seperator = System.getProperties().get("file.separator").toString();
  120. return seperator;
  121. }
  122. final public String getUserName() {
  123. String userName = (String)System.getProperties().get("user.name");
  124. return userName;
  125. }
  126. }