1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.mindtree.techworks.insight.gui.search;
25
26 import java.awt.Component;
27 import java.awt.Dimension;
28 import java.awt.GridBagConstraints;
29 import java.awt.GridBagLayout;
30 import java.awt.Insets;
31 import java.awt.event.ActionEvent;
32 import java.awt.event.ActionListener;
33
34 import javax.swing.JButton;
35 import javax.swing.JDialog;
36 import javax.swing.JLabel;
37 import javax.swing.JOptionPane;
38 import javax.swing.JTextField;
39
40 import com.mindtree.techworks.insight.InsightConstants;
41 import com.mindtree.techworks.insight.eventsearch.SearchCriteria;
42 import com.mindtree.techworks.insight.gui.EventDetailsPresentation;
43 import com.mindtree.techworks.insight.gui.Insight;
44 import com.mindtree.techworks.insight.gui.widgets.StatusBar;
45
46
47
48
49
50
51
52
53
54
55 public class SearchTextFrame extends JDialog {
56
57
58
59
60 private static final long serialVersionUID = -32898128179387599L;
61
62
63
64
65 private static final int WIDTH = 300;
66 private static final int HEIGHT = 20;
67
68
69
70
71 private GridBagLayout gl;
72 private GridBagConstraints gc;
73
74
75
76
77 private JTextField searchInputField;
78
79
80
81
82 private JButton findButton;
83 private JButton closeButton;
84
85
86
87
88 private Insight insight;
89
90
91
92
93 private EventDetailsPresentation eventDetailsPresentation;
94
95
96
97
98
99 public SearchTextFrame(Insight insight, EventDetailsPresentation eventDetailsPresentation) {
100 super(JOptionPane.getFrameForComponent(insight),InsightConstants.getLiteral("FIND_TITLE"),true);
101 this.insight = insight;
102 this.eventDetailsPresentation = eventDetailsPresentation;
103 gl = new GridBagLayout();
104 gc = new GridBagConstraints();
105 getContentPane().setLayout(gl);
106
107 addComponent(new JLabel(InsightConstants.getLiteral("FIND_WHAT")),0,0,0,0,1,1);
108 searchInputField = new JTextField();
109 addComponent(searchInputField,1,0,1,0, 3, 1);
110
111 ButtionActionProcessor actionProcessor = new ButtionActionProcessor();
112 findButton = new JButton(InsightConstants.getLiteral("FIND"));
113 closeButton = new JButton(InsightConstants.getLiteral("CANCEL"));
114 findButton.addActionListener(actionProcessor);
115 closeButton.addActionListener(actionProcessor);
116 searchInputField.addActionListener(actionProcessor);
117 addComponent(findButton,0,1,0,0,1,1);
118 addComponent(closeButton,1,1,0,0,1,1);
119
120 this.searchInputField.setPreferredSize(new Dimension(WIDTH, HEIGHT));
121 }
122
123
124
125
126 public void showFrame() {
127 this.pack();
128
129 int insightX = insight.getX();
130 int insightY = insight.getY();
131 int thisX = insightX + ((this.insight.getWidth() - this.getWidth())/ 2);
132 int thisY = insightY + ((this.insight.getHeight() - this.getHeight())/ 2);
133 this.setLocation(thisX, thisY);
134 this.show();
135 }
136
137
138
139
140 public void hideFrame() {
141 this.hide();
142 }
143
144
145
146
147 private final void addComponent(Component c, int gridx, int gridy, int weightx,
148 int weighty, int width, int height) {
149 gc.fill = GridBagConstraints.BOTH;
150 gc.anchor = GridBagConstraints.NORTHWEST;
151 gc.insets = new Insets(5,5,5,5);
152 gc.gridx = gridx;
153 gc.gridy = gridy;
154 gc.weightx = weightx;
155 gc.weighty = weighty;
156 gc.gridwidth = width;
157 gc.gridheight = height;
158 gl.setConstraints( c, gc);
159 getContentPane().add(c);
160 }
161
162 private final class ButtionActionProcessor implements ActionListener {
163
164
165
166
167
168 public void actionPerformed(ActionEvent e) {
169 Object source = e.getSource();
170 if (source == findButton || source == searchInputField) {
171 String searchText = searchInputField.getText();
172 if (searchText.trim().length() == 0) {
173 StatusBar.getInstance().setDisplayText(0,InsightConstants.getLiteral("ERROR_NO_SEARCH_TEXT"),false);
174 return;
175 }
176
177
178
179 if (eventDetailsPresentation.highlightText(searchText, SearchCriteria.ALL_FIELDS_SEARCH)) {
180 hideFrame();
181 }
182 } else if (source == closeButton) {
183 hideFrame();
184 }
185 }
186 }
187 }