-
Notifications
You must be signed in to change notification settings - Fork 116
Individual colors on navtabs #3680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gabriel-desmarchelier
wants to merge
10
commits into
ControlSystemStudio:master
Choose a base branch
from
lcaouen:individual-colors-on-navtabs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−33
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
251ed4a
create individual color properties for each tab
c0bef37
create enable_individual_colors propert for navtabs and manage the wi…
e96f8d6
fix call to setTabNames in NavigationTabsDemo.java
400445a
NavigationTabs : fix minor typo issues
e404138
NavigationTabs : indentation is consistent in using 4 spaces
f425702
NavigationTabs : using a single setTabs method to update Tabs
6e6247c
NavigatonTabs : fix minor typo issues
272a540
remove Messages import
7f4f726
NavigatonTabs : fix minor typo issues
666a19e
NavigationTabs : fix NavigationTabsDemo.java
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,7 +12,9 @@ | |
| import java.util.concurrent.CopyOnWriteArrayList; | ||
|
|
||
| import org.csstudio.display.builder.model.properties.Direction; | ||
| import org.csstudio.display.builder.model.properties.WidgetColor; | ||
| import org.csstudio.display.builder.representation.javafx.JFXUtil; | ||
| import org.phoebus.ui.javafx.NonCachingScrollPane; | ||
|
|
||
| import javafx.collections.ObservableList; | ||
| import javafx.css.PseudoClass; | ||
|
|
@@ -26,7 +28,6 @@ | |
| import javafx.scene.layout.VBox; | ||
| import javafx.scene.paint.Color; | ||
| import javafx.scene.text.Font; | ||
| import org.phoebus.ui.javafx.NonCachingScrollPane; | ||
|
|
||
| /** Navigation Tabs | ||
| * | ||
|
|
@@ -72,10 +73,20 @@ public static interface Listener | |
| private final Pane body = new Pane(); | ||
|
|
||
| /** Labels for the tabs */ | ||
| private final List<String> tabs = new CopyOnWriteArrayList<>(); | ||
| private final List<String> tab_names = new CopyOnWriteArrayList<>(); | ||
|
|
||
| /** Selected colors for the tabs */ | ||
| private final List<WidgetColor> tab_selected_colors = new CopyOnWriteArrayList<>(); | ||
|
|
||
| /** Deselected colors for the tabs */ | ||
| private final List<WidgetColor> tab_deselected_colors = new CopyOnWriteArrayList<>(); | ||
|
|
||
| /** Size and spacing for the tabs */ | ||
| private int tab_width = 100, tab_height = 50, tab_spacing = 2; | ||
|
|
||
| /** Enable per tab colors */ | ||
| private boolean enable_per_tab_colors = false; | ||
|
|
||
| /** Direction of tabs */ | ||
| private Direction direction = Direction.VERTICAL; | ||
|
|
||
|
|
@@ -84,6 +95,7 @@ public static interface Listener | |
| deselected = Color.rgb(200, 200, 200); | ||
|
|
||
| private Font font = null; | ||
| private int selected_tab = -1; | ||
|
|
||
| /** Listener to selected tab | ||
| * | ||
|
|
@@ -122,22 +134,22 @@ public void removeListener(final Listener listener) | |
| this.listener = null; | ||
| } | ||
|
|
||
| /** @param tabs Tab labels */ | ||
| public void setTabs(final List<String> tabs) | ||
| /** @param tabs Tabs */ | ||
| public void setTabs(final List<String> tab_names, final List<WidgetColor> tab_selected_colors, final List<WidgetColor> tab_deselected_colors) | ||
| { | ||
| this.tabs.clear(); | ||
| this.tabs.addAll(tabs); | ||
| this.tab_names.clear(); | ||
| this.tab_names.addAll(tab_names); | ||
| this.tab_selected_colors.clear(); | ||
| this.tab_selected_colors.addAll(tab_selected_colors); | ||
| this.tab_deselected_colors.clear(); | ||
| this.tab_deselected_colors.addAll(tab_deselected_colors); | ||
| updateTabs(); | ||
| } | ||
|
|
||
| /** @return Index of the selected tab. -1 if there are no buttons or nothing selected */ | ||
| public int getSelectedTab() | ||
| { | ||
| final ObservableList<Node> siblings = buttons.getChildren(); | ||
| for (int i=0; i<siblings.size(); ++i) | ||
| if (((ToggleButton) siblings.get(i)).isSelected()) | ||
| return i; | ||
| return -1; | ||
| return selected_tab; | ||
| } | ||
|
|
||
| /** Select a tab | ||
|
|
@@ -202,6 +214,15 @@ public void setTabSpacing(final int spacing) | |
| updateTabs(); | ||
| } | ||
|
|
||
| /** @param enable per tab colors */ | ||
| public void setEnablePerTabColors(final boolean enabled) | ||
| { | ||
| if (enable_per_tab_colors == enabled) | ||
| return; | ||
| enable_per_tab_colors = enabled; | ||
| updateTabs(); | ||
| } | ||
|
|
||
| /** @param color Color for selected tab */ | ||
| public void setSelectedColor(final Color color) | ||
| { | ||
|
|
@@ -250,17 +271,42 @@ private void updateTabs() | |
| buttons.getStyleClass().add("navtab_tabregion"); | ||
|
|
||
| // Create button for each tab | ||
| for (int i=0; i<tabs.size(); ++i) | ||
| { | ||
| final ToggleButton button = new ToggleButton(tabs.get(i)); | ||
| Color tmpColor = deselected; | ||
| WidgetColor tmpWidgetColor = null; | ||
|
|
||
| for (int i = 0; i < tab_names.size(); ++i) { | ||
| final ToggleButton button = new ToggleButton(tab_names.get(i)); | ||
| // Buttons without text vanish, creating a gap in the tab lineup. | ||
| if (button.getText().isEmpty()) | ||
| button.setVisible(false); | ||
| if (direction == Direction.HORIZONTAL) | ||
| button.pseudoClassStateChanged(HORIZONTAL, true); | ||
|
|
||
| if (getSelectedTab() == i) { | ||
| button.setSelected(true); | ||
| // Set color to global "selected" color value | ||
| tmpColor = selected; | ||
| // If the per-tab colors are enabled, the color to apply is to be found in the tab_selected_colors list | ||
| if (enable_per_tab_colors) { | ||
| if (i < tab_selected_colors.size()) { | ||
| tmpWidgetColor = tab_selected_colors.get(i); | ||
| tmpColor = JFXUtil.convert(tmpWidgetColor); | ||
| } | ||
| } | ||
| } else { | ||
| // Set color to global "deselected" color value | ||
| tmpColor = deselected; | ||
| // If the per-tab colors are enabled, the color to apply is to be found in the tab_deselected_colors list | ||
| if (enable_per_tab_colors) { | ||
| if (i < tab_deselected_colors.size()) { | ||
| tmpWidgetColor = tab_deselected_colors.get(i); | ||
| tmpColor = JFXUtil.convert(tmpWidgetColor); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // base color, '-fx-color', is either selected or deselected | ||
| button.setStyle("-fx-color: " + JFXUtil.webRGB(deselected)); | ||
| button.setStyle("-fx-color: " + JFXUtil.webRGB(tmpColor)); | ||
| button.getStyleClass().add("navtab_button"); | ||
| button.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE); | ||
| button.setPrefSize(tab_width, tab_height); | ||
|
|
@@ -277,27 +323,48 @@ private void updateTabs() | |
| private void handleTabSelection(final ToggleButton pressed, final boolean notify) | ||
| { | ||
| final ObservableList<Node> siblings = buttons.getChildren(); | ||
| int i = 0, selected_tab = -1; | ||
| int i = 0; | ||
| selected_tab = -1; | ||
| Color tmpColor = deselected; | ||
| WidgetColor tmpWidgetColor = null; | ||
|
||
| for (Node sibling : siblings) | ||
| { | ||
| final ToggleButton button = (ToggleButton) sibling; | ||
| if (button == pressed) | ||
| { | ||
| // Set color to global "selected" color value | ||
| tmpColor = selected; | ||
| // If user clicked a button that was already selected, | ||
| // it would now be de-selected, leaving nothing selected. | ||
| if (! pressed.isSelected()) | ||
| { // Re-select! | ||
| pressed.setSelected(true); | ||
| } | ||
| // Highlight active tab by setting it to the 'selected' color | ||
| pressed.setStyle("-fx-color: " + JFXUtil.webRGB(selected)); | ||
| // If the per-tab colors are enabled, the color to apply is to be found in the tab_selected_colors list | ||
| if (enable_per_tab_colors) { | ||
| if (i < tab_selected_colors.size()) { | ||
| tmpWidgetColor = tab_selected_colors.get(i); | ||
| tmpColor = JFXUtil.convert(tmpWidgetColor); | ||
| } | ||
| } | ||
| pressed.setStyle("-fx-color: " + JFXUtil.webRGB(tmpColor)); | ||
| selected_tab = i; | ||
| } | ||
| else if (button.isSelected()) | ||
| { | ||
| // Radio-button behavior: De-select other tabs | ||
| button.setSelected(false); | ||
| button.setStyle("-fx-color: " + JFXUtil.webRGB(deselected)); | ||
| // Set color to global "deselected" color value | ||
| tmpColor = deselected; | ||
| // If the per-tab colors are enabled, the color to apply is to be found in the tab_deselected_colors list | ||
| if (enable_per_tab_colors) { | ||
| if (i < tab_deselected_colors.size()) { | ||
| tmpWidgetColor = tab_deselected_colors.get(i); | ||
| tmpColor = JFXUtil.convert(tmpWidgetColor); | ||
| } | ||
| } | ||
| button.setStyle("-fx-color: " + JFXUtil.webRGB(tmpColor)); | ||
| } | ||
| ++i; | ||
| } | ||
|
|
@@ -306,4 +373,4 @@ else if (button.isSelected()) | |
| if (selected_tab >= 0 && notify && safe_copy != null) | ||
| safe_copy.tabSelected(selected_tab); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable tmpWidgetColor is declared but never used in a meaningful way. It's assigned values but those values are never read. This variable should be removed and you can directly pass the list element to JFXUtil.convert().