Exemple #1
2
  /**
   * This method initializes jTextPane
   *
   * @return javax.swing.JTextPane
   */
  private JTextPane getJTextPane() {
    if (jTextPane == null) {
      jTextPane = new JTextPane();
      jTextPane.setEditorKit(new HTMLEditorKit());
      HTMLDocument doc =
          new HTMLDocument() {
            private static final long serialVersionUID = 1L;

            @Override
            public Font getFont(AttributeSet attr) {
              Object family = attr.getAttribute(StyleConstants.FontFamily);
              Object size = attr.getAttribute(StyleConstants.FontSize);
              if (family == null && size == null) {
                return new Font("SansSerif", Font.PLAIN, currentFontSize);
              }
              return super.getFont(attr);
            }
          };
      doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);
      doc.setPreservesUnknownTags(false);
      jTextPane.setStyledDocument(doc);
      jTextPane.setEditable(false);
    }
    return jTextPane;
  }
  public void showItem() {

    if (!this.editorPanel.getViewer().isLanguageFunctionAvailable()) {

      return;
    }

    this.highlight =
        this.editorPanel
            .getEditor()
            .addHighlight(this.position, this.position + this.word.length(), null, true);

    final FindSynonymsActionHandler _this = this;

    QTextEditor editor = this.editorPanel.getEditor();

    Rectangle r = null;

    try {

      r = editor.modelToView(this.position);

    } catch (Exception e) {

      // BadLocationException!
      Environment.logError("Location: " + this.position + " is not valid", e);

      UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

      return;
    }

    int y = r.y;

    // Show a panel of all the items.
    final QPopup p = this.popup;

    p.setOpaque(false);

    Synonyms syns = null;

    try {

      syns = this.projectViewer.getSynonymProvider().getSynonyms(this.word);

    } catch (Exception e) {

      UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

      Environment.logError("Unable to lookup synonyms for: " + word, e);

      return;
    }

    if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("ed"))) {

      // Trim off the ed and try again.
      try {

        syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 2));

      } catch (Exception e) {

        UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

        Environment.logError("Unable to lookup synonyms for: " + word, e);

        return;
      }
    }

    if ((syns.words.size() == 0) && (this.word.toLowerCase().endsWith("s"))) {

      // Trim off the ed and try again.
      try {

        syns = this.projectViewer.getSynonyms(this.word.substring(0, this.word.length() - 1));

      } catch (Exception e) {

        UIUtils.showErrorMessage(this.editorPanel, "Unable to display synonyms.");

        Environment.logError("Unable to lookup synonyms for: " + word, e);

        return;
      }
    }

    StringBuilder sb = new StringBuilder();

    if (syns.words.size() > 0) {

      sb.append("6px");

      for (int i = 0; i < syns.words.size(); i++) {

        if (sb.length() > 0) {

          sb.append(", ");
        }

        sb.append("p, 3px, [p,90px], 5px");
      }
      /*
                if (syns.words.size () > 0)
                {

                    sb.append (",5px");

                }
      */
    } else {

      sb.append("6px, p, 6px");
    }

    FormLayout summOnly = new FormLayout("3px, fill:380px:grow, 3px", sb.toString());
    PanelBuilder pb = new PanelBuilder(summOnly);

    CellConstraints cc = new CellConstraints();

    int ind = 2;

    Map<String, String> names = new HashMap();
    names.put(Synonyms.ADJECTIVE + "", "Adjectives");
    names.put(Synonyms.NOUN + "", "Nouns");
    names.put(Synonyms.VERB + "", "Verbs");
    names.put(Synonyms.ADVERB + "", "Adverbs");
    names.put(Synonyms.OTHER + "", "Other");

    if (syns.words.size() == 0) {

      JLabel l = new JLabel("No synonyms found.");
      l.setFont(l.getFont().deriveFont(Font.ITALIC));

      pb.add(l, cc.xy(2, 2));
    }

    // Determine what type of word we are looking for.
    for (Synonyms.Part i : syns.words) {

      JLabel l = new JLabel(names.get(i.type + ""));

      l.setFont(l.getFont().deriveFont(Font.ITALIC));
      l.setFont(l.getFont().deriveFont((float) UIUtils.getEditorFontSize(10)));
      l.setBorder(
          new CompoundBorder(
              new MatteBorder(0, 0, 1, 0, Environment.getBorderColor()),
              new EmptyBorder(0, 0, 3, 0)));

      pb.add(l, cc.xy(2, ind));

      ind += 2;

      HTMLEditorKit kit = new HTMLEditorKit();
      HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();

      JTextPane t = new JTextPane(doc);
      t.setEditorKit(kit);
      t.setEditable(false);
      t.setOpaque(false);

      StringBuilder buf =
          new StringBuilder(
              "<style>a { text-decoration: none; } a:hover { text-decoration: underline; }</style><span style='color: #000000; font-size: "
                  + ((int) UIUtils.getEditorFontSize(10) /*t.getFont ().getSize () + 2*/)
                  + "pt; font-family: "
                  + t.getFont().getFontName()
                  + ";'>");

      for (int x = 0; x < i.words.size(); x++) {

        String w = (String) i.words.get(x);

        buf.append("<a class='x' href='http://" + w + "'>" + w + "</a>");

        if (x < (i.words.size() - 1)) {

          buf.append(", ");
        }
      }

      buf.append("</span>");

      t.setText(buf.toString());

      t.addHyperlinkListener(
          new HyperlinkAdapter() {

            public void hyperlinkUpdate(HyperlinkEvent ev) {

              if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {

                QTextEditor ed = _this.editorPanel.getEditor();

                ed.replaceText(
                    _this.position, _this.position + _this.word.length(), ev.getURL().getHost());

                ed.removeHighlight(_this.highlight);

                _this.popup.setVisible(false);

                _this.projectViewer.fireProjectEvent(
                    ProjectEvent.SYNONYM, ProjectEvent.REPLACE, ev.getURL().getHost());
              }
            }
          });

      // Annoying that we have to do this but it prevents the text from being too small.

      t.setSize(new Dimension(380, Short.MAX_VALUE));

      JScrollPane sp = new JScrollPane(t);

      t.setCaretPosition(0);

      sp.setOpaque(false);
      sp.getVerticalScrollBar().setValue(0);
      /*
                  sp.setPreferredSize (t.getPreferredSize ());
                  sp.setMaximumSize (new Dimension (380,
                                                    75));
      */
      sp.getViewport().setOpaque(false);
      sp.setOpaque(false);
      sp.setBorder(null);
      sp.getViewport().setBackground(Color.WHITE);
      sp.setAlignmentX(Component.LEFT_ALIGNMENT);

      pb.add(sp, cc.xy(2, ind));

      ind += 2;
    }

    JPanel pan = pb.getPanel();
    pan.setOpaque(true);
    pan.setBackground(Color.WHITE);

    this.popup.setContent(pan);

    // r.y -= this.editorPanel.getScrollPane ().getVerticalScrollBar ().getValue ();

    Point po = SwingUtilities.convertPoint(editor, r.x, r.y, this.editorPanel);

    r.x = po.x;
    r.y = po.y;

    // Subtract the insets of the editorPanel.
    Insets ins = this.editorPanel.getInsets();

    r.x -= ins.left;
    r.y -= ins.top;

    this.editorPanel.showPopupAt(this.popup, r, "above", true);
  }
  private void initComponents() {
    accountCombo = new AccountListComboBox();

    helpPane = new JTextPane();
    helpPane.setEditable(false);
    helpPane.setEditorKit(new StyledEditorKit());
    helpPane.setBackground(getBackground());
    helpPane.setText(TextResource.getString("QifOne.txt"));

    /* Create the combo for date format selection */
    String[] formats = {QifUtils.US_FORMAT, QifUtils.EU_FORMAT};
    dateFormatCombo = new JComboBox<>(formats);

    dateFormatCombo.addActionListener(this);
    dateFormatCombo.setSelectedIndex(pref.getInt(DATE_FORMAT, 0));

    accountCombo.addActionListener(this);

    /* Try a set the combobox to the last selected account */
    String lastAccount = pref.get(LAST_ACCOUNT, "");

    Account last = EngineFactory.getEngine(EngineFactory.DEFAULT).getAccountByUuid(lastAccount);

    if (last != null) {
      setAccount(last);
    }
  }
  public EditorConsolePane() {
    super();
    textArea = new JTextPane();
    textArea.setEditorKit(new HTMLEditorKit());
    textArea.setTransferHandler(new JTextPaneHTMLTransferHandler());
    String css = PreferencesUser.getInstance().getConsoleCSS();
    ((HTMLEditorKit) textArea.getEditorKit()).getStyleSheet().addRule(css);
    textArea.setEditable(false);

    setLayout(new BorderLayout());
    add(new JScrollPane(textArea), BorderLayout.CENTER);

    if (ENABLE_IO_REDIRECT) {
      Debug.log(3, "EditorConsolePane: starting redirection to message area");
      int npipes = 2;
      NUM_PIPES = npipes * ScriptRunner.scriptRunner.size();
      pin = new PipedInputStream[NUM_PIPES];
      reader = new Thread[NUM_PIPES];
      for (int i = 0; i < NUM_PIPES; i++) {
        pin[i] = new PipedInputStream();
      }

      int irunner = 0;
      for (IScriptRunner srunner : ScriptRunner.scriptRunner.values()) {
        Debug.log(3, "EditorConsolePane: redirection for %s", srunner.getName());
        if (srunner.doSomethingSpecial(
            "redirect", Arrays.copyOfRange(pin, irunner * npipes, irunner * npipes + 2))) {
          Debug.log(3, "EditorConsolePane: redirection success for %s", srunner.getName());
          quit = false; // signals the Threads that they should exit
          // TODO Hack to avoid repeated redirect of stdout/err
          ScriptRunner.systemRedirected = true;

          // Starting two seperate threads to read from the PipedInputStreams
          for (int i = irunner * npipes; i < irunner * npipes + npipes; i++) {
            reader[i] = new Thread(this);
            reader[i].setDaemon(true);
            reader[i].start();
          }
          irunner++;
        }
      }
    }

    // Create the popup menu.
    popup = new JPopupMenu();
    JMenuItem menuItem = new JMenuItem("Clear messages");
    // Add ActionListener that clears the textArea
    menuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            textArea.setText("");
          }
        });
    popup.add(menuItem);

    // Add listener to components that can bring up popup menus.
    MouseListener popupListener = new PopupListener(popup);
    textArea.addMouseListener(popupListener);
  }
  private void initDebugTextPane() {
    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
    HTMLDocument htmlDocument = new HTMLDocument();

    debugTextPane.setEditable(false);
    debugTextPane.setBackground(Color.WHITE);
    debugTextPane.setEditorKit(htmlEditorKit);
    htmlEditorKit.install(debugTextPane);
    debugTextPane.setDocument(htmlDocument);
  }
Exemple #6
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;
  }
Exemple #7
0
  HtmlPanel(final Map<String, Action> actions, HtmlPage page) throws IOException {
    super(new BorderLayout());

    this.actions = actions;
    textPane = new JTextPane();
    find = new JTextField();
    matches = new JLabel();
    this.page = null;

    final Dimension d = matches.getPreferredSize();
    matches.setPreferredSize(new Dimension(100, d.height));

    textPane.setEditable(false);
    textPane.setFocusable(false);
    textPane.addHyperlinkListener(
        new HyperlinkListener() {

          public final void hyperlinkUpdate(HyperlinkEvent ev) {
            if (ev.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              final JEditorPane pane = (JEditorPane) ev.getSource();
              if (ev instanceof HTMLFrameHyperlinkEvent) {
                final HTMLFrameHyperlinkEvent evt = (HTMLFrameHyperlinkEvent) ev;
                final HTMLDocument doc = (HTMLDocument) pane.getDocument();
                doc.processHTMLFrameHyperlinkEvent(evt);
              } else if (Desktop.isDesktopSupported())
                try {
                  Desktop.getDesktop().browse(ev.getURL().toURI());
                } catch (final Exception e) {
                  e.printStackTrace();
                }
            }
          }
        });

    final HTMLEditorKit kit =
        new HTMLEditorKit() {
          private static final long serialVersionUID = 1L;

          @Override
          public final Document createDefaultDocument() {
            final HTMLDocument doc = (HTMLDocument) super.createDefaultDocument();
            // Load synchronously.
            doc.setAsynchronousLoadPriority(-1);
            return doc;
          }
        };

    final StyleSheet styleSheet = kit.getStyleSheet();
    final InputStream is = getClass().getResourceAsStream("/doogal.css");
    try {
      styleSheet.loadRules(newBufferedReader(is), null);
    } finally {
      is.close();
    }

    textPane.setEditorKit(kit);

    final Document doc = kit.createDefaultDocument();
    textPane.setDocument(doc);
    textPane.addMouseListener(
        new MouseAdapter() {

          private final void showPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
              final JPopupMenu menu = newPopupMenu(TableType.DOCUMENT, actions);
              if (null != menu) menu.show(e.getComponent(), e.getX(), e.getY());
            }
          }

          @Override
          public final void mousePressed(MouseEvent e) {
            showPopup(e);
          }

          @Override
          public final void mouseReleased(MouseEvent e) {
            showPopup(e);
          }
        });
    find.setColumns(16);
    find.setFont(new Font("Dialog", Font.PLAIN, TINY_FONT));
    find.setMargin(new Insets(2, 2, 2, 2));
    find.addActionListener(
        new ActionListener() {
          public final void actionPerformed(ActionEvent ev) {
            find(find.getText());
          }
        });

    final JLabel label = new JLabel("Quick Find: ");
    label.setLabelFor(find);

    final JButton clear = new JButton("Clear");
    clear.setMargin(new Insets(1, 5, 0, 5));
    clear.setFont(new Font("Dialog", Font.PLAIN, TINY_FONT));
    clear.addActionListener(
        new ActionListener() {
          public final void actionPerformed(ActionEvent e) {
            find.setText("");
            find("");
          }
        });

    final JPanel findPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    findPanel.add(label);
    findPanel.add(find);
    findPanel.add(clear);
    findPanel.add(matches);

    scrollPane =
        new JScrollPane(
            textPane,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setFocusable(false);
    final JScrollBar scrollBar = scrollPane.getVerticalScrollBar();
    scrollBar.setBlockIncrement(scrollBar.getBlockIncrement() * 20);
    scrollBar.setUnitIncrement(scrollBar.getUnitIncrement() * 20);

    add(scrollPane, BorderLayout.CENTER);
    add(findPanel, BorderLayout.SOUTH);

    setPage(page);
  }
  About() {
    window = new JWindow();
    this.setPreferredSize(new Dimension(650, 550));
    this.setVisible(true);
    this.setLayout(null);

    JTextPane text = new JTextPane();
    text.setBounds(5, 150, 625, 525);
    text.setVisible(true);
    text.setEditable(false);
    text.setOpaque(false);
    HTMLEditorKit htmlKit =
        new HTMLEditorKit() {
          public Parser getParser() {
            return super.getParser();
          }
        };
    HTMLDocument htmlDoc = new HTMLDocument();
    text.addHyperlinkListener(
        new HyperlinkListener() {
          public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
              if (Desktop.isDesktopSupported()) {
                try {
                  Desktop.getDesktop().browse(e.getURL().toURI());
                  return;
                } catch (IOException e1) {
                } catch (URISyntaxException e1) {
                }
              }
              try {
                Runtime.getRuntime().exec("xdg-open ".concat(e.getURL().toString()));
              } catch (IOException ioex) {
                ControlRoom.log(
                    Level.WARNING,
                    "Failed to show file: '"
                        + e.getURL().toString()
                        + "'. Possible unsupported File Manager...",
                    null);
              }
            }
          }
        });
    text.setEditorKit(htmlKit);
    text.setDocument(htmlDoc);
    try {
      BufferedReader reader =
          new BufferedReader(
              new InputStreamReader(
                  this.getClass().getResourceAsStream("/resources/about.html"), "UTF-8"));
      htmlKit.read(reader, htmlDoc, htmlDoc.getLength());
    } catch (IOException ioex) {
      ControlRoom.log(Level.SEVERE, "Failed to read about.html", ioex);
    } catch (BadLocationException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }

    text.addMouseListener(this);
    window.getContentPane().add(text);
    window.getContentPane().add(this);
    window.addMouseListener(this);
    window.pack();
    ControlRoom.setWindowRelativeToCentral(window);
    window.setVisible(true);
    window.setAlwaysOnTop(true);
  }
  public IRCBOT(boolean uList, String channel, int chatNum) {

    // chatter = new ChatDisplay("<html><body bgcolor='black'><table border=0pt width=100%>");
    winNum = chatNum;
    URL iconURL = getClass().getResource("P_300x300.png");
    ImageIcon icon = new ImageIcon(iconURL);
    setIconImage(icon.getImage());

    Action doNothing =
        new AbstractAction() {

          @Override
          public void actionPerformed(ActionEvent e) {}
        };

    channelName = channel;
    standardWindow = uList;

    chatInput = new JTextArea(4, 55);
    chatInput.setWrapStyleWord(true);
    chatInput.setLineWrap(true);
    chatInput.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "doNothing");
    chatScreen = new JTextPane();
    chatScreen.setContentType("text/html");
    chatScreen.setEditorKit(kit);
    chatScreen.setDocument(doc);
    userList = new JTextPane();
    registeredUserList = new JTextPane();
    sendButton = new JButton("SEND");
    g_start = new JButton("START");
    g_end = new JButton("END");
    g_reroll = new JButton("secret");

    JLabel l_giveaway = new JLabel("Giveaway", JLabel.CENTER);
    JLabel l_chat = new JLabel("Chat", JLabel.CENTER);
    JLabel l_uList = new JLabel("User List", JLabel.CENTER);

    sendButton.addActionListener(this);
    g_start.addActionListener(this);
    g_end.addActionListener(this);
    g_reroll.addActionListener(this);

    g_start.setEnabled(false); // disabled for basic irc client
    g_end.setEnabled(false);
    g_reroll.setEnabled(false);

    // String start = "<html><body>";

    Dimension min = new Dimension(100, 1);
    Dimension pref = new Dimension(150, 1);
    Dimension max = new Dimension(600, 600);
    // chatScreen.setMinimumSize(min);
    // userList.setMinimumSize(min);
    // chatInput.addKeyListener(KeyBoardListener);

    JPanel mainPanel = new JPanel(new BorderLayout(5, 5));
    JPanel left = new JPanel(new BorderLayout(5, 5));
    JPanel mid = new JPanel(new BorderLayout(5, 5));
    JPanel right = new JPanel(new BorderLayout(5, 5));
    JPanel giveaway_buttons = new JPanel(new BorderLayout(5, 5));

    JPanel sendBar = new JPanel();
    scrollChat = new JScrollPane(chatScreen);
    JScrollPane scrollChatInput = new JScrollPane(chatInput);
    userListScroll = new JScrollPane(userList);
    JScrollPane regUserListScroll = new JScrollPane(registeredUserList);

    userListScroll.setMinimumSize(min);
    // userListScroll.setPreferredSize(pref);
    // userListScroll.setMaximumSize(new Dimension(800,600));
    // userListScroll.setPreferredSize(new Dimension(100,100));
    // scrollChat.setPreferredSize(pref);
    scrollChat.setMinimumSize(min);
    // scrollChat.setMaximumSize(new Dimension(500,500));
    regUserListScroll.setPreferredSize(pref);

    mid.add(l_chat, BorderLayout.NORTH);
    mid.add(scrollChat, BorderLayout.CENTER);

    right.add(l_uList, BorderLayout.NORTH);
    right.add(userListScroll, BorderLayout.CENTER);

    giveaway_buttons.add(g_start, BorderLayout.WEST);
    giveaway_buttons.add(g_end, BorderLayout.CENTER);
    giveaway_buttons.add(g_reroll, BorderLayout.PAGE_END);

    left.add(giveaway_buttons, BorderLayout.PAGE_END);

    JSplitPane chat_userList = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mid, right);
    chat_userList.setOneTouchExpandable(true);
    chat_userList.setDividerLocation(500);
    chat_userList.setResizeWeight(0.5);
    chat_userList.setContinuousLayout(true);
    // chat_userList.setPreferredSize(new Dimension(100,100));
    chat_userList.setMinimumSize(min);
    // chat_userList.setMaximumSize(max);

    userListScroll.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
    // scroll.add(chatScreen);

    sendBar.add(scrollChatInput);
    sendBar.add(sendButton);

    if (standardWindow) {

      mainPanel.add(chat_userList, BorderLayout.CENTER);
      mainPanel.add(sendBar, BorderLayout.PAGE_END);

      JMenuBar menuBar = new JMenuBar();
      JMenu fileMenu = new JMenu("File");
      settings = new JMenuItem("Settings");

      settings.addActionListener(this);

      fileMenu.add(settings);
      menuBar.add(fileMenu);

      left.add(l_giveaway, BorderLayout.NORTH);
      left.add(regUserListScroll, BorderLayout.CENTER);
      // left.setBorder(new EmptyBorder(0,5,0,0));
      // chat_userList.setBorder(new EtchedBorder(0,0,0,5));
      mainPanel.add(left, BorderLayout.WEST);
      mainPanel.add(menuBar, BorderLayout.PAGE_START);
      // mainPanel.setBorder(new EmptyBorder(0,10,10,10));
    } else {
      mainPanel.add(scrollChat, BorderLayout.CENTER);
    }
    registeredUserList.setEditable(false);
    userList.setEditable(false);
    chatScreen.setEditable(false);

    registeredUserList.setFont(new Font("Courier New", Font.PLAIN, 12));
    chatScreen.setFont(new Font("Courier New", Font.PLAIN, 12));
    chatInput.setFont(new Font("Courier New", Font.PLAIN, 12));

    getContentPane().add(mainPanel);
    setSize(800, 500);
    setVisible(true);
    setResizable(true);
    setLocationRelativeTo(null);
    setTitle("IRC Chatter");
    setMinimumSize(new Dimension(500, 200));

    addWindowListener(
        new WindowAdapter() {
          @Override
          public void windowClosing(WindowEvent e) {
            // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n");
            if (sock.isSafe() == true) sock.outputText("PART " + channelName + "\r\n");
            // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n");
          }
        });
    chatInput.addKeyListener(this);
    chatInput.requestFocus();
  }
    public ChatPanel(final Client client) {
        this.client = client;

        input = new JTextField();
        //prevent unintended focus (by window activate etc. - allow focus just on direct click)
        input.setFocusable(false);
        input.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                activateChat();
            }
        });
        input.addKeyListener(new KeyAdapter() {
            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    clean();
                }
            }
        });
        input.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String msg = input.getText();
                if (!"".equals(msg)) {
                    forceFocus = true; //prevent panel flashing
                    client.getConnection().send(createPostChatMessage(msg));
                }
                clean();
            }
        });
        input.addFocusListener(new FocusListener() {
            @Override
            public void focusLost(FocusEvent e) {
                updateMessaagesVisibility();
            }

            @Override
            public void focusGained(FocusEvent e) {
                updateMessaagesVisibility();
            }
        });

        input.setOpaque(false);
        input.setBackground(client.getTheme().getTransparentInputBg());
        Color textColor = client.getTheme().getTextColor();
        if (textColor != null) {
            input.setForeground(client.getTheme().getTextColor());
            input.setCaretColor(client.getTheme().getTextColor());
        }
        TextPrompt tp = new TextPrompt(_("Type to chat"), input);
        tp.setShow(Show.FOCUS_LOST);
        tp.changeStyle(Font.ITALIC);
        tp.changeAlpha(0.4f);

        messagesPane = new JTextPane();
        messagesPane.setEditorKit(new WrapEditorKit());
        messagesPane.setFocusable(false);
        messagesPane.setOpaque(false);

        setBackground(client.getTheme().getTransparentPanelBg());
        setLayout(new MigLayout(""));
        add(messagesPane, "pos 10 n (100%-10) (100%-35)");
        add(input, "pos 10 (100%-35) (100%-10) (100%-10)");
    }
  private void initialize() {
    frame = new JFrame();
    frame.setSize(828, 520);
    frame.setLocationRelativeTo(null);
    frame.getContentPane().setLayout(null);
    textPane.setBounds(10, 5, 772, 125);
    textPane.setEditorKit(new HTMLEditorKit());

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.setBounds(10, 11, 792, 301);
    frame.getContentPane().add(tabbedPane);

    JPanel panelCase = new JPanel();
    tabbedPane.addTab("Case Tab", null, panelCase, null);
    panelCase.setLayout(null);

    tableCase = new JTable();
    tableCase.setBounds(10, 11, 634, 219);
    caseRows = new ArrayList<CaseRow>();
    panelCase.add(tableCase);
    tableCaseModel = new CaseTableModel(caseRows);
    tableCase.setModel(tableCaseModel);

    JPanel panel_Query = new JPanel();
    panel_Query.setBounds(10, 323, 792, 141);
    frame.getContentPane().add(panel_Query);
    panel_Query.setLayout(null);
    panel_Query.add(textPane);

    JScrollPane scrollPaneCase = new JScrollPane(tableCase);
    scrollPaneCase.setBounds(10, 11, 754, 164);
    panelCase.add(scrollPaneCase);

    JPanel panelCoalesce = new JPanel();
    tabbedPane.addTab("Coalesce Tab", null, panelCoalesce, null);

    tableCoalesce = new JTable();
    tableCoalesce.setBounds(1, 36, 765, 0);
    panelCoalesce.add(tableCoalesce);
    panelCase.setLayout(null);
    coalesceRows = new ArrayList<CoalesceRow>();
    tableCoalesceModel = new CoalesceTableModel(coalesceRows);
    panelCoalesce.setLayout(null);
    tableCoalesce.setModel(tableCoalesceModel);

    JScrollPane scrollPaneCoalesce = new JScrollPane(tableCoalesce);
    scrollPaneCoalesce.setBounds(10, 11, 767, 131);
    panelCoalesce.add(scrollPaneCoalesce);

    JPanel coalesceButtonPanel = new JPanel();
    coalesceButtonPanel.setBounds(10, 201, 757, 50);
    panelCoalesce.add(coalesceButtonPanel);
    coalesceButtonPanel.setLayout(null);

    JButton coalesceAddBtn = new JButton("ADD");
    coalesceAddBtn.setIcon(new ImageIcon(TeslaCase.class.getResource("/png/addd.png")));
    coalesceAddBtn.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (pojoRow.getRowType() == null) {
              pojoRow.setRowType("Coalesce");
              TeslaTransFunctions.initializeCoalesceTables();
            }
            tableCoalesce.editCellAt(-1, -1);
            if (txtEnterStringField.getText().equals("")) {
              query = TeslaTransFunctions.displayCoalesceQuery(coalesceRows);
              textPane.setText(QueryColorUtil.queryColorChange(query));
              tableCoalesceModel.updateUI(pojoRow);
              tableCoalesce.scrollRectToVisible(
                  tableCoalesce.getCellRect(tableCoalesce.getRowCount() - 1, 0, true));
            } else {
              pojoRow.setCoalesceString(txtEnterStringField.getText());
              query =
                  TeslaTransFunctions.displayCoalesceQuery_1(txtEnterStringField.getText(), query);
              tableCoalesce.editCellAt(-1, -1);
              frame.setVisible(false);
            }
          }
        });
    coalesceAddBtn.setBounds(286, 16, 115, 29);
    coalesceButtonPanel.add(coalesceAddBtn);

    JButton coalescebtnDone = new JButton("DONE");
    coalescebtnDone.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            tableCoalesce.editCellAt(-1, -1);
            if (txtEnterStringField.getText().equals("")) {
              query = TeslaTransFunctions.displayCoalesceQuery(coalesceRows);
              textPane.setText(QueryColorUtil.queryColorChange(query));
              tableCoalesceModel.updateUI(pojoRow);
              tableCoalesce.scrollRectToVisible(
                  tableCoalesce.getCellRect(tableCoalesce.getRowCount() - 1, 0, true));
            } else {
              pojoRow.setCoalesceString(txtEnterStringField.getText());
              query =
                  TeslaTransFunctions.displayCoalesceQuery_1(txtEnterStringField.getText(), query);
              tableCoalesce.editCellAt(-1, -1);
              frame.setVisible(false);
            }
            frame.setVisible(false);
          }
        });
    coalescebtnDone.setBounds(499, 19, 89, 23);
    coalesceButtonPanel.add(coalescebtnDone);

    txtEnterStringField = new JTextField();
    txtEnterStringField.setBounds(287, 158, 146, 26);
    panelCoalesce.add(txtEnterStringField);
    txtEnterStringField.setColumns(10);

    JLabel lblEnterText = new JLabel("Enter Text");
    lblEnterText.setBounds(125, 161, 119, 20);
    panelCoalesce.add(lblEnterText);

    JPanel panelCaseButton = new JPanel();
    panelCaseButton.setBounds(26, 202, 726, 44);
    panelCase.add(panelCaseButton);

    JButton btnAddCase = new JButton("ADD");
    btnAddCase.setBounds(288, 11, 89, 23);
    btnAddCase.setIcon(new ImageIcon(TeslaCase.class.getResource("/png/addd.png")));
    btnAddCase.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (pojoRow.getRowType() == null) {
              pojoRow.setRowType("Case");
              TeslaTransFunctions.initializeCaseTables();
            }
            tableCase.editCellAt(-1, -1);
            query = TeslaTransFunctions.displayCaseQuery(caseRows);
            textPane.setText(QueryColorUtil.queryColorChange(query));
            tableCaseModel.updateUI(pojoRow);
            tableCase.scrollRectToVisible(
                tableCase.getCellRect(tableCase.getRowCount() - 1, 0, true));
          }
        });
    panelCaseButton.setLayout(null);
    panelCaseButton.add(btnAddCase);

    JButton btnNewButton = new JButton("ELSE");
    btnNewButton.setIcon(new ImageIcon(TeslaCase.class.getResource("/png/Locking.png")));
    btnNewButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            tableCase.editCellAt(-1, -1);
            query = TeslaTransFunctions.displayCaseQuery(caseRows);
            textPane.setText(QueryColorUtil.queryColorChange(query));
            tableCaseModel.updateUI1(pojoRow);
            tableCase.scrollRectToVisible(
                tableCase.getCellRect(tableCase.getRowCount() - 1, 0, true));
          }
        });
    btnNewButton.setBounds(496, 11, 89, 23);
    panelCaseButton.add(btnNewButton);

    JButton btnElse = new JButton("DONE");
    btnElse.setIcon(new ImageIcon(TeslaCase.class.getResource("/png/Exit.png")));
    btnElse.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            tableCase.editCellAt(-1, -1);
            frame.setVisible(false);
          }
        });
    btnElse.setBounds(72, 11, 89, 23);
    panelCaseButton.add(btnElse);

    frame.setVisible(true);
  }