-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
51 deletions.
There are no files selected for viewing
80 changes: 32 additions & 48 deletions
80
Common/src/main/java/com/tabnineCommon/chat/ChatDisabledComponents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,44 @@ | ||
package com.tabnineCommon.chat | ||
|
||
import java.awt.Desktop | ||
import java.awt.event.MouseEvent | ||
import java.awt.event.MouseListener | ||
import java.io.IOException | ||
import java.net.URI | ||
import java.net.URISyntaxException | ||
import javax.swing.BorderFactory | ||
import javax.swing.JLabel | ||
import javax.swing.SwingConstants | ||
|
||
val CHAT_DISABLED_PAGE = """ | ||
<html> | ||
import com.intellij.ide.BrowserUtil | ||
import com.tabnineCommon.binary.requests.login.LoginRequest | ||
import com.tabnineCommon.general.DependencyContainer | ||
import javax.swing.JEditorPane | ||
import javax.swing.event.HyperlinkEvent | ||
import javax.swing.event.HyperlinkListener | ||
|
||
val LOGIN_BUTTON = "<p>If you already have access to chat, please <a href=\"https://app.tabnine.com/signin\">sign in</a></p>".trimIndent() | ||
|
||
fun createChatDisabledJPane(isLoggedIn: Boolean = false): JEditorPane { | ||
val pane = JEditorPane( | ||
"text/html", | ||
"""<html> | ||
<body style="padding: 20px;"> | ||
<div style="font-size: 12px; margin-bottom: 8px"><b>Tabnine Chat is currently in Beta</b></div> | ||
<div style="font-size: 10px;"> | ||
<p style="margin-bottom: 8px">We understand that waiting for this awesome feature isn’t easy, but we guarantee it will be worth it.</p> | ||
<p style="margin-bottom: 8px">Tabnine Chat will soon be available to all users, and we'll make sure to keep you informed. Thank you for your patience! <a href=""> Learn more</a></p> | ||
<p>Received Tabnine Chat beta access? Please ensure you're signed in</p> | ||
<p style="margin-bottom: 8px">Tabnine Chat will soon be available to all users, and we'll make sure to keep you informed. Thank you for your patience! <a href="https://www.tabnine.com/#ChatSection"> Learn more</a></p> | ||
${if (!isLoggedIn) LOGIN_BUTTON else ""} | ||
</div> | ||
</body> | ||
</html> | ||
""".trimIndent() | ||
|
||
fun createChatDisabledJLabel(): JLabel { | ||
val label = JLabel( | ||
CHAT_DISABLED_PAGE, SwingConstants.CENTER | ||
) | ||
|
||
label.border = BorderFactory.createEmptyBorder(10, 0, 0, 0) | ||
label.addMouseListener(NaiveOpenLinkListener("https://www.tabnine.com/#ChatSection")) | ||
|
||
return label | ||
} | ||
|
||
class NaiveOpenLinkListener(private val link: String) : MouseListener { | ||
override fun mouseClicked(e: MouseEvent?) { | ||
try { | ||
Desktop.getDesktop().browse(URI(link)) | ||
return | ||
} catch (e1: IOException) { | ||
e1.printStackTrace() | ||
} catch (e1: URISyntaxException) { | ||
e1.printStackTrace() | ||
} | ||
} | ||
|
||
override fun mousePressed(e: MouseEvent?) { | ||
} | ||
|
||
override fun mouseReleased(e: MouseEvent?) { | ||
} | ||
|
||
override fun mouseEntered(e: MouseEvent?) { | ||
""".trimIndent() | ||
).apply { | ||
isEditable = false | ||
isOpaque = false | ||
} | ||
pane.addHyperlinkListener( | ||
HyperlinkListener { it -> | ||
if (it.eventType !== HyperlinkEvent.EventType.ACTIVATED) { | ||
return@HyperlinkListener | ||
} | ||
if (it.url.toString() == "https://www.tabnine.com/#ChatSection") { | ||
BrowserUtil.browse(it.url.toString()) | ||
} else if (it.url.toString() == "https://app.tabnine.com/signin") { | ||
DependencyContainer.instanceOfBinaryRequestFacade().executeRequest(LoginRequest {}) | ||
} | ||
} | ||
) | ||
|
||
override fun mouseExited(e: MouseEvent?) { | ||
} | ||
return pane | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters