mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-04 06:05:10 +00:00
Fixed deprecation warnings on Locale constructor and editor viewToModel/modelToView
This commit is contained in:
@@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.gui;
|
||||
|
||||
import com.jpexs.decompiler.flash.configuration.Configuration;
|
||||
import com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTreeModel;
|
||||
import com.jpexs.decompiler.flash.gui.translator.Translator;
|
||||
import com.jpexs.decompiler.flash.treeitems.TreeItem;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
@@ -30,6 +31,7 @@ import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.SystemColor;
|
||||
import java.awt.TexturePaint;
|
||||
@@ -38,6 +40,8 @@ import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.geom.Point2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.VolatileImage;
|
||||
import java.io.IOException;
|
||||
@@ -48,6 +52,7 @@ import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -77,13 +82,16 @@ import javax.swing.UIDefaults;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.plaf.FontUIResource;
|
||||
import javax.swing.plaf.TextUI;
|
||||
import javax.swing.plaf.basic.BasicColorChooserUI;
|
||||
import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.DefaultTableColumnModel;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableModel;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import javax.swing.text.Position;
|
||||
import javax.swing.tree.TreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon;
|
||||
@@ -794,4 +802,123 @@ public class View {
|
||||
public static boolean isOceanic() {
|
||||
return SubstanceLookAndFeel.getCurrentSkin() instanceof OceanicSkin;
|
||||
}
|
||||
|
||||
/**
|
||||
* This calls JTextComponent.viewToModel2D on Java 9+ or viewToModel on Java 8.
|
||||
* @param editor
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
public static int textComponentViewToModel(JTextComponent editor, Point2D pt) {
|
||||
try {
|
||||
return (int)(Integer)JTextComponent.class.getDeclaredMethod("viewToModel2D", Point2D.class).invoke(editor, pt);
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex) {
|
||||
//method does not exist, we must be on Java8
|
||||
}
|
||||
|
||||
//Try older method
|
||||
Point p = new Point((int) Math.round(pt.getX()), (int) Math.round(pt.getY()));
|
||||
try {
|
||||
return (int)(Integer)JTextComponent.class.getDeclaredMethod("viewToModel", Point.class).invoke(editor, p);
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex) {
|
||||
Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This calls JTextComponent.viewToModel2D on Java 9+ or viewToModel on Java 8.
|
||||
* @param editor
|
||||
* @param pt
|
||||
* @return
|
||||
*/
|
||||
public static int textComponentViewToModel(JTextComponent editor, Point pt) {
|
||||
Point2D p2d = new Point2D.Double(pt.x, pt.y);
|
||||
return textComponentViewToModel(editor, p2d);
|
||||
}
|
||||
|
||||
/**
|
||||
* This calls JTextComponent.modelToView2D on Java 9+ or modelToView on Java 8.
|
||||
* @param editor
|
||||
* @param pos
|
||||
* @return
|
||||
* @throws javax.swing.text.BadLocationException
|
||||
*/
|
||||
public static Rectangle2D textComponentModelToView(JTextComponent editor, int pos) throws BadLocationException {
|
||||
try {
|
||||
return (Rectangle2D)JTextComponent.class.getDeclaredMethod("modelToView2D", int.class).invoke(editor, pos);
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex) {
|
||||
//method does not exist, we must be on Java8
|
||||
}
|
||||
|
||||
//Try older method
|
||||
try {
|
||||
return (Rectangle)JTextComponent.class.getDeclaredMethod("modelToView", int.class).invoke(editor, pos);
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex) {
|
||||
Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This calls TextUI.modelToView2D on Java 9+ or modelToView on Java 8.
|
||||
* @param textUi
|
||||
* @param t
|
||||
* @param pos
|
||||
* @param bias
|
||||
* @return
|
||||
* @throws javax.swing.text.BadLocationException
|
||||
*/
|
||||
public static Rectangle2D textUIModelToView(TextUI textUi, JTextComponent t, int pos, Position.Bias bias) throws BadLocationException {
|
||||
try {
|
||||
return (Rectangle2D) TextUI.class.getDeclaredMethod("modelToView2D", JTextComponent.class, int.class, Position.Bias.class).invoke(textUi, t, pos, bias);
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex) {
|
||||
//method does not exist, we must be on Java8
|
||||
}
|
||||
|
||||
//Try older method
|
||||
try {
|
||||
return (Rectangle) TextUI.class.getDeclaredMethod("modelToView", JTextComponent.class, int.class, Position.Bias.class).invoke(textUi, t, pos, bias);
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex) {
|
||||
Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates locale using Locale.of on Java19, using constructor on older Javas.
|
||||
* @param language
|
||||
* @param country
|
||||
* @return
|
||||
*/
|
||||
public static Locale createLocale(String language, String country) {
|
||||
try {
|
||||
return (Locale) Locale.class.getDeclaredMethod("of", String.class, String.class).invoke(null, language, country);
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex) {
|
||||
try {
|
||||
return Locale.class.getDeclaredConstructor(String.class, String.class).newInstance(language, country);
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex1) {
|
||||
Logger.getLogger(Translator.class.getName()).log(Level.SEVERE, null, ex1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates locale using Locale.of on Java19, using constructor on older Javas.
|
||||
* @param language
|
||||
* @return
|
||||
*/
|
||||
public static Locale createLocale(String language) {
|
||||
try {
|
||||
return (Locale) Locale.class.getDeclaredMethod("of", String.class).invoke(null, language);
|
||||
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException ex) {
|
||||
try {
|
||||
return Locale.class.getDeclaredConstructor(String.class).newInstance(language);
|
||||
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex1) {
|
||||
Logger.getLogger(Translator.class.getName()).log(Level.SEVERE, null, ex1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +274,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
|
||||
}
|
||||
|
||||
public int getMultinameUnderMouseCursor(Point pt, Reference<ABC> abcUsed) {
|
||||
return getMultinameAtPos(viewToModel(pt), abcUsed);
|
||||
return getMultinameAtPos(View.textComponentViewToModel(this, pt), abcUsed);
|
||||
}
|
||||
|
||||
public int getMultinameUnderCaret(Reference<ABC> abcUsed) {
|
||||
@@ -1039,7 +1039,7 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
|
||||
}
|
||||
|
||||
final Point point = new Point(e.getX(), e.getY());
|
||||
final int pos = abcPanel.decompiledTextArea.viewToModel(point);
|
||||
final int pos = View.textComponentViewToModel(abcPanel.decompiledTextArea,point);
|
||||
final String identifier = abcPanel.getMainPanel().getActionPanel().getStringUnderPosition(pos, abcPanel.decompiledTextArea);
|
||||
|
||||
if (identifier != null && !identifier.isEmpty()) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -222,8 +223,9 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Rectangle r = modelToView(pos);
|
||||
scrollRectToVisible(r);
|
||||
Rectangle2D r = com.jpexs.decompiler.flash.gui.View.textComponentModelToView(LineMarkedEditorPane.this, pos);
|
||||
Rectangle r2 = new Rectangle((int) r.getX(), (int) r.getY(), (int) r.getWidth(), (int) r.getHeight());
|
||||
scrollRectToVisible(r2);
|
||||
} catch (BadLocationException ex) {
|
||||
//ignore
|
||||
}
|
||||
@@ -245,8 +247,8 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Rectangle r = modelToView(pos);
|
||||
return new Point(r.x, r.y);
|
||||
Rectangle2D r = com.jpexs.decompiler.flash.gui.View.textComponentModelToView(this, pos);
|
||||
return new Point((int) r.getX(), (int) r.getY());
|
||||
} catch (BadLocationException ex) {
|
||||
return null;
|
||||
}
|
||||
@@ -354,12 +356,12 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
|
||||
SyntaxDocument sd = (SyntaxDocument) d;
|
||||
|
||||
//correction of token last character
|
||||
int pos = viewToModel(lastPos);
|
||||
Rectangle r;
|
||||
int pos = com.jpexs.decompiler.flash.gui.View.textComponentViewToModel(this, lastPos);
|
||||
Rectangle2D r;
|
||||
try {
|
||||
r = modelToView(pos);
|
||||
r = com.jpexs.decompiler.flash.gui.View.textComponentModelToView(this, pos);
|
||||
if (r != null) {
|
||||
if (lastPos.x < r.x) {
|
||||
if (lastPos.x < r.getX()) {
|
||||
pos--;
|
||||
}
|
||||
}
|
||||
@@ -519,20 +521,9 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
|
||||
Segment seg = new Segment();
|
||||
((SyntaxDocument) c.getDocument()).getText(offs0, offs1 - offs0, seg);
|
||||
|
||||
Rectangle r = mapper.modelToView(c, offs0, Position.Bias.Forward);
|
||||
Rectangle2D r = com.jpexs.decompiler.flash.gui.View.textUIModelToView(mapper, c, offs0, Position.Bias.Forward);
|
||||
FontMetrics fm = g.getFontMetrics();
|
||||
//int fh = fm.getHeight();
|
||||
fgStyle.drawText(seg, r.x, r.y + fm.getAscent(), g, null, offs0);
|
||||
/*for (int i = offs0; i < offs1; i++) {
|
||||
|
||||
Rectangle r = mapper.modelToView(c, i, Position.Bias.Forward);
|
||||
Rectangle r1 = mapper.modelToView(c, i + 1, Position.Bias.Forward);
|
||||
if (r1.y == r.y) {
|
||||
((SyntaxDocument) c.getDocument()).getText(i, 1, seg);
|
||||
fgStyle.drawText(seg, r.x, r.y, g, null, i);
|
||||
//g.drawLine(r.x, r.y + r.height - 3, r1.x, r.y + r.height - 3);
|
||||
}
|
||||
}*/
|
||||
fgStyle.drawText(seg, (int) r.getX(), (int) r.getY() + fm.getAscent(), g, null, offs0);
|
||||
|
||||
} catch (BadLocationException e) {
|
||||
// can't render
|
||||
@@ -599,10 +590,10 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan
|
||||
g.setColor(col);
|
||||
for (int i = offs0; i < offs1; i++) {
|
||||
|
||||
Rectangle r = mapper.modelToView(c, i, Position.Bias.Forward);
|
||||
Rectangle r1 = mapper.modelToView(c, i + 1, Position.Bias.Forward);
|
||||
if (r1.y == r.y) {
|
||||
g.drawLine(r.x, r.y + r.height - 3, r1.x, r.y + r.height - 3);
|
||||
Rectangle2D r = com.jpexs.decompiler.flash.gui.View.textUIModelToView(mapper, c, i, Position.Bias.Forward);
|
||||
Rectangle2D r1 = com.jpexs.decompiler.flash.gui.View.textUIModelToView(mapper, c, i + 1, Position.Bias.Forward);
|
||||
if (r1.getY() == r.getY()) {
|
||||
g.drawLine((int) r.getX(), (int) (r.getY() + r.getHeight() - 3), (int) r1.getX(), (int) (r.getY() + r.getHeight() - 3));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
@@ -1239,10 +1240,13 @@ public class Translator extends JFrame implements ItemListener {
|
||||
public String toString() {
|
||||
String[] parts = locale.split("_");
|
||||
Locale loc;
|
||||
if (parts.length == 2) {
|
||||
loc = new Locale(parts[0], parts[1]);
|
||||
|
||||
|
||||
|
||||
if (parts.length == 2) {
|
||||
loc = View.createLocale(parts[0], parts[1]);
|
||||
} else {
|
||||
loc = new Locale(parts[0]);
|
||||
loc = View.createLocale(parts[0]);
|
||||
}
|
||||
|
||||
String ret = loc.getDisplayName() + " [" + locale + "]";
|
||||
|
||||
Reference in New Issue
Block a user