Skip to content

Commit

Permalink
Separate "include" and "exclude" items in the filter and show them in…
Browse files Browse the repository at this point in the history
… the tooltip
  • Loading branch information
cdcsgit committed Dec 23, 2021
1 parent 8de43a8 commit ae960ba
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 38 deletions.
21 changes: 0 additions & 21 deletions src/com/blogspot/kotlinstudy/lognote/ColorComboBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,6 @@ class ColorComboBox<E> : JComboBox<E>() {
textField.border = BorderFactory.createLineBorder(Color.black)
}

fun isExistItem(item:String) : Boolean {
var isExist = false
for (idx in 0 until itemCount) {
if (getItemAt(idx).toString() == item) {
isExist = true
break
}
}
return isExist
}

fun setEnabledFilter(enabled: Boolean) {
isEnabled = enabled
if (!enabled && editor.item.toString().isEmpty()) {
isVisible = false
}
else {
isVisible = true
}
}

internal class ComboBoxRenderer : BasicComboBoxRenderer() {
override fun getListCellRendererComponent(
list: JList<*>, value: Any,
Expand Down
143 changes: 143 additions & 0 deletions src/com/blogspot/kotlinstudy/lognote/FilterComboBox.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package com.blogspot.kotlinstudy.lognote

import java.awt.Color
import java.awt.Component
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
import java.awt.event.MouseEvent
import javax.swing.*
import javax.swing.plaf.basic.BasicComboBoxRenderer
import javax.swing.plaf.basic.BasicComboBoxUI

class FilterComboBox<E> : JComboBox<E>() {
var mTf: JTextField? = null
var mEnabledTfTooltip = true

init {
ui = BasicComboBoxUI()
ui.installUI(this)

mTf = editor.editorComponent as JTextField
mTf!!.border = BorderFactory.createLineBorder(Color.black)
mTf!!.toolTipText = toolTipText
mTf!!.addKeyListener(KeyHandler())
}

fun setEnabledFilter(enabled: Boolean) {
isEnabled = enabled
if (!enabled && editor.item.toString().isEmpty()) {
isVisible = false
}
else {
isVisible = true
}
}

fun isExistItem(item:String) : Boolean {
var isExist = false
for (idx in 0 until itemCount) {
if (getItemAt(idx).toString() == item) {
isExist = true
break
}
}
return isExist
}

private fun parsePattern(pattern: String) : Array<String> {
val patterns: Array<String> = Array<String>(2) { "" }

val patternSplit = pattern.split("|")
var prevPatternIdx = -1

for (item in patternSplit) {
if (prevPatternIdx != -1) {
patterns[prevPatternIdx] += "|"
patterns[prevPatternIdx] += item

if (!item.substring(item.length - 1).equals("\\")) {
prevPatternIdx = -1
}
continue
}

if (item.isNotEmpty()) {
if (item[0] != '-') {
if (patterns[0].isNotEmpty()) {
patterns[0] += "|"
patterns[0] += item
} else {
patterns[0] = item
}
if (item.substring(item.length - 1).equals("\\")) {
prevPatternIdx = 0
}
} else {
if (patterns[1].isNotEmpty()) {
patterns[1] += "|"
patterns[1] += item.substring(1)
} else {
patterns[1] = item.substring(1)
}
if (item.substring(item.length - 1).equals("\\")) {
prevPatternIdx = 1
}
}
}
}

return patterns
}

fun updateTooltip() {
if (!mEnabledTfTooltip) {
return;
}
val patterns = parsePattern(mTf!!.text)
var includeStr = patterns[0]
var excludeStr = patterns[1]

if (includeStr.isNotEmpty()) {
includeStr = includeStr.replace("|", "<font color=#303030><b>|</b></font>")
}

if (excludeStr.isNotEmpty()) {
excludeStr = excludeStr.replace("|", "<font color=#303030><b>|</b></font>")
}

var tooltip = "<html><b>$toolTipText</b><br>"
tooltip += "<font color=#000000>INCLUDE : </font><font size=5 color=#0000FF>$includeStr</font><br>"
tooltip += "<font color=#000000>EXCLUDE : </font><font size=5 color=#FF0000>$excludeStr</font><br>"
tooltip += "</html>"
mTf!!.toolTipText = tooltip
}

internal inner class KeyHandler : KeyAdapter() {
override fun keyReleased(e: KeyEvent) {
updateTooltip()
ToolTipManager.sharedInstance().mouseMoved(MouseEvent(mTf, 0, 0, 0, 0, preferredSize.height / 3, 0, false))
super.keyReleased(e)
}
}

internal class ComboBoxRenderer : BasicComboBoxRenderer() {
override fun getListCellRendererComponent(
list: JList<*>, value: Any,
index: Int, isSelected: Boolean, cellHasFocus: Boolean
): Component {
if (isSelected) {
background = list.selectionBackground
foreground = list.selectionForeground
if (-1 < index) {
list.toolTipText = list.selectedValue.toString()
}
} else {
background = list.background
foreground = list.foreground
}
font = list.font
text = value.toString()
return this
}
}
}
49 changes: 32 additions & 17 deletions src/com/blogspot/kotlinstudy/lognote/MainUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,27 @@ class MainUI(title: String) : JFrame() {
private lateinit var mLogPanel: JPanel
private lateinit var mShowLogPanel: JPanel
private lateinit var mMatchCaseBtn: ColorToggleButton
private lateinit var mShowLogCombo: ColorComboBox<String>
private lateinit var mShowLogCombo: FilterComboBox<String>
private lateinit var mShowLogToggle: ColorToggleButton
private lateinit var mShowLogTogglePanel: JPanel

private lateinit var mBoldLogPanel: JPanel
private lateinit var mBoldLogCombo: ColorComboBox<String>
private lateinit var mBoldLogCombo: FilterComboBox<String>
private lateinit var mBoldLogToggle: ColorToggleButton
private lateinit var mBoldLogTogglePanel: JPanel

private lateinit var mShowTagPanel: JPanel
private lateinit var mShowTagCombo: ColorComboBox<String>
private lateinit var mShowTagCombo: FilterComboBox<String>
private lateinit var mShowTagToggle: ColorToggleButton
private lateinit var mShowTagTogglePanel: JPanel

private lateinit var mShowPidPanel: JPanel
private lateinit var mShowPidCombo: ColorComboBox<String>
private lateinit var mShowPidCombo: FilterComboBox<String>
private lateinit var mShowPidToggle: ColorToggleButton
private lateinit var mShowPidTogglePanel: JPanel

private lateinit var mShowTidPanel: JPanel
private lateinit var mShowTidCombo: ColorComboBox<String>
private lateinit var mShowTidCombo: FilterComboBox<String>
private lateinit var mShowTidToggle: ColorToggleButton
private lateinit var mShowTidTogglePanel: JPanel

Expand Down Expand Up @@ -422,10 +422,10 @@ class MainUI(title: String) : JFrame() {

mLogPanel = JPanel()
mShowLogPanel = JPanel()
mShowLogCombo = ColorComboBox<String>()
mShowLogCombo = FilterComboBox<String>()
mShowLogCombo.toolTipText = TooltipStrings.LOG_COMBO
mShowLogCombo.isEditable = true
mShowLogCombo.renderer = ColorComboBox.ComboBoxRenderer()
mShowLogCombo.renderer = FilterComboBox.ComboBoxRenderer()
mShowLogCombo.editor.editorComponent.addKeyListener(mKeyHandler)
mShowLogCombo.addItemListener(mItemHandler)
mShowLogCombo.addPopupMenuListener(mPopupMenuHandler)
Expand All @@ -439,10 +439,11 @@ class MainUI(title: String) : JFrame() {
mShowLogToggle.addItemListener(mItemHandler)

mBoldLogPanel = JPanel()
mBoldLogCombo = ColorComboBox<String>()
mBoldLogCombo = FilterComboBox<String>()
mBoldLogCombo.toolTipText = TooltipStrings.BOLD_COMBO
mBoldLogCombo.mEnabledTfTooltip = false
mBoldLogCombo.isEditable = true
mBoldLogCombo.renderer = ColorComboBox.ComboBoxRenderer()
mBoldLogCombo.renderer = FilterComboBox.ComboBoxRenderer()
mBoldLogCombo.editor.editorComponent.addKeyListener(mKeyHandler)
mBoldLogCombo.addItemListener(mItemHandler)
mBoldLogCombo.editor.editorComponent.addMouseListener(mMouseHandler)
Expand All @@ -455,10 +456,10 @@ class MainUI(title: String) : JFrame() {
mBoldLogToggle.addItemListener(mItemHandler)

mShowTagPanel = JPanel()
mShowTagCombo = ColorComboBox<String>()
mShowTagCombo = FilterComboBox<String>()
mShowTagCombo.toolTipText = TooltipStrings.TAG_COMBO
mShowTagCombo.isEditable = true
mShowTagCombo.renderer = ColorComboBox.ComboBoxRenderer()
mShowTagCombo.renderer = FilterComboBox.ComboBoxRenderer()
mShowTagCombo.editor.editorComponent.addKeyListener(mKeyHandler)
mShowTagCombo.addItemListener(mItemHandler)
mShowTagCombo.editor.editorComponent.addMouseListener(mMouseHandler)
Expand All @@ -471,10 +472,10 @@ class MainUI(title: String) : JFrame() {
mShowTagToggle.addItemListener(mItemHandler)

mShowPidPanel = JPanel()
mShowPidCombo = ColorComboBox<String>()
mShowPidCombo = FilterComboBox<String>()
mShowPidCombo.toolTipText = TooltipStrings.PID_COMBO
mShowPidCombo.isEditable = true
mShowPidCombo.renderer = ColorComboBox.ComboBoxRenderer()
mShowPidCombo.renderer = FilterComboBox.ComboBoxRenderer()
mShowPidCombo.editor.editorComponent.addKeyListener(mKeyHandler)
mShowPidCombo.addItemListener(mItemHandler)
mShowPidCombo.editor.editorComponent.addMouseListener(mMouseHandler)
Expand All @@ -487,10 +488,10 @@ class MainUI(title: String) : JFrame() {
mShowPidToggle.addItemListener(mItemHandler)

mShowTidPanel = JPanel()
mShowTidCombo = ColorComboBox<String>()
mShowTidCombo = FilterComboBox<String>()
mShowTidCombo.toolTipText = TooltipStrings.TID_COMBO
mShowTidCombo.isEditable = true
mShowTidCombo.renderer = ColorComboBox.ComboBoxRenderer()
mShowTidCombo.renderer = FilterComboBox.ComboBoxRenderer()
mShowTidCombo.editor.editorComponent.addKeyListener(mKeyHandler)
mShowTidCombo.addItemListener(mItemHandler)
mShowTidCombo.editor.editorComponent.addMouseListener(mMouseHandler)
Expand Down Expand Up @@ -694,6 +695,9 @@ class MainUI(title: String) : JFrame() {
mShowLogCombo.addItem(item)
}
}

mShowLogCombo.updateTooltip()

if (mShowLogCombo.itemCount > 0) {
mShowLogCombo.selectedIndex = 0
}
Expand All @@ -716,6 +720,9 @@ class MainUI(title: String) : JFrame() {
mShowTagCombo.selectedIndex = 0
}
}

mShowTagCombo.updateTooltip()

check = mConfigManager.mProperties.get(mConfigManager.ITEM_SHOW_TAG_CHECK) as? String
if (!check.isNullOrEmpty()) {
mShowTagToggle.isSelected = check.toBoolean()
Expand Down Expand Up @@ -750,6 +757,9 @@ class MainUI(title: String) : JFrame() {
mBoldLogCombo.selectedIndex = 0
}
}

mBoldLogCombo.updateTooltip()

check = mConfigManager.mProperties.get(mConfigManager.ITEM_HIGHLIGHT_LOG_CHECK) as? String
if (!check.isNullOrEmpty()) {
mBoldLogToggle.isSelected = check.toBoolean()
Expand Down Expand Up @@ -1750,6 +1760,7 @@ class MainUI(title: String) : JFrame() {
}
resetComboItem(combo, item)
mFilteredTableModel.mFilterLog = item
combo.updateTooltip()
} else if (p0?.source == mBoldLogCombo) {
if (mBoldLogCombo.selectedIndex < 0) {
return
Expand All @@ -1758,6 +1769,7 @@ class MainUI(title: String) : JFrame() {
val item = combo.selectedItem!!.toString()
resetComboItem(combo, item)
mFilteredTableModel.mFilterHighlightLog = item
combo.updateTooltip()
} else if (p0?.source == mShowTagCombo) {
if (mShowTagCombo.selectedIndex < 0) {
return
Expand All @@ -1766,6 +1778,7 @@ class MainUI(title: String) : JFrame() {
val item = combo.selectedItem!!.toString()
resetComboItem(combo, item)
mFilteredTableModel.mFilterTag = item
combo.updateTooltip()
} else if (p0?.source == mShowPidCombo) {
if (mShowPidCombo.selectedIndex < 0) {
return
Expand All @@ -1774,6 +1787,7 @@ class MainUI(title: String) : JFrame() {
val item = combo.selectedItem!!.toString()
resetComboItem(combo, item)
mFilteredTableModel.mFilterPid = item
combo.updateTooltip()
} else if (p0?.source == mShowTidCombo) {
if (mShowTidCombo.selectedIndex < 0) {
return
Expand All @@ -1782,6 +1796,7 @@ class MainUI(title: String) : JFrame() {
val item = combo.selectedItem!!.toString()
resetComboItem(combo, item)
mFilteredTableModel.mFilterTid = item
combo.updateTooltip()
}
}

Expand All @@ -1806,7 +1821,7 @@ class MainUI(title: String) : JFrame() {
}
}

fun resetComboItem(combo: ColorComboBox<String>, item: String) {
fun resetComboItem(combo: FilterComboBox<String>, item: String) {
if (combo.isExistItem(item)) {
if (combo.selectedIndex == 0) {
return
Expand All @@ -1819,7 +1834,7 @@ class MainUI(title: String) : JFrame() {
}

fun goToLine(line: Int) {
println("Line : " + line)
println("Line : $line")
if (line < 0) {
return
}
Expand Down

0 comments on commit ae960ba

Please sign in to comment.