/*
 * @(#) ConvolveOpFactory.java 1.0 99/10/4
 * Copyright (c) 1999 Larry Rodrigues
 */
//package app;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.awt.geom.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;

public class GraphicsInfo extends JFrame {
   GraphicsEnvironment graphicsEnv;
   public static void main(String[] args){
      GraphicsInfo gi = new GraphicsInfo();
   }

   public GraphicsInfo() {
      setTitle(" Graphics Info");
      graphicsEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
      createUI();
   }

   protected void createUI() {
      String[] deviceNames  =  getGraphicsDevices();
      JList deviceList = new JList(deviceNames);
      deviceList.setBackground(Color.black);
      deviceList.setForeground(Color.green);
      deviceList.setBorder(BorderFactory.createTitledBorder("Screen Devices"));
      String[] fontNames = graphicsEnv.getAvailableFontFamilyNames();
      JTextArea screenInfo = new JTextArea();
      screenInfo.setBackground(Color.black);
      screenInfo.setForeground(Color.green);
      screenInfo.setBorder(BorderFactory.createTitledBorder("Screen Info"));
      screenInfo.setText(getScreenInfo());
      JPanel screenInfoPanel = new JPanel();
      screenInfoPanel.setLayout( new GridLayout(2,1));
      screenInfoPanel.add( deviceList);
      screenInfoPanel.add(screenInfo);
      JList fontList = new JList(fontNames);
      fontList.setBorder(BorderFactory.createTitledBorder("Available Fonts"));
      fontList.setBackground(Color.black);
      fontList.setForeground(Color.green);
      JScrollPane jsp = new JScrollPane(fontList);
      getContentPane().setLayout(new GridLayout(1,2));
      getContentPane().add(screenInfoPanel);
      getContentPane().add(jsp);
      pack();
      setSize(600,400);
      show();
   }

   public String[] getGraphicsDevices() {
      GraphicsDevice[] gd = graphicsEnv.getScreenDevices();
      int numdevices = gd.length;
      String gdnames[] = new String[numdevices];
      for(int i=0; i<numdevices;i++) {
          int deviceType = gd[i].getType();
          String deviceName = getDeviceTypeAsText(deviceType);
          gdnames[i] = deviceName + gd[i].getIDstring();
      }
      return gdnames;
   }

   public String getScreenInfo() {
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      Dimension  screenSize = toolkit.getScreenSize();
      int dotsPerInch = toolkit.getScreenResolution();
      String screenInfo = " Screen size "+ "\n"+
                          " width  : " + Integer.toString(screenSize.width) + "\n"+
                          " height : " + Integer.toString(screenSize.height)+ "\n"+
                          "Screen resolution : "+ Integer.toString(dotsPerInch)+ " dots per inch";
      return screenInfo;
   }
   
   public String getDeviceTypeAsText(int deviceType){
      switch (deviceType) {
         case GraphicsDevice.TYPE_PRINTER:
            return "Printer";
         case GraphicsDevice.TYPE_RASTER_SCREEN:
            return "Screen";
         case GraphicsDevice.TYPE_IMAGE_BUFFER:
           return "Image Buffer";
         default:
           return "Unknown";
      }
   }
}


