-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathWindowObjectListWithFilter.java
143 lines (131 loc) · 4.42 KB
/
WindowObjectListWithFilter.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright (C) 2014 Alfons Wirtz
* website www.freerouting.net
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License at <http://www.gnu.org/licenses/>
* for more details.
*
* ObjectListWindowWithFilter.java
*
* Created on 24. Maerz 2005, 10:10
*/
package gui;
/**
* Abstract class for windows displaying a list of objects
* The object name can be filttered by an alphanumeric input string. * @author Alfons Wirtz
*/
public abstract class WindowObjectListWithFilter extends WindowObjectList
{
/** Creates a new instance of ObjectListWindowWithFilter */
public WindowObjectListWithFilter(BoardFrame p_board_frame)
{
super(p_board_frame);
java.util.ResourceBundle resources =
java.util.ResourceBundle.getBundle("gui.resources.WindowObjectList", p_board_frame.get_locale());
javax.swing.JPanel input_panel = new javax.swing.JPanel();
this.south_panel.add(input_panel, java.awt.BorderLayout.SOUTH);
javax.swing.JLabel filter_label = new javax.swing.JLabel(resources.getString("filter"));
input_panel.add(filter_label, java.awt.BorderLayout.WEST);
this.filter_string = new javax.swing.JTextField(10);
this.filter_string.setText("");
input_panel.add(filter_string, java.awt.BorderLayout.EAST);
}
/**
* Adds p_object to the list only if its name matches the filter.
*/
protected void add_to_list(Object p_object)
{
String curr_filter_string = this.filter_string.getText().trim();
boolean object_matches;
if (curr_filter_string.length() == 0)
{
object_matches = true;
}
else
{
object_matches = p_object.toString().contains(curr_filter_string);
}
if (object_matches)
{
super.add_to_list(p_object);
}
}
/**
* Returns the filter text string of this window.
*/
public SnapshotInfo get_snapshot_info()
{
int [] selected_indices;
if (this.list != null)
{
selected_indices = this.list.getSelectedIndices();
}
else
{
selected_indices = new int[0];
}
return new SnapshotInfo(filter_string.getText(), selected_indices);
}
public void set_snapshot_info(SnapshotInfo p_snapshot_info)
{
if (!p_snapshot_info.filter.equals(this.filter_string.getText()))
{
this.filter_string.setText(p_snapshot_info.filter);
this.recalculate();
}
if (this.list != null && p_snapshot_info.selected_indices.length > 0)
{
this.list.setSelectedIndices(p_snapshot_info.selected_indices);
}
}
/**
* Saves also the filter string to disk.
*/
public void save(java.io.ObjectOutputStream p_object_stream)
{
try
{
p_object_stream.writeObject(filter_string.getText());
}
catch (java.io.IOException e)
{
System.out.println("WindowObjectListWithFilter.save: save failed");
}
super.save(p_object_stream);
}
public boolean read(java.io.ObjectInputStream p_object_stream)
{
try
{
String curr_string = (String) p_object_stream.readObject();
this.filter_string.setText(curr_string);
}
catch (Exception e)
{
System.out.println("WindowObjectListWithFilter.read: read failed");
}
return super.read(p_object_stream);
}
private final javax.swing.JTextField filter_string;
/**
* Information to be stored in a SnapShot.
*/
public static class SnapshotInfo implements java.io.Serializable
{
private SnapshotInfo(String p_filter, int[] p_selected_indices)
{
filter = p_filter;
selected_indices = p_selected_indices;
}
private final String filter;
private final int [] selected_indices;
}
}