001: package Schmortopf.Main;
002:
003: /**
004: *
005: * This panel is displayed on the right side of
006: * the IDE_ProjectFrame's menupanel.
007: *
008: * It displays project informations like :
009: * - current number of changed files (which have to be saved)
010: * - the currently compiled files during compilations
011: *
012: */
013:
014: import java.awt.*;
015: import java.awt.event.*;
016: import javax.swing.*;
017: import javax.swing.border.*;
018: import Schmortopf.Utility.gui.*;
019: import Language.Language;
020:
021: final public class ProjectInfoPanel extends JPanel {
022: // Model attributes
023: private int numberOfChangedProjectFiles = 0;
024:
025: // View attributes
026: private JLabel numberOfChangedProjectFilesLabel;
027: private JTextField compilerInfoField = null;
028: private AnimatedColorPanel compilerInfoPanel = null;
029:
030: // The compilerInfoField has two backgroundcolors :
031: // One neutral background, when nothing happens, and
032: // one slightly red colored background, when we have action.
033: // Both colors are derivated from the (current) theme label background.
034: private Color neutralBackground = null;
035: private Color redbackground = null;
036:
037: private final static int compilerInfoFieldColumns = 38;
038:
039: public ProjectInfoPanel(final IDE_MainFrameProvider mainFrame,
040: final IDE_ProjectFrame projectFrame) {
041: this .setLayout(new BorderLayout(0, 0));
042: final JPanel basisPanel = new JPanel(new FlowLayout(
043: FlowLayout.LEFT, 1, 1));
044: basisPanel.setOpaque(false); // see through to the gradientpanel
045: // Putting the basisPanel into "this" panel prevents the FlowLayout
046: // manager from incrementing the linenumber, when the components
047: // don't fit in one line anymore. Like this, parts always are visible,
048: // if the frame is made smaller horizontally.
049:
050: // first add an empty JLabel, which only serves as distance holder
051: // to the left. Its automatically scaled with the current
052: // fontsize by Swing itself, also on theme changes.
053: final JLabel placeHolderLabel1 = new JLabel(" ");
054: placeHolderLabel1.setAlignmentX(0.0f);
055: placeHolderLabel1.setBorder(BorderFactory.createEmptyBorder(0,
056: 0, 0, 0));
057: basisPanel.add(placeHolderLabel1);
058:
059: final int spaceUnit = UIManager.getFont("Label.font").getSize();
060: // The number-of-changed-files line :
061: this .numberOfChangedProjectFilesLabel = new JLabel("");
062: this .numberOfChangedProjectFilesLabel.setOpaque(true);
063: final JPanel numberOfChangedProjectFilesPanel = new JPanel(
064: new BorderLayout(0, 0));
065: numberOfChangedProjectFilesPanel.setBorder(BorderFactory
066: .createEmptyBorder(0, 0, 0, 0));
067: numberOfChangedProjectFilesPanel.setAlignmentX(0.0f);
068:
069: numberOfChangedProjectFilesPanel.add(
070: this .numberOfChangedProjectFilesLabel,
071: BorderLayout.CENTER);
072:
073: //numberOfChangedProjectFilesPanel.setBorder( BorderFactory.createEmptyBorder(0,0,0,0));
074: numberOfChangedProjectFilesPanel.setBorder(BorderFactory
075: .createEtchedBorder());
076:
077: basisPanel.add(numberOfChangedProjectFilesPanel);
078: this .setNumberOfChangedProjectFiles(0); // makes the layout looking ok.
079:
080: // Add another empty JLabel, which only serves as distance holder.
081: final JLabel placeHolderLabel2 = new JLabel(" ");
082: placeHolderLabel2.setBorder(BorderFactory.createEmptyBorder(0,
083: 0, 0, 0));
084: placeHolderLabel2.setAlignmentX(0.0f);
085: basisPanel.add(placeHolderLabel2);
086:
087: // The compiler info line :
088: this .compilerInfoField = new JTextField(
089: compilerInfoFieldColumns);
090: this .compilerInfoField.setEditable(false);
091: this .compilerInfoField.setFont(UIManager.getFont("Label.font"));
092: this .compilerInfoField.setBorder(BorderFactory
093: .createEmptyBorder(0, 0, 0, 0));
094:
095: this .neutralBackground = UIManager.getColor("Label.background");
096: this .redbackground = this
097: .colorSlightlyRed(this .neutralBackground);
098:
099: this .compilerInfoField.setOpaque(false);
100:
101: this .compilerInfoPanel = new AnimatedColorPanel(
102: new BorderLayout(0, 0), 333);
103:
104: this .compilerInfoPanel.add(this .compilerInfoField,
105: BorderLayout.CENTER);
106:
107: //this.compilerInfoPanel.setBorder( BorderFactory.createEmptyBorder(0,0,0,0) );
108: this .compilerInfoPanel.setBorder(BorderFactory
109: .createEtchedBorder());
110:
111: this
112: .setCompilerInfo(
113: " "
114: + Language
115: .Translate("The compiler has not been started yet."),
116: false); // makes the layout looking ok.
117:
118: basisPanel.add(this .compilerInfoPanel);
119:
120: this .add(basisPanel, BorderLayout.WEST);
121: this .setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
122: this .setOpaque(false); // because otherwise we wouldn't see
123: // the underlying GradientPanel
124: } // Constructor
125:
126: /**
127: * Overwritten method. Additionally updates special components.
128: */
129: public void updateUI() {
130: super .updateUI();
131: if (this .compilerInfoField != null) {
132: EventQueue.invokeLater(new Runnable() {
133: public void run() {
134: compilerInfoField.setEditable(false);
135: compilerInfoField.setFont(UIManager
136: .getFont("Label.font"));
137: compilerInfoField.setBorder(BorderFactory
138: .createEmptyBorder(0, 0, 0, 0));
139: compilerInfoField
140: .setColumns(compilerInfoFieldColumns);
141: neutralBackground = UIManager
142: .getColor("Label.background");
143: redbackground = colorSlightlyRed(neutralBackground);
144: compilerInfoField.setBackground(neutralBackground);
145: // reset :
146: setNumberOfChangedProjectFiles(getNumberOfChangedProjectFiles());
147: }
148: });
149: }
150: }
151:
152: final public void setNumberOfChangedProjectFiles(final int number) {
153: this .numberOfChangedProjectFiles = number;
154: EventQueue.invokeLater(new Runnable() {
155: public void run() {
156: numberOfChangedProjectFilesLabel.setOpaque(true);
157: numberOfChangedProjectFilesLabel
158: .setForeground(UIManager
159: .getColor("TextField.foreground"));
160: if (number == 0) {
161: Color c = new Color(neutralBackground.getRed(),
162: neutralBackground.getGreen(),
163: neutralBackground.getBlue());
164: numberOfChangedProjectFilesLabel.setBackground(c);
165: numberOfChangedProjectFilesLabel.setText(Language
166: .Translate(" No changed file "));
167: } else if (number == 1) {
168: Color c = new Color(redbackground.getRed(),
169: redbackground.getGreen(), redbackground
170: .getBlue());
171: numberOfChangedProjectFilesLabel.setBackground(c);
172: numberOfChangedProjectFilesLabel.setText(" "
173: + Language.Translate("% changed file ", ""
174: + number));
175: } else {
176: Color c = new Color(redbackground.getRed(),
177: redbackground.getGreen(), redbackground
178: .getBlue());
179: numberOfChangedProjectFilesLabel.setBackground(c);
180: numberOfChangedProjectFilesLabel.setText(" "
181: + Language.Translate("% changed files ",
182: "" + number));
183: }
184: }
185: });
186: }
187:
188: final public void setCompilerInfo(final String text,
189: final boolean markRed) {
190: // inside EDT
191: this .compilerInfoField.setText(" " + text);
192: this .compilerInfoPanel.activateAnimation(markRed);
193: }
194:
195: public int getNumberOfChangedProjectFiles() {
196: return this .numberOfChangedProjectFiles;
197: }
198:
199: private Color colorSlightlyRed(Color c) {
200: int r = c.getRed() + 32;
201: if (r > 255)
202: r = 255;
203: int g = c.getGreen() - 16;
204: if (g < 0)
205: g = 0;
206: int b = c.getBlue() - 16;
207: if (b < 0)
208: b = 0;
209: return new Color(r, g, b);
210: } // colorSlightlyRed
211:
212: } // ProjectInfoPanel
|