-
Notifications
You must be signed in to change notification settings - Fork 136
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 #1396 from SJuliez/ci-am-gear
CI Anti-Mek Gear
- Loading branch information
Showing
6 changed files
with
117 additions
and
22 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
84 changes: 84 additions & 0 deletions
84
megameklab/src/megameklab/ui/generalUnit/ClickableLabel.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,84 @@ | ||
/* | ||
* Copyright (c) 2024 - The MegaMek Team. All Rights Reserved. | ||
* | ||
* This file is part of MegaMekLab. | ||
* | ||
* MegaMek is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* MegaMek is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with MegaMek. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package megameklab.ui.generalUnit; | ||
|
||
import javax.swing.*; | ||
import java.awt.event.MouseEvent; | ||
import java.awt.event.MouseListener; | ||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* This is a specialized label for {@link StatusBar} that calls a callback method | ||
* when it is clicked and shows its text underlined while hovered. | ||
*/ | ||
class ClickableLabel extends JLabel implements MouseListener { | ||
|
||
private static final String HOVERED_PREFIX = "<HTML><U>"; | ||
private static final String NON_HOVERED_PREFIX = "<HTML>"; | ||
private boolean isHovered = false; | ||
private String baseText = ""; | ||
private final Consumer<MouseEvent> clickCallback; | ||
|
||
/** | ||
* Creates a new clickable label. The given callback method is called when the | ||
* label is mouse-clicked. | ||
* | ||
* @param clickCallback The method to call when the label is clicked | ||
*/ | ||
ClickableLabel(Consumer<MouseEvent> clickCallback) { | ||
this.clickCallback = Objects.requireNonNull(clickCallback); | ||
addMouseListener(this); | ||
} | ||
|
||
@Override | ||
public void setText(String text) { | ||
baseText = text; | ||
updateText(); | ||
} | ||
|
||
private void updateText() { | ||
super.setText((isHovered ? HOVERED_PREFIX : NON_HOVERED_PREFIX) + baseText); | ||
} | ||
|
||
@Override | ||
public void mouseClicked(MouseEvent e) { | ||
clickCallback.accept(e); | ||
} | ||
|
||
@Override | ||
public void mousePressed(MouseEvent e) { | ||
} | ||
|
||
@Override | ||
public void mouseReleased(MouseEvent e) { | ||
} | ||
|
||
@Override | ||
public void mouseEntered(MouseEvent e) { | ||
isHovered = true; | ||
updateText(); | ||
} | ||
|
||
@Override | ||
public void mouseExited(MouseEvent e) { | ||
isHovered = false; | ||
updateText(); | ||
} | ||
} |
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
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