Search in sources :

Example 31 with DefaultCaret

use of javax.swing.text.DefaultCaret in project megameklab by MegaMek.

the class UnitUtil method showBVCalculations.

public static void showBVCalculations(String bvText, JFrame frame) {
    HTMLEditorKit kit = new HTMLEditorKit();
    JEditorPane textPane = new JEditorPane("text/html", "");
    JScrollPane scroll = new JScrollPane();
    textPane.setEditable(false);
    textPane.setCaret(new DefaultCaret());
    textPane.setEditorKit(kit);
    scroll.setViewportView(textPane);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    textPane.setText(bvText);
    scroll.setVisible(true);
    JDialog jdialog = new JDialog();
    jdialog.add(scroll);
    Dimension size = new Dimension((int) (CConfig.getIntParam("WINDOWWIDTH") / 1.5), CConfig.getIntParam("WINDOWHEIGHT"));
    jdialog.setPreferredSize(size);
    jdialog.setMinimumSize(size);
    scroll.setPreferredSize(size);
    scroll.setMinimumSize(size);
    // text.setPreferredSize(size);
    jdialog.setLocationRelativeTo(frame);
    jdialog.setVisible(true);
    try {
        textPane.setSelectionStart(0);
        textPane.setSelectionEnd(0);
    } catch (Exception ex) {
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultCaret(javax.swing.text.DefaultCaret) JEditorPane(javax.swing.JEditorPane) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Dimension(java.awt.Dimension) JDialog(javax.swing.JDialog) LocationFullException(megamek.common.LocationFullException)

Example 32 with DefaultCaret

use of javax.swing.text.DefaultCaret in project megameklab by MegaMek.

the class UnitUtil method showUnitSpecs.

public static void showUnitSpecs(Entity unit, JFrame frame) {
    HTMLEditorKit kit = new HTMLEditorKit();
    MechView mechView = null;
    try {
        mechView = new MechView(unit, true);
    } catch (Exception e) {
    // error unit didn't load right. this is bad news.
    }
    StringBuffer unitSpecs = new StringBuffer("<html><body>");
    unitSpecs.append(mechView.getMechReadoutBasic());
    unitSpecs.append(mechView.getMechReadoutLoadout());
    unitSpecs.append("</body></html>");
    // System.err.println(unitSpecs.toString());
    JEditorPane textPane = new JEditorPane("text/html", "");
    JScrollPane scroll = new JScrollPane();
    textPane.setEditable(false);
    textPane.setCaret(new DefaultCaret());
    textPane.setEditorKit(kit);
    scroll.setViewportView(textPane);
    scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    scroll.getVerticalScrollBar().setUnitIncrement(20);
    textPane.setText(unitSpecs.toString());
    scroll.setVisible(true);
    JDialog jdialog = new JDialog();
    jdialog.add(scroll);
    /*
         * if (unit instanceof Mech) { EntityVerifier entityVerifier = new
         * EntityVerifier(new File("data/mechfiles/UnitVerifierOptions.xml"));
         * //$NON-NLS-1$ TestMech test = new TestMech((Mech)unit,
         * entityVerifier.mechOption, null); JEditorPane pane2 = new
         * JEditorPane();
         * pane2.setText(test.printWeightCalculation().toString());
         * jdialog.add(pane2); }
         */
    Dimension size = new Dimension(CConfig.getIntParam("WINDOWWIDTH") / 2, CConfig.getIntParam("WINDOWHEIGHT"));
    jdialog.setPreferredSize(size);
    jdialog.setMinimumSize(size);
    scroll.setPreferredSize(size);
    scroll.setMinimumSize(size);
    // text.setPreferredSize(size);
    jdialog.setLocationRelativeTo(frame);
    jdialog.setVisible(true);
    try {
        textPane.setSelectionStart(0);
        textPane.setSelectionEnd(0);
    } catch (Exception ex) {
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) MechView(megamek.common.MechView) DefaultCaret(javax.swing.text.DefaultCaret) JEditorPane(javax.swing.JEditorPane) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) Dimension(java.awt.Dimension) LocationFullException(megamek.common.LocationFullException) JDialog(javax.swing.JDialog)

Example 33 with DefaultCaret

use of javax.swing.text.DefaultCaret in project DistributedFractalNetwork by Budder21.

the class ClientTest method main.

public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException, IOException {
    System.out.println("client test");
    Layer.initializeFractalRegistry();
    Log log = new Log();
    log.setPrintStream(System.out);
    log.setLogLevel(Log.LEVEL_LOG);
    log.setPrintLevel(Log.LEVEL_LOG);
    Client c = new Client();
    System.out.println("display");
    String ip = JOptionPane.showInputDialog("IP Address");
    Thread t = null;
    t = new Thread(() -> {
        JFrame f = new JFrame();
        JTextArea text = new JTextArea(20, 25);
        JScrollPane scroll = new JScrollPane(text);
        DefaultCaret caret = (DefaultCaret) text.getCaret();
        caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
        scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
        scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        f.setContentPane(scroll);
        f.pack();
        f.setLocationRelativeTo(null);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        while (true) {
            text.setText(log.getLog());
            try {
                t.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    });
    t.start();
    c.init(log, ip);
}
Also used : JScrollPane(javax.swing.JScrollPane) JTextArea(javax.swing.JTextArea) DefaultCaret(javax.swing.text.DefaultCaret) Log(util.Log) JFrame(javax.swing.JFrame)

Example 34 with DefaultCaret

use of javax.swing.text.DefaultCaret in project java-swing-tips by aterai.

the class LineCursorTextArea method updateUI.

// public LineCursorTextArea(String text, int rows, int columns) {
// super(text, rows, columns);
// }
@Override
public void updateUI() {
    super.updateUI();
    Caret caret = new DefaultCaret() {

        // [UnsynchronizedOverridesSynchronized]
        // Unsynchronized method damage overrides synchronized method in DefaultCaret
        @SuppressWarnings("PMD.AvoidSynchronizedAtMethodLevel")
        @Override
        protected synchronized void damage(Rectangle r) {
            if (Objects.nonNull(r)) {
                JTextComponent c = getComponent();
                x = 0;
                y = r.y;
                width = c.getSize().width;
                height = r.height;
                c.repaint();
            }
        }
    };
    // caret.setBlinkRate(getCaret().getBlinkRate());
    caret.setBlinkRate(UIManager.getInt("TextArea.caretBlinkRate"));
    setCaret(caret);
}
Also used : DefaultCaret(javax.swing.text.DefaultCaret) JTextComponent(javax.swing.text.JTextComponent) Caret(javax.swing.text.Caret) DefaultCaret(javax.swing.text.DefaultCaret)

Example 35 with DefaultCaret

use of javax.swing.text.DefaultCaret in project java-swing-tips by aterai.

the class LineCursorTextArea method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Caret c = getCaret();
    if (c instanceof DefaultCaret) {
        Graphics2D g2 = (Graphics2D) g.create();
        Rectangle r = SwingUtilities.calculateInnerArea(this, null);
        DefaultCaret caret = (DefaultCaret) c;
        int y = caret.y + caret.height - 1;
        g2.setPaint(LINE_COLOR);
        g2.drawLine(r.x, y, (int) r.getMaxX(), y);
        g2.dispose();
    }
}
Also used : DefaultCaret(javax.swing.text.DefaultCaret) Caret(javax.swing.text.Caret) DefaultCaret(javax.swing.text.DefaultCaret)

Aggregations

DefaultCaret (javax.swing.text.DefaultCaret)50 JScrollPane (javax.swing.JScrollPane)15 JTextArea (javax.swing.JTextArea)12 Dimension (java.awt.Dimension)8 JPanel (javax.swing.JPanel)8 JLabel (javax.swing.JLabel)7 Caret (javax.swing.text.Caret)7 BorderLayout (java.awt.BorderLayout)5 ActionEvent (java.awt.event.ActionEvent)5 JButton (javax.swing.JButton)5 ActionListener (java.awt.event.ActionListener)4 FocusEvent (java.awt.event.FocusEvent)4 JDialog (javax.swing.JDialog)4 JFrame (javax.swing.JFrame)4 LocationFullException (megamek.common.LocationFullException)4 FocusListener (java.awt.event.FocusListener)3 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)3 Color (java.awt.Color)2 Font (java.awt.Font)2 Point (java.awt.Point)2