Closes #9, "Option for Tabs"

This commit is contained in:
emmanue1 2015-05-02 10:26:31 +02:00
parent a458f81241
commit 466433276c
11 changed files with 121 additions and 20 deletions

View File

@ -15,6 +15,8 @@ public interface PreferencesPanel {
public void init(Color errorBackgroundColor);
public boolean isActivated();
public void loadPreferences(Map<String, String> preferences);
public void savePreferences(Map<String, String> preferences);

View File

@ -286,7 +286,10 @@ class MainController implements API {
}
void onPreferences() {
preferencesController.show({ checkPreferencesChange(currentPage) })
preferencesController.show({
checkPreferencesChange(currentPage)
mainView.preferencesChanged(preferences)
})
}
void onCurrentPageChanged(JComponent page) {

View File

@ -9,5 +9,5 @@ import jd.gui.spi.PreferencesPanel
@Singleton(lazy = true)
class PreferencesPanelService {
final List<PreferencesPanel> providers = ServiceLoader.load(PreferencesPanel).toList()
final List<PreferencesPanel> providers = ServiceLoader.load(PreferencesPanel).toList().grep { it.isActivated() }
}

View File

@ -15,6 +15,7 @@ import jd.gui.api.feature.PageClosable
import jd.gui.api.feature.FocusedTypeGettable
import jd.gui.api.feature.ContentSavable
import jd.gui.api.feature.ContentCopyable
import jd.gui.api.feature.PreferencesChangeListener
import jd.gui.api.feature.SourcesSavable
import jd.gui.api.feature.UriGettable
import jd.gui.api.feature.UriOpenable
@ -41,7 +42,7 @@ import jd.gui.view.component.panel.MainTabbedPanel
import java.awt.event.KeyAdapter
import java.awt.event.KeyEvent
class MainView implements UriOpenable {
class MainView implements UriOpenable, PreferencesChangeListener {
SwingBuilder swing
History history
Closure openFilesClosure
@ -127,6 +128,7 @@ class MainView implements UriOpenable {
}
}
})
mainTabbedPanel.preferencesChanged(configuration.preferences)
findComboBox.editor.editorComponent.addKeyListener(new KeyAdapter() {
String lastStr = ''
@ -318,4 +320,9 @@ class MainView implements UriOpenable {
}
return success
}
// --- PreferencesChangeListener --- //
void preferencesChanged(Map<String, String> preferences) {
swing.mainTabbedPanel.preferencesChanged(preferences)
}
}

View File

@ -7,6 +7,7 @@ package jd.gui.view.component.panel
import jd.gui.api.feature.PageChangeListener
import jd.gui.api.feature.PageChangeable
import jd.gui.api.feature.PreferencesChangeListener
import jd.gui.api.feature.UriGettable
import jd.gui.api.feature.UriOpenable
@ -41,14 +42,22 @@ class MainTabbedPanel extends TabbedPanel implements UriOpenable, PageChangeList
tabbedPane.addChangeListener(new ChangeListener() {
void stateChanged(ChangeEvent e) {
if (pageChangedListenersEnabled) {
def page = tabbedPane.selectedComponent?.getClientProperty('currentPage')
def subPage = tabbedPane.selectedComponent
if (page == null) {
page = tabbedPane.selectedComponent
}
// Fire page changed event
for (def listener : pageChangedListeners) {
listener.pageChanged(page)
if (subPage) {
def page = subPage.getClientProperty('currentPage')
if (page == null) {
page = tabbedPane.selectedComponent
}
// Fire page changed event
for (def listener : pageChangedListeners) {
listener.pageChanged(page)
}
// Update current sub-page preferences
if (subPage instanceof PreferencesChangeListener) {
subPage.preferencesChanged(preferences)
}
}
}
}
@ -155,4 +164,15 @@ class MainTabbedPanel extends TabbedPanel implements UriOpenable, PageChangeList
listener.pageChanged(page)
}
}
// --- PreferencesChangeListener --- //
void preferencesChanged(Map<String, String> preferences) {
super.preferencesChanged(preferences)
// Update current sub-page preferences
def subPage = tabbedPane.selectedComponent
if (subPage instanceof PreferencesChangeListener) {
subPage.preferencesChanged(preferences)
}
}
}

View File

@ -5,6 +5,7 @@
package jd.gui.view.component.panel
import jd.gui.api.feature.PreferencesChangeListener
import jd.gui.api.feature.UriGettable
import jd.gui.service.platform.PlatformService
@ -29,11 +30,14 @@ import java.awt.event.MouseAdapter
import java.awt.event.MouseEvent
import java.awt.event.MouseListener
class TabbedPanel extends JPanel {
class TabbedPanel extends JPanel implements PreferencesChangeListener {
static final ImageIcon closeIcon = new ImageIcon(TabbedPanel.class.classLoader.getResource('images/close.gif'))
static final ImageIcon closeActivateIcon = new ImageIcon(TabbedPanel.class.classLoader.getResource('images/close_active.gif'))
static final String TAB_LAYOUT = 'UITabsPreferencesProvider.singleLineTabs'
JTabbedPane tabbedPane
Map<String, String> preferences
TabbedPanel() {
create()
@ -84,6 +88,11 @@ class TabbedPanel extends JPanel {
}
public <T extends JComponent & UriGettable> void addPage(String title, Icon icon, String tip, T page) {
// Update preferences
if (page instanceof PreferencesChangeListener) {
page.preferencesChanged(preferences)
}
// Add a new tab
JLabel tabCloseButton = new JLabel(closeIcon)
tabCloseButton.toolTipText = 'Close this panel'
tabCloseButton.addMouseListener(new MouseListener() {
@ -110,8 +119,10 @@ class TabbedPanel extends JPanel {
int index = tabbedPane.getTabCount()
tabbedPane.addTab(title, page)
tabbedPane.setTabComponentAt(index, tab)
tabbedPane.selectedIndex = index
// Ensure new page is visible (bug with SCROLL_TAB_LAYOUT)
tabbedPane.selectedIndex = 0
tabbedPane.selectedIndex = index
getLayout().show(this, 'tabs')
}
@ -180,4 +191,22 @@ class TabbedPanel extends JPanel {
getLayout().show(this, 'panel')
}
}
// --- PreferencesChangeListener --- //
void preferencesChanged(Map<String, String> preferences) {
// Store preferences
this.preferences = preferences
// Update layout
if ('true'.equals(preferences.get(TAB_LAYOUT))) {
tabbedPane.tabLayoutPolicy = JTabbedPane.SCROLL_TAB_LAYOUT
} else {
tabbedPane.tabLayoutPolicy = JTabbedPane.WRAP_TAB_LAYOUT
}
// Ensure selected sub-page is visible (bug with SCROLL_TAB_LAYOUT)
int index = tabbedPane.selectedIndex
if (index != -1) {
tabbedPane.selectedIndex = 0
tabbedPane.selectedIndex = index
}
}
}

View File

@ -9,6 +9,7 @@ import jd.gui.api.API
import jd.gui.api.feature.PageChangeListener
import jd.gui.api.feature.PageChangeable
import jd.gui.api.feature.PageClosable
import jd.gui.api.feature.PreferencesChangeListener
import jd.gui.api.feature.TreeNodeExpandable
import jd.gui.api.feature.UriGettable
import jd.gui.api.model.TreeNodeData
@ -28,7 +29,7 @@ import javax.swing.tree.DefaultMutableTreeNode
import java.awt.*
import java.util.List
class TreeTabbedPanel extends JPanel implements UriGettable, UriOpenable, PageChangeable, PageClosable {
class TreeTabbedPanel extends JPanel implements UriGettable, UriOpenable, PageChangeable, PageClosable, PreferencesChangeListener {
API api
URI uri
Tree tree
@ -242,4 +243,9 @@ class TreeTabbedPanel extends JPanel implements UriGettable, UriOpenable, PageCh
return false
}
}
// --- PreferencesChangeListener --- //
void preferencesChanged(Map<String, String> preferences) {
tabbedPanel.preferencesChanged(preferences)
}
}

View File

@ -40,17 +40,45 @@ subprojects.each { subproject ->
}
jar {
dependsOn subprojects.tasks['classes']
manifest {
attributes 'Main-Class': 'jd.gui.App', 'SplashScreen-Image': 'images/jd_icon_128.png'
}
dependsOn subprojects.tasks['jar']
def deps = []
subprojects.each { subproject ->
from subproject.sourceSets.main.output.classesDir
from subproject.sourceSets.main.output.resourcesDir
deps += subproject.configurations.runtime - subproject.configurations.provided
}
from { deps.unique().collect { it.isDirectory() ? it : zipTree(it) } }
subprojects.each { subproject ->
deps -= subproject.jar.archivePath
}
deps = deps.unique().collect { it.isDirectory() ? it : zipTree(it) }
manifest {
attributes 'Main-Class': 'jd.gui.App', 'SplashScreen-Image': 'images/jd_icon_128.png'
}
from deps
exclude 'META-INF/services/jd.gui.spi.*'
duplicatesStrategy DuplicatesStrategy.EXCLUDE
doFirst {
// Create temporary directory
def tmpSpiDir = file('build/tmp/spi')
tmpSpiDir.deleteDir()
tmpSpiDir.mkdirs()
// Copy and merge SPI config files
subprojects.each { subproject ->
def servicesDir = file(subproject.sourceSets.main.output.resourcesDir.path + File.separator + 'META-INF' + File.separator + 'services')
if (servicesDir.exists()) {
servicesDir.eachFile { source ->
def target = file(tmpSpiDir.path + File.separator + source.name)
target << source.text
}
}
}
// Add to JAR file
into('META-INF/services') {
from tmpSpiDir
}
}
}
// Windows wrapper configuration to generate "jd-gui.exe" //
@ -75,7 +103,7 @@ task launch4j(type: Exec, dependsOn: [':jar', ':launch4jConfig']) {
}
}
// Distribution for OSX //
// Distributions for OSX and Windows //
distributions {
osx {
contents {

View File

@ -52,6 +52,8 @@ class ClassFileSaverPreferencesProvider extends JPanel implements PreferencesPan
public void init(Color errorBackgroundColor) {}
public boolean isActivated() { true }
void loadPreferences(Map<String, String> preferences) {
escapeUnicodeCharactersCheckBox.selected = 'true'.equals(preferences.get(ESCAPE_UNICODE_CHARACTERS))
omitThisPrefixCheckBox.selected = 'true'.equals(preferences.get(OMIT_THIS_PREFIX))

View File

@ -44,6 +44,8 @@ class ClassFileViewerPreferencesProvider extends JPanel implements PreferencesPa
public void init(Color errorBackgroundColor) {}
public boolean isActivated() { true }
void loadPreferences(Map<String, String> preferences) {
escapeUnicodeCharactersCheckBox.selected = !'false'.equals(preferences.get(ESCAPE_UNICODE_CHARACTERS))
omitThisPrefixCheckBox.selected = 'true'.equals(preferences.get(OMIT_THIS_PREFIX))

View File

@ -44,6 +44,8 @@ class DirectoryIndexerPreferencesProvider extends JPanel implements PreferencesP
this.errorBackgroundColor = errorBackgroundColor
}
public boolean isActivated() { true }
void loadPreferences(Map<String, String> preferences) {
maximumDepthTextField.text = preferences.get(MAXIMUM_DEPTH_KEY) ?: '15'
maximumDepthTextField.setCaretPosition(maximumDepthTextField.text.size())