001package jmri.jmrit.display; 002 003import java.awt.Color; 004import java.awt.Dimension; 005import java.awt.Font; 006import java.awt.Frame; 007import java.awt.event.ActionEvent; 008import java.awt.event.ActionListener; 009import java.awt.event.FocusEvent; 010import java.awt.event.FocusListener; 011import java.awt.event.KeyEvent; 012import java.awt.event.KeyListener; 013import java.util.ArrayList; 014import javax.swing.BorderFactory; 015import javax.swing.BoxLayout; 016import javax.swing.JButton; 017import javax.swing.JCheckBox; 018import javax.swing.JColorChooser; 019import javax.swing.JComboBox; 020import javax.swing.JComponent; 021import javax.swing.JFrame; 022import javax.swing.JLabel; 023import javax.swing.JList; 024import javax.swing.JPanel; 025import javax.swing.JScrollPane; 026import javax.swing.JTabbedPane; 027import javax.swing.JTextField; 028import javax.swing.ListSelectionModel; 029import javax.swing.SpinnerNumberModel; 030import javax.swing.border.Border; 031import javax.swing.border.CompoundBorder; 032import javax.swing.border.LineBorder; 033import javax.swing.colorchooser.AbstractColorChooserPanel; 034import javax.swing.event.ChangeEvent; 035import javax.swing.event.ChangeListener; 036import javax.swing.event.ListSelectionEvent; 037import jmri.util.swing.SplitButtonColorChooserPanel; 038import org.slf4j.Logger; 039import org.slf4j.LoggerFactory; 040 041/** 042 * Creates the UI to set the properties of a range of Positionable Icons on 043 * (Control) Panels. 044 */ 045public class PositionablePropertiesUtil { 046 047 Frame mFrame = null; 048 protected Positionable _parent; 049 JPanel detailpanel = new JPanel(); 050 JTabbedPane propertiesPanel; 051 052 PositionablePropertiesUtil(Positionable p) { 053 _parent = p; 054 } 055 056 public void display() { 057 propertiesPanel = new JTabbedPane(); 058 getCurrentValues(); 059 JPanel exampleHolder = new JPanel(); 060 //example = new JLabel(text); 061 062 for (TextDetails textDetails : txtList) { 063 JPanel p = new JPanel(); 064 p.setBorder(BorderFactory.createTitledBorder(textDetails.getDescription())); 065 p.add(textDetails.getLabel()); // add a visual example for each 066 exampleHolder.add(p); 067 } 068 //exampleHolder.add(example); 069 JPanel tmp = new JPanel(); 070 071 tmp.setLayout(new BoxLayout(tmp, BoxLayout.Y_AXIS)); 072 tmp.add(propertiesPanel); 073 tmp.add(detailpanel); 074 tmp.add(exampleHolder); 075 textPanel(); 076 editText(); 077 borderPanel(); 078 sizePosition(); 079 080 JPanel _buttonArea = new JPanel(); 081 082 JButton cancel = new JButton(Bundle.getMessage("ButtonCancel")); 083 _buttonArea.add(cancel); 084 cancel.addActionListener((ActionEvent e) -> { 085 undoChanges(); 086 mFrame.dispose(); 087 }); 088 089 JButton applyButton = new JButton(Bundle.getMessage("ButtonApply")); 090 _buttonArea.add(applyButton); 091 applyButton.addActionListener((ActionEvent e) -> fontApply()); 092 093 JButton okButton = new JButton(Bundle.getMessage("ButtonOK")); 094 _buttonArea.add(okButton); 095 okButton.addActionListener((ActionEvent e) -> { 096 fontApply(); 097 mFrame.dispose(); 098 }); 099 tmp.add(_buttonArea); 100 101 exampleHolder.setBackground(_parent.getParent().getBackground()); 102 mFrame = new JFrame(_parent.getNameString()); 103 mFrame.add(tmp); 104 mFrame.pack(); 105 mFrame.setVisible(true); 106 preview(); 107 } 108 109 JComponent _textPanel; 110 111 JTextField fontSizeField; 112 113 String[] _justification = {Bundle.getMessage("left"), Bundle.getMessage("right"), Bundle.getMessage("center")}; 114 JComboBox<String> _justificationCombo; 115 116 /** 117 * Create and fill in the Font (Decoration) tab of the UI. 118 */ 119 void textPanel() { 120 _textPanel = new JPanel(); 121 _textPanel.setLayout(new BoxLayout(_textPanel, BoxLayout.Y_AXIS)); 122 JPanel fontColorPanel = new JPanel(); 123 fontColorPanel.add(new JLabel(Bundle.getMessage("FontColor") + ": ")); 124 125 JPanel fontSizePanel = new JPanel(); 126 fontSizePanel.setLayout(new BoxLayout(fontSizePanel, BoxLayout.Y_AXIS)); 127 fontSizeChoice = new JList<>(fontSizes); 128 129 fontSizeChoice.setSelectedValue("" + fontSize, true); 130 fontSizeChoice.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 131 JScrollPane listScroller = new JScrollPane(fontSizeChoice); 132 listScroller.setPreferredSize(new Dimension(60, 80)); 133 134 JPanel FontPanel = new JPanel(); 135 fontSizeField = new JTextField("" + fontSize, fontSizeChoice.getWidth()); 136 fontSizeField.addKeyListener(previewKeyActionListener); 137 fontSizePanel.add(fontSizeField); 138 fontSizePanel.add(listScroller); 139 FontPanel.add(fontSizePanel); 140 141 JPanel Style = new JPanel(); 142 Style.setLayout(new BoxLayout(Style, BoxLayout.Y_AXIS)); 143 Style.add(bold); 144 Style.add(italic); 145 FontPanel.add(Style); 146 _textPanel.add(FontPanel); 147 148 JPanel justificationPanel = new JPanel(); 149 _justificationCombo = new JComboBox<>(_justification); 150 switch (justification) { 151 case 0x00: 152 _justificationCombo.setSelectedIndex(0); 153 break; 154 case 0x02: 155 _justificationCombo.setSelectedIndex(1); 156 break; 157 default: 158 _justificationCombo.setSelectedIndex(2); 159 break; 160 } 161 justificationPanel.add(new JLabel(Bundle.getMessage("Justification") + ": ")); 162 justificationPanel.add(_justificationCombo); 163 _textPanel.add(justificationPanel); 164 165 _justificationCombo.addActionListener(previewActionListener); 166 bold.addActionListener(previewActionListener); 167 italic.addActionListener(previewActionListener); 168 //fontSizeChoice.addActionListener(previewActionListener); 169 fontSizeChoice.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { 170 fontSizeField.setText(fontSizeChoice.getSelectedValue()); 171 preview(); 172 }); 173 174 for (int i = 0; i < txtList.size(); i++) { // repeat 4 times for sensor icons, or just once 175 final int x = i; 176 177 JPanel txtPanel = new JPanel(); 178 179 JColorChooser txtColorChooser = new JColorChooser(defaultForeground); 180 txtColorChooser.setPreviewPanel(new JPanel()); // remove the preview panel 181 AbstractColorChooserPanel[] txtColorPanels = { new SplitButtonColorChooserPanel()}; 182 txtColorChooser.setChooserPanels(txtColorPanels); 183 txtColorChooser.getSelectionModel().addChangeListener(previewChangeListener); 184 txtPanel.add(txtColorChooser); 185 txtColorChooser.getSelectionModel().addChangeListener((ChangeEvent ce) -> txtList.get(x).setForeground(txtColorChooser.getColor())); 186 187 JPanel p = new JPanel(); 188 p.add(new JLabel(Bundle.getMessage("FontColor") + ": ")); 189 p.add(txtColorChooser); 190 191 txtPanel.add(p); 192 193 defaultBackground = _parent.getBackground(); 194 JColorChooser txtBackColorChooser = new JColorChooser(defaultBackground); 195 txtBackColorChooser.setPreviewPanel(new JPanel()); // remove the preview panel 196 AbstractColorChooserPanel[] txtBackColorPanels = { new SplitButtonColorChooserPanel()}; 197 txtBackColorChooser.setChooserPanels(txtBackColorPanels); 198 txtBackColorChooser.getSelectionModel().addChangeListener(previewChangeListener); 199 txtPanel.add(txtBackColorChooser); 200 txtBackColorChooser.getSelectionModel().addChangeListener((ChangeEvent ce) -> txtList.get(x).setBackground(txtBackColorChooser.getColor())); 201 p = new JPanel(); 202 p.add(new JLabel(Bundle.getMessage("FontBackgroundColor") + ": ")); 203 p.add(txtBackColorChooser); 204 205 String _borderTitle = txtList.get(i).getDescription(); 206 if (_borderTitle.equals(Bundle.getMessage("TextExampleLabel"))) { 207 _borderTitle = Bundle.getMessage("TextDecoLabel"); // replace default label by an appropriate one for text decoration box on Font tab 208 } 209 txtPanel.setBorder(BorderFactory.createTitledBorder(_borderTitle)); 210 txtPanel.add(p); 211 212 _textPanel.add(txtPanel); 213 214 } 215 propertiesPanel.addTab(Bundle.getMessage("FontTabTitle"), null, _textPanel, Bundle.getMessage("FontTabTooltip")); 216 } 217 218 ActionListener previewActionListener = (ActionEvent actionEvent) -> preview(); 219 220 ChangeListener spinnerChangeListener = (ChangeEvent actionEvent) -> preview(); 221 222 FocusListener textFieldFocus = new FocusListener() { 223 @Override 224 public void focusGained(FocusEvent e) { 225 } 226 227 @Override 228 public void focusLost(FocusEvent e) { 229 JTextField tmp = (JTextField) e.getSource(); 230 if (tmp.getText().equals("")) { 231 tmp.setText("0"); 232 preview(); 233 } 234 } 235 }; 236 237 KeyListener previewKeyActionListener = new KeyListener() { 238 @Override 239 public void keyTyped(KeyEvent E) { 240 } 241 242 @Override 243 public void keyPressed(KeyEvent E) { 244 } 245 246 @Override 247 public void keyReleased(KeyEvent E) { 248 JTextField tmp = (JTextField) E.getSource(); 249 if (!tmp.getText().equals("")) { 250 preview(); 251 } 252 } 253 }; 254 255 ChangeListener previewChangeListener = (ChangeEvent ce) -> preview(); 256 257 private JColorChooser borderColorChooser = null; 258 javax.swing.JSpinner borderSizeTextSpin; 259 javax.swing.JSpinner marginSizeTextSpin; 260 261 /** 262 * Create and fill in the Border tab of the UI. 263 */ 264 void borderPanel() { 265 JPanel borderPanel = new JPanel(); 266 267 borderColorChooser = new JColorChooser(defaultBorderColor); 268 AbstractColorChooserPanel[] borderColorPanels = { new SplitButtonColorChooserPanel()}; 269 borderColorChooser.setChooserPanels(borderColorPanels); 270 borderColorChooser.setPreviewPanel(new JPanel()); // remove the preview panel 271 272 borderColorChooser.getSelectionModel().addChangeListener(previewChangeListener); 273 274 JPanel borderColorPanel = new JPanel(); 275 borderColorPanel.add(new JLabel(Bundle.getMessage("borderColor") + ": ")); 276 borderColorPanel.add(borderColorChooser); 277 278 JPanel borderSizePanel = new JPanel(); 279 borderSizeTextSpin = getSpinner(borderSize, Bundle.getMessage("borderSize")); 280 borderSizeTextSpin.addChangeListener(spinnerChangeListener); 281 borderSizePanel.add(new JLabel(Bundle.getMessage("borderSize") + ": ")); 282 borderSizePanel.add(borderSizeTextSpin); 283 284 JPanel marginSizePanel = new JPanel(); 285 marginSizeTextSpin = getSpinner(marginSize, Bundle.getMessage("marginSize")); 286 marginSizeTextSpin.addChangeListener(spinnerChangeListener); 287 288 marginSizePanel.add(new JLabel(Bundle.getMessage("marginSize") + ": ")); 289 marginSizePanel.add(marginSizeTextSpin); 290 291 borderPanel.setLayout(new BoxLayout(borderPanel, BoxLayout.Y_AXIS)); 292 borderPanel.add(borderColorPanel); 293 borderPanel.add(borderSizePanel); 294 borderPanel.add(marginSizePanel); 295 296 propertiesPanel.addTab(Bundle.getMessage("Border"), null, borderPanel, Bundle.getMessage("BorderTabTooltip")); 297 298 } 299 300 javax.swing.JSpinner xPositionTextSpin; 301 javax.swing.JSpinner yPositionTextSpin; 302 javax.swing.JSpinner widthSizeTextSpin; 303 javax.swing.JSpinner heightSizeTextSpin; 304 JCheckBox autoWidth; 305 306 /** 307 * Create and fill in the Contents tab of the UI (Text Label objects). 308 */ 309 void editText() { 310 JPanel editText = new JPanel(); 311 editText.setLayout(new BoxLayout(editText, BoxLayout.Y_AXIS)); 312 for (int i = 0; i < txtList.size(); i++) { 313 final int x = i; 314 JPanel p = new JPanel(); 315 316 String _borderTitle = txtList.get(i).getDescription(); 317 if (_borderTitle.equals(Bundle.getMessage("TextExampleLabel"))) { 318 _borderTitle = Bundle.getMessage("TextBorderLabel"); // replace label provided by Ctor by an appropriate one for text string box on Contents tab 319 } 320 p.setBorder(BorderFactory.createTitledBorder(_borderTitle)); 321 322 JLabel txt = new JLabel(Bundle.getMessage("TextValueLabel") + ": "); 323 JTextField textField = new JTextField(txtList.get(i).getText(), 20); 324 textField.addKeyListener(new KeyListener() { 325 @Override 326 public void keyTyped(KeyEvent E) { 327 } 328 329 @Override 330 public void keyPressed(KeyEvent E) { 331 } 332 333 @Override 334 public void keyReleased(KeyEvent E) { 335 JTextField tmp = (JTextField) E.getSource(); 336 txtList.get(x).setText(tmp.getText()); 337 preview(); 338 } 339 }); 340 p.add(txt); 341 p.add(textField); 342 editText.add(p); 343 } 344 propertiesPanel.addTab(Bundle.getMessage("EditTextLabel"), null, editText, Bundle.getMessage("EditTabTooltip")); 345 } 346 347 /** 348 * Create and fill in the Size & Position tab of the UI. 349 */ 350 void sizePosition() { 351 352 JPanel posPanel = new JPanel(); 353 354 JPanel xyPanel = new JPanel(); 355 xyPanel.setLayout(new BoxLayout(xyPanel, BoxLayout.Y_AXIS)); 356 JPanel xPanel = new JPanel(); 357 JLabel txt = new JLabel(" X: "); 358 xPositionTextSpin = getSpinner(xPos, "x position"); 359 xPositionTextSpin.addChangeListener(spinnerChangeListener); 360 xPanel.add(txt); 361 xPanel.add(xPositionTextSpin); 362 363 JPanel yPanel = new JPanel(); 364 txt = new JLabel(" Y: "); 365 yPositionTextSpin = getSpinner(yPos, "y position"); 366 yPositionTextSpin.addChangeListener(spinnerChangeListener); 367 yPanel.add(txt); 368 yPanel.add(yPositionTextSpin); 369 370 xyPanel.add(xPanel); 371 xyPanel.add(yPanel); 372 373 JPanel sizePanel = new JPanel(); 374 sizePanel.setLayout(new BoxLayout(sizePanel, BoxLayout.Y_AXIS)); 375 JPanel widthPanel = new JPanel(); 376 widthSizeTextSpin = getSpinner(fixedWidth, Bundle.getMessage("width")); 377 widthSizeTextSpin.addChangeListener(spinnerChangeListener); 378 /*widthSizeText = new JTextField(""+fixedWidth, 10); 379 widthSizeText.addKeyListener(previewKeyActionListener);*/ 380 txt = new JLabel(Bundle.getMessage("width") + ": "); 381 widthPanel.add(txt); 382 widthPanel.add(widthSizeTextSpin); 383 384 JPanel heightPanel = new JPanel(); 385 /*heightSizeText = new JTextField(""+fixedHeight, 10); 386 heightSizeText.addKeyListener(previewKeyActionListener);*/ 387 heightSizeTextSpin = getSpinner(fixedHeight, Bundle.getMessage("height")); 388 heightSizeTextSpin.addChangeListener(spinnerChangeListener); 389 txt = new JLabel(Bundle.getMessage("height") + ": "); 390 heightPanel.add(txt); 391 heightPanel.add(heightSizeTextSpin); 392 393 sizePanel.add(widthPanel); 394 sizePanel.add(heightPanel); 395 396 posPanel.add(xyPanel); 397 posPanel.add(sizePanel); 398 posPanel.setLayout(new BoxLayout(posPanel, BoxLayout.Y_AXIS)); 399 400 propertiesPanel.addTab(Bundle.getMessage("SizeTabTitle"), null, posPanel, Bundle.getMessage("SizeTabTooltip")); 401 } 402 403 void fontApply() { 404 pop.setFontSize(Integer.parseInt(fontSizeField.getText())); 405 if (bold.isSelected()) { 406 pop.setFontStyle(Font.BOLD, 0); 407 } else { 408 pop.setFontStyle(0, Font.BOLD); 409 } 410 if (italic.isSelected()) { 411 pop.setFontStyle(Font.ITALIC, 0); 412 } else { 413 pop.setFontStyle(0, Font.ITALIC); 414 } 415 416 Color desiredColor; 417 if (_parent instanceof SensorIcon) { 418 SensorIcon si = (SensorIcon) _parent; 419 if (si.isIcon()) { 420 PositionableLabel pp = (PositionableLabel) _parent; 421 pp.setText(txtList.get(0).getText()); 422 pop.setForeground(txtList.get(0).getForeground()); 423 pop.setBackgroundColor(txtList.get(0).getBackground()); 424 } else { 425 si.setActiveText(txtList.get(0).getText()); 426 si.setTextActive(txtList.get(0).getForeground()); 427 si.setBackgroundActive(txtList.get(0).getBackground()); 428 429 si.setInactiveText(txtList.get(1).getText()); 430 si.setTextInActive(txtList.get(1).getForeground()); 431 si.setBackgroundInActive(txtList.get(1).getBackground()); 432 433 si.setUnknownText(txtList.get(2).getText()); 434 si.setTextUnknown(txtList.get(2).getForeground()); 435 si.setBackgroundUnknown(txtList.get(2).getBackground()); 436 437 si.setInconsistentText(txtList.get(3).getText()); 438 si.setTextInconsistent(txtList.get(3).getForeground()); 439 si.setBackgroundInconsistent(txtList.get(3).getBackground()); 440 } 441 } else if (_parent instanceof PositionableJPanel) { 442 pop.setForeground(txtList.get(0).getForeground()); 443 pop.setBackgroundColor(txtList.get(0).getBackground()); 444 } else { 445 PositionableLabel pp = (PositionableLabel) _parent; 446 pp.setText(txtList.get(0).getText()); 447 pop.setForeground(txtList.get(0).getForeground()); 448 pop.setBackgroundColor(txtList.get(0).getBackground()); 449 } 450 451 int deg = _parent.getDegrees(); 452 if (deg != 0) { 453 _parent.rotate(0); 454 } 455 desiredColor = borderColorChooser.getColor(); 456 pop.setBorderColor(desiredColor); 457 458 pop.setBorderSize(((Number) borderSizeTextSpin.getValue()).intValue()); 459 460 pop.setMargin(((Number) marginSizeTextSpin.getValue()).intValue()); 461 _parent.setLocation(((Number) xPositionTextSpin.getValue()).intValue(), ((Number) yPositionTextSpin.getValue()).intValue()); 462 pop.setFixedWidth(((Number) widthSizeTextSpin.getValue()).intValue()); 463 pop.setFixedHeight(((Number) heightSizeTextSpin.getValue()).intValue()); 464 switch (_justificationCombo.getSelectedIndex()) { 465 case 0: 466 pop.setJustification(0x00); 467 break; 468 case 1: 469 pop.setJustification(0x02); 470 break; 471 case 2: 472 pop.setJustification(0x04); 473 break; 474 default: 475 log.warn("Unhandled combo index: {}", _justificationCombo.getSelectedIndex()); 476 break; 477 } 478 _parent.rotate(deg); 479 } 480 481 void cancelButton() { 482 mFrame.dispose(); 483 } 484 485 void preview() { 486 int attrs = Font.PLAIN; 487 if (bold.isSelected()) { 488 attrs = Font.BOLD; 489 } 490 if (italic.isSelected()) { 491 attrs |= Font.ITALIC; 492 } 493 494 Font newFont = new Font(_parent.getFont().getName(), attrs, Integer.parseInt(fontSizeField.getText())); 495 496 Color desiredColor; 497 498 desiredColor = borderColorChooser.getColor(); 499 Border borderMargin; 500 int margin = ((Number) marginSizeTextSpin.getValue()).intValue(); 501 Border outlineBorder; 502 if (desiredColor != null) { 503 outlineBorder = new LineBorder(desiredColor, ((Number) borderSizeTextSpin.getValue()).intValue()); 504 } else { 505 outlineBorder = BorderFactory.createEmptyBorder(0, 0, 0, 0); 506 } 507 int hoz = 0; 508 switch (_justificationCombo.getSelectedIndex()) { 509 case 0: 510 hoz = (0x02); 511 break; 512 case 1: 513 hoz = (0x04); 514 break; 515 case 2: 516 hoz = (0x00); 517 break; 518 default: 519 log.warn("Unhandled combo index: {}", _justificationCombo.getSelectedIndex()); 520 break; 521 } 522 523 for (TextDetails textDetails : txtList) { 524 JLabel tmp = textDetails.getLabel(); 525 if (tmp.isOpaque()) { 526 borderMargin = new LineBorder(tmp.getBackground(), margin); 527 } else { 528 borderMargin = BorderFactory.createEmptyBorder(margin, margin, margin, margin); 529 } 530 tmp.setFont(newFont); 531 tmp.setHorizontalAlignment(hoz); 532 tmp.setBorder(new CompoundBorder(outlineBorder, borderMargin)); 533 tmp.setSize(new Dimension(maxWidth(tmp), maxHeight(tmp))); 534 tmp.setPreferredSize(new Dimension(maxWidth(tmp), maxHeight(tmp))); 535 536 } 537 mFrame.pack(); 538 } 539 540 int maxWidth(JLabel tmp) { 541 int max = 0; 542 if (((Number) widthSizeTextSpin.getValue()).intValue() != 0) { 543 max = ((Number) widthSizeTextSpin.getValue()).intValue(); 544 max += ((Number) borderSizeTextSpin.getValue()).intValue() * 2; 545 } else { 546 if (tmp.getText().trim().length() > 0) { 547 max = tmp.getFontMetrics(tmp.getFont()).stringWidth(tmp.getText()); 548 } 549 if (pop != null) { 550 max += ((Number) marginSizeTextSpin.getValue()).intValue() * 2; 551 max += ((Number) borderSizeTextSpin.getValue()).intValue() * 2; 552 } 553 } 554 return max; 555 } 556 557 public int maxHeight(JLabel tmp) { 558 int max = 0; 559 if (((Number) heightSizeTextSpin.getValue()).intValue() != 0) { 560 max = ((Number) heightSizeTextSpin.getValue()).intValue(); 561 max += ((Number) borderSizeTextSpin.getValue()).intValue() * 2; 562 } else { 563 if (tmp.getText().trim().length() > 0) { 564 max = tmp.getFontMetrics(tmp.getFont()).getHeight(); 565 } 566 if (pop != null) { 567 max += ((Number) marginSizeTextSpin.getValue()).intValue() * 2; 568 max += ((Number) borderSizeTextSpin.getValue()).intValue() * 2; 569 } 570 } 571 572 return max; 573 } 574 PositionablePopupUtil pop; 575 576 private void undoChanges() { 577 if (_parent instanceof SensorIcon) { 578 SensorIcon si = (SensorIcon) _parent; 579 if (si.isIcon()) { 580 PositionableLabel pp = (PositionableLabel) _parent; 581 pp.setText(txtList.get(0).getOrigText()); 582 pop.setForeground(txtList.get(0).getOrigForeground()); 583 pop.setBackgroundColor(txtList.get(0).getOrigBackground()); 584 } else { 585 si.setActiveText(txtList.get(0).getOrigText()); 586 si.setTextActive(txtList.get(0).getOrigForeground()); 587 si.setBackgroundActive(txtList.get(0).getOrigBackground()); 588 589 si.setInactiveText(txtList.get(1).getOrigText()); 590 si.setTextInActive(txtList.get(1).getOrigForeground()); 591 si.setBackgroundInActive(txtList.get(1).getOrigBackground()); 592 593 si.setUnknownText(txtList.get(2).getOrigText()); 594 si.setTextUnknown(txtList.get(2).getOrigForeground()); 595 si.setBackgroundUnknown(txtList.get(2).getOrigBackground()); 596 597 si.setInconsistentText(txtList.get(3).getOrigText()); 598 si.setTextInconsistent(txtList.get(3).getOrigForeground()); 599 si.setBackgroundInconsistent(txtList.get(3).getOrigBackground()); 600 } 601 } else if (_parent instanceof PositionableJPanel) { 602 pop.setForeground(txtList.get(0).getForeground()); 603 pop.setBackgroundColor(txtList.get(0).getBackground()); 604 } else { 605 PositionableLabel pp = (PositionableLabel) _parent; 606 pp.setText(txtList.get(0).getOrigText()); 607 pop.setForeground(txtList.get(0).getOrigForeground()); 608 pop.setBackgroundColor(txtList.get(0).getOrigBackground()); 609 } 610 int deg = _parent.getDegrees(); 611 if (deg != 0) { 612 _parent.rotate(0); 613 } 614 pop.setJustification(justification); 615 pop.setFixedWidth(fixedWidth); 616 pop.setFixedHeight(fixedHeight); 617 pop.setMargin(marginSize); 618 pop.setBorderSize(borderSize); 619 pop.setFontStyle(0, fontStyle); 620 pop.setFontSize(fontSize); 621 pop.setBorderColor(defaultBorderColor); 622 _parent.setLocation(xPos, yPos); 623 _parent.rotate(deg); 624 } 625 626 private void getCurrentValues() { 627 pop = _parent.getPopupUtility(); 628 txtList = new ArrayList<>(); 629 630 if (_parent instanceof SensorIcon) { 631 SensorIcon si = (SensorIcon) _parent; 632 if (si.isIcon()) { 633 // just 1 label Example 634 txtList.add(new TextDetails(Bundle.getMessage("TextExampleLabel"), pop.getText(), pop.getForeground(), pop.getBackground())); 635 } else { 636 // 4 different labels (and bordered boxes to set decoration of) labels 637 txtList.add(new TextDetails(Bundle.getMessage("SensorStateActive"), si.getActiveText(), si.getTextActive(), si.getBackgroundActive())); 638 txtList.add(new TextDetails(Bundle.getMessage("SensorStateInactive"), si.getInactiveText(), si.getTextInActive(), si.getBackgroundInActive())); 639 txtList.add(new TextDetails(Bundle.getMessage("BeanStateUnknown"), si.getUnknownText(), si.getTextUnknown(), si.getBackgroundUnknown())); 640 txtList.add(new TextDetails(Bundle.getMessage("BeanStateInconsistent"), si.getInconsistentText(), si.getTextInconsistent(), si.getBackgroundInconsistent())); 641 } 642 } else { 643 // just 1 label Example 644 txtList.add(new TextDetails(Bundle.getMessage("TextExampleLabel"), pop.getText(), pop.getForeground(), pop.getBackground())); 645 } 646 647 fixedWidth = pop.getFixedWidth(); 648 fixedHeight = pop.getFixedHeight(); 649 marginSize = pop.getMargin(); 650 borderSize = pop.getBorderSize(); 651 justification = pop.getJustification(); 652 fontStyle = pop.getFontStyle(); 653 fontSize = pop.getFontSize(); 654 if ((Font.BOLD & fontStyle) == Font.BOLD) { 655 bold.setSelected(true); 656 } 657 if ((Font.ITALIC & fontStyle) == Font.ITALIC) { 658 italic.setSelected(true); 659 } 660 if (_parent.isOpaque()) { 661 defaultBackground = _parent.getBackground(); 662 } 663 defaultForeground = pop.getForeground(); 664 defaultBorderColor = pop.getBorderColor(); 665 if (_parent instanceof MemoryOrGVIcon) { 666 MemoryOrGVIcon pm = (MemoryOrGVIcon) _parent; 667 xPos = pm.getOriginalX(); 668 yPos = pm.getOriginalY(); 669 } else { 670 xPos = _parent.getX(); 671 yPos = _parent.getY(); 672 } 673 } 674 private int fontStyle; 675 private Color defaultForeground = Color.black; 676 private Color defaultBackground; 677 private Color defaultBorderColor = Color.black; 678 private int fixedWidth = 0; 679 private int fixedHeight = 0; 680 private int marginSize = 0; 681 private int borderSize = 0; 682 private int justification; 683 private int fontSize; 684 private int xPos; 685 private int yPos; 686 687 private ArrayList<TextDetails> txtList = null; 688 689 private final JCheckBox italic = new JCheckBox(Bundle.getMessage("Italic"), false); 690 private final JCheckBox bold = new JCheckBox(Bundle.getMessage("Bold"), false); 691 692 protected JList<String> fontSizeChoice; 693 694 protected String[] fontSizes = {"6", "8", "10", "11", "12", "14", "16", 695 "20", "24", "28", "32", "36"}; 696 697 javax.swing.JSpinner getSpinner(int value, String tooltip) { 698 SpinnerNumberModel model = new SpinnerNumberModel(0, 0, 9999, 1); 699 javax.swing.JSpinner spinX = new javax.swing.JSpinner(model); 700 spinX.setValue(value); 701 spinX.setToolTipText(tooltip); 702 spinX.setMaximumSize(new Dimension( 703 spinX.getMaximumSize().width, spinX.getPreferredSize().height)); 704 return spinX; 705 } 706 707 static class TextDetails { 708 709 TextDetails(String desc, String txt, Color fore, Color back) { 710 if (txt == null) { 711 text = ""; 712 // contents of icon state labels <active> are entered in SensorIcon.java 713 } else { 714 text = txt; 715 } 716 description = desc; 717 example = new JLabel(text); 718 setForeground(fore); 719 setBackground(back); 720 origForeground = fore; 721 origBackground = back; 722 origText = txt; 723 } 724 725 Color foreground; 726 Color background; 727 Color origForeground; 728 Color origBackground; 729 String origText; 730 String text; 731 JLabel example; 732 String description; 733 734 Color getForeground() { 735 return foreground; 736 } 737 738 Color getBackground() { 739 return background; 740 } 741 742 String getText() { 743 return text; 744 } 745 746 Color getOrigForeground() { 747 return origForeground; 748 } 749 750 Color getOrigBackground() { 751 return origBackground; 752 } 753 754 String getOrigText() { 755 return origText; 756 } 757 758 String getDescription() { 759 return description; 760 } 761 762 void setForeground(Color fore) { 763 foreground = fore; 764 example.setForeground(fore); 765 } 766 767 void setBackground(Color back) { 768 background = back; 769 if (back != null) { 770 example.setOpaque(true); 771 example.setBackground(back); 772 } else { 773 example.setOpaque(false); 774 } 775 } 776 777 void setText(String txt) { 778 text = txt; 779 example.setText(txt); 780 } 781 782 JLabel getLabel() { 783 return example; 784 } 785 786 } 787 788 private final static Logger log = LoggerFactory.getLogger(PositionablePropertiesUtil.class); 789}