linux 에서의 파일 타입

OS/linux 2022. 5. 6. 15:36
반응형
#define S_IFMT  00170000    
#define S_IFSOCK 0140000    
#define S_IFLNK  0120000    
#define S_IFREG  0100000    
#define S_IFBLK  0060000    
#define S_IFDIR  0040000    
#define S_IFCHR  0020000    
#define S_IFIFO  0010000    
#define S_ISUID  0004000    
#define S_ISGID  0002000    
#define S_ISVTX  0001000    
    
#define S_ISLNK(m)  (((m) & S_IFMT) == S_IFLNK)    
#define S_ISREG(m)  (((m) & S_IFMT) == S_IFREG)    
#define S_ISDIR(m)  (((m) & S_IFMT) == S_IFDIR)    
#define S_ISCHR(m)  (((m) & S_IFMT) == S_IFCHR)    
#define S_ISBLK(m)  (((m) & S_IFMT) == S_IFBLK)    
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)    
#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)

/usr/include/linux/stat.h

반응형
:

Multiline combobox + word highlight

프로그래밍/java 2022. 3. 24. 22:09
반응형

Mulitline combobox - dynamic, ComboBoxEditor

word highlight - Highlighter

package test.swing;

import javax.swing.*;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
import java.awt.*;
import java.awt.event.*;

class TextAreaComboBoxEditor implements ComboBoxEditor {
    private MyTextArea textArea = new MyTextArea();
    private JComboBox<String> mCombo;

    public TextAreaComboBoxEditor(JComboBox<String> combo) {
        mCombo = combo;
        textArea.setWrapStyleWord(true);
        textArea.setLineWrap(true);

        textArea.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
            }

            @Override
            public void keyPressed(KeyEvent e) {
            }

            @Override
            public void keyReleased(KeyEvent e) {
                System.out.println("A " + mCombo.getPreferredSize().height + ", " + textArea.getPreferredSize().height);
                mCombo.setPreferredSize(new Dimension(mCombo.getPreferredSize().width, textArea.getPreferredSize().height));
                textArea.setUpdateHighlighter(true);
                mCombo.getParent().revalidate();
                mCombo.getParent().repaint();
            }
        });

        textArea.addFocusListener(new FocusListener() {
            @Override
            public void focusGained(FocusEvent e) {

            }

            @Override
            public void focusLost(FocusEvent e) {
                textArea.setUpdateHighlighter(true);
            }
        });
    }

    @Override
    public Component getEditorComponent() {
        return textArea;
    }

    @Override
    public void setItem(Object anObject) {
        if (anObject instanceof String) {
            textArea.setText((String) anObject);
        } else {
            textArea.setText(null);
        }
    }

    @Override
    public Object getItem() {
        return textArea.getText();
    }

    @Override
    public void selectAll() {
        textArea.selectAll();
    }

    @Override
    public void addActionListener(ActionListener l) {
    }

    @Override
    public void removeActionListener(ActionListener l) {
    }

    class MyTextArea extends JTextArea {
        public void setUpdateHighlighter(boolean mUpdateHighlighter) {
            this.mUpdateHighlighter = mUpdateHighlighter;
        }

        private boolean mUpdateHighlighter = false;

        @Override
        public void paint(Graphics g) {
            if (mUpdateHighlighter) {
                Highlighter highlighter = getHighlighter();
                Highlighter.HighlightPainter painter1 = new DefaultHighlighter.DefaultHighlightPainter(Color.GREEN);
                Highlighter.HighlightPainter painter2 = new DefaultHighlighter.DefaultHighlightPainter(Color.LIGHT_GRAY);
                String text = getText();
                String separator = " ";

                try {
                    highlighter.removeAllHighlights();

                    int currPos = 0;
                    while (currPos < text.length()) {
                        int startPos = currPos;
                        int separatorPos = text.indexOf(separator, currPos);
                        int endPos = separatorPos;
                        if (separatorPos < 0) {
                            endPos = text.length();
                        }

                        if (startPos >= 0 && endPos > startPos) {
                            highlighter.addHighlight(startPos, endPos, painter1);
                        }

                        if (separatorPos >= 0) {
                            highlighter.addHighlight(separatorPos, separatorPos + 1, painter2);
                        }
                        currPos = endPos + 1;
                    }
                } catch (BadLocationException ex) {
                    ex.printStackTrace();
                }

                mUpdateHighlighter = false;
            }
            super.paint(g);
        }
    }
}

public class MainTest extends JFrame
{
    public MainTest()
    {
        setPreferredSize(new Dimension(400, 120));
        JComboBox<String> combo = new JComboBox<>();
        combo.setPreferredSize(new Dimension(100, 18));
        combo.setEditor(new TextAreaComboBoxEditor(combo));
        combo.setEditable(true);

        JPanel panel = new JPanel();
        panel.add(combo);
        this.add(panel);

        this.setTitle("combo Example");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.pack();
        this.setVisible(true);
    }

    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new MainTest();
            }
        });
    }
}

 

실행 화면

 

반응형
:

c++ getline 예제 코드

프로그래밍/c,c++ 2022. 2. 21. 14:01
반응형

코드

#include <iostream>

using namespace std;
int main() {
    string input = "";

    while (input != "quit") {
        getline(cin, input);
        cout << "read string = " << input << endl;
    }

    return 0;
}

 

실행

$ ./a.out

read string = 
aa
read string = aa
aa bb
read string = aa bb
quit
read string = quit
반응형
: