[microba] IJPL-157402 Remove unused GradientEditor

GitOrigin-RevId: 00d57f081ff856fbdc70eae5ffcc93aa224dac03
This commit is contained in:
Konstantin Hudyakov
2024-07-04 12:06:08 +03:00
committed by intellij-monorepo-bot
parent c788902ef7
commit a57ad70c81
8 changed files with 1 additions and 553 deletions

View File

@@ -31,7 +31,6 @@ MarkerBar
* Flipped marks
GradientBar
GradientEditor
* Key-point based palette
* Linear color interpolation
* Horizontal/vertical alignment

View File

@@ -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);

View File

@@ -9,8 +9,7 @@ import java.beans.PropertyChangeListener;
* The upper and lower bound values are introduced to further describe table
* data. For example, <code>BoundedTableModel</code> is used as a data model
* for <code>{@link com.michaelbaranov.microba.marker.MarkerBar}</code>,
* <code>{@link com.michaelbaranov.microba.gradient.GradientBar}</code>,
* <code>{@link com.michaelbaranov.microba.gradienteditor.GradientEditor}</code>
* <code>{@link com.michaelbaranov.microba.gradient.GradientBar}</code>
*
* @version 0.1 (rev. 13 Aug 2005)
* @author Michael Baranov <a

View File

@@ -1,131 +0,0 @@
package com.michaelbaranov.microba.gradienteditor;
import com.michaelbaranov.microba.common.AbstractBoundedTableModelWithSelection;
import com.michaelbaranov.microba.marker.MarkerMutationModel;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
/**
* A basic implementation of {@link AbstractBoundedTableModelWithSelection} and
* {@link MarkerMutationModel}. Used by default by {@link GradientEditor} as a
* color model, color selection model and color mutation model.
*
* <p>
* 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<Integer> position = new ArrayList<>(32);
protected List<Color> 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);
}
}

View File

@@ -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.
* <p>
*
* This is a component for displaying/modifying a gradient (palette).
*
* <p>
* Implementation details: <br>
* 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 <code>null<code>.
* @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
* <code>{@link ListSelectionModel#getLeadSelectionIndex()}</code> to
* determine selected marker.
*
* @param selectionModel
* new selection model. May be <code>null<code>.
*
* @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
* <code>{@link ListSelectionModel#getLeadSelectionIndex()}</code> to
* determine selected marker.
*
* @param selectionModel
* new selection model. May be <code>null<code>.
*
* @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 <code>null<code>.
* @see #getAlphaMutationModel()
* @see MarkerMutationModel
*/
public void setAlphaMutationModel(MarkerMutationModel mutationModel) {
this.alphaMutationModel = mutationModel;
}
}

View File

@@ -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);
}
}
}

View File

@@ -1,7 +0,0 @@
package com.michaelbaranov.microba.gradienteditor.ui;
import javax.swing.plaf.ComponentUI;
public class GradientEditorUI extends ComponentUI{
}

View File

@@ -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));
}
}