KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bluej > editor > moe > StatusLabel


1 // Copyright (c) 2000, 2005 BlueJ Group, Deakin University
2
//
3
// This software is made available under the terms of the "MIT License"
4
// A copy of this license is included with this source distribution
5
// in "license.txt" and is also available at:
6
// http://www.opensource.org/licenses/mit-license.html
7
// Any queries should be directed to Michael Kolling mik@bluej.org
8

9 package bluej.editor.moe;
10
11 import bluej.Config;
12 import java.awt.*; // New Event model
13
import javax.swing.*;
14
15 /**
16 ** @author Michael Kolling
17 **
18 **/

19
20 public final class StatusLabel extends JLabel
21 {
22     // ---------------- CONSTANTS -----------------
23

24     public static Font statusFont = new Font("SansSerif", Font.BOLD | Font.ITALIC, 11);
25
26     // current save state
27
static final int READONLY = 0;
28     static final int SAVED = 1;
29     static final int CHANGED = 2;
30
31     private final String JavaDoc[] stateString = {
32         Config.getString("editor.state.readOnly"),
33         Config.getString("editor.state.saved"),
34         Config.getString("editor.state.changed")
35     };
36
37
38     // ------------ INSTANCE VARIABLES ------------
39

40     private int state;
41
42
43     // -------------- CONSTRUCTORS ----------------
44

45     public StatusLabel(int initialState)
46     {
47         super("", JLabel.CENTER);
48         setText(stateString[initialState]);
49         setFont(statusFont);
50         setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 8));
51         state = initialState;
52     }
53
54     // ------------- PUBLIC METHODS ---------------
55

56     public boolean isSaved()
57     {
58         return (state != CHANGED);
59     }
60
61     public boolean isChanged()
62     {
63         return (state == CHANGED);
64     }
65
66     public boolean isReadOnly()
67     {
68         return (state == READONLY);
69     }
70
71     public void setState(int newState)
72     {
73         state = newState;
74         setText(stateString[state]);
75     }
76
77 } // end class StatusLabel
78
Popular Tags