Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: rcsdesign/QueryStringDialog.java


1   package rcsdesign;
2   
3   
4   import java.awt.*;
5   import java.awt.event.*;
6   
7   /*
8    *
9    * QueryDialog
10   *
11   */
12  public class QueryStringDialog extends Dialog implements ActionListener
13  {
14    GridBagLayout lmInner = null;
15    Panel innerPanel = null;
16    TextArea msgArea = null;
17    TextField queryField = null;
18    Button okButton = null;
19    FlowLayout lm = null;
20    public boolean done = false;
21    public boolean ok = false;
22    static public boolean cancel = false;
23    static public boolean debug_on = false;
24    String queryString = "";
25  
26    Dimension d = new Dimension(480,240);
27  
28    QueryStringDialog(Frame parent, String title, String message, String default_string)
29    {
30      super(parent, title, true);
31      setSize(d);
32      lm = new FlowLayout(FlowLayout.LEFT);
33      setLayout(lm);
34      int text_length = 10;
35      int text_width = 40;
36      
37      try
38      {
39        Font f = getFont();
40        if(null == f)
41        {
42          Font smallFont = null;
43          smallFont = new Font("TimesRoman",Font.PLAIN, 12);
44          setFont(smallFont);
45          f = getFont();
46        }  
47        int font_height = 10;
48        int font_width = 6;
49        if(null != f)
50        {
51          FontMetrics fm = getFontMetrics(f);
52          if(null != fm)
53          {
54            font_height = fm.getHeight();
55            if(font_height < 10)
56            {
57              font_height = 10;
58            }
59            font_width = fm.stringWidth("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")/62;
60            if(font_width < 6)
61            {
62              font_width = 6;
63            }
64          }
65        }
66        if(debug_on)
67        {
68          System.out.println("font_height = "+font_height);
69          System.out.println("font_width = "+font_width);
70        }
71        text_length = d.height/font_height;
72        if(text_length < 8)
73        {
74          text_length = 8;
75        }
76        text_width = d.width/font_width;
77        if(text_width < 20)
78        {
79          text_width = 20;
80        }
81      }
82      catch(Exception e)
83      {
84        e.printStackTrace();
85      }
86      if(debug_on)
87      {
88        System.out.println("text_length = "+text_length);
89        System.out.println("text_width = "+text_width);
90      }
91      innerPanel = new Panel();
92      lmInner = new GridBagLayout();
93      innerPanel.setLayout(lmInner);
94      GridBagConstraints c = new GridBagConstraints();
95      msgArea = new TextArea(message,text_length/2,text_width -5);
96      msgArea.setEditable(false);
97      innerPanel.add(msgArea);
98      c.gridx = 0;
99      c.gridy = 0;
100     c.gridwidth = 3;
101     c.anchor = GridBagConstraints.NORTHWEST;
102     c.fill = GridBagConstraints.HORIZONTAL;
103     lmInner.setConstraints(msgArea,c);
104     if(null == default_string)
105       {
106         default_string  = "";
107       }
108     queryField = new TextField(default_string,20);
109     innerPanel.add(queryField);
110     c.gridx = 0;
111     c.gridy = 1;
112     c.gridwidth = 3;
113     lmInner.setConstraints(queryField,c);
114     queryField.requestFocus();
115     queryField.addActionListener(this);
116 
117     okButton = new Button("OK");
118     innerPanel.add(okButton);
119     c.gridx = 0;
120     c.gridy = 2;
121     c.gridwidth = 1;
122     c.fill = GridBagConstraints.NONE;
123     lmInner.setConstraints(okButton,c);
124     okButton.addActionListener(this);
125     add(innerPanel);
126     setSize(d);
127     if(debug_on)
128     {
129       System.out.println("Showing QueryStringDialog with message = "+message);
130     }
131           setVisible(true);
132   }
133 
134   public void actionPerformed(ActionEvent evt)
135   {
136     if(evt.getSource()  == okButton || evt.getSource() == queryField)
137       {
138         ok = true;
139         done = true;
140         queryString = queryField.getText();
141         dispose();
142         return;
143       }
144   }
145 
146   public Dimension getPreferredSize()
147   {
148     return d;
149   }
150 
151   public Dimension getMinimumSize()
152   {
153     return d;
154   }
155 
156 
157 
158 }
159