Exemplo n.º 1
0
  public JPanel createTabButton(final Tab tab) {
    final JPanel panel = new JPanel();
    final JButton button = new JButton("Bot");
    final JPopupMenu closeMenu = new JPopupMenu();
    final JMenuItem closeItem = new JMenuItem("Close");

    button.setIcon(Configuration.icon("res/icon_tab_small.png"));
    button.setBounds(0, 0, 84, 24);
    button.setFocusable(false);
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateTabs(tab);
          }
        });
    button.addMouseListener(
        new MouseAdapter() {
          public void mousePressed(MouseEvent e) {
            checkForTriggerEvent(e);
          }

          public void mouseReleased(MouseEvent e) {
            checkForTriggerEvent(e);
          }

          private void checkForTriggerEvent(MouseEvent e) {
            if (e.isPopupTrigger()) {
              closeMenu.show(e.getComponent(), e.getX(), e.getY());
            }
          }
        });

    closeItem.addActionListener(
        new ActionListener() {
          @SuppressWarnings("deprecation")
          public void actionPerformed(ActionEvent e) {
            closeTab(tab);
            tab.getContent().getApplet().stop();
            tab.getContent().getApplet().destroy();
            tab.getContent().getBot().getThread().interrupt();
            tab.getContent().getBot().getThread().stop();
          }
        });
    closeMenu.add(closeItem);

    panel.setPreferredSize(new Dimension(84, 32));
    panel.setMinimumSize(new Dimension(84, 32));
    panel.setMaximumSize(new Dimension(84, 32));
    panel.setLayout(null);
    panel.add(button);
    return panel;
  }
Exemplo n.º 2
0
  private void fetch(String res) throws IOException {
    URL url = new URL(Configuration.composeres() + res);
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod("GET");
    con.setDoInput(true);
    con.setConnectTimeout(5000);
    con.setRequestProperty(
        "User-Agent",
        "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11");

    ReadableByteChannel rbc = Channels.newChannel(con.getInputStream());
    FileOutputStream fos = new FileOutputStream(Configuration.STORAGE_DIR + File.separator + res);
    fos.getChannel().transferFrom(rbc, 0, 1 << 24);
    fos.close();
    rbc.close();
  }