001: /*
002: * GameDesignPreviewComponent.java
003: *
004: * Created on June 19, 2007, 2:38 AM
005: */
006:
007: package org.netbeans.modules.vmd.game.view;
008:
009: import java.awt.Color;
010: import java.awt.Dimension;
011: import java.awt.event.MouseEvent;
012: import java.awt.event.MouseListener;
013: import java.beans.PropertyChangeEvent;
014: import java.beans.PropertyChangeListener;
015: import java.util.List;
016: import javax.swing.Action;
017: import javax.swing.JComponent;
018: import javax.swing.JPanel;
019: import javax.swing.JPopupMenu;
020: import javax.swing.ToolTipManager;
021: import org.netbeans.modules.vmd.game.model.Editable;
022: import org.netbeans.modules.vmd.game.model.GlobalRepository;
023:
024: /**
025: *
026: * @author kaja
027: */
028: public class GameDesignPreviewComponent extends JPanel implements
029: MouseListener, PropertyChangeListener {
030:
031: private static final Color COLOR_HILITE = ColorConstants.COLOR_OUTLINE_HILITE;
032: private static final Color COLOR_PLAIN = ColorConstants.COLOR_OUTLINE_PLAIN;
033: private static final Color COLOR_BACKGROUND = ColorConstants.COLOR_EDITOR_PANEL;
034:
035: private GlobalRepository gameDesign;
036:
037: private Editable editable;
038:
039: /** Creates new form GameDesignPreviewComponent */
040: public GameDesignPreviewComponent(GlobalRepository gameDesign,
041: JComponent preview, String name, Editable editable) {
042: this .gameDesign = gameDesign;
043: this .editable = editable;
044: this .addMouseListener(this );
045: initComponents();
046: this .labelName.setText(name);
047: this .panelPreview.add(preview);
048: editable.addPropertyChangeListener(this );
049: ToolTipManager.sharedInstance().registerComponent(this );
050: }
051:
052: @Override
053: public String getToolTipText(MouseEvent event) {
054: return editable.getName();
055: }
056:
057: /** This method is called from within the constructor to
058: * initialize the form.
059: * WARNING: Do NOT modify this code. The content of this method is
060: * always regenerated by the Form Editor.
061: */
062: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
063: private void initComponents() {
064:
065: panelPreview = new javax.swing.JPanel();
066: labelName = new javax.swing.JLabel();
067:
068: setBackground(COLOR_BACKGROUND);
069:
070: panelPreview.setBackground(new java.awt.Color(255, 255, 255));
071: panelPreview.setBorder(new javax.swing.border.LineBorder(
072: new java.awt.Color(163, 184, 215), 1, true));
073: panelPreview.setLayout(new java.awt.BorderLayout());
074:
075: labelName.setBackground(COLOR_BACKGROUND);
076: labelName.setForeground(new java.awt.Color(100, 123, 156));
077: labelName
078: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
079: labelName.setText(org.openide.util.NbBundle.getMessage(
080: GameDesignPreviewComponent.class,
081: "GameDesignPreviewComponent.labelName.text")); // NOI18N
082: labelName.setBorder(new javax.swing.border.LineBorder(
083: new java.awt.Color(163, 184, 215), 1, true));
084: labelName.setInheritsPopupMenu(false);
085:
086: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
087: this );
088: this .setLayout(layout);
089: layout
090: .setHorizontalGroup(layout
091: .createParallelGroup(
092: org.jdesktop.layout.GroupLayout.LEADING)
093: .add(
094: org.jdesktop.layout.GroupLayout.TRAILING,
095: layout
096: .createSequentialGroup()
097: .addContainerGap()
098: .add(
099: layout
100: .createParallelGroup(
101: org.jdesktop.layout.GroupLayout.TRAILING)
102: .add(
103: org.jdesktop.layout.GroupLayout.LEADING,
104: panelPreview,
105: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
106: 101,
107: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
108: .add(
109: org.jdesktop.layout.GroupLayout.LEADING,
110: labelName,
111: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
112: 101,
113: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
114: .addContainerGap()));
115: layout
116: .setVerticalGroup(layout
117: .createParallelGroup(
118: org.jdesktop.layout.GroupLayout.LEADING)
119: .add(
120: org.jdesktop.layout.GroupLayout.TRAILING,
121: layout
122: .createSequentialGroup()
123: .addContainerGap()
124: .add(
125: panelPreview,
126: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
127: 101,
128: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
129: .addPreferredGap(
130: org.jdesktop.layout.LayoutStyle.RELATED)
131: .add(
132: labelName,
133: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
134: 19,
135: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
136: .addContainerGap()));
137: }// </editor-fold>//GEN-END:initComponents
138:
139: // Variables declaration - do not modify//GEN-BEGIN:variables
140: private javax.swing.JLabel labelName;
141: private javax.swing.JPanel panelPreview;
142:
143: // End of variables declaration//GEN-END:variables
144:
145: public void mouseClicked(MouseEvent e) {
146: //System.out.println("Clicked - request editing!");
147: this .gameDesign.getMainView().requestEditing(editable);
148: }
149:
150: public void mousePressed(MouseEvent e) {
151: if (e.isPopupTrigger()) {
152: this .handlePopup(e);
153: }
154: }
155:
156: public void mouseReleased(MouseEvent e) {
157: if (e.isPopupTrigger()) {
158: this .handlePopup(e);
159: }
160: }
161:
162: private void handlePopup(MouseEvent e) {
163: JPopupMenu menu = new JPopupMenu();
164: List<Action> actions = this .editable.getActions();
165: for (Action action : actions) {
166: menu.add(action);
167: }
168: menu.show(this , e.getX(), e.getY());
169: }
170:
171: public void mouseEntered(MouseEvent e) {
172: panelPreview.setBorder(new javax.swing.border.LineBorder(
173: COLOR_HILITE, 1, true));
174: labelName.setBorder(new javax.swing.border.LineBorder(
175: COLOR_HILITE, 1, true));
176: //labelName.setOpaque(true);
177: }
178:
179: public void mouseExited(MouseEvent e) {
180: panelPreview.setBorder(new javax.swing.border.LineBorder(
181: COLOR_PLAIN, 1, true));
182: labelName.setBorder(new javax.swing.border.LineBorder(
183: COLOR_PLAIN, 1, true));
184: //labelName.setOpaque(false);
185: }
186:
187: @Override
188: public Dimension getMinimumSize() {
189: return super .getPreferredSize();
190: }
191:
192: @Override
193: public Dimension getMaximumSize() {
194: return super .getPreferredSize();
195: }
196:
197: @Override
198: public Dimension getPreferredSize() {
199: return new Dimension(125, 150);
200: }
201:
202: public void propertyChange(PropertyChangeEvent evt) {
203: this .panelPreview.repaint();
204: if (evt.getPropertyName().equals(Editable.PROPERTY_NAME)) {
205: this .labelName.setText((String) evt.getNewValue());
206: }
207: }
208:
209: }
|