in batik-svgbrowser/src/main/java/org/apache/batik/apps/svgbrowser/PreferenceDialog.java [913:1072]
protected JPanel buildStylesheetPanel() {
JGridBagPanel.InsetsManager im = new JGridBagPanel.InsetsManager() {
protected Insets i1 = new Insets(5, 5, 0, 0);
protected Insets i2 = new Insets(5, 0, 0, 0);
protected Insets i3 = new Insets(0, 5, 0, 0);
protected Insets i4 = new Insets(0, 0, 0, 0);
public Insets getInsets(int x, int y) {
if (y >= 1 && y <= 5) {
return x == 0 ? i2 : i1;
}
return x == 0 ? i4 : i3;
}
};
JGridBagPanel p = new JGridBagPanel(im);
p.setBorder(BorderFactory.createEmptyBorder(16, 16, 16, 16));
userStylesheetEnabled = new JCheckBox(Resources.getString(PREFERENCE_KEY_LABEL_ENABLE_USER_STYLESHEET));
userStylesheetEnabled.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
boolean b = userStylesheetEnabled.isSelected();
userStylesheetLabel.setEnabled(b);
userStylesheet.setEnabled(b);
userStylesheetBrowse.setEnabled(b);
}
});
userStylesheetLabel = new JLabel(Resources.getString(PREFERENCE_KEY_LABEL_USER_STYLESHEET));
userStylesheet = new JTextField();
userStylesheetBrowse = new JButton(Resources.getString(PREFERENCE_KEY_LABEL_BROWSE));
userStylesheetBrowse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
File f = null;
if (Platform.isOSX) {
FileDialog fileDialog =
new FileDialog
((Frame) getOwner(),
Resources.getString(PREFERENCE_KEY_BROWSE_TITLE));
fileDialog.setVisible(true);
String filename = fileDialog.getFile();
if (filename != null) {
String dirname = fileDialog.getDirectory();
f = new File(dirname, filename);
}
} else {
JFileChooser fileChooser = new JFileChooser(new File("."));
fileChooser.setDialogTitle
(Resources.getString(PREFERENCE_KEY_BROWSE_TITLE));
fileChooser.setFileHidingEnabled(false);
int choice =
fileChooser.showOpenDialog(PreferenceDialog.this);
if (choice == JFileChooser.APPROVE_OPTION) {
f = fileChooser.getSelectedFile();
}
}
if (f != null) {
try {
userStylesheet.setText(f.getCanonicalPath());
} catch (IOException ex) {
}
}
}
});
JLabel mediaLabel = new JLabel(Resources.getString(PREFERENCE_KEY_LABEL_CSS_MEDIA_TYPES));
mediaLabel.setVerticalAlignment(SwingConstants.TOP);
mediaList = new JList();
mediaList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
mediaList.setModel(mediaListModel);
mediaList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
updateMediaListButtons();
}
});
mediaListModel.addListDataListener(new ListDataListener() {
public void contentsChanged(ListDataEvent e) {
updateMediaListButtons();
}
public void intervalAdded(ListDataEvent e) {
updateMediaListButtons();
}
public void intervalRemoved(ListDataEvent e) {
updateMediaListButtons();
}
});
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBorder(BorderFactory.createLoweredBevelBorder());
scrollPane.getViewport().add(mediaList);
JButton addButton = new JButton(Resources.getString(PREFERENCE_KEY_LABEL_ADD));
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
CSSMediaPanel.AddMediumDialog dialog =
new CSSMediaPanel.AddMediumDialog(PreferenceDialog.this);
dialog.pack();
dialog.setVisible(true);
if (dialog.getReturnCode() ==
CSSMediaPanel.AddMediumDialog.CANCEL_OPTION
|| dialog.getMedium() == null) {
return;
}
String medium = dialog.getMedium().trim();
if (medium.length() == 0 || mediaListModel.contains(medium)) {
return;
}
for (int i = 0;
i < mediaListModel.size() && medium != null;
++i) {
String s = (String) mediaListModel.getElementAt(i);
int c = medium.compareTo(s);
if (c == 0) {
medium = null;
} else if (c < 0) {
mediaListModel.insertElementAt(medium, i);
medium = null;
}
}
if (medium != null) {
mediaListModel.addElement(medium);
}
}
});
mediaListRemoveButton = new JButton(Resources.getString(PREFERENCE_KEY_LABEL_REMOVE));
mediaListRemoveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int index = mediaList.getSelectedIndex();
mediaList.clearSelection();
if (index >= 0) {
mediaListModel.removeElementAt(index);
}
}
});
mediaListClearButton = new JButton(Resources.getString(PREFERENCE_KEY_LABEL_CLEAR));
mediaListClearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mediaList.clearSelection();
mediaListModel.removeAllElements();
}
});
p.add(userStylesheetEnabled, 1, 0, 2, 1, WEST, NONE, 0, 0);
p.add(userStylesheetLabel, 0, 1, 1, 1, EAST, NONE, 0, 0);
p.add(userStylesheet, 1, 1, 1, 1, WEST, HORIZONTAL, 1, 0);
p.add(userStylesheetBrowse, 2, 1, 1, 1, WEST, HORIZONTAL, 0, 0);
p.add(mediaLabel, 0, 2, 1, 1, EAST, VERTICAL, 0, 0);
p.add(scrollPane, 1, 2, 1, 4, WEST, BOTH, 1, 1);
p.add(new JPanel(), 2, 2, 1, 1, WEST, BOTH, 0, 1);
p.add(addButton, 2, 3, 1, 1, SOUTHWEST, HORIZONTAL, 0, 0);
p.add(mediaListRemoveButton, 2, 4, 1, 1, SOUTHWEST, HORIZONTAL, 0, 0);
p.add(mediaListClearButton, 2, 5, 1, 1, SOUTHWEST, HORIZONTAL, 0, 0);
return p;
}