@Override public synchronized void write(byte[] ba, int str, int len) { try { curLength += len; if (bytesEndWith(ba, str, len, LINE_SEP)) { lineLengths.addLast(new Integer(curLength)); curLength = 0; if (lineLengths.size() > maxLines) { textArea.replaceRange(null, 0, lineLengths.removeFirst().intValue()); } } for (int xa = 0; xa < 10; xa++) { try { textArea.append(new String(ba, str, len)); break; } catch ( Throwable thr) { // sometimes throws a java.lang.Error: Interrupted attempt to aquire write // lock if (xa == 9) { thr.printStackTrace(); } } } textArea.setCaretPosition(textArea.getText().length()); } catch (Throwable thr) { CharArrayWriter caw = new CharArrayWriter(); thr.printStackTrace(new PrintWriter(caw, true)); textArea.append(System.getProperty("line.separator", "\n")); textArea.append(caw.toString()); } }
public void valueChanged(ListSelectionEvent event) { if (table.getSelectedRow() == -1) textArea.setText(null); else { TableItem item = table.getTableItemAt(table.getSelectedRow()); textArea.setText(item.toString()); } textArea.setCaretPosition(0); }
/** * Updates all of the components in the panel to match that of the associated Artifact. * * @see #ArtifactView(Artifact, DataProvider) */ public void rebuild() { title.setText(SHTML + TITLE + elem.title + EHTML); donor.setText(SHTML + DONOR + elem.donor + EHTML); subDate.setText(SHTML + SUB_DATE + elem.subDate.toString() + EHTML); objDate.setText(SHTML + OBJ_DATE + elem.objDate.toString() + EHTML); medium.setText(SHTML + MEDIUM + elem.medium + EHTML); accNum.setText(SHTML + ACC_NUM + elem.accNum + EHTML); descView.setText(elem.desc); descView.setCaretPosition(0); validate(); }
private void showHelp(String help[]) { txtCommand.setText(help[0]); bHelp = true; pResult.removeAll(); pResult.add(txtResultScroll, BorderLayout.CENTER); pResult.doLayout(); txtResult.setText(help[1]); pResult.repaint(); txtCommand.requestFocus(); txtCommand.setCaretPosition(help[0].length()); }
public void actionPerformed(ActionEvent e) { // Handle open button action. if (e.getSource() == openButton) { int returnVal = fc.showOpenDialog(DirectorySize.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); // This is where a real application would open the file. ListSubDirectorySizes(file); } else { log.append("Open command cancelled by user." + newline); } log.setCaretPosition(log.getDocument().getLength()); // Handle save button action. } else if (e.getSource() == saveButton) { log.setText(""); // reset } }
// called by the Client to append text in the TextArea void append(String str) { chatArea.append(str); chatArea.setCaretPosition(chatArea.getText().length() - 1); }
public boolean loadSourceFile(File file) { boolean result = false; selectedPath = file.getParent(); BufferedReader sourceFile = null; String directoryPath = file.getParent(); String sourceName = file.getName(); int idx = sourceName.lastIndexOf("."); fileExt = idx == -1 ? "" : sourceName.substring(idx + 1); baseName = idx == -1 ? sourceName.substring(0) : sourceName.substring(0, idx); String basePath = directoryPath + File.separator + baseName; DataOptions.directoryPath = directoryPath; sourcePath = file.getPath(); AssemblerOptions.sourcePath = sourcePath; AssemblerOptions.listingPath = basePath + ".lst"; AssemblerOptions.objectPath = basePath + ".cd"; String var = System.getenv("ROPE_MACROS_DIR"); if (var != null && !var.isEmpty()) { File dir = new File(var); if (dir.exists() && dir.isDirectory()) { AssemblerOptions.macroPath = var; } else { AssemblerOptions.macroPath = directoryPath; } } else { AssemblerOptions.macroPath = directoryPath; } DataOptions.inputPath = AssemblerOptions.objectPath; DataOptions.outputPath = basePath + ".out"; DataOptions.readerPath = null; DataOptions.punchPath = basePath + ".pch"; DataOptions.tape1Path = basePath + ".mt1"; DataOptions.tape2Path = basePath + ".mt2"; DataOptions.tape3Path = basePath + ".mt3"; DataOptions.tape4Path = basePath + ".mt4"; DataOptions.tape5Path = basePath + ".mt5"; DataOptions.tape6Path = basePath + ".mt6"; this.setTitle("EDIT: " + sourceName); fileText.setText(sourcePath); if (dialog == null) { dialog = new AssemblerDialog(mainFrame, "Assembler options"); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension dialogSize = dialog.getSize(); dialog.setLocation( (screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2); } dialog.initialize(); AssemblerOptions.command = dialog.buildCommand(); sourceArea.setText(null); try { sourceFile = new BufferedReader(new FileReader(file)); String line; while ((line = sourceFile.readLine()) != null) { sourceArea.append(line + "\n"); } sourceArea.setCaretPosition(0); optionsButton.setEnabled(true); assembleButton.setEnabled(true); saveButton.setEnabled(true); setSourceChanged(false); undoMgr.discardAllEdits(); result = true; } catch (IOException ex) { ex.printStackTrace(); } finally { try { if (sourceFile != null) { sourceFile.close(); } } catch (IOException ignore) { } } return result; }
public SwingUpdaterUI(String oldBuildDesc, String newBuildDesc, InstallOperation operation) { myOperation = operation; myProcessTitle = new JLabel(" "); myProcessProgress = new JProgressBar(0, 100); myProcessStatus = new JLabel(" "); myCancelButton = new JButton(CANCEL_BUTTON_TITLE); myConsole = new JTextArea(); myConsole.setLineWrap(true); myConsole.setWrapStyleWord(true); myConsole.setCaretPosition(myConsole.getText().length()); myConsole.setTabSize(1); myConsolePane = new JPanel(new BorderLayout()); myConsolePane.add(new JScrollPane(myConsole)); myConsolePane.setBorder(BUTTONS_BORDER); myConsolePane.setVisible(false); myCancelButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doCancel(); } }); myFrame = new JFrame(); myFrame.setTitle(TITLE); myFrame.setLayout(new BorderLayout()); myFrame.getRootPane().setBorder(FRAME_BORDER); myFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); myFrame.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { doCancel(); } }); JPanel processPanel = new JPanel(); processPanel.setLayout(new BoxLayout(processPanel, BoxLayout.Y_AXIS)); processPanel.add(myProcessTitle); processPanel.add(myProcessProgress); processPanel.add(myProcessStatus); processPanel.add(myConsolePane); for (Component each : processPanel.getComponents()) { ((JComponent) each).setAlignmentX(Component.LEFT_ALIGNMENT); } JPanel buttonsPanel = new JPanel(); buttonsPanel.setBorder(BUTTONS_BORDER); buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS)); buttonsPanel.add(Box.createHorizontalGlue()); buttonsPanel.add(myCancelButton); myProcessTitle.setText("<html>Updating " + oldBuildDesc + " to " + newBuildDesc + "..."); myFrame.add(processPanel, BorderLayout.CENTER); myFrame.add(buttonsPanel, BorderLayout.SOUTH); myFrame.setMinimumSize(new Dimension(500, 50)); myFrame.pack(); myFrame.setLocationRelativeTo(null); myFrame.setVisible(true); myQueue.add( new UpdateRequest() { @Override public void perform() { doPerform(); } }); startRequestDispatching(); }
/* * @param String s - send s to output textArea */ public void setOutput(String s) { // if (debugBoardPanel) { bottomText.append("\n" + s); bottomText.setCaretPosition(bottomText.getDocument().getLength()); // } }
public void setup() { setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); title = new JLabel(SHTML + TITLE + elem.title + EHTML); gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; gbc.gridy = 4; gbc.gridx = 0; gbc.gridwidth = 2; gbc.gridheight = 1; gbc.weighty = 1.0; add(title, gbc); donor = new JLabel(SHTML + DONOR + elem.donor + EHTML); gbc.gridy = 5; add(donor, gbc); subDate = new JLabel(SHTML + SUB_DATE + elem.subDate.toString() + EHTML); gbc.gridy = 6; add(subDate, gbc); objDate = new JLabel(SHTML + OBJ_DATE + elem.objDate.toString() + EHTML); gbc.gridy = 7; add(objDate, gbc); medium = new JLabel(SHTML + MEDIUM + elem.medium + EHTML); gbc.gridy = 8; add(medium, gbc); accNum = new JLabel(SHTML + ACC_NUM + elem.accNum + EHTML); gbc.gridy = 9; add(accNum, gbc); desc = new JLabel(SHTML + DESC + EHTML); // gbc.anchor = GridBagConstraints.PAGE_START; gbc.insets = new Insets(0, 50, 0, 0); gbc.gridy = 4; gbc.gridx = 2; add(desc, gbc); descView = new JTextArea(); descView.setLineWrap(true); descView.setWrapStyleWord(true); descView.setEditable(false); descView.setText(elem.desc); descView.setFont(new Font("Times New Roman", Font.PLAIN, 13)); JScrollPane scrollPane = new JScrollPane(descView); scrollPane.setPreferredSize(new Dimension(225, 100)); // scrollPane.setBorder(null); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); descView.setCaretPosition(0); gbc.gridy = 5; gbc.gridheight = 4; gbc.gridx = 2; add(scrollPane, gbc); gbc.insets = null; gbc.gridy = 0; gbc.gridx = 0; gbc.gridwidth = 4; gbc.gridheight = 4; gbc.fill = GridBagConstraints.HORIZONTAL; gbc.insets = new Insets(0, 0, 10, 0); vpan = new V3DPanel(elem, provider); vpan.setPreferredSize(new Dimension(500, 300)); setBackground(BACKGROUND); add(vpan, gbc); validate(); }
/** Create an editor1 to represent the given document. */ protected JTextComponent createEditor() { JTextArea ed; ed = new JTextArea(notepadHeight, notepadWidth); ed.setCaretPosition(0); // aa return (ed); }