Skip to content

Commit

Permalink
Add a popup with Clear action on log display
Browse files Browse the repository at this point in the history
  • Loading branch information
hbitteur committed Aug 23, 2023
1 parent 1d81063 commit dd14028
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
46 changes: 46 additions & 0 deletions src/main/org/audiveris/omr/log/LogPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import org.audiveris.omr.constant.Constant;
import org.audiveris.omr.constant.ConstantSet;
import org.audiveris.omr.ui.util.SeparablePopupMenu;
import static org.audiveris.omr.ui.util.UIPredicates.isContextWanted;
import org.audiveris.omr.ui.util.UIUtil;

import org.slf4j.Logger;
Expand All @@ -33,9 +35,15 @@

import java.awt.Color;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Map;

import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
Expand Down Expand Up @@ -87,6 +95,8 @@ public LogPane ()
logArea.setMargin(new Insets(5, 5, 5, 5));
document = (AbstractDocument) logArea.getStyledDocument();

logArea.addMouseListener(new MyMouseAdapter());

// Let the scroll pane display the log area
component.setViewportView(logArea);
}
Expand Down Expand Up @@ -206,4 +216,40 @@ private static class Constants
"Lucida Console",
"Font name for log pane");
}

//-------------//
// ClearAction //
//-------------//
private class ClearAction
extends AbstractAction
{
ClearAction ()
{
putValue(NAME, "Clear");
putValue(SHORT_DESCRIPTION, "Clear this display (the log file is not modified)");
}

@Override
public void actionPerformed (ActionEvent e)
{
clearLog();
}
}

//----------------//
// MyMouseAdapter //
//----------------//
private class MyMouseAdapter
extends MouseAdapter
{
@Override
public void mousePressed (MouseEvent e)
{
if (isContextWanted(e)) {
final JPopupMenu popup = new SeparablePopupMenu();
popup.add(new JMenuItem(new ClearAction()));
popup.show(logArea, e.getX(), e.getY());
}
}
}
}
17 changes: 4 additions & 13 deletions src/main/org/audiveris/omr/ui/MainGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,13 @@ public class MainGui
/** The related concrete frame. */
private JFrame frame;

/** Bottom pane split between the logPane and the errorsPane. */
private JSplitPane bottomPane;

/** Log pane, which displays logging info. */
private LogPane logPane;

/** GlassPane needed to handle drag and drop from shape palette. */
private final OmrGlassPane glassPane = new OmrGlassPane();

/** Main pane with Sheet on top and Log+Errors on bottom. */
/** Main pane with Sheet on top and Log on bottom. */
private JSplitPane mainPane;

/** Step menu. */
Expand Down Expand Up @@ -177,7 +174,7 @@ private void defineLayout ()
// |i| | +===================================+=============+ | | |
// |n| +=====================================================+ | |
// |P+=========================================================+ |
// |a| bottomPane (logPane) | |
// |a| logPane | |
// |n| | |
// |e| | |
// | +=========================================================+ |
Expand All @@ -201,15 +198,9 @@ private void defineLayout ()
content.add(mainPane, BorderLayout.CENTER);
mainPane.addPropertyChangeListener(JSplitPane.DIVIDER_LOCATION_PROPERTY, this);

// Bottom = Log (other things removed)
// Bottom: Log
logPane = new LogPane();

bottomPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
bottomPane.setBorder(null);
bottomPane.setDividerSize(1);
bottomPane.setResizeWeight(0.5d); // Cut in half initially
bottomPane.setLeftComponent(logPane.getComponent());
mainPane.setBottomComponent(bottomPane);
mainPane.setBottomComponent(logPane.getComponent());
}

//-------------//
Expand Down

0 comments on commit dd14028

Please sign in to comment.