use of javax.swing.text.DefaultCaret in project java-swing-tips by aterai.
the class HighlightCursorTextArea method updateUI.
@Override
public void updateUI() {
super.updateUI();
setOpaque(false);
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 HighlightCursorTextArea method paintComponent.
@Override
protected void paintComponent(Graphics g) {
Caret c = getCaret();
if (c instanceof DefaultCaret) {
Graphics2D g2 = (Graphics2D) g.create();
DefaultCaret caret = (DefaultCaret) c;
Rectangle r = SwingUtilities.calculateInnerArea(this, rect);
r.y = caret.y;
r.height = caret.height;
g2.setPaint(LINE_COLOR);
g2.fill(r);
g2.dispose();
}
super.paintComponent(g);
}
use of javax.swing.text.DefaultCaret in project Orthanc_Tools by salimkanoun.
the class Monitoring_GUI method buildCDPanel.
private JPanel buildCDPanel() {
// On prends les settings du registery
jPrefer = Preferences.userNodeForPackage(Burner_Settings.class);
jPrefer = jPrefer.node("CDburner");
CD_Burner.fijiDirectory = jPrefer.get("fijiDirectory", null);
CD_Burner.epsonDirectory = jPrefer.get("epsonDirectory", null);
CD_Burner.labelFile = jPrefer.get("labelFile", null);
CD_Burner.dateFormatChoix = jPrefer.get("DateFormat", null);
JPanel contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
JTextArea textArea = new JTextArea();
textArea.setRows(5);
DefaultCaret caret = (DefaultCaret) textArea.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setViewportView(textArea);
contentPane.add(scrollPane, BorderLayout.CENTER);
JPanel panel = new JPanel();
contentPane.add(panel, BorderLayout.SOUTH);
btnStartMonitoring = new JButton("Start monitoring");
btnStartMonitoring.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (CD_Burner.epsonDirectory == null || CD_Burner.fijiDirectory == null || CD_Burner.labelFile == null || CD_Burner.dateFormatChoix == null) {
// Message d'erreur doit faire le set de output folder
JOptionPane.showMessageDialog(null, "Go to settings Menu to set missing paths", "Set directories and date format", JOptionPane.ERROR_MESSAGE);
} else {
textArea.append("Monitoring Orthanc \n");
// On ouvre le watcher dans un nouveau thread pour ne pas bloquer l'interface
background = new Thread(new Runnable() {
public void run() {
cdBurner.watchOrthancStableStudies();
/*try {
//SK ICI A IMPLEMENTER
// Remplacer par le Watch API
//cdBurner.watchFolder();
} catch (IOException | InterruptedException | ParseException e) {
e.printStackTrace();
}*/
}
});
background.start();
// On grise le boutton pour empecher la creation d'un nouveau watcher
btnStartMonitoring.setEnabled(false);
btnStopMonitoring.setEnabled(true);
}
}
});
JButton btnSettings = new JButton("Settings");
btnSettings.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Burner_Settings settings = new Burner_Settings();
settings.setVisible(true);
settings.setModal(true);
// On refresh les changement de variable � la fin de l'operation
CD_Burner.fijiDirectory = jPrefer.get("fijiDirectory", null);
CD_Burner.epsonDirectory = jPrefer.get("epsonDirectory", null);
CD_Burner.labelFile = jPrefer.get("labelFile", null);
CD_Burner.dateFormatChoix = jPrefer.get("DateFormat", null);
}
});
panel.add(btnSettings);
panel.add(btnStartMonitoring);
btnStopMonitoring = new JButton("Stop Monitoring");
btnStopMonitoring.setEnabled(false);
btnStopMonitoring.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
background.interrupt();
textArea.append("Monitoring Terminated \n");
btnStartMonitoring.setEnabled(true);
btnStopMonitoring.setEnabled(false);
}
});
panel.add(btnStopMonitoring);
JPanel Title = new JPanel();
contentPane.add(Title, BorderLayout.NORTH);
JLabel lblCdburnerBySassa = new JLabel("CD Burner Activity");
Title.add(lblCdburnerBySassa);
return contentPane;
}
use of javax.swing.text.DefaultCaret in project Orthanc_Tools by salimkanoun.
the class VueRest method showConsoleFrame.
/**
* Create GUI to display log message during retrieve operations
*/
private void showConsoleFrame() {
JFrame console = new JFrame();
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
console.add(panel);
JScrollPane scrollPane = new JScrollPane();
textAreaConsole = new JTextArea(10, 80);
textAreaConsole.setAutoscrolls(true);
DefaultCaret caret = (DefaultCaret) textAreaConsole.getCaret();
caret.setUpdatePolicy(DefaultCaret.OUT_BOTTOM);
scrollPane.setViewportView(textAreaConsole);
panel.add(scrollPane, BorderLayout.CENTER);
JButton btnCsvRetrieveReport = new JButton("Save To CSV");
btnCsvRetrieveReport.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JFileChooser csvReport = new JFileChooser();
csvReport.setFileSelectionMode(JFileChooser.FILES_ONLY);
csvReport.setSelectedFile(new File("Report_AutoRetrieve_" + df.format(new Date()) + ".csv"));
int ok = csvReport.showSaveDialog(null);
if (ok == JFileChooser.APPROVE_OPTION) {
AutoQueryResultTableDialog.writeCSV(textAreaConsole.getText(), csvReport.getSelectedFile().getAbsolutePath().toString());
}
}
});
JPanel button = new JPanel();
btnCsvRetrieveReport.setToolTipText("Set Folder to generate report of AutoQuery");
button.add(btnCsvRetrieveReport);
panel.add(button, BorderLayout.SOUTH);
console.pack();
console.setLocationRelativeTo(this);
console.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
console.setVisible(true);
}
use of javax.swing.text.DefaultCaret in project chatty by chatty.
the class DebugWindow method createLogArea.
private static JTextArea createLogArea() {
// Caret to prevent scrolling
DefaultCaret caret = new DefaultCaret();
caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
JTextArea text = new JTextArea();
text.setEditable(false);
text.setFont(Font.decode(Font.MONOSPACED));
text.setCaret(caret);
return text;
}
Aggregations