Skip to content

Commit

Permalink
Removed the use of deprecated Java elements by the application code
Browse files Browse the repository at this point in the history
  • Loading branch information
hbitteur committed Jan 29, 2024
1 parent 07e7331 commit a152145
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 29 deletions.
5 changes: 2 additions & 3 deletions src/main/org/audiveris/omr/CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private void checkParams ()
if ((params.step != null) && (params.step != OmrStep.last())) {
String msg = "'-transcribe' option not compatible with '-step " + params.step
+ "' option";
throw new CmdLineException(parser, msg);
throw new CmdLineException(parser, new Throwable(msg));
}

params.step = OmrStep.last();
Expand All @@ -158,8 +158,7 @@ public List<CliTask> getCliTasks ()

// Task kind is fully determined by argument extension
params.arguments.stream().map(argument -> argument.toString().trim().replace('\\', '/'))
.filter(str -> (!str.isEmpty())).forEachOrdered(str ->
{
.filter(str -> (!str.isEmpty())).forEachOrdered(str -> {
final Path path = Paths.get(str);

if (str.endsWith(OMR.BOOK_EXTENSION)) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/org/audiveris/omr/classifier/ui/SampleMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public SampleMenu (Glyph glyph,
//-----------//
// addSample //
//-----------//
@SuppressWarnings("deprecation")
private void addSample (Shape shape)
{
// TODO: we need staff information (-> interline and pitch)
Expand Down Expand Up @@ -146,8 +147,7 @@ private class AssignMenu
extends JMenu
{

private final ActionListener listener = (ActionEvent e) ->
{
private final ActionListener listener = (ActionEvent e) -> {
final JMenuItem source = (JMenuItem) e.getSource();
final Shape shape = Shape.valueOf(source.getText());
addSample(shape);
Expand Down Expand Up @@ -190,8 +190,7 @@ private class SelectMenu

private void populate ()
{
ShapeSet.addAllShapes(sheet.getStub().getMusicFamily(), this, (ActionEvent e) ->
{
ShapeSet.addAllShapes(sheet.getStub().getMusicFamily(), this, (ActionEvent e) -> {
JMenuItem source = (JMenuItem) e.getSource();
Shape shape = Shape.valueOf(source.getText());
addSample(shape);
Expand Down
5 changes: 3 additions & 2 deletions src/main/org/audiveris/omr/score/ui/BookPdfOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.itextpdf.awt.PdfGraphics2D;
import com.itextpdf.text.Document;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfContentByte;
Expand Down Expand Up @@ -117,8 +118,8 @@ public void write (List<SheetStub> stubs,
document.newPage();
}

PdfContentByte cb = writer.getDirectContent();
Graphics2D g2 = cb.createGraphics(width, height);
final PdfContentByte cb = writer.getDirectContent();
final Graphics2D g2 = new PdfGraphics2D(cb, width, height);

// Scale: 1
g2.scale(1, 1);
Expand Down
1 change: 1 addition & 0 deletions src/main/org/audiveris/omr/sheet/stem/StemsStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ protected void doEpilog (Sheet sheet,
* @throws StepException if step got stopped
*/
@Override
@SuppressWarnings("deprecation")
protected Void doProlog (Sheet sheet)
throws StepException
{
Expand Down
4 changes: 2 additions & 2 deletions src/main/org/audiveris/omr/sig/inter/BeamGroupInter.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ private AbstractChordInter checkForSplit ()
Collections.sort(
questionableBeams,
(b1,
b2) ->
{
b2) -> {
final double y1 = LineUtil.yAtX(b1.getMedian(), tail.x);
final double tailDy1 = Math.abs(y1 - tail.y);
final double y2 = LineUtil.yAtX(b2.getMedian(), tail.x);
Expand Down Expand Up @@ -1072,6 +1071,7 @@ private static boolean checkBeamGroups (Measure measure)
* @param system the system to check for beam groups
*/
@Deprecated
@SuppressWarnings("deprecation")
public static void checkSystemForOldBeamGroup (SystemInfo system)
{
// Checking one beam is enough
Expand Down
6 changes: 4 additions & 2 deletions src/main/org/audiveris/omr/sig/ui/ChordListMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -905,13 +906,14 @@ public void actionPerformed (ActionEvent e)
final AbstractChordInter src = chords.get(i);

for (AbstractChordInter tgt : chords.subList(i + 1, chords.size())) {
Relation rel = relationClass.newInstance();
Relation rel = relationClass.getDeclaredConstructor().newInstance();
strs.add(new SourceTargetRelation(src, tgt, rel));
}
}

sheet.getInterController().linkMultiple(sig, strs);
} catch (InstantiationException | IllegalAccessException ex) {
} catch (InstantiationException | IllegalAccessException //
| NoSuchMethodException | InvocationTargetException ex) {
logger.error("Could not instantiate class {}", relationClass, ex);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/audiveris/omr/ui/EntityAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected EntityAction (Collection<Action> entityActions,
item.setAccelerator(
KeyStroke.getKeyStroke(
key.charAt(0),
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
Toolkit.getDefaultToolkit().getMenuShortcutKeyMaskEx()));
}

// Add an icon in the Tool bar?
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/audiveris/omr/ui/MacApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static boolean setupMacMenus ()
try {
//The class used to register hooks
Class<?> appClass = Class.forName("com.apple.eawt.Application");
Object app = appClass.newInstance();
Object app = appClass.getDeclaredConstructor().newInstance();

//Enable the about menu item and the preferences menu item
for (String methodName : new String[]
Expand Down
13 changes: 8 additions & 5 deletions src/main/org/audiveris/omr/ui/action/ActionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ private ApplicationAction registerAction (ActionDescriptor desc)

if (instance == null) {
// Fall back to allocate a new class instance
instance = classe.newInstance();
instance = classe.getDeclaredConstructor().newInstance();
}

// Retrieve the action instance
Expand All @@ -252,7 +252,8 @@ private ApplicationAction registerAction (ActionDescriptor desc)
// Insertion of a button on Tool Bar?
if (desc.buttonClassName != null) {
Class buttonClass = classLoader.loadClass(desc.buttonClassName);
AbstractButton button = (AbstractButton) buttonClass.newInstance();
AbstractButton button = (AbstractButton) buttonClass.getDeclaredConstructor()
.newInstance();
button.setAction(action);
toolBar.add(button);
button.setBorder(UIUtil.getToolBorder());
Expand All @@ -262,7 +263,8 @@ private ApplicationAction registerAction (ActionDescriptor desc)
logger.error("Unknown action {} in class {}", desc.methodName, desc.className);
}
} catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException
| InstantiationException | SecurityException | InvocationTargetException ex) {
| InstantiationException | SecurityException | NoSuchMethodException
| InvocationTargetException ex) {
logger.warn("Error while registering " + desc, ex);
}

Expand Down Expand Up @@ -360,7 +362,7 @@ private void registerDomainActions (String domain,
itemClass = JMenuItem.class;
}

JMenuItem item = itemClass.newInstance();
JMenuItem item = itemClass.getDeclaredConstructor().newInstance();

// Inject menu item information
if (desc.methodName != null) {
Expand All @@ -381,7 +383,8 @@ private void registerDomainActions (String domain,
menu.add(item);
}
} catch (ClassNotFoundException | IllegalAccessException
| InstantiationException ex) {
| InstantiationException | NoSuchMethodException
| InvocationTargetException ex) {
logger.warn("Error with " + desc.itemClassName, ex);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/org/audiveris/omr/ui/treetable/JTreeTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public boolean isCellEditable (EventObject e)
tree,
me.getID(),
me.getWhen(),
me.getModifiers(),
me.getModifiersEx(),
me.getX() - getCellRect(0, counter, true).x,
me.getY(),
me.getClickCount(),
Expand Down
12 changes: 8 additions & 4 deletions src/main/org/audiveris/omr/ui/util/DynamicMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.InvocationTargetException;

import javax.swing.Action;
import javax.swing.JMenu;
import javax.swing.event.MenuEvent;
Expand Down Expand Up @@ -72,12 +74,13 @@ public DynamicMenu (Action action,
Class<? extends JMenu> menuClass)
{
try {
menu = menuClass.newInstance();
menu = menuClass.getDeclaredConstructor().newInstance();
menu.setAction(action);

// Listener to menu selection, to modify content on-the-fly
menu.addMenuListener(menuListener);
} catch (IllegalAccessException | InstantiationException ex) {
} catch (IllegalAccessException | InstantiationException //
| NoSuchMethodException | InvocationTargetException ex) {
logger.error("Could not instantiate " + menuClass, ex);
menu = null;
}
Expand All @@ -93,12 +96,13 @@ public DynamicMenu (String menuLabel,
Class<? extends JMenu> menuClass)
{
try {
menu = menuClass.newInstance();
menu = menuClass.getDeclaredConstructor().newInstance();
menu.setText(menuLabel);

// Listener to menu selection, to modify content on-the-fly
menu.addMenuListener(menuListener);
} catch (IllegalAccessException | InstantiationException ex) {
} catch (IllegalAccessException | InstantiationException //
| NoSuchMethodException | InvocationTargetException ex) {
logger.error("Could not instantiate " + menuClass, ex);
menu = null;
}
Expand Down
9 changes: 5 additions & 4 deletions src/main/org/audiveris/omr/ui/view/HistoryMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.slf4j.LoggerFactory;

import java.awt.event.ActionEvent;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Paths;

import javax.swing.JMenu;
Expand Down Expand Up @@ -89,13 +90,12 @@ public HistoryMenu (AbstractHistory history,
public void populate (JMenu menu,
Class<?> resourceClass)
{
history.feedMenu(menu, (ActionEvent e) ->
{
history.feedMenu(menu, (ActionEvent e) -> {
try {
final String str = e.getActionCommand().trim();

if (!str.isEmpty()) {
final PathTask task = pathTaskClass.newInstance();
final PathTask task = pathTaskClass.getDeclaredConstructor().newInstance();

if (pathTaskClass.isAssignableFrom(LoadBookTask.class)) {
((LoadBookTask) task).setPath(SheetPath.decode(str));
Expand All @@ -105,7 +105,8 @@ public void populate (JMenu menu,

task.execute();
}
} catch (IllegalAccessException | InstantiationException ex) {
} catch (IllegalAccessException | InstantiationException //
| NoSuchMethodException | InvocationTargetException ex) {
logger.warn("Error in HistoryMenu " + ex, ex);
}
});
Expand Down

0 comments on commit a152145

Please sign in to comment.