From a57ad70c818546ce6ef5543f5d5a7f55ffc12485 Mon Sep 17 00:00:00 2001 From: Konstantin Hudyakov Date: Thu, 4 Jul 2024 12:06:08 +0300 Subject: [PATCH] [microba] IJPL-157402 Remove unused GradientEditor GitOrigin-RevId: 00d57f081ff856fbdc70eae5ffcc93aa224dac03 --- libraries/microba/README.md | 1 - .../com/michaelbaranov/microba/Microba.java | 3 - .../microba/common/BoundedTableModel.java | 3 +- .../DefaultGradientEditorModel.java | 131 ------------- .../gradienteditor/GradientEditor.java | 177 ------------------ .../ui/GradientEditorLayout.java | 60 ------ .../gradienteditor/ui/GradientEditorUI.java | 7 - .../ui/basic/BasicGradientEditorUI.java | 172 ----------------- 8 files changed, 1 insertion(+), 553 deletions(-) delete mode 100644 libraries/microba/src/com/michaelbaranov/microba/gradienteditor/DefaultGradientEditorModel.java delete mode 100644 libraries/microba/src/com/michaelbaranov/microba/gradienteditor/GradientEditor.java delete mode 100644 libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/GradientEditorLayout.java delete mode 100644 libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/GradientEditorUI.java delete mode 100644 libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/basic/BasicGradientEditorUI.java diff --git a/libraries/microba/README.md b/libraries/microba/README.md index 27b529c5d466..4cd7a9df6611 100644 --- a/libraries/microba/README.md +++ b/libraries/microba/README.md @@ -31,7 +31,6 @@ MarkerBar * Flipped marks GradientBar -GradientEditor * Key-point based palette * Linear color interpolation * Horizontal/vertical alignment diff --git a/libraries/microba/src/com/michaelbaranov/microba/Microba.java b/libraries/microba/src/com/michaelbaranov/microba/Microba.java index de575012ff36..262d2e39f0cb 100644 --- a/libraries/microba/src/com/michaelbaranov/microba/Microba.java +++ b/libraries/microba/src/com/michaelbaranov/microba/Microba.java @@ -4,7 +4,6 @@ import com.michaelbaranov.microba.calendar.ui.basic.BasicCalendarPaneUI; import com.michaelbaranov.microba.calendar.ui.basic.BasicDatePickerUI; import com.michaelbaranov.microba.common.MicrobaComponent; import com.michaelbaranov.microba.gradient.ui.basic.BasicGradientUI; -import com.michaelbaranov.microba.gradienteditor.ui.basic.BasicGradientEditorUI; import com.michaelbaranov.microba.marker.ui.basic.BasicMarkerBarUI; import com.michaelbaranov.microba.marker.ui.metal.MetalMarkerBarUI; import com.michaelbaranov.microba.marker.ui.motif.MotifMarkerBarUI; @@ -58,8 +57,6 @@ public class Microba { UIManager.put(packagePrefix + "calendar.ui.basic.BasicDatePickerUI", BasicDatePickerUI.class); UIManager.put("microba.GradientUI", packagePrefix + "gradient.ui.basic.BasicGradientUI"); UIManager.put(packagePrefix + "gradient.ui.basic.BasicGradientUI", BasicGradientUI.class); - UIManager.put("microba.GradientEditorUI", packagePrefix + "gradienteditor.ui.basic.BasicGradientEditorUI"); - UIManager.put(packagePrefix + "gradienteditor.ui.basic.BasicGradientEditorUI", BasicGradientEditorUI.class); UIManager.put("microba.MarkerBarUI", packagePrefix + "marker.ui.basic.BasicMarkerBarUI"); UIManager.put(packagePrefix + "marker.ui.basic.BasicMarkerBarUI", BasicMarkerBarUI.class); diff --git a/libraries/microba/src/com/michaelbaranov/microba/common/BoundedTableModel.java b/libraries/microba/src/com/michaelbaranov/microba/common/BoundedTableModel.java index bb083710fba5..29d944129076 100644 --- a/libraries/microba/src/com/michaelbaranov/microba/common/BoundedTableModel.java +++ b/libraries/microba/src/com/michaelbaranov/microba/common/BoundedTableModel.java @@ -9,8 +9,7 @@ import java.beans.PropertyChangeListener; * The upper and lower bound values are introduced to further describe table * data. For example, BoundedTableModel is used as a data model * for {@link com.michaelbaranov.microba.marker.MarkerBar}, - * {@link com.michaelbaranov.microba.gradient.GradientBar}, - * {@link com.michaelbaranov.microba.gradienteditor.GradientEditor} + * {@link com.michaelbaranov.microba.gradient.GradientBar} * * @version 0.1 (rev. 13 Aug 2005) * @author Michael Baranov - * This implementation is mutable. - * - * @author Michael Baranov - * - */ -public class DefaultGradientEditorModel extends - AbstractBoundedTableModelWithSelection implements MarkerMutationModel { - - public static final int POSITION_COLUMN = 0; - - public static final int COLOR_COLUMN = 1; - - protected List position = new ArrayList<>(32); - - protected List color = new ArrayList<>(32); - - public DefaultGradientEditorModel() { - super(); - setSelectionMode(SINGLE_SELECTION); - - position.add(Integer.valueOf(0)); - color.add(Color.BLACK); - - position.add(Integer.valueOf(255)); - color.add(Color.WHITE); - - } - - @Override - public void removeMarkerAtIndex(int index) { - if (isSelectedIndex(index)) { - removeSelectionInterval(index, index); - } - position.remove(index); - color.remove(index); - fireTableRowsDeleted(index, index); - - } - - @Override - public int addMarkAtPosition(int pos) { - position.add(Integer.valueOf(pos)); - color.add(new Color((float) Math.random(), (float) Math.random(), - (float) Math.random())); - int index = position.size() - 1; - fireTableRowsInserted(index, index); - return index; - } - - @Override - public int getLowerBound() { - return 0; - } - - @Override - public int getUpperBound() { - return 255; - } - - @Override - public int getRowCount() { - return position.size(); - } - - @Override - public int getColumnCount() { - return 2; - } - - @Override - public Class getColumnClass(int columnIndex) { - return switch (columnIndex) { - case POSITION_COLUMN -> Integer.class; - case COLOR_COLUMN -> Color.class; - default -> super.getColumnClass(columnIndex); - }; - } - - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - return switch (columnIndex) { - case POSITION_COLUMN -> position.get(rowIndex); - case COLOR_COLUMN -> color.get(rowIndex); - default -> null; - }; - } - - @Override - public void setValueAt(Object aValue, int rowIndex, int columnIndex) { - switch (columnIndex) { - case POSITION_COLUMN: - - for (int i = 0; i < position.size(); i++) - if (rowIndex != i && aValue.equals(position.get(i))) { - return; - } - - position.remove(rowIndex); - position.add(rowIndex, (Integer)aValue); - fireTableCellUpdated(rowIndex, columnIndex); - break; - - case COLOR_COLUMN: - color.remove(rowIndex); - color.add(rowIndex, (Color)aValue); - fireTableCellUpdated(rowIndex, columnIndex); - break; - } - } - - @Override - public boolean isCellEditable(int rowIndex, int columnIndex) { - // protecting first 2 rows (first and last marker) from being moved - return !(columnIndex == POSITION_COLUMN && rowIndex < 2); - } -} diff --git a/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/GradientEditor.java b/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/GradientEditor.java deleted file mode 100644 index 48ba704dfab1..000000000000 --- a/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/GradientEditor.java +++ /dev/null @@ -1,177 +0,0 @@ -package com.michaelbaranov.microba.gradienteditor; - -import com.michaelbaranov.microba.gradient.GradientBar; -import com.michaelbaranov.microba.marker.MarkerBar; -import com.michaelbaranov.microba.marker.MarkerMutationModel; - -import javax.swing.*; - -/** - * IMPORTANT: alpha featre not implemented. Stubs only. No alpha marker bar yet. - *

- * - * This is a component for displaying/modifying a gradient (palette). - * - *

- * Implementation details:
- * This implementation combines a {@link GradientBar} with two {@link MarkerBar} - * components. The marker bars are used to provide editing capabilities to the - * gradient bar. Note, that this component doesn't provide direct - * color-selecting capabilitied but relies on other external components such as - * {@link JColorChooser}. - * - * @author Michael Baranov - * - */ -public class GradientEditor extends GradientBar { - - /** - * The name of a "colorSelectionModel" property. - */ - public static final String PROPERTY_COLOR_SELECTION_MODEL = "colorSelectionModel"; - - /** - * The name of a "alphaSelectionModel" property. - */ - public static final String PROPERTY_ALPHA_SELECTION_MODEL = "alphaSelectionModel"; - - /** - * The name of a "colorMutationModel" property. - */ - public static final String PROPERTY_COLOR_MUTATION_MODEL = "colorMutationModel"; - - /** - * The name of a "alphaMutationModel" property. - */ - public static final String PROPERTY_ALPHA_MUTATION_MODEL = "alphaMutationModel"; - - private static final String uiClassID = "microba.GradientEditorUI"; - - private ListSelectionModel colorSelectionModel = null; - - private ListSelectionModel alphaSelectionModel = null; - - private MarkerMutationModel colorMutationModel = null; - - private MarkerMutationModel alphaMutationModel = null; - - /** - * Constructor. - */ - public GradientEditor() { - super(); - DefaultGradientEditorModel defaultGradientEditorModel = new DefaultGradientEditorModel(); - dataModel = defaultGradientEditorModel; - colorSelectionModel = defaultGradientEditorModel; - colorMutationModel = defaultGradientEditorModel; - setFocusable(true); - updateUI(); - } - - @Override - public String getUIClassID() { - return uiClassID; - } - - /** - * Regturns the current color mutation model. - * - * @return current color mutation model - * @see #setColorMutationModel(MarkerMutationModel) - * @see MarkerMutationModel - */ - public MarkerMutationModel getColorMutationModel() { - return colorMutationModel; - } - - /** - * Replaces current color mutation model with given one. - * - * @param mutationModel - * new mutation model. May be null. - * @see #getColorMutationModel() - * @see MarkerMutationModel - */ - public void setColorMutationModel(MarkerMutationModel mutationModel) { - MarkerMutationModel oldMutationModel = this.colorMutationModel; - this.colorMutationModel = mutationModel; - firePropertyChange(PROPERTY_COLOR_MUTATION_MODEL, oldMutationModel, mutationModel); - } - - /** - * Returns current color selection model. - * - * @return current color selection model. - * @see #setColorSelectionModel(ListSelectionModel) - */ - public ListSelectionModel getColorSelectionModel() { - return colorSelectionModel; - } - - /** - * Replaces current color selection model with given one. This - * implementation uses - * {@link ListSelectionModel#getLeadSelectionIndex()} to - * determine selected marker. - * - * @param selectionModel - * new selection model. May be null. - * - * @see #getColorSelectionModel() - */ - public void setColorSelectionModel(ListSelectionModel selectionModel) { - ListSelectionModel oldSelectionModel = this.colorSelectionModel; - this.colorSelectionModel = selectionModel; - firePropertyChange(PROPERTY_COLOR_SELECTION_MODEL, oldSelectionModel, - selectionModel); - } - - /** - * Returns current alpha selection model. - * - * @return current alpha selection model. - * @see #setAlphaSelectionModel(ListSelectionModel) - */ - public ListSelectionModel getAlphaSelectionModel() { - return alphaSelectionModel; - } - - /** - * Replaces current alpha selection model with given one. This - * implementation uses - * {@link ListSelectionModel#getLeadSelectionIndex()} to - * determine selected marker. - * - * @param selectionModel - * new selection model. May be null. - * - * @see #getAlphaSelectionModel() - */ - public void setAlphaSelectionModel(ListSelectionModel selectionModel) { - this.alphaSelectionModel = selectionModel; - } - - /** - * Regturns the current alpha mutation model. - * - * @return current alpha mutation model - * @see #setAlphaMutationModel(MarkerMutationModel) - * @see MarkerMutationModel - */ - public MarkerMutationModel getAlphaMutationModel() { - return alphaMutationModel; - } - - /** - * Replaces current alpha mutation model with given one. - * - * @param mutationModel - * new mutation model. May be null. - * @see #getAlphaMutationModel() - * @see MarkerMutationModel - */ - public void setAlphaMutationModel(MarkerMutationModel mutationModel) { - this.alphaMutationModel = mutationModel; - } - -} diff --git a/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/GradientEditorLayout.java b/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/GradientEditorLayout.java deleted file mode 100644 index 4ff7592e0e8b..000000000000 --- a/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/GradientEditorLayout.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.michaelbaranov.microba.gradienteditor.ui; - -import com.michaelbaranov.microba.gradient.GradientBar; -import com.michaelbaranov.microba.gradienteditor.GradientEditor; -import com.michaelbaranov.microba.marker.MarkerBar; - -import javax.swing.*; -import java.awt.*; - -public class GradientEditorLayout implements LayoutManager { - - private final MarkerBar bar; - - private final GradientBar gradient; - - public GradientEditorLayout(MarkerBar bar, GradientBar gradient) { - this.bar = bar; - this.gradient = gradient; - } - - @Override - public void addLayoutComponent(String name, Component comp) { - } - - @Override - public void removeLayoutComponent(Component comp) { - } - - @Override - public Dimension preferredLayoutSize(Container parent) { - return parent.getPreferredSize(); - } - - @Override - public Dimension minimumLayoutSize(Container parent) { - return parent.getMinimumSize(); - } - - @Override - public void layoutContainer(Container parent) { - GradientEditor e = (GradientEditor) parent; - Insets i = parent.getInsets(); - int gap = bar.getMarkerSideGap(); - if (e.getOrientation() == SwingConstants.HORIZONTAL) { - bar.setBounds(i.left, i.top, parent.getWidth() - i.left - i.right, - bar.getPreferredSize().height); - gradient.setBounds(i.left + gap, bar.getBounds().y - + bar.getBounds().height, parent.getWidth() - i.left - - i.right - gap - gap, parent.getHeight() - i.top - - i.bottom - bar.getHeight()); - } else { - gradient.setBounds(i.left, i.top+gap, - gradient.getPreferredSize().width,parent.getHeight() - i.top - i.bottom-gap-gap); - bar.setBounds(gradient.getBounds().x+gradient.getBounds().width ,i.top, - bar.getPreferredSize().width,gradient.getBounds().height+gap+gap); - - } - } - -} diff --git a/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/GradientEditorUI.java b/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/GradientEditorUI.java deleted file mode 100644 index 44ed4f374c1f..000000000000 --- a/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/GradientEditorUI.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.michaelbaranov.microba.gradienteditor.ui; - -import javax.swing.plaf.ComponentUI; - -public class GradientEditorUI extends ComponentUI{ - -} diff --git a/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/basic/BasicGradientEditorUI.java b/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/basic/BasicGradientEditorUI.java deleted file mode 100644 index 6853aad838de..000000000000 --- a/libraries/microba/src/com/michaelbaranov/microba/gradienteditor/ui/basic/BasicGradientEditorUI.java +++ /dev/null @@ -1,172 +0,0 @@ -package com.michaelbaranov.microba.gradienteditor.ui.basic; - -import java.awt.Dimension; -import java.awt.FlowLayout; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; - -import javax.swing.JComponent; -import javax.swing.ListSelectionModel; -import javax.swing.SwingConstants; -import javax.swing.plaf.ComponentUI; - -import com.michaelbaranov.microba.common.BoundedTableModel; -import com.michaelbaranov.microba.gradient.GradientBar; -import com.michaelbaranov.microba.gradienteditor.GradientEditor; -import com.michaelbaranov.microba.gradienteditor.ui.GradientEditorLayout; -import com.michaelbaranov.microba.gradienteditor.ui.GradientEditorUI; -import com.michaelbaranov.microba.marker.MarkerBar; -import com.michaelbaranov.microba.marker.MarkerMutationModel; - -public class BasicGradientEditorUI extends GradientEditorUI { - - protected GradientBar gradientBar; - - protected MarkerBar colorBar; - - protected MarkerBar alphaBar; - - private GradientEditor gradient; - - private GradientEditorListener editorListener; - - public static ComponentUI createUI(JComponent c) { - return new BasicGradientEditorUI(); - } - - public void installUI(JComponent component) { - gradient = (GradientEditor) component; - editorListener = new GradientEditorListener(); - createAndConfigureSubcomponents(); - installSubcomponents(); - installListeners(); - gradient.revalidate(); - } - - public void uninstallUI(JComponent component) { - // JGradient gradient = (JGradient) component; - uninstallSubcomponents(); - uninstallListeners(); - } - - protected void installSubcomponents() { - gradient.setLayout(new GradientEditorLayout(colorBar, gradientBar)); - gradient.add(colorBar); - gradient.add(gradientBar); - } - - protected void uninstallSubcomponents() { - gradient.setLayout(new FlowLayout()); - gradient.remove(colorBar); - gradient.remove(gradientBar); - } - - private void installListeners() { - gradient.addPropertyChangeListener(editorListener); - } - - private void uninstallListeners() { - gradient.removePropertyChangeListener(editorListener); - } - - private void createAndConfigureSubcomponents() { - gradientBar = new GradientBar(gradient.getDataModel()); - gradientBar.setOrientation(gradient.getOrientation()); - gradientBar.setColorPositionColumn(gradient.getColorPositionColumn()); - gradientBar.setColorColumn(gradient.getColorColumn()); - - colorBar = new MarkerBar(gradient.getDataModel(), gradient - .getColorSelectionModel()); - colorBar.setOrientation(gradient.getOrientation()); - colorBar.setMutationModel(gradient.getColorMutationModel()); - colorBar.setPositionColumn(gradient.getColorPositionColumn()); - colorBar.setColorColumn(gradient.getColorColumn()); - - alphaBar = new MarkerBar(gradient.getDataModel(), gradient - .getColorSelectionModel()); - alphaBar.setOrientation(gradient.getOrientation()); - alphaBar.setMutationModel(gradient.getColorMutationModel()); - alphaBar.setPositionColumn(gradient.getColorPositionColumn()); - alphaBar.setColorColumn(gradient.getColorColumn()); - } - - class GradientEditorListener implements PropertyChangeListener { - - public void propertyChange(PropertyChangeEvent evt) { - if (GradientEditor.PROPERTY_DATA_MODEL - .equals(evt.getPropertyName())) { - gradientBar.setDataModel((BoundedTableModel) evt.getNewValue()); - colorBar.setDataModel((BoundedTableModel) evt.getNewValue()); - } - if (GradientEditor.PROPERTY_COLOR_SELECTION_MODEL.equals(evt - .getPropertyName())) { - colorBar.setSelectionModel((ListSelectionModel) evt - .getNewValue()); - } - if (GradientEditor.PROPERTY_COLOR_MUTATION_MODEL.equals(evt - .getPropertyName())) { - colorBar.setMutationModel((MarkerMutationModel) evt - .getNewValue()); - } - if (GradientEditor.PROPERTY_COLOR_POSITION_COLUMN.equals(evt - .getPropertyName())) { - colorBar.setPositionColumn(((Integer) evt.getNewValue()) - .intValue()); - gradientBar - .setColorPositionColumn(((Integer) evt.getNewValue()) - .intValue()); - } - if (GradientEditor.PROPERTY_COLOR_COLUMN.equals(evt - .getPropertyName())) { - gradientBar.setColorColumn(((Integer) evt.getNewValue()) - .intValue()); - colorBar.setColorColumn(((Integer) evt.getNewValue()) - .intValue()); - - } - if (GradientEditor.PROPERTY_ORIENTATION.equals(evt - .getPropertyName())) { - colorBar.setOrientation(((Integer) evt.getNewValue()) - .intValue()); - gradientBar.setOrientation(((Integer) evt.getNewValue()) - .intValue()); - } - if ("enabled".equals(evt.getPropertyName())) { - colorBar.setEnabled(((Boolean) evt.getNewValue()) - .booleanValue()); - gradientBar.setEnabled(((Boolean) evt.getNewValue()) - .booleanValue()); - } - - } - - } - - public Dimension getMinimumSize(JComponent c) { - GradientBar gradient = (GradientBar) c; - - Dimension minimumSize = gradientBar.getMinimumSize(); - Dimension minimumSize2 = colorBar.getMinimumSize(); - if (gradient.getOrientation() == SwingConstants.HORIZONTAL) - return new Dimension(Math - .max(minimumSize.width, minimumSize2.width), - minimumSize.height + minimumSize2.height); - else - return new Dimension(minimumSize.width + minimumSize2.width, Math - .max(minimumSize.height, minimumSize2.height)); - - } - - public Dimension getPreferredSize(JComponent c) { - Dimension preferredSize = gradientBar.getPreferredSize(); - Dimension preferredSize2 = colorBar.getPreferredSize(); - if (gradient.getOrientation() == SwingConstants.HORIZONTAL) - return new Dimension(Math.max(preferredSize.width, - preferredSize2.width), preferredSize.height - + preferredSize2.height); - else - return new Dimension(preferredSize.width + preferredSize2.width, - Math.max(preferredSize.height, preferredSize2.height)); - } - -}