-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathResEditIndex.java
More file actions
117 lines (95 loc) · 3.12 KB
/
ResEditIndex.java
File metadata and controls
117 lines (95 loc) · 3.12 KB
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
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.RowSorter;
import javax.swing.SortOrder;
public class ResEditIndex extends JFrame
{
private static final long serialVersionUID = -766099048104505721L;
private JScrollPane scrollpane;
ResEdit TypeIndexEditor;
OStack stack;
private String[] columnNames = {"Type", "Count"};
public ResEditIndex(PCARDFrame parent)
{
super();
stack = parent.stack;
setTitle("Resource Editor");
//テーブルを用意
String[][] tabledata = { {"", ""} };
JTable table = new JTable(tabledata, columnNames);
//table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setEnabled(false);
//table.setDefaultRenderer(Object.class, new MultiLineCellRenderer());
//スクロール
scrollpane = new JScrollPane(table);
add(scrollpane);
setTable(stack.rsrc);
//ウィンドウ位置とサイズ設定
setBounds(0,0,560,480);
setLocationRelativeTo(parent);
setVisible(true);
}
JTable table;
String[][] tabledata;
public void setTable(Rsrc rsrc){
ArrayList<Integer> countList = new ArrayList<Integer>();
ArrayList<String> typeList = new ArrayList<String>();
Iterator<Rsrc.rsrcClass> it = rsrc.rsrcIdMap.values().iterator();
while(it.hasNext()){
Rsrc.rsrcClass r = it.next();
if(typeList.contains(r.type)){
int i = typeList.indexOf(r.type);
int count = countList.get(i);
countList.set(i, count+1);
}
else{
typeList.add(r.type);
countList.add(1);
}
}
tabledata = new String[typeList.size()][2];
int i;
for(i=0; i<typeList.size(); i++){
tabledata[i][0] = typeList.get(i);
tabledata[i][1] = Integer.toString(countList.get(i));
}
table = new JTable(tabledata, columnNames);
//table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.setEnabled(false);
table.setDefaultRenderer(Object.class, new MultiLineCellRenderer());
table.setAutoCreateRowSorter(true);
ArrayList<RowSorter.SortKey> s = new ArrayList<RowSorter.SortKey>();
s.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
table.getRowSorter().setSortKeys(s);
table.addMouseListener(new MouseAdapter() {
@Override public void mouseClicked(final MouseEvent me) {
if(me.getClickCount()==2) {
Point pt = me.getPoint();
int idx = table.rowAtPoint(pt);
if(idx>=0) {
int row = table.convertRowIndexToModel(idx);
new ResEdit(stack.pcard, tabledata[row][0], null);
}
}
}
});
Rectangle rect = scrollpane.getBounds();
int scroll = scrollpane.getVerticalScrollBar().getValue();
remove(scrollpane);
scrollpane = new JScrollPane(table);
add(scrollpane);
scrollpane.getVerticalScrollBar().setValue(scroll);
/*scrollpane.removeAll();
scrollpane.add(table);
scrollpane.setViewportView(table);*/
scrollpane.setBounds(rect);
//repaint();
}
}