Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import org.netbeans.modules.debugger.jpda.models.AbstractObjectVariable;
import org.netbeans.modules.debugger.jpda.models.ShortenedStrings;
import org.netbeans.modules.debugger.jpda.models.ShortenedStrings.StringInfo;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
Expand All @@ -49,57 +46,31 @@
* @author Martin Entlicher
*/
class BigStringCustomEditor extends JPanel implements ActionListener {

static final int MAX_STRING_LENGTH = AbstractObjectVariable.MAX_STRING_LENGTH;

private final StringInfo shortenedInfo;
private final String fullString;

private BigStringCustomEditor(Component delegateCustomEditor, StringInfo shortenedInfo, int preferredShortLength) {

private BigStringCustomEditor(Component delegateCustomEditor, StringInfo shortenedInfo) {
this.shortenedInfo = shortenedInfo;
this.fullString = null;
int shortLength;
if (preferredShortLength >= 0) {
shortLength = preferredShortLength;
} else {
shortLength = shortenedInfo.getShortLength();
}
int shortLength = shortenedInfo.getShortenedString().length();
int fullLength = shortenedInfo.getLength();
init(delegateCustomEditor, shortLength, fullLength);
}

private BigStringCustomEditor(Component delegateCustomEditor,
String shortString, String fullString) {
this.shortenedInfo = null;
this.fullString = fullString;
init(delegateCustomEditor, shortString.length(), fullString.length());
}

static BigStringCustomEditor createIfBig(PropertyEditor propertyEditor, String value) {
ShortenedStrings.StringInfo shortenedInfo = ShortenedStrings.getShortenedInfo(value);

static BigStringCustomEditor createIfBig(PropertyEditor propertyEditor, StringInfo shortenedInfo) {
if (shortenedInfo != null) {
if (!(shortenedInfo.getShortLength() > MAX_STRING_LENGTH)) {
return new BigStringCustomEditor(propertyEditor.getCustomEditor(), shortenedInfo, -1);
} else {
String shortText = value.substring(0, MAX_STRING_LENGTH) + "...";
propertyEditor.setValue(shortText);
return new BigStringCustomEditor(propertyEditor.getCustomEditor(), shortenedInfo, shortText.length() - 3);
}
} else if (value.length() > MAX_STRING_LENGTH) {
String shortText = value.substring(0, MAX_STRING_LENGTH) + "...";
propertyEditor.setValue(shortText);
return new BigStringCustomEditor(propertyEditor.getCustomEditor(), shortText, value);
propertyEditor.setValue(shortenedInfo.getShortenedString() + "...");
return new BigStringCustomEditor(propertyEditor.getCustomEditor(), shortenedInfo);
} else {
return null;
}
}

private void init(Component contentComponent, int shortLength, int fullLength) {
setLayout(new java.awt.BorderLayout());
add(contentComponent, BorderLayout.CENTER);
add(createSavePanel(shortLength, fullLength), BorderLayout.SOUTH);
}

@NbBundle.Messages({"# {0} - number of displayed characters,",
"# {1} - total number of characters in the string,",
"MSG_TooLargeString=The String value is too large. Displaying {0} out of {1} characters."})
Expand All @@ -111,7 +82,7 @@ private JPanel createSavePanel(int shortLength, int fullLength) {
panel.setBorder(new EmptyBorder(10, 12, 0, 11));
return panel;
}

@NbBundle.Messages("BTN_SaveValueToFile=&Save Value to File")
private JButton createSaveButton() {
JButton button = new JButton();
Expand All @@ -128,42 +99,18 @@ public void actionPerformed(ActionEvent e) {
fchb.setTitle(Bundle.DLG_SaveToFile());
final File f = fchb.showSaveDialog();
if (f != null) {
new RequestProcessor(BigStringCustomEditor.class).post(new Runnable() {
@Override
public void run() {
save(f);
}
new RequestProcessor(BigStringCustomEditor.class).post(() -> {
save(f);
});
}
}

private void save(File f) {
Reader r;
if (shortenedInfo != null) {
r = shortenedInfo.getContent();
} else {
r = new StringReader(fullString);
}
Writer w = null;
try {
w = new FileWriter(f);
final char[] BUFFER = new char[65536];
int len;
while ((len = r.read(BUFFER)) > 0) {
w.write(BUFFER, 0, len);
}
try (Writer w = new FileWriter(f); Reader r = shortenedInfo.getContent()) {
r.transferTo(w);
} catch (IOException ioex) {
NotifyDescriptor nd = new NotifyDescriptor.Message(ioex.getLocalizedMessage(), NotifyDescriptor.WARNING_MESSAGE);
DialogDisplayer.getDefault().notifyLater(nd);
} finally {
if (w != null) {
try {
w.close();
} catch (IOException ex) {}
}
try {
r.close();
} catch (IOException ex) {}
}
}
}
Loading
Loading