gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / DefaultZoomDialog.java @ 1698
History | View | Annotate | Download (3.27 KB)
1 | 1698 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | package org.gvsig.tools.swing.impl; |
||
25 | |||
26 | import java.awt.BorderLayout; |
||
27 | import java.awt.Dialog; |
||
28 | import java.awt.Dimension; |
||
29 | import java.awt.Toolkit; |
||
30 | import java.awt.event.ActionEvent; |
||
31 | import java.awt.event.ActionListener; |
||
32 | |||
33 | import javax.swing.BorderFactory; |
||
34 | import javax.swing.JButton; |
||
35 | import javax.swing.JDialog; |
||
36 | import javax.swing.JPanel; |
||
37 | import javax.swing.JScrollPane; |
||
38 | import javax.swing.JTextArea; |
||
39 | |||
40 | public class DefaultZoomDialog extends JDialog { |
||
41 | |||
42 | /**
|
||
43 | *
|
||
44 | */
|
||
45 | private static final long serialVersionUID = 7913363575200612492L; |
||
46 | |||
47 | private String value = null; |
||
48 | private JTextArea text = null; |
||
49 | |||
50 | public DefaultZoomDialog(String title) { |
||
51 | super((Dialog) null, title, true); |
||
52 | } |
||
53 | |||
54 | public DefaultZoomDialog(String title, String value) { |
||
55 | this(title);
|
||
56 | this.value = value;
|
||
57 | initComponents(); |
||
58 | |||
59 | } |
||
60 | |||
61 | public void setEditable(boolean editable) { |
||
62 | this.text.setEditable(editable);
|
||
63 | } |
||
64 | |||
65 | private void initComponents() { |
||
66 | |||
67 | JPanel panel = new JPanel(); |
||
68 | panel.setLayout(new BorderLayout()); |
||
69 | |||
70 | text = new JTextArea(); |
||
71 | text.setText(value); |
||
72 | text.setLineWrap(true);
|
||
73 | JScrollPane scroll = new JScrollPane(text); |
||
74 | panel.add(scroll, BorderLayout.CENTER);
|
||
75 | panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
||
76 | |||
77 | JPanel p = new JPanel(); |
||
78 | |||
79 | JButton close = new JButton("Close"); |
||
80 | close.addActionListener(new ActionListener() { |
||
81 | @Override
|
||
82 | public void actionPerformed(ActionEvent arg0) { |
||
83 | value = text.getText(); |
||
84 | setVisible(false);
|
||
85 | } |
||
86 | }); |
||
87 | |||
88 | p.setLayout(new BorderLayout()); |
||
89 | p.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
||
90 | p.add(close, BorderLayout.LINE_END);
|
||
91 | |||
92 | panel.add(p, BorderLayout.PAGE_END);
|
||
93 | |||
94 | panel.setPreferredSize(new Dimension(600, 250)); |
||
95 | |||
96 | this.setContentPane(panel);
|
||
97 | |||
98 | this.center();
|
||
99 | this.pack();
|
||
100 | } |
||
101 | |||
102 | public void center() { |
||
103 | Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); |
||
104 | Dimension size = this.getPreferredSize(); |
||
105 | int x = (int) ((dimension.getWidth() - size.getWidth()) / 2); |
||
106 | int y = (int) ((dimension.getHeight() - size.getHeight()) / 2); |
||
107 | this.setLocation(x, y);
|
||
108 | } |
||
109 | |||
110 | public String getText() { |
||
111 | return this.value; |
||
112 | } |
||
113 | } |