mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-10-22 21:21:02 +00:00
GP-4818 - Theming - Added a combo box renderer to do combo box things
This commit is contained in:
parent
1baf101d43
commit
5ef04e831c
|
@ -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.
|
||||
|
@ -23,7 +23,7 @@ import javax.swing.tree.TreePath;
|
|||
import docking.DialogComponentProvider;
|
||||
import docking.widgets.combobox.GhidraComboBox;
|
||||
import docking.widgets.label.GLabel;
|
||||
import docking.widgets.list.GListCellRenderer;
|
||||
import docking.widgets.list.GComboBoxCellRenderer;
|
||||
import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;
|
||||
import ghidra.app.plugin.core.datamgr.tree.ArchiveNode;
|
||||
import ghidra.app.plugin.core.datamgr.tree.DataTypeTreeNode;
|
||||
|
@ -68,8 +68,7 @@ public class CreateTypeDefDialog extends DialogComponentProvider {
|
|||
panel.add(nameTextField);
|
||||
|
||||
// data type info
|
||||
dataTypeEditor =
|
||||
new DataTypeSelectionEditor(plugin.getTool(), AllowedDataTypes.ALL);
|
||||
dataTypeEditor = new DataTypeSelectionEditor(plugin.getTool(), AllowedDataTypes.ALL);
|
||||
panel.add(new GLabel("Data type:"));
|
||||
panel.add(dataTypeEditor.getEditorComponent());
|
||||
|
||||
|
@ -88,8 +87,8 @@ public class CreateTypeDefDialog extends DialogComponentProvider {
|
|||
dataTypeEditor.setDefaultSelectedTreePath(selectedTreePath);
|
||||
|
||||
dataTypeManagerBox = new GhidraComboBox<>();
|
||||
dataTypeManagerBox.setRenderer(
|
||||
GListCellRenderer.createDefaultCellTextRenderer(dtm -> dtm.getName()));
|
||||
dataTypeManagerBox
|
||||
.setRenderer(GComboBoxCellRenderer.createDefaultTextRenderer(dtm -> dtm.getName()));
|
||||
|
||||
DataTypeManager[] dataTypeManagers = plugin.getDataTypeManagers();
|
||||
for (DataTypeManager manager : dataTypeManagers) {
|
||||
|
|
|
@ -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.
|
||||
|
@ -30,6 +30,7 @@ import docking.action.MenuData;
|
|||
import docking.widgets.OptionDialog;
|
||||
import docking.widgets.combobox.GhidraComboBox;
|
||||
import docking.widgets.label.GLabel;
|
||||
import docking.widgets.list.GComboBoxCellRenderer;
|
||||
import docking.widgets.tree.GTreeNode;
|
||||
import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;
|
||||
import ghidra.app.plugin.core.datamgr.DataTypesActionContext;
|
||||
|
@ -203,15 +204,15 @@ public class AssociateDataTypeAction extends DockingAction {
|
|||
|
||||
private JComponent buildWorkPanel() {
|
||||
|
||||
archivesBox.setRenderer(new DefaultListCellRenderer() {
|
||||
archivesBox.setRenderer(new GComboBoxCellRenderer<>() {
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value,
|
||||
int index, boolean isSelected, boolean cellHasFocus) {
|
||||
public Component getListCellRendererComponent(JList<? extends Archive> list,
|
||||
Archive value, int index, boolean isSelected, boolean cellHasFocus) {
|
||||
|
||||
JLabel renderer = (JLabel) super.getListCellRendererComponent(list, value,
|
||||
index, isSelected, cellHasFocus);
|
||||
Archive a = (Archive) value;
|
||||
Archive a = value;
|
||||
renderer.setText(a.getName());
|
||||
return renderer;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -33,6 +33,7 @@ import docking.DialogComponentProvider;
|
|||
import docking.widgets.checkbox.GCheckBox;
|
||||
import docking.widgets.combobox.GhidraComboBox;
|
||||
import docking.widgets.label.*;
|
||||
import docking.widgets.list.GComboBoxCellRenderer;
|
||||
import docking.widgets.list.GListCellRenderer;
|
||||
import docking.widgets.spinner.IntegerSpinner;
|
||||
import docking.widgets.table.threaded.ThreadedTableModelListener;
|
||||
|
@ -664,7 +665,7 @@ public class EncodedStringsDialog extends DialogComponentProvider {
|
|||
translateComboBox.setSelectedItem(defaultSTS);
|
||||
}
|
||||
|
||||
translateComboBox.setRenderer(GListCellRenderer.createDefaultCellTextRenderer(
|
||||
translateComboBox.setRenderer(GComboBoxCellRenderer.createDefaultTextRenderer(
|
||||
sts -> sts != null ? sts.getTranslationServiceName() : ""));
|
||||
}
|
||||
|
||||
|
@ -1153,7 +1154,7 @@ public class EncodedStringsDialog extends DialogComponentProvider {
|
|||
return "%s%s (%d)".formatted(name, example, count);
|
||||
};
|
||||
|
||||
setRenderer(GListCellRenderer.createDefaultCellTextRenderer(cellToTextMappingFunction));
|
||||
setRenderer(GListCellRenderer.createDefaultTextRenderer(cellToTextMappingFunction));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -38,7 +38,7 @@ import docking.widgets.button.BrowseButton;
|
|||
import docking.widgets.combobox.GhidraComboBox;
|
||||
import docking.widgets.dialogs.MultiLineMessageDialog;
|
||||
import docking.widgets.label.GLabel;
|
||||
import docking.widgets.list.GListCellRenderer;
|
||||
import docking.widgets.list.GComboBoxCellRenderer;
|
||||
import generic.theme.GIcon;
|
||||
import generic.theme.Gui;
|
||||
import ghidra.app.services.ProgramManager;
|
||||
|
@ -259,7 +259,7 @@ public class ImporterDialog extends DialogComponentProvider {
|
|||
loaderComboBox.addItemListener(e -> selectedLoaderChanged());
|
||||
loaderComboBox.setEnterKeyForwarding(true);
|
||||
loaderComboBox.setRenderer(
|
||||
GListCellRenderer.createDefaultCellTextRenderer(loader -> loader.getName()));
|
||||
GComboBoxCellRenderer.createDefaultTextRenderer(loader -> loader.getName()));
|
||||
|
||||
if (!orderedLoaders.isEmpty()) {
|
||||
loaderComboBox.setSelectedIndex(0);
|
||||
|
@ -572,8 +572,8 @@ public class ImporterDialog extends DialogComponentProvider {
|
|||
}
|
||||
|
||||
private void chooseProjectFolder() {
|
||||
DataTreeDialog dataTreeDialog = new DataTreeDialog(getComponent(),
|
||||
"Choose a project folder", CHOOSE_FOLDER);
|
||||
DataTreeDialog dataTreeDialog =
|
||||
new DataTreeDialog(getComponent(), "Choose a project folder", CHOOSE_FOLDER);
|
||||
dataTreeDialog.setSelectedFolder(destinationFolder);
|
||||
dataTreeDialog.showComponent();
|
||||
DomainFolder folder = dataTreeDialog.getDomainFolder();
|
||||
|
|
|
@ -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.
|
||||
|
@ -23,6 +23,7 @@ import java.awt.event.ItemListener;
|
|||
|
||||
import javax.swing.*;
|
||||
|
||||
import docking.widgets.list.GComboBoxCellRenderer;
|
||||
import ghidra.features.base.codecompare.model.FunctionComparisonModel;
|
||||
import ghidra.features.base.codecompare.model.FunctionComparisonModelListener;
|
||||
import ghidra.features.base.codecompare.panel.CodeComparisonPanel;
|
||||
|
@ -209,7 +210,7 @@ public class MultiFunctionComparisonPanel extends FunctionComparisonPanel
|
|||
* Cell renderer for combo boxes that changes the default display to show
|
||||
* both the function name and the program it comes from
|
||||
*/
|
||||
private class FunctionListCellRenderer extends DefaultListCellRenderer {
|
||||
private class FunctionListCellRenderer extends GComboBoxCellRenderer<Object> {
|
||||
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
|
||||
|
|
|
@ -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.
|
||||
|
@ -216,7 +216,7 @@ public class ThemeIconTableModel extends GDynamicColumnTableModel<IconValue, Obj
|
|||
private class ThemeIconRenderer extends AbstractGColumnRenderer<ResolvedIcon> {
|
||||
|
||||
public ThemeIconRenderer() {
|
||||
setBaseFontId("font.monospaced");
|
||||
setFont(getFixedWidthFont());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -273,5 +273,5 @@ public class ThemeIconTableModel extends GDynamicColumnTableModel<IconValue, Obj
|
|||
}
|
||||
|
||||
private record ResolvedIcon(String id, String refId, Icon icon) {
|
||||
/**/}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -61,8 +61,8 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
return !Boolean.getBoolean(DISABLE_ALTERNATING_ROW_COLORS_PROPERTY);
|
||||
}
|
||||
|
||||
protected final Border focusBorder;
|
||||
protected final Border noFocusBorder;
|
||||
protected Border focusBorder;
|
||||
protected Border noFocusBorder;
|
||||
protected Font defaultFont;
|
||||
protected Font fixedWidthFont;
|
||||
protected Font boldFont;
|
||||
|
@ -141,6 +141,8 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
boldFont = f.deriveFont(Font.BOLD);
|
||||
italicFont = f.deriveFont(Font.ITALIC);
|
||||
|
||||
// Gui does not allow registering the same component multiple times, so unregister first
|
||||
Gui.unRegisterFont(this, fontId);
|
||||
Gui.registerFont(this, fontId);
|
||||
}
|
||||
|
||||
|
@ -151,7 +153,7 @@ public abstract class AbstractGCellRenderer extends GDHtmlLabel {
|
|||
checkForInvalidSetFont(f);
|
||||
}
|
||||
|
||||
private void checkForInvalidSetFont(Font f) {
|
||||
protected void checkForInvalidSetFont(Font f) {
|
||||
//
|
||||
// Due to the nature of how setFont() is typically used (external client setup vs internal
|
||||
// rendering), we created setBaseFontId() to allow external clients to set the base font in
|
||||
|
|
|
@ -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.
|
||||
|
@ -31,7 +31,7 @@ public class DefaultDropDownSelectionDataModel<T> implements DropDownTextFieldDa
|
|||
private DataToStringConverter<T> searchConverter;
|
||||
private DataToStringConverter<T> descriptionConverter;
|
||||
private ListCellRenderer<T> renderer =
|
||||
GListCellRenderer.createDefaultCellTextRenderer(value -> searchConverter.getString(value));
|
||||
GListCellRenderer.createDefaultTextRenderer(value -> searchConverter.getString(value));
|
||||
|
||||
public static DefaultDropDownSelectionDataModel<String> getStringModel(List<String> strings) {
|
||||
return new DefaultDropDownSelectionDataModel<>(strings,
|
||||
|
|
|
@ -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.
|
||||
|
@ -393,7 +393,7 @@ public class GhidraFileChooser extends ReusableDialogComponentProvider implement
|
|||
|
||||
JLabel filterLabel = new GLabel("Type:");
|
||||
filterCombo = new GComboBox<>();
|
||||
filterCombo.setRenderer(GListCellRenderer.createDefaultCellTextRenderer(
|
||||
filterCombo.setRenderer(GListCellRenderer.createDefaultTextRenderer(
|
||||
fileFilter -> fileFilter != null ? fileFilter.getDescription() : ""));
|
||||
filterModel = (DefaultComboBoxModel<GhidraFileFilter>) filterCombo.getModel();
|
||||
addFileFilter(GhidraFileFilter.ALL);
|
||||
|
|
|
@ -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.
|
||||
|
@ -30,7 +30,7 @@ import docking.widgets.checkbox.GCheckBox;
|
|||
import docking.widgets.combobox.GComboBox;
|
||||
import docking.widgets.label.GIconLabel;
|
||||
import docking.widgets.label.GLabel;
|
||||
import docking.widgets.list.GListCellRenderer;
|
||||
import docking.widgets.list.GComboBoxCellRenderer;
|
||||
import ghidra.util.HelpLocation;
|
||||
import ghidra.util.layout.*;
|
||||
|
||||
|
@ -268,8 +268,8 @@ public class FilterOptionsEditorDialog extends DialogComponentProvider {
|
|||
}
|
||||
|
||||
globbingCheckbox = new GCheckBox("Allow Globbing");
|
||||
globbingCheckbox.setToolTipText(
|
||||
"Toggles whether globbing chars (?*) are literal or wildcards");
|
||||
globbingCheckbox
|
||||
.setToolTipText("Toggles whether globbing chars (?*) are literal or wildcards");
|
||||
if (initialFilterOptions.isGlobbingAllowed()) {
|
||||
globbingCheckbox.setSelected(true);
|
||||
}
|
||||
|
@ -331,9 +331,9 @@ public class FilterOptionsEditorDialog extends DialogComponentProvider {
|
|||
setBorder(BorderFactory.createEmptyBorder(5, 4, 10, 4));
|
||||
|
||||
pathCheckbox = new GCheckBox("Use Path");
|
||||
pathCheckbox.setToolTipText("<html>" +
|
||||
"Allows filtering on node paths, for example '*/folder/node' or " +
|
||||
"'*folder1*folder2*node'");
|
||||
pathCheckbox.setToolTipText(
|
||||
"<html>" + "Allows filtering on node paths, for example '*/folder/node' or " +
|
||||
"'*folder1*folder2*node'");
|
||||
if (initialFilterOptions.shouldUsePath()) {
|
||||
pathCheckbox.setSelected(true);
|
||||
}
|
||||
|
@ -456,8 +456,8 @@ public class FilterOptionsEditorDialog extends DialogComponentProvider {
|
|||
|
||||
// Delimiter Row
|
||||
JLabel delimiterCharacterFieldName = new GLabel("Delimiter:");
|
||||
delimiterCharacterFieldName.setToolTipText(
|
||||
"Set the character used to separate filter terms.");
|
||||
delimiterCharacterFieldName
|
||||
.setToolTipText("Set the character used to separate filter terms.");
|
||||
|
||||
delimiterCharacterCB = new GComboBox<>(FilterOptions.VALID_MULTITERM_DELIMITERS_ARRAY);
|
||||
delimiterCharacterCB.setRenderer(new DelimiterListCellRenderer());
|
||||
|
@ -499,7 +499,7 @@ public class FilterOptionsEditorDialog extends DialogComponentProvider {
|
|||
add(optionsPaneDisableLayer);
|
||||
}
|
||||
|
||||
private class DelimiterListCellRenderer extends GListCellRenderer<String> {
|
||||
private class DelimiterListCellRenderer extends GComboBoxCellRenderer<String> {
|
||||
|
||||
public DelimiterListCellRenderer() {
|
||||
setHTMLRenderingEnabled(true);
|
||||
|
|
|
@ -0,0 +1,77 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
*
|
||||
* 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.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package docking.widgets.list;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import java.util.function.Function;
|
||||
|
||||
import generic.theme.*;
|
||||
|
||||
/**
|
||||
* Provides a common implementation of a combo box drop-down list renderer, for use with
|
||||
* JComboBoxes.
|
||||
* <p>
|
||||
* HTML rendering defaults to disabled. See {@link #setHTMLRenderingEnabled(boolean)}.
|
||||
*
|
||||
* @param <E> the element-type this list models.
|
||||
*/
|
||||
public class GComboBoxCellRenderer<E> extends GListCellRenderer<E> {
|
||||
|
||||
private static final Color COMBO_BOX_BACKGROUND_COLOR = new GColor("color.bg.combobox.row");
|
||||
|
||||
/**
|
||||
* Returns a new GComboBoxCellRenderer that maps the list's data instance to a string used in
|
||||
* the cell.
|
||||
* <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 GComboBoxCellRenderer instance
|
||||
*/
|
||||
public static <E> GComboBoxCellRenderer<E> createDefaultTextRenderer(
|
||||
Function<E, String> cellToTextMappingFunction) {
|
||||
return new GComboBoxCellRenderer<>() {
|
||||
@Override
|
||||
protected String getItemText(E value) {
|
||||
return cellToTextMappingFunction.apply(value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// overridden to return the combo box-specific background color
|
||||
@Override
|
||||
protected Color getDefaultBackgroundColor() {
|
||||
return COMBO_BOX_BACKGROUND_COLOR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkForInvalidSetFont(Font f) {
|
||||
|
||||
//
|
||||
// The Metal LaF will use the combo's renderer to paint the contents when it is not
|
||||
// editable. (It uses the cell editor when it is editable.) The UI in this case will call
|
||||
// renderer.setFont(comboBox.getFont()) before painting. We don't want to generate font
|
||||
// warnings when this is the case, since we have no control over that behavior.
|
||||
//
|
||||
if (ThemeManager.getInstance().getLookAndFeelType() == LafType.METAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.checkForInvalidSetFont(f);
|
||||
}
|
||||
}
|
|
@ -15,12 +15,15 @@
|
|||
*/
|
||||
package docking.widgets.list;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
|
||||
import docking.widgets.AbstractGCellRenderer;
|
||||
import generic.theme.GColor;
|
||||
import generic.theme.GThemeDefaults.Colors.Palette;
|
||||
|
||||
/**
|
||||
|
@ -32,6 +35,8 @@ import generic.theme.GThemeDefaults.Colors.Palette;
|
|||
*/
|
||||
public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListCellRenderer<E> {
|
||||
|
||||
private static final Color LIST_BACKGROUND_COLOR = new GColor("color.bg.list.row");
|
||||
|
||||
/**
|
||||
* Returns a new ListCellRenderer that maps the list's data instance to a string used in the cell.
|
||||
* <p>
|
||||
|
@ -41,7 +46,7 @@ public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListC
|
|||
* @param cellToTextMappingFunction a function that maps your custom type to a string value
|
||||
* @return new GListCellRenderer instance
|
||||
*/
|
||||
public static <E> GListCellRenderer<E> createDefaultCellTextRenderer(
|
||||
public static <E> GListCellRenderer<E> createDefaultTextRenderer(
|
||||
Function<E, String> cellToTextMappingFunction) {
|
||||
return new GListCellRenderer<>() {
|
||||
@Override
|
||||
|
@ -58,6 +63,26 @@ public class GListCellRenderer<E> extends AbstractGCellRenderer implements ListC
|
|||
|
||||
// lists don't need alternation for rows, as they don't use long columnar data
|
||||
setShouldAlternateRowBackgroundColors(false);
|
||||
|
||||
// Base our borders on those used by the list. ComboBoxes do not change the list borders in
|
||||
// the Look and Feel.
|
||||
noFocusBorder = getBorder("List.noFocusBorder");
|
||||
focusBorder = getBorder("List.focusCellHighlightBorder");
|
||||
}
|
||||
|
||||
private Border getBorder(String id) {
|
||||
Border border = UIManager.getBorder(id);
|
||||
if (border == null) {
|
||||
// A reasonable default value picked based on examining the existing LaFs
|
||||
border = BorderFactory.createEmptyBorder(2, 4, 2, 4);
|
||||
}
|
||||
return border;
|
||||
}
|
||||
|
||||
// overridden to return the list-specific background color
|
||||
@Override
|
||||
protected Color getDefaultBackgroundColor() {
|
||||
return LIST_BACKGROUND_COLOR;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
|
@ -25,7 +25,7 @@ import javax.swing.border.BevelBorder;
|
|||
import docking.widgets.EmptyBorderButton;
|
||||
import docking.widgets.combobox.GhidraComboBox;
|
||||
import docking.widgets.label.GDLabel;
|
||||
import docking.widgets.list.GListCellRenderer;
|
||||
import docking.widgets.list.GComboBoxCellRenderer;
|
||||
import generic.theme.GThemeDefaults.Colors.Messages;
|
||||
import ghidra.util.layout.VerticalLayout;
|
||||
import resources.Icons;
|
||||
|
@ -72,18 +72,11 @@ class ColumnFilterPanel extends JPanel {
|
|||
|
||||
DefaultComboBoxModel<ColumnFilterData<?>> model = new DefaultComboBoxModel<>(v);
|
||||
columnFilterComboBox = new GhidraComboBox<>(model);
|
||||
columnFilterComboBox.setRenderer(new GListCellRenderer<>() {
|
||||
|
||||
columnFilterComboBox.setRenderer(new GComboBoxCellRenderer<>() {
|
||||
@Override
|
||||
protected String getItemText(ColumnFilterData<?> value) {
|
||||
return value == null ? "" : value.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldAlternateRowBackgroundColor() {
|
||||
// alternating colors look odd in this combo box
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
columnFilterComboBox.setSelectedItem(filterEntry.getColumnFilterData());
|
||||
|
|
|
@ -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.
|
||||
|
@ -23,7 +23,7 @@ import javax.swing.*;
|
|||
|
||||
import docking.widgets.EmptyBorderButton;
|
||||
import docking.widgets.combobox.GComboBox;
|
||||
import docking.widgets.list.GListCellRenderer;
|
||||
import docking.widgets.list.GComboBoxCellRenderer;
|
||||
import docking.widgets.table.constraint.ColumnConstraint;
|
||||
import resources.Icons;
|
||||
|
||||
|
@ -119,17 +119,11 @@ public class ConstraintFilterPanel extends JPanel {
|
|||
constraintComboBox.addActionListener(constraintComboBoxListener);
|
||||
}
|
||||
|
||||
private class ConstraintComboBoxCellRenderer extends GListCellRenderer<ColumnConstraint<?>> {
|
||||
|
||||
private class ConstraintComboBoxCellRenderer
|
||||
extends GComboBoxCellRenderer<ColumnConstraint<?>> {
|
||||
@Override
|
||||
protected String getItemText(ColumnConstraint<?> value) {
|
||||
return value.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldAlternateRowBackgroundColor() {
|
||||
// alternating colors look odd in this combo box
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -24,7 +24,7 @@ import javax.swing.JPanel;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import docking.widgets.combobox.GComboBox;
|
||||
import docking.widgets.list.GListCellRenderer;
|
||||
import docking.widgets.list.GComboBoxCellRenderer;
|
||||
import docking.widgets.table.constraint.BooleanMatchColumnConstraint;
|
||||
import docking.widgets.table.constraint.ColumnConstraint;
|
||||
|
||||
|
@ -48,8 +48,8 @@ public class BooleanConstraintEditor extends AbstractColumnConstraintEditor<Bool
|
|||
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
comboBox = new GComboBox<>(new Boolean[] { Boolean.TRUE, Boolean.FALSE });
|
||||
comboBox.setRenderer(GListCellRenderer.createDefaultCellTextRenderer(
|
||||
b -> StringUtils.capitalize(b.toString())));
|
||||
comboBox.setRenderer(GComboBoxCellRenderer
|
||||
.createDefaultTextRenderer(b -> StringUtils.capitalize(b.toString())));
|
||||
comboBox.addItemListener(e -> valueChanged());
|
||||
|
||||
panel.add(comboBox, BorderLayout.CENTER);
|
||||
|
|
|
@ -26,6 +26,10 @@ color.fg.table.uneditable.unselected = color.palette.lightgray
|
|||
color.fg.error.table.unselected = color.fg.error
|
||||
color.fg.error.table.selected = color.palette.lightpink
|
||||
|
||||
// allow list and combobox renderers to vary independently of tables, which some LaFs use
|
||||
color.bg.list.row = color.bg.table.row
|
||||
color.bg.combobox.row = color.bg.table.row
|
||||
|
||||
color.bg.tree = [color]system.color.bg.view
|
||||
color.bg.tree.drag = color.palette.lavender
|
||||
color.bg.tree.selected = [color]system.color.bg.selected.view
|
||||
|
@ -128,7 +132,10 @@ icon.make.selection = stack.png
|
|||
|
||||
|
||||
|
||||
[Metal]
|
||||
|
||||
// the Metal LaF overrides combo box rendering with this line: "ComboBox.background", control
|
||||
color.bg.combobox.row = [color]system.color.bg.control
|
||||
|
||||
[Flat Dark]
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
@ -370,6 +370,11 @@ public class ApplicationThemeManager extends ThemeManager {
|
|||
lookAndFeelManager.registerFont(component, fontId, fontStyle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unRegisterFont(JComponent component, String fontId) {
|
||||
lookAndFeelManager.unRegisterFont(component, fontId);
|
||||
}
|
||||
|
||||
private void installFlatLookAndFeels() {
|
||||
UIManager.installLookAndFeel(LafType.FLAT_LIGHT.getName(), FlatLightLaf.class.getName());
|
||||
UIManager.installLookAndFeel(LafType.FLAT_DARK.getName(), FlatDarkLaf.class.getName());
|
||||
|
|
|
@ -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.
|
||||
|
@ -190,6 +190,20 @@ public class Gui {
|
|||
themeManager.registerFont(component, fontId, fontStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the component and font id binding made in a previous call to
|
||||
* {@link #registerFont(Component, String)}.
|
||||
* <p>
|
||||
* Clients need to call this method if they decide to change the font id being used for a given
|
||||
* component. Must clients do not need to use this method.
|
||||
*
|
||||
* @param component the component to remove
|
||||
* @param fontId the id of the font previously registered
|
||||
*/
|
||||
public static void unRegisterFont(JComponent component, String fontId) {
|
||||
themeManager.unRegisterFont(component, fontId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the active theme is using dark defaults
|
||||
* @return true if the active theme is using dark defaults
|
||||
|
|
|
@ -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.
|
||||
|
@ -592,6 +592,16 @@ public abstract class ThemeManager {
|
|||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the component and font id binding made in a previous call to
|
||||
* {@link #registerFont(Component, String)}.
|
||||
* @param component the component to remove
|
||||
* @param fontId the id of the font previously registered
|
||||
*/
|
||||
public void unRegisterFont(JComponent component, String fontId) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current theme use dark default values.
|
||||
* @return true if the current theme use dark default values.
|
||||
|
|
|
@ -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.
|
||||
|
@ -17,6 +17,7 @@ package generic.theme.laf;
|
|||
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.util.Iterator;
|
||||
import java.util.Objects;
|
||||
|
||||
import generic.theme.Gui;
|
||||
|
@ -60,6 +61,21 @@ public class ComponentFontRegistry {
|
|||
components.add(sc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given component from this registry.
|
||||
* @param component the component
|
||||
*/
|
||||
public void removeComponent(Component component) {
|
||||
Iterator<StyledComponent> it = components.iterator();
|
||||
while (it.hasNext()) {
|
||||
StyledComponent sc = it.next();
|
||||
if (component == sc.component) {
|
||||
it.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the font for all components bound to this registry's font id.
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
|
@ -237,6 +237,21 @@ public abstract class LookAndFeelManager {
|
|||
register.addComponent(component, fontStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given component and id binding from this class.
|
||||
* @param component the component to remove
|
||||
* @param fontId the id used when originally registered
|
||||
* @see #registerFont(Component, String)
|
||||
*/
|
||||
public void unRegisterFont(JComponent component, String fontId) {
|
||||
componentToIdMap.remove(component);
|
||||
|
||||
ComponentFontRegistry registry = fontRegistryMap.get(fontId);
|
||||
if (registry != null) {
|
||||
registry.removeComponent(component);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForAlreadyRegistered(Component component, String newFontId) {
|
||||
String existingFontId = componentToIdMap.get(component);
|
||||
if (existingFontId != null) {
|
||||
|
@ -397,9 +412,7 @@ public abstract class LookAndFeelManager {
|
|||
UIDefaults defaults = UIManager.getDefaults();
|
||||
|
||||
Set<Entry<Object, Object>> set = defaults.entrySet();
|
||||
Iterator<Entry<Object, Object>> iterator = set.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<Object, Object> entry = iterator.next();
|
||||
for (Entry<Object, Object> entry : set) {
|
||||
Object key = entry.getKey();
|
||||
|
||||
if (key.toString().toLowerCase().indexOf("font") != -1) {
|
||||
|
@ -440,5 +453,4 @@ public abstract class LookAndFeelManager {
|
|||
}
|
||||
return colorKeys;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
@ -224,9 +224,9 @@ class ToolConnectionPanel extends JPanel implements ListSelectionListener {
|
|||
});
|
||||
eventList.setCellRenderer(new DataCellRenderer());
|
||||
producerList.setCellRenderer(
|
||||
GListCellRenderer.createDefaultCellTextRenderer(tool -> tool.getName()));
|
||||
GListCellRenderer.createDefaultTextRenderer(tool -> tool.getName()));
|
||||
consumerList.setCellRenderer(
|
||||
GListCellRenderer.createDefaultCellTextRenderer(tool -> tool.getName()));
|
||||
GListCellRenderer.createDefaultTextRenderer(tool -> tool.getName()));
|
||||
producerModel = (DefaultListModel<PluginTool>) producerList.getModel();
|
||||
consumerModel = (DefaultListModel<PluginTool>) consumerList.getModel();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user