summaryrefslogtreecommitdiffhomepage
path: root/IDE/src/main/java/org/elmahrouss/CodeEditorView.java
blob: e759c6941f29f60f3cb8cff145954038b73aaede (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 *	========================================================
 *
 *	MPCC
 * 	Copyright 2024, Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

 package org.elmahrouss;

import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;

/*
 * Editor view class
 */
public class CodeEditorView extends Pane 
{
    private Pane linePane;
    private Label codeText;
    private boolean readOnly;
    private HBox codeBox;
    private String fileName = "untitled.c";
    private CodeEditorController codeEditorController;

    CodeEditorView() 
    {
        super();

        this.readOnly = readOnly;

        codeText = new Label();

        codeText.setStyle("-fx-font-size: 20");
        codeText.setTextFill(Color.color(1, 1, 1));

        codeText.setWrapText(true);
        codeText.setTranslateX(70);
        codeText.setTranslateY(30);

        linePane = new Pane();

        linePane.setStyle("-fx-background-color: #" + CodeEditorTheme.LINE_THEME);
        linePane.setMinSize(52, AppSettings.HEIGHT);
        linePane.setMaxSize(52, AppSettings.HEIGHT);

        this.setStyle("-fx-background-color: #" + CodeEditorTheme.BACKGROUND_THEME);

        this.setMinSize(AppSettings.WIDTH, AppSettings.HEIGHT);
        this.setMaxSize(AppSettings.WIDTH, AppSettings.HEIGHT);

        codeBox = new HBox();

        codeBox.getChildren().add(codeText);

        this.getChildren().addAll(linePane, codeBox);
    }

    public boolean isReadOnly() { return readOnly; }

    public void setReadOnly(Boolean readOnly) { this.readOnly = readOnly; }

    public String getFilename() { return fileName; }
    
    public void setFilename(String fileName) 
    { 
        if (readOnly) 
            return;
    
        this.fileName = fileName; 
    }

    public String getContents() { 
        if (this.codeText == null)
            return "";

        return codeText.getText(); 
    }
    
    public void setContents(String content) 
    {
        if (this.codeText == null)
            return;

        this.codeText.setText(content); 
    }

    CodeEditorController getController() { return codeEditorController; }
    void setController(CodeEditorController ctrl) { codeEditorController = ctrl; }
}