Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/swing/WindowsPlacesBar.java
41153 views
1
/*
2
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
package sun.swing;
26
27
import java.awt.Dimension;
28
import java.awt.Insets;
29
import java.awt.Color;
30
import java.awt.Image;
31
32
import java.awt.event.ActionEvent;
33
import java.awt.event.ActionListener;
34
35
import java.beans.PropertyChangeEvent;
36
import java.beans.PropertyChangeListener;
37
38
import java.io.File;
39
import java.security.AccessController;
40
import java.security.PrivilegedAction;
41
42
import javax.swing.JToolBar;
43
import javax.swing.JFileChooser;
44
import javax.swing.JToggleButton;
45
import javax.swing.ButtonGroup;
46
import javax.swing.UIManager;
47
import javax.swing.Icon;
48
import javax.swing.ImageIcon;
49
import javax.swing.JComponent;
50
import javax.swing.Box;
51
52
import javax.swing.border.EmptyBorder;
53
import javax.swing.border.BevelBorder;
54
import javax.swing.filechooser.FileSystemView;
55
56
import sun.awt.shell.ShellFolder;
57
import sun.awt.OSInfo;
58
59
/**
60
* <b>WARNING:</b> This class is an implementation detail and is only
61
* public so that it can be used by two packages. You should NOT consider
62
* this public API.
63
*
64
* @author Leif Samuelsson
65
*/
66
@SuppressWarnings("serial") // JDK-implementation class
67
public class WindowsPlacesBar extends JToolBar
68
implements ActionListener, PropertyChangeListener {
69
JFileChooser fc;
70
JToggleButton[] buttons;
71
ButtonGroup buttonGroup;
72
File[] files;
73
final Dimension buttonSize;
74
75
public WindowsPlacesBar(JFileChooser fc, boolean isXPStyle) {
76
super(JToolBar.VERTICAL);
77
this.fc = fc;
78
setFloatable(false);
79
putClientProperty("JToolBar.isRollover", Boolean.TRUE);
80
81
boolean isXPPlatform = (OSInfo.getOSType() == OSInfo.OSType.WINDOWS &&
82
OSInfo.getWindowsVersion().compareTo(OSInfo.WINDOWS_XP) >= 0);
83
84
if (isXPStyle) {
85
buttonSize = new Dimension(83, 69);
86
putClientProperty("XPStyle.subAppName", "placesbar");
87
setBorder(new EmptyBorder(1, 1, 1, 1));
88
} else {
89
// The button size almost matches the XP style when in Classic style on XP
90
buttonSize = new Dimension(83, isXPPlatform ? 65 : 54);
91
setBorder(new BevelBorder(BevelBorder.LOWERED,
92
UIManager.getColor("ToolBar.highlight"),
93
UIManager.getColor("ToolBar.background"),
94
UIManager.getColor("ToolBar.darkShadow"),
95
UIManager.getColor("ToolBar.shadow")));
96
}
97
Color bgColor = new Color(UIManager.getColor("ToolBar.shadow").getRGB());
98
setBackground(bgColor);
99
FileSystemView fsv = fc.getFileSystemView();
100
101
files = fsv.getChooserShortcutPanelFiles();
102
103
buttons = new JToggleButton[files.length];
104
buttonGroup = new ButtonGroup();
105
for (int i = 0; i < files.length; i++) {
106
if (fsv.isFileSystemRoot(files[i])) {
107
// Create special File wrapper for drive path
108
files[i] = fsv.createFileObject(files[i].getAbsolutePath());
109
}
110
111
String folderName = fsv.getSystemDisplayName(files[i]);
112
int index = folderName.lastIndexOf(File.separatorChar);
113
if (index >= 0 && index < folderName.length() - 1) {
114
folderName = folderName.substring(index + 1);
115
}
116
Icon icon;
117
if (files[i] instanceof ShellFolder) {
118
// We want a large icon, fsv only gives us a small.
119
ShellFolder sf = (ShellFolder)files[i];
120
Image image = sf.getIcon(true);
121
122
if (image == null) {
123
// Get default image
124
image = (Image) ShellFolder.get("shell32LargeIcon 1");
125
}
126
127
icon = image == null ? null : new ImageIcon(image, sf.getFolderType());
128
} else {
129
icon = fsv.getSystemIcon(files[i]);
130
}
131
buttons[i] = new JToggleButton(folderName, icon);
132
if (isXPStyle) {
133
buttons[i].putClientProperty("XPStyle.subAppName", "placesbar");
134
} else {
135
Color fgColor = new Color(UIManager.getColor("List.selectionForeground").getRGB());
136
buttons[i].setContentAreaFilled(false);
137
buttons[i].setForeground(fgColor);
138
}
139
buttons[i].setMargin(new Insets(3, 2, 1, 2));
140
buttons[i].setFocusPainted(false);
141
buttons[i].setIconTextGap(0);
142
buttons[i].setHorizontalTextPosition(JToggleButton.CENTER);
143
buttons[i].setVerticalTextPosition(JToggleButton.BOTTOM);
144
buttons[i].setAlignmentX(JComponent.CENTER_ALIGNMENT);
145
buttons[i].setPreferredSize(buttonSize);
146
buttons[i].setMaximumSize(buttonSize);
147
buttons[i].addActionListener(this);
148
add(buttons[i]);
149
if (i < files.length-1 && isXPStyle) {
150
add(Box.createRigidArea(new Dimension(1, 1)));
151
}
152
buttonGroup.add(buttons[i]);
153
}
154
doDirectoryChanged(fc.getCurrentDirectory());
155
}
156
157
protected void doDirectoryChanged(File f) {
158
for (int i=0; i<buttons.length; i++) {
159
JToggleButton b = buttons[i];
160
if (files[i].equals(f)) {
161
b.setSelected(true);
162
break;
163
} else if (b.isSelected()) {
164
// Remove temporarily from group because it doesn't
165
// allow for no button to be selected.
166
buttonGroup.remove(b);
167
b.setSelected(false);
168
buttonGroup.add(b);
169
}
170
}
171
}
172
173
public void propertyChange(PropertyChangeEvent e) {
174
String prop = e.getPropertyName();
175
if (prop == JFileChooser.DIRECTORY_CHANGED_PROPERTY) {
176
doDirectoryChanged(fc.getCurrentDirectory());
177
}
178
}
179
180
public void actionPerformed(ActionEvent e) {
181
JToggleButton b = (JToggleButton)e.getSource();
182
for (int i=0; i<buttons.length; i++) {
183
if (b == buttons[i]) {
184
fc.setCurrentDirectory(files[i]);
185
break;
186
}
187
}
188
}
189
190
public Dimension getPreferredSize() {
191
Dimension min = super.getMinimumSize();
192
Dimension pref = super.getPreferredSize();
193
int h = min.height;
194
if (buttons != null && buttons.length > 0 && buttons.length < 5) {
195
JToggleButton b = buttons[0];
196
if (b != null) {
197
int bh = 5 * (b.getPreferredSize().height + 1);
198
if (bh > h) {
199
h = bh;
200
}
201
}
202
}
203
if (h > pref.height) {
204
pref = new Dimension(pref.width, h);
205
}
206
return pref;
207
}
208
}
209
210