Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
OTP4U (One Time Pad For You) - Util.java

Util.java

Caricato da: Teutoburgo
Scarica il programma completo

  1. /*
  2.  * Util.java
  3.  *
  4.  * Created on July 5, 2003, 8:11 AM
  5.  */
  6.  
  7. package tk.teutoburgo.otp4u.gui;
  8.  
  9. import java.awt.*;
  10. import java.io.*;
  11. import javax.swing.*;
  12.  
  13. /**
  14.  *
  15.  * @author  Karl Dinwiddie
  16.  *
  17.  * Generic public static GUI related utility methods.
  18.  *
  19.  */
  20. public class Util {
  21.     public static Toolkit tk;
  22.    
  23.     public static final void init(final Toolkit toolKit) {
  24.         tk = toolKit;
  25.     }
  26.  
  27.     public static final String getStringFromFile(File file) throws IOException {
  28.         StringBuffer rtn = new StringBuffer();
  29.         FileReader fr = new FileReader(file);
  30.         BufferedReader br = new BufferedReader(fr);
  31.         String s = br.readLine();
  32.         while (s != null) {
  33.             rtn.append(s).append("\n");
  34.             s = br.readLine();
  35.         }
  36.         br.close();
  37.         fr.close();
  38.         return rtn.toString();
  39.     }
  40.    
  41.     public static final void saveStringToFile(String s, File file) throws IOException {
  42.         FileWriter fw = new FileWriter(file);
  43.         BufferedWriter br = new BufferedWriter(fw);
  44.         br.write(s);
  45.         br.close();
  46.         fw.close();
  47.     }
  48.    
  49.     public static final File getFileFromUser(final String prompt) {
  50.         File rtn = null;
  51.         JFileChooser chooser = new JFileChooser();
  52.         chooser.setDialogTitle(prompt);
  53.         if (chooser.showOpenDialog(new JFrame()) == JFileChooser.APPROVE_OPTION) {
  54.             rtn = chooser.getSelectedFile();
  55.         }
  56.         return rtn;
  57.     }
  58.    
  59.     public static final boolean isWindowsOS = System.getProperty("os.name").toLowerCase().indexOf("windows") > -1;
  60.    
  61.    
  62.     public static final Point centerInScreen(Dimension d) {
  63.         final Dimension s = tk.getScreenSize();
  64.         return new Point((int)((s.width-d.width)/2),(int) ((s.height-d.height)/2));
  65.     }
  66.    
  67. }