Search in sources :

Example 41 with JTextArea

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);
}
Also used : JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) Container(java.awt.Container) JFrame(javax.swing.JFrame) JScrollPane(javax.swing.JScrollPane) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Color(java.awt.Color) ConcurrentMap(java.util.concurrent.ConcurrentMap) JLabel(javax.swing.JLabel) TreeMap(java.util.TreeMap) IOException(java.io.IOException) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Lock(java.util.concurrent.locks.Lock) ActionListener(java.awt.event.ActionListener) ExecutorService(java.util.concurrent.ExecutorService)

Example 42 with JTextArea

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);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) Set(java.util.Set) JTextArea(javax.swing.JTextArea) JFrame(javax.swing.JFrame) DumpData(com.android.preload.DumpData)

Example 43 with JTextArea

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
}
Also used : JTextArea(javax.swing.JTextArea) Test(org.junit.Test)

Example 44 with JTextArea

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)));
}
Also used : JTextArea(javax.swing.JTextArea) Test(org.junit.Test)

Example 45 with JTextArea

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)));
}
Also used : JTextArea(javax.swing.JTextArea) Test(org.junit.Test)

Aggregations

JTextArea (javax.swing.JTextArea)158 JScrollPane (javax.swing.JScrollPane)92 JPanel (javax.swing.JPanel)68 JButton (javax.swing.JButton)55 BorderLayout (java.awt.BorderLayout)52 JLabel (javax.swing.JLabel)50 JFrame (javax.swing.JFrame)31 Dimension (java.awt.Dimension)29 JTextField (javax.swing.JTextField)28 ActionEvent (java.awt.event.ActionEvent)26 ActionListener (java.awt.event.ActionListener)22 Font (java.awt.Font)19 Color (java.awt.Color)18 FlowLayout (java.awt.FlowLayout)18 GridBagLayout (java.awt.GridBagLayout)17 Insets (java.awt.Insets)17 GridBagConstraints (java.awt.GridBagConstraints)16 Container (java.awt.Container)15 EmptyBorder (javax.swing.border.EmptyBorder)15 JCheckBox (javax.swing.JCheckBox)14