-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathNaviViewExt.java
128 lines (114 loc) · 4.58 KB
/
NaviViewExt.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (C) 2015 markiewb
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package de.markiewb.netbeans.plugins.outline;
import de.markiewb.netbeans.plugins.outline.options.Options;
import bluej.editor.moe.NaviView;
import de.markiewb.netbeans.plugins.outline.options.CodeoutlineOptionsPanel;
import java.awt.Dimension;
import java.io.IOException;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
import javax.swing.BorderFactory;
import javax.swing.JScrollBar;
import javax.swing.border.BevelBorder;
import javax.swing.text.Document;
import org.netbeans.api.editor.mimelookup.MimeLookup;
import org.netbeans.api.editor.mimelookup.MimePath;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.NbPreferences;
import org.openide.util.WeakListeners;
/**
*
* @author markiewb
*/
public class NaviViewExt extends NaviView implements PreferenceChangeListener {
public NaviViewExt(Document document, JScrollBar scrollBar) {
super(document, scrollBar);
this.setBorder(BorderFactory.createEmptyBorder());
{
//add listener for View|Show Outline
Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs));
}
{
//add listener for preferences set by options dialog
Preferences prefs = NbPreferences.forModule(CodeoutlineOptionsPanel.class);
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs));
}
//initial setup from configuration
preferenceChange(null);
}
private void setupWidth(int width) {
this.setPreferredSize(new Dimension(width, 0));
this.setMaximumSize(new Dimension(width, Integer.MAX_VALUE));
//relayout for on the fly-layouting
this.revalidate();
}
@Override
public void preferenceChange(PreferenceChangeEvent evt) {
if (evt == null
|| Options.KEY_OUTLINE.equals(evt.getKey())) {
setVisible(Options.isVisible());
}
if (evt == null
|| Options.KEY_WIDTH.equals(evt.getKey())) {
setupWidth(Options.getWidth());
}
if (evt == null
|| Options.KEY_POSITION.equals(evt.getKey())) {
updatePosition();
}
}
private void updatePosition() {
/**
* <pre>
* <filesystem>
* <folder name="Editors">
* <folder name="SideBar">
* <file name="de-markiewb-netbeans-plugins-outline-OutlineSideBarFactory.instance">
* <attr name="position" intvalue="10000"/>
* <attr name="location" stringvalue="East"/>
* <attr name="scrollable" boolvalue="false"/>
* </file>
* </folder>
* </folder>
* </filesystem>
* </pre>
*/
try {
FileObject configFile = FileUtil.getConfigFile("Editors/SideBar/de-markiewb-netbeans-plugins-outline-OutlineSideBarFactory.instance");
Options.Position position = Options.getPosition();
switch (position) {
case LEFT:
//does not work at runtime, needs a restart
configFile.setAttribute("location", "West");
break;
case RIGHT:
//does not work at runtime, needs a restart
configFile.setAttribute("location", "East");
break;
default:
throw new AssertionError();
}
this.revalidate();
} catch (IOException iOException) {
}
}
}