diff --git a/java/src/jmri/jmrit/display/AnalogClock2Display.java b/java/src/jmri/jmrit/display/AnalogClock2Display.java index 38e844383f4..7439809ade2 100644 --- a/java/src/jmri/jmrit/display/AnalogClock2Display.java +++ b/java/src/jmri/jmrit/display/AnalogClock2Display.java @@ -214,17 +214,21 @@ public void setScale(double scale) { return; } AffineTransform t = AffineTransform.getScaleInstance(scale, scale); + clockIcon = new NamedIcon("resources/clock2.gif", "resources/clock2.gif"); int w = (int) Math.ceil(scale * clockIcon.getIconWidth()); int h = (int) Math.ceil(scale * clockIcon.getIconHeight()); clockIcon.transformImage(w, h, t, null); + scaledIcon = new NamedIcon("resources/logo.gif", "resources/logo.gif"); w = (int) Math.ceil(scale * scaledIcon.getIconWidth()); h = (int) Math.ceil(scale * scaledIcon.getIconHeight()); scaledIcon.transformImage(w, h, t, null); + jmriIcon = new NamedIcon("resources/logo.gif", "resources/logo.gif"); w = (int) Math.ceil(scale * jmriIcon.getIconWidth()); h = (int) Math.ceil(scale * jmriIcon.getIconHeight()); jmriIcon.transformImage(w, h, t, null); + logo = jmriIcon.getImage(); + clockFace = clockIcon.getImage(); setSize(clockIcon.getIconHeight()); - scale *= getScale(); super.setScale(scale); } @@ -337,8 +341,8 @@ private void scaleFace() { size = Math.min(panelHeight, panelWidth); } faceSize = size; - if (faceSize == 0) { - faceSize = 1; + if (faceSize <= 12) { + return; } // Had trouble getting the proper sizes when using Images by themselves so diff --git a/java/src/jmri/jmrit/display/DisplayFrame.java b/java/src/jmri/jmrit/display/DisplayFrame.java index b9f0b951084..1b8728029b6 100644 --- a/java/src/jmri/jmrit/display/DisplayFrame.java +++ b/java/src/jmri/jmrit/display/DisplayFrame.java @@ -1,7 +1,24 @@ package jmri.jmrit.display; +import java.awt.Color; import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.image.BufferedImage; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingConstants; + +import jmri.jmrit.display.palette.Bundle; +import jmri.jmrit.display.palette.DecoratorPanel; import jmri.util.JmriJFrame; +import jmri.util.swing.DrawSquares; +import jmri.util.swing.ImagePanel; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,7 +40,7 @@ class jmri.util.swing.ImagePanel { +paintComponent() } class jmri.jmrit.DisplayFrame #88dddd { --previewBgSet +-previewBgIndex #SetInitListener() #setPreviewBg(i) #getPreviewBg() @@ -64,6 +81,17 @@ class jmri.jmrit.display.IconEditor */ public class DisplayFrame extends JmriJFrame { + static Color _grayColor = new Color(235, 235, 235); + static Color _darkGrayColor = new Color(150, 150, 150); + static protected Color[] colorChoice = new Color[]{Color.white, _grayColor, _darkGrayColor}; // panel bg color picked up directly + + // Array of BufferedImage backgrounds loaded as background image in Preview, shared across tabs + private BufferedImage[] _backgrounds; + private Editor _editor; // current panel editor using this frame + private Color _panelBackground; // current background + private int previewBgIndex = 0; // Shared index setting for preview pane background color combo choice. + + /** * Create a JmriJFrame with standard settings, optional save/restore of size * and position. @@ -87,6 +115,19 @@ public DisplayFrame(String name, boolean saveSize, boolean savePosition) { super(name, saveSize, savePosition); } + /** + * Create a JmriJFrame for ItemPalette or for edit popups of a given editor panel. + * Such child classes need to provide backgrounds for their panes and panels. + * + * @param name title of the Frame + * @param editor editor of panel items + */ + public DisplayFrame(String name, Editor editor) { + super(name, false, false); + _editor = editor; + makeBackgrounds(); + } + /** * Create a JmriJFrame with standard settings, including saving/restoring of * size and position. @@ -106,31 +147,89 @@ public DisplayFrame(String name) { } /** - * Shared setting for preview pane background color combo choice. - * Starts as 0 = use current Panel bg color. + * This may be used as a callback to notify children of this class + * when the preview color has changed. + * Children of this class should override if there are several other + * members with separate preview panels. e.g. ItemPalette + * + * @param index index of selection in _backgrounds array */ - protected int previewBgSet = 0; - public void setPreviewBg(int index) { - previewBgSet = index; -// log.debug("prev set to {}", index); + previewBgIndex = index; } public int getPreviewBg() { - return previewBgSet; + return previewBgIndex; + } + + public BufferedImage getPreviewBackground() { + return _backgrounds[previewBgIndex]; + } + + /** + * + * @return the color of the background of editor display panel + */ + public Color getCurrentColor() { + // should be _editor.getTargetPanel().getBackground() + return _panelBackground; + } + + public BufferedImage getBackground(int index) { + return _backgrounds[index]; + } + + /** + * Called when the background of the display panel is changed. + * @param ed the editor of the display panel + */ + public void updateBackground(Editor ed) { + if (ed == null) { + log.error("updateBackground called for a null editor!"); + return; + } + _editor = ed; + Color color = ed.getTargetPanel().getBackground(); + if (!color.equals(_panelBackground)) { + _backgrounds[0] = DrawSquares.getImage(500, 400, 10, color, color); + _panelBackground = color; + if (previewBgIndex == 0) { + setPreviewBg(0); // notify children + } + } } - - public void updateBackground0(java.awt.image.BufferedImage im) { + + public Editor getEditor() { + return _editor; + } + + /** + * Make an array of background BufferedImages for the PreviewPanels + */ + private void makeBackgrounds() { + _panelBackground = _editor.getTargetPanel().getBackground(); // start using Panel background color + if (_backgrounds == null) { // reduces load but will not redraw for new size + _backgrounds = new BufferedImage[5]; + for (int i = 1; i <= 3; i++) { + _backgrounds[i] = DrawSquares.getImage(500, 400, 10, colorChoice[i - 1], colorChoice[i - 1]); + // [i-1] because choice 0 is not in colorChoice[] + } + _backgrounds[4] = DrawSquares.getImage(500, 400, 10, Color.white, _grayColor); + } + // always update background from Panel Editor + _backgrounds[0] = DrawSquares.getImage(500, 400, 10, _panelBackground, _panelBackground); + log.debug("makeBackgrounds backgrounds[0] = {}", _backgrounds[0]); } /** + * Resizes this frame to accommodate the size of the tab panel when tab is changed. + * Otherwise it may force the tab panel to use scrollbars or be far oversized. * * @param container Container to be resized * @param deltaDim Size difference of container with old contents * @param newDim Size of the new contents - * @param ed panel editor */ - public void reSize(java.awt.Container container, Dimension deltaDim, Dimension newDim, Editor ed) { + public void reSize(java.awt.Container container, Dimension deltaDim, Dimension newDim) { Dimension dim = new Dimension(deltaDim.width + newDim.width, deltaDim.height + newDim.height); container.setPreferredSize(dim); container.invalidate(); @@ -144,20 +243,6 @@ public void reSize(java.awt.Container container, Dimension deltaDim, Dimension n } } - /** - * Listens for init() = display of the frame - */ - protected jmri.jmrit.display.palette.InitEventListener listener; - /** - * Register display of a different tab. Used on {@link jmri.jmrit.display.palette.ItemPanel} - * - * @param listener to attach - */ - public void setInitEventListener(jmri.jmrit.display.palette.InitEventListener listener) { - log.debug("listener attached"); - this.listener = listener; - } - private final static Logger log = LoggerFactory.getLogger(DisplayFrame.class); } diff --git a/java/src/jmri/jmrit/display/Editor.java b/java/src/jmri/jmrit/display/Editor.java index 59b0a0486c2..584df01b7ec 100644 --- a/java/src/jmri/jmrit/display/Editor.java +++ b/java/src/jmri/jmrit/display/Editor.java @@ -24,6 +24,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; @@ -2939,31 +2940,34 @@ protected boolean setTextAttributes(Positionable p, JPopupMenu popup) { } popup.add(new AbstractAction(Bundle.getMessage("TextAttributes")) { Positionable comp; + Editor ed; @Override public void actionPerformed(ActionEvent e) { - (new TextAttrDialog(comp)).setVisible(true); + (new TextAttrDialog(comp, ed)).setVisible(true); } AbstractAction init(Positionable pos, Editor e) { // e unused? comp = pos; + ed = e; return this; } }.init(p, this)); return true; } - public class TextAttrDialog extends JDialog { + public class TextAttrDialog extends DisplayFrame { Positionable _pos; DecoratorPanel _decorator; + BufferedImage[] _backgrounds; - TextAttrDialog(Positionable p) { - super(_targetFrame, Bundle.getMessage("TextAttributes"), true); + TextAttrDialog(Positionable p, Editor ed) { + super(Bundle.getMessage("TextAttributes"), ed); _pos = p; JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); - _decorator = new DecoratorPanel(_pos.getEditor(), null); + _decorator = new DecoratorPanel(this); _decorator.initDecoratorPanel(_pos); panel.add(_decorator); panel.add(makeDoneButtonPanel()); diff --git a/java/src/jmri/jmrit/display/IndicatorTrackIcon.java b/java/src/jmri/jmrit/display/IndicatorTrackIcon.java index 740c21727c3..719094be094 100644 --- a/java/src/jmri/jmrit/display/IndicatorTrackIcon.java +++ b/java/src/jmri/jmrit/display/IndicatorTrackIcon.java @@ -350,7 +350,7 @@ public void actionPerformed(ActionEvent e) { protected void editItem() { _paletteFrame = makePaletteFrame(java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("IndicatorTrack"))); - _trackPanel = new IndicatorItemPanel(_paletteFrame, "IndicatorTrack", _iconFamily, _editor); + _trackPanel = new IndicatorItemPanel(_paletteFrame, "IndicatorTrack", _iconFamily); ActionListener updateAction = new ActionListener() { @Override diff --git a/java/src/jmri/jmrit/display/IndicatorTurnoutIcon.java b/java/src/jmri/jmrit/display/IndicatorTurnoutIcon.java index 46e697065b5..e7ecdb4a0e7 100644 --- a/java/src/jmri/jmrit/display/IndicatorTurnoutIcon.java +++ b/java/src/jmri/jmrit/display/IndicatorTurnoutIcon.java @@ -446,7 +446,7 @@ private void setStatus(OBlock block, int state) { protected void editItem() { _paletteFrame = makePaletteFrame(java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("IndicatorTO"))); _itemPanel = new IndicatorTOItemPanel(_paletteFrame, "IndicatorTO", _iconFamily, - PickListModel.turnoutPickModelInstance(), _editor); + PickListModel.turnoutPickModelInstance()); ActionListener updateAction = new ActionListener() { @Override public void actionPerformed(ActionEvent a) { diff --git a/java/src/jmri/jmrit/display/MultiSensorIcon.java b/java/src/jmri/jmrit/display/MultiSensorIcon.java index 0bb36d856a1..389fc54cb07 100644 --- a/java/src/jmri/jmrit/display/MultiSensorIcon.java +++ b/java/src/jmri/jmrit/display/MultiSensorIcon.java @@ -246,7 +246,7 @@ public void actionPerformed(ActionEvent e) { protected void editItem() { _paletteFrame = makePaletteFrame(Bundle.getMessage("EditItem", Bundle.getMessage("MultiSensor"))); _itemPanel = new MultiSensorItemPanel(_paletteFrame, "MultiSensor", _iconFamily, - PickListModel.multiSensorPickModelInstance(), _editor); + PickListModel.multiSensorPickModelInstance()); ActionListener updateAction = (ActionEvent a) -> { updateItem(); }; diff --git a/java/src/jmri/jmrit/display/PositionableLabel.java b/java/src/jmri/jmrit/display/PositionableLabel.java index 20317cd6602..a87ad83e48a 100644 --- a/java/src/jmri/jmrit/display/PositionableLabel.java +++ b/java/src/jmri/jmrit/display/PositionableLabel.java @@ -621,11 +621,9 @@ protected void editIcon() { * @return DisplayFrame for palette item */ public DisplayFrame makePaletteFrame(String title) { - jmri.jmrit.display.palette.ItemPalette.loadIcons(_editor); + jmri.jmrit.display.palette.ItemPalette.loadIcons(); - DisplayFrame paletteFrame = new DisplayFrame(title, false, false); -// paletteFrame.setLocationRelativeTo(this); -// paletteFrame.toFront(); + DisplayFrame paletteFrame = new DisplayFrame(title, _editor); return paletteFrame; } @@ -667,7 +665,7 @@ public void actionPerformed(ActionEvent e) { protected void editIconItem() { _paletteFrame = makePaletteFrame( java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("BeanNameTurnout"))); - _iconItemPanel = new IconItemPanel(_paletteFrame, "Icon", _editor); // NOI18N + _iconItemPanel = new IconItemPanel(_paletteFrame, "Icon"); // NOI18N ActionListener updateAction = (ActionEvent a) -> { updateIconItem(); }; diff --git a/java/src/jmri/jmrit/display/PreviewPanel.java b/java/src/jmri/jmrit/display/PreviewPanel.java new file mode 100644 index 00000000000..42b00ac646b --- /dev/null +++ b/java/src/jmri/jmrit/display/PreviewPanel.java @@ -0,0 +1,89 @@ +package jmri.jmrit.display; + +import java.awt.Color; +import java.awt.event.ActionEvent; + +import javax.swing.BorderFactory; +import javax.swing.BoxLayout; +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingConstants; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import jmri.jmrit.display.palette.Bundle; +import jmri.util.swing.ImagePanel; + +/** + * Companion class to DisplayFrame + * @author peteCressman 2020 + * + */ +public class PreviewPanel extends JPanel { + + DisplayFrame _parent; + JComboBox _bgColorBox; + + public PreviewPanel(DisplayFrame parent, ImagePanel panel1, ImagePanel panel2, boolean hasComboBox) { + super(); + _parent = parent; + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + setBorder(BorderFactory.createTitledBorder( + BorderFactory.createLineBorder(Color.black, 1), + Bundle.getMessage("PreviewBorderTitle"))); + if (hasComboBox) { + add(makeBgButtonPanel(panel1, panel2)); + + } + if (panel1 != null) { + add(panel1); + } + if (panel2 != null) { + add(panel2); + } + } + + public void setBackgroundSelection(int index) { + if (_bgColorBox != null) { + _bgColorBox.setSelectedIndex(index); + } + } + + private JPanel makeBgButtonPanel(ImagePanel preview1, ImagePanel preview2) { + _bgColorBox = new JComboBox<>(); + _bgColorBox.addItem(Bundle.getMessage("PanelBgColor")); // PanelColor key is specific for CPE, but too long for combo + _bgColorBox.addItem(Bundle.getMessage("White")); + _bgColorBox.addItem(Bundle.getMessage("LightGray")); + _bgColorBox.addItem(Bundle.getMessage("DarkGray")); + _bgColorBox.addItem(Bundle.getMessage("Checkers")); + _bgColorBox.setSelectedIndex(_parent.getPreviewBg()); // Global field, starts as 0 = panel bg color + + JPanel bkgdBoxPanel = new JPanel(); + bkgdBoxPanel.setLayout(new BoxLayout(bkgdBoxPanel, BoxLayout.Y_AXIS)); + bkgdBoxPanel.add(new JLabel(Bundle.getMessage("setBackground"), SwingConstants.RIGHT)); + bkgdBoxPanel.add(_bgColorBox); + + _bgColorBox.addActionListener((ActionEvent e) -> { + int previewBgSet = _bgColorBox.getSelectedIndex(); + _parent.setPreviewBg(previewBgSet); // notify user choice in field on children override + // load background image + log.debug("PreviewPanel coler #{} set", previewBgSet); + if (preview1 != null) { + preview1.setImage(_parent.getPreviewBackground()); + preview1.revalidate(); // force redraw + } + if (preview2 != null) { + preview2.setImage(_parent.getPreviewBackground()); + preview2.revalidate(); // force redraw + } + }); + JPanel panel = new JPanel(); + panel.add(bkgdBoxPanel); + return panel; + } + + private final static Logger log = LoggerFactory.getLogger(PreviewPanel.class); + + } diff --git a/java/src/jmri/jmrit/display/SensorIcon.java b/java/src/jmri/jmrit/display/SensorIcon.java index 3fa56dddda7..c89cd85c330 100644 --- a/java/src/jmri/jmrit/display/SensorIcon.java +++ b/java/src/jmri/jmrit/display/SensorIcon.java @@ -449,7 +449,7 @@ public void actionPerformed(ActionEvent e) { protected void editItem() { _paletteFrame = makePaletteFrame(java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("BeanNameSensor"))); _itemPanel = new TableItemPanel<>(_paletteFrame, "Sensor", _iconFamily, - PickListModel.sensorPickModelInstance(), _editor); // NOI18N + PickListModel.sensorPickModelInstance()); // NOI18N ActionListener updateAction = (ActionEvent a) -> { updateItem(); }; diff --git a/java/src/jmri/jmrit/display/SignalHeadIcon.java b/java/src/jmri/jmrit/display/SignalHeadIcon.java index a832be98eb5..195e579037b 100644 --- a/java/src/jmri/jmrit/display/SignalHeadIcon.java +++ b/java/src/jmri/jmrit/display/SignalHeadIcon.java @@ -382,7 +382,7 @@ protected void editItem() { _paletteFrame = makePaletteFrame(java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("BeanNameSignalHead"))); _itemPanel = new SignalHeadItemPanel(_paletteFrame, "SignalHead", getFamily(), - PickListModel.signalHeadPickModelInstance(), _editor); // NOI18N + PickListModel.signalHeadPickModelInstance()); // NOI18N ActionListener updateAction = new ActionListener() { @Override public void actionPerformed(ActionEvent a) { diff --git a/java/src/jmri/jmrit/display/SignalMastIcon.java b/java/src/jmri/jmrit/display/SignalMastIcon.java index 178aef73cc7..53bd30d9a6f 100644 --- a/java/src/jmri/jmrit/display/SignalMastIcon.java +++ b/java/src/jmri/jmrit/display/SignalMastIcon.java @@ -416,7 +416,7 @@ protected void editItem() { _paletteFrame = makePaletteFrame(java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("BeanNameSignalMast"))); _itemPanel = new SignalMastItemPanel(_paletteFrame, "SignalMast", getFamily(), - PickListModel.signalMastPickModelInstance(), _editor); + PickListModel.signalMastPickModelInstance()); ActionListener updateAction = new ActionListener() { @Override public void actionPerformed(ActionEvent a) { diff --git a/java/src/jmri/jmrit/display/TurnoutIcon.java b/java/src/jmri/jmrit/display/TurnoutIcon.java index 15ff924b385..15217941db0 100644 --- a/java/src/jmri/jmrit/display/TurnoutIcon.java +++ b/java/src/jmri/jmrit/display/TurnoutIcon.java @@ -383,7 +383,7 @@ protected void editItem() { _paletteFrame = makePaletteFrame(java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("BeanNameTurnout"))); _itemPanel = new TableItemPanel<>(_paletteFrame, "Turnout", _iconFamily, - PickListModel.turnoutPickModelInstance(), _editor); // NOI18N + PickListModel.turnoutPickModelInstance()); // NOI18N ActionListener updateAction = new ActionListener() { @Override public void actionPerformed(ActionEvent a) { diff --git a/java/src/jmri/jmrit/display/controlPanelEditor/ControlPanelEditor.java b/java/src/jmri/jmrit/display/controlPanelEditor/ControlPanelEditor.java index 106431a3061..5ef11df1575 100644 --- a/java/src/jmri/jmrit/display/controlPanelEditor/ControlPanelEditor.java +++ b/java/src/jmri/jmrit/display/controlPanelEditor/ControlPanelEditor.java @@ -51,7 +51,6 @@ import jmri.CatalogTreeManager; import jmri.ConfigureManager; import jmri.InstanceManager; -import jmri.jmrit.catalog.CatalogPanel; import jmri.jmrit.catalog.ImageIndexEditor; import jmri.jmrit.catalog.NamedIcon; import jmri.jmrit.display.CoordinateEdit; @@ -1069,7 +1068,17 @@ protected Positionable getCurrentSelection(MouseEvent event) { } } else { if (event.isControlDown() && (event.isPopupTrigger() || event.isMetaDown() || event.isAltDown())) { - new ColorDialog(this, getTargetPanel(), ColorDialog.ONLY, null); + ActionListener ca = null; + Editor ed = this; + ca = new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (_itemPalette != null) { + _itemPalette.setEditor(ed); + } + } + }; + new ColorDialog(this, getTargetPanel(), ColorDialog.ONLY, ca); } } if (!isEditable() && selection != null && selection.isHidden()) { diff --git a/java/src/jmri/jmrit/display/controlPanelEditor/ConvertDialog.java b/java/src/jmri/jmrit/display/controlPanelEditor/ConvertDialog.java index 0ff3d26495b..0b7a2061477 100644 --- a/java/src/jmri/jmrit/display/controlPanelEditor/ConvertDialog.java +++ b/java/src/jmri/jmrit/display/controlPanelEditor/ConvertDialog.java @@ -58,7 +58,7 @@ public void windowClosing(java.awt.event.WindowEvent e) { ActionListener updateAction; if (pos instanceof TurnoutIcon) { title = "IndicatorTO"; - _panel = new IndicatorTOItemPanel(_filler, title, null, null, cb._editor) { + _panel = new IndicatorTOItemPanel(_filler, title, null, null) { @Override protected void showIcons() { super.showIcons(); @@ -75,7 +75,7 @@ protected void hideIcons() { }; } else { title = "IndicatorTrack"; - _panel = new IndicatorItemPanel(_filler, title, null, cb._editor) { + _panel = new IndicatorItemPanel(_filler, title, null) { @Override protected void showIcons() { super.showIcons(); @@ -93,12 +93,6 @@ protected void hideIcons() { } _panel.init(updateAction); -/* JPanel content = new JPanel(); - content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); - content.add(new JLabel(Bundle.getMessage("notIndicatorIcon"))); - content.add(_panel); - Dimension dim = content.getPreferredSize(); - */ JPanel buttonPanel = _panel.getBottomPanel(); _panel.getUpdateButton().setText(Bundle.getMessage("convert")); JButton button = new JButton(Bundle.getMessage("skip")); diff --git a/java/src/jmri/jmrit/display/palette/BackgroundItemPanel.java b/java/src/jmri/jmrit/display/palette/BackgroundItemPanel.java index f167c3816b8..720aef0ab60 100644 --- a/java/src/jmri/jmrit/display/palette/BackgroundItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/BackgroundItemPanel.java @@ -1,12 +1,22 @@ package jmri.jmrit.display.palette; +import java.awt.Color; +import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; + +import jmri.util.swing.JmriColorChooser; + import javax.swing.JButton; +import javax.swing.JColorChooser; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.event.ChangeEvent; + import jmri.jmrit.display.DisplayFrame; import jmri.jmrit.display.Editor; +import jmri.util.swing.DrawSquares; import jmri.util.swing.ImagePanel; /** @@ -14,22 +24,33 @@ */ public class BackgroundItemPanel extends IconItemPanel { + JColorChooser _chooser; + JButton _colorButton; + JPanel _colorPanel; + Color _color; + /** * Constructor for background of icons or panel color. * @param parentFrame ItemPalette instance * @param type identifier of the ItemPanel type, should be "Background" - * @param editor Editor that called this ItemPalette */ - public BackgroundItemPanel(DisplayFrame parentFrame, String type, Editor editor) { - super(parentFrame, type, editor); + public BackgroundItemPanel(DisplayFrame parentFrame, String type) { + super(parentFrame, type); _level = Editor.BKG; } @Override public void init() { if (!_initialized) { - super.init(); - _iconPanel.setImage(_backgrounds[0]); + add(instructions()); + initIconFamiliesPanel(false); + initLinkPanel(); + _colorPanel = makeColorPanel(); + add(_colorPanel); + add(makeBottomPanel(null)); + _catalog = makeCatalog(); + add(_catalog); + _initialized = true; } } @@ -42,6 +63,61 @@ protected JPanel instructions() { return panel; } + @Override + protected JPanel makeBottomPanel(ActionListener doneAction) { + JPanel bottomPanel = super.makeBottomPanel(doneAction); + _colorButton = new JButton(Bundle.getMessage("ButtonShowColorPanel")); + _colorButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent a) { + if (_colorPanel.isVisible()) { + hideColorPanel(); + } else { + showColorPanel(); + } + } + }); + _colorButton.setToolTipText(Bundle.getMessage("ToolTipCatalog")); + bottomPanel.add(_colorButton); + + return bottomPanel; + } + + @Override + protected void hideColorPanel() { + _iconPanel.setImage(_frame.getBackground(0)); + Dimension oldDim = getSize(); + boolean isPalette = (_frame instanceof ItemPalette); + Dimension totalDim; + if (isPalette) { + totalDim = ItemPalette._tabPane.getSize(); + } else { + totalDim = _frame.getSize(); + } + _colorPanel.setVisible(false); + _colorPanel.invalidate(); + reSizeDisplay(isPalette, oldDim, totalDim); + _colorButton.setText(Bundle.getMessage("ButtonShowColorPanel")); + } + + protected void showColorPanel() { + deselectIcon(); + hideCatalog(); + _chooser.setColor(_frame.getCurrentColor()); + Dimension oldDim = getSize(); + boolean isPalette = (_frame instanceof ItemPalette); + Dimension totalDim; + if (isPalette) { + totalDim = ItemPalette._tabPane.getSize(); + } else { + totalDim = _frame.getSize(); + } + _colorPanel.setVisible(true); + _colorPanel.invalidate(); + reSizeDisplay(isPalette, oldDim, totalDim); + _colorButton.setText(Bundle.getMessage("HideColorPanel")); + } + @Override protected void initLinkPanel() { JPanel bottomPanel = new JPanel(); @@ -49,34 +125,59 @@ protected void initLinkPanel() { backgroundButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent a) { - hideCatalog(); - ActionListener colorAction = ((ActionEvent event) -> { - colorChanged(); // callback - }); - new ColorDialog(_editor, _editor.getTargetPanel(), ColorDialog.ONLY, colorAction); + if (!_colorPanel.isVisible()) { + showColorPanel(); + } else { + setColor(); + } } }); - backgroundButton.setToolTipText(Bundle.getMessage("ToolTipEditColor")); + backgroundButton.setToolTipText(Bundle.getMessage("ToColorBackground")); bottomPanel.add(backgroundButton); add(bottomPanel); } - - private void colorChanged() { - java.awt.Color c = _editor.getTargetPanel().getBackground(); - java.awt.image.BufferedImage im = jmri.util.swing.DrawSquares.getImage(500, 400, 10, c, c); - _paletteFrame.updateBackground0(im); + + private JPanel makeColorPanel() { + JPanel panel =new JPanel(); + _chooser = new JColorChooser(_frame.getCurrentColor()); + _chooser.setPreviewPanel(new JPanel()); + _chooser.getSelectionModel().addChangeListener((ChangeEvent e) -> { + colorChange(); + }); + _chooser.setColor(_frame.getCurrentColor()); + _chooser = JmriColorChooser.extendColorChooser(_chooser); + panel.add(_chooser); + panel.setVisible(false); + return panel; } - @Override - protected void setEditor(Editor ed) { - super.setEditor(ed); - if (_iconPanel !=null) { - _iconPanel.setImage(_backgrounds[0]); + private void colorChange() { + _color = _chooser.getColor(); + _iconPanel.setImage(DrawSquares.getImage(500, 400, 10, _color, _color)); + _iconPanel.invalidate(); + } + + private void setColor() { + if (_color == null) { + JOptionPane.showMessageDialog(_frame, + Bundle.getMessage("ToColorBackground", Bundle.getMessage("ButtonBackgroundColor")), + Bundle.getMessage("ErrorTitle"), JOptionPane.ERROR_MESSAGE); + return; } + _frame.getEditor().setBackgroundColor(_color); + _frame.updateBackground(_frame.getEditor()); } @Override - protected JPanel makeBgButtonPanel(ImagePanel preview1, ImagePanel preview2) { - return null; // no button to set Preview Bg on BackgroundItemPanel + protected void previewColorChange() { + if (_initialized) { + ImagePanel iconPanel = _catalog.getPreviewPanel(); + if (iconPanel != null) { + iconPanel.setImage(_frame.getPreviewBackground()); + } + _iconPanel.setImage(_frame.getPreviewBackground()); + _iconPanel.setImage(_frame.getBackground(0)); + } } + } diff --git a/java/src/jmri/jmrit/display/palette/ClockItemPanel.java b/java/src/jmri/jmrit/display/palette/ClockItemPanel.java index 1445ec10812..890e0ed8b6e 100644 --- a/java/src/jmri/jmrit/display/palette/ClockItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/ClockItemPanel.java @@ -25,8 +25,8 @@ */ public class ClockItemPanel extends IconItemPanel { - public ClockItemPanel(DisplayFrame parentFrame, String type, Editor editor) { - super(parentFrame, type, editor); + public ClockItemPanel(DisplayFrame parentFrame, String type) { + super(parentFrame, type); setToolTipText(Bundle.getMessage("ToolTipDragIcon")); } @@ -73,7 +73,7 @@ protected void addIconsToPanel(HashMap iconMap) { } _iconPanel.add(panel); } - _iconPanel.setImage(_backgrounds[_paletteFrame.getPreviewBg()]); // pick up shared setting + _iconPanel.setImage(_frame.getPreviewBackground()); // pick up shared setting } public class ClockDragJLabel extends DragJLabel { @@ -93,9 +93,9 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti AnalogClock2Display c; String link = _linkName.getText().trim(); if (link.length() == 0) { - c = new AnalogClock2Display(_editor); + c = new AnalogClock2Display(_frame.getEditor()); } else { - c = new AnalogClock2Display(_editor, link); + c = new AnalogClock2Display(_frame.getEditor(), link); } c.setOpaque(false); c.update(); diff --git a/java/src/jmri/jmrit/display/palette/ColorDialog.java b/java/src/jmri/jmrit/display/palette/ColorDialog.java index 84e95f3bbeb..ecdb6195382 100644 --- a/java/src/jmri/jmrit/display/palette/ColorDialog.java +++ b/java/src/jmri/jmrit/display/palette/ColorDialog.java @@ -77,7 +77,7 @@ public ColorDialog(Frame client, JComponent t, int type, ActionListener ca) { _saveUtil = p.getPopupUtility(); p.remove(); } - } else { + } else { _util = null; } _saveOpaque = t.isOpaque(); diff --git a/java/src/jmri/jmrit/display/palette/DecoratorPanel.java b/java/src/jmri/jmrit/display/palette/DecoratorPanel.java index 1dbf98dd66b..7091e283718 100644 --- a/java/src/jmri/jmrit/display/palette/DecoratorPanel.java +++ b/java/src/jmri/jmrit/display/palette/DecoratorPanel.java @@ -35,6 +35,7 @@ import jmri.jmrit.display.Positionable; import jmri.jmrit.display.PositionableLabel; import jmri.jmrit.display.PositionablePopupUtil; +import jmri.jmrit.display.PreviewPanel; import jmri.jmrit.display.SensorIcon; import jmri.jmrit.display.palette.TextItemPanel.DragDecoratorLabel; import jmri.util.swing.ImagePanel; @@ -68,8 +69,8 @@ public class DecoratorPanel extends JPanel implements ChangeListener { private AJSpinner _heightSpin; private JColorChooser _chooser; - ImagePanel _previewPanel; - private final JPanel _samplePanel; + private PreviewPanel _previewPanel; + private ImagePanel _samplePanel; private PositionablePopupUtil _util; private HashMap _samples = null; private int _selectedButton; @@ -79,32 +80,22 @@ public class DecoratorPanel extends JPanel implements ChangeListener { private AJRadioButton _fontButton; private AJRadioButton _borderButton; private AJRadioButton _backgroundButton; - - protected BufferedImage[] _backgrounds; // array of Image backgrounds - protected JComboBox _bgColorBox; + private boolean addBgCombo; Editor _editor; - protected DisplayFrame _paletteFrame; + protected DisplayFrame _frame; - public DecoratorPanel(Editor editor, DisplayFrame paletteFrame) { - _editor = editor; - _paletteFrame = paletteFrame; + public DecoratorPanel(DisplayFrame frame) { + _editor = frame.getEditor(); + _frame = frame; setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); Color panelBackground = _editor.getTargetPanel().getBackground(); // start using Panel background color - // create array of backgrounds, _currentBackground already set and used - _backgrounds = ItemPanel.makeBackgrounds(null, panelBackground); _chooser = new JColorChooser(panelBackground); _samples = new HashMap<>(); - _previewPanel = new ImagePanel(); - _previewPanel.setLayout(new BorderLayout()); - _previewPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black, 1), - Bundle.getMessage("PreviewBorderTitle"))); - _previewPanel.add(Box.createVerticalStrut(STRUT), BorderLayout.PAGE_START); - _previewPanel.add(Box.createVerticalStrut(STRUT), BorderLayout.PAGE_END); - - _samplePanel = new JPanel(); - _samplePanel.add(Box.createHorizontalStrut(STRUT)); + _samplePanel = new ImagePanel(); + _samplePanel.add(Box.createVerticalStrut(50)); + _samplePanel.setBorder(BorderFactory.createLineBorder(Color.black)); _samplePanel.setOpaque(false); } @@ -143,6 +134,7 @@ public static JPanel makeSpinPanel(String caption, JSpinner spin, ChangeListener /* Called by Palette's TextItemPanel i.e. make a new panel item to drag */ protected void initDecoratorPanel(DragDecoratorLabel sample) { + addBgCombo = true; sample.setDisplayLevel(Editor.LABELS); sample.setBackground(_editor.getTargetPanel().getBackground()); _util = sample.getPopupUtility(); @@ -158,6 +150,7 @@ protected void initDecoratorPanel(DragDecoratorLabel sample) { /* Called by Editor's TextAttrDialog - i.e. update a panel item from menu */ public void initDecoratorPanel(Positionable pos) { + addBgCombo = false; Positionable item = pos.deepClone(); // need copy of PositionableJPanel in PopupUtility _util = item.getPopupUtility(); item.remove(); // don't need copy any more. Removes ghost image of PositionableJPanels @@ -245,16 +238,6 @@ private void finishInit(boolean addBgCombo) { _chooser.getSelectionModel().addChangeListener(this); _chooser.setPreviewPanel(new JPanel()); add(_chooser); - _previewPanel.add(_samplePanel, BorderLayout.CENTER); - - // add a SetBackground combo - if (addBgCombo) { - add(add(makeBgButtonPanel(_previewPanel, null, _backgrounds))); // no listener on this variant - } - add(_previewPanel); - _previewPanel.setImage(_backgrounds[0]); - _previewPanel.revalidate(); // force redraw - // after everything created, set selections _fontPanel.setFontSelections(); updateSamples(); } @@ -331,7 +314,9 @@ private JPanel makeTextPanel(String state, JLabel sample, boolean addTextField) } else { bundleCaption = state; } - panel.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage(bundleCaption))); + panel.setBorder(BorderFactory.createTitledBorder( + BorderFactory.createLineBorder(Color.black, 1), + Bundle.getMessage(bundleCaption))); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); JPanel p = new JPanel(); if (addTextField) { @@ -363,6 +348,13 @@ public void keyReleased(KeyEvent evt) { } panel.add(p); + if (addBgCombo) { + _previewPanel = new PreviewPanel(_frame, _samplePanel, null, true); + } else { + _previewPanel = new PreviewPanel(_frame, _samplePanel, null, false); + } + add(_previewPanel); + p = new JPanel(); _fontButton = makeColorRadioButton("FontColor", FOREGROUND_BUTTON, state); p.add(_fontButton); @@ -421,6 +413,9 @@ public void actionPerformed(ActionEvent a) { return button; } + protected void setPreviewIndex(int idx) { + + } protected void updateSamples() { if (_previewPanel == null) { return; @@ -481,66 +476,9 @@ protected void updateSamples() { _samplePanel.repaint(); } - /** - * Create panel element containing [Set background:] drop down list. - * Special version for Decorator, no access to shared variable previewBgSet. - * @see ItemPanel - * - * @param preview1 ImagePanel containing icon set - * @param preview2 not used, matches method in ItemPanel - * @param imgArray array of colored background images - * @return a JPanel with label and drop down - */ - private JPanel makeBgButtonPanel(@Nonnull ImagePanel preview1, ImagePanel preview2, BufferedImage[] imgArray) { - _bgColorBox = new JComboBox<>(); - _bgColorBox.addItem(Bundle.getMessage("PanelBgColor")); // PanelColor key is specific for CPE, too long for combo - _bgColorBox.addItem(Bundle.getMessage("White")); - _bgColorBox.addItem(Bundle.getMessage("LightGray")); - _bgColorBox.addItem(Bundle.getMessage("DarkGray")); - _bgColorBox.addItem(Bundle.getMessage("Checkers")); - int index; - if (_paletteFrame != null) { - index = _paletteFrame.getPreviewBg(); - } else { - index = 0; - } - _bgColorBox.setSelectedIndex(index); - _bgColorBox.addActionListener((ActionEvent e) -> { - if (imgArray != null) { - // index may repeat - int previewBgSet = _bgColorBox.getSelectedIndex(); // store user choice - if (_paletteFrame != null) { - _paletteFrame.setPreviewBg(previewBgSet); - } - // load background image - log.debug("Palette Decorator setImage called {}", previewBgSet); - preview1.setImage(imgArray[previewBgSet]); - // preview.setOpaque(false); // needed? - preview1.revalidate(); // force redraw - } else { - log.debug("imgArray is empty"); - } - }); - JPanel backgroundPanel = new JPanel(); - backgroundPanel.setLayout(new BoxLayout(backgroundPanel, BoxLayout.Y_AXIS)); - JPanel pp = new JPanel(); - pp.setLayout(new FlowLayout(FlowLayout.CENTER)); - pp.add(new JLabel(Bundle.getMessage("setBackground"))); - pp.add(_bgColorBox); - backgroundPanel.add(pp); - backgroundPanel.setMaximumSize(backgroundPanel.getPreferredSize()); - return backgroundPanel; - } - - // called when editor changed - protected BufferedImage[] getBackgrounds() { - return _backgrounds; - } // called when editor changed - protected void setBackgrounds(BufferedImage[] imgArray) { - _backgrounds = imgArray; - _previewPanel.setImage(imgArray[0]); - _previewPanel.revalidate(); // force redraw + protected void sampleBgColorChange() { + _previewPanel.setBackgroundSelection(_frame.getPreviewBg()); } @Override diff --git a/java/src/jmri/jmrit/display/palette/DetectionPanel.java b/java/src/jmri/jmrit/display/palette/DetectionPanel.java index 3232abd08c6..e3e056f5751 100644 --- a/java/src/jmri/jmrit/display/palette/DetectionPanel.java +++ b/java/src/jmri/jmrit/display/palette/DetectionPanel.java @@ -255,7 +255,7 @@ private void checkDetection() { } else { Sensor sensor = InstanceManager.sensorManagerInstance().getSensor(name); if (sensor == null) { - JOptionPane.showMessageDialog(_parent._paletteFrame, + JOptionPane.showMessageDialog(_parent._frame, Bundle.getMessage("InvalidOccDetector", name), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); _occDetectorName.setText(null); diff --git a/java/src/jmri/jmrit/display/palette/DragJComponent.java b/java/src/jmri/jmrit/display/palette/DragJComponent.java index 9e4eb82762f..9a85c01f43e 100644 --- a/java/src/jmri/jmrit/display/palette/DragJComponent.java +++ b/java/src/jmri/jmrit/display/palette/DragJComponent.java @@ -40,9 +40,8 @@ public abstract class DragJComponent extends JPanel implements DragGestureListen public DragJComponent(DataFlavor flavor, JComponent comp) { super(); - String borderName = ItemPalette.convertText("dragToPanel"); setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), - borderName)); + Bundle.getMessage("dragToPanel"))); // guestimate border is about 5 pixels thick. plus some margin add(comp); Dimension dim = comp.getPreferredSize(); diff --git a/java/src/jmri/jmrit/display/palette/FamilyItemPanel.java b/java/src/jmri/jmrit/display/palette/FamilyItemPanel.java index fd997eb4851..4da104784a4 100644 --- a/java/src/jmri/jmrit/display/palette/FamilyItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/FamilyItemPanel.java @@ -9,7 +9,6 @@ import java.awt.datatransfer.DataFlavor; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.image.BufferedImage; import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; @@ -29,6 +28,7 @@ import jmri.jmrit.catalog.NamedIcon; import jmri.jmrit.display.DisplayFrame; import jmri.jmrit.display.Editor; +import jmri.jmrit.display.PreviewPanel; import jmri.util.swing.ImagePanel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +46,6 @@ public abstract class FamilyItemPanel extends ItemPanel { protected JPanel _iconFamilyPanel; // Holds preview of _iconPanel & _dragIconPanel. They alternate being empty protected ImagePanel _dragIconPanel; // a panel on _iconFamilyPanel - to drag to control panel, hidden upon [Show Icons] protected ImagePanel _iconPanel; // a panel on _iconFamilyPanel - all icons in family, shown upon [Show Icons] - protected JPanel _previewPanel; protected JPanel _familyButtonPanel; // panel of radioButtons to select icon family protected int _buttonPosition = 0; // position of _iconFamilyPanel (TableItemPanels use 1) @@ -69,10 +68,9 @@ public abstract class FamilyItemPanel extends ItemPanel { * @param parentFrame enclosing parentFrame * @param type bean type * @param family icon family - * @param editor panel editor */ - public FamilyItemPanel( DisplayFrame parentFrame, String type, String family, Editor editor) { - super(parentFrame, type, editor); + public FamilyItemPanel( DisplayFrame parentFrame, String type, String family) { + super(parentFrame, type); _family = family; } @@ -255,15 +253,15 @@ private void checkCurrentMap(HashMap iconMap) { _family = null; // user doesn't want to be bothered return; } - InstanceManager.getDefault(jmri.util.PlaceWindow.class).nextTo(_editor, null, _paletteFrame); - _family = JOptionPane.showInputDialog(_paletteFrame, Bundle.getMessage("NoFamilyName"), + InstanceManager.getDefault(jmri.util.PlaceWindow.class).nextTo(_frame.getEditor(), null, _frame); + _family = JOptionPane.showInputDialog(_frame, Bundle.getMessage("NoFamilyName"), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE); } if (_family != null && _family.trim().length() > 0) { // make sure name does not duplicate a known name Iterator it = families.keySet().iterator(); - while (!ItemPalette.familyNameOK(_paletteFrame, _itemType, _family, it)) { - _family = JOptionPane.showInputDialog(_paletteFrame, Bundle.getMessage("EnterFamilyName"), + while (!ItemPalette.familyNameOK(_itemType, _family, it)) { + _family = JOptionPane.showInputDialog(_frame, Bundle.getMessage("EnterFamilyName"), Bundle.getMessage("createNewIconSet", _itemType), JOptionPane.QUESTION_MESSAGE); if (_family == null) { return; // user cancelled @@ -274,12 +272,12 @@ private void checkCurrentMap(HashMap iconMap) { if (_suppressNamePrompts) { return; // user not interested in updating catalog } - int result = JOptionPane.showConfirmDialog(_paletteFrame, + int result = JOptionPane.showConfirmDialog(_frame, Bundle.getMessage("UnkownFamilyName", _family), Bundle.getMessage("QuestionTitle"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { - if (!ItemPalette.addFamily(_paletteFrame, _itemType, _family, iconMap)) { - JOptionPane.showMessageDialog(_paletteFrame, + if (!ItemPalette.addFamily(_itemType, _family, iconMap)) { + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("badName", _family, _itemType), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); // } else { // icon set added to catalog with name _family @@ -295,8 +293,8 @@ private void checkCurrentMap(HashMap iconMap) { protected String getValidFamilyName(String family) { HashMap> families = ItemPalette.getFamilyMaps(_itemType); Iterator it = families.keySet().iterator(); - while (!ItemPalette.familyNameOK(_paletteFrame, _itemType, family, it)) { - family = JOptionPane.showInputDialog(_paletteFrame, Bundle.getMessage("EnterFamilyName"), + while (!ItemPalette.familyNameOK(_itemType, family, it)) { + family = JOptionPane.showInputDialog(_frame, Bundle.getMessage("EnterFamilyName"), Bundle.getMessage("createNewIconSet", _itemType), JOptionPane.QUESTION_MESSAGE); if (family == null) { return null; // user cancelled @@ -307,8 +305,8 @@ protected String getValidFamilyName(String family) { } protected boolean addFamily(String type, String family, HashMap iconMap) { - if (!ItemPalette.addFamily(_paletteFrame, type, family, iconMap)) { - JOptionPane.showMessageDialog(_paletteFrame, + if (!ItemPalette.addFamily(type, family, iconMap)) { + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("badName", _family, _itemType), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); return false; @@ -543,29 +541,24 @@ ActionListener init(String f) { */ protected void addFamilyPanels(JPanel familyPanel) { log.debug("addFamilyPanels for {}", _itemType); - boolean makeBgBoxPanel = false; if (_iconPanel == null) { // don't overwrite existing _iconPanel _iconPanel = new ImagePanel(); _iconPanel.setLayout(new FlowLayout()); _iconPanel.setBorder(BorderFactory.createLineBorder(Color.black)); - makeBgBoxPanel = true; + _iconPanel.setImage(_frame.getPreviewBackground()); + _iconFamilyPanel.add(_iconPanel); } if (!_suppressDragging) { makeDragIconPanel(0); } - if (makeBgBoxPanel) { - if (!_update && !_suppressDragging) { - _previewPanel = makePreviewPanel(_iconPanel, _dragIconPanel); - } else { - _previewPanel = makePreviewPanel(_iconPanel, null); - _previewPanel.setVisible(false); - } - _iconFamilyPanel.add(_previewPanel); + if (!_update && !_suppressDragging) { + _previewPanel = new PreviewPanel(_frame, _iconPanel, _dragIconPanel, true); } else { - _iconPanel.setImage(_backgrounds[0]); - _iconFamilyPanel.add(_iconPanel); + _previewPanel = new PreviewPanel(_frame, _iconPanel, null, false); + _previewPanel.setVisible(false); } + _iconFamilyPanel.add(_previewPanel); _iconFamilyPanel.add(familyPanel); if (_bottom1Panel != null) { _bottom1Panel.setVisible(true); @@ -592,25 +585,21 @@ protected void makeDragIconPanel(int position) { } else { _dragIconPanel.removeAll(); } - if (_backgrounds != null) { - int previewBgSet = _paletteFrame.getPreviewBg(); - _dragIconPanel.setImage(_backgrounds[previewBgSet]); // pick up shared setting - if (_iconPanel != null) { - _iconPanel.setImage(_backgrounds[previewBgSet]); // pick up shared setting - } - } else { - log.error("FamilyItemPanel - no value for previewBgSet"); + + _dragIconPanel.setImage(_frame.getPreviewBackground()); // pick up shared setting + if (_iconPanel != null) { + _iconPanel.setImage(_frame.getPreviewBackground()); // pick up shared setting } _dragIconPanel.setVisible(true); } protected void familiesMissing() { - int result = JOptionPane.showConfirmDialog(_paletteFrame, + int result = JOptionPane.showConfirmDialog(_frame, Bundle.getMessage("AllFamiliesDeleted", _itemType), Bundle.getMessage("QuestionTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { - ItemPalette.loadMissingItemType(_itemType, _editor); + ItemPalette.loadMissingItemType(_itemType); initIconFamiliesPanel(); _bottom1Panel.setVisible(true); _bottom2Panel.setVisible(false); @@ -666,7 +655,7 @@ protected void addIconsToPanel(HashMap iconMap, ImagePanel ic if (log.isDebugEnabled()) { log.debug("add icon {} to Panel. key= {}", icon.getName(), key); } - String borderName = getIconBorderName(key); + String borderName = ItemPalette.convertText(key); panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), borderName)); JLabel image; if (dropIcon) { @@ -722,10 +711,6 @@ protected void addIconsToPanel(HashMap iconMap, ImagePanel ic log.debug("addIconsToPanel for type {} family \"{}\"", _itemType, _family); } - protected String getIconBorderName(String key) { - return ItemPalette.convertText(key); - } - protected JLabel getDragger(DataFlavor flavor, HashMap map, NamedIcon icon) { return null; } @@ -756,7 +741,7 @@ protected void makeDndIconPanel(HashMap iconMap, String displ protected JPanel makeDragIcon(NamedIcon icon, JLabel label) { JPanel panel = new JPanel(new FlowLayout()); - String borderName = ItemPalette.convertText("dragToPanel"); + String borderName = Bundle.getMessage("dragToPanel"); panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), borderName)); panel.setToolTipText(Bundle.getMessage("ToolTipDragIcon")); @@ -775,8 +760,8 @@ protected JPanel makeDragIcon(NamedIcon icon, JLabel label) { } protected void hideIcons() { - boolean isPalette = (_paletteFrame instanceof ItemPalette); - Dimension totalDim = _paletteFrame.getSize(); + boolean isPalette = (_frame instanceof ItemPalette); + Dimension totalDim = _frame.getSize(); Dimension oldDim = getSize(); if (_update) { _previewPanel.setVisible(false); @@ -796,8 +781,8 @@ protected void hideIcons() { } protected void showIcons() { - boolean isPalette = (_paletteFrame instanceof ItemPalette); - Dimension totalDim = _paletteFrame.getSize(); + boolean isPalette = (_frame instanceof ItemPalette); + Dimension totalDim = _frame.getSize(); Dimension oldDim = getSize(); if (_update) { _previewPanel.setVisible(true); @@ -820,7 +805,7 @@ protected void showIcons() { * Action item for deletion of an icon family. */ protected void deleteFamilySet() { - if (JOptionPane.showConfirmDialog(_paletteFrame, Bundle.getMessage("confirmDelete", _family), + if (JOptionPane.showConfirmDialog(_frame, Bundle.getMessage("confirmDelete", _family), Bundle.getMessage("QuestionTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { ItemPalette.removeIconMap(_itemType, _family); @@ -861,7 +846,7 @@ public void actionPerformed(ActionEvent a) { } protected boolean newFamilyDialog() { - String family = JOptionPane.showInputDialog(_paletteFrame, Bundle.getMessage("EnterFamilyName"), + String family = JOptionPane.showInputDialog(_frame, Bundle.getMessage("EnterFamilyName"), Bundle.getMessage("createNewIconSet", _itemType), JOptionPane.QUESTION_MESSAGE); if (family == null || family.trim().length() == 0) { // bail out @@ -870,7 +855,7 @@ protected boolean newFamilyDialog() { Iterator iter = ItemPalette.getFamilyMaps(_itemType).keySet().iterator(); while (iter.hasNext()) { if (family.equals(iter.next())) { - JOptionPane.showMessageDialog(_paletteFrame, + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("DuplicateFamilyName", family, _itemType), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); return false; @@ -880,30 +865,9 @@ protected boolean newFamilyDialog() { return true; } - @Override - protected void setPreviewBg(int index) { - if (_dialog != null) { - ImagePanel iconPanel = _dialog.getIconEditPanel(); - if (iconPanel != null) { - iconPanel.setImage(_backgrounds[index]); - } - iconPanel = _dialog.getCatalogPreviewPanel(); - if (iconPanel != null) { - iconPanel.setImage(_backgrounds[index]); - } - } - if (_iconPanel != null) { - _iconPanel.setImage(_backgrounds[index]); - } - } - - @Override - protected void updateBackground0(BufferedImage im) { - _backgrounds[0] = im; - } - protected void openDialog(String type, String family, HashMap iconMap) { closeDialogs(); + previewColorChange(); // set panel color for icon's background _dialog = new IconDialog(type, family, this, iconMap); } @@ -974,21 +938,18 @@ protected void setFamilyButton() { } @Override - protected void setEditor(Editor ed) { - super.setEditor(ed); - if (_initialized) { - boolean visible = (_iconPanel != null && _iconPanel.isVisible()); // check for invalid _initialized state - makeDragIconPanel(0); - makeDndIconPanel(_currentIconMap, "BeanStateUnknown"); - if (_family != null) { - setFamily(_family); + protected void previewColorChange() { + if (_dialog != null) { + ImagePanel iconPanel = _dialog.getIconEditPanel(); + if (iconPanel != null) { + iconPanel.setImage(_frame.getPreviewBackground()); } - if (visible) { - _showIconsButton.setText(Bundle.getMessage("HideIcons")); - } else { - _showIconsButton.setText(Bundle.getMessage("ShowIcons")); + iconPanel = _dialog.getCatalogPreviewPanel(); + if (iconPanel != null) { + iconPanel.setImage(_frame.getPreviewBackground()); } } + super.previewColorChange(); } protected void setIconMap(HashMap map) { diff --git a/java/src/jmri/jmrit/display/palette/IconDialog.java b/java/src/jmri/jmrit/display/palette/IconDialog.java index ae25762405e..7c93db2629d 100644 --- a/java/src/jmri/jmrit/display/palette/IconDialog.java +++ b/java/src/jmri/jmrit/display/palette/IconDialog.java @@ -17,6 +17,7 @@ import javax.swing.JScrollPane; import jmri.jmrit.catalog.CatalogPanel; import jmri.jmrit.catalog.NamedIcon; +import jmri.util.swing.DrawSquares; import jmri.util.swing.ImagePanel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -92,9 +93,9 @@ private CatalogPanel makeCatalog() { catalog.setToolTipText(Bundle.getMessage("ToolTipDragIcon")); ImagePanel panel = catalog.getPreviewPanel(); if (!_parent.isUpdate()) { - panel.setImage(_parent._backgrounds[_parent.getParentFrame().getPreviewBg()]); + panel.setImage(_parent._frame.getPreviewBackground()); } else { - panel.setImage(_parent._backgrounds[0]); //update always should be the panel background + panel.setImage(_parent._frame.getBackground(0)); //update always should be the panel background } return catalog; } @@ -127,7 +128,7 @@ protected boolean doDoneAction() { ItemPalette.removeIconMap(_type, _family); return _parent.addFamily(_type, _family, _iconMap); } else if (!_parent.isUnstoredMap()) { - JOptionPane.showMessageDialog(_parent._paletteFrame, + JOptionPane.showMessageDialog(_parent._frame, Bundle.getMessage("DuplicateFamilyName", _family, _type), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); return false; @@ -212,9 +213,9 @@ protected void makeIconPanel(HashMap iconMap, ImagePanel icon iconPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black, 1), Bundle.getMessage("PreviewBorderTitle"))); if (!_parent.isUpdate()) { - iconPanel.setImage(_parent._backgrounds[_parent.getParentFrame().getPreviewBg()]); + iconPanel.setImage(_parent._frame.getPreviewBackground()); } else { - iconPanel.setImage(_parent._backgrounds[0]); //update always should be the panel background + iconPanel.setImage(_parent._frame.getBackground(0)); //update always should be the panel background } log.debug("iconMap size = {}", _iconMap.size()); _parent.addIconsToPanel(iconMap, iconPanel, true); diff --git a/java/src/jmri/jmrit/display/palette/IconItemPanel.java b/java/src/jmri/jmrit/display/palette/IconItemPanel.java index 12eac5b1ff2..d108f1f2e2e 100644 --- a/java/src/jmri/jmrit/display/palette/IconItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/IconItemPanel.java @@ -15,9 +15,9 @@ import java.awt.dnd.DropTargetListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; -import java.awt.image.BufferedImage; import java.io.IOException; import java.util.HashMap; import java.util.Iterator; @@ -38,6 +38,7 @@ import jmri.jmrit.display.Editor; import jmri.jmrit.display.LinkingLabel; import jmri.jmrit.display.PositionableLabel; +import jmri.jmrit.display.PreviewPanel; import jmri.util.swing.ImagePanel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,10 +64,9 @@ public class IconItemPanel extends ItemPanel { * * @param type type * @param parentFrame parentFrame - * @param editor editor */ - public IconItemPanel(DisplayFrame parentFrame, String type, Editor editor) { - super(parentFrame, type, editor); + public IconItemPanel(DisplayFrame parentFrame, String type) { + super(parentFrame, type); setToolTipText(Bundle.getMessage("ToolTipDragIcon")); } @@ -74,15 +74,15 @@ public IconItemPanel(DisplayFrame parentFrame, String type, Editor editor) { public void init() { if (!_initialized) { add(instructions()); - initIconFamiliesPanel(); + initIconFamiliesPanel(true); initLinkPanel(); - makeBottomPanel(null); + add(makeBottomPanel(null)); _catalog = makeCatalog(); add(_catalog); super.init(); } _catalog.invalidate(); - _iconPanel.invalidate(); + _previewPanel.invalidate(); } /** @@ -96,7 +96,7 @@ public void init(ActionListener doneAction) { _update = true; _suppressDragging = true; // no dragging when updating add(new JLabel(Bundle.getMessage("ToUpdateIcon", Bundle.getMessage("updateButton")))); - initIconFamiliesPanel(); + initIconFamiliesPanel(true); makeBottomPanel(doneAction); _catalog = makeCatalog(); add(_catalog); @@ -117,13 +117,13 @@ protected JPanel instructions() { return panel; } - private CatalogPanel makeCatalog() { + protected CatalogPanel makeCatalog() { CatalogPanel catalog = CatalogPanel.makeDefaultCatalog(false, false, !_update); ImagePanel panel = catalog.getPreviewPanel(); if (!isUpdate()) { - panel.setImage(_backgrounds[getParentFrame().getPreviewBg()]); + panel.setImage(_frame.getPreviewBackground()); } else { - panel.setImage(_backgrounds[0]); //update always should be the panel background + panel.setImage(_frame.getBackground(0)); //update always should be the panel background catalog.setParent(this); } catalog.setToolTipText(Bundle.getMessage("ToolTipDragCatalog")); @@ -132,32 +132,28 @@ private CatalogPanel makeCatalog() { } @Override - protected void setPreviewBg(int index) { - if (_catalog != null) { + protected void previewColorChange() { + if (_initialized) { ImagePanel iconPanel = _catalog.getPreviewPanel(); if (iconPanel != null) { - iconPanel.setImage(_backgrounds[index]); + iconPanel.setImage(_frame.getPreviewBackground()); } } - if (_iconPanel != null) { - _iconPanel.setImage(_backgrounds[index]); - } + super.previewColorChange(); } - @Override - protected void updateBackground0(BufferedImage im) { - _backgrounds[0] = im; - } - - /** + /* * Plain icons have only one family, usually named "set". * Override for plain icon {@literal &} background and put all icons here. */ - protected void initIconFamiliesPanel() { + protected void initIconFamiliesPanel(boolean addComboBox) { if (_iconPanel == null) { // create a new one _iconPanel = new ImagePanel(); + _iconPanel.add(Box.createVerticalStrut(20)); _iconPanel.setBorder(BorderFactory.createLineBorder(Color.black)); - add(makePreviewPanel(_iconPanel, null), 1); + _previewPanel = new PreviewPanel(_frame, _iconPanel, null, addComboBox); + _iconPanel.setImage(_frame.getPreviewBackground()); + add(_previewPanel, 1); _iconPanel.addMouseListener(new IconListener()); } @@ -187,7 +183,7 @@ protected void addIconsToPanel(HashMap iconMap) { if (_iconPanel == null) { _iconPanel = new ImagePanel(); - add(makePreviewPanel(_iconPanel, null), 1); + add(new PreviewPanel(_frame, _iconPanel, null, true), 1); log.error("setFamily called with _iconPanel == null typs= {}", _itemType); } else { _iconPanel.removeAll(); @@ -200,27 +196,9 @@ protected void addIconsToPanel(HashMap iconMap) { IconDisplayPanel panel = new IconDisplayPanel(borderName, icon); _iconPanel.add(panel); } -// _iconPanel.setPreferredSize(new Dimension((iconMap.size()+1)*100, 100)); - } - - @Override - protected void setEditor(Editor ed) { - super.setEditor(ed); - if (_initialized) { - addIconsToPanel(_iconMap); - } } - protected void updateFamiliesPanel() { - log.debug("updateFamiliesPanel for {}", _itemType); - initIconFamiliesPanel(); - validate(); - } - - /** - * SOUTH Panel - */ - private void makeBottomPanel(ActionListener doneAction) { + protected JPanel makeBottomPanel(ActionListener doneAction) { JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new FlowLayout()); @@ -273,17 +251,20 @@ public void actionPerformed(ActionEvent a) { updateButton.addActionListener(doneAction); bottomPanel.add(updateButton); } - add(bottomPanel); + return bottomPanel; + } + + protected void hideColorPanel() { } - void hideCatalog() { + protected void hideCatalog() { Dimension oldDim = getSize(); - boolean isPalette = (_paletteFrame instanceof ItemPalette); + boolean isPalette = (_frame instanceof ItemPalette); Dimension totalDim; if (isPalette) { totalDim = ItemPalette._tabPane.getSize(); } else { - totalDim = _paletteFrame.getSize(); + totalDim = _frame.getSize(); } _catalog.setVisible(false); _catalog.invalidate(); @@ -291,16 +272,16 @@ void hideCatalog() { _catalogButton.setText(Bundle.getMessage("ButtonShowCatalog")); } - void showCatalog() { + protected void showCatalog() { + hideColorPanel(); Dimension oldDim = getSize(); - boolean isPalette = (_paletteFrame instanceof ItemPalette); + boolean isPalette = (_frame instanceof ItemPalette); Dimension totalDim; if (isPalette) { totalDim = ItemPalette._tabPane.getSize(); } else { - totalDim = _paletteFrame.getSize(); + totalDim = _frame.getSize(); } -// _catalog.setWidth(oldDim.width); _catalog.setVisible(true); _catalog.invalidate(); reSizeDisplay(isPalette, oldDim, totalDim); @@ -344,7 +325,7 @@ protected void putIcon(String name, NamedIcon icon) { */ protected void deleteIcon() { if (_selectedIcon == null) { - JOptionPane.showMessageDialog(_paletteFrame, Bundle.getMessage("ToSelectIcon"), + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("ToSelectIcon"), Bundle.getMessage("ReminderTitle"), JOptionPane.INFORMATION_MESSAGE); return; } @@ -357,7 +338,7 @@ protected void deleteIcon() { private void renameIcon() { if (_selectedIcon != null) { - String name = JOptionPane.showInputDialog(_paletteFrame, Bundle.getMessage("NoIconName"), + String name = JOptionPane.showInputDialog(_frame, Bundle.getMessage("NoIconName"), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE); if (name != null) { _iconMap.remove(_selectedIcon._borderName); @@ -366,7 +347,7 @@ private void renameIcon() { deselectIcon(); } } else { - JOptionPane.showMessageDialog(_paletteFrame, Bundle.getMessage("ToSelectIcon"), + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("ToSelectIcon"), Bundle.getMessage("ReminderTitle"), JOptionPane.INFORMATION_MESSAGE); } } @@ -462,9 +443,9 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti String link = _linkName.getText().trim(); PositionableLabel l; if (link.length() == 0) { - l = new PositionableLabel(NamedIcon.getIconByName(url), _editor); + l = new PositionableLabel(NamedIcon.getIconByName(url), _frame.getEditor()); } else { - l = new LinkingLabel(NamedIcon.getIconByName(url), _editor, link); + l = new LinkingLabel(NamedIcon.getIconByName(url), _frame.getEditor(), link); } l.setLevel(level); return l; @@ -550,7 +531,7 @@ private void accept(DropTargetDropEvent e, NamedIcon newIcon) { } } - public class IconDisplayPanel extends JPanel implements MouseListener{ + public class IconDisplayPanel extends JPanel implements MouseListener { String _borderName; NamedIcon _icon; @@ -647,7 +628,7 @@ public void mouseExited(MouseEvent event) { } } - class IconListener implements MouseListener { + class IconListener extends MouseAdapter { @Override public void mouseClicked(MouseEvent event) { if (event.getSource() instanceof IconDisplayPanel) { @@ -657,18 +638,6 @@ public void mouseClicked(MouseEvent event) { deselectIcon(); } } - @Override - public void mousePressed(MouseEvent event) { - } - @Override - public void mouseReleased(MouseEvent event) { - } - @Override - public void mouseEntered(MouseEvent event) { - } - @Override - public void mouseExited(MouseEvent event) { - } } private final static Logger log = LoggerFactory.getLogger(IconItemPanel.class); diff --git a/java/src/jmri/jmrit/display/palette/IndicatorItemPanel.java b/java/src/jmri/jmrit/display/palette/IndicatorItemPanel.java index a84cbd8ae24..ac83b1aeb63 100644 --- a/java/src/jmri/jmrit/display/palette/IndicatorItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/IndicatorItemPanel.java @@ -27,11 +27,11 @@ public class IndicatorItemPanel extends FamilyItemPanel { private DetectionPanel _detectPanel; - /** - * Constructor for plain icons and backgrounds. + /* + * Constructor for track icons. */ - public IndicatorItemPanel(DisplayFrame parentFrame, String type, String family, Editor editor) { - super(parentFrame, type, family, editor); + public IndicatorItemPanel(DisplayFrame parentFrame, String type, String family) { + super(parentFrame, type, family); } /** @@ -157,7 +157,7 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti log.debug("IndicatorDragJLabel.getTransferData"); } if (flavor.isMimeTypeEqual(Editor.POSITIONABLE_FLAVOR)) { - IndicatorTrackIcon t = new IndicatorTrackIcon(_editor); + IndicatorTrackIcon t = new IndicatorTrackIcon(_frame.getEditor()); t.setOccBlock(_detectPanel.getOccBlock()); t.setOccSensor(_detectPanel.getOccSensor()); diff --git a/java/src/jmri/jmrit/display/palette/IndicatorTOIconDialog.java b/java/src/jmri/jmrit/display/palette/IndicatorTOIconDialog.java index 888a4ed0a5a..35c6f539b8e 100644 --- a/java/src/jmri/jmrit/display/palette/IndicatorTOIconDialog.java +++ b/java/src/jmri/jmrit/display/palette/IndicatorTOIconDialog.java @@ -77,7 +77,7 @@ private void addFamilySet() { } } Object[] selections = options.toArray(); - String key = (String) JOptionPane.showInputDialog(_parent._paletteFrame, + String key = (String) JOptionPane.showInputDialog(_parent._frame, Bundle.getMessage("PickStatus"), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE, null, selections, selections[0]); if (key != null) { @@ -86,7 +86,7 @@ private void addFamilySet() { // new IndicatorTOIconDialog(_type, null, parent, _key, _iconMap); } } else { - JOptionPane.showMessageDialog(_parent._paletteFrame, + JOptionPane.showMessageDialog(_parent._frame, Bundle.getMessage("AllStatus"), Bundle.getMessage("MessageTitle"), JOptionPane.INFORMATION_MESSAGE); } diff --git a/java/src/jmri/jmrit/display/palette/IndicatorTOItemPanel.java b/java/src/jmri/jmrit/display/palette/IndicatorTOItemPanel.java index 2adaf21fcca..3387fc4e8c9 100644 --- a/java/src/jmri/jmrit/display/palette/IndicatorTOItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/IndicatorTOItemPanel.java @@ -44,8 +44,8 @@ public class IndicatorTOItemPanel extends TableItemPanel { private DetectionPanel _detectPanel; protected HashMap> _iconGroupsMap; - public IndicatorTOItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model, Editor editor) { - super(parentFrame, type, family, model, editor); + public IndicatorTOItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model) { + super(parentFrame, type, family, model); } /** @@ -58,7 +58,7 @@ public void init() { if (!_initialized) { _update = false; _suppressDragging = false; - add(initTablePanel(_model, _editor)); // top of Panel + add(initTablePanel(_model)); // top of Panel _detectPanel = new DetectionPanel(this); add(_detectPanel); initIconFamiliesPanel(); @@ -127,7 +127,7 @@ private void checkCurrentMaps(HashMap> iconMa } } if (ItemPalette.getLevel4Family(_itemType, _family) != null) { - JOptionPane.showMessageDialog(_paletteFrame, + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("DuplicateFamilyName", _family, _itemType), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); // make sure name does not duplicate a known name @@ -135,7 +135,7 @@ private void checkCurrentMaps(HashMap> iconMa } if (!_suppressNamePrompts) { if (_family == null || _family.trim().length() == 0) { - _family = JOptionPane.showInputDialog(_paletteFrame, Bundle.getMessage("NoFamilyName"), + _family = JOptionPane.showInputDialog(_frame, Bundle.getMessage("NoFamilyName"), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE); if (_family == null || _family.trim().length() == 0) { // bail out @@ -144,11 +144,11 @@ private void checkCurrentMaps(HashMap> iconMa return; } } - int result = JOptionPane.showConfirmDialog(_paletteFrame, + int result = JOptionPane.showConfirmDialog(_frame, Bundle.getMessage("UnkownFamilyName", _family), Bundle.getMessage("QuestionTitle"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { - ItemPalette.addLevel4Family(_paletteFrame, _itemType, _family, iconMaps); + ItemPalette.addLevel4Family(_itemType, _family, iconMaps); } else if (result == JOptionPane.NO_OPTION) { _suppressNamePrompts = true; } @@ -159,8 +159,8 @@ private void checkCurrentMaps(HashMap> iconMa * Get a handle in order to change visibility. */ @Override - protected JPanel initTablePanel(PickListModel model, Editor editor) { - _tablePanel = super.initTablePanel(model, editor); + protected JPanel initTablePanel(PickListModel model) { + _tablePanel = super.initTablePanel(model); return _tablePanel; } @@ -320,7 +320,7 @@ public void actionPerformed(ActionEvent a) { @Override protected boolean newFamilyDialog() { - String family = JOptionPane.showInputDialog(_paletteFrame, Bundle.getMessage("EnterFamilyName"), + String family = JOptionPane.showInputDialog(_frame, Bundle.getMessage("EnterFamilyName"), Bundle.getMessage("createNewIconSet", _itemType), JOptionPane.QUESTION_MESSAGE); if (family == null || family.trim().length() == 0) { // bail out @@ -329,7 +329,7 @@ protected boolean newFamilyDialog() { Iterator iter = ItemPalette.getLevel4FamilyMaps(_itemType).keySet().iterator(); while (iter.hasNext()) { if (family.equals(iter.next())) { - JOptionPane.showMessageDialog(_paletteFrame, + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("DuplicateFamilyName", family, _itemType), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); return false; @@ -383,7 +383,7 @@ public void actionPerformed(ActionEvent a) { */ @Override protected void deleteFamilySet() { - if (JOptionPane.showConfirmDialog(_paletteFrame, Bundle.getMessage("confirmDelete", _family), + if (JOptionPane.showConfirmDialog(_frame, Bundle.getMessage("confirmDelete", _family), Bundle.getMessage("QuestionTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) { ItemPalette.removeLevel4IconMap(_itemType, _family, null); @@ -401,7 +401,7 @@ private void createNewFamily(String family) { for (int i = 0; i < STATUS_KEYS.length; i++) { _iconGroupsMap.put(STATUS_KEYS[i], makeNewIconMap("Turnout")); // NOI18N } - ItemPalette.addLevel4Family(_editor, _itemType, family, _iconGroupsMap); + ItemPalette.addLevel4Family(_itemType, family, _iconGroupsMap); _tablePanel.setVisible(true); initIconFamiliesPanel(); setFamily(family); @@ -412,19 +412,19 @@ private void createNewFamily(String family) { * Action item to rename an icon family. */ protected void renameFamily() { - String family = JOptionPane.showInputDialog(_paletteFrame, Bundle.getMessage("EnterFamilyName"), + String family = JOptionPane.showInputDialog(_frame, Bundle.getMessage("EnterFamilyName"), Bundle.getMessage("renameFamily"), JOptionPane.QUESTION_MESSAGE); if (family != null && family.trim().length() > 0) { ItemPalette.removeLevel4IconMap(_itemType, _family, null); _family = family; - ItemPalette.addLevel4Family(_editor, _itemType, family, _iconGroupsMap); + ItemPalette.addLevel4Family(_itemType, family, _iconGroupsMap); _tablePanel.setVisible(true); initIconFamiliesPanel(); setFamily(family); } } - /** + /* * _iconGroupsMap holds edit changes when done is pressed. */ protected void updateIconGroupsMap(String key, HashMap iconMap) { @@ -546,7 +546,7 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti } if (flavor.isMimeTypeEqual(Editor.POSITIONABLE_FLAVOR)) { - IndicatorTurnoutIcon t = new IndicatorTurnoutIcon(_editor); + IndicatorTurnoutIcon t = new IndicatorTurnoutIcon(_frame.getEditor()); t.setOccBlock(_detectPanel.getOccBlock()); t.setOccSensor(_detectPanel.getOccSensor()); diff --git a/java/src/jmri/jmrit/display/palette/InitEventListener.java b/java/src/jmri/jmrit/display/palette/InitEventListener.java deleted file mode 100644 index dc6bafd2cba..00000000000 --- a/java/src/jmri/jmrit/display/palette/InitEventListener.java +++ /dev/null @@ -1,8 +0,0 @@ -package jmri.jmrit.display.palette; - -/** - * Custom listener to respond to redisplay of a tabbed pane. - */ -public interface InitEventListener { - void onInitEvent(int choice, int selectedPane); -} diff --git a/java/src/jmri/jmrit/display/palette/ItemDialog.java b/java/src/jmri/jmrit/display/palette/ItemDialog.java index 664b4d7a83e..bc3ecca866b 100644 --- a/java/src/jmri/jmrit/display/palette/ItemDialog.java +++ b/java/src/jmri/jmrit/display/palette/ItemDialog.java @@ -10,13 +10,12 @@ * While not exactly a singleton class, only one version of the dialog should be * viable at a time - i.e. the version for a particular device type. * - * @author Pete Cressman Copyright (c) 2010 + * @author Pete Cressman Copyright (c) 2010, 2020 */ public class ItemDialog extends JmriJFrame { protected FamilyItemPanel _parent; protected String _type; - // protected String _family; public ItemDialog(String type, String title, FamilyItemPanel parent) { super(title, false, false); diff --git a/java/src/jmri/jmrit/display/palette/ItemPalette.java b/java/src/jmri/jmrit/display/palette/ItemPalette.java index 75644f4fcf1..4301f5dbb6b 100644 --- a/java/src/jmri/jmrit/display/palette/ItemPalette.java +++ b/java/src/jmri/jmrit/display/palette/ItemPalette.java @@ -143,6 +143,7 @@ class TextItemPanel public class ItemPalette extends DisplayFrame implements ChangeListener { public static final int STRUT_SIZE = 10; + static final String RED_X = "resources/icons/misc/X-red.gif"; protected static JTabbedPane _tabPane; private static HashMap _tabIndex; @@ -204,20 +205,20 @@ static CatalogTreeNode store3levelMap(String type, HashMap(); _indicatorTOMaps = new HashMap<>(); - if (!loadSavedIcons(ed)) { - loadDefaultIcons(ed); + if (!loadSavedIcons()) { + loadDefaultIcons(); } } } - static boolean loadSavedIcons(Editor ed) { + static boolean loadSavedIcons() { CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class); CatalogTree tree = manager.getBySystemName("NXPI"); if (tree != null) { @@ -230,13 +231,13 @@ static boolean loadSavedIcons(Editor ed) { // not very elegant (i.e. extensible), but maybe all that's needed. if (typeName.equals("IndicatorTO")) { HashMap>> familyTOMap - = loadIndicatorFamilyMap(node, ed); + = loadIndicatorFamilyMap(node); log.debug("Add {} indicatorTO families to item type {} for _indicatorTOMaps.", familyTOMap.size(), typeName ); _indicatorTOMaps.put(typeName, familyTOMap); } else { HashMap> familyMap - = loadFamilyMap(node, ed); + = loadFamilyMap(node); _iconMaps.put(typeName, familyMap); log.debug("Add item type {} to _iconMaps.", typeName); } @@ -248,19 +249,19 @@ static boolean loadSavedIcons(Editor ed) { } static HashMap>> - loadIndicatorFamilyMap(CatalogTreeNode node, Editor ed) { + loadIndicatorFamilyMap(CatalogTreeNode node) { HashMap>> familyMap = new HashMap<>(); Enumeration ee = node.children(); while (ee.hasMoreElements()) { CatalogTreeNode famNode = (CatalogTreeNode)ee.nextElement(); String name = (String) famNode.getUserObject(); - familyMap.put(name, loadFamilyMap(famNode, ed)); + familyMap.put(name, loadFamilyMap(famNode)); } return familyMap; } - static HashMap> loadFamilyMap(CatalogTreeNode node, Editor ed) { + static HashMap> loadFamilyMap(CatalogTreeNode node) { HashMap> familyMap = new HashMap<>(); Enumeration ee = node.children(); while (ee.hasMoreElements()) { @@ -274,17 +275,12 @@ static HashMap> loadFamilyMap(CatalogTreeNode String path = leaf.getPath(); NamedIcon icon = NamedIcon.getIconByName(path); if (icon == null) { - icon = ed.loadFailed(iconName, path); - if (icon == null) { - log.info("{} removed for url = {}", iconName, path); - } else { - InstanceManager.getDefault(CatalogTreeManager.class).indexChanged(true); - } - } - if (icon != null) { - iconMap.put(iconName, icon); - log.debug("Add {} icon to family \"{}\"", iconName, familyName); + log.warn("loadFamilyMap cannot find icon \"{}\" in family\"{}\" at path \"{}\"", iconName, familyName, path); + String fileName = RED_X; + icon = new jmri.jmrit.catalog.NamedIcon(fileName, fileName); } + iconMap.put(iconName, icon); + log.debug("Add {} icon to family \"{}\"", iconName, familyName); } familyMap.put(familyName, iconMap); } @@ -294,7 +290,6 @@ static HashMap> loadFamilyMap(CatalogTreeNode static List getDefaultIconItemTypes() throws org.jdom2.JDOMException, java.io.IOException { URL file = FileUtil.findURL("xml/defaultPanelIcons.xml"); if (file == null) { - log.error("defaultPanelIcons file (xml/defaultPanelIcons.xml) doesn't exist."); throw new IllegalArgumentException("defaultPanelIcons file (xml/defaultPanelIcons.xml) doesn't exist."); } jmri.jmrit.XmlFile xf = new jmri.jmrit.XmlFile() { @@ -303,37 +298,37 @@ static List getDefaultIconItemTypes() throws org.jdom2.JDOMException, j return (root.getChild("ItemTypes").getChildren()); } - static void loadDefaultIcons(Editor ed) { + static void loadDefaultIcons() { try { List typeList = getDefaultIconItemTypes(); for (Element type : typeList) { String typeName = type.getName(); List families = type.getChildren(); - loadFamilies(typeName, families, ed); + loadFamilies(typeName, families); } } catch (org.jdom2.JDOMException | java.io.IOException e) { log.error("error reading file \"defaultPanelIcons.xml\" due to: ", e); } } - static void loadFamilies(String typeName, List families, Editor ed) { + static void loadFamilies(String typeName, List families) { // detect this is a 4 level map collection. // not very elegant (i.e. extensible), but maybe all that's needed. if (typeName.equals("IndicatorTO")) { HashMap>> familyTOMap - = loadDefaultIndicatorTOMap(families, ed); + = loadDefaultIndicatorTOMap(families); _indicatorTOMaps.put(typeName, familyTOMap); log.debug("Add {} indicatorTO families to item type {} to _indicatorTOMaps.", familyTOMap.size(), typeName); } else { - HashMap> familyMap = loadDefaultFamilyMap(families, ed); + HashMap> familyMap = loadDefaultFamilyMap(families); _iconMaps.put(typeName, familyMap); log.debug("Add {} families to item type \"{}\" to _iconMaps.", familyMap.size(), typeName); } } - static void loadMissingItemType(String itemType, Editor ed) { + static void loadMissingItemType(String itemType) { try { List typeList = getDefaultIconItemTypes(); for (Element type : typeList) { @@ -342,7 +337,7 @@ static void loadMissingItemType(String itemType, Editor ed) { continue; } List families = type.getChildren(); - loadFamilies(itemType, families, ed); + loadFamilies(itemType, families); InstanceManager.getDefault(CatalogTreeManager.class).indexChanged(true); } } catch (org.jdom2.JDOMException | java.io.IOException ex) { @@ -350,7 +345,7 @@ static void loadMissingItemType(String itemType, Editor ed) { } } - static HashMap> loadDefaultFamilyMap(List families, Editor ed) { + static HashMap> loadDefaultFamilyMap(List families) { HashMap> familyMap = new HashMap<>(); for (int k = 0; k < families.size(); k++) { String familyName = families.get(k).getName(); @@ -361,20 +356,18 @@ static HashMap> loadDefaultFamilyMap(List> loadDefaultFamilyMap(List>> - loadDefaultIndicatorTOMap(List typeList, Editor ed) { + loadDefaultIndicatorTOMap(List typeList) { HashMap>> familyTOMap = new HashMap<>(); // Map of all families of type, typeName for (int k = 0; k < typeList.size(); k++) { String familyName = typeList.get(k).getName(); List types = typeList.get(k).getChildren(); - HashMap> familyMap = loadDefaultFamilyMap(types, ed); + HashMap> familyMap = loadDefaultFamilyMap(types); familyTOMap.put(familyName, familyMap); if (log.isDebugEnabled()) { log.debug("Add {} IndicatorTO sub-families to item type {} to IndicatorTO families.", @@ -401,16 +394,16 @@ static HashMap> loadDefaultFamilyMap(List { return InstanceManager.setDefault(ItemPalette.class, new ItemPalette(title, ed)); }); - Iterator iter = _tabIndex.values().iterator(); - while (iter.hasNext()) { - iter.next().setEditor(ed); + if (!ed.equals(instance.getEditor())) { + instance.updateBackground(ed); + InstanceManager.getDefault(jmri.util.PlaceWindow.class).nextTo(ed, null, instance); } String name = ed.getName(); if (name == null || name.equals("")) { @@ -423,15 +416,20 @@ static public ItemPalette getDefault(String title, @Nonnull Editor ed) { instance.setVisible(true); return instance; } + + public void setEditor(Editor ed) { + updateBackground(ed); + InstanceManager.getDefault(jmri.util.PlaceWindow.class).nextTo(ed, null, this); + } public ItemPalette(String title, Editor ed) { - super(false, false); - init(title, ed); + super(title, ed); + init(title); } - private void init(String title, Editor ed) { + private void init(String title) { this.setTitle(title); - loadIcons(ed); + loadIcons(); addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { @@ -439,8 +437,8 @@ public void windowClosing(java.awt.event.WindowEvent e) { } }); - makeMenus(ed); - buildTabPane(this, ed); + makeMenus(); + buildTabPane(this); setLayout(new BorderLayout(5, 5)); add(_tabPane, BorderLayout.CENTER); @@ -451,66 +449,66 @@ public void windowClosing(java.awt.event.WindowEvent e) { /* * Add the tabs on the Control Panel Editor. */ - static void buildTabPane(ItemPalette palette, Editor editor) { + static void buildTabPane(ItemPalette palette) { _tabPane = new JTabbedPane(); _tabIndex = new HashMap<>(); ItemPanel itemPanel = new TableItemPanel<>(palette, "Turnout", null, - PickListModel.turnoutPickModelInstance(), editor); + PickListModel.turnoutPickModelInstance()); addItemTab(itemPanel, "Turnout", "BeanNameTurnout"); itemPanel.init(); // show panel on start itemPanel = new TableItemPanel<>(palette, "Sensor", null, - PickListModel.sensorPickModelInstance(), editor); + PickListModel.sensorPickModelInstance()); addItemTab(itemPanel, "Sensor", "BeanNameSensor"); itemPanel = new SignalHeadItemPanel(palette, "SignalHead", null, - PickListModel.signalHeadPickModelInstance(), editor); + PickListModel.signalHeadPickModelInstance()); addItemTab(itemPanel, "SignalHead", "BeanNameSignalHead"); itemPanel = new SignalMastItemPanel(palette, "SignalMast", null, - PickListModel.signalMastPickModelInstance(), editor); + PickListModel.signalMastPickModelInstance()); addItemTab(itemPanel, "SignalMast", "BeanNameSignalMast"); itemPanel = new MemoryItemPanel(palette, "Memory", null, - PickListModel.memoryPickModelInstance(), editor); + PickListModel.memoryPickModelInstance()); addItemTab(itemPanel, "Memory", "BeanNameMemory"); itemPanel = new ReporterItemPanel(palette, "Reporter", null, - PickListModel.reporterPickModelInstance(), editor); + PickListModel.reporterPickModelInstance()); addItemTab(itemPanel, "Reporter", "BeanNameReporter"); itemPanel = new TableItemPanel<>(palette, "Light", null, - PickListModel.lightPickModelInstance(), editor); + PickListModel.lightPickModelInstance()); addItemTab(itemPanel, "Light", "BeanNameLight"); itemPanel = new MultiSensorItemPanel(palette, "MultiSensor", null, - PickListModel.multiSensorPickModelInstance(), editor); + PickListModel.multiSensorPickModelInstance()); addItemTab(itemPanel, "MultiSensor", "MultiSensor"); - itemPanel = new IconItemPanel(palette, "Icon", editor); + itemPanel = new IconItemPanel(palette, "Icon"); addItemTab(itemPanel, "Icon", "Icon"); - itemPanel = new BackgroundItemPanel(palette, "Background", editor); + itemPanel = new BackgroundItemPanel(palette, "Background"); addItemTab(itemPanel, "Background", "Background"); - itemPanel = new TextItemPanel(palette, "Text", editor); + itemPanel = new TextItemPanel(palette, "Text"); addItemTab(itemPanel, "Text", "Text"); - itemPanel = new RPSItemPanel(palette, "RPSReporter", null, editor); + itemPanel = new RPSItemPanel(palette, "RPSReporter", null); addItemTab(itemPanel, "RPSReporter", "RPSreporter"); - itemPanel = new ClockItemPanel(palette, "FastClock", editor); + itemPanel = new ClockItemPanel(palette, "FastClock"); addItemTab(itemPanel, "FastClock", "FastClock"); - itemPanel = new IndicatorItemPanel(palette, "IndicatorTrack", null, editor); + itemPanel = new IndicatorItemPanel(palette, "IndicatorTrack", null); addItemTab(itemPanel, "IndicatorTrack", "IndicatorTrack"); itemPanel = new IndicatorTOItemPanel(palette, "IndicatorTO", null, - PickListModel.turnoutPickModelInstance(), editor); + PickListModel.turnoutPickModelInstance()); addItemTab(itemPanel, "IndicatorTO", "IndicatorTO"); - itemPanel = new PortalItemPanel(palette, "Portal", null, editor); + itemPanel = new PortalItemPanel(palette, "Portal", null); addItemTab(itemPanel, "Portal", "BeanNamePortal"); _tabPane.addChangeListener(palette); @@ -523,13 +521,12 @@ static void addItemTab(ItemPanel itemPanel, String key, String tabTitle) { } @Override - public void updateBackground0(java.awt.image.BufferedImage im) { - int bgIdx = getPreviewBg(); - Iterator iter = _tabIndex.values().iterator(); - while (iter.hasNext()) { - ItemPanel panel = iter.next(); - panel.updateBackground0(im); - panel.setPreviewBg(bgIdx); + public void setPreviewBg(int index) { + super.setPreviewBg(index); + if (_currentItemPanel != null) { // wait until tab panels are created + for (ItemPanel panel : _tabIndex.values()) { + panel.previewColorChange(); + } } } @@ -559,14 +556,11 @@ public void stateChanged(ChangeEvent e) { p._itemType, newTabDim.width, newTabDim.height, deltaDim.width, deltaDim.height); } deltaDim = p.shellDimension(p); - reSize(_tabPane, deltaDim, newTabDim, p._editor); - if (p._bgColorBox != null) { - p._bgColorBox.setSelectedIndex(getPreviewBg()); - } + reSize(_tabPane, deltaDim, newTabDim); _currentItemPanel = p; } - private void makeMenus(Editor editor) { + private void makeMenus() { JMenuBar menuBar = new JMenuBar(); JMenu findIcon = new JMenu(Bundle.getMessage("findIconMenu")); menuBar.add(findIcon); @@ -614,9 +608,9 @@ public void closePanels(java.awt.event.WindowEvent e) { /* * Look for duplicate name of family in the iterated set. */ - protected static boolean familyNameOK(java.awt.Frame frame, String type, String family, Iterator it) { + static protected boolean familyNameOK(String type, String family, Iterator it) { if (family == null || family.length() == 0) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, Bundle.getMessage("EnterFamilyName"), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); return false; @@ -625,7 +619,7 @@ protected static boolean familyNameOK(java.awt.Frame frame, String type, String String f = it.next(); log.debug("familyNameOK compare {} {} to {}", type, family, f); if (family.equals(f)) { - JOptionPane.showMessageDialog(frame, + JOptionPane.showMessageDialog(null, java.text.MessageFormat.format(Bundle.getMessage("DuplicateFamilyName"), new Object[]{family, type}), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); @@ -638,25 +632,20 @@ protected static boolean familyNameOK(java.awt.Frame frame, String type, String /** * Add a new Family of icons to the device type. * - * @param frame frame * @param type type * @param family family * @param iconMap iconMap * @return result */ - static protected boolean addFamily(java.awt.Frame frame, String type, String family, HashMap iconMap) { + static protected boolean addFamily(String type, String family, HashMap iconMap) { if (ItemPalette.getFamilyMaps(type) == null) { HashMap> typeMap = new HashMap<>(); _iconMaps.put(type, typeMap); // typeMap.put(family, iconMap); } Iterator iter = ItemPalette.getFamilyMaps(type).keySet().iterator(); - if (familyNameOK(frame, type, family, iter)) { + if (familyNameOK(type, family, iter)) { getFamilyMaps(type).put(family, iconMap); - /* ItemPanel itemPanel = _tabIndex.get(type); - if (itemPanel instanceof FamilyItemPanel) { - ((FamilyItemPanel)itemPanel).updateFamiliesPanel(); - }*/ InstanceManager.getDefault(CatalogTreeManager.class).indexChanged(true); return true; } @@ -716,17 +705,16 @@ static protected HashMap getIconMap(String type, String famil /** * ************ Currently only needed for IndicatorTO type ************** - * @param frame frame * @param type type * @param family family * @param iconMap iconMap * @return result */ // add entire family - static protected boolean addLevel4Family(java.awt.Frame frame, String type, String family, + static protected boolean addLevel4Family(String type, String family, HashMap> iconMap) { - Iterator iter = ItemPalette.getLevel4FamilyMaps(type).keySet().iterator(); - if (familyNameOK(frame, type, family, iter)) { + Iterator iter = getLevel4FamilyMaps(type).keySet().iterator(); + if (familyNameOK(type, family, iter)) { getLevel4FamilyMaps(type).put(family, iconMap); InstanceManager.getDefault(CatalogTreeManager.class).indexChanged(true); return true; @@ -791,11 +779,7 @@ static public String convertText(String name) { // NOI18N cName = Bundle.getMessage(name); } catch (java.util.MissingResourceException mre) { - try { - cName = Bundle.getMessage(name); - } catch (java.util.MissingResourceException mre2) { - cName = name; - } + cName = name; } return cName; } diff --git a/java/src/jmri/jmrit/display/palette/ItemPanel.java b/java/src/jmri/jmrit/display/palette/ItemPanel.java index 840f0f59efb..79ff42e70b1 100644 --- a/java/src/jmri/jmrit/display/palette/ItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/ItemPanel.java @@ -1,27 +1,18 @@ package jmri.jmrit.display.palette; -import java.awt.Color; import java.awt.Dimension; -import java.awt.FlowLayout; -import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.image.BufferedImage; import java.util.HashMap; import javax.annotation.Nonnull; -import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; -import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; -import javax.swing.SwingConstants; import jmri.jmrit.catalog.NamedIcon; import jmri.jmrit.display.DisplayFrame; -import jmri.jmrit.display.Editor; +import jmri.jmrit.display.PreviewPanel; import jmri.jmrit.display.controlPanelEditor.PortalIcon; -import jmri.util.swing.DrawSquares; -import jmri.util.swing.ImagePanel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,40 +33,27 @@ * devices. * @see jmri.jmrit.display.DisplayFrame for class diagram for the palette package. * - * @author Pete Cressman Copyright (c) 2010 + * @author Pete Cressman Copyright (c) 2010, 2020 * @author Egbert Broerse Copyright 2017 */ public abstract class ItemPanel extends JPanel { - protected DisplayFrame _paletteFrame; + protected DisplayFrame _frame; protected String _itemType; - protected Editor _editor; protected boolean _initialized = false; // has init() been run protected boolean _update = false; // editing existing icon, do not allow icon dragging. Set in init() protected boolean _suppressDragging; protected JTextField _linkName = new JTextField(30); - static Color _grayColor = new Color(235, 235, 235); - static Color _darkGrayColor = new Color(150, 150, 150); - static protected Color[] colorChoice = new Color[]{Color.white, _grayColor, _darkGrayColor}; // panel bg color picked up directly - /** - * Array of BufferedImage backgrounds loaded as background image in Preview (not shared across tabs) - */ - protected BufferedImage[] _backgrounds; - /** - * JComboBox to choose the above backgrounds - */ - protected JComboBox _bgColorBox = null; + protected PreviewPanel _previewPanel; /** * Constructor for all item types. * * @param parentFrame ItemPalette instance * @param type identifier of the ItemPanel type - * @param editor Editor that called this ItemPalette */ - public ItemPanel(DisplayFrame parentFrame, String type, Editor editor) { - _paletteFrame = parentFrame; + public ItemPanel(DisplayFrame parentFrame, String type) { + _frame = parentFrame; _itemType = type; - updateBackgrounds(editor); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); } @@ -98,21 +76,20 @@ public void init() { */ abstract public void init(ActionListener doneAction); + /** + * A different panel has the focus and may have a different panel background + * or a PreviewPanel has changed a viewing background + * + protected void editorChange() { + }*/ - protected void setEditor(Editor ed) { - updateBackgrounds(ed); // editor change may change panel background - if (_bgColorBox != null) { - _bgColorBox.setSelectedIndex(_paletteFrame.getPreviewBg()); + protected void previewColorChange() { + if (_previewPanel != null) { + _previewPanel.setBackgroundSelection(_frame.getPreviewBg()); + _previewPanel.invalidate(); } } - /* - * Notification to itemPanel to update child dialogs, if any - */ - abstract protected void setPreviewBg(int index); - - abstract protected void updateBackground0(BufferedImage im); - public boolean oktoUpdate() { return true; } @@ -134,96 +111,6 @@ protected void initLinkPanel() { add(blurb); } - /** - * Create panel element containing [Set background:] drop down list. - * - * @see DecoratorPanel - * @param preview1 preview pane1 to set background image on - * @param preview2 (optional) second preview pane1 to set background image on - * @return JPanel with label and drop down with actions - */ - protected JPanel makeBgButtonPanel(ImagePanel preview1, ImagePanel preview2) { - if (_bgColorBox == null) { - _bgColorBox = new JComboBox<>(); - _bgColorBox.addItem(Bundle.getMessage("PanelBgColor")); // PanelColor key is specific for CPE, but too long for combo - _bgColorBox.addItem(Bundle.getMessage("White")); - _bgColorBox.addItem(Bundle.getMessage("LightGray")); - _bgColorBox.addItem(Bundle.getMessage("DarkGray")); - _bgColorBox.addItem(Bundle.getMessage("Checkers")); - _bgColorBox.setSelectedIndex(_paletteFrame.getPreviewBg()); // Global field, starts as 0 = panel bg color - _bgColorBox.addActionListener((ActionEvent e) -> { - if (_backgrounds != null) { - int previewBgSet = _bgColorBox.getSelectedIndex(); - _paletteFrame.setPreviewBg(previewBgSet); // store user choice in field on parent - setPreviewBg(previewBgSet); - // load background image - log.debug("ItemPalette setImage called {}", previewBgSet); - if (preview1 != null) { - preview1.setImage(_backgrounds[previewBgSet]); - preview1.revalidate(); // force redraw - } - if (preview2 != null) { - preview2.setImage(_backgrounds[previewBgSet]); - preview2.revalidate(); // force redraw - } - } else { - log.debug("imgArray is empty"); - } - }); - } - JPanel backgroundPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); - backgroundPanel.add(new JLabel(Bundle.getMessage("setBackground"))); - backgroundPanel.add(_bgColorBox); - return backgroundPanel; - } - - /** - * Create array of backgrounds for preview pane. - * @param ed Panel editor - */ - protected void updateBackgrounds(Editor ed) { - _editor = ed; - Color currentBackground = ed.getTargetPanel().getBackground(); // start using Panel background color - _backgrounds = makeBackgrounds(_backgrounds, currentBackground); - } - - static protected BufferedImage[] makeBackgrounds(BufferedImage[] backgrounds, Color panelBackground) { - if (backgrounds == null) { // reduces load but will not redraw for new size - backgrounds = new BufferedImage[5]; - for (int i = 1; i <= 3; i++) { - backgrounds[i] = DrawSquares.getImage(500, 400, 10, colorChoice[i - 1], colorChoice[i - 1]); - // [i-1] because choice 0 is not in colorChoice[] - } - backgrounds[4] = DrawSquares.getImage(500, 400, 10, Color.white, _grayColor); - } - // always update background from Panel Editor - backgrounds[0] = DrawSquares.getImage(500, 400, 10, panelBackground, panelBackground); - log.debug("makeBackgrounds backgrounds[0] = {}", backgrounds[0]); - return backgrounds; - } - - protected JPanel makePreviewPanel(ImagePanel panel1, ImagePanel panel2) { - JPanel previewPanel = new JPanel(); - previewPanel.setLayout(new BoxLayout(previewPanel, BoxLayout.Y_AXIS)); - previewPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black, 1), - Bundle.getMessage("PreviewBorderTitle"))); - makeBgButtonPanel(panel1, panel2); - if (_bgColorBox != null) { - JPanel bkgdBoxPanel = new JPanel(); - bkgdBoxPanel.add(new JLabel(Bundle.getMessage("setBackground"), SwingConstants.RIGHT)); - bkgdBoxPanel.add(_bgColorBox); - previewPanel.add(bkgdBoxPanel); - _bgColorBox.setSelectedIndex(_paletteFrame.getPreviewBg()); - } - if (panel1 != null) { - previewPanel.add(panel1); - } - if (panel2 != null) { - previewPanel.add(panel2); - } - return previewPanel; - } - public void closeDialogs() { } @@ -293,14 +180,12 @@ static private String[] getNames(String type) { } } - static String redX = "resources/icons/misc/X-red.gif"; - @Nonnull static protected HashMap makeNewIconMap(String type) { HashMap newMap = new HashMap<>(); String[] names = getNames(type); for (int i = 0; i < names.length; i++) { - NamedIcon icon = new jmri.jmrit.catalog.NamedIcon(redX, redX); + NamedIcon icon = new jmri.jmrit.catalog.NamedIcon(ItemPalette.RED_X, ItemPalette.RED_X); newMap.put(names[i], icon); } return newMap; @@ -310,7 +195,7 @@ static protected void checkIconMap(String type, HashMap map) String[] names = getNames(type); for (int i = 0; i < names.length; i++) { if (map.get(names[i]) == null) { - NamedIcon icon = new jmri.jmrit.catalog.NamedIcon(redX, redX); + NamedIcon icon = new jmri.jmrit.catalog.NamedIcon(ItemPalette.RED_X, ItemPalette.RED_X); // store RedX as default icon if icon not set map.put(names[i], icon); } @@ -318,7 +203,7 @@ static protected void checkIconMap(String type, HashMap map) } protected DisplayFrame getParentFrame() { - return _paletteFrame; + return _frame; } // oldDim old panel size, @@ -334,22 +219,25 @@ protected void reSizeDisplay(boolean isPalette, Dimension oldDim, Dimension tota } Dimension deltaDim = shellDimension(this); if (isPalette && _initialized) { - _paletteFrame.reSize(ItemPalette._tabPane, deltaDim, newDim, _editor); + _frame.reSize(ItemPalette._tabPane, deltaDim, newDim); } else if (_update || _initialized) { - _paletteFrame.reSize(_paletteFrame, deltaDim, newDim, _editor); + _frame.reSize(_frame, deltaDim, newDim); } } public Dimension shellDimension(ItemPanel panel) { if (panel instanceof FamilyItemPanel) { if (panel._itemType.equals("SignalMast") || panel._itemType.equals("Reporter")) { - return new Dimension(23, 138); + return new Dimension(23, 136); + } + if (panel._itemType.equals("RPSReporter") || panel._itemType.equals("Portal")) { + return new Dimension(10, 80); } return new Dimension(23, 122); } else if (panel instanceof IconItemPanel) { - return new Dimension(23, 106); + return new Dimension(20, 90); } - return new Dimension(25, 140); + return new Dimension(8, 120); } private final static Logger log = LoggerFactory.getLogger(ItemPanel.class); } diff --git a/java/src/jmri/jmrit/display/palette/MemoryItemPanel.java b/java/src/jmri/jmrit/display/palette/MemoryItemPanel.java index 285588a6291..5384652c951 100644 --- a/java/src/jmri/jmrit/display/palette/MemoryItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/MemoryItemPanel.java @@ -23,6 +23,7 @@ import jmri.jmrit.display.MemoryIcon; import jmri.jmrit.display.MemoryInputIcon; import jmri.jmrit.display.MemorySpinnerIcon; +import jmri.jmrit.display.PreviewPanel; import jmri.jmrit.picker.PickListModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,18 +34,20 @@ enum Type { READONLY, READWRITE, SPINNER, COMBO } JSpinner _spinner; + String[] list = {"Item1", "Item2", "Item3"}; - public MemoryItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model, Editor editor) { - super(parentFrame, type, family, model, editor); + public MemoryItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model) { + super(parentFrame, type, family, model); } @Override public void init() { if (!_initialized) { - add(initTablePanel(_model, _editor)); + add(initTablePanel(_model)); initIconFamiliesPanel(); add(_iconFamilyPanel); - add(makeBgButtonPanel(_dragIconPanel, _iconPanel)); + _previewPanel = new PreviewPanel(_frame, _dragIconPanel, _iconPanel, true); + add(_previewPanel); _initialized = true; } } @@ -53,23 +56,21 @@ protected JPanel instructions() { JPanel blurb = new JPanel(); blurb.setLayout(new BoxLayout(blurb, BoxLayout.Y_AXIS)); blurb.add(Box.createVerticalStrut(ItemPalette.STRUT_SIZE)); - blurb.add(new JLabel(Bundle.getMessage("AddToPanel"))); - blurb.add(new JLabel(Bundle.getMessage("DragIconPanel"))); + blurb.add(new JLabel(Bundle.getMessage("AddMemoryToPanel"))); + blurb.add(new JLabel(Bundle.getMessage("MemoryDragStart"))); + blurb.add(new JLabel(Bundle.getMessage("MemoryDragFix"))); blurb.add(Box.createVerticalStrut(ItemPalette.STRUT_SIZE)); - blurb.add(new JLabel(Bundle.getMessage("nullMemoryIcon"), - NamedIcon.getIconByName("resources/icons/misc/X-red.gif"), - javax.swing.SwingConstants.TRAILING)); - blurb.add(new JLabel(Bundle.getMessage("emptyMemoryIcon"))); - blurb.add(new JLabel(Bundle.getMessage("emptyMemoryFix"))); - blurb.add(Box.createVerticalStrut(ItemPalette.STRUT_SIZE)); - blurb.add(new JLabel(Bundle.getMessage("comboMemory1"))); - blurb.add(new JLabel(Bundle.getMessage("comboMemory2", Bundle.getMessage("EditItem", Bundle.getMessage("BeanNameMemory"))))); + blurb.add(new JLabel(Bundle.getMessage("DecorateMemory"))); blurb.add(Box.createVerticalStrut(ItemPalette.STRUT_SIZE)); JPanel panel = new JPanel(); panel.add(blurb); return panel; } + @Override + protected void hideIcons() { + } + /** * CENTER Panel */ @@ -100,6 +101,7 @@ protected void makeDndIconPanel(java.util.HashMap iconMap, St JPanel panel = new JPanel(); panel.setOpaque(false); panel.setLayout(new java.awt.GridBagLayout()); + Editor editor = _frame.getEditor(); java.awt.GridBagConstraints c = new java.awt.GridBagConstraints(); c.gridwidth = 1; c.gridheight = 1; @@ -112,24 +114,9 @@ protected void makeDndIconPanel(java.util.HashMap iconMap, St label.setOpaque(false); panel.add(label, c); c.gridy = 1; - _writeMem = new MemoryInputIcon(5, _editor); + _writeMem = new MemoryInputIcon(5, editor); panel.add(makeDragIcon(_writeMem, Type.READWRITE), c); - _spinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1)); - JTextField field = ((JSpinner.DefaultEditor) _spinner.getEditor()).getTextField(); - field.setColumns(2); - field.setText("5"); - _spinner.setMaximumSize(_spinner.getPreferredSize()); - _spinner.addChangeListener(this); - c.gridy = 2; - panel.add(_spinner, c); - - c.gridy = 3; - c.anchor = java.awt.GridBagConstraints.NORTH; - label = new JLabel(Bundle.getMessage("NumColsLabel")); - label.setOpaque(false); - panel.add(label, c); - c.gridx = 1; c.gridy = 0; c.anchor = java.awt.GridBagConstraints.CENTER; @@ -137,7 +124,7 @@ protected void makeDndIconPanel(java.util.HashMap iconMap, St label.setOpaque(false); panel.add(label, c); c.gridy = 1; - _readMem = new MemoryIcon(NamedIcon.getIconByName("resources/icons/misc/X-red.gif"), _editor); + _readMem = new MemoryIcon("_____", editor); panel.add(makeDragIcon(_readMem, Type.READONLY), c); c.gridx = 2; @@ -146,19 +133,37 @@ protected void makeDndIconPanel(java.util.HashMap iconMap, St label.setOpaque(false); panel.add(label, c); c.gridy = 1; - _spinMem = new MemorySpinnerIcon(_editor); + _spinMem = new MemorySpinnerIcon(editor); panel.add(makeDragIcon(_spinMem, Type.SPINNER), c); - c.gridx = 0; - c.gridy = 2; - c.gridwidth = 4; + c.gridx = 3; + c.gridy = 0; label = new JLabel(Bundle.getMessage("ComboMemory")); label.setOpaque(false); panel.add(label, c); - c.gridy = 3; - _comboMem = new MemoryComboIcon(_editor, null); + c.gridy = 1; + String[] list = {"item1", "Item2", "Item3"}; + _comboMem = new MemoryComboIcon(editor, list); panel.add(makeDragIcon(_comboMem, Type.COMBO), c); + _spinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1)); + JTextField field = ((JSpinner.DefaultEditor) _spinner.getEditor()).getTextField(); + field.setColumns(2); + field.setText("5"); + _spinner.setMaximumSize(_spinner.getPreferredSize()); + _spinner.addChangeListener(this); + c.gridx = 1; + c.gridy = 2; + c.gridwidth = 2; + c.anchor = java.awt.GridBagConstraints.CENTER; + panel.add(_spinner, c); + + c.gridy = 3; + c.anchor = java.awt.GridBagConstraints.NORTH; + label = new JLabel(Bundle.getMessage("MemoryWidth")); + label.setOpaque(false); + panel.add(label, c); + _dragIconPanel.add(panel); _dragIconPanel.invalidate(); } @@ -207,11 +212,6 @@ public void valueChanged(ListSelectionEvent e) { _updateButton.setEnabled(true); _updateButton.setToolTipText(null); } - Memory bean = getDeviceNamedBean(); - _readMem.setMemory(bean.getDisplayName()); - _writeMem.setMemory(bean.getDisplayName()); - _spinMem.setMemory(bean.getDisplayName()); - _comboMem.setMemory(bean.getDisplayName()); } else { if (_updateButton != null) { _updateButton.setEnabled(false); @@ -224,16 +224,6 @@ public void valueChanged(ListSelectionEvent e) { validate(); } - @Override - protected void setEditor(Editor ed) { - updateBackgrounds(ed); // editor change may change panel background - if (_initialized) { - _dragIconPanel.removeAll(); - makeDragIconPanel(1); - makeDndIconPanel(null, null); - } - } - protected IconDragJComponent getDragger(DataFlavor flavor, Type type, JComponent comp) { return new IconDragJComponent(flavor, type, comp); } @@ -269,40 +259,42 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti return null; } + Editor editor = _frame.getEditor(); if (flavor.isMimeTypeEqual(Editor.POSITIONABLE_FLAVOR)) { + int numCols = 5; + try { + ((JSpinner.DefaultEditor) _spinner.getEditor()).commitEdit(); + SpinnerNumberModel spinModel = (SpinnerNumberModel) _spinner.getModel(); + if (log.isDebugEnabled()) { + log.debug("MemoryDnD.createTransferable: spinCols= " + + spinModel.getNumber().intValue()); + } + numCols = spinModel.getNumber().intValue(); + } catch (java.text.ParseException pe) { + log.error("MemoryDnD.createTransferable: " + pe); + } switch (_memType) { case READONLY: - MemoryIcon m = new MemoryIcon("", _editor); + MemoryIcon m = new MemoryIcon("", editor); m.setMemory(bean.getDisplayName()); - m.setSize(m.getPreferredSize().width, m.getPreferredSize().height); +// m.setSize(m.getPreferredSize().width, m.getPreferredSize().height); + m.getPopupUtility().setFixedWidth(numCols*10); m.setLevel(Editor.MEMORIES); return m; case READWRITE: - int numCols = 5; - try { - ((JSpinner.DefaultEditor) _spinner.getEditor()).commitEdit(); - SpinnerNumberModel spinModel = (SpinnerNumberModel) _spinner.getModel(); - if (log.isDebugEnabled()) { - log.debug("MemoryDnD.createTransferable: spinCols= " - + spinModel.getNumber().intValue()); - } - numCols = spinModel.getNumber().intValue(); - } catch (java.text.ParseException pe) { - log.error("MemoryDnD.createTransferable: " + pe); - } - MemoryInputIcon mi = new MemoryInputIcon(numCols, _editor); + MemoryInputIcon mi = new MemoryInputIcon(numCols, editor); mi.setMemory(bean.getDisplayName()); mi.setSize(mi.getPreferredSize().width, mi.getPreferredSize().height); mi.setLevel(Editor.MEMORIES); return mi; case SPINNER: - MemorySpinnerIcon ms = new MemorySpinnerIcon(_editor); + MemorySpinnerIcon ms = new MemorySpinnerIcon(editor); ms.setMemory(bean.getDisplayName()); ms.setSize(ms.getPreferredSize().width, ms.getPreferredSize().height); ms.setLevel(Editor.MEMORIES); return ms; case COMBO: - MemoryComboIcon mc = new MemoryComboIcon(_editor, null); + MemoryComboIcon mc = new MemoryComboIcon(editor, list); mc.setMemory(bean.getDisplayName()); mc.setSize(mc.getPreferredSize().width, mc.getPreferredSize().height); mc.setLevel(Editor.MEMORIES); diff --git a/java/src/jmri/jmrit/display/palette/MultiSensorIconDialog.java b/java/src/jmri/jmrit/display/palette/MultiSensorIconDialog.java index a9dfefe6336..01fef3756b2 100644 --- a/java/src/jmri/jmrit/display/palette/MultiSensorIconDialog.java +++ b/java/src/jmri/jmrit/display/palette/MultiSensorIconDialog.java @@ -92,11 +92,11 @@ private boolean addNewIcon(String name) { log.debug("addNewIcon Action: iconMap.size()= " + _iconMap.size()); } if (name == null || name.length() == 0) { - JOptionPane.showMessageDialog(_parent._paletteFrame, Bundle.getMessage("NoIconName"), + JOptionPane.showMessageDialog(_parent._frame, Bundle.getMessage("NoIconName"), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); return false; } else if (_iconMap.get(name) != null) { - JOptionPane.showMessageDialog(_parent._paletteFrame, + JOptionPane.showMessageDialog(_parent._frame, Bundle.getMessage("DuplicateIconName", name), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); return false; diff --git a/java/src/jmri/jmrit/display/palette/MultiSensorItemPanel.java b/java/src/jmri/jmrit/display/palette/MultiSensorItemPanel.java index 98941393af9..75f7d545484 100644 --- a/java/src/jmri/jmrit/display/palette/MultiSensorItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/MultiSensorItemPanel.java @@ -37,13 +37,13 @@ public class MultiSensorItemPanel extends TableItemPanel { MultiSensorSelectionModel _selectionModel; boolean _upDown = false; - public MultiSensorItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model, Editor editor) { - super(parentFrame, type, family, model, editor); + public MultiSensorItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model) { + super(parentFrame, type, family, model); setToolTipText(Bundle.getMessage("ToolTipDragSelection")); } @Override - protected JPanel initTablePanel(PickListModel model, Editor editor) { + protected JPanel initTablePanel(PickListModel model) { _table = model.makePickTable(); TableColumn column = new TableColumn(PickListModel.POSITION_COL); column.setHeaderValue("Position"); @@ -98,10 +98,6 @@ public void actionPerformed(ActionEvent a) { public void clearSelections() { _selectionModel.clearSelection(); int size = 6; - // if (_family!=null) { - // HashMap map = ItemPalette.getIconMap(_itemType, _family); - // size = map.size(); - // } HashMap map = getIconMap(); if (map != null) { size = map.size(); @@ -302,7 +298,7 @@ public void addSelectionInterval(int index0, int index1) { @Override public void setSelectionInterval(int row, int index1) { if (_nextPosition >= _positions.length) { - JOptionPane.showMessageDialog(_paletteFrame, + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("NeedIcon", _selectionModel.getPositions().length), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); return; @@ -311,9 +307,12 @@ public void setSelectionInterval(int row, int index1) { log.debug("setSelectionInterval({}, {})", row, index1); } Sensor bean = _tableModel.getBySystemName((String) _table.getValueAt(row, 0)); + if (bean == null) { + return; + } String position = (String) _tableModel.getValueAt(row, PickListModel.POSITION_COL); if (position != null && position.length() > 0) { - JOptionPane.showMessageDialog(_paletteFrame, + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("DuplicatePosition", new Object[]{bean.getDisplayName(), position}), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); @@ -383,7 +382,7 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti if (flavor.isMimeTypeEqual(Editor.POSITIONABLE_FLAVOR)) { if (_itemType.equals("MultiSensor")) { - MultiSensorIcon ms = new MultiSensorIcon(_editor); + MultiSensorIcon ms = new MultiSensorIcon(_frame.getEditor()); ms.setInactiveIcon(new NamedIcon(iconMap.get("SensorStateInactive"))); ms.setInconsistentIcon(new NamedIcon(iconMap.get("BeanStateInconsistent"))); ms.setUnknownIcon(new NamedIcon(iconMap.get("BeanStateUnknown"))); diff --git a/java/src/jmri/jmrit/display/palette/PaletteBundle.properties b/java/src/jmri/jmrit/display/palette/PaletteBundle.properties index ac3c964a8ef..70c91953f23 100644 --- a/java/src/jmri/jmrit/display/palette/PaletteBundle.properties +++ b/java/src/jmri/jmrit/display/palette/PaletteBundle.properties @@ -42,7 +42,9 @@ HideIcons = Hide Icons ButtonEditIcons = Edit Icons ButtonShowCatalog = Icon Catalog HideCatalog = Hide Catalog -ButtonBackgroundColor = Set Panel Background Color... +ButtonShowColorPanel= Color Chooser +HideColorPanel = Hide Color Panel +ButtonBackgroundColor= Set Panel Background Color updateButton = Update Panel addNewFamily = Add New Icon Set addIcon = Add Icon @@ -125,13 +127,13 @@ ToUpdateIcon = To change icon, select another and press the [{0}] button. ToLinkToURL = You can make clicking on this object link to another JMRI Panel or URL, enterPanel = -- for a JMRI Panel, type "frame:" into the field at bottom. enterURL = -- for an URL, type the link (i.e. "http://etc") into the field at bottom. -ToColorBackground = To choose a Color Background: press [{0}] +ToColorBackground = To choose a Color Background:\nSelect a color from the Color Panel, then press [{0}] AddClockToPanel = Drag the icon below to add a {0} to your Control Panel. -nullMemoryIcon = is displayed for the Display Memory Icon when Memory is null . -emptyMemoryIcon = When Memory is an empty string i.e. "", the Display Memory Icon is blank. -emptyMemoryFix = When blank, enter a value in the other memory icons to view and drag it. -comboMemory2 = Use the [{0}] popup to add or delete items. -comboMemory1 = The ComboBox Memory Icon sets a memory by selecting an item from the ComboBox. +AddMemoryToPanel = To Add a Memory type to your control panel: +MemoryDragStart = Start the drag by mousing down in the area outside of the Memory itself. +MemoryDragFix = (Some parts of the memory types are not selectable) +DecorateMemory = After dragging, use the [Edit Memory] pop-up to decorate the icon. +MemoryWidth = Number of Characters Wide (roughly) addTextAndAttrs = Enter text and choose attributes for the label in the Preview panel. Then # tooltips diff --git a/java/src/jmri/jmrit/display/palette/PortalItemPanel.java b/java/src/jmri/jmrit/display/palette/PortalItemPanel.java index 5210d3b2b3e..9dbeb65f5da 100644 --- a/java/src/jmri/jmrit/display/palette/PortalItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/PortalItemPanel.java @@ -8,7 +8,6 @@ import javax.swing.JPanel; import jmri.jmrit.catalog.NamedIcon; import jmri.jmrit.display.DisplayFrame; -import jmri.jmrit.display.Editor; import jmri.jmrit.display.controlPanelEditor.ControlPanelEditor; /** @@ -16,15 +15,15 @@ * users may have customized the defaultPanelIcons, the default family, * "Standard" is added by overriding the initIconFamiliesPanel method. * -* @author Pete Cressman Copyright (c) 2013 +* @author Pete Cressman Copyright (c) 2013, 2020 */ -public /*abstract*/ class PortalItemPanel extends FamilyItemPanel { +public class PortalItemPanel extends FamilyItemPanel { /* * Constructor types with multiple families and multiple icon families. */ - public PortalItemPanel(DisplayFrame parentFrame, String type, String family, Editor editor) { - super(parentFrame, type, family, editor); + public PortalItemPanel(DisplayFrame parentFrame, String type, String family) { + super(parentFrame, type, family); } /** @@ -61,7 +60,7 @@ public void actionPerformed(ActionEvent a) { private void setDefaults() { HashMap map = getIconMap(); - ((ControlPanelEditor) _editor).setDefaultPortalIcons(jmri.jmrit.display.PositionableIcon.cloneMap(map, null)); + ((ControlPanelEditor)_frame.getEditor()).setDefaultPortalIcons(jmri.jmrit.display.PositionableIcon.cloneMap(map, null)); } @Override diff --git a/java/src/jmri/jmrit/display/palette/RPSItemPanel.java b/java/src/jmri/jmrit/display/palette/RPSItemPanel.java index a856bfb7d9d..fe3e64f4e7d 100644 --- a/java/src/jmri/jmrit/display/palette/RPSItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/RPSItemPanel.java @@ -16,8 +16,8 @@ public class RPSItemPanel extends FamilyItemPanel { - public RPSItemPanel(DisplayFrame parentFrame, String type, String family, Editor editor) { - super(parentFrame, type, family, editor); + public RPSItemPanel(DisplayFrame parentFrame, String type, String family) { + super(parentFrame, type, family); } @Override @@ -57,7 +57,7 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti log.debug("IconDragJLabel.getTransferData"); } if (flavor.isMimeTypeEqual(Editor.POSITIONABLE_FLAVOR)) { - RpsPositionIcon r = new RpsPositionIcon(_editor); + RpsPositionIcon r = new RpsPositionIcon(_frame.getEditor()); r.setActiveIcon(new NamedIcon(iconMap.get("active"))); r.setErrorIcon(new NamedIcon(iconMap.get("error"))); r.setSize(r.getPreferredSize().width, r.getPreferredSize().height); diff --git a/java/src/jmri/jmrit/display/palette/ReporterItemPanel.java b/java/src/jmri/jmrit/display/palette/ReporterItemPanel.java index cc67223035a..f0366c17d9f 100644 --- a/java/src/jmri/jmrit/display/palette/ReporterItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/ReporterItemPanel.java @@ -17,6 +17,7 @@ import jmri.jmrit.catalog.NamedIcon; import jmri.jmrit.display.DisplayFrame; import jmri.jmrit.display.Editor; +import jmri.jmrit.display.PreviewPanel; import jmri.jmrit.display.ReporterIcon; import jmri.jmrit.picker.PickListModel; import jmri.util.swing.ImagePanel; @@ -27,8 +28,8 @@ public class ReporterItemPanel extends TableItemPanel { ReporterIcon _reporter; - public ReporterItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model, Editor editor) { - super(parentFrame, type, family, model, editor); + public ReporterItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model) { + super(parentFrame, type, family, model); } protected JPanel instructions() { @@ -62,7 +63,8 @@ protected void initIconFamiliesPanel() { if (_iconPanel == null) { // keep an existing panel _iconPanel = new ImagePanel(); // never shown, so don't bother to configure, but element must exist } - _iconFamilyPanel.add(makePreviewPanel(null, _dragIconPanel)); + _previewPanel = new PreviewPanel(_frame, null, _dragIconPanel, true); + _iconFamilyPanel.add(_previewPanel); } @Override @@ -81,7 +83,7 @@ protected void makeDndIconPanel(HashMap iconMap, String displ if (_update) { return; } - _reporter = new ReporterIcon(_editor); + _reporter = new ReporterIcon(_frame.getEditor()); JPanel panel = new JPanel(); panel.setOpaque(false); JPanel comp; @@ -127,7 +129,7 @@ public void valueChanged(ListSelectionEvent e) { if (_updateButton != null) { _updateButton.setEnabled(false); _updateButton.setToolTipText(Bundle.getMessage("ToolTipPickFromTable")); - _reporter = new ReporterIcon(_editor); + _reporter = new ReporterIcon(_frame.getEditor()); } } validate(); @@ -165,7 +167,7 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti } if (flavor.isMimeTypeEqual(Editor.POSITIONABLE_FLAVOR)) { - ReporterIcon r = new ReporterIcon(_editor); + ReporterIcon r = new ReporterIcon(_frame.getEditor()); r.setReporter(bean.getDisplayName()); r.setLevel(Editor.REPORTERS); return r; diff --git a/java/src/jmri/jmrit/display/palette/SignalHeadItemPanel.java b/java/src/jmri/jmrit/display/palette/SignalHeadItemPanel.java index 55b8084304c..08546921fe4 100644 --- a/java/src/jmri/jmrit/display/palette/SignalHeadItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/SignalHeadItemPanel.java @@ -28,12 +28,12 @@ public class SignalHeadItemPanel extends TableItemPanel { - public SignalHeadItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model, Editor editor) { - super(parentFrame, type, family, model, editor); + public SignalHeadItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model) { + super(parentFrame, type, family, model); } @Override - protected JPanel initTablePanel(PickListModel model, Editor editor) { + protected JPanel initTablePanel(PickListModel model) { _table = model.makePickTable(); JPanel topPanel = new JPanel(); topPanel.setLayout(new BorderLayout()); @@ -119,7 +119,7 @@ public void valueChanged(ListSelectionEvent e) { protected HashMap getFilteredIconMap(HashMap allIconsMap) { if (allIconsMap == null) { - JOptionPane.showMessageDialog(_paletteFrame, + JOptionPane.showMessageDialog(_frame, Bundle.getMessage("FamilyNotFound", _itemType, _family), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); return null; @@ -139,7 +139,10 @@ protected HashMap getFilteredIconMap(HashMap map = getFilteredIconMap(iMap); Iterator> iter = map.entrySet().iterator(); diff --git a/java/src/jmri/jmrit/display/palette/SignalMastItemPanel.java b/java/src/jmri/jmrit/display/palette/SignalMastItemPanel.java index 65827f480d5..50d02236a20 100644 --- a/java/src/jmri/jmrit/display/palette/SignalMastItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/SignalMastItemPanel.java @@ -27,6 +27,7 @@ import jmri.jmrit.catalog.NamedIcon; import jmri.jmrit.display.DisplayFrame; import jmri.jmrit.display.Editor; +import jmri.jmrit.display.PreviewPanel; import jmri.jmrit.display.SignalMastIcon; import jmri.jmrit.picker.PickListModel; import jmri.util.swing.ImagePanel; @@ -36,7 +37,7 @@ /** * TableItemPanel extension for placing of SignalMast items with a fixed set of icons. * - * @author Pete Cressman Copyright (c) 2010, 2011 + * @author Pete Cressman Copyright (c) 2010, 2011, 2020 * @author Egbert Broerse 2017 */ public class SignalMastItemPanel extends TableItemPanel { @@ -47,8 +48,8 @@ public class SignalMastItemPanel extends TableItemPanel { private JPanel _blurb; private NamedIcon _defaultIcon; - public SignalMastItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model, Editor editor) { - super(parentFrame, type, family, model, editor); + public SignalMastItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model) { + super(parentFrame, type, family, model); try { _mast = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast("IF$vsm:AAR-1946:SL-2-high-abs($0003)"); } catch (IllegalArgumentException ex) { @@ -59,8 +60,7 @@ public SignalMastItemPanel(DisplayFrame parentFrame, String type, String family, if (icon != null ) { _defaultIcon = icon; } else { - String name = "resources/icons/misc/X-red.gif"; - _defaultIcon = new NamedIcon(name, name); + _defaultIcon = new NamedIcon(ItemPalette.RED_X, ItemPalette.RED_X); } _iconMastMap = null; _mast = null; @@ -128,9 +128,9 @@ protected void initIconFamiliesPanel() { panel.add(_promptLabel); _iconFamilyPanel.add(panel); if (!_update) { - _previewPanel = makePreviewPanel(_iconPanel, _dragIconPanel); + _previewPanel = new PreviewPanel(_frame, _iconPanel, _dragIconPanel, true); } else { - _previewPanel = makePreviewPanel(_iconPanel, null); + _previewPanel = new PreviewPanel(_frame, _iconPanel, null, false); } _iconFamilyPanel.add(_previewPanel); } @@ -270,12 +270,12 @@ protected void showIcons() { if (log.isDebugEnabled()) { log.debug("showIcons for= {}, {}", _itemType, _family); } - boolean isPalette = (_paletteFrame instanceof ItemPalette); + boolean isPalette = (_frame instanceof ItemPalette); Dimension totalDim; if (isPalette) { totalDim = ItemPalette._tabPane.getSize(); } else { - totalDim = _paletteFrame.getSize(); + totalDim = _frame.getSize(); } Dimension oldDim = getSize(); _iconPanel.setVisible(true); @@ -299,12 +299,12 @@ protected void hideIcons() { if (log.isDebugEnabled()) { log.debug("hideIcons for= {}, {}", _itemType, _family); } - boolean isPalette = (_paletteFrame instanceof ItemPalette); + boolean isPalette = (_frame instanceof ItemPalette); Dimension totalDim; if (isPalette) { totalDim = ItemPalette._tabPane.getSize(); } else { - totalDim = _paletteFrame.getSize(); + totalDim = _frame.getSize(); } Dimension oldDim = getSize(); _iconPanel.setVisible(false); @@ -390,7 +390,7 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti } if (flavor.isMimeTypeEqual(Editor.POSITIONABLE_FLAVOR)) { - SignalMastIcon sm = new SignalMastIcon(_editor); + SignalMastIcon sm = new SignalMastIcon(_frame.getEditor()); sm.setSignalMast(bean.getDisplayName()); sm.setLevel(Editor.SIGNALS); return sm; diff --git a/java/src/jmri/jmrit/display/palette/TableItemPanel.java b/java/src/jmri/jmrit/display/palette/TableItemPanel.java index 463fbbf24f1..43f89ac4f13 100644 --- a/java/src/jmri/jmrit/display/palette/TableItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/TableItemPanel.java @@ -37,8 +37,9 @@ * FamilyItemPanel extension for placing of CPE item types that come from tool Tables * - e.g. Turnouts, Sensors, Lights, Signal Heads, etc. * - * @author Pete Cressman Copyright (c) 2010, 2011 + * @author Pete Cressman Copyright (c) 2010, 2011, 2020 */ + public class TableItemPanel extends FamilyItemPanel implements ListSelectionListener { int ROW_HEIGHT; @@ -60,10 +61,9 @@ public class TableItemPanel extends FamilyItemPanel impleme * @param type item type * @param family icon family * @param model list model - * @param editor associated Panel editor */ - public TableItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model, Editor editor) { - super(parentFrame, type, family, editor); + public TableItemPanel(DisplayFrame parentFrame, String type, String family, PickListModel model) { + super(parentFrame, type, family); _model = model; } @@ -74,7 +74,7 @@ public TableItemPanel(DisplayFrame parentFrame, String type, String family, Pick public void init() { if (!_initialized) { super.init(); - add(initTablePanel(_model, _editor), 0); // top of Panel + add(initTablePanel(_model), 0); // top of Panel _buttonPosition = 1; } hideIcons(); @@ -86,7 +86,7 @@ public void init() { */ @Override public void init(ActionListener doneAction, HashMap iconMap) { - add(initTablePanel(_model, _editor), 0); + add(initTablePanel(_model), 0); _buttonPosition = 1; super.init(doneAction, iconMap); } @@ -94,7 +94,7 @@ public void init(ActionListener doneAction, HashMap iconMap) /* * Top Panel. */ - protected JPanel initTablePanel(PickListModel model, Editor editor) { + protected JPanel initTablePanel(PickListModel model) { _table = model.makePickTable(); _table.getSelectionModel().addListSelectionListener(this); ROW_HEIGHT = _table.getRowHeight(); @@ -135,7 +135,7 @@ public void actionPerformed(ActionEvent a) { } protected void makeAddToTableWindow() { - _addTableDialog = new JDialog(_paletteFrame, Bundle.getMessage("AddToTableTitle"), true); + _addTableDialog = new JDialog(_frame, Bundle.getMessage("AddToTableTitle"), true); ActionListener cancelListener = new ActionListener() { @Override @@ -152,9 +152,9 @@ public void actionPerformed(ActionEvent a) { _sysNametext, _userNametext, "addToTable", okListener, cancelListener); _addTableDialog.getContentPane().add(addPanel); _addTableDialog.pack(); - _addTableDialog.setSize(_paletteFrame.getSize().width - 20, _addTableDialog.getPreferredSize().height); + _addTableDialog.setSize(_frame.getSize().width - 20, _addTableDialog.getPreferredSize().height); _addTableDialog.setLocation(10, 35); - _addTableDialog.setLocationRelativeTo(_paletteFrame); + _addTableDialog.setLocationRelativeTo(_frame); _addTableDialog.toFront(); _addTableDialog.setVisible(true); } @@ -184,7 +184,7 @@ protected void addToTable() { } _addTableDialog.dispose(); } catch (IllegalArgumentException ex) { - JOptionPane.showMessageDialog(_paletteFrame, ex.getMessage(), + JOptionPane.showMessageDialog(_frame, ex.getMessage(), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE); } } @@ -302,9 +302,10 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti return null; } + Editor editor = _frame.getEditor(); if (flavor.isMimeTypeEqual(Editor.POSITIONABLE_FLAVOR)) { if (_itemType.equals("Turnout")) { - TurnoutIcon t = new TurnoutIcon(_editor); + TurnoutIcon t = new TurnoutIcon(editor); t.setTurnout(bean.getDisplayName()); Iterator> iter = iMap.entrySet().iterator(); while (iter.hasNext()) { @@ -316,7 +317,7 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti return t; } else if (_itemType.equals("Sensor")) { SensorIcon s = new SensorIcon(new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", - "resources/icons/smallschematics/tracksegments/circuit-error.gif"), _editor); + "resources/icons/smallschematics/tracksegments/circuit-error.gif"), editor); Iterator> iter = iMap.entrySet().iterator(); while (iter.hasNext()) { Entry ent = iter.next(); @@ -327,7 +328,7 @@ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorExcepti s.setLevel(Editor.SENSORS); return s; } else if (_itemType.equals("Light")) { - LightIcon l = new LightIcon(_editor); + LightIcon l = new LightIcon(editor); l.setOffIcon(iMap.get("StateOff")); l.setOnIcon(iMap.get("StateOn")); l.setInconsistentIcon(iMap.get("BeanStateInconsistent")); diff --git a/java/src/jmri/jmrit/display/palette/TextItemPanel.java b/java/src/jmri/jmrit/display/palette/TextItemPanel.java index d8f6b91ed8f..659126bbd7a 100644 --- a/java/src/jmri/jmrit/display/palette/TextItemPanel.java +++ b/java/src/jmri/jmrit/display/palette/TextItemPanel.java @@ -1,6 +1,5 @@ package jmri.jmrit.display.palette; -import java.awt.Color; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; @@ -14,7 +13,6 @@ import java.awt.dnd.DragSourceListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.awt.image.BufferedImage; import java.io.IOException; import javax.swing.Box; import javax.swing.BoxLayout; @@ -33,6 +31,7 @@ /** * ItemPanel for text labels. * @see ItemPanel palette class diagram + * @author Pete Cressman Copyright (c) 2010, 2011, 2020 */ public class TextItemPanel extends ItemPanel /*implements ActionListener */ { @@ -43,10 +42,9 @@ public class TextItemPanel extends ItemPanel /*implements ActionListener */ { * * @param parentFrame ItemPalette instance * @param type identifier of the ItemPanel type, should be "Text" - * @param editor Editor that called this ItemPalette */ - public TextItemPanel(DisplayFrame parentFrame, String type, Editor editor) { - super(parentFrame, type, editor); + public TextItemPanel(DisplayFrame parentFrame, String type) { + super(parentFrame, type); setToolTipText(Bundle.getMessage("ToolTipDragText")); } @@ -61,23 +59,20 @@ public void init() { JPanel p = new JPanel(); p.add(blurb); add(p); - DragDecoratorLabel sample = new DragDecoratorLabel(Bundle.getMessage("sample"), _editor); - _decorator = new DecoratorPanel(_editor, _paletteFrame); + DragDecoratorLabel sample = new DragDecoratorLabel(Bundle.getMessage("sample"), _frame.getEditor()); + _decorator = new DecoratorPanel(_frame); _decorator.initDecoratorPanel(sample); add(_decorator); - _paletteFrame.pack(); + _frame.pack(); if (log.isDebugEnabled()) { log.debug("end init: TextItemPanel size {}", getPreferredSize()); } super.init(); } - if (_decorator != null) { - _decorator._bgColorBox.setSelectedIndex(_paletteFrame.getPreviewBg()); - } } public void init(ActionListener doneAction, Positionable pos) { - _decorator = new DecoratorPanel(_editor, _paletteFrame); + _decorator = new DecoratorPanel(_frame); _decorator.initDecoratorPanel(pos); } @@ -86,16 +81,9 @@ public void init(ActionListener doneAction) { } @Override - protected void updateBackground0(BufferedImage im) { - if (_decorator != null) { - _decorator._bgColorBox.setSelectedIndex(_paletteFrame.getPreviewBg()); - } - } - - @Override - protected void setPreviewBg(int index) { - if (_decorator != null) { - _decorator._bgColorBox.setSelectedIndex(_paletteFrame.getPreviewBg()); + protected void previewColorChange() { + if (_decorator != null) { + _decorator.sampleBgColorChange(); } } @@ -117,17 +105,6 @@ public void actionPerformed(ActionEvent a) { return panel; } - @Override - protected void setEditor(Editor ed) { - super.setEditor(ed); - if (_decorator != null) { - Color panelBackground = _editor.getTargetPanel().getBackground(); - // set Panel background color - _decorator.setBackgrounds(makeBackgrounds(_decorator.getBackgrounds(), panelBackground)); - _decorator._bgColorBox.setSelectedIndex(_paletteFrame.getPreviewBg()); - } - } - public void updateAttributes(PositionableLabel l) { _decorator.setAttributes(l); PositionablePopupUtil util = _decorator.getPositionablePopupUtil(); diff --git a/java/src/jmri/util/PlaceWindow.java b/java/src/jmri/util/PlaceWindow.java index 874247af6ad..ccc0b8d7f65 100644 --- a/java/src/jmri/util/PlaceWindow.java +++ b/java/src/jmri/util/PlaceWindow.java @@ -152,106 +152,117 @@ private Point findLocation(Window parent, Component comp, Window target) { compDim = parentDim; margin = 0; } + int num = screenNum - 1; + int screenLeft = 0; + while (num >= 0) { + screenLeft += getScreenSize(num).width; + num--; + } + int screenRight = screenLeft + parentScreen.width; if (log.isDebugEnabled()) { - log.debug("\"parent at loc ({}, {}) is on screen #{}. Size: width= {}, height= {}", + log.debug("parent at loc ({}, {}) is on screen #{}. Size: width= {}, height= {}", parentLoc.x, parentLoc.y, screenNum, parentDim.width, parentDim.height); - log.debug("\"Component at loc ({}, {}). Size: width= {}, height= {}", + log.debug("Component at loc ({}, {}). Size: width= {}, height= {}", compLoc.x, compLoc.y, compDim.width, compDim.height); - log.debug("\"targetDim: width= {}, height= {}. parent screen Size: width= {}, height= {}", - targetDim.width, targetDim.height, parentScreen.width, parentScreen.height); - } - int widthUpToParent = 0; - while (screenNum > 0) { - widthUpToParent += getScreenSize(screenNum-1).width; - screenNum--; + log.debug("targetDim: width= {}, height= {}. screenLeft= {}, screen= {} x {}", + targetDim.width, targetDim.height, screenLeft, parentScreen.width, parentScreen.height); } // try left or right of Component int xr = compLoc.x + compDim.width + margin; int xl = compLoc.x - targetDim.width - margin; + // compute the corresponding vertical offset int hOff = compLoc.y + (compDim.height - targetDim.height)/2; + if (hOff + targetDim.height > parentScreen.height) { + hOff = parentScreen.height - targetDim.height; + } if (hOff < 0) { hOff = 0; - } else if (hOff + targetDim.height > parentDim.height) { - hOff = parentLoc.y + parentDim.height - targetDim.height; } // try above or below Component int yb = compLoc.y + compDim.height + margin; int ya = compLoc.y - targetDim.height - margin; + // compute the corresponding horizontal offset int vOff = compLoc.x + (compDim.width - targetDim.width)/2; - if (vOff < widthUpToParent) { - vOff = widthUpToParent; - } else if (vOff + targetDim.width > parentLoc.x + parentDim.width) { - vOff = parentLoc.x + parentDim.width - targetDim.width; + if (vOff + targetDim.width > parentScreen.width - targetDim.width) { + vOff = parentScreen.width - targetDim.width; } - if (vOff < 0) { - vOff = 0; + if (vOff < screenLeft) { + vOff = screenLeft; + } + if (log.isDebugEnabled()) { + log.debug("UpperleftCorners: xl=({},{}), xr=({},{}), yb=({},{}), ya=({},{})", + xl,hOff, xr,hOff, vOff,yb, vOff,ya); } // try to keep completely within the parent window if (xl >= parentLoc.x){ return new Point(xl, hOff); - } else if (xr + targetDim.width <= parentLoc.x + parentDim.width) { + } else if ((xr + targetDim.width <= parentLoc.x + parentDim.width)) { return new Point(xr, hOff); } else if (yb + targetDim.height <= parentLoc.y + parentDim.height) { return new Point(vOff, yb); } else if (ya >= parentLoc.y) { + if (ya < 0) { + ya = 0; + } return new Point(vOff, ya); } // none were entirely within the parent window + // try to keep completely within the parent screen - if (xl >= widthUpToParent){ + if (log.isDebugEnabled()) { + log.debug("Off screen: left= {}, right = {}, below= {}, above= {}", + xl, xr, yb, ya); + } + if (xl > screenLeft){ return new Point(xl, hOff); - } else if (xr + targetDim.width <= widthUpToParent + parentScreen.width) { + } else if (xr + targetDim.width <= screenRight) { return new Point(xr, hOff); } else if (yb + targetDim.height <= parentScreen.height) { return new Point(vOff, yb); } else if (ya >= 0) { return new Point(vOff, ya); } + // none were entirely within the parent screen. // position, but insure target stays on the total screen - if (log.isDebugEnabled()) log.debug("Outside parent: xl = {}, xr= {}, yb= {}, ya= {}", xl, xr, yb, ya); - int offScreen = widthUpToParent - xl; // note above !(xl >= widthUpToParent) + if (log.isDebugEnabled()) log.debug("Outside: widthUpToParent= {}, _totalScreenWidth= {}, screenHeight={}", + parentLoc.x, _totalScreenDim.width, parentScreen.height); + int offScreen = screenLeft - xl; int minOff = offScreen; - if (xl < widthUpToParent) { - xl = widthUpToParent; + log.debug("offScreen= {} minOff= {}, xl= {}", offScreen, minOff, xl); + if (xl < 0) { + xl = 0; } loc = new Point(xl, hOff); - log.debug("offScreen= {} minOff= {}, xl= {}", offScreen, minOff, xl); - - int maxRight = 0; - for (int i=0; i < _screenSize.length; i++) { - maxRight += _screenSize[i].width; - } - if (xr + targetDim.width <= maxRight) { // target entirely on total screen - offScreen = (xr + targetDim.width) - (widthUpToParent + parentScreen.width); - xr = widthUpToParent + parentScreen.width - targetDim.width; - } else { - offScreen = (xr + targetDim.width) - maxRight; // !(xr + targetDim.width <= maxRight) - xr = maxRight - targetDim.width; - } + + offScreen = xr + targetDim.width - screenRight; + xr = screenRight - targetDim.width; + log.debug("offScreen= {} minOff= {}, xr= {}", offScreen, minOff, xr); if (offScreen < minOff) { minOff = offScreen; loc = new Point(xr, hOff); } - log.debug("offScreen= {} minOff= {}, xr= {}", offScreen, minOff, xr); - offScreen = (yb + targetDim.height) - parentScreen.height; // !(yb + targetDim.height <= parentScreen.height) + offScreen = (yb + targetDim.height) - parentScreen.height; + yb = parentScreen.height - targetDim.height; + log.debug("offScreen= {} minOff = {}, yb= {}", offScreen, minOff, yb); if (offScreen < minOff) { minOff = offScreen; - yb = parentScreen.height - targetDim.height; + if (yb < 0) { + yb = 0; + } loc = new Point(vOff, yb); } - log.debug("offScreen= {} minOff = {}, yb= {}", offScreen, minOff, yb); offScreen = -ya; // !(ya >= 0) + log.debug("offScreen= {} minOff = {}, ya= {}", offScreen, minOff, ya); if (offScreen < minOff) { - ya = 0; minOff = offScreen; + ya = 0; loc = new Point(vOff, ya); } - log.debug("offScreen= {} minOff = {}, ya= {}", offScreen, minOff, ya); return loc; } diff --git a/java/test/jmri/jmrit/display/PreviewPanelTest.java b/java/test/jmri/jmrit/display/PreviewPanelTest.java new file mode 100644 index 00000000000..3df2dd8e131 --- /dev/null +++ b/java/test/jmri/jmrit/display/PreviewPanelTest.java @@ -0,0 +1,26 @@ +package jmri.jmrit.display; + +import org.junit.Assert; +import org.junit.Test; + +import jmri.jmrit.display.EditorScaffold; +import jmri.util.JUnitUtil; + +/** + * Tests for the PreviewPanel class + * + * @author Pete Cressman Copyright (C) 2020 + */ +public class PreviewPanelTest { + + @Test + public void testCtor() { + EditorScaffold editor = new EditorScaffold("ED"); + DisplayFrame df = new DisplayFrame("DisplayFrame", editor); + PreviewPanel p = new PreviewPanel(df, null, null, true); + Assert.assertNotNull("PreviewPanel Constructor",p); + JUnitUtil.dispose(df); + JUnitUtil.dispose(editor); + } + +} diff --git a/java/test/jmri/jmrit/display/palette/BackgroundItemPanelTest.java b/java/test/jmri/jmrit/display/palette/BackgroundItemPanelTest.java index 1959440d260..d7f73efb40b 100644 --- a/java/test/jmri/jmrit/display/palette/BackgroundItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/BackgroundItemPanelTest.java @@ -20,8 +20,7 @@ public class BackgroundItemPanelTest { public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); DisplayFrame df = new DisplayFrame(); - EditorScaffold es = new EditorScaffold(); - BackgroundItemPanel t = new BackgroundItemPanel(df,"test",es); + BackgroundItemPanel t = new BackgroundItemPanel(df,"test"); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/ClockItemPanelTest.java b/java/test/jmri/jmrit/display/palette/ClockItemPanelTest.java index 7ad69924f5d..2df3409d619 100644 --- a/java/test/jmri/jmrit/display/palette/ClockItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/ClockItemPanelTest.java @@ -20,8 +20,7 @@ public class ClockItemPanelTest { public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); DisplayFrame df = new DisplayFrame("Clock item Panel Test"); - EditorScaffold es = new EditorScaffold(); - ClockItemPanel t = new ClockItemPanel(df,"test",es); + ClockItemPanel t = new ClockItemPanel(df,"test"); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/DecoratorPanelTest.java b/java/test/jmri/jmrit/display/palette/DecoratorPanelTest.java index 0bcfaca9a3e..667bae0793c 100644 --- a/java/test/jmri/jmrit/display/palette/DecoratorPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/DecoratorPanelTest.java @@ -1,13 +1,15 @@ package jmri.jmrit.display.palette; import java.awt.GraphicsEnvironment; -import jmri.jmrit.display.controlPanelEditor.ControlPanelEditor; +import jmri.jmrit.display.EditorScaffold; import jmri.util.JUnitUtil; import org.junit.After; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; import org.junit.Test; +import jmri.jmrit.display.DisplayFrame; +import jmri.jmrit.display.PositionableLabel; /** * @@ -15,13 +17,22 @@ */ public class DecoratorPanelTest { + EditorScaffold editor; + DisplayFrame df; + @Test public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); - ControlPanelEditor editor = new ControlPanelEditor("ED"); - DecoratorPanel t = new DecoratorPanel(editor, null); - Assert.assertNotNull("exists",t); - JUnitUtil.dispose(editor); + DecoratorPanel dec = new DecoratorPanel(df); + Assert.assertNotNull("exists", dec); + } + + @Test + public void testInit() { + Assume.assumeFalse(GraphicsEnvironment.isHeadless()); + DecoratorPanel dec = new DecoratorPanel(df); + dec.initDecoratorPanel(new PositionableLabel("one", editor)); + Assert.assertNotNull("exists", dec); } // The minimal setup for log4J @@ -29,10 +40,14 @@ public void testCTor() { public void setUp() { JUnitUtil.setUp(); jmri.util.JUnitUtil.resetProfileManager(); + editor = new EditorScaffold("Editor"); + df = new DisplayFrame("DisplayFrame", editor); } @After public void tearDown() { + JUnitUtil.dispose(df); + JUnitUtil.dispose(editor); JUnitUtil.tearDown(); } diff --git a/java/test/jmri/jmrit/display/palette/DetectionPanelTest.java b/java/test/jmri/jmrit/display/palette/DetectionPanelTest.java index 66092b6e356..5e9e294f0d5 100644 --- a/java/test/jmri/jmrit/display/palette/DetectionPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/DetectionPanelTest.java @@ -25,7 +25,7 @@ public void testCTor() { ip = ItemPalette.getDefault("Test ItemPalette", es); ip.pack(); }); - TextItemPanel tip = new TextItemPanel(ip, "test", es); + TextItemPanel tip = new TextItemPanel(ip, "test"); DetectionPanel t = new DetectionPanel(tip); Assert.assertNotNull("exists", t); JUnitUtil.dispose(ip); diff --git a/java/test/jmri/jmrit/display/palette/IconDialogTest.java b/java/test/jmri/jmrit/display/palette/IconDialogTest.java index cb42c35f4ad..15234e03334 100644 --- a/java/test/jmri/jmrit/display/palette/IconDialogTest.java +++ b/java/test/jmri/jmrit/display/palette/IconDialogTest.java @@ -3,7 +3,6 @@ import java.awt.GraphicsEnvironment; import jmri.Turnout; import jmri.jmrit.display.DisplayFrame; -import jmri.jmrit.display.Editor; import jmri.jmrit.display.EditorScaffold; import jmri.jmrit.picker.PickListModel; import jmri.util.JUnitUtil; @@ -22,15 +21,15 @@ public class IconDialogTest { @Test public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); - new EditorScaffold(); PickListModel tableModel = PickListModel.turnoutPickModelInstance(); - DisplayFrame df = new DisplayFrame("Icon Dialog Test"); - Editor editor = new EditorScaffold(); - TableItemPanel tip = new TableItemPanel<>(df,"IS01","",tableModel,editor); + EditorScaffold editor = new EditorScaffold("Editor"); + DisplayFrame df = new DisplayFrame("Icon Dialog Test", editor); + TableItemPanel tip = new TableItemPanel<>(df,"IS01","",tableModel); IconDialog t = new IconDialog("Icon","Icon",tip,null); Assert.assertNotNull("exists",t); JUnitUtil.dispose(t); JUnitUtil.dispose(df); + JUnitUtil.dispose(editor); } // The minimal setup for log4J diff --git a/java/test/jmri/jmrit/display/palette/IconItemPanelTest.java b/java/test/jmri/jmrit/display/palette/IconItemPanelTest.java index f4fb3ed6d45..1e3963e6a69 100644 --- a/java/test/jmri/jmrit/display/palette/IconItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/IconItemPanelTest.java @@ -20,8 +20,7 @@ public class IconItemPanelTest { public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); DisplayFrame df = new DisplayFrame(); - EditorScaffold es = new EditorScaffold(); - IconItemPanel t = new IconItemPanel(df,"test",es); + IconItemPanel t = new IconItemPanel(df,"test"); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/IndicatorItemPanelTest.java b/java/test/jmri/jmrit/display/palette/IndicatorItemPanelTest.java index 0d6cdc05491..ba10a2846e9 100644 --- a/java/test/jmri/jmrit/display/palette/IndicatorItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/IndicatorItemPanelTest.java @@ -20,8 +20,7 @@ public class IndicatorItemPanelTest { public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); DisplayFrame df = new DisplayFrame(); - EditorScaffold es = new EditorScaffold(); - IndicatorItemPanel t = new IndicatorItemPanel(df,"test1","test2",es); + IndicatorItemPanel t = new IndicatorItemPanel(df,"test1","test2"); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/IndicatorTOIconDialogTest.java b/java/test/jmri/jmrit/display/palette/IndicatorTOIconDialogTest.java index f0afb93ca33..fec33541f46 100644 --- a/java/test/jmri/jmrit/display/palette/IndicatorTOIconDialogTest.java +++ b/java/test/jmri/jmrit/display/palette/IndicatorTOIconDialogTest.java @@ -2,7 +2,6 @@ import java.awt.GraphicsEnvironment; import jmri.jmrit.display.DisplayFrame; -import jmri.jmrit.display.Editor; import jmri.jmrit.display.EditorScaffold; import jmri.jmrit.picker.PickListModel; import jmri.util.JUnitUtil; @@ -22,13 +21,15 @@ public class IndicatorTOIconDialogTest { public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); PickListModel tableModel = PickListModel.turnoutPickModelInstance(); - DisplayFrame df = new DisplayFrame("Indicator TO Icon Dialog Test"); - Editor editor = new EditorScaffold(); - IndicatorTOItemPanel itp = new IndicatorTOItemPanel(df,"IT01","",tableModel,editor); + jmri.util.JUnitUtil.resetProfileManager(); + EditorScaffold editor = new EditorScaffold("ED"); + DisplayFrame df = new DisplayFrame("DisplayFrame", editor); + IndicatorTOItemPanel itp = new IndicatorTOItemPanel(df,"IT01","",tableModel); IndicatorTOIconDialog t = new IndicatorTOIconDialog("Turnout","Turnout",itp,"",null); Assert.assertNotNull("exists",t); JUnitUtil.dispose(t); JUnitUtil.dispose(df); + JUnitUtil.dispose(editor); } // The minimal setup for log4J diff --git a/java/test/jmri/jmrit/display/palette/IndicatorTOItemPanelTest.java b/java/test/jmri/jmrit/display/palette/IndicatorTOItemPanelTest.java index 85240094080..495f005227f 100644 --- a/java/test/jmri/jmrit/display/palette/IndicatorTOItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/IndicatorTOItemPanelTest.java @@ -23,8 +23,7 @@ public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); PickListModel tableModel = PickListModel.turnoutPickModelInstance(); DisplayFrame df = new DisplayFrame("Indicator TO Item Panel Test"); - Editor editor = new EditorScaffold(); - IndicatorTOItemPanel t = new IndicatorTOItemPanel(df,"IT01","",tableModel,editor); + IndicatorTOItemPanel t = new IndicatorTOItemPanel(df,"IT01","",tableModel); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/MemoryItemPanelTest.java b/java/test/jmri/jmrit/display/palette/MemoryItemPanelTest.java index 906baa30669..54ada2bb0a3 100644 --- a/java/test/jmri/jmrit/display/palette/MemoryItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/MemoryItemPanelTest.java @@ -28,7 +28,7 @@ public void testCTor() { ip = ItemPalette.getDefault("test palette", editor); ip.pack(); }); - MemoryItemPanel t = new MemoryItemPanel(ip, "IM01", "", tableModel, editor); + MemoryItemPanel t = new MemoryItemPanel(ip, "IM01", "", tableModel); Assert.assertNotNull("exists", t); JUnitUtil.dispose(ip); JUnitUtil.dispose(editor); diff --git a/java/test/jmri/jmrit/display/palette/MultiSensorIconDialogTest.java b/java/test/jmri/jmrit/display/palette/MultiSensorIconDialogTest.java index 1fd1dbf4145..a9272761941 100644 --- a/java/test/jmri/jmrit/display/palette/MultiSensorIconDialogTest.java +++ b/java/test/jmri/jmrit/display/palette/MultiSensorIconDialogTest.java @@ -3,7 +3,6 @@ import java.awt.GraphicsEnvironment; import jmri.Sensor; import jmri.jmrit.display.DisplayFrame; -import jmri.jmrit.display.Editor; import jmri.jmrit.display.EditorScaffold; import jmri.jmrit.picker.PickListModel; import jmri.util.JUnitUtil; @@ -23,13 +22,15 @@ public class MultiSensorIconDialogTest { public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); PickListModel tableModel = PickListModel.sensorPickModelInstance(); // NOI18N - DisplayFrame df = new DisplayFrame("Indicator TO Icon Dialog Test"); // NOI18N - Editor editor = new EditorScaffold(); - MultiSensorItemPanel mip = new MultiSensorItemPanel(df,"IS01","",tableModel,editor); + EditorScaffold editor = new EditorScaffold("ED"); + DisplayFrame df = new DisplayFrame("Indicator TO Icon Dialog Test", editor); // NOI18N + MultiSensorItemPanel mip = new MultiSensorItemPanel(df,"IS01","",tableModel); MultiSensorIconDialog t = new MultiSensorIconDialog("MultiSensor","MultiSensor",mip,null); // NOI18N Assert.assertNotNull("exists",t); // NOI18N JUnitUtil.dispose(t); JUnitUtil.dispose(df); + JUnitUtil.dispose(df); + JUnitUtil.dispose(editor); } // The minimal setup for log4J diff --git a/java/test/jmri/jmrit/display/palette/MultiSensorItemPanelTest.java b/java/test/jmri/jmrit/display/palette/MultiSensorItemPanelTest.java index 2fc341787f7..4f871e91b46 100644 --- a/java/test/jmri/jmrit/display/palette/MultiSensorItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/MultiSensorItemPanelTest.java @@ -23,8 +23,7 @@ public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); PickListModel tableModel = PickListModel.sensorPickModelInstance(); DisplayFrame df = new DisplayFrame("MultiSensor Item Panel Test"); - Editor editor = new EditorScaffold(); - MultiSensorItemPanel t = new MultiSensorItemPanel(df,"IS01","",tableModel,editor); + MultiSensorItemPanel t = new MultiSensorItemPanel(df,"IS01","",tableModel); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/PortalItemPanelTest.java b/java/test/jmri/jmrit/display/palette/PortalItemPanelTest.java index 7771123abb0..cc9c2d7207c 100644 --- a/java/test/jmri/jmrit/display/palette/PortalItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/PortalItemPanelTest.java @@ -20,8 +20,7 @@ public class PortalItemPanelTest { public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); DisplayFrame df = new DisplayFrame(); - EditorScaffold es = new EditorScaffold(); - PortalItemPanel t = new PortalItemPanel(df,"test1","test2",es); + PortalItemPanel t = new PortalItemPanel(df,"test1","test2"); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/RPSItemPanelTest.java b/java/test/jmri/jmrit/display/palette/RPSItemPanelTest.java index 1d48b3b27b8..dee5ac98bbd 100644 --- a/java/test/jmri/jmrit/display/palette/RPSItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/RPSItemPanelTest.java @@ -20,8 +20,7 @@ public class RPSItemPanelTest { public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); DisplayFrame df = new DisplayFrame(); - EditorScaffold es = new EditorScaffold(); - RPSItemPanel t = new RPSItemPanel(df,"test1","test2",es); + RPSItemPanel t = new RPSItemPanel(df,"test1","test2"); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/ReporterItemPanelTest.java b/java/test/jmri/jmrit/display/palette/ReporterItemPanelTest.java index efd3599f624..76ba3643985 100644 --- a/java/test/jmri/jmrit/display/palette/ReporterItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/ReporterItemPanelTest.java @@ -23,8 +23,7 @@ public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); PickListModel tableModel = PickListModel.reporterPickModelInstance(); DisplayFrame df = new DisplayFrame("Reporter Item Panel Test"); - Editor editor = new EditorScaffold(); - ReporterItemPanel t = new ReporterItemPanel(df,"IR01","",tableModel,editor); + ReporterItemPanel t = new ReporterItemPanel(df,"IR01","",tableModel); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/SignalHeadIconDialogTest.java b/java/test/jmri/jmrit/display/palette/SignalHeadIconDialogTest.java index 2ea9999dec8..28ec299b4c2 100644 --- a/java/test/jmri/jmrit/display/palette/SignalHeadIconDialogTest.java +++ b/java/test/jmri/jmrit/display/palette/SignalHeadIconDialogTest.java @@ -23,13 +23,14 @@ public class SignalHeadIconDialogTest { public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); PickListModel tableModel = PickListModel.signalHeadPickModelInstance(); // NOI18N - DisplayFrame df = new DisplayFrame("Indicator TO Icon Dialog Test"); // NOI18N - Editor editor = new EditorScaffold(); - SignalHeadItemPanel sip = new SignalHeadItemPanel(df,"IS01","",tableModel,editor); // NOI18N + EditorScaffold editor = new EditorScaffold("ED"); + DisplayFrame df = new DisplayFrame("Indicator TO Icon Dialog Test", editor); // NOI18N + SignalHeadItemPanel sip = new SignalHeadItemPanel(df,"IS01","",tableModel); // NOI18N SignalHeadIconDialog t = new SignalHeadIconDialog("SignalHead","SignalHead",sip,null); // NOI18N Assert.assertNotNull("exists",t); // NOI18N JUnitUtil.dispose(t); JUnitUtil.dispose(df); + JUnitUtil.dispose(editor); } // The minimal setup for log4J diff --git a/java/test/jmri/jmrit/display/palette/SignalHeadItemPanelTest.java b/java/test/jmri/jmrit/display/palette/SignalHeadItemPanelTest.java index 18cc42f2cd7..ba8270d3508 100644 --- a/java/test/jmri/jmrit/display/palette/SignalHeadItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/SignalHeadItemPanelTest.java @@ -23,8 +23,7 @@ public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); PickListModel tableModel = PickListModel.signalHeadPickModelInstance(); DisplayFrame df = new DisplayFrame("SignalHead Item Panel Test"); - Editor editor = new EditorScaffold(); - SignalHeadItemPanel t = new SignalHeadItemPanel(df,"IH01","",tableModel,editor); + SignalHeadItemPanel t = new SignalHeadItemPanel(df,"IH01","",tableModel); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/SignalMastItemPanelTest.java b/java/test/jmri/jmrit/display/palette/SignalMastItemPanelTest.java index 6b4f8c603c9..54b8a79f5af 100644 --- a/java/test/jmri/jmrit/display/palette/SignalMastItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/SignalMastItemPanelTest.java @@ -23,8 +23,7 @@ public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); PickListModel tableModel = PickListModel.signalMastPickModelInstance(); DisplayFrame df = new DisplayFrame("SignalMast Item Panel Test"); - Editor editor = new EditorScaffold(); - SignalMastItemPanel t = new SignalMastItemPanel(df,"IM01","",tableModel,editor); + SignalMastItemPanel t = new SignalMastItemPanel(df,"IM01","",tableModel); Assert.assertNotNull("exists",t); JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/TableItemPanelTest.java b/java/test/jmri/jmrit/display/palette/TableItemPanelTest.java index e55ddea105e..bcbd54c2054 100644 --- a/java/test/jmri/jmrit/display/palette/TableItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/TableItemPanelTest.java @@ -24,8 +24,7 @@ public void testCTor() { Assume.assumeFalse(GraphicsEnvironment.isHeadless()); PickListModel tableModel = PickListModel.turnoutPickModelInstance(); DisplayFrame df = new DisplayFrame("Table Item Panel Test"); // NOI18N - Editor editor = new EditorScaffold(); - TableItemPanel t = new TableItemPanel(df,"IS01","",tableModel,editor); // NOI18N + TableItemPanel t = new TableItemPanel(df,"IS01","",tableModel); // NOI18N Assert.assertNotNull("exists",t); // NOI18N JUnitUtil.dispose(df); } diff --git a/java/test/jmri/jmrit/display/palette/TextItemPanelTest.java b/java/test/jmri/jmrit/display/palette/TextItemPanelTest.java index becadc2dfc9..7007ea075ff 100644 --- a/java/test/jmri/jmrit/display/palette/TextItemPanelTest.java +++ b/java/test/jmri/jmrit/display/palette/TextItemPanelTest.java @@ -26,7 +26,7 @@ public void testCTor() { ip = ItemPalette.getDefault("Test ItemPalette", es); ip.pack(); }); - TextItemPanel t = new TextItemPanel(ip, "test", es); + TextItemPanel t = new TextItemPanel(ip, "test"); Assert.assertNotNull("exists", t); JUnitUtil.dispose(ip); JUnitUtil.dispose(es);