public ConsoleManager(GlowServer server) { this.server = server; // install Ansi code handler, which makes colors work on Windows AnsiConsole.systemInstall(); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } // used until/unless gui is created consoleHandler = new FancyConsoleHandler(); // consoleHandler.setFormatter(new DateOutputFormatter(CONSOLE_DATE)); logger.addHandler(consoleHandler); // todo: why is this here? Runtime.getRuntime().addShutdownHook(new ServerShutdownThread()); // reader must be initialized before standard streams are changed try { reader = new ConsoleReader(); } catch (IOException ex) { logger.log(Level.SEVERE, "Exception initializing console reader", ex); } reader.addCompleter(new CommandCompleter()); // set system output streams System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO), true)); System.setErr(new PrintStream(new LoggerOutputStream(Level.WARNING), true)); }
private void redirectIO() { // redirect std I/O to console and problems: // > System.out => console // > System.err => problems // > console => System.in System.setOut(consoleView.getOutputStream()); System.setErr(problemsView.getOutputStream()); // redirect input from console to System.in System.setIn(consoleView.getInputStream()); }
protected static Logger setupLogger() { final Logger logger = Utils.getLogger(); File logDirectory = new File(Utils.getLauncherDirectory(), "logs"); if (!logDirectory.exists()) { logDirectory.mkdir(); } File logs = new File(logDirectory, "lovelauncher_%D.log"); RotatingFileHandler fileHandler = new RotatingFileHandler(logs.getPath()); fileHandler.setFormatter(new TechnicLogFormatter()); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(fileHandler); SpoutcraftLauncher.handler = fileHandler; if (params != null && !params.isDebugMode()) { logger.setUseParentHandlers(false); System.setOut(new PrintStream(new LoggerOutputStream(console, Level.INFO, logger), true)); System.setErr(new PrintStream(new LoggerOutputStream(console, Level.SEVERE, logger), true)); } Thread.setDefaultUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { logger.log(Level.SEVERE, "Unhandled Exception in " + t, e); if (errorDialog == null) { LauncherFrame frame = null; try { frame = Launcher.getFrame(); } catch (Exception ex) { // This can happen if we have a very early crash- before Launcher initializes } errorDialog = new ErrorDialog(frame, e); errorDialog.setVisible(true); } } }); return logger; }
private void createUIComponents() { displayArea = new JEditorPane("text/html", ""); displayArea.setEditable(false); kit = new HTMLEditorKit(); displayArea.setEditorKit(kit); JScrollPane scrollPane = new JScrollPane(displayArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); logType = ELogType.valueOf(SettingsUtils.getValue(ESetting.LOGTYPE)); refreshLogs(); Logger.addListener(this); System.setOut(new OutputOverride(System.out, LogLevel.INFO)); System.setErr(new OutputOverride(System.err, LogLevel.ERROR)); try { Logger.addListener(new LogWriter(new File(launcherLogFile))); } catch (IOException e1) { Logger.logError(e1.getMessage(), e1); } }
private void redirectSystemStreams() { OutputStream out = new OutputStream() { @Override public void write(int b) throws IOException { updateTextArea(String.valueOf((char) b)); } @Override public void write(byte[] b, int off, int len) throws IOException { updateTextArea(new String(b, off, len)); } @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); } }; System.setOut(new PrintStream(out, true)); System.setErr(new PrintStream(out, true)); }
public static void main() { // Main frame = new JFrame("Java Playground"); frame.setSize(640, 480); // Make sure the divider is properly resized frame.addComponentListener( new ComponentAdapter() { public void componentResized(ComponentEvent c) { splitter.setDividerLocation(.8); } }); // Make sure the JVM is reset on close frame.addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent w) { new FrameAction().kill(); } }); // Setting up the keybinding // Ctrl+k or Cmd+k -> compile bind(KeyEvent.VK_K); // Ctrl+e or Cmd+e -> console bind(KeyEvent.VK_E); // Save, New file, Open file, Print. // Currently UNUSED until I figure out how normal java files and playground files will // interface. bind(KeyEvent.VK_S); bind(KeyEvent.VK_N); bind(KeyEvent.VK_O); bind(KeyEvent.VK_P); // Binds the keys to the action defined in the FrameAction class. frame.getRootPane().getActionMap().put("console", new FrameAction()); // The main panel for typing code in. text = new JTextPane(); textScroll = new JScrollPane(text); textScroll.setBorder(null); textScroll.setPreferredSize(new Dimension(640, 480)); // Document with syntax highlighting. Currently unfinished. doc = text.getStyledDocument(); doc.addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent d) {} public void insertUpdate(DocumentEvent d) {} public void removeUpdate(DocumentEvent d) {} }); ((AbstractDocument) doc).setDocumentFilter(new NewLineFilter()); // The output log; a combination compiler warning/error/runtime error/output log. outputText = new JTextPane(); outputScroll = new JScrollPane(outputText); outputScroll.setBorder(null); // "Constant" for the error font error = new SimpleAttributeSet(); error.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE); error.addAttribute(StyleConstants.Foreground, Color.RED); // "Constant" for the warning message font warning = new SimpleAttributeSet(); warning.addAttribute(StyleConstants.CharacterConstants.Italic, Boolean.TRUE); warning.addAttribute(StyleConstants.Foreground, Color.PINK); // "Constant" for the debugger error font progErr = new SimpleAttributeSet(); progErr.addAttribute(StyleConstants.Foreground, Color.BLUE); // Print streams to redirect System.out and System.err. out = new TextOutputStream(outputText, null); err = new TextOutputStream(outputText, error); System.setOut(new PrintStream(out)); System.setErr(new PrintStream(err)); // Sets up the output log outputText.setEditable(false); outputScroll.setVisible(true); // File input/output setup chooser = new JFileChooser(); // Setting up miscellaneous stuff compiler = ToolProvider.getSystemJavaCompiler(); JVMrunning = false; redirectErr = null; redirectOut = null; redirectIn = null; // Sets up the splitter pane and opens the program up splitter = new JSplitPane(JSplitPane.VERTICAL_SPLIT, textScroll, outputScroll); consoleDisplayed = false; splitter.remove(outputScroll); // Initially hides terminal until it is needed splitter.setOneTouchExpandable(true); frame.add(splitter); frame.setVisible(true); // Sets the divider to the proper one, for debugging // splitter.setDividerLocation(.8); }
public UServerManager() { try { ULogoWindow logow = new ULogoWindow(); logow.setVisible(true); Thread.sleep(2500); logow.dispose(); } catch (Exception ex) { ex.printStackTrace(); } fParam.setConnectionType(UParameters.CONNECTION_TYPE_NETWORK); fParamDialog = new UServerManagerParamDialog(); fParamDialog.setLocationRelativeTo((Frame) null); fParamDialog.setVisible(true); if (!fParamDialog.getStatus()) { System.exit(0); // 以下の部分はサーバの初期化による出力を拾えないための方策. // 非常にまずいが仕方ない.標準出力タブは必ず入れる. } System.setOut(UParameters.fPrintStream); fUpdateTimer = new javax.swing.Timer(fInterval * 1000, this); fUpdateTimer.setInitialDelay(0); fServer = new UMartNetwork( fParam.getMemberLog(), fParam.getPriceInfoDB(), fParam.getStartPoint(), fParam.getSeed(), fParam.getDays(), fParam.getBoardPerDay(), fParamNet.getPort()); if (fParam.isLogCreate()) { try { fServer.initLog(); } catch (IOException ioex) { JOptionPane.showMessageDialog( null, fRb.getString("ERROR_CANNOT_CREATE_LOGS"), fRb.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); System.exit(5); } catch (Exception ex) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); JOptionPane.showMessageDialog( null, fRb.getString("ERROR_FATAL") + "\n" + sw.toString(), fRb.getString("ERROR_DIALOG_TITLE"), JOptionPane.ERROR_MESSAGE); System.exit(5); } } fServer.startLoginManager(); initAgents(fParam.getMachineAgentArray()); fGui = new UServerManagerMainWindow(this, fParam.getTabs()); fParam.setMainComponet(fGui); fGui.setTimer(fUpdateTimer); fGui.mainImpl(); ActionListener guiUpdater = new ActionListener() { public void actionPerformed(ActionEvent e) { fGui.gUpdate(); } }; fGuiUpdateTimer = new javax.swing.Timer(TIMER_INTERVAL * 1000, guiUpdater); fGuiUpdateTimer.start(); // 1日目の1回目の注文期間に進めておく fUpdateTimer.setRepeats(false); fUpdateTimer.start(); }