/** Override JTextField's paint method to show progress information. */ @Override public void paint(Graphics g) { super.paint(g); if (progressValue > 0) { g.setColor(progressColor); g.fillRect(0, 0, (int) (getWidth() * progressValue / (float) 100), getHeight()); } }
public void paint(Graphics g) { super.paint(g); if (!isEditing) return; Dimension psize = getPreferredSize(); if (isFocused) g.setColor(Color.yellow); else g.setColor(Color.green); g.drawLine(0, 0, psize.width, 0); g.drawLine(0, 0, 0, psize.height); g.drawLine(0, psize.height - 1, psize.width - 1, psize.height - 1); g.drawLine(psize.width - 1, 0, psize.width - 1, psize.height - 1); }
@Override public void paint(Graphics g) { super.paint(g); if (getText().length() == 0) { int h = getHeight(); ((Graphics2D) g) .setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); Insets ins = getInsets(); FontMetrics fm = g.getFontMetrics(); int c0 = getBackground().getRGB(); int c1 = getForeground().getRGB(); int m = 0xfefefefe; int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1); g.setColor(new Color(c2, true)); g.drawString(_hint, ins.left, h / 2 + fm.getAscent() / 2 - 2); } }
public void startGui() { JTerminalListener listener = new JTerminalListener(); jFrame = new JFrame("Glowstone"); jTerminal = new JTerminal(); jInput = new JTextField(80) { @Override public void setBorder(Border border) {} }; jInput.paint(null); jInput.setFont(new Font("Monospaced", Font.PLAIN, 12)); jInput.setBackground(Color.BLACK); jInput.setForeground(Color.WHITE); jInput.setMargin(new Insets(0, 0, 0, 0)); jInput.addKeyListener(listener); JLabel caret = new JLabel("> "); caret.setFont(new Font("Monospaced", Font.PLAIN, 12)); caret.setForeground(Color.WHITE); JPanel ipanel = new JPanel(); ipanel.add(caret, BorderLayout.WEST); ipanel.add(jInput, BorderLayout.EAST); ipanel.setBorder(BorderFactory.createEmptyBorder()); ipanel.setBackground(Color.BLACK); ipanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); ipanel.setSize(jTerminal.getWidth(), ipanel.getHeight()); jFrame.getContentPane().add(jTerminal, BorderLayout.NORTH); jFrame.getContentPane().add(ipanel, BorderLayout.SOUTH); jFrame.addWindowListener(listener); jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); jFrame.setLocationRelativeTo(null); jFrame.pack(); jFrame.setVisible(true); sender = new ColoredCommandSender(); logger.removeHandler(consoleHandler); logger.addHandler( new StreamHandler(new TerminalOutputStream(), new DateOutputFormatter(CONSOLE_DATE))); }
@Override public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension d = getSize(); g2.setColor(Color.WHITE); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.fillRoundRect(0, 0, d.width, d.height, 16, 16); int progressX = maxProgress > 0 ? (d.width * currentProgress / maxProgress) : 0; int bgProgressX = maxBackgroundProgress > 0 ? (d.width * currentBackgroundProgress / maxBackgroundProgress) : 0; int thirdHeight = d.height / 3; Paint oldPaint = g2.getPaint(); if (bgProgressX > 0) { GradientPaint pt = new GradientPaint(0, 0, TOP_BG_COLOR, 0, thirdHeight, MID_BG_COLOR); GradientPaint pb = new GradientPaint(0, d.height, BOT_BG_COLOR, 0, thirdHeight, MID_BG_COLOR); g2.setPaint(pt); g2.fillRoundRect(0, 0, bgProgressX, d.height, 16, 16); // g2bi.setPaint(pb); // g2bi.fillRect(0, thirdHeight, bgProgressX, d.height); } if (progressX > 0) { GradientPaint pt = new GradientPaint(0, 0, TOP_COLOR, 0, thirdHeight, MID_COLOR); GradientPaint pb = new GradientPaint(0, d.height, BOT_COLOR, 0, thirdHeight, MID_COLOR); g2.setPaint(pt); g2.fillRoundRect(0, 0, progressX, d.height, 16, 16); // g2bi.setPaint(pb); // g2bi.fillRect(0, thirdHeight, progressX, d.height); } g2.setPaint(oldPaint); super.paint(g); }
public void paint(Graphics g) { super.paint(g); if (this == selComp) { setBackground(vLightBlue); setEditable(true); SwingUtilities.invokeLater( new Runnable() { public void run() { requestFocusInWindow(); setEnabled(true); getCaret().setVisible(true); } }); } else { setBackground(Color.WHITE); setEditable(false); getCaret().setVisible(false); } }
public ConsoleManager(GlowServer server, String mode) { this.server = server; if (mode.equalsIgnoreCase("gui")) { JTerminalListener listener = new JTerminalListener(); jFrame = new JFrame("Glowstone"); jTerminal = new JTerminal(); jInput = new JTextField(80) { @Override public void setBorder(Border border) {} }; jInput.paint(null); jInput.setFont(new Font("Monospaced", Font.PLAIN, 12)); jInput.setBackground(Color.BLACK); jInput.setForeground(Color.WHITE); jInput.setMargin(new Insets(0, 0, 0, 0)); jInput.addKeyListener(listener); JLabel caret = new JLabel("> "); caret.setFont(new Font("Monospaced", Font.PLAIN, 12)); caret.setForeground(Color.WHITE); JPanel ipanel = new JPanel(); ipanel.add(caret, BorderLayout.WEST); ipanel.add(jInput, BorderLayout.EAST); ipanel.setBorder(BorderFactory.createEmptyBorder()); ipanel.setBackground(Color.BLACK); ipanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); ipanel.setSize(jTerminal.getWidth(), ipanel.getHeight()); jFrame.getContentPane().add(jTerminal, BorderLayout.NORTH); jFrame.getContentPane().add(ipanel, BorderLayout.SOUTH); jFrame.addWindowListener(listener); jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); jFrame.setLocationRelativeTo(null); jFrame.pack(); jFrame.setVisible(true); } else if (mode.equalsIgnoreCase("jline")) { jLine = true; } consoleHandler = new FancyConsoleHandler(); String logFile = server.getLogFile(); if (new File(logFile).getParentFile() != null) { new File(logFile).getParentFile().mkdirs(); } fileHandler = new RotatingFileHandler(logFile); consoleHandler.setFormatter(new DateOutputFormatter(new SimpleDateFormat("HH:mm:ss"))); fileHandler.setFormatter(new DateOutputFormatter(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"))); Logger logger = Logger.getLogger(""); for (Handler h : logger.getHandlers()) { logger.removeHandler(h); } logger.addHandler(consoleHandler); logger.addHandler(fileHandler); try { reader = new ConsoleReader(); } catch (IOException ex) { server .getLogger() .log(Level.SEVERE, "Exception inintializing console reader: {0}", ex.getMessage()); ex.printStackTrace(); } Runtime.getRuntime().addShutdownHook(new ServerShutdownThread()); System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO), true)); System.setErr(new PrintStream(new LoggerOutputStream(Level.SEVERE), true)); }