Search in sources :

Example 36 with DefaultCaret

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);
}
Also used : DefaultCaret(javax.swing.text.DefaultCaret) JTextComponent(javax.swing.text.JTextComponent) Caret(javax.swing.text.Caret) DefaultCaret(javax.swing.text.DefaultCaret)

Example 37 with DefaultCaret

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);
}
Also used : DefaultCaret(javax.swing.text.DefaultCaret) Caret(javax.swing.text.Caret) DefaultCaret(javax.swing.text.DefaultCaret)

Example 38 with DefaultCaret

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) BorderLayout(java.awt.BorderLayout) DefaultCaret(javax.swing.text.DefaultCaret) ActionListener(java.awt.event.ActionListener) EmptyBorder(javax.swing.border.EmptyBorder)

Example 39 with DefaultCaret

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) BorderLayout(java.awt.BorderLayout) DefaultCaret(javax.swing.text.DefaultCaret) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) JFrame(javax.swing.JFrame) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) File(java.io.File) Date(java.util.Date)

Example 40 with DefaultCaret

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;
}
Also used : 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