Fix compatibility with the UI Designer & Maven

This commit is contained in:
ME1312 2018-10-22 22:06:25 -04:00
parent 6925a7bccb
commit dfa37c9022
No known key found for this signature in database
GPG Key ID: FEFFE2F698E88FA8
3 changed files with 274 additions and 148 deletions

View File

@ -17,6 +17,12 @@
</repositories>
<dependencies>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>7.0.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.md_5</groupId>
<artifactId>bungeecord-internal</artifactId>
@ -43,12 +49,29 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<source>1.7</source>
<target>1.8</target>
</configuration>
</plugin>

View File

@ -27,7 +27,17 @@ public final class ConsolePlugin extends Plugin implements Listener {
@Override
public void onEnable() {
SubAPI.getInstance().addListener(this::enable, this::disable);
SubAPI.getInstance().addListener(new Runnable() {
@Override
public void run() {
enable();
}
}, new Runnable() {
@Override
public void run() {
disable();
}
});
}
public void enable() {

View File

@ -11,6 +11,8 @@ import org.fusesource.jansi.AnsiOutputStream;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.text.*;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
@ -68,7 +70,9 @@ public final class ConsoleWindow implements SubLogFilter {
}
});
private boolean[] kpressed = new boolean[65535];
private KeyEventDispatcher keys = event -> {
private KeyEventDispatcher keys = new KeyEventDispatcher() {
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
switch (event.getID()) {
case KeyEvent.KEY_PRESSED:
kpressed[event.getKeyCode()] = true;
@ -96,7 +100,7 @@ public final class ConsoleWindow implements SubLogFilter {
break;
case KeyEvent.VK_ENTER:
if (find.isVisible() && !ifocus)
find(kpressed[KeyEvent.VK_SHIFT] != Boolean.TRUE);
ConsoleWindow.this.find(kpressed[KeyEvent.VK_SHIFT] != Boolean.TRUE);
break;
case KeyEvent.VK_TAB:
if (!ifocus) input.requestFocusInWindow();
@ -105,9 +109,10 @@ public final class ConsoleWindow implements SubLogFilter {
}
return false;
}
};
public ConsoleWindow(ConsolePlugin plugin, SubLogger logger) {
public ConsoleWindow(final ConsolePlugin plugin, final SubLogger logger) {
this.plugin = plugin;
this.logger = logger;
@ -117,19 +122,29 @@ public final class ConsoleWindow implements SubLogFilter {
JMenu menu = new JMenu("\u00A0Log\u00A0");
JMenuItem item = new JMenuItem("Clear Screen");
item.setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
item.addActionListener(event -> clear());
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
ConsoleWindow.this.clear();
}
});
menu.add(item);
item = new JMenuItem("Reload Log");
item.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
item.addActionListener(event -> {
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
log.setText(RESET_VALUE);
loadContent();
ConsoleWindow.this.loadContent();
}
});
menu.add(item);
if (logger.getHandler() instanceof SubServer || logger.getHandler() instanceof SubCreator) {
item = new JCheckBoxMenuItem("Auto Popout Log");
item.setSelected((logger.getHandler() instanceof SubServer && (plugin.config.get().getStringList("Enabled-Servers").contains(((SubServer) logger.getHandler()).getName().toLowerCase()))) || (logger.getHandler() instanceof SubCreator && (plugin.config.get().getStringList("Enabled-Creators").contains(((SubCreator) logger.getHandler()).getHost().getName().toLowerCase()))));
item.addActionListener(event -> {
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
try {
if (logger.getHandler() instanceof SubServer) {
List<String> list = plugin.config.get().getStringList("Enabled-Servers");
@ -153,6 +168,7 @@ public final class ConsoleWindow implements SubLogFilter {
} catch (Exception e) {
e.printStackTrace();
}
}
});
menu.add(item);
jMenu.add(menu);
@ -161,7 +177,9 @@ public final class ConsoleWindow implements SubLogFilter {
menu = new JMenu("\u00A0Search\u00A0");
item = new JMenuItem("Find");
item.setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
item.addActionListener(event -> {
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (find.isVisible()) {
find.setVisible(false);
findI = 0;
@ -171,28 +189,35 @@ public final class ConsoleWindow implements SubLogFilter {
findT.selectAll();
findT.requestFocusInWindow();
}
}
});
menu.add(item);
item = new JMenuItem("Find Next");
item.addActionListener(event -> {
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (find.isVisible()) {
find(true);
ConsoleWindow.this.find(true);
} else {
find.setVisible(true);
findT.selectAll();
findT.requestFocusInWindow();
}
}
});
menu.add(item);
item = new JMenuItem("Find Previous");
item.addActionListener(event -> {
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (find.isVisible()) {
find(false);
ConsoleWindow.this.find(false);
} else {
find.setVisible(true);
findT.selectAll();
findT.requestFocusInWindow();
}
}
});
menu.add(item);
jMenu.add(menu);
@ -200,45 +225,67 @@ public final class ConsoleWindow implements SubLogFilter {
menu = new JMenu("\u00A0View\u00A0");
item = new JMenuItem("Scroll to Top");
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_UP, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
item.addActionListener(event -> vScroll.getVerticalScrollBar().setValue(0));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
vScroll.getVerticalScrollBar().setValue(0);
}
});
menu.add(item);
item = new JMenuItem("Scroll to Bottom");
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
item.addActionListener(event -> vScroll.getVerticalScrollBar().setValue(vScroll.getVerticalScrollBar().getMaximum() - vScroll.getVerticalScrollBar().getVisibleAmount()));
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
vScroll.getVerticalScrollBar().setValue(vScroll.getVerticalScrollBar().getMaximum() - vScroll.getVerticalScrollBar().getVisibleAmount());
}
});
menu.add(item);
menu.addSeparator();
item = new JCheckBoxMenuItem("Show Text Colors");
item.setSelected(true);
item.addActionListener(event -> {
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
ansi = ((AbstractButton) event.getSource()).getModel().isSelected();
log.setText(RESET_VALUE);
loadContent();
ConsoleWindow.this.loadContent();
}
});
menu.add(item);
item = new JMenuItem("Reset Text Size");
item.addActionListener(event -> {
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
HTMLDocument doc = (HTMLDocument) log.getDocument();
fontSize = 12;
doc.getStyleSheet().addRule("body {font-size: " + fontSize + ";}\n");
hScroll();
ConsoleWindow.this.hScroll();
}
});
menu.add(item);
item = new JMenuItem("Bigger Text");
item.setAccelerator(KeyStroke.getKeyStroke('=', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
item.addActionListener(event -> {
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
HTMLDocument doc = (HTMLDocument) log.getDocument();
fontSize += 2;
doc.getStyleSheet().addRule("body {font-size: " + fontSize + ";}\n");
hScroll();
ConsoleWindow.this.hScroll();
}
});
menu.add(item);
item = new JMenuItem("Smaller Text");
item.setAccelerator(KeyStroke.getKeyStroke('-', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), true));
item.addActionListener(event -> {
item.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
HTMLDocument doc = (HTMLDocument) log.getDocument();
fontSize -= 2;
doc.getStyleSheet().addRule("body {font-size: " + fontSize + ";}\n");
hScroll();
ConsoleWindow.this.hScroll();
}
});
menu.add(item);
jMenu.add(menu);
@ -246,7 +293,12 @@ public final class ConsoleWindow implements SubLogFilter {
window.setJMenuBar(jMenu);
window.setContentPane(panel);
window.pack();
Util.isException(() -> window.setIconImage(ImageIO.read(ConsolePlugin.class.getResourceAsStream("/SubServers.png"))));
Util.isException(new Util.ExceptionRunnable() {
@Override
public void run() throws Throwable {
window.setIconImage(ImageIO.read(ConsolePlugin.class.getResourceAsStream("/SubServers.png")));
}
});
window.setTitle(logger.getName() + " \u2014 SubServers 2");
window.setSize(1024, 576);
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
@ -298,7 +350,9 @@ public final class ConsoleWindow implements SubLogFilter {
popup = new TextFieldPopup(input, true);
input.setBorder(BorderFactory.createLineBorder(new Color(40, 44, 45), 4));
input.addActionListener((ActionEvent event) -> {
input.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (logger.getHandler() instanceof SubServer && input.getText().length() > 0 && !input.getText().equals(">")) {
if (((SubServer) logger.getHandler()).command((input.getText().startsWith(">")) ? input.getText().substring(1) : input.getText())) {
popup.commands.add((input.getText().startsWith(">")) ? input.getText().substring(1) : input.getText());
@ -307,6 +361,7 @@ public final class ConsoleWindow implements SubLogFilter {
input.setText("");
}
}
}
});
((AbstractDocument) input.getDocument()).setDocumentFilter(new DocumentFilter() {
@Override
@ -349,21 +404,27 @@ public final class ConsoleWindow implements SubLogFilter {
}
});
vScroll.getHorizontalScrollBar().addAdjustmentListener(event -> {
vScroll.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent event) {
if (!eScroll.contains(event.getValue())) {
eScroll.add(event.getValue());
hScroll.setValue(event.getValue());
} else {
eScroll.remove((Object) event.getValue());
}
}
});
hScroll.addAdjustmentListener(event -> {
hScroll.addAdjustmentListener(new AdjustmentListener() {
@Override
public void adjustmentValueChanged(AdjustmentEvent event) {
if (!eScroll.contains(event.getValue())) {
eScroll.add(event.getValue());
vScroll.getHorizontalScrollBar().setValue(event.getValue());
} else {
eScroll.remove((Object) event.getValue());
}
}
});
new TextFieldPopup(findT, false);
@ -390,27 +451,49 @@ public final class ConsoleWindow implements SubLogFilter {
findO = 0;
}
});
findP.addChangeListener(e -> {
findP.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (findP.getModel().isPressed()) findP.setBackground(new Color(40, 44, 45));
else findP.setBackground(new Color(69, 73, 74));
}
});
findP.setBorder(new ButtonBorder(40, 44, 45, 4));
findP.addActionListener(event -> find(false));
findN.addChangeListener(e -> {
findP.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
ConsoleWindow.this.find(false);
}
});
findN.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (findN.getModel().isPressed()) findN.setBackground(new Color(40, 44, 45));
else findN.setBackground(new Color(69, 73, 74));
}
});
findN.setBorder(new ButtonBorder(40, 44, 45, 4));
findN.addActionListener(event -> find(true));
findD.addChangeListener(e -> {
findN.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
ConsoleWindow.this.find(true);
}
});
findD.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (findD.getModel().isPressed()) findD.setBackground(new Color(40, 44, 45));
else findD.setBackground(new Color(69, 73, 74));
}
});
findD.setBorder(new ButtonBorder(40, 44, 45, 4));
findD.addActionListener(event -> {
findD.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
find.setVisible(false);
findI = 0;
findO = 0;
}
});
@ -439,7 +522,10 @@ public final class ConsoleWindow implements SubLogFilter {
LinkedList<Object> list = new LinkedList<Object>();
list.addAll(logger.getMessageHistory());
if (logger.getHandler() instanceof SubServer) list.addAll(((SubServer) logger.getHandler()).getCommandHistory());
list.sort((A, B) -> {
Collections.sort(list, new Comparator<Object>() {
@Override
public int compare(Object A, Object B) {
Date a = null, b = null;
if (A instanceof SubLogger.LogMessage) a = ((SubLogger.LogMessage) A).getDate();
@ -449,6 +535,7 @@ public final class ConsoleWindow implements SubLogFilter {
if (B instanceof SubServer.LoggedCommand) b = ((SubServer.LoggedCommand) B).getDate();
return (a == null || b == null) ? 0 : a.compareTo(b);
}
});
for (Object obj : list) {
if (obj instanceof SubLogger.LogMessage) log(((SubLogger.LogMessage) obj).getDate(), ((SubLogger.LogMessage) obj).getLevel(), ((SubLogger.LogMessage) obj).getMessage());
@ -536,7 +623,13 @@ public final class ConsoleWindow implements SubLogFilter {
try {
boolean found = false;
if (findI + findLength >= document.getLength()) findI = 1;
if (findI < 0 || findI + findLength >= document.getLength()) {
if (direction) {
findI = 1;
} else {
findI = document.getLength() - findLength;
}
}
while (findLength <= document.getLength()) {
String match = document.getText(findI, findLength).toLowerCase();
@ -560,7 +653,7 @@ public final class ConsoleWindow implements SubLogFilter {
}
} catch (BadLocationException e) {
findI = log.getText().length() - 1;
findI = -2;
JOptionPane.showMessageDialog(window,
((findO > 0)?"There are no more results\nSearch again to start from the " + ((direction)?"top":"bottom"):"Couldn't find \"" + findT.getText() + "\""),
"Find",