mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GP-3684 - Fixed html rendering bug in comboboxes
This commit is contained in:
parent
5fe28ee208
commit
aa7cfa6705
2 changed files with 27 additions and 70 deletions
|
@ -21,6 +21,8 @@ import javax.swing.BorderFactory;
|
|||
import javax.swing.JComponent;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.plaf.UIResource;
|
||||
import javax.swing.plaf.basic.BasicHTML;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
|
||||
import docking.widgets.label.GDHtmlLabel;
|
||||
import generic.theme.GColor;
|
||||
|
@ -174,17 +176,13 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
return isSelected ? Tables.UNEDITABLE_SELECTED : Tables.UNEDITABLE_UNSELECTED;
|
||||
}
|
||||
|
||||
// ==================================================================================================
|
||||
//==================================================================================================
|
||||
// Methods overridden for performance reasons (see DefaultTableCellRenderer &
|
||||
// DefaultListCellRenderer)
|
||||
//==================================================================================================
|
||||
|
||||
/**
|
||||
* Overridden for performance reasons.
|
||||
* See the <a href="#override">Implementation Note</a>
|
||||
* for more information.
|
||||
*
|
||||
* @since 1.5
|
||||
* See {@link DefaultTableCellRenderer} class header javadoc for more info.
|
||||
*/
|
||||
@Override
|
||||
public void invalidate() {
|
||||
|
@ -196,9 +194,7 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overridden for performance reasons.
|
||||
* See the <a href="#override">Implementation Note</a>
|
||||
* for more information.
|
||||
* See {@link DefaultTableCellRenderer} class header javadoc for more info.
|
||||
*/
|
||||
@Override
|
||||
public void validate() {
|
||||
|
@ -206,9 +202,7 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overridden for performance reasons.
|
||||
* See the <a href="#override">Implementation Note</a>
|
||||
* for more information.
|
||||
* See {@link DefaultTableCellRenderer} class header javadoc for more info.
|
||||
*/
|
||||
@Override
|
||||
public void revalidate() {
|
||||
|
@ -216,9 +210,7 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overridden for performance reasons.
|
||||
* See the <a href="#override">Implementation Note</a>
|
||||
* for more information.
|
||||
* See {@link DefaultTableCellRenderer} class header javadoc for more info.
|
||||
*/
|
||||
@Override
|
||||
public void repaint(long tm, int x, int y, int width, int height) {
|
||||
|
@ -226,9 +218,7 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overridden for performance reasons.
|
||||
* See the <a href="#override">Implementation Note</a>
|
||||
* for more information.
|
||||
* See {@link DefaultTableCellRenderer} class header javadoc for more info.
|
||||
*/
|
||||
@Override
|
||||
public void repaint(Rectangle r) {
|
||||
|
@ -236,11 +226,7 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overridden for performance reasons.
|
||||
* See the <a href="#override">Implementation Note</a>
|
||||
* for more information.
|
||||
*
|
||||
* @since 1.5
|
||||
* See {@link DefaultTableCellRenderer} class header javadoc for more info.
|
||||
*/
|
||||
@Override
|
||||
public void repaint() {
|
||||
|
@ -248,26 +234,23 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overridden for performance reasons.
|
||||
* See the <a href="#override">Implementation Note</a>
|
||||
* for more information.
|
||||
* See {@link DefaultTableCellRenderer} class header javadoc for more info.
|
||||
*/
|
||||
@Override
|
||||
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
|
||||
if (propertyName.equals("text") || propertyName.equals("labelFor") ||
|
||||
propertyName.equals("displayedMnemonic") ||
|
||||
((propertyName.equals("font") || propertyName.equals("foreground")) &&
|
||||
oldValue != newValue &&
|
||||
getClientProperty(javax.swing.plaf.basic.BasicHTML.propertyKey) != null)) {
|
||||
|
||||
super.firePropertyChange(propertyName, oldValue, newValue);
|
||||
protected void firePropertyChange(String property, Object oldValue, Object newValue) {
|
||||
if (property.equals("text") || property.equals("labelFor") ||
|
||||
property.equals("displayedMnemonic") || property.equals("html")) {
|
||||
super.firePropertyChange(property, oldValue, newValue);
|
||||
}
|
||||
else if (getClientProperty(BasicHTML.propertyKey) != null) {
|
||||
if (property.equals("font") || property.equals("foreground")) {
|
||||
super.firePropertyChange(property, oldValue, newValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden for performance reasons.
|
||||
* See the <a href="#override">Implementation Note</a>
|
||||
* for more information.
|
||||
* See {@link DefaultTableCellRenderer} class header javadoc for more info.
|
||||
*/
|
||||
@Override
|
||||
public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
@ -15,8 +15,7 @@
|
|||
*/
|
||||
package docking.widgets.list;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.awt.Component;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.swing.*;
|
||||
|
@ -38,7 +37,7 @@ public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListC
|
|||
* <p>
|
||||
* Use this if you only need to provide a way to get the string value from the type being shown
|
||||
* in the list.
|
||||
*
|
||||
*
|
||||
* @param cellToTextMappingFunction a function that maps your custom type to a string value
|
||||
* @return new GListCellRenderer instance
|
||||
*/
|
||||
|
@ -75,6 +74,7 @@ public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListC
|
|||
boolean isSelected, boolean hasFocus) {
|
||||
|
||||
setText(getItemText(value));
|
||||
|
||||
setHorizontalAlignment(
|
||||
value instanceof Number ? SwingConstants.RIGHT : SwingConstants.LEFT);
|
||||
ListModel<? extends E> model = list.getModel();
|
||||
|
@ -83,14 +83,13 @@ public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListC
|
|||
if (isSelected) {
|
||||
setForeground(list.getSelectionForeground());
|
||||
setBackground(list.getSelectionBackground());
|
||||
setOpaque(true);
|
||||
}
|
||||
else {
|
||||
setForegroundColor(list, model, value);
|
||||
|
||||
JList.DropLocation dropLocation = list.getDropLocation();
|
||||
// @formatter:off
|
||||
boolean isDropRow = (dropLocation != null &&
|
||||
boolean isDropRow = (dropLocation != null &&
|
||||
dropLocation.isInsert() &&
|
||||
dropLocation.getIndex() == index);
|
||||
// @formatter:on
|
||||
|
@ -103,6 +102,7 @@ public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListC
|
|||
}
|
||||
|
||||
setBorder(hasFocus ? focusBorder : noFocusBorder);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -114,30 +114,4 @@ public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListC
|
|||
protected void configureFont(JList<? extends E> list, ListModel<? extends E> model, int index) {
|
||||
setFont(defaultFont);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the width, height necessary to display the largest element in this list.
|
||||
* <p>
|
||||
* Useful for setting a JList's fixed cell width and height to the actual necessary size.
|
||||
* <p>
|
||||
* NOTE: the items and the renderer must be in plain text mode, not HTML rendering mode.
|
||||
*
|
||||
* @param list the JList that uses this cell renderer
|
||||
* @param items the items to measure
|
||||
* @param minWidth the minimum width that can be returned
|
||||
* @param minHeight the minimum height that can be returned
|
||||
* @return a new Dimension containing a width and height value necessary to display the largest
|
||||
* element in the list
|
||||
*/
|
||||
public Dimension computePlainTextListCellDimensions(JList<? extends E> list, List<E> items,
|
||||
int minWidth, int minHeight) {
|
||||
configureFont(list, list.getModel(), 0);
|
||||
FontMetrics metrics = getFontMetrics(getFont());
|
||||
int maxWidth = minWidth;
|
||||
for (E item : items) {
|
||||
String text = getItemText(item).toString();
|
||||
maxWidth = Math.max(maxWidth, metrics.stringWidth(text));
|
||||
}
|
||||
return new Dimension(maxWidth, Math.max(metrics.getHeight(), minHeight));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue