-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
599 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package messageTab.Info; | ||
|
||
import com.google.gson.Gson; | ||
|
||
public class InfoEntry { | ||
|
||
private String value = ""; | ||
private String type = ""; | ||
private boolean enable = true; | ||
private boolean editable = true;//whether you can edit name and type | ||
private String comment = ""; | ||
|
||
public static final String Type_URL ="Type_URL"; | ||
public static final String Type_Email ="Type_Email"; | ||
|
||
public InfoEntry() { | ||
//to resolve "default constructor not found" error | ||
} | ||
|
||
public InfoEntry(String value, String type, boolean enable) { | ||
this.value = value; | ||
this.type = type; | ||
this.enable = enable; | ||
} | ||
|
||
public InfoEntry(String value, String type, boolean enable, boolean editable) { | ||
this.value = value; | ||
this.type = type; | ||
this.enable = enable; | ||
this.editable = editable; | ||
} | ||
|
||
public InfoEntry(String value, String type, boolean enable, boolean editable, String comment) { | ||
this.value = value; | ||
this.type = type; | ||
this.enable = enable; | ||
this.editable = editable; | ||
this.comment = comment; | ||
} | ||
|
||
|
||
|
||
public String getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(String value) { | ||
this.value = value; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public boolean isEnable() { | ||
return enable; | ||
} | ||
|
||
public void setEnable(boolean enable) { | ||
this.enable = enable; | ||
} | ||
|
||
public boolean isEditable() { | ||
return editable; | ||
} | ||
|
||
public void setEditable(boolean editable) { | ||
this.editable = editable; | ||
} | ||
|
||
public String getComment() { | ||
return comment; | ||
} | ||
|
||
public void setComment(String comment) { | ||
this.comment = comment; | ||
} | ||
|
||
public String ToJson() {//注意函数名称,如果是get set开头,会被认为是Getter和Setter函数,会在序列化过程中被调用。 | ||
return new Gson().toJson(this); | ||
} | ||
|
||
public InfoEntry FromJson(String json) {//注意函数名称,如果是get set开头,会被认为是Getter和Setter函数,会在序列化过程中被调用。 | ||
return new Gson().fromJson(json, InfoEntry.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
package messageTab.Info; | ||
|
||
import java.awt.BorderLayout; | ||
import java.awt.FlowLayout; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
|
||
import javax.swing.JButton; | ||
import javax.swing.JComponent; | ||
import javax.swing.JFrame; | ||
import javax.swing.JLabel; | ||
import javax.swing.JPanel; | ||
import javax.swing.JScrollPane; | ||
import javax.swing.JTextField; | ||
import javax.swing.SwingUtilities; | ||
import javax.swing.Timer; | ||
import javax.swing.border.EmptyBorder; | ||
import javax.swing.event.DocumentEvent; | ||
import javax.swing.event.DocumentListener; | ||
|
||
public class InfoPanel extends JPanel { | ||
|
||
private final JTextField searchField; | ||
private final JLabel statusLabel = new JLabel(" 0 matches"); | ||
boolean isRequest; | ||
private final JComponent parent; | ||
|
||
|
||
InfoPanel(JComponent parent) { | ||
|
||
this.parent = parent; | ||
setBorder(new EmptyBorder(5, 5, 5, 5)); | ||
setLayout(new BorderLayout(0, 0)); | ||
|
||
JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); | ||
add(buttonPanel, BorderLayout.NORTH); | ||
|
||
InfoTableModel model = new InfoTableModel(); | ||
InfoTable table = new InfoTable(model); | ||
JScrollPane scrollPane = new JScrollPane(); | ||
scrollPane.add(table); | ||
add(scrollPane, BorderLayout.CENTER); | ||
|
||
|
||
|
||
JPanel footPanel = new JPanel(new BorderLayout()); | ||
searchField = new JTextField(); | ||
Timer searchTimer = createSearchTimer(); | ||
searchField.getDocument().addDocumentListener(new DocumentListener() { | ||
@Override | ||
public void insertUpdate(DocumentEvent e) { | ||
searchTimer.restart(); | ||
} | ||
|
||
@Override | ||
public void removeUpdate(DocumentEvent e) { | ||
searchTimer.restart(); | ||
} | ||
|
||
@Override | ||
public void changedUpdate(DocumentEvent e) { | ||
searchTimer.restart(); | ||
} | ||
}); | ||
|
||
JButton leftButton = new JButton("<"); | ||
leftButton.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
} | ||
}); | ||
JButton rightButton = new JButton(">"); | ||
rightButton.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
} | ||
}); | ||
JPanel panelA = new JPanel(); | ||
panelA.add(leftButton); | ||
panelA.add(rightButton); | ||
|
||
footPanel.add(panelA, BorderLayout.WEST); | ||
footPanel.add(searchField, BorderLayout.CENTER); | ||
|
||
footPanel.add(statusLabel, BorderLayout.EAST); | ||
|
||
add(footPanel, BorderLayout.SOUTH); | ||
} | ||
|
||
|
||
private Timer createSearchTimer() { | ||
Timer searchTimer = new Timer(1000, new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
// 执行搜索操作 | ||
String searchTerm = searchField.getText(); | ||
//search(searchTerm, false, false); | ||
} | ||
}); | ||
searchTimer.setRepeats(false); // 设置计时器只执行一次 | ||
return searchTimer; | ||
} | ||
/* | ||
private void search(String searchTerm, boolean isRegex, boolean isCaseSensitive) { | ||
if (searchTerm.isEmpty()) { | ||
return; | ||
} | ||
int flags = 0; | ||
if (!isCaseSensitive) { | ||
flags |= Pattern.CASE_INSENSITIVE; | ||
} | ||
Pattern pattern; | ||
if (isRegex) { | ||
pattern = Pattern.compile(searchTerm, flags); | ||
Matcher matcher = pattern.matcher(text); | ||
while (matcher.find()) { | ||
int start = matcher.start(); | ||
int end = matcher.end(); | ||
try { | ||
highlighter.addHighlight(start, end, new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW)); | ||
} catch (BadLocationException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} else { | ||
int index = text.indexOf(searchTerm); | ||
while (index != -1) { | ||
try { | ||
textArea.getHighlighter().addHighlight(index, index + searchTerm.length(), new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW)); | ||
index = text.indexOf(searchTerm, index + searchTerm.length()); // 继续搜索下一个匹配项 | ||
} catch (BadLocationException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} | ||
int num = textArea.getHighlighter().getHighlights().length; | ||
statusLabel.setText(" " + num + " matches"); | ||
}*/ | ||
|
||
|
||
|
||
public static void main(String[] args) { | ||
SwingUtilities.invokeLater(new Runnable() { | ||
@Override | ||
public void run() { | ||
JFrame jf = new JFrame(); | ||
InfoPanel panel = new InfoPanel(null); | ||
jf.setContentPane(panel); | ||
jf.setVisible(true); | ||
jf.pack(); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.