use of javax.swing.JTextArea in project yyl_example by Relucent.
the class PingMain method main.
public static void main(String[] args) throws Throwable {
JFrame frame = new JFrame();
Container container = frame.getContentPane();
container.setLayout(null);
{
container.add(addComponent(new JLabel("开始IP:"), 10, 10, 60, 20));
container.add(addComponent(beginText = new JTextField(), 60, 10, 90, 20));
beginText.setText("192.168.1.1");
}
{
container.add(addComponent(new JLabel("结束IP:"), 160, 10, 60, 20));
container.add(addComponent(endText = new JTextField(), 210, 10, 90, 20));
endText.setText("192.168.1.254");
}
{
container.add(addComponent(btnExecute = new JButton("PING"), 310, 10, 75, 20));
}
{
container.add(addComponent(btnCancel = new JButton("取消"), 390, 10, 75, 20));
btnCancel.setEnabled(true);
}
{
container.add(addComponent(new JLabel("结果JSON:"), 10, 40, 100, 20));
JScrollPane scroller = addComponent(new JScrollPane(resultText = new JTextArea()), 10, 60, 460, 350);
scroller.setBorder(BorderFactory.createLineBorder(new Color(0xFF0000)));
resultText.setEditable(false);
container.add(scroller);
}
{
btnExecute.addActionListener(new ActionListener() {
//点击转换按钮时候触发
public void actionPerformed(ActionEvent event) {
(thread = new Thread() {
@Override
public void run() {
btnExecute.setEnabled(false);
beginText.setEnabled(false);
endText.setEnabled(false);
btnCancel.setEnabled(true);
try {
long begin = 0;
long end = 0;
try {
begin = getHexIp(beginText.getText());
end = getHexIp(endText.getText());
} catch (Exception e) {
e.printStackTrace();
resultText.setText("IP地址输出错误,只支持IP4!");
return;
}
if (begin < 0 || end < 0 || begin >= 4294967295L || end >= 4294967295L) {
resultText.setText("IP地址输出错误,只支持IP4.");
return;
}
if (begin > end) {
long temp = begin;
begin = end;
end = temp;
}
if (end - begin > 500) {
resultText.setText("IP地址区间过大,一次只支持500个IP");
return;
}
final ConcurrentMap<String, Boolean> map = new ConcurrentHashMap<String, Boolean>();
ExecutorService es = Executors.newFixedThreadPool(20);
final StringBuilder string = new StringBuilder();
resultText.setText("PING:");
final Lock lock = new ReentrantLock();
for (long i = begin; i <= end; i++) {
String value = Long.toHexString(i);
for (; 8 > value.length(); ) {
value = "0" + value;
}
final String ip = value = //
new StringBuilder().append(Integer.parseInt(value.substring(0, 2), 16)).append(//
".").append(Integer.parseInt(value.substring(2, 4), 16)).append(//
".").append(Integer.parseInt(value.substring(4, 6), 16)).append(//
".").append(Integer.parseInt(value.substring(6, 8), 16)).toString();
es.execute(new Runnable() {
@Override
public void run() {
Boolean result = ping(ip);
map.put(ip, result);
try {
lock.lock();
string.append("ping:").append(ip).append("|").append(result).append("\n");
resultText.setText(string.toString());
} finally {
lock.unlock();
}
}
});
}
es.shutdown();
try {
es.awaitTermination(((end - begin) * 5) / 10 + 20, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
TreeMap<String, Boolean> tmap = new TreeMap<String, Boolean>();
tmap.putAll(map);
string.delete(0, string.length());
for (Map.Entry<String, Boolean> entry : map.entrySet()) {
string.append(entry.getKey()).append(" |").append(entry.getValue()).append("\n");
resultText.setText(string.toString());
}
} catch (Exception e) {
resultText.setText(e.toString());
} finally {
btnExecute.setEnabled(true);
beginText.setEnabled(true);
endText.setEnabled(true);
btnCancel.setEnabled(true);
thread = null;
}
}
}).start();
}
;
});
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
Thread vThread = thread;
if (vThread != null) {
vThread.interrupt();
}
}
});
}
frame.setBounds(100, 100, 485, 450);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Ping");
frame.setResizable(false);
frame.setVisible(true);
}
use of javax.swing.JTextArea in project android_frameworks_base by ResurrectionRemix.
the class ShowDataAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
// TODO(agampe): Auto-generated method stub
int selRow = Main.getUI().getSelectedDataTableRow();
if (selRow != -1) {
DumpData data = dataTableModel.getData().get(selRow);
Map<String, Set<String>> inv = data.invertData();
StringBuilder builder = new StringBuilder();
// First bootclasspath.
add(builder, "Boot classpath:", inv.get(null));
// Now everything else.
for (String k : inv.keySet()) {
if (k != null) {
builder.append("==================\n\n");
add(builder, k, inv.get(k));
}
}
JFrame newFrame = new JFrame(data.getPackageName() + " " + data.getDate());
newFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
newFrame.getContentPane().add(new JScrollPane(new JTextArea(builder.toString())), BorderLayout.CENTER);
newFrame.setSize(800, 600);
newFrame.setLocationRelativeTo(null);
newFrame.setVisible(true);
}
}
use of javax.swing.JTextArea in project zaproxy by zaproxy.
the class HttpTextViewUtilsUnitTest method shouldNotAllowUndefinedViewWhenGettingHeaderToViewPosition.
@Test(expected = IllegalArgumentException.class)
public void shouldNotAllowUndefinedViewWhenGettingHeaderToViewPosition() {
// Given
JTextArea undefinedView = null;
// When
HttpTextViewUtils.getHeaderToViewPosition(undefinedView, HEADER, 0, 0);
// Then = IllegalArgumentException
}
use of javax.swing.JTextArea in project zaproxy by zaproxy.
the class HttpTextViewUtilsUnitTest method shouldReturnInvalidPositionIfOffsetStartIsGreaterThanViewLengthWhenGettingHeaderToViewPosition.
@Test
public void shouldReturnInvalidPositionIfOffsetStartIsGreaterThanViewLengthWhenGettingHeaderToViewPosition() {
// Given
JTextArea view = new JTextArea("ABC");
int start = 5;
int end = 6;
// When
int[] pos = HttpTextViewUtils.getHeaderToViewPosition(view, HEADER, start, end);
// Then
assertThat(pos, is(equalTo(HttpTextViewUtils.INVALID_POSITION)));
}
use of javax.swing.JTextArea in project zaproxy by zaproxy.
the class HttpTextViewUtilsUnitTest method shouldReturnInvalidPositionIfOffsetEndIsGreaterThanViewLengthWhenGettingHeaderToViewPosition.
@Test
public void shouldReturnInvalidPositionIfOffsetEndIsGreaterThanViewLengthWhenGettingHeaderToViewPosition() {
// Given
JTextArea view = new JTextArea("ABC");
int start = 2;
int end = 6;
// When
int[] pos = HttpTextViewUtils.getHeaderToViewPosition(view, HEADER, start, end);
// Then
assertThat(pos, is(equalTo(HttpTextViewUtils.INVALID_POSITION)));
}
Aggregations