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) {
}
}
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) {
}
}
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);
}
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);
}
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();
}
}
Aggregations