-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32 from xpdota/update-notifier
Notification for an update
- Loading branch information
Showing
6 changed files
with
138 additions
and
15 deletions.
There are no files selected for viewing
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
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
51 changes: 51 additions & 0 deletions
51
xivsupport/src/main/java/gg/xp/xivsupport/gui/tabs/SmartTabbedPane.java
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package gg.xp.xivsupport.gui.tabs; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class SmartTabbedPane extends JTabbedPane implements TabAware { | ||
|
||
private static final Color warningTabColor = new Color(62, 27, 27); | ||
|
||
public SmartTabbedPane() { | ||
} | ||
|
||
public SmartTabbedPane(int tabPlacement) { | ||
super(tabPlacement); | ||
} | ||
|
||
public SmartTabbedPane(int tabPlacement, int tabLayoutPolicy) { | ||
super(tabPlacement, tabLayoutPolicy); | ||
} | ||
|
||
public List<Component> getTabs() { | ||
int count = getTabCount(); | ||
List<Component> out = new ArrayList<>(count); | ||
for (int i = 0; i < count; i++) { | ||
out.add(getComponent(i)); | ||
} | ||
return out; | ||
} | ||
|
||
@Override | ||
public boolean hasWarning() { | ||
return Arrays.stream(getComponents()).anyMatch(tab -> (tab instanceof TabAware aware && aware.hasWarning())); | ||
} | ||
|
||
public void recheckTabs() { | ||
SwingUtilities.invokeLater(this::repaint); | ||
notifyParents(); | ||
} | ||
|
||
@Override | ||
public Color getBackgroundAt(int index) { | ||
Component comp = getComponentAt(index); | ||
if (comp instanceof TabAware tabAware && tabAware.hasWarning()) { | ||
return warningTabColor; | ||
} | ||
return super.getBackgroundAt(index); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
xivsupport/src/main/java/gg/xp/xivsupport/gui/tabs/TabAware.java
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package gg.xp.xivsupport.gui.tabs; | ||
|
||
import java.awt.*; | ||
|
||
public interface TabAware { | ||
|
||
default boolean hasWarning() { | ||
return false; | ||
} | ||
|
||
Component getParent(); | ||
|
||
default void notifyParents() { | ||
Component parent = getParent(); | ||
while (parent != null) { | ||
if (parent instanceof SmartTabbedPane stp) { | ||
stp.recheckTabs(); | ||
break; | ||
} | ||
else { | ||
parent = parent.getParent(); | ||
} | ||
} | ||
} | ||
|
||
} |
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
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