diff --git a/AutoComplete/src/main/java/org/fife/ui/autocomplete/AutoCompleteDescWindow.java b/AutoComplete/src/main/java/org/fife/ui/autocomplete/AutoCompleteDescWindow.java index 71f6675..912c7ef 100644 --- a/AutoComplete/src/main/java/org/fife/ui/autocomplete/AutoCompleteDescWindow.java +++ b/AutoComplete/src/main/java/org/fife/ui/autocomplete/AutoCompleteDescWindow.java @@ -511,7 +511,47 @@ public void updateUI() { TipUtil.tweakTipEditorPane(descArea); scrollPane.setBackground(descArea.getBackground()); scrollPane.getViewport().setBackground(descArea.getBackground()); - ((JPanel)getContentPane()).setBorder(TipUtil.getToolTipBorder()); + ((JPanel) getContentPane()).setBorder(TipUtil.getToolTipBorder()); + + ComponentOrientation orientation = ac.getTextComponentOrientation(); + setArrowIcon(forwardAction, orientation.isLeftToRight(), "forward"); + setArrowIcon(backAction, orientation.isLeftToRight(), "back"); + } + + /** + * Sets the appropriate arrow icon for the specified navigation action based on + * the component orientation (Left-to-Right or Right-to-Left) and action type. + *
+ * This method first checks the {@link UIManager} for a custom icon registered under
+ * the semantic key. If absent, it loads the default icon resource from the classpath,
+ * caches it in the {@link UIManager} for future use, and assigns it to the action.
+ *
+ * @param action the menu or toolbar action to update with the icon
+ * @param ltr {@code true} if the component orientation is Left-to-Right; {@code false} for Right-to-Left
+ * @param type the type of navigation action, either {@code "back"} or {@code "forward"}
+ */
+ private static void setArrowIcon(Action action, boolean ltr, String type) {
+ // Determine the UIManager key based on action type and text direction
+ String key = "back".equals(type) ?
+ (ltr ? "autocomplete.descWindow.backIcon" : "autocomplete.descWindow.forwardIcon") :
+ (ltr ? "autocomplete.descWindow.forwardIcon" : "autocomplete.descWindow.backIcon");
+
+ Icon icon = UIManager.getIcon(key);
+
+ if (icon == null) {
+ // Fallback to default classpath resources if not defined in UIManager
+ String resourceName = key.endsWith("backIcon") ? "arrow_left.png" : "arrow_right.png";
+ URL url = AutoCompleteDescWindow.class.getResource(resourceName);
+
+ if (url != null) {
+ icon = new ImageIcon(url);
+ UIManager.put(key, icon);
+ } else {
+ throw new IllegalArgumentException("Icon resource not found on classpath: " + resourceName);
+ }
+ }
+
+ action.putValue(Action.SMALL_ICON, icon);
}
@@ -578,29 +618,23 @@ void setCompletion(Completion c, String anchor,
class ToolBarBackAction extends AbstractAction {
ToolBarBackAction(boolean ltr) {
- String img = "org/fife/ui/autocomplete/arrow_" +
- (ltr ? "left.png" : "right.png");
- ClassLoader cl = getClass().getClassLoader();
- Icon icon = new ImageIcon(cl.getResource(img));
- putValue(Action.SMALL_ICON, icon);
+ setArrowIcon(this, ltr, "back");
}
@Override
public void actionPerformed(ActionEvent e) {
- if (historyPos>0) {
+ if (historyPos > 0) {
HistoryEntry pair = history.get(--historyPos);
descArea.setText(pair.summary);
- if (pair.anchor!=null) {
+ if (pair.anchor != null) {
//System.out.println("Scrolling to: " + pair.anchor);
descArea.scrollToReference(pair.anchor);
- }
- else {
+ } else {
descArea.setCaretPosition(0);
}
setActionStates();
}
}
-
}
@@ -610,23 +644,18 @@ public void actionPerformed(ActionEvent e) {
class ToolBarForwardAction extends AbstractAction {
ToolBarForwardAction(boolean ltr) {
- String img = "org/fife/ui/autocomplete/arrow_" +
- (ltr ? "right.png" : "left.png");
- ClassLoader cl = getClass().getClassLoader();
- Icon icon = new ImageIcon(cl.getResource(img));
- putValue(Action.SMALL_ICON, icon);
+ setArrowIcon(this, ltr, "forward");
}
@Override
public void actionPerformed(ActionEvent e) {
- if (history!=null && historyPos