예제 #1
0
  public Container CreateContentPane() {
    // Create the content-pane-to-be.
    JPanel contentPane = new JPanel(new BorderLayout());
    contentPane.setOpaque(true);

    // the log panel
    log = new JTextPane();
    log.setEditable(false);
    log.setBackground(Color.BLACK);
    logPane = new JScrollPane(log);
    kit = new HTMLEditorKit();
    doc = new HTMLDocument();
    log.setEditorKit(kit);
    log.setDocument(doc);
    DefaultCaret c = (DefaultCaret) log.getCaret();
    c.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
    ClearLog();

    // the preview panel
    previewPane = new DrawPanel();
    previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right);

    // status bar
    statusBar = new StatusBar();
    Font f = statusBar.getFont();
    statusBar.setFont(f.deriveFont(Font.BOLD, 15));
    Dimension d = statusBar.getMinimumSize();
    d.setSize(d.getWidth(), d.getHeight() + 30);
    statusBar.setMinimumSize(d);

    // layout
    Splitter split = new Splitter(JSplitPane.VERTICAL_SPLIT);
    split.add(previewPane);
    split.add(logPane);
    split.setDividerSize(8);

    contentPane.add(statusBar, BorderLayout.SOUTH);
    contentPane.add(split, BorderLayout.CENTER);

    // open the file
    if (recentFiles[0].length() > 0) {
      OpenFileOnDemand(recentFiles[0]);
    }

    // connect to the last port
    ListSerialPorts();
    if (Arrays.asList(portsDetected).contains(recentPort)) {
      OpenPort(recentPort);
    }

    return contentPane;
  }
예제 #2
0
 public void setCaretPosition(int position) {
   Caret c = textView.getCaret();
   // move the caret
   c.setDot(position);
 }
예제 #3
0
 public int getCaretPosition() {
   Caret c = textView.getCaret();
   return c.getDot();
 }
예제 #4
0
  /** Create panel at the bottom with differents consoles to report injection process. */
  public PanelBottom() {
    // Object creation after customization
    this.consoleTab.getProxy().setEditable(false);
    SwingAppender.register(this.consoleTab);

    this.chunkTab = new JPopupTextArea().getProxy();
    this.chunkTab.setEditable(false);

    this.binaryTab = new JPopupTextArea().getProxy();
    this.binaryTab.setEditable(false);

    this.javaTab.getProxy().setEditable(false);
    SwingAppender.register(this.javaTab);

    this.network = new JSplitPaneWithZeroSizeDivider();
    this.network.setResizeWeight(1);
    this.network.setDividerSize(0);
    this.network.setDividerLocation(600);
    this.network.setBorder(BorderFactory.createMatteBorder(1, 1, 0, 0, HelperGUI.COMPONENT_BORDER));
    this.networkTable =
        new JTable(0, 4) {
          @Override
          public boolean isCellEditable(int row, int column) {
            return false;
          }

          @Override
          public String getToolTipText(MouseEvent e) {
            String tip = null;
            java.awt.Point p = e.getPoint();
            int rowIndex = rowAtPoint(p);
            int colIndex = columnAtPoint(p);

            try {
              // comment row, exclude heading
              if (rowIndex != 0 && colIndex == 1) {
                tip = getValueAt(rowIndex, colIndex).toString();
              }
            } catch (RuntimeException e1) {
              // catch null pointer exception if mouse is over an empty line
            }

            return "<html><p width=\"1024\">" + tip + "</p></html>";
          }
        };

    new TableFilterHeader(this.networkTable, AutoChoices.ENABLED);

    this.networkTable.setComponentPopupMenu(new JPopupMenuTable(this.networkTable));
    this.networkTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    this.networkTable.setRowSelectionAllowed(true);
    this.networkTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    this.networkTable.setRowHeight(20);
    this.networkTable.setGridColor(Color.LIGHT_GRAY);
    this.networkTable.getTableHeader().setReorderingAllowed(false);

    this.networkTable.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            PanelBottom.this.networkTable.requestFocusInWindow();
            // move selected row and place cursor on focused cell
            if (SwingUtilities.isRightMouseButton(e)) {
              Point p = e.getPoint();

              // get the row index that contains that coordinate
              int rowNumber = PanelBottom.this.networkTable.rowAtPoint(p);
              int colNumber = PanelBottom.this.networkTable.columnAtPoint(p);
              // Get the ListSelectionModel of the JTable
              DefaultListSelectionModel model =
                  (DefaultListSelectionModel) PanelBottom.this.networkTable.getSelectionModel();
              DefaultListSelectionModel model2 =
                  (DefaultListSelectionModel)
                      PanelBottom.this.networkTable.getColumnModel().getSelectionModel();

              PanelBottom.this.networkTable.setRowSelectionInterval(rowNumber, rowNumber);
              model.moveLeadSelectionIndex(rowNumber);
              model2.moveLeadSelectionIndex(colNumber);
            }
          }
        });

    this.networkTable.setModel(
        new DefaultTableModel() {
          private String[] columns = {
            I18n.NETWORK_TAB_METHOD_COLUMN,
            I18n.NETWORK_TAB_URL_COLUMN,
            I18n.NETWORK_TAB_SIZE_COLUMN,
            I18n.NETWORK_TAB_TYPE_COLUMN
          };

          @Override
          public int getColumnCount() {
            return this.columns.length;
          }

          @Override
          public String getColumnName(int index) {
            return this.columns[index];
          }
        });

    class CenterRenderer extends DefaultTableCellRenderer {
      public CenterRenderer() {
        this.setHorizontalAlignment(JLabel.CENTER);
      }
    }

    DefaultTableCellRenderer centerHorizontalAlignment = new CenterRenderer();
    this.networkTable.getColumnModel().getColumn(2).setCellRenderer(centerHorizontalAlignment);
    this.networkTable.getColumnModel().getColumn(3).setCellRenderer(centerHorizontalAlignment);

    this.networkTable
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), null);
    this.networkTable
        .getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_DOWN_MASK), null);

    Set<AWTKeyStroke> forward =
        new HashSet<AWTKeyStroke>(
            this.networkTable.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    forward.add(KeyStroke.getKeyStroke("TAB"));
    this.networkTable.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, forward);
    Set<AWTKeyStroke> backward =
        new HashSet<AWTKeyStroke>(
            this.networkTable.getFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));
    backward.add(KeyStroke.getKeyStroke("shift TAB"));
    this.networkTable.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, backward);

    final TableCellRenderer tcrOs = this.networkTable.getTableHeader().getDefaultRenderer();
    this.networkTable
        .getTableHeader()
        .setDefaultRenderer(
            new TableCellRenderer() {
              @Override
              public Component getTableCellRendererComponent(
                  JTable table,
                  Object value,
                  boolean isSelected,
                  boolean hasFocus,
                  int row,
                  int column) {
                JLabel lbl =
                    (JLabel)
                        tcrOs.getTableCellRendererComponent(
                            table, value, isSelected, hasFocus, row, column);
                lbl.setBorder(
                    BorderFactory.createCompoundBorder(
                        BorderFactory.createMatteBorder(0, 0, 1, 1, Color.LIGHT_GRAY),
                        BorderFactory.createEmptyBorder(0, 5, 0, 5)));
                return lbl;
              }
            });

    JScrollIndicator scroller = new JScrollIndicator(this.networkTable);
    scroller.scrollPane.setBorder(BorderFactory.createEmptyBorder(0, 0, -1, -1));
    scroller.scrollPane.setViewportBorder(BorderFactory.createEmptyBorder(0, 0, -1, -1));
    this.network.setLeftComponent(scroller);

    MouseTabbedPane networkDetailTabs = new MouseTabbedPane();
    networkDetailTabs.addTab(
        I18n.NETWORK_TAB_RESPONSE_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabResponse));
    networkDetailTabs.addTab(
        I18n.NETWORK_TAB_SOURCE_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabSource));
    networkDetailTabs.addTab(
        I18n.NETWORK_TAB_PREVIEW_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabPreview));
    networkDetailTabs.addTab(
        I18n.NETWORK_TAB_HEADERS_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabHeader));
    networkDetailTabs.addTab(
        I18n.NETWORK_TAB_COOKIES_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabCookie));
    networkDetailTabs.addTab(
        I18n.NETWORK_TAB_PARAMS_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabParam));
    networkDetailTabs.addTab(
        I18n.NETWORK_TAB_TIMING_LABEL, new LightScrollPane(1, 1, 0, 0, networkTabTiming));

    DefaultCaret caret = (DefaultCaret) networkTabResponse.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    caret = (DefaultCaret) networkTabSource.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    caret = (DefaultCaret) networkTabPreview.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    caret = (DefaultCaret) networkTabHeader.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    caret = (DefaultCaret) networkTabCookie.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    caret = (DefaultCaret) networkTabParam.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
    caret = (DefaultCaret) networkTabTiming.getCaret();
    caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);

    networkTabHeader.setLineWrap(true);
    networkTabCookie.setLineWrap(true);
    networkTabParam.setLineWrap(true);
    networkTabResponse.setLineWrap(true);
    networkTabTiming.setLineWrap(true);
    networkTabSource.setLineWrap(true);

    networkTabPreview.setContentType("text/html");
    networkTabPreview.setEditable(false);

    this.networkTable.getColumnModel().getColumn(0).setResizable(false);
    this.networkTable.getColumnModel().getColumn(0).setPreferredWidth(120);
    this.networkTable.getColumnModel().getColumn(0).setMinWidth(120);
    this.networkTable.getColumnModel().getColumn(0).setMaxWidth(120);

    this.networkTable.getColumnModel().getColumn(2).setResizable(false);
    this.networkTable.getColumnModel().getColumn(2).setPreferredWidth(45);
    this.networkTable.getColumnModel().getColumn(2).setMinWidth(45);
    this.networkTable.getColumnModel().getColumn(2).setMaxWidth(45);

    this.networkTable.getColumnModel().getColumn(3).setResizable(false);
    this.networkTable.getColumnModel().getColumn(3).setPreferredWidth(85);
    this.networkTable.getColumnModel().getColumn(3).setMinWidth(85);
    this.networkTable.getColumnModel().getColumn(3).setMaxWidth(85);

    this.networkTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent event) {
                // prevent double event
                if (!event.getValueIsAdjusting()
                    && PanelBottom.this.networkTable.getSelectedRow() > -1) {
                  networkTabHeader.setText(
                      listHTTPHeader
                          .get(PanelBottom.this.networkTable.getSelectedRow())
                          .getHeader());
                  networkTabCookie.setText(
                      listHTTPHeader
                          .get(PanelBottom.this.networkTable.getSelectedRow())
                          .getCookie());
                  networkTabParam.setText(
                      listHTTPHeader.get(PanelBottom.this.networkTable.getSelectedRow()).getPost());

                  networkTabResponse.setText("");
                  for (String key :
                      listHTTPHeader
                          .get(PanelBottom.this.networkTable.getSelectedRow())
                          .getResponse()
                          .keySet()) {
                    networkTabResponse.append(
                        key
                            + ": "
                            + listHTTPHeader
                                .get(PanelBottom.this.networkTable.getSelectedRow())
                                .getResponse()
                                .get(key));
                    networkTabResponse.append("\n");
                  }

                  networkTabTiming.setText("?");
                  networkTabSource.setText(
                      listHTTPHeader.get(PanelBottom.this.networkTable.getSelectedRow()).source);
                  networkTabPreview.setText(
                      "<html>"
                          + listHTTPHeader.get(PanelBottom.this.networkTable.getSelectedRow())
                              .source
                          + "</html>");
                }
              }
            });

    this.network.setRightComponent(networkDetailTabs);

    MediatorGUI.register(new AdapterBottomTabbedPane());
    MediatorGUI.bottom().setBorder(BorderFactory.createEmptyBorder(1, 1, 0, 0));
    MediatorGUI.bottom().setMinimumSize(new Dimension());

    MediatorGUI.bottom()
        .addTab(
            "Console",
            new ImageIcon(getClass().getResource("/com/jsql/view/swing/images/console.gif")),
            new LightScrollPane(1, 1, 0, 0, this.consoleTab.getProxy()),
            I18n.CONSOLE_TAB_TOOLTIP);
    MediatorGUI.bottom()
        .setTabComponentAt(
            MediatorGUI.bottom().indexOfTab("Console"),
            new JLabel(
                I18n.CONSOLE_TAB_LABEL,
                new ImageIcon(getClass().getResource("/com/jsql/view/swing/images/console.gif")),
                SwingConstants.CENTER));

    // Order is important
    Preferences prefs = Preferences.userRoot().node(InjectionModel.class.getName());
    if (prefs.getBoolean(HelperGUI.JAVA_VISIBLE, false)) {
      this.insertJavaDebugTab();
    }
    if (prefs.getBoolean(HelperGUI.NETWORK_VISIBLE, true)) {
      this.insertNetworkTab();
    }
    if (prefs.getBoolean(HelperGUI.CHUNK_VISIBLE, true)) {
      this.insertChunkTab();
    }
    if (prefs.getBoolean(HelperGUI.BINARY_VISIBLE, true)) {
      this.insertBinaryTab();
    }

    MediatorGUI.bottom()
        .addChangeListener(
            new ChangeListener() {
              @Override
              public void stateChanged(ChangeEvent arg0) {
                JTabbedPane tabs = MediatorGUI.bottom();
                if (tabs.getSelectedIndex() > -1) {
                  Component currentTabHeader = tabs.getTabComponentAt(tabs.getSelectedIndex());
                  if (currentTabHeader != null) {
                    currentTabHeader.setFont(currentTabHeader.getFont().deriveFont(Font.PLAIN));
                  }
                }
              }
            });

    this.setLayout(new OverlayLayout(this));

    BasicArrowButton showBottomButton = new BasicArrowButton(BasicArrowButton.SOUTH);
    showBottomButton.setBorderPainted(false);
    showBottomButton.setPreferredSize(showBottomButton.getPreferredSize());
    showBottomButton.setMaximumSize(showBottomButton.getPreferredSize());

    showBottomButton.addActionListener(PanelLeftRightBottom.HIDESHOWPANEL);

    JPanel arrowDownPanel = new JPanel();
    arrowDownPanel.setLayout(new BoxLayout(arrowDownPanel, BoxLayout.PAGE_AXIS));
    arrowDownPanel.setOpaque(false);
    showBottomButton.setOpaque(false);
    // Disable overlap with zerosizesplitter
    arrowDownPanel.setBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0));
    arrowDownPanel.setPreferredSize(new Dimension(17, 27));
    arrowDownPanel.setMaximumSize(new Dimension(17, 27));
    arrowDownPanel.add(showBottomButton);
    this.add(arrowDownPanel);
    this.add(MediatorGUI.bottom());

    // Do Overlay
    arrowDownPanel.setAlignmentX(1.0f);
    arrowDownPanel.setAlignmentY(0.0f);
    MediatorGUI.bottom().setAlignmentX(1.0f);
    MediatorGUI.bottom().setAlignmentY(0.0f);

    this.chunkTab.setLineWrap(true);
    this.binaryTab.setLineWrap(true);
  }