-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathImageTableModel.java
executable file
·149 lines (122 loc) · 3.79 KB
/
ImageTableModel.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
144
145
146
147
148
149
import javax.imageio.ImageIO;
import javax.swing.table.AbstractTableModel;
import java.awt.Image;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class ImageTableModel extends AbstractTableModel{
private ArrayList<RowElement> field_data=new ArrayList<RowElement>();
/** */
private static final long serialVersionUID = 1L;
public ImageTableModel(){
}
public void addElement(String ... path_to_image){
String unique_identifier=this.getUniqueIdentifier();
ImageIdentifier[] identifiers=new ImageIdentifier[path_to_image.length];
for(int counter=0;counter<path_to_image.length;counter++){
identifiers[counter]=new ImageIdentifier(path_to_image[counter]);
}
this.field_data.add(new RowElement(unique_identifier,identifiers));
repaint_table();
}
public void deleteElement(String unique_identifier){
int index_for_delete=this.getIndexByUniqueIdentifier(unique_identifier);
if(index_for_delete>=0){
this.field_data.remove(index_for_delete);
repaint_table();
}
}
/** repaint table for visible changing */
private void repaint_table(){
// TODO repaint Table
}
/**
* return index of RowElement into ArrayList by unique_idetifier
* @param unique_identifier óíèêàëüíûé èäåíòèôèêàòîð
* @return èíäåêñ èíèêàëüíîãî èäåíòèôèêàòîðà
*/
private int getIndexByUniqueIdentifier(String unique_identifier){
for(int counter=0;counter<field_data.size();counter++){
if(field_data.get(counter).isUniqueIdentifierEquals(unique_identifier)){
return counter;
}
}
return -1;
}
/** ãåíåðàòîð óíèêàëüíîãî èäåíòèôèêàòîðà */
private String getUniqueIdentifier(){
// TODO create generator
// check for repeat
return " ";
}
@Override
public int getColumnCount() {
return 0;
}
@Override
public int getRowCount() {
return 0;
}
@Override
public Object getValueAt(int arg0, int arg1) {
return null;
}
}
/** îáúåêò, êîòîðûé îòâå÷àåò çà ïîëó÷åíèå èçîáðàæåíèÿ */
class ImageIdentifier{
private String field_path_to_image;
private Image field_image_full;
private Image field_image_thumb;
public ImageIdentifier(String path_to_image){
this.field_path_to_image=path_to_image;
field_image_full=this.getImageFromPath(path_to_image);
field_image_thumb=this.getThumbFromImage(field_image_full);
}
public String getPathImage(){
return this.field_path_to_image;
}
private Image getImageFromPath(String path_to_image){
try{
return ImageIO.read(new File(path_to_image));
}catch(IOException ex){
return null;
}
}
private Image getThumbFromImage(Image full_image){
//TODO create cut image
return full_image;
}
public Image getImage(){
return field_image_full;
}
public Image getThumbImage(){
return field_image_thumb;
}
}
/** ýëåìåíò, êîòîðûé ñîäåðæèò èçîáðàæåíèå è óíèêàëüíûé èäåíòèôèêàòîð */
class RowElement{
/** îáúåêò, ñîäåðæàùèé óíèêàëüíûé èäåíòèôèêàòîð */
private String field_unique_identifier;
/** îáúåêò, ñîäåðæàùèé èçîáðàæåíèÿ */
private ImageIdentifier[] field_image_identifier;
/** Ýëåìåíò èç ñòðîêè òàáëèöû
* @param unique_identifier - óíèêàëüíûé èäåíòèôèêàòîð
* @param identifier èäåíòèôèêàòîðû èçîáðàæåíèé
*
* */
public RowElement(String unique_identifier,
ImageIdentifier ... identifiers){
this.field_unique_identifier=unique_identifier;
this.field_image_identifier=identifiers;
}
public ImageIdentifier[] getIdentifier(){
return this.field_image_identifier;
}
/** ïðîâåðêà íà equals óíèêàëüíîãî èäåíòèôèêàòîðà
* @param value èäåíòèôèêàòîð äëÿ ïðîâåðêè
* @return true - åñëè èäåíòèôèêàòîðû ñîâïàäàþò
* */
public boolean isUniqueIdentifierEquals(String value){
return field_unique_identifier.equals(value);
}
}