Swing CustomLineBorder 만들기(top, left, bottom, right 지정하여 적용하기)

프로그래밍/java 2022. 1. 6. 22:58
반응형

생성시 지정된 면만 border 적용 하도록 border 재정의 함

나중에 같은 동작을 하는 MatteBorder 가 있다는 거 확인함.... 만들기 전에 찾아봐야돼~

https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/border/MatteBorder.html

package test.swing;

import javax.swing.*;
import javax.swing.border.AbstractBorder;
import java.awt.*;

// Custom Line border
public class MainTest {
    public static void main(String[] args) {
        MainUI mainUI = new MainUI();
        mainUI.setVisible(true);
    }
}

class CustomLineBorder extends AbstractBorder
{
    public static final int TOP = 0x1;
    public static final int LEFT = 0x2;
    public static final int BOTTOM = 0x4;
    public static final int RIGHT = 0x8;
    private Color mColor;
    private int mThickness;
    private int mTarget;

    public CustomLineBorder(Color colour, int thickness, int target)
    {
        mColor = colour;
        mThickness = thickness;
        mTarget = target;
    }

    @Override
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
    {
        if (g != null)
        {
            g.setColor(mColor);
            if ((mTarget & TOP) != 0) {
                for (int i = 0; i < mThickness; i++) {
                    g.drawLine(x, y + i, width, y + i);
                }
            }
            if ((mTarget & LEFT) != 0) {
                for (int i = 0; i < mThickness; i++) {
                    g.drawLine(x + i, y, x + i, height);
                }
            }
            if ((mTarget & BOTTOM) != 0) {
                for (int i = 0; i < mThickness; i++) {
                    g.drawLine(x, height - i - 1, width, height - i - 1);
                }
            }
            if ((mTarget & RIGHT) != 0) {
                for (int i = 0; i < mThickness; i++) {
                    g.drawLine(width - i - 1, y, width - i - 1, height);
                }
            }
        }
    }

    @Override
    public Insets getBorderInsets(Component c)
    {
        return (getBorderInsets(c, new Insets(0, 0, 0, 0)));
    }

    @Override
    public Insets getBorderInsets(Component c, Insets insets)
    {
        insets.top = 0;
        insets.left = 0;
        insets.bottom = 0;
        insets.right = 0;
        if ((mTarget & TOP) != 0) {
            insets.top = mThickness;
        }
        if ((mTarget & LEFT) != 0) {
            insets.left = mThickness;
        }
        if ((mTarget & BOTTOM) != 0) {
            insets.bottom = mThickness;
        }
        if ((mTarget & RIGHT) != 0) {
            insets.right = mThickness;
        }

        return insets;
    }

    @Override
    public boolean isBorderOpaque()
    {
        return true;
    }
}

class MainUI extends JFrame {
    MainUI() {
        setPreferredSize(new Dimension(400, 420));
        
        JPanel pane = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 20));
        pane.setBackground(new Color(0x85, 0x85, 0x85));

        JLabel label = new JLabel("Red, 1, TOP");
        label.setPreferredSize(new Dimension(300, 40));
        label.setOpaque(true);
        label.setBackground(Color.WHITE);
        label.setBorder(new CustomLineBorder(Color.RED, 1, CustomLineBorder.TOP));
        pane.add(label);

        label = new JLabel("Red, 5, LEFT");
        label.setPreferredSize(new Dimension(300, 40));
        label.setOpaque(true);
        label.setBackground(Color.WHITE);
        label.setBorder(new CustomLineBorder(Color.RED, 5, CustomLineBorder.LEFT));
        pane.add(label);

        label = new JLabel("Red, 5, Bottom");
        label.setPreferredSize(new Dimension(300, 40));
        label.setOpaque(true);
        label.setBackground(Color.WHITE);
        label.setBorder(new CustomLineBorder(Color.RED, 5, CustomLineBorder.BOTTOM));
        pane.add(label);

        label = new JLabel("Red, 15, Right");
        label.setPreferredSize(new Dimension(300, 40));
        label.setOpaque(true);
        label.setBackground(Color.WHITE);
        label.setBorder(new CustomLineBorder(Color.RED, 15, CustomLineBorder.RIGHT));
        pane.add(label);

        label = new JLabel("Blue, 5, TOP LEFT");
        label.setPreferredSize(new Dimension(300, 40));
        label.setOpaque(true);
        label.setBackground(Color.WHITE);
        label.setBorder(new CustomLineBorder(Color.BLUE, 5, CustomLineBorder.LEFT | CustomLineBorder.TOP));
        pane.add(label);

        label = new JLabel("Blue, 5, TOP RIGHT BOTTOM");
        label.setPreferredSize(new Dimension(300, 40));
        label.setOpaque(true);
        label.setBackground(Color.WHITE);
        label.setBorder(new CustomLineBorder(Color.BLUE, 5, CustomLineBorder.TOP | CustomLineBorder.RIGHT | CustomLineBorder.BOTTOM));
        pane.add(label);

        add(pane);

        pack();
    }
}

실행결과

 

 

반응형
:

Android sepolicy 상태 확인 하기

OS/Android 2022. 1. 3. 22:49
반응형

Process 별 sepolicy 보기

1. android 기기에 adb 연결

2. adb shell ps -eZ

......
u:r:priv_app:s0:c522,c768      u10_a248      29036    825 33799276 202616 0                  0 S com.google.android.googlequicksearchbox:search
u:r:priv_app:s0:c522,c768      u10_a247      29162    825 15532196 85196 0                   0 S com.google.process.gapps
u:r:gmscore_app:s0:c522,c768   u10_a247      29170    825 16504752 154944 0                  0 S com.google.android.gms
u:r:priv_app:s0:c522,c768      u10_a248      29251    825 16446808 150508 0                  0 S com.google.android.googlequicksearchbox:interactor
u:r:untrusted_app:s0:c1,c257,c512,c768 u0_a257 29267  825 32630088 143932 0                  0 S com.android.chrome:privileged_process2
u:r:app_zygote:s0:c512,c768    u0_a257       29274    825 16171312 74484 0                   0 S com.android.chrome_zygote
u:r:untrusted_app:s0:c5,c257,c522,c768 u10_a261 29314 825 15570464 85916 0                   0 S com.google.android.webview:webview_service
......

파일 별 sepolicy 보기

1. android 기기에 adb 연결

2. adb shell ls -lZ

......
drwxr-xr-x  18 root   system    u:object_r:tmpfs:s0                    380 2019-11-22 01:22 mnt
drwxr-xr-x   4 root   root      u:object_r:vendor_file:s0             4096 2009-01-01 00:00 odm
drwxr-xr-x   2 root   root      u:object_r:oemfs:s0                   4096 2009-01-01 00:00 oem
drwxrwx--x   3 root   system    u:object_r:omr_file:s0                4096 2019-01-06 12:31 omr
drwxr-xr-x   4 root   root      u:object_r:vendor_file:s0             4096 2009-01-01 00:00 optics
drwxr-xr-x   7 root   root      u:object_r:system_file:s0             4096 2009-01-01 00:00 prism
dr-xr-xr-x 846 root   root      u:object_r:proc:s0                       0 1970-01-01 09:00 proc
drwxr-xr-x   9 root   root      u:object_r:system_file:s0             4096 2009-01-01 00:00 product
......

 

반응형
:

adb logcat 주요 옵션

OS/Android 2021. 12. 30. 20:58
반응형

테스트 adb 버전

$ adb --version
Android Debug Bridge version 1.0.41
Version 31.0.2-7242960

전체 옵션 보기

$ adb logcat -h              
Usage: logcat [options] [filterspecs]

General options:
  -b, --buffer=<buffer>       Request alternate ring buffer(s):
                                main system radio events crash default all
                              Additionally, 'kernel' for userdebug and eng builds, and
......

logcat 버퍼 크기 확인

  -g, --buffer-size           Get the size of the ring buffers within logd.



$ adb logcat -g
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 2 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

logcat 버퍼 크기 변경

  -b, --buffer=<buffer>       Request alternate ring buffer(s):
                                main system radio events crash default all
                              Additionally, 'kernel' for userdebug and eng builds, and
                              'security' for Device Owner installations.
                              Multiple -b parameters or comma separated list of buffers are
                              allowed. Buffers are interleaved.
                              Default -b main,system,crash,kernel.

  -G, --buffer-size=<size>    Set size of a ring buffer in logd. May suffix with K or M.
                              This can individually control each buffer's size with -b.



set system buffer

$ adb logcat -G 5M -b system

$ adb logcat -g             
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 5 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 256 KiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

set all buffer

$ adb logcat -G 5M          

$ adb logcat -g   
main: ring buffer is 5 MiB (4 MiB consumed), max entry is 5120 B, max payload is 4068 B
system: ring buffer is 5 MiB (1 MiB consumed), max entry is 5120 B, max payload is 4068 B
crash: ring buffer is 5 MiB (0 B consumed), max entry is 5120 B, max payload is 4068 B
kernel: ring buffer is 5 MiB (0 B consumed), max entry is 5120 B, max payload is 4068 B

기존 로그 지우기

  -c, --clear                 Clear (flush) the entire log and exit.
                              if -f is specified, clear the specified file and its related rotated
                              log files instead.
                              if -L is specified, clear pstore log instead.



$ adb logcat -c

로그 덤프(non block)

  -d                          Dump the log and then exit (don't block).



$ adb logcat -d
--------- beginning of system
12-30 15:11:05.979  1132  5037 I ActivityManager: Process com.samsung.android.dqagent
--------- beginning of main
12-30 15:11:05.980   825   825 I Zygote  : Process 25662 exited due to signal 9 (Killed)
12-30 15:11:05.980   604   604 I lmkd    : cached 5, sandbox(not0) 2
12-30 15:11:05.981  1132  1423 I libprocessgroup: Successfully killed process cgroup 
......
12-30 15:11:14.978   805   805 E audit   : type=1327 audit(1640844674.973:574366029):
12-30 15:11:14.978   805   805 E audit   : type=1400 audit(1640844674.977:574366030):
12-30 15:11:14.978   805   805 E audit   : type=1300 audit(1640844674.977:574366030):
$

로그 저장(block)

Option (adb logcat -h)
Outfile files:
  -f, --file=<file>           Log to file instead of stdout.
  -r, --rotate-kbytes=<n>     Rotate log every <n> kbytes. Requires -f option.
  -n, --rotate-count=<count>  Sets max number of rotated logs to <count>, default 4.



1000K, 최대 20개, /storage/emulated/0/logcat에 저장

$ adb logcat -r 1000 -n 20 -f /storage/emulated/0/logcat/logcat.log

$ adb shell ls -lh /storage/emulated/0/logcat/
total 676K
-rw-rw---- 1 root everybody 634K 2021-12-30 15:24 logcat.log
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.01

$ adb shell ls -lh /storage/emulated/0/logcat/
total 1.0M
-rw-rw---- 1 root everybody 222K 2021-12-30 15:25 logcat.log
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.01
-rw-rw---- 1 root everybody 0.9M 2021-12-30 15:24 logcat.log.02

필터링

Filtering:
  -s                          Set default filter to silent. Equivalent to filterspec '*:S'
......

filterspecs are a series of 
  <tag>[:priority]

where <tag> is a log component tag (or * for all) and priority is:
  V    Verbose (default for <tag>)
  D    Debug (default for '*')
  I    Info
  W    Warn
  E    Error
  F    Fatal
  S    Silent (suppress all output)



$ adb logcat -s "AlarmManager:*" "BatteryStatsService:*"
12-30 15:39:24.326  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive
12-30 15:39:24.353  1132  4035 I BatteryStatsService: In wakeup_callback: resumed from 
12-30 15:39:25.054  1132  4935 I BatteryStatsService: In wakeup_callback: suspend aborted
12-30 15:39:26.410  1132  3545 V AlarmManager: unblockMARsRestrictedAlarmsForUidPackage

thread, time 정보 출력

-v <format>, --format=<format> options:
  Sets log print format verb and adverbs, where <format> is:
    brief long process raw tag thread threadtime time


default : Depends on the adb version
$ adb logcat -s "AlarmManager:*"
12-30 15:26:40.860  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive

$ adb logcat -s "AlarmManager:*" -v time
12-30 15:22:01.749 E/AlarmManager( 1132): Set nextNonWakeup as mNextNonWakeupDeliveryTime

$ adb logcat -s "AlarmManager:*" -v thread
E( 1132: 1836) Set nextNonWakeup as mNextNonWakeupDeliveryTime=781912438 , orig nextNonWakeup=0

$ adb logcat -s "AlarmManager:*" -v threadtime
12-30 15:14:24.021  1132  1836 E AlarmManager: Set nextNonWakeup as mNextNonWakeupDelive

로그 레벨별 색 적용

$ adb logcat -v color

 

 

 

반응형
: