Skip to content

Commit

Permalink
Fill opacity as a graphic property #505
Browse files Browse the repository at this point in the history
  • Loading branch information
nroduit committed Jan 5, 2024
1 parent f33ddd4 commit 8ca6ef3
Show file tree
Hide file tree
Showing 36 changed files with 416 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,16 @@
*/
package org.weasis.acquire.dockable.components.actions.annotate;

import java.awt.Color;
import java.awt.Component;
import java.util.Optional;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.SwingUtilities;
import javax.swing.border.Border;
import org.weasis.acquire.Messages;
import org.weasis.base.viewer2d.EventManager;
Expand All @@ -30,9 +27,6 @@
import org.weasis.core.api.gui.util.GuiUtils;
import org.weasis.core.api.gui.util.ToggleButtonListener;
import org.weasis.core.api.image.util.Unit;
import org.weasis.core.api.util.ResourceUtil;
import org.weasis.core.api.util.ResourceUtil.ActionIcon;
import org.weasis.core.ui.editor.image.MeasureToolBar;
import org.weasis.core.ui.editor.image.dockable.MeasureTool;
import org.weasis.core.util.StringUtil;

Expand Down Expand Up @@ -74,41 +68,11 @@ public AnnotationOptionsPanel() {
private JPanel createLineStylePanel() {
JLabel label =
new JLabel(org.weasis.core.Messages.getString("MeasureToolBar.line") + StringUtil.COLON);
JButton button = new JButton(ResourceUtil.getIcon(ActionIcon.PIPETTE));
button.setToolTipText(org.weasis.core.Messages.getString("MeasureTool.pick"));
button.addActionListener(
e -> {
JButton b = (JButton) e.getSource();
Color newColor =
JColorChooser.showDialog(
SwingUtilities.getWindowAncestor(AnnotationOptionsPanel.this),
org.weasis.core.Messages.getString("MeasureTool.pick_color"),
b.getBackground());
if (newColor != null) {
b.setBackground(newColor);
MeasureTool.viewSetting.setLineColor(newColor);
updateMeasureProperties();
}
});
JButton button = MeasureTool.buildLineColorButton(this);

JSpinner spinner = new JSpinner();
GuiUtils.setNumberModel(spinner, MeasureTool.viewSetting.getLineWidth(), 1, 8, 1);
spinner.addChangeListener(
e -> {
Object val = ((JSpinner) e.getSource()).getValue();
if (val instanceof Integer intVal) {
MeasureTool.viewSetting.setLineWidth(intVal);
updateMeasureProperties();
}
});
MeasureTool.viewSetting.initLineWidthSpinner(spinner);

return GuiUtils.getFlowLayoutPanel(label, button, spinner);
}

private void updateMeasureProperties() {
MeasureToolBar.getMeasureGraphicList()
.forEach(g -> MeasureToolBar.applyDefaultSetting(MeasureTool.viewSetting, g));
MeasureToolBar.getDrawGraphicList()
.forEach(g -> MeasureToolBar.applyDefaultSetting(MeasureTool.viewSetting, g));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ protected boolean dropFiles(List<File> files, TransferSupport support) {
private void importInExplorer(
List<DataExplorerView> exps, final List<File> vals, DropLocation dropLocation) {
if (exps.size() == 1) {
exps.get(0).importFiles(vals.toArray(new File[0]), true);
exps.getFirst().importFiles(vals.toArray(new File[0]), true);
} else {
Point p;
if (dropLocation == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ public String toString() {
}

public static FontItem getFontItem(String key) {
return getFontItem(key, FontItem.DEFAULT);
}

public static FontItem getFontItem(String key, FontItem defaultItem) {
for (FontItem item : FontItem.values()) {
if (item.key.equals(key)) {
return item;
}
}
return DEFAULT;
return defaultItem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ public MeasureDialog(ViewCanvas<?> view2d, List<DragGraphic> selectedGraphic) {

public void iniGraphicDialog() {
if (!graphics.isEmpty()) {
DragGraphic graphic = graphics.get(0);
DragGraphic graphic = graphics.getFirst();
this.color = (Color) graphic.getColorPaint();
int width = graphic.getLineThickness().intValue();
boolean fill = graphic.getFilled();
float opacity = graphic.getFillOpacity();

spinnerLineWidth.setValue(width);
jCheckBoxFilled.setSelected(fill);
slicerOpacity.setValue((int) (opacity * 100f));

boolean areaGraphics = false;
boolean mfill = false;
boolean mcolor = false;
boolean mwidth = false;
boolean mopacity = false;
for (DragGraphic g : graphics) {
if (g instanceof GraphicArea) {
areaGraphics = true;
Expand All @@ -68,6 +71,9 @@ public void iniGraphicDialog() {
if (!color.equals(g.getColorPaint())) {
mcolor = true;
}
if (g.getFillOpacity() != opacity) {
mopacity = true;
}
}

checkBoxColor.setEnabled(mcolor);
Expand All @@ -80,7 +86,10 @@ public void iniGraphicDialog() {
checkBoxFill.setEnabled(mfill);
jCheckBoxFilled.setEnabled(areaGraphics && !mfill);

if (graphics.size() == 1 || (!mcolor && !mfill && !mwidth)) {
checkBoxFillOpacity.setEnabled(mopacity);
slicerOpacity.setEnabled(areaGraphics && !mopacity);

if (graphics.size() == 1 || (!mcolor && !mfill && !mwidth && !mopacity)) {
overrideMultipleValues.setVisible(false);
} else {
int size = overrideMultipleValues.getPreferredSize().width / 2;
Expand All @@ -93,6 +102,8 @@ public void iniGraphicDialog() {
panelFilled.add(GuiUtils.boxHorizontalStrut(size));
panelFilled.add(checkBoxFill);
panelFilled.add(GuiUtils.boxHorizontalStrut(size));
panelOpacity.add(checkBoxFillOpacity);
panelOpacity.add(GuiUtils.boxHorizontalStrut(size));
}
if (view2D != null
&& graphics.size() == 1
Expand Down Expand Up @@ -130,9 +141,12 @@ protected void okAction() {
if (jCheckBoxFilled.isEnabled()) {
graphic.setFilled(jCheckBoxFilled.isSelected());
}
if (slicerOpacity.isEnabled()) {
graphic.setFillOpacity(slicerOpacity.getValue() / 100f);
}
}
if (graphics.size() == 1 && view2D != null) {
DragGraphic graphic = graphics.get(0);
DragGraphic graphic = graphics.getFirst();
if (graphic instanceof AnnotationGraphic) {
graphic.setLabel(EscapeChars.convertToLines(textPane.getText()), view2D);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,29 @@
import java.awt.FlowLayout;
import java.awt.Window;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.DefaultBoundedRangeModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.border.TitledBorder;
import org.weasis.core.Messages;
import org.weasis.core.api.gui.util.DecFormatter;
import org.weasis.core.api.gui.util.GuiUtils;
import org.weasis.core.api.gui.util.JSliderW;
import org.weasis.core.api.gui.util.SliderChangeListener;
import org.weasis.core.api.util.FontItem;
import org.weasis.core.api.util.ResourceUtil;
import org.weasis.core.api.util.ResourceUtil.ActionIcon;
import org.weasis.core.util.StringUtil;

public abstract class PropertiesDialog extends JDialog {

public static final String FILL_OPACITY = "Fill opacity";
protected Color color;

private final JPanel panel1 = new JPanel();
Expand All @@ -39,15 +47,18 @@ public abstract class PropertiesDialog extends JDialog {
protected final JLabel jLabelLineColor = new JLabel();
protected final JButton jButtonColor = new JButton(ResourceUtil.getIcon(ActionIcon.PIPETTE));
protected final JCheckBox jCheckBoxFilled = new JCheckBox();
protected final JSliderW slicerOpacity = createOpacitySlider(FILL_OPACITY);
protected final JButton overrideMultipleValues =
new JButton(Messages.getString("PropertiesDialog.header_override"));
protected final JCheckBox checkBoxColor = new JCheckBox();
protected final JCheckBox checkBoxFillOpacity = new JCheckBox();
protected final JCheckBox checkBoxWidth = new JCheckBox();
protected final JCheckBox checkBoxFill = new JCheckBox();

protected final JPanel panelColor = GuiUtils.getFlowLayoutPanel(FlowLayout.TRAILING, 2, 5);
protected final JPanel panelLine = GuiUtils.getFlowLayoutPanel(FlowLayout.TRAILING, 2, 5);
protected final JPanel panelFilled = GuiUtils.getFlowLayoutPanel(FlowLayout.TRAILING, 2, 5);
protected final JPanel panelOpacity = GuiUtils.getFlowLayoutPanel(FlowLayout.TRAILING, 2, 5);

protected PropertiesDialog(Window parent, String title) {
super(parent, title, ModalityType.APPLICATION_MODAL);
Expand All @@ -70,6 +81,7 @@ private void init() {
jButtonColor.addActionListener(e -> openColorChooser((JButton) e.getSource()));

jCheckBoxFilled.setText(Messages.getString("PropertiesDialog.fill_shape"));
slicerOpacity.addChangeListener(_ -> updateSlider(slicerOpacity, FILL_OPACITY));

getContentPane().add(panel1);

Expand All @@ -96,6 +108,11 @@ private void init() {
JCheckBox box = (JCheckBox) e.getSource();
jCheckBoxFilled.setEnabled(box.isSelected());
});
checkBoxFillOpacity.addActionListener(
e -> {
JCheckBox box = (JCheckBox) e.getSource();
slicerOpacity.setEnabled(box.isSelected());
});

JPanel centerPanel = GuiUtils.getVerticalBoxLayoutPanel();
centerPanel.add(GuiUtils.getFlowLayoutPanel(FlowLayout.TRAILING, 2, 5, overrideMultipleValues));
Expand All @@ -107,10 +124,12 @@ private void init() {
panelLine.add(spinnerLineWidth);

panelFilled.add(jCheckBoxFilled);
panelOpacity.add(slicerOpacity);

centerPanel.add(panelColor);
centerPanel.add(panelLine);
centerPanel.add(panelFilled);
centerPanel.add(panelOpacity);
centerPanel.add(GuiUtils.boxVerticalStrut(10));
panel1.add(centerPanel, BorderLayout.CENTER);
}
Expand All @@ -124,6 +143,32 @@ protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
}

public static float updateSlider(JSliderW slider, String titlePrefix) {
float value = slider.getValue() / 100f;
SliderChangeListener.updateSliderProperties(slider, getOpacityTitle(titlePrefix, value));
return value;
}

private static String getOpacityTitle(String titlePrefix, float value) {
return titlePrefix + StringUtil.COLON_AND_SPACE + DecFormatter.percentTwoDecimal(value);
}

public static JSliderW createOpacitySlider(String titlePrefix) {
DefaultBoundedRangeModel model = new DefaultBoundedRangeModel(100, 0, 0, 100);
TitledBorder titledBorder =
new TitledBorder(
BorderFactory.createEmptyBorder(),
getOpacityTitle(titlePrefix, model.getValue() / 100f),
TitledBorder.LEADING,
TitledBorder.DEFAULT_POSITION,
FontItem.MEDIUM.getFont(),
null);
JSliderW s = new JSliderW(model);
s.setDisplayValueInTitle(true);
s.setBorder(titledBorder);
return s;
}

protected abstract void okAction();

protected void quitWithoutSaving() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public static List<MeasureItem> getStatistics(

Double suv = (Double) layer.getSourceTagValue(TagW.SuvFactor);
if (channelIndex == null && Objects.nonNull(suv)) {
unit = "SUVbw";
unit = "SUVbw, g/ml"; // NON-NLS
addMeasure(measList, IMAGE_MIN, null, min * suv, unit);
addMeasure(measList, IMAGE_MAX, null, max * suv, unit);
addMeasure(measList, IMAGE_MEAN, null, mean * suv, unit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ public GridBagLayoutModel getViewLayout(String title) {
public void addSeriesList(List<MediaSeries<E>> seriesList, boolean bestDefaultLayout) {
if (seriesList != null && !seriesList.isEmpty()) {
if (SynchData.Mode.TILE.equals(synchView.getSynchData().getMode())) {
addSeries(seriesList.get(0));
addSeries(seriesList.getFirst());
return;
}
setSelectedAndGetFocus();
Expand All @@ -886,7 +886,7 @@ public void addSeriesList(List<MediaSeries<E>> seriesList, boolean bestDefaultLa
}
}
if (!view2ds.isEmpty()) {
setSelectedImagePane(view2ds.get(0));
setSelectedImagePane(view2ds.getFirst());
}
for (MediaSeries mediaSeries : seriesList) {
addSeries(mediaSeries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ public MeasureToolBar(final ImageViewerEventManager<?> eventManager, int index)
throw new IllegalArgumentException("EventManager cannot be null");
}
this.eventManager = eventManager;

MeasureToolBar.measureGraphicList.forEach(
g -> MeasureToolBar.applyDefaultSetting(MeasureTool.viewSetting, g));
MeasureToolBar.drawGraphicList.forEach(
g -> MeasureToolBar.applyDefaultSetting(MeasureTool.viewSetting, g));
MeasureTool.updateMeasureProperties();

Optional<ComboItemListener<Graphic>> measure = eventManager.getAction(ActionW.DRAW_MEASURE);
measure.ifPresent(comboItemListener -> add(buildButton(comboItemListener)));
Expand Down Expand Up @@ -205,6 +201,8 @@ public static void applyDefaultSetting(ViewSetting setting, Graphic graphic) {
if (graphic instanceof DragGraphic g) {
g.setLineThickness((float) setting.getLineWidth());
g.setPaint(setting.getLineColor());
g.setFilled(setting.isFilled());
g.setFillOpacity(setting.getFillOpacity());
}
}

Expand Down
Loading

0 comments on commit 8ca6ef3

Please sign in to comment.