mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-09-11 03:35:28 +02:00
manual and code: fixed colour handling of the messages and better descripted it in the manual
This commit is contained in:
@@ -25,7 +25,6 @@ import javafx.scene.control.TableRow; // For the priority coloring
|
||||
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.css.PseudoClass;
|
||||
import javafx.geometry.*;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.input.*;
|
||||
@@ -3754,67 +3753,54 @@ public class Kst4ContestApplication extends Application implements StatusUpdateL
|
||||
}
|
||||
});
|
||||
|
||||
//experimental row coloring on new private messages (and recolouring if they get older)
|
||||
// Color new private messages and restore the normal row style after five minutes.
|
||||
tbl_privateMSGTable.setRowFactory(tv -> new TableRow<ChatMessage>() {
|
||||
@Override
|
||||
protected void updateItem(ChatMessage item, boolean empty) {
|
||||
protected void updateItem(
|
||||
final ChatMessage item,
|
||||
final boolean empty
|
||||
) {
|
||||
super.updateItem(item, empty);
|
||||
try {
|
||||
if (item != null) {
|
||||
|
||||
if (item.getSender().getCallSign().equals(chatcontroller.getChatPreferences().getStn_loginCallSign())) {
|
||||
PseudoClass foo = PseudoClass.getPseudoClass("messageHighlightOwn-column");
|
||||
getStyleClass().removeAll(
|
||||
PrivateMessageRowStyleResolver.knownStyleClasses()
|
||||
);
|
||||
|
||||
// System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> pm row style " + this.getStyleClass());
|
||||
tv.setStyle(null);
|
||||
if (empty || item == null || item.getSender() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// this.getStyleClass().clear();
|
||||
this.getStyleClass().add("messageHighlightOwn-column"); //add new special colored css reference
|
||||
// setStyle("-fx-background-color: #ADD8E6;");
|
||||
} else {
|
||||
final String ownCallsign = chatcontroller
|
||||
.getChatPreferences()
|
||||
.getStn_loginCallSign();
|
||||
|
||||
// System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> pm row style " + this.getStyleClass());
|
||||
final boolean ownMessage = Objects.equals(
|
||||
item.getSender().getCallSign(),
|
||||
ownCallsign
|
||||
);
|
||||
|
||||
if (( (new Utils4KST().time_generateCurrentEpochTime())) - (Long.parseLong(item.getMessageGeneratedTime())) <= 30 ) { //after 30 seconds change color
|
||||
// setStyle("-fx-background-color: #FF6F00;");
|
||||
this.getStyleClass().clear();
|
||||
this.getStyleClass().add("messageHighlight30-column"); //add new special colored css reference
|
||||
final String styleClass;
|
||||
|
||||
} else if (( (new Utils4KST().time_generateCurrentEpochTime())) - (Long.parseLong(item.getMessageGeneratedTime())) <= 60 ) { //after 60 seconds change color
|
||||
this.getStyleClass().clear();
|
||||
this.getStyleClass().add("messageHighlight60-column"); //add new special colored css reference
|
||||
// setStyle("-fx-background-color: #FFB300;");
|
||||
} else if (( (new Utils4KST().time_generateCurrentEpochTime())) - (Long.parseLong(item.getMessageGeneratedTime())) <= 90 ) { //after 90 seconds change color
|
||||
this.getStyleClass().clear();
|
||||
this.getStyleClass().add("messageHighlight90-column"); //add new special colored css reference
|
||||
// setStyle("-fx-background-color: #FFB300;");
|
||||
} else if (( (new Utils4KST().time_generateCurrentEpochTime())) - (Long.parseLong(item.getMessageGeneratedTime())) <= 120 ) { //after 120 seconds change color
|
||||
this.getStyleClass().clear();
|
||||
this.getStyleClass().add("messageHighlight120-column"); //add new special colored css reference
|
||||
// setStyle("-fx-background-color: #FFD54F;");
|
||||
} else if (( (new Utils4KST().time_generateCurrentEpochTime())) - (Long.parseLong(item.getMessageGeneratedTime())) <= 180 ) { //after 180 seconds change color
|
||||
this.getStyleClass().clear();
|
||||
this.getStyleClass().add("messageHighlight180-column"); //add new special colored css reference
|
||||
// setStyle("-fx-background-color: #FFD54F;");
|
||||
} else if (( (new Utils4KST().time_generateCurrentEpochTime())) - (Long.parseLong(item.getMessageGeneratedTime())) <= 300 ) { //after 300 seconds change color
|
||||
this.getStyleClass().clear();
|
||||
this.getStyleClass().add("messageHighlight300-column"); //add new special colored css reference
|
||||
// setStyle("-fx-background-color: #FFF176;");
|
||||
} else
|
||||
{
|
||||
if (ownMessage) {
|
||||
styleClass = PrivateMessageRowStyleResolver
|
||||
.resolveStyleClass(true, 0);
|
||||
} else {
|
||||
try {
|
||||
final long ageSeconds = new Utils4KST()
|
||||
.time_generateCurrentEpochTime()
|
||||
- Long.parseLong(
|
||||
item.getMessageGeneratedTime()
|
||||
);
|
||||
|
||||
// setStyle("");
|
||||
}
|
||||
}
|
||||
|
||||
// switch (Integer.parseInt("" + (((new Utils4KST().time_generateCurrentEpochTime())) - (Long.parseLong(item.getMessageGeneratedTime()))))) {
|
||||
// case int i
|
||||
// } //TODO: update to JDK21 or bigger, then a range case is possible, improves speed maybe
|
||||
styleClass = PrivateMessageRowStyleResolver
|
||||
.resolveStyleClass(false, ageSeconds);
|
||||
} catch (NumberFormatException exception) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// System.out.println("---> messagealter ---> " + (((new Utils4KST().time_generateCurrentEpochTime())) - (Long.parseLong(item.getMessageGeneratedTime()))));
|
||||
} catch (Exception e) {
|
||||
;
|
||||
if (styleClass != null) {
|
||||
getStyleClass().add(styleClass);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12952,4 +12938,4 @@ class CheckBoxTableCell<S, T> extends TableCell<S, T> {
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package kst4contest.view;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Selects the CSS style class used for a private-message table row.
|
||||
*/
|
||||
public final class PrivateMessageRowStyleResolver {
|
||||
|
||||
/** Style used for messages sent by the local station. */
|
||||
public static final String OWN_STYLE_CLASS =
|
||||
"messageHighlightOwn-column";
|
||||
|
||||
/** Upper inclusive age bounds for the private-message color levels. */
|
||||
private static final List<Long> AGE_LIMITS = List.of(
|
||||
30L,
|
||||
60L,
|
||||
90L,
|
||||
120L,
|
||||
180L,
|
||||
300L
|
||||
);
|
||||
|
||||
/** Style classes corresponding to the configured age bounds. */
|
||||
private static final List<String> AGE_STYLES = List.of(
|
||||
"messageHighlight30-column",
|
||||
"messageHighlight60-column",
|
||||
"messageHighlight90-column",
|
||||
"messageHighlight120-column",
|
||||
"messageHighlight180-column",
|
||||
"messageHighlight300-column"
|
||||
);
|
||||
|
||||
/** All private-message row classes managed by the row factory. */
|
||||
private static final List<String> MANAGED_STYLES = List.of(
|
||||
OWN_STYLE_CLASS,
|
||||
AGE_STYLES.get(0),
|
||||
AGE_STYLES.get(1),
|
||||
AGE_STYLES.get(2),
|
||||
AGE_STYLES.get(3),
|
||||
AGE_STYLES.get(4),
|
||||
AGE_STYLES.get(5)
|
||||
);
|
||||
|
||||
private PrivateMessageRowStyleResolver() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the complete set of private-message row classes managed by the
|
||||
* row factory.
|
||||
*
|
||||
* @return immutable list of managed style classes
|
||||
*/
|
||||
public static List<String> knownStyleClasses() {
|
||||
return MANAGED_STYLES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the private-message row class for the supplied message age.
|
||||
*
|
||||
* @param ownMessage whether the message was sent by the local station
|
||||
* @param ageSeconds message age in seconds
|
||||
* @return managed CSS class, or {@code null} after the five-minute window
|
||||
*/
|
||||
public static String resolveStyleClass(
|
||||
final boolean ownMessage,
|
||||
final long ageSeconds
|
||||
) {
|
||||
String styleClass = null;
|
||||
if (ownMessage) {
|
||||
styleClass = OWN_STYLE_CLASS;
|
||||
} else {
|
||||
for (int index = 0; index < AGE_LIMITS.size(); index++) {
|
||||
if (ageSeconds <= AGE_LIMITS.get(index)) {
|
||||
styleClass = AGE_STYLES.get(index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return styleClass;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package kst4contest.test;
|
||||
|
||||
import kst4contest.view.PrivateMessageRowStyleResolver;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
class PrivateMessageRowStyleResolverTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"0, messageHighlight30-column",
|
||||
"30, messageHighlight30-column",
|
||||
"31, messageHighlight60-column",
|
||||
"60, messageHighlight60-column",
|
||||
"61, messageHighlight90-column",
|
||||
"90, messageHighlight90-column",
|
||||
"91, messageHighlight120-column",
|
||||
"120, messageHighlight120-column",
|
||||
"121, messageHighlight180-column",
|
||||
"180, messageHighlight180-column",
|
||||
"181, messageHighlight300-column",
|
||||
"300, messageHighlight300-column"
|
||||
})
|
||||
void selectsAgeStyleClassAtEveryBoundary(
|
||||
long ageSeconds,
|
||||
String expectedStyleClass
|
||||
) {
|
||||
assertEquals(
|
||||
expectedStyleClass,
|
||||
PrivateMessageRowStyleResolver.resolveStyleClass(
|
||||
false,
|
||||
ageSeconds
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnsNoAgeStyleClassAfterFiveMinutes() {
|
||||
assertNull(
|
||||
PrivateMessageRowStyleResolver.resolveStyleClass(
|
||||
false,
|
||||
301
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void keepsOwnMessageStyleAfterFiveMinutes() {
|
||||
assertEquals(
|
||||
PrivateMessageRowStyleResolver.OWN_STYLE_CLASS,
|
||||
PrivateMessageRowStyleResolver.resolveStyleClass(
|
||||
true,
|
||||
301
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user