From: Ben Soares Date: Thu, 19 Oct 2023 20:06:00 +0000 (+0100) Subject: Merge branch 'patch/JAL-4298_synchronize_consoledoc' into bug/JAL-4298_java_console_c... X-Git-Tag: Release_2_11_3_0~3^2~37^2~6 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5e17ddc59003daff5f9933cf5710889bcdb9e856;hp=-c;p=jalview.git Merge branch 'patch/JAL-4298_synchronize_consoledoc' into bug/JAL-4298_java_console_causing_hang_at_startup --- 5e17ddc59003daff5f9933cf5710889bcdb9e856 diff --combined src/jalview/gui/Console.java index 631e0a2,9fe7195..7e8cbc6 --- a/src/jalview/gui/Console.java +++ b/src/jalview/gui/Console.java @@@ -53,7 -53,6 +53,7 @@@ import javax.swing.JTextArea import javax.swing.border.Border; import javax.swing.text.DefaultCaret; +import jalview.bin.Cache; import jalview.log.JLoggerI.LogLevel; import jalview.log.JLoggerLog4j; import jalview.log.JalviewAppender; @@@ -107,7 -106,7 +107,7 @@@ public class Console extends WindowAdap private JComboBox logLevelCombo = new JComboBox(); - protected LogLevel startingLogLevel = LogLevel.INFO; + protected LogLevel startingLogLevel = null; public Console() { @@@ -148,7 -147,6 +148,7 @@@ scrollPane.setBorder(noBorder); textArea.addMouseListener(new MouseAdapter() { + @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) @@@ -174,7 -172,6 +174,7 @@@ MessageManager.getString("label.copy_to_clipboard")); copyToClipboardButton.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { copyConsoleTextToClipboard(); @@@ -186,14 -183,12 +186,14 @@@ private Color fg = textArea.getForeground(); + @Override public void mousePressed(MouseEvent e) { textArea.setBackground(textArea.getSelectionColor()); textArea.setForeground(textArea.getSelectedTextColor()); } + @Override public void mouseReleased(MouseEvent e) { textArea.setBackground(bg); @@@ -217,35 -212,11 +217,35 @@@ // logLevelCombo.addItem(LogLevel.ERROR); // logLevelCombo.addItem(LogLevel.OFF); // set startingLogLevel - startingLogLevel = jalview.bin.Console.log == null ? LogLevel.INFO - : jalview.bin.Console.log.getLevel(); + if (jalview.bin.Console.log == null) + { + try + { + startingLogLevel = LogLevel + .valueOf(Cache.getDefault(Cache.JALVIEWLOGLEVEL, null)); + } catch (IllegalArgumentException e1) + { + jalview.bin.Console.debug( + "Invalid value for preference " + Cache.JALVIEWLOGLEVEL); + } catch (NullPointerException e2) + { + // no value in preferences + } finally + { + if (startingLogLevel == null) + { + startingLogLevel = LogLevel.INFO; + } + } + } + else + { + startingLogLevel = jalview.bin.Console.log.getLevel(); + } setChosenLogLevelCombo(); logLevelCombo.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { if (jalview.bin.Console.log != null) @@@ -342,7 -313,7 +342,7 @@@ boolean added = false; for (int i = 0; i < logLevelCombo.getItemCount(); i++) { - LogLevel l = (LogLevel) logLevelCombo.getItemAt(i); + LogLevel l = logLevelCombo.getItemAt(i); if (l.compareTo(setLogLevel) >= 0) { logLevelCombo.insertItemAt(setLogLevel, i); @@@ -504,32 -475,36 +504,32 @@@ */ public Console(Desktop desktop) { - this(desktop, true); - } - - /** - * attach a console to the desktop - the desktop will open it if requested. - * - * @param desktop - * @param showjconsole - * - if true, then redirect stdout immediately - */ - public Console(Desktop desktop, boolean showjconsole) - { parent = desktop; // window name - get x,y,width, height possibly scaled - Rectangle bounds = desktop.getLastKnownDimensions("JAVA_CONSOLE_"); - if (bounds == null) + Rectangle bounds = parent == null ? null + : parent.getLastKnownDimensions("JAVA_CONSOLE_"); + if (bounds != null) + { + frame = initFrame( + ChannelProperties.getProperty("app_name") + " Java Console", + bounds.width, bounds.height, bounds.x, bounds.y); + } + else if (parent != null && parent.getWidth() > 0 + && parent.getHeight() > 0) { frame = initFrame( ChannelProperties.getProperty("app_name") + " Java Console", - desktop.getWidth() / 2, desktop.getHeight() / 4, - desktop.getX(), desktop.getY()); + parent.getWidth() / 2, parent.getHeight() / 4, parent.getX(), + parent.getY()); } else { frame = initFrame( ChannelProperties.getProperty("app_name") + " Java Console", - bounds.width, bounds.height, bounds.x, bounds.y); + MIN_WIDTH, MIN_HEIGHT, 10, 10); } frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); - // desktop.add(frame); + // parent.add(frame); initConsole(false); LogLevel level = (LogLevel) logLevelCombo.getSelectedItem(); if (!Platform.isJS()) @@@ -562,7 -537,6 +562,7 @@@ pin.close(); } catch (Exception e) { + jalview.bin.Console.debug("pin.close() error", e); } try { @@@ -570,14 -544,12 +570,14 @@@ pin2.close(); } catch (Exception e) { + jalview.bin.Console.debug("pin2.close() error", e); } try { textAppender.join(10); } catch (Exception e) { + jalview.bin.Console.debug("textAppender.join(10) error", e); } } /* @@@ -637,14 -609,13 +637,14 @@@ { try { - this.wait(100); + this.wait(100); // ##### implicated BLOCKED if (pin.available() == 0) { trimBuffer(false); } } catch (InterruptedException ie) { + jalview.bin.Console.debug("pin.available() error", ie); } } @@@ -670,14 -641,13 +670,14 @@@ { try { - this.wait(100); + this.wait(100); // ##### implicated BLOCKED if (pin2.available() == 0) { trimBuffer(false); } } catch (InterruptedException ie) { + jalview.bin.Console.debug("pin.available() error", ie); } } while (pin2.available() != 0) @@@ -713,12 -683,16 +713,16 @@@ displayPipe = tmp; } // simply append whole buffer - textArea.append(replace.toString()); // ##### implicated BLOCKED - count += replace.length(); - if (count > byteslim) + synchronized (textArea.getDocument()) { - trimBuffer(false); + textArea.append(replace.toString()); + count += replace.length(); + if (count > byteslim) + { + trimBuffer(false); + } } - ++ } if (displayPipe.length() == 0) { @@@ -731,7 -705,6 +735,7 @@@ } } catch (InterruptedException e) { + jalview.bin.Console.debug("displayPipe.length() error", e); } } } @@@ -742,7 -715,7 +746,7 @@@ this.wait(100); } catch (InterruptedException e) { - + jalview.bin.Console.debug("this.wait(100) error", e); } } if (quit) @@@ -769,7 -742,6 +773,7 @@@ this.wait(1000); } catch (InterruptedException ie) { + jalview.bin.Console.debug("this.wait(1000) error", ie); } throw new NullPointerException( MessageManager.getString("exception.application_test_npe")); @@@ -813,7 -785,7 +817,7 @@@ + "\nTruncated...\n"; } catch (Exception e) { - e.printStackTrace(); + jalview.bin.Console.warn("textArea Exception", e); } } // trim the buffer @@@ -837,7 -809,7 +841,7 @@@ } } catch (Exception e) { - e.printStackTrace(); + jalview.bin.Console.warn("textArea Exception", e); } // lines = textArea.getLineCount(); }