use of javax.swing.text.BadLocationException in project Openfire by igniterealtime.
the class Launcher method startApplication.
private synchronized void startApplication() {
if (openfired == null) {
try {
File windowsExe = new File(binDir, "openfired.exe");
File unixExe = new File(binDir, "openfired");
if (windowsExe.exists()) {
openfired = Runtime.getRuntime().exec(new String[] { windowsExe.toString() });
} else if (unixExe.exists()) {
openfired = Runtime.getRuntime().exec(new String[] { unixExe.toString() });
} else {
throw new FileNotFoundException();
}
} catch (Exception e) {
// Try one more time using the jar and hope java is on the path
try {
File libDir = new File(binDir.getParentFile(), "lib").getAbsoluteFile();
openfired = Runtime.getRuntime().exec(new String[] { "java", "-jar", new File(libDir, "startup.jar").toString() });
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null, "Launcher could not start,\n" + appName, "File not found", JOptionPane.ERROR_MESSAGE);
}
}
final SimpleAttributeSet styles = new SimpleAttributeSet();
SwingWorker<String, Void> inputWorker = new SwingWorker<String, Void>() {
@Override
public String doInBackground() {
if (openfired != null) {
// Get the input stream and read from it
try (InputStream in = openfired.getInputStream()) {
int c;
while ((c = in.read()) != -1) {
try {
StyleConstants.setFontFamily(styles, "courier new");
pane.getDocument().insertString(pane.getDocument().getLength(), "" + (char) c, styles);
} catch (BadLocationException e) {
// Ignore.
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
return "ok";
}
};
inputWorker.execute();
SwingWorker<String, Void> errorWorker = new SwingWorker<String, Void>() {
@Override
public String doInBackground() {
if (openfired != null) {
// Get the input stream and read from it
try (InputStream in = openfired.getErrorStream()) {
int c;
while ((c = in.read()) != -1) {
try {
StyleConstants.setForeground(styles, Color.red);
pane.getDocument().insertString(pane.getDocument().getLength(), "" + (char) c, styles);
} catch (BadLocationException e) {
// Ignore.
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
return "ok";
}
};
errorWorker.execute();
if (freshStart) {
try {
Thread.sleep(1000);
cardLayout.show(cardPanel, "running");
} catch (Exception ex) {
// Ignore.
}
freshStart = false;
} else {
// Clear Text
pane.setText("");
cardLayout.show(cardPanel, "running");
}
}
}
use of javax.swing.text.BadLocationException in project languagetool by languagetool-org.
the class ResultAreaHelper method setHeader.
private void setHeader(String txt) {
HTMLDocument d = (HTMLDocument) statusPane.getDocument();
Element e = d.getElement(HEADER);
try {
d.setInnerHTML(e, "<p class=\"grayed\">" + txt + "</p>");
} catch (BadLocationException ex) {
Tools.showError(ex);
} catch (IOException ex) {
Tools.showError(ex);
}
}
use of javax.swing.text.BadLocationException in project languagetool by languagetool-org.
the class ResultAreaHelper method setMain.
private void setMain(String html) {
HTMLDocument d = (HTMLDocument) statusPane.getDocument();
Element e = d.getElement(MAIN);
try {
d.setInnerHTML(e, html);
} catch (BadLocationException ex) {
Tools.showError(ex);
} catch (IOException ex) {
Tools.showError(ex);
}
}
use of javax.swing.text.BadLocationException in project processing by processing.
the class FindReplace method find.
// look for the next instance of the find string to be found
// once found, select it (and go to that line)
private boolean find(boolean wrap, boolean backwards) {
String searchTerm = findField.getText();
// this will catch "find next" being called when no search yet
if (searchTerm.length() != 0) {
String text = editor.getText();
// Started work on find/replace across tabs. These two variables store
// the original tab and selection position so that it knew when to stop
// rotating through.
Sketch sketch = editor.getSketch();
int tabIndex = sketch.getCurrentCodeIndex();
if (ignoreCase) {
searchTerm = searchTerm.toLowerCase();
text = text.toLowerCase();
}
int nextIndex;
if (!backwards) {
//int selectionStart = editor.textarea.getSelectionStart();
int selectionEnd = editor.getSelectionStop();
nextIndex = text.indexOf(searchTerm, selectionEnd);
if (nextIndex == -1 && wrap && !allTabs) {
// if wrapping, a second chance is ok, start from beginning
nextIndex = text.indexOf(searchTerm, 0);
} else if (nextIndex == -1 && allTabs) {
// For searching in all tabs, wrapping always happens.
int tempIndex = tabIndex;
// Look for searchterm in all tabs.
while (tabIndex <= sketch.getCodeCount() - 1) {
if (tabIndex == sketch.getCodeCount() - 1) {
// System.out.println("wrapping.");
tabIndex = -1;
} else if (tabIndex == sketch.getCodeCount() - 1) {
break;
}
try {
Document doc = sketch.getCode(tabIndex + 1).getDocument();
if (doc != null) {
// this thing has the latest changes
text = doc.getText(0, doc.getLength());
} else {
// not this thing.
text = sketch.getCode(tabIndex + 1).getProgram();
}
} catch (BadLocationException e) {
e.printStackTrace();
}
tabIndex++;
if (ignoreCase) {
text = text.toLowerCase();
}
nextIndex = text.indexOf(searchTerm, 0);
if (nextIndex != -1 || tabIndex == tempIndex) {
break;
}
}
// No tab switching should happen, restore tabIndex
if (nextIndex == -1) {
tabIndex = tempIndex;
}
}
} else {
//int selectionStart = editor.textarea.getSelectionStart();
int selectionStart = editor.getSelectionStart() - 1;
if (selectionStart >= 0) {
nextIndex = text.lastIndexOf(searchTerm, selectionStart);
} else {
nextIndex = -1;
}
if (wrap && !allTabs && nextIndex == -1) {
// if wrapping, a second chance is ok, start from the end
nextIndex = text.lastIndexOf(searchTerm);
} else if (nextIndex == -1 && allTabs) {
int tempIndex = tabIndex;
// Look for search term in previous tabs.
while (tabIndex >= 0) {
if (tabIndex == 0) {
//System.out.println("wrapping.");
tabIndex = sketch.getCodeCount();
} else if (tabIndex == 0) {
break;
}
try {
Document doc = sketch.getCode(tabIndex - 1).getDocument();
if (doc != null) {
// this thing has the latest changes
text = doc.getText(0, doc.getLength());
} else {
// not this thing.
text = sketch.getCode(tabIndex - 1).getProgram();
}
} catch (BadLocationException e) {
e.printStackTrace();
}
tabIndex--;
if (ignoreCase) {
text = text.toLowerCase();
}
nextIndex = text.lastIndexOf(searchTerm);
if (nextIndex != -1 || tabIndex == tempIndex) {
break;
}
}
// No tab switching should happen, restore tabIndex
if (nextIndex == -1) {
tabIndex = tempIndex;
}
}
}
if (nextIndex != -1) {
if (allTabs) {
sketch.setCurrentCode(tabIndex);
}
editor.setSelection(nextIndex, nextIndex + searchTerm.length());
} else {
//Toolkit.getDefaultToolkit().beep();
}
if (nextIndex != -1) {
setFound(true);
return true;
}
}
setFound(false);
return false;
}
use of javax.swing.text.BadLocationException in project processing by processing.
the class CompositionTextManager method insertFullWidthSpace.
/**
* Insert full width space
*/
public void insertFullWidthSpace() {
initialCaretPosition = textArea.getCaretPosition();
int layoutCaretPosition = initialCaretPosition;
try {
textArea.getDocument().insertString(layoutCaretPosition, " ", null);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
Aggregations