use of java.awt.Label in project JSettlers2 by jdmonin.
the class SOCHandPanel method createAndAddResourceColorSquare.
/**
* Create a ColorSquare and its Label, with the given text key, and add them to the layout.
* The new colorsquare and label will be "returned" by setting the
* {@link #createColorSqRetSq} and {@link #createColorSqRetLbl} fields.
*
* @param rc Color for the square, such as {@link ColorSquare#CLAY}
* @param rtxtkey Text key for i18n, such as {@code "resources.clay"}.
* If this key gives the text "Clay", the label will be "Clay:" and the
* tooltip will be "Right-click to trade clay".
* @since 2.0.00
*/
private final void createAndAddResourceColorSquare(final Color rc, final String rtxtkey) {
final String rtxt = strings.get(rtxtkey);
// "Clay:"
createColorSqRetLbl = new Label(rtxt + ":");
add(createColorSqRetLbl);
createColorSqRetSq = new ColorSquare(rc, 0);
add(createColorSqRetSq);
createColorSqRetSq.setTooltipText(// "Right-click to trade clay"
strings.get("hpan.trade.rightclick", rtxt.toLowerCase()));
}
use of java.awt.Label in project JSettlers2 by jdmonin.
the class SOCHandPanel method creation.
/**
* Stuff to do when a SOCHandPanel is created.
* Calls {@link #removePlayer()} as part of creation.
*
* @param pi player interface
* @param pl the player data, cannot be null
* @param in the interactive flag setting
*/
protected void creation(SOCPlayerInterface pi, SOCPlayer pl, boolean in) {
playerInterface = pi;
client = pi.getClient();
game = pi.getGame();
player = pl;
playerNumber = player.getPlayerNumber();
playerIsCurrent = false;
// confirmed by call to removePlayer() at end of method.
playerIsClient = false;
interactive = in;
// Note no AWT layout is used - custom layout, see doLayout().
final Color pcolor = playerInterface.getPlayerColor(playerNumber);
setBackground(pcolor);
setForeground(COLOR_FOREGROUND);
setFont(new Font("SansSerif", Font.PLAIN, 10));
// "One moment..."
blankStandIn = new ColorSquare(pcolor, strings.get("hpan.one.moment"));
blankStandIn.setVisible(false);
// playerinterface.initInterfaceElements will add blankStandIn to its layout, and set its size/position.
faceImg = new SOCFaceButton(playerInterface, playerNumber);
add(faceImg);
pname = new Label();
pname.setFont(new Font("SansSerif", Font.PLAIN, 13));
add(pname);
// Will be calculated at first turn
pnameActiveBG = null;
startBut = new Button(START);
startBut.addActionListener(this);
// this button always enabled
add(startBut);
// "Points: "
vpLab = new Label(strings.get("hpan.points") + " ");
add(vpLab);
vpSq = new ColorSquare(ColorSquare.GREY, 0);
// "Total victory points for this opponent"
vpSq.setTooltipText(strings.get("hpan.points.total.opponent"));
// "Close to winning"
final String vp_close_to_win = strings.get("hpan.points.closetowin");
if (game.vp_winner <= 12) {
// (win checked in SOCGame.checkForWinner)
vpSq.setTooltipHighWarningLevel(vp_close_to_win, game.vp_winner - 2);
} else {
vpSq.setTooltipHighWarningLevel(vp_close_to_win, game.vp_winner - 3);
}
add(vpSq);
if (game.hasSeaBoard) {
// "Special Victory Points, click for details"
final String svp_tt = strings.get("hpan.svp.tt");
// "SVP: "
svpLab = new Label(strings.get("hpan.svp") + " ");
svpLab.setVisible(false);
add(svpLab);
new AWTToolTip(svp_tt, svpLab);
svpLab.addMouseListener(this);
svpSq = new ColorSquare(ColorSquare.GREY, 0);
svpSq.setVisible(false);
svpSq.setTooltipText(svp_tt);
add(svpSq);
svpSq.addMouseListener(this);
} else {
svpLab = null;
svpSq = null;
}
final Font DIALOG_PLAIN_10 = new Font("Dialog", Font.PLAIN, 10);
larmyLab = new JLabel("", SwingConstants.CENTER);
// was bold 12pt SansSerif before v2.0.00 (i18n: needs room for more chars)
larmyLab.setFont(DIALOG_PLAIN_10);
add(larmyLab);
lroadLab = new JLabel("", SwingConstants.RIGHT);
// was bold 12pt SansSerif before v2.0.00
lroadLab.setFont(DIALOG_PLAIN_10);
add(lroadLab);
createAndAddResourceColorSquare(ColorSquare.CLAY, "resources.clay");
clayLab = createColorSqRetLbl;
claySq = createColorSqRetSq;
createAndAddResourceColorSquare(ColorSquare.ORE, "resources.ore");
oreLab = createColorSqRetLbl;
oreSq = createColorSqRetSq;
createAndAddResourceColorSquare(ColorSquare.SHEEP, "resources.sheep");
sheepLab = createColorSqRetLbl;
sheepSq = createColorSqRetSq;
createAndAddResourceColorSquare(ColorSquare.WHEAT, "resources.wheat");
wheatLab = createColorSqRetLbl;
wheatSq = createColorSqRetSq;
createAndAddResourceColorSquare(ColorSquare.WOOD, "resources.wood");
woodLab = createColorSqRetLbl;
woodSq = createColorSqRetSq;
// done, clear refs
createColorSqRetLbl = null;
// done, clear refs
createColorSqRetSq = null;
resourceSqDivLine = new ColorSquare(Color.BLACK);
add(resourceSqDivLine);
// cardLab = new Label("Cards:");
// add(cardLab);
inventoryItems = new ArrayList<SOCInventoryItem>();
inventory = new List(0, false);
// support double-click
inventory.addActionListener(this);
add(inventory);
final String pieces_available_to_place = strings.get("hpan.pieces.available");
roadSq = new ColorSquare(ColorSquare.GREY, 0);
add(roadSq);
roadSq.setTooltipText(pieces_available_to_place);
// "Almost out of roads to place"
roadSq.setTooltipLowWarningLevel(strings.get("hpan.roads.almostout"), 2);
// "No more roads available"
roadSq.setTooltipZeroText(strings.get("hpan.roads.out"));
// "Roads:"
roadLab = new JLabel(strings.get("hpan.roads"));
roadLab.setFont(DIALOG_PLAIN_10);
add(roadLab);
settlementSq = new ColorSquare(ColorSquare.GREY, 0);
add(settlementSq);
settlementSq.setTooltipText(pieces_available_to_place);
settlementSq.setTooltipLowWarningLevel(strings.get("hpan.stlmts.almostout"), 1);
settlementSq.setTooltipZeroText(strings.get("hpan.stlmts.out"));
// "Stlmts:"
settlementLab = new JLabel(strings.get("hpan.stlmts"));
settlementLab.setFont(DIALOG_PLAIN_10);
add(settlementLab);
citySq = new ColorSquare(ColorSquare.GREY, 0);
add(citySq);
citySq.setTooltipText(pieces_available_to_place);
citySq.setTooltipLowWarningLevel(strings.get("hpan.cities.almostout"), 1);
citySq.setTooltipZeroText(strings.get("hpan.cities.out"));
// "Cities:"
cityLab = new JLabel(strings.get("hpan.cities"));
cityLab.setFont(DIALOG_PLAIN_10);
add(cityLab);
if (game.hasSeaBoard) {
shipSq = new ColorSquare(ColorSquare.GREY, 0);
add(shipSq);
shipSq.setTooltipText(pieces_available_to_place);
shipSq.setTooltipLowWarningLevel(strings.get("hpan.ships.almostout"), 2);
shipSq.setTooltipZeroText(strings.get("hpan.ships.out"));
// "Ships:"
shipLab = new JLabel(strings.get("hpan.ships"));
shipLab.setFont(DIALOG_PLAIN_10);
add(shipLab);
} else {
// shipSq, shipLab already null
}
if (game.isGameOptionSet(SOCGameOption.K_SC_CLVI)) {
// No trailing space (room for wider colorsquares at left)
clothLab = new JLabel(strings.get("hpan.cloth"));
clothLab.setFont(DIALOG_PLAIN_10);
add(clothLab);
clothSq = new ColorSquare(ColorSquare.GREY, 0);
add(clothSq);
// "Amount of cloth traded from villages"
clothSq.setTooltipText(strings.get("hpan.cloth.amounttraded"));
} else if (game.isGameOptionSet(SOCGameOption.K_SC_WOND)) {
// Blank at wonder level 0; other levels' text set by updateValue(WonderLevel)
wonderLab = new JLabel("");
// same font as larmyLab, lroadLab
wonderLab.setFont(DIALOG_PLAIN_10);
add(wonderLab);
} else {
// clothSq, clothLab, wonderLab already null
}
// No trailing space (room for wider colorsquares at left)
knightsLab = new JLabel(strings.get("hpan.soldiers"));
knightsLab.setFont(DIALOG_PLAIN_10);
add(knightsLab);
knightsSq = new ColorSquare(ColorSquare.GREY, 0);
add(knightsSq);
// "Size of this army"
knightsSq.setTooltipText(strings.get("hpan.soldiers.sizearmy"));
resourceLab = new Label(RESOURCES);
add(resourceLab);
resourceSq = new ColorSquare(ColorSquare.GREY, 0);
add(resourceSq);
// "Amount in hand"
resourceSq.setTooltipText(strings.get("hpan.amounthand"));
// "If 7 is rolled, would discard half these resources"
resourceSq.setTooltipHighWarningLevel(strings.get("hpan.rsrc.roll7discard"), 8);
// "Dev. Cards: "
developmentLab = new Label(strings.get("hpan.devcards") + " ");
add(developmentLab);
developmentSq = new ColorSquare(ColorSquare.GREY, 0);
add(developmentSq);
developmentSq.setTooltipText(strings.get("hpan.amounthand"));
// button text will change soon in updateSeatLockButton()
sittingRobotLockBut = new Button(ROBOTLOCKBUT_U);
sittingRobotLockBut.addActionListener(this);
sittingRobotLockBut.setEnabled(interactive);
add(sittingRobotLockBut);
takeOverBut = new Button(TAKEOVER);
takeOverBut.addActionListener(this);
takeOverBut.setEnabled(interactive);
add(takeOverBut);
sitBut = new Button(SIT);
sitBut.addActionListener(this);
sitBut.setEnabled(interactive);
add(sitBut);
sitButIsLock = false;
robotBut = new Button(ROBOT);
robotBut.addActionListener(this);
robotBut.setEnabled(interactive);
add(robotBut);
playCardBut = new Button(CARD);
playCardBut.addActionListener(this);
playCardBut.setEnabled(interactive);
add(playCardBut);
playerTradingDisabled = game.isGameOptionSet("NT");
giveLab = new Label(GIVE);
add(giveLab);
if (interactive)
new AWTToolTip(strings.get("hpan.trade.igive.tip"), giveLab);
// "Resources to give to other players or the bank"
getLab = new Label(GET);
add(getLab);
if (interactive)
new AWTToolTip(strings.get("hpan.trade.iget.tip"), getLab);
// "Resources to get from other players or the bank"
sqPanel = new SquaresPanel(interactive, this);
add(sqPanel);
// will become visible only for seated client player
sqPanel.setVisible(false);
if (playerTradingDisabled) {
offerBut = null;
offerButTip = null;
} else {
offerBut = new Button(SEND);
offerBut.addActionListener(this);
offerBut.setEnabled(interactive);
add(offerBut);
if (interactive)
offerButTip = new AWTToolTip(OFFERBUTTIP_ENA, offerBut);
}
// clearOfferBut used by bank/port trade, and player trade
clearOfferBut = new Button(CLEAR);
clearOfferBut.addActionListener(this);
clearOfferBut.setEnabled(interactive);
add(clearOfferBut);
bankBut = new Button(BANK);
bankBut.addActionListener(this);
bankBut.setEnabled(interactive);
add(bankBut);
if (interactive)
new AWTToolTip(strings.get("hpan.trade.bankport.tip"), bankBut);
// "Trade these resources with the bank or a port"
bankUndoBut = new Button(BANK_UNDO);
bankUndoBut.addActionListener(this);
bankUndoBut.setEnabled(false);
add(bankUndoBut);
if (playerTradingDisabled) {
// playerSend, playerSendMap, playerSendForPrevTrade already null
} else {
playerSend = new ColorSquare[game.maxPlayers - 1];
playerSendMap = new int[game.maxPlayers - 1];
playerSendForPrevTrade = new boolean[game.maxPlayers - 1];
// set the trade buttons correctly
int cnt = 0;
for (int pn = 0; pn < game.maxPlayers; pn++) {
if (pn != playerNumber) {
Color color = playerInterface.getPlayerColor(pn);
playerSendMap[cnt] = pn;
playerSendForPrevTrade[cnt] = true;
playerSend[cnt] = new ColorSquare(ColorSquare.CHECKBOX, true, color);
playerSend[cnt].setColor(playerInterface.getPlayerColor(pn));
playerSend[cnt].setBoolValue(true);
add(playerSend[cnt]);
cnt++;
}
}
}
// if(playerTradingDisabled)
rollPromptCountdownLab = new Label(" ");
add(rollPromptCountdownLab);
// Nothing yet (no game in progress)
rollPromptInUse = false;
// Nothing yet
autoRollTimerTask = null;
rollBut = new Button(ROLL);
rollBut.addActionListener(this);
rollBut.setEnabled(interactive);
add(rollBut);
doneBut = new Button(DONE);
doneBut.addActionListener(this);
doneBut.setEnabled(interactive);
doneButIsRestart = false;
add(doneBut);
quitBut = new Button(QUIT);
quitBut.addActionListener(this);
quitBut.setEnabled(interactive);
add(quitBut);
offer = new TradeOfferPanel(this, playerNumber);
offer.setVisible(false);
offerIsResetMessage = false;
add(offer);
// Set tooltip appearance to look like rest of SOCHandPanel; currently only this panel uses Swing tooltips
if (!didSwingTooltipDefaults) {
UIManager.put("ToolTip.foreground", COLOR_FOREGROUND);
UIManager.put("ToolTip.background", Color.WHITE);
UIManager.put("ToolTip.font", DIALOG_PLAIN_10);
didSwingTooltipDefaults = true;
}
// set the starting state of the panel
removePlayer();
}
use of java.awt.Label in project dwoss by gg-net.
the class SwingPopupSwingParentSwing method main.
public static void main(String[] args) {
UiCore.startSwing(() -> new MainPanel());
final JDialog d = new JDialog(SwingCore.mainFrame(), "ExtraDialog", Dialog.ModalityType.MODELESS);
Label label = new Label("Ein extra Dialog");
d.getContentPane().add(label);
d.pack();
d.setLocation(500, 500);
d.setVisible(true);
String adress = "Hans Mustermann\nMusterstrasse 22\n12345 Musterhausen";
// Swing Panel in Swing Dialog
Ui.exec(() -> {
Ui.build(label).swing().eval(() -> adress, () -> new DocumentAdressUpdateViewOkCanceler()).opt().ifPresent(System.out::println);
});
}
use of java.awt.Label in project GDSC-SMLM by aherbert.
the class SpotAnalysis method createTextPanel.
private static Panel createTextPanel(TextField textField, String label, String value) {
final Panel panel = new Panel();
panel.setLayout(new BorderLayout());
final Label listLabel = new Label(label, 0);
textField.setText(value);
panel.add(listLabel, BorderLayout.WEST);
panel.add(textField, BorderLayout.CENTER);
return panel;
}
use of java.awt.Label in project GDSC-SMLM by aherbert.
the class ResultsManager method addInputSourceToDialog.
/**
* Add a list of input sources to the generic dialog. The choice field will be named inputName. If
* the file input option is true then a field will be added name 'Input_file'.
*
* @param gd the dialog
* @param inputName the input name
* @param inputOption The option to select by default
* @param source the source
* @param filename the filename
*/
private static void addInputSourceToDialog(final ExtendedGenericDialog gd, String inputName, String inputOption, Set<String> source, String filename) {
final String[] options = source.toArray(new String[0]);
// Find the option
inputOption = removeFormatting(inputOption);
int optionIndex = 0;
for (int i = 0; i < options.length; i++) {
final String name = removeFormatting(options[i]);
if (name.equals(inputOption)) {
optionIndex = i;
break;
}
}
final Choice choice = gd.addAndGetChoice(inputName, options, options[optionIndex]);
if (filename != null) {
gd.addFilenameField("Input_file", filename);
// This could be a user configured option in a global GDSC settings class.
if (ImageJUtils.isShowGenericDialog()) {
final Label l = gd.getLastLabel();
final Panel p = gd.getLastPanel();
final ItemListener listener = event -> {
final boolean enable = INPUT_FILE.equals(choice.getSelectedItem());
if (enable != l.isVisible()) {
l.setVisible(enable);
p.setVisible(enable);
gd.pack();
}
};
// Run once to set up
listener.itemStateChanged(null);
choice.addItemListener(listener);
}
}
}
Aggregations