Skip to content

Commit

Permalink
Palette cleanup. Improve background color refresh of ItemPalette panels.
Browse files Browse the repository at this point in the history
Fix issues with Background panel and Memory types panels. Fix
AnalogClock scaling, Now has minimal scale reduction to 10% and no
longer disappears. Fix PlaceWindow for multi-screen environments.
  • Loading branch information
petecressman committed Apr 5, 2020
1 parent 1f1905c commit bc5ca54
Show file tree
Hide file tree
Showing 63 changed files with 901 additions and 869 deletions.
10 changes: 7 additions & 3 deletions java/src/jmri/jmrit/display/AnalogClock2Display.java
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
137 changes: 111 additions & 26 deletions 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;

Expand All @@ -23,7 +40,7 @@ class jmri.util.swing.ImagePanel {
+paintComponent()
}
class jmri.jmrit.DisplayFrame #88dddd {
-previewBgSet
-previewBgIndex
#SetInitListener()
#setPreviewBg(i)
#getPreviewBg()
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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();
Expand All @@ -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);

}
14 changes: 9 additions & 5 deletions java/src/jmri/jmrit/display/Editor.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/display/IndicatorTrackIcon.java
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/display/IndicatorTurnoutIcon.java
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion java/src/jmri/jmrit/display/MultiSensorIcon.java
Expand Up @@ -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();
};
Expand Down
8 changes: 3 additions & 5 deletions java/src/jmri/jmrit/display/PositionableLabel.java
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
};
Expand Down

0 comments on commit bc5ca54

Please sign in to comment.