Fix checkstyles
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package net.runelite.client.plugins.notes;
|
package net.runelite.client.plugins.notes;
|
||||||
|
|
||||||
class DeleteOnlyPageException extends RuntimeException {
|
class DeleteOnlyPageException extends RuntimeException
|
||||||
DeleteOnlyPageException() {
|
{
|
||||||
super("Cannot delete the only page");
|
DeleteOnlyPageException()
|
||||||
}
|
{
|
||||||
|
super("Cannot delete the only page");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,100 +24,123 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.notes;
|
package net.runelite.client.plugins.notes;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import java.awt.BorderLayout;
|
||||||
import net.runelite.client.ui.ColorScheme;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.FocusEvent;
|
||||||
import javax.swing.*;
|
import java.awt.event.FocusListener;
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
import javax.swing.text.Document;
|
import javax.swing.text.Document;
|
||||||
import javax.swing.undo.CannotUndoException;
|
import javax.swing.undo.CannotUndoException;
|
||||||
import javax.swing.undo.UndoManager;
|
import javax.swing.undo.UndoManager;
|
||||||
import java.awt.*;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import java.awt.event.ActionEvent;
|
import net.runelite.client.ui.ColorScheme;
|
||||||
import java.awt.event.FocusEvent;
|
|
||||||
import java.awt.event.FocusListener;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
class NoteTab extends JPanel {
|
class NoteTab extends JPanel
|
||||||
private final NotesManager manager;
|
{
|
||||||
private final JTextArea notesEditor = new JTextArea();
|
private final NotesManager manager;
|
||||||
private final UndoManager undoRedo = new UndoManager();
|
private final JTextArea notesEditor = new JTextArea();
|
||||||
|
private final UndoManager undoRedo = new UndoManager();
|
||||||
|
|
||||||
private int index;
|
private int index;
|
||||||
|
|
||||||
NoteTab(NotesManager mManager, int mIndex) {
|
NoteTab(NotesManager mManager, int mIndex)
|
||||||
manager = mManager;
|
{
|
||||||
index = mIndex;
|
manager = mManager;
|
||||||
|
index = mIndex;
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
||||||
|
|
||||||
notesEditor.setTabSize(2);
|
notesEditor.setTabSize(2);
|
||||||
notesEditor.setLineWrap(true);
|
notesEditor.setLineWrap(true);
|
||||||
notesEditor.setWrapStyleWord(true);
|
notesEditor.setWrapStyleWord(true);
|
||||||
|
|
||||||
notesEditor.setOpaque(false);
|
notesEditor.setOpaque(false);
|
||||||
|
|
||||||
notesEditor.setText(manager.getNotes().get(mIndex));
|
notesEditor.setText(manager.getNotes().get(mIndex));
|
||||||
|
|
||||||
// setting the limit to a 500 as UndoManager registers every key press,
|
// setting the limit to a 500 as UndoManager registers every key press,
|
||||||
// which means that be default we would be able to undo only a sentence.
|
// which means that be default we would be able to undo only a sentence.
|
||||||
// note: the default limit is 100
|
// note: the default limit is 100
|
||||||
undoRedo.setLimit(500);
|
undoRedo.setLimit(500);
|
||||||
notesEditor.getDocument().addUndoableEditListener(e -> undoRedo.addEdit(e.getEdit()));
|
notesEditor.getDocument().addUndoableEditListener(e -> undoRedo.addEdit(e.getEdit()));
|
||||||
|
|
||||||
notesEditor.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo");
|
notesEditor.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo");
|
||||||
notesEditor.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo");
|
notesEditor.getInputMap().put(KeyStroke.getKeyStroke("control Y"), "Redo");
|
||||||
|
|
||||||
notesEditor.getActionMap().put("Undo", new AbstractAction("Undo") {
|
notesEditor.getActionMap().put("Undo", new AbstractAction("Undo")
|
||||||
@Override
|
{
|
||||||
public void actionPerformed(ActionEvent e) {
|
@Override
|
||||||
try {
|
public void actionPerformed(ActionEvent e)
|
||||||
if (undoRedo.canUndo()) {
|
{
|
||||||
undoRedo.undo();
|
try
|
||||||
}
|
{
|
||||||
} catch (CannotUndoException ex) {
|
if (undoRedo.canUndo())
|
||||||
log.warn("Notes Document Unable To Undo: " + ex);
|
{
|
||||||
}
|
undoRedo.undo();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
catch (CannotUndoException ex)
|
||||||
|
{
|
||||||
|
log.warn("Notes Document Unable To Undo: " + ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
notesEditor.getActionMap().put("Redo", new AbstractAction("Redo") {
|
notesEditor.getActionMap().put("Redo", new AbstractAction("Redo")
|
||||||
@Override
|
{
|
||||||
public void actionPerformed(ActionEvent e) {
|
@Override
|
||||||
try {
|
public void actionPerformed(ActionEvent e)
|
||||||
if (undoRedo.canRedo()) {
|
{
|
||||||
undoRedo.redo();
|
try
|
||||||
}
|
{
|
||||||
} catch (CannotUndoException ex) {
|
if (undoRedo.canRedo())
|
||||||
log.warn("Notes Document Unable To Redo: " + ex);
|
{
|
||||||
}
|
undoRedo.redo();
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
catch (CannotUndoException ex)
|
||||||
|
{
|
||||||
|
log.warn("Notes Document Unable To Redo: " + ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
notesEditor.addFocusListener(new FocusListener() {
|
notesEditor.addFocusListener(new FocusListener()
|
||||||
@Override
|
{
|
||||||
public void focusGained(FocusEvent e) {
|
@Override
|
||||||
|
public void focusGained(FocusEvent e)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void focusLost(FocusEvent e) {
|
public void focusLost(FocusEvent e)
|
||||||
notesChanged(notesEditor.getDocument());
|
{
|
||||||
}
|
notesChanged(notesEditor.getDocument());
|
||||||
|
}
|
||||||
|
|
||||||
private void notesChanged(Document doc) {
|
private void notesChanged(Document doc)
|
||||||
try {
|
{
|
||||||
// get document text and save to config whenever editor is changed
|
try
|
||||||
String data = doc.getText(0, doc.getLength());
|
{
|
||||||
manager.updateNote(index, data);
|
// get document text and save to config whenever editor is changed
|
||||||
} catch (BadLocationException ex) {
|
String data = doc.getText(0, doc.getLength());
|
||||||
log.warn("Notes Document Bad Location: " + ex);
|
manager.updateNote(index, data);
|
||||||
}
|
}
|
||||||
}
|
catch (BadLocationException ex)
|
||||||
});
|
{
|
||||||
add(notesEditor, BorderLayout.CENTER);
|
log.warn("Notes Document Bad Location: " + ex);
|
||||||
setBorder(new EmptyBorder(10, 10, 10, 10));
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
add(notesEditor, BorderLayout.CENTER);
|
||||||
|
setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ import net.runelite.client.config.ConfigItem;
|
|||||||
@ConfigGroup("notes")
|
@ConfigGroup("notes")
|
||||||
public interface NotesConfig extends Config
|
public interface NotesConfig extends Config
|
||||||
{
|
{
|
||||||
String CONFIG_GROUP = "notes";
|
String CONFIG_GROUP = "notes";
|
||||||
String NOTES = "notes";
|
String NOTES = "notes";
|
||||||
|
|
||||||
int MAX_NOTES = 5;
|
int MAX_NOTES = 5;
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "notesData",
|
keyName = "notesData",
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ package net.runelite.client.plugins.notes;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import joptsimple.internal.Strings;
|
import joptsimple.internal.Strings;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -34,77 +38,84 @@ import net.runelite.client.eventbus.EventBus;
|
|||||||
import net.runelite.client.plugins.notes.events.PageAdded;
|
import net.runelite.client.plugins.notes.events.PageAdded;
|
||||||
import net.runelite.client.plugins.notes.events.PageDeleted;
|
import net.runelite.client.plugins.notes.events.PageDeleted;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class NotesManager {
|
public class NotesManager
|
||||||
@Inject
|
{
|
||||||
private ConfigManager configManager;
|
@Inject
|
||||||
|
private ConfigManager configManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private NotesConfig config;
|
private NotesConfig config;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private List<String> notes = new ArrayList<>();
|
private List<String> notes = new ArrayList<>();
|
||||||
|
|
||||||
void loadNotes() {
|
void loadNotes()
|
||||||
final String configJson = configManager.getConfiguration(NotesConfig.CONFIG_GROUP, NotesConfig.NOTES);
|
{
|
||||||
|
final String configJson = configManager.getConfiguration(NotesConfig.CONFIG_GROUP, NotesConfig.NOTES);
|
||||||
|
|
||||||
notes = null;
|
notes = null;
|
||||||
if (!Strings.isNullOrEmpty(configJson)) {
|
if (!Strings.isNullOrEmpty(configJson))
|
||||||
final Gson gson = new Gson();
|
{
|
||||||
notes = gson.fromJson(configJson, new TypeToken<ArrayList<String>>() {
|
final Gson gson = new Gson();
|
||||||
}.getType());
|
notes = gson.fromJson(configJson, new TypeToken<ArrayList<String>>()
|
||||||
}
|
{
|
||||||
|
}.getType());
|
||||||
|
}
|
||||||
|
|
||||||
if (notes == null) {
|
if (notes == null)
|
||||||
notes = new ArrayList<>();
|
{
|
||||||
}
|
notes = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
// migrate from legacy single tab notes
|
// migrate from legacy single tab notes
|
||||||
if (!config.notesData().isEmpty()) {
|
if (!config.notesData().isEmpty())
|
||||||
log.info("Adding tab for legacy note data");
|
{
|
||||||
notes.add(0, config.notesData());
|
log.info("Adding tab for legacy note data");
|
||||||
}
|
notes.add(0, config.notesData());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void updateNote(int index, String data) {
|
void updateNote(int index, String data)
|
||||||
notes.set(index, data);
|
{
|
||||||
save();
|
notes.set(index, data);
|
||||||
}
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
void save() {
|
void save()
|
||||||
final Gson gson = new Gson();
|
{
|
||||||
final String json = gson.toJson(notes);
|
final Gson gson = new Gson();
|
||||||
configManager.setConfiguration(NotesConfig.CONFIG_GROUP, NotesConfig.NOTES, json);
|
final String json = gson.toJson(notes);
|
||||||
|
configManager.setConfiguration(NotesConfig.CONFIG_GROUP, NotesConfig.NOTES, json);
|
||||||
|
|
||||||
// Remove legacy notes
|
// Remove legacy notes
|
||||||
if (!config.notesData().isEmpty()) {
|
if (!config.notesData().isEmpty())
|
||||||
log.info("Removing legacy note data");
|
{
|
||||||
config.notesData("");
|
log.info("Removing legacy note data");
|
||||||
}
|
config.notesData("");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void addPage() {
|
void addPage()
|
||||||
notes.add("");
|
{
|
||||||
eventBus.post(PageAdded.class, new PageAdded(notes.size() - 1));
|
notes.add("");
|
||||||
save();
|
eventBus.post(PageAdded.class, new PageAdded(notes.size() - 1));
|
||||||
}
|
save();
|
||||||
|
}
|
||||||
|
|
||||||
void deletePage(int index) {
|
void deletePage(int index)
|
||||||
if (notes.size() <= 1) {
|
{
|
||||||
throw new DeleteOnlyPageException();
|
if (notes.size() <= 1)
|
||||||
}
|
{
|
||||||
|
throw new DeleteOnlyPageException();
|
||||||
|
}
|
||||||
|
|
||||||
notes.remove(index);
|
notes.remove(index);
|
||||||
eventBus.post(PageDeleted.class, new PageDeleted(index));
|
eventBus.post(PageDeleted.class, new PageDeleted(index));
|
||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,24 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.plugins.notes;
|
package net.runelite.client.plugins.notes;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JMenuItem;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import static javax.swing.JOptionPane.ERROR_MESSAGE;
|
||||||
|
import static javax.swing.JOptionPane.YES_NO_OPTION;
|
||||||
|
import static javax.swing.JOptionPane.YES_OPTION;
|
||||||
|
import static javax.swing.JOptionPane.getRootFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.runelite.client.eventbus.EventBus;
|
import net.runelite.client.eventbus.EventBus;
|
||||||
import net.runelite.client.plugins.notes.events.PageAdded;
|
import net.runelite.client.plugins.notes.events.PageAdded;
|
||||||
@@ -36,134 +54,138 @@ import net.runelite.client.ui.components.materialtabs.MaterialTab;
|
|||||||
import net.runelite.client.ui.components.materialtabs.MaterialTabGroup;
|
import net.runelite.client.ui.components.materialtabs.MaterialTabGroup;
|
||||||
import net.runelite.client.util.ImageUtil;
|
import net.runelite.client.util.ImageUtil;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static javax.swing.JOptionPane.*;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Singleton
|
@Singleton
|
||||||
class NotesPanel extends PluginPanel {
|
class NotesPanel extends PluginPanel
|
||||||
@Inject
|
{
|
||||||
private NotesManager notesManager;
|
@Inject
|
||||||
|
private NotesManager notesManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
|
|
||||||
private final JPanel display = new JPanel();
|
private final JPanel display = new JPanel();
|
||||||
private final MaterialTabGroup tabGroup = new MaterialTabGroup(display);
|
private final MaterialTabGroup tabGroup = new MaterialTabGroup(display);
|
||||||
private final ImageIcon addIcon = new ImageIcon(ImageUtil.getResourceStreamFromClass(getClass(), "add_icon.png"));
|
private final ImageIcon addIcon = new ImageIcon(ImageUtil.getResourceStreamFromClass(getClass(), "add_icon.png"));
|
||||||
private MaterialTab addTab;
|
private MaterialTab addTab;
|
||||||
private List<MaterialTab> tabs = new ArrayList<>();
|
private List<MaterialTab> tabs = new ArrayList<>();
|
||||||
|
|
||||||
void init(final NotesConfig config) {
|
void init(final NotesConfig config)
|
||||||
eventBus.subscribe(PageAdded.class, this, this::onPageAdded);
|
{
|
||||||
eventBus.subscribe(PageDeleted.class, this, this::onPageDeleted);
|
eventBus.subscribe(PageAdded.class, this, this::onPageAdded);
|
||||||
|
eventBus.subscribe(PageDeleted.class, this, this::onPageDeleted);
|
||||||
|
|
||||||
// this may or may not qualify as a hack
|
// this may or may not qualify as a hack
|
||||||
// but this lets the editor pane expand to fill the whole parent panel
|
// but this lets the editor pane expand to fill the whole parent panel
|
||||||
getParent().setLayout(new BorderLayout());
|
getParent().setLayout(new BorderLayout());
|
||||||
getParent().add(this, BorderLayout.CENTER);
|
getParent().add(this, BorderLayout.CENTER);
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
setBackground(ColorScheme.DARK_GRAY_COLOR);
|
setBackground(ColorScheme.DARK_GRAY_COLOR);
|
||||||
|
|
||||||
tabGroup.setBorder(new EmptyBorder(0, 0, 10, 0));
|
tabGroup.setBorder(new EmptyBorder(0, 0, 10, 0));
|
||||||
|
|
||||||
buildAddTab();
|
buildAddTab();
|
||||||
|
|
||||||
add(tabGroup, BorderLayout.NORTH);
|
add(tabGroup, BorderLayout.NORTH);
|
||||||
add(display, BorderLayout.CENTER);
|
add(display, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildAddTab() {
|
private void buildAddTab()
|
||||||
addTab = new MaterialTab(addIcon, tabGroup, new JPanel());
|
{
|
||||||
addTab.setOnSelectEvent(() -> {
|
addTab = new MaterialTab(addIcon, tabGroup, new JPanel());
|
||||||
notesManager.addPage();
|
addTab.setOnSelectEvent(() -> {
|
||||||
return false;
|
notesManager.addPage();
|
||||||
});
|
return false;
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void rebuild() {
|
void rebuild()
|
||||||
tabs = new LinkedList<>();
|
{
|
||||||
tabGroup.removeAll();
|
tabs = new LinkedList<>();
|
||||||
|
tabGroup.removeAll();
|
||||||
|
|
||||||
int totalNotes = notesManager.getNotes().size();
|
int totalNotes = notesManager.getNotes().size();
|
||||||
|
|
||||||
for (int i = 0; i < totalNotes; i++) {
|
for (int i = 0; i < totalNotes; i++)
|
||||||
MaterialTab tab = buildTab(i);
|
{
|
||||||
tabs.add(tab);
|
MaterialTab tab = buildTab(i);
|
||||||
tabGroup.addTab(tab);
|
tabs.add(tab);
|
||||||
}
|
tabGroup.addTab(tab);
|
||||||
|
}
|
||||||
|
|
||||||
if (totalNotes < NotesConfig.MAX_NOTES) {
|
if (totalNotes < NotesConfig.MAX_NOTES)
|
||||||
tabGroup.addTab(addTab);
|
{
|
||||||
}
|
tabGroup.addTab(addTab);
|
||||||
|
}
|
||||||
|
|
||||||
if (tabs.size() > 0) {
|
if (tabs.size() > 0)
|
||||||
// select the first tab
|
{
|
||||||
tabGroup.select(tabGroup.getTab(0));
|
// select the first tab
|
||||||
}
|
tabGroup.select(tabGroup.getTab(0));
|
||||||
|
}
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPageAdded(PageAdded e) {
|
private void onPageAdded(PageAdded e)
|
||||||
MaterialTab tab = buildTab(e.getIndex());
|
{
|
||||||
tabs.add(tab);
|
MaterialTab tab = buildTab(e.getIndex());
|
||||||
tabGroup.addTab(tab);
|
tabs.add(tab);
|
||||||
|
tabGroup.addTab(tab);
|
||||||
|
|
||||||
// re-add add button to make it last
|
// re-add add button to make it last
|
||||||
tabGroup.removeTab(addTab);
|
tabGroup.removeTab(addTab);
|
||||||
if (notesManager.getNotes().size() < NotesConfig.MAX_NOTES) {
|
if (notesManager.getNotes().size() < NotesConfig.MAX_NOTES)
|
||||||
tabGroup.addTab(addTab);
|
{
|
||||||
}
|
tabGroup.addTab(addTab);
|
||||||
|
}
|
||||||
|
|
||||||
revalidate();
|
revalidate();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPageDeleted(PageDeleted e) {
|
private void onPageDeleted(PageDeleted e)
|
||||||
rebuild();
|
{
|
||||||
}
|
rebuild();
|
||||||
|
}
|
||||||
|
|
||||||
private MaterialTab buildTab(int index) {
|
private MaterialTab buildTab(int index)
|
||||||
String name = String.valueOf(index + 1);
|
{
|
||||||
NoteTab noteTab = new NoteTab(notesManager, index);
|
String name = String.valueOf(index + 1);
|
||||||
|
NoteTab noteTab = new NoteTab(notesManager, index);
|
||||||
|
|
||||||
MaterialTab materialTab = new MaterialTab(name, tabGroup, noteTab);
|
MaterialTab materialTab = new MaterialTab(name, tabGroup, noteTab);
|
||||||
materialTab.setPreferredSize(new Dimension(30, 27));
|
materialTab.setPreferredSize(new Dimension(30, 27));
|
||||||
materialTab.setName(name);
|
materialTab.setName(name);
|
||||||
|
|
||||||
final JMenuItem deleteMenuItem = new JMenuItem();
|
final JMenuItem deleteMenuItem = new JMenuItem();
|
||||||
deleteMenuItem.setText(String.format("Delete note %s", name));
|
deleteMenuItem.setText(String.format("Delete note %s", name));
|
||||||
|
|
||||||
deleteMenuItem.addActionListener(e -> {
|
deleteMenuItem.addActionListener(e -> {
|
||||||
if (JOptionPane.showConfirmDialog(getRootFrame(), String.format("Delete note page %s?", name), "Notes", YES_NO_OPTION) != YES_OPTION) {
|
if (JOptionPane.showConfirmDialog(getRootFrame(), String.format("Delete note page %s?", name), "Notes", YES_NO_OPTION) != YES_OPTION)
|
||||||
return;
|
{
|
||||||
}
|
return;
|
||||||
try {
|
}
|
||||||
notesManager.deletePage(index);
|
try
|
||||||
} catch (DeleteOnlyPageException err) {
|
{
|
||||||
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(getRootFrame(),
|
notesManager.deletePage(index);
|
||||||
"Cannot delete the last page",
|
}
|
||||||
"Notes", ERROR_MESSAGE));
|
catch (DeleteOnlyPageException err)
|
||||||
}
|
{
|
||||||
});
|
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(getRootFrame(),
|
||||||
|
"Cannot delete the last page",
|
||||||
|
"Notes", ERROR_MESSAGE));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
final JPopupMenu contextMenu = new JPopupMenu();
|
final JPopupMenu contextMenu = new JPopupMenu();
|
||||||
contextMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
|
contextMenu.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
contextMenu.add(deleteMenuItem);
|
contextMenu.add(deleteMenuItem);
|
||||||
|
|
||||||
materialTab.setComponentPopupMenu(contextMenu);
|
materialTab.setComponentPopupMenu(contextMenu);
|
||||||
|
|
||||||
return materialTab;
|
return materialTab;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
package net.runelite.client.plugins.notes;
|
package net.runelite.client.plugins.notes;
|
||||||
|
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.eventbus.EventBus;
|
import net.runelite.client.eventbus.EventBus;
|
||||||
import net.runelite.client.events.SessionOpen;
|
import net.runelite.client.events.SessionOpen;
|
||||||
@@ -34,10 +37,6 @@ import net.runelite.client.ui.ClientToolbar;
|
|||||||
import net.runelite.client.ui.NavigationButton;
|
import net.runelite.client.ui.NavigationButton;
|
||||||
import net.runelite.client.util.ImageUtil;
|
import net.runelite.client.util.ImageUtil;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
import java.awt.image.BufferedImage;
|
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Notes",
|
name = "Notes",
|
||||||
description = "Enable the Notes panel",
|
description = "Enable the Notes panel",
|
||||||
@@ -53,8 +52,8 @@ public class NotesPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private NotesConfig config;
|
private NotesConfig config;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private NotesManager notesManager;
|
private NotesManager notesManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private EventBus eventBus;
|
private EventBus eventBus;
|
||||||
@@ -87,8 +86,8 @@ public class NotesPlugin extends Plugin
|
|||||||
|
|
||||||
clientToolbar.addNavigation(navButton);
|
clientToolbar.addNavigation(navButton);
|
||||||
|
|
||||||
notesManager.loadNotes();
|
notesManager.loadNotes();
|
||||||
panel.rebuild();
|
panel.rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,7 +100,7 @@ public class NotesPlugin extends Plugin
|
|||||||
|
|
||||||
private void onSessionOpen(SessionOpen event)
|
private void onSessionOpen(SessionOpen event)
|
||||||
{
|
{
|
||||||
notesManager.loadNotes();
|
notesManager.loadNotes();
|
||||||
panel.rebuild();
|
panel.rebuild();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import lombok.Setter;
|
|||||||
import net.runelite.api.events.Event;
|
import net.runelite.api.events.Event;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PageAdded implements Event {
|
public class PageAdded implements Event
|
||||||
@Getter
|
{
|
||||||
@Setter
|
@Getter
|
||||||
private int index;
|
@Setter
|
||||||
|
private int index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,9 @@ import lombok.Setter;
|
|||||||
import net.runelite.api.events.Event;
|
import net.runelite.api.events.Event;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PageDeleted implements Event {
|
public class PageDeleted implements Event
|
||||||
@Getter
|
{
|
||||||
@Setter
|
@Getter
|
||||||
private int index;
|
@Setter
|
||||||
|
private int index;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,11 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.client.ui.components.materialtabs;
|
package net.runelite.client.ui.components.materialtabs;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.*;
|
import java.awt.FlowLayout;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will be a container (group) for the new Material Tabs. It will
|
* This class will be a container (group) for the new Material Tabs. It will
|
||||||
@@ -82,7 +83,8 @@ public class MaterialTabGroup extends JPanel
|
|||||||
return tabs.get(index);
|
return tabs.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTab(MaterialTab tab) {
|
public void addTab(MaterialTab tab)
|
||||||
|
{
|
||||||
tabs.add(tab);
|
tabs.add(tab);
|
||||||
add(tab, BorderLayout.NORTH);
|
add(tab, BorderLayout.NORTH);
|
||||||
|
|
||||||
@@ -90,7 +92,8 @@ public class MaterialTabGroup extends JPanel
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeTab(MaterialTab tab) {
|
public void removeTab(MaterialTab tab)
|
||||||
|
{
|
||||||
tabs.remove(tab);
|
tabs.remove(tab);
|
||||||
remove(tab);
|
remove(tab);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user