001: package org.objectweb.salome_tmf.api;
002:
003: import java.awt.Dimension;
004: import java.awt.Font;
005: import java.awt.GraphicsConfiguration;
006: import java.awt.GraphicsDevice;
007: import java.awt.GraphicsEnvironment;
008: import java.awt.Rectangle;
009: import java.io.InputStream;
010: import java.sql.Date;
011: import java.sql.Time;
012: import java.util.Calendar;
013: import java.util.GregorianCalendar;
014: import java.util.Properties;
015:
016: import javax.swing.UIManager;
017:
018: public class Util {
019: /**
020: * Recherche de l'heure courante
021: * @return heure actuelle
022: */
023: public static Time getCurrentTime() {
024: Calendar calendar = new GregorianCalendar();
025: int heure = calendar.get(Calendar.HOUR_OF_DAY);
026: int minute = calendar.get(Calendar.MINUTE);
027: int seconde = calendar.get(Calendar.SECOND);
028: String chaineHeureActuelle = heure + ":" + minute + ":"
029: + seconde;
030: Time heureActuelle = Time.valueOf(chaineHeureActuelle);
031: return heureActuelle;
032: }
033:
034: /**
035: * Recherche de la date actuelle
036: * @return date actuelle
037: */
038:
039: public static Date getCurrentDate() {
040: Calendar calendar = new GregorianCalendar();
041: int year = calendar.get(Calendar.YEAR);
042: int month = calendar.get(Calendar.MONTH) + 1;
043: int day = calendar.get(Calendar.DAY_OF_MONTH);
044: String chaineDateActuelle = year + "-" + month + "-" + day;
045: Date dateActuelle = Date.valueOf(chaineDateActuelle);
046:
047: return dateActuelle;
048: }
049:
050: public static Properties getPropertiesFile(String file)
051: throws Exception {
052: Properties prop = new Properties();
053: InputStream in = Util.class.getResourceAsStream(file);
054: prop.load(in);
055: in.close();
056: return prop;
057: }
058:
059: public static Properties getPropertiesStream(InputStream in)
060: throws Exception {
061: Properties prop = new Properties();
062: prop.load(in);
063: in.close();
064: return prop;
065: }
066:
067: public static Properties getPropertiesFile(java.net.URL url)
068: throws Exception {
069: Properties prop = new Properties();
070: InputStream in = url.openStream();
071: prop.load(in);
072: in.close();
073: return prop;
074: }
075:
076: public static void adaptFont() {
077: try {
078: GraphicsEnvironment ge = GraphicsEnvironment
079: .getLocalGraphicsEnvironment();
080: GraphicsDevice[] gs = ge.getScreenDevices();
081: GraphicsDevice gd = gs[0];
082: GraphicsConfiguration[] gc = gd.getConfigurations();
083: Rectangle dim = gc[0].getBounds();
084: System.out.println("------------------------Resolution "
085: + dim.width + " x " + dim.height);
086: if (800 >= dim.width) {
087: setUIFont(new Font("Arial", Font.PLAIN, 9));
088: } else if (1024 >= dim.width) {
089: setUIFont(new Font("Arial", Font.PLAIN, 11));
090: } else if (1280 >= dim.width) {
091: setUIFont(new Font("Arial", Font.PLAIN, 13));
092: }
093: } catch (Exception e) {
094: e.printStackTrace();
095: }
096: }
097:
098: public static void setUIFont(Font f) {
099: //
100: // sets the default font for all Swing components.
101: // ex.
102: // setUIFont (new javax.swing.plaf.FontUIResource("Serif",Font.ITALIC,12));
103: //
104: java.util.Enumeration keys = UIManager.getDefaults().keys();
105: while (keys.hasMoreElements()) {
106: Object key = keys.nextElement();
107: Object value = UIManager.get(key);
108: if (value instanceof javax.swing.plaf.FontUIResource)
109: UIManager.put(key, f);
110: }
111: }
112:
113: static public void log(String str) {
114: if (Api.isDEBUG())
115: System.out.println(str);
116: }
117: }
|