mirror of
https://github.com/java-decompiler/jd-gui.git
synced 2025-01-22 12:05:44 +00:00
Fixes #48, adds "UI > Main window > Single instance" to preferences
This commit is contained in:
parent
77f1f1c82d
commit
d71bed51ba
@ -7,26 +7,40 @@ package jd.gui
|
||||
|
||||
import groovy.swing.SwingBuilder
|
||||
import jd.gui.service.configuration.ConfigurationPersisterService
|
||||
import jd.gui.util.net.InterProcessCommunications
|
||||
|
||||
import javax.swing.JOptionPane
|
||||
|
||||
import jd.gui.controller.MainController
|
||||
|
||||
class App {
|
||||
static final String SINGLE_INSTANCE = 'UIMainWindowPreferencesProvider.singleInstance'
|
||||
|
||||
static MainController controller
|
||||
|
||||
static void main(String[] args) {
|
||||
if (args.contains("-h")) {
|
||||
JOptionPane.showMessageDialog(null, """Usage: jd-gui [option] [input-file] ...
|
||||
|
||||
Option:
|
||||
-h\tshow this help message and exit""", Constants.APP_NAME)
|
||||
JOptionPane.showMessageDialog(null, "Usage: jd-gui [option] [input-file] ...\n\nOption:\n -h Show this help message and exit", Constants.APP_NAME, JOptionPane.INFORMATION_MESSAGE)
|
||||
} else {
|
||||
// Load preferences
|
||||
def persister = ConfigurationPersisterService.instance.get()
|
||||
def configuration = persister.load()
|
||||
addShutdownHook { persister.save(configuration) }
|
||||
|
||||
if ('true'.equals(configuration.preferences.get(SINGLE_INSTANCE))) {
|
||||
def ipc = new InterProcessCommunications()
|
||||
|
||||
try {
|
||||
ipc.listen { String[] receivedArgs ->
|
||||
controller.openFiles(receivedArgs.collect { new File(it) })
|
||||
}
|
||||
} catch (Exception notTheFirstInstanceException) {
|
||||
// Send args to main windows and exit
|
||||
ipc.send(args)
|
||||
System.exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
// Create SwingBuilder, set look and feel
|
||||
def swing = new SwingBuilder()
|
||||
swing.lookAndFeel(configuration.lookAndFeel)
|
||||
|
@ -40,7 +40,7 @@ import jd.gui.spi.SourceSaver
|
||||
import jd.gui.spi.TreeNodeFactory
|
||||
import jd.gui.spi.TypeFactory
|
||||
import jd.gui.spi.UriLoader
|
||||
import jd.gui.util.UriUtil
|
||||
import jd.gui.util.net.UriUtil
|
||||
|
||||
import javax.swing.Icon
|
||||
import javax.swing.JComponent
|
||||
|
@ -12,7 +12,7 @@ import jd.gui.api.feature.IndexesChangeListener
|
||||
import jd.gui.api.model.Container
|
||||
import jd.gui.api.model.Indexes
|
||||
import jd.gui.model.configuration.Configuration
|
||||
import jd.gui.util.UriUtil
|
||||
import jd.gui.util.net.UriUtil
|
||||
import jd.gui.view.OpenTypeView
|
||||
|
||||
import java.awt.Cursor
|
||||
|
@ -11,7 +11,7 @@ import jd.gui.api.feature.IndexesChangeListener
|
||||
import jd.gui.api.model.Container
|
||||
import jd.gui.api.model.Indexes
|
||||
import jd.gui.model.configuration.Configuration
|
||||
import jd.gui.util.UriUtil
|
||||
import jd.gui.util.net.UriUtil
|
||||
import jd.gui.view.OpenTypeHierarchyView
|
||||
|
||||
import java.awt.Cursor
|
||||
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2015 Emmanuel Dupuy
|
||||
* This program is made available under the terms of the GPLv3 License.
|
||||
*/
|
||||
|
||||
package jd.gui.service.preferencespanel
|
||||
|
||||
import jd.gui.spi.PreferencesPanel
|
||||
|
||||
import javax.swing.*
|
||||
import java.awt.*
|
||||
|
||||
/**
|
||||
* JTabbedPane.WRAP_TAB_LAYOUT is not supported by Aqua L&F.
|
||||
* This panel is not activated on Mac OSX.
|
||||
*/
|
||||
class UISingleInstancePreferencesProvider extends JPanel implements PreferencesPanel {
|
||||
|
||||
static final String SINGLE_INSTANCE = 'UIMainWindowPreferencesProvider.singleInstance'
|
||||
|
||||
JCheckBox singleInstanceTabsCheckBox
|
||||
|
||||
UISingleInstancePreferencesProvider() {
|
||||
super(new GridLayout(0,1))
|
||||
|
||||
singleInstanceTabsCheckBox = new JCheckBox('Single instance')
|
||||
|
||||
add(singleInstanceTabsCheckBox)
|
||||
}
|
||||
|
||||
// --- PreferencesPanel --- //
|
||||
String getPreferencesGroupTitle() { 'User Interface' }
|
||||
String getPreferencesPanelTitle() { 'Main window' }
|
||||
|
||||
public void init(Color errorBackgroundColor) {}
|
||||
|
||||
public boolean isActivated() {
|
||||
System.getProperty('os.name').toLowerCase().contains('mac os') == false
|
||||
}
|
||||
|
||||
void loadPreferences(Map<String, String> preferences) {
|
||||
singleInstanceTabsCheckBox.selected = 'true'.equals(preferences.get(SINGLE_INSTANCE))
|
||||
}
|
||||
|
||||
void savePreferences(Map<String, String> preferences) {
|
||||
preferences.put(SINGLE_INSTANCE, Boolean.toString(singleInstanceTabsCheckBox.selected))
|
||||
}
|
||||
|
||||
boolean arePreferencesValid() { true }
|
||||
|
||||
void addPreferencesChangeListener(PreferencesPanel.PreferencesPanelChangeListener listener) {}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2008-2015 Emmanuel Dupuy
|
||||
* This program is made available under the terms of the GPLv3 License.
|
||||
*/
|
||||
|
||||
package jd.gui.util.net
|
||||
|
||||
class InterProcessCommunications {
|
||||
|
||||
protected static final int PORT = 2015_6
|
||||
|
||||
void listen(Closure closure) throws Exception {
|
||||
def listener = new ServerSocket(PORT)
|
||||
|
||||
new Thread().start {
|
||||
while (true) {
|
||||
listener.accept().withCloseable { Socket socket ->
|
||||
closure(new ObjectInputStream(socket.inputStream).readObject())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void send(Object obj) {
|
||||
new Socket(InetAddress.localHost, PORT).withCloseable { Socket socket ->
|
||||
new ObjectOutputStream(socket.outputStream).writeObject(obj)
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
* This program is made available under the terms of the GPLv3 License.
|
||||
*/
|
||||
|
||||
package jd.gui.util
|
||||
package jd.gui.util.net
|
||||
|
||||
import jd.gui.api.API
|
||||
import jd.gui.api.model.Container
|
@ -1 +1,2 @@
|
||||
jd.gui.service.preferencespanel.UISingleInstancePreferencesProvider
|
||||
jd.gui.service.preferencespanel.UITabsPreferencesProvider
|
||||
|
Loading…
x
Reference in New Issue
Block a user