![JAR search and dependency download from the Maven repository](/logo.png)
org.freedesktop.dbus.viewer.TabbedSaveAction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dbus-java Show documentation
Show all versions of dbus-java Show documentation
Slightly improved version of the Java DBus library
provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/).
Changes:
- Fixed lot's of Java warnings
- Fixed broken 'Gettext' feature (Exceptions on unsupported languages, usage of "_" as method name).
- Renamed some classes/methods/variables to comply with Java naming scheme.
- Removed usage of proprietary logger and replaced it with sl4fj.
- Renamed/refactored some parts to be more 'Java' like (e.g. naming, shadowing)
- Fixed problems with DbusConnection.getConnection(SESSION) when using display export (e.g. SSH X11 forward)
/*
D-Bus Java Viewer
Copyright (c) 2006 Peter Cox
This program is free software; you can redistribute it and/or modify it
under the terms of either the GNU Lesser General Public License Version 2 or the
Academic Free Licence Version 2.1.
Full licence texts are included in the COPYING file with this program.
*/
package org.freedesktop.dbus.viewer;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.text.JTextComponent;
abstract class TabbedSaveAction extends AbstractAction implements Iterable {
private static final long serialVersionUID = -1L;
/** File chooser component.
* Make static so that previous save location is stored
*/
private static JFileChooser chooser;
// CHECKSTYLE:OFF
protected final JTabbedPane tabbedPane;
// CHECKSTYLE:ON
protected TabbedSaveAction(JTabbedPane _tabbedPane) {
super();
this.tabbedPane = _tabbedPane;
}
protected TabbedSaveAction(JTabbedPane _tabbedPane, String _name) {
super(_name);
this.tabbedPane = _tabbedPane;
}
/** Get the text file object associated with the supplied index
* @param index The tabbed pane index
* @return The text file object for the referenced tab
*/
protected TextFile getTextFile(int index) {
JScrollPane scrollPane = (JScrollPane) tabbedPane.getComponentAt(index);
JTextComponent textComponent = (JTextComponent) scrollPane.getViewport().getView();
final String sourceCode = textComponent.getText();
final String fileName = getFileName(index);
TextFile textFile = new TextFile(fileName, sourceCode);
return textFile;
}
/** Get the file name for the supplied index
* @param index The tabbed pane index
* @return The file name for the referenced tab
*/
protected String getFileName(int index) {
return (index > -1) ? tabbedPane.getTitleAt(index) : "";
}
/** {@inheritDoc} */
@Override
public final void actionPerformed(ActionEvent e) {
if (chooser == null) {
/** Occurs on event dispatch thread, so no problems with lazy static init here */
chooser = new JFileChooser();
}
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogTitle("Select parent directory for saving");
int result = chooser.showDialog(tabbedPane, "Select");
if (result == JFileChooser.APPROVE_OPTION) {
File parentDirectory = chooser.getSelectedFile();
if (parentDirectory.exists() || parentDirectory.mkdirs()) {
if (parentDirectory.canWrite()) {
Runnable runnable = new FileSaver(tabbedPane, parentDirectory, this);
new Thread(runnable).start();
} else {
JOptionPane.showMessageDialog(tabbedPane, "Could not write to parent directory", "Invalid Parent Directory", JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(tabbedPane, "Could not access parent directory", "Invalid Parent Directory", JOptionPane.ERROR_MESSAGE);
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy