* ListasycombosView.java
*/
package listasycombos;
import java.awt.Color;
import java.awt.event.ItemEvent;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
/**
* The application's main frame.
*/
public class ListasycombosView extends FrameView {
//IMAGENES
private String ima[] = { "calamardo,.jpg", "pokemon.png", "avatar.png", "catdog.gif",
"calamardo 45.jpg", "rocko.png", "beavers.png"};
private Icon imagen[] = {new ImageIcon (ima[0]) {}, new ImageIcon (ima[1]),
new ImageIcon (ima[2]), new ImageIcon (ima[3]),
new ImageIcon (ima[4]), new ImageIcon (ima[5]),
new ImageIcon (ima[6])};
// private final String ncolores[] = {"Negro", "DeepSkyBlue", "LimeGreen", "Firebrick", "Orange1", "DeepPink1", "DarkOrchid3"};
private final Color colores[] = {Color.black, new Color(0, 191, 255),
new Color(50, 205, 50), new Color(178, 34, 34),
new Color(255, 165, 0), new Color(255, 20, 147), new Color(154, 50, 205) };
private String edos[] = { "CAPITAL DEL ESTADO", "PACHUCA", "PUEBLA", "CD. DE MEXICO",
"VILLA HERMOSA", "JALAPA"};
private String ed[] = {new String (edos[0]), new String (edos[1]),
new String (edos[2]), new String (edos[3]),
new String (edos[4]), new String (edos[5])};
public ListasycombosView(SingleFrameApplication app) {
super(app);
initComponents();
// status bar initialization - message timeout, idle icon and busy animation, etc
ResourceMap resourceMap = getResourceMap();
int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
messageTimer = new Timer(messageTimeout, new ActionListener() {
public void actionPerformed(ActionEvent e) {
statusMessageLabel.setText("");
}
});
messageTimer.setRepeats(false);
int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
for (int i = 0; i < busyIcons.length; i++) {
busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
}
busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
public void actionPerformed(ActionEvent e) {
busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
}
});
idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
// connecting action tasks to status bar via TaskMonitor
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
String propertyName = evt.getPropertyName();
if ("started".equals(propertyName)) {
if (!busyIconTimer.isRunning()) {
statusAnimationLabel.setIcon(busyIcons[0]);
busyIconIndex = 0;
busyIconTimer.start();
}
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
} else if ("done".equals(propertyName)) {
busyIconTimer.stop();
statusAnimationLabel.setIcon(idleIcon);
progressBar.setVisible(false);
progressBar.setValue(0);
} else if ("message".equals(propertyName)) {
String text = (String)(evt.getNewValue());
statusMessageLabel.setText((text == null) ? "" : text);
messageTimer.restart();
} else if ("progress".equals(propertyName)) {
int value = (Integer)(evt.getNewValue());
progressBar.setVisible(true);
progressBar.setIndeterminate(false);
progressBar.setValue(value);
}
}
});
}
@Action
public void showAboutBox() {
if (aboutBox == null) {
JFrame mainFrame = ListasycombosApp.getApplication().getMainFrame();
aboutBox = new ListasycombosAboutBox(mainFrame);
aboutBox.setLocationRelativeTo(mainFrame);
}
ListasycombosApp.getApplication().show(aboutBox);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
fondo = new javax.swing.JPanel();
comimi = new javax.swing.JComboBox();
jScrollPane1 = new javax.swing.JScrollPane();
lcol = new javax.swing.JList();
comedo = new javax.swing.JComboBox();
imi = new javax.swing.JLabel();
edo = new javax.swing.JLabel();
menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu();
javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
statusPanel = new javax.swing.JPanel();
javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
statusMessageLabel = new javax.swing.JLabel();
statusAnimationLabel = new javax.swing.JLabel();
progressBar = new javax.swing.JProgressBar();
org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(listasycombos.ListasycombosApp.class).getContext().getResourceMap(ListasycombosView.class);
fondo.setBackground(resourceMap.getColor("fondo.background")); // NOI18N
fondo.setName("fondo"); // NOI18N
comimi.setBackground(resourceMap.getColor("comimi.background")); // NOI18N
comimi.setFont(resourceMap.getFont("comimi.font")); // NOI18N
comimi.setForeground(resourceMap.getColor("comimi.foreground")); // NOI18N
comimi.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "muestra", "pokemon.png", "avatar.png", "catdog", "calamardo", "rocko", "castores " }));
comimi.setName("comimi"); // NOI18N
comimi.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
comimiItemStateChanged(evt);
}
});
jScrollPane1.setName("jScrollPane1"); // NOI18N
lcol.setBackground(resourceMap.getColor("lcol.background")); // NOI18N
lcol.setFont(resourceMap.getFont("lcol.font")); // NOI18N
lcol.setForeground(resourceMap.getColor("lcol.foreground")); // NOI18N
lcol.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Negro", "Azul", "Verde", "Rojo", "Naranja", "Rosa", "Morado" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
lcol.setName("lcol"); // NOI18N
lcol.setSelectionBackground(resourceMap.getColor("lcol.selectionBackground")); // NOI18N
lcol.setSelectionForeground(resourceMap.getColor("lcol.selectionForeground")); // NOI18N
lcol.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
lcolValueChanged(evt);
}
});
jScrollPane1.setViewportView(lcol);
comedo.setBackground(resourceMap.getColor("comedo.background")); // NOI18N
comedo.setFont(resourceMap.getFont("comedo.font")); // NOI18N
comedo.setForeground(resourceMap.getColor("comedo.foreground")); // NOI18N
comedo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "ESTADO DE LA REPUBLICA", "HIDALGO", "PUEBLA", "MEXICO", "TABASCO", "VERACRUZ" }));
comedo.setName("comedo"); // NOI18N
comedo.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
comedoItemStateChanged(evt);
}
});
imi.setBackground(resourceMap.getColor("imi.background")); // NOI18N
imi.setFont(resourceMap.getFont("imi.font")); // NOI18N
imi.setForeground(resourceMap.getColor("imi.foreground")); // NOI18N
imi.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
imi.setIcon(resourceMap.getIcon("imi.icon")); // NOI18N
imi.setText(resourceMap.getString("imi.text")); // NOI18N
imi.setName("imi"); // NOI18N
edo.setBackground(resourceMap.getColor("edo.background")); // NOI18N
edo.setFont(resourceMap.getFont("edo.font")); // NOI18N
edo.setForeground(resourceMap.getColor("edo.foreground")); // NOI18N
edo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
edo.setText(resourceMap.getString("edo.text")); // NOI18N
edo.setName("edo"); // NOI18N
org.jdesktop.layout.GroupLayout fondoLayout = new org.jdesktop.layout.GroupLayout(fondo);
fondo.setLayout(fondoLayout);
fondoLayout.setHorizontalGroup(
fondoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(fondoLayout.createSequentialGroup()
.add(fondoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(fondoLayout.createSequentialGroup()
.addContainerGap()
.add(fondoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(fondoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, comimi, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, comedo, 0, 266, Short.MAX_VALUE))
.add(imi, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 422, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(31, 31, 31)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 116, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(fondoLayout.createSequentialGroup()
.add(42, 42, 42)
.add(edo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 273, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(140, Short.MAX_VALUE))
);
fondoLayout.setVerticalGroup(
fondoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(fondoLayout.createSequentialGroup()
.add(21, 21, 21)
.add(comimi, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(comedo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(35, 35, 35)
.add(imi, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(edo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(38, 38, 38))
.add(fondoLayout.createSequentialGroup()
.add(34, 34, 34)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 139, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(309, Short.MAX_VALUE))
);
menuBar.setName("menuBar"); // NOI18N
fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
fileMenu.setName("fileMenu"); // NOI18N
javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(listasycombos.ListasycombosApp.class).getContext().getActionMap(ListasycombosView.class, this);
exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
helpMenu.setName("helpMenu"); // NOI18N
aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
aboutMenuItem.setName("aboutMenuItem"); // NOI18N
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
statusPanel.setBackground(resourceMap.getColor("statusPanel.background")); // NOI18N
statusPanel.setName("statusPanel"); // NOI18N
statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N
statusMessageLabel.setName("statusMessageLabel"); // NOI18N
statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N
progressBar.setName("progressBar"); // NOI18N
org.jdesktop.layout.GroupLayout statusPanelLayout = new org.jdesktop.layout.GroupLayout(statusPanel);
statusPanel.setLayout(statusPanelLayout);
statusPanelLayout.setHorizontalGroup(
statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 719, Short.MAX_VALUE)
.add(statusPanelLayout.createSequentialGroup()
.addContainerGap()
.add(statusMessageLabel)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 549, Short.MAX_VALUE)
.add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(statusAnimationLabel)
.addContainerGap())
);
statusPanelLayout.setVerticalGroup(
statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusPanelLayout.createSequentialGroup()
.add(statusPanelSeparator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(statusPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(statusMessageLabel)
.add(statusAnimationLabel)
.add(progressBar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(3, 3, 3))
);
setComponent(fondo);
setMenuBar(menuBar);
setStatusBar(statusPanel);
}// </editor-fold>
private void comimiItemStateChanged(java.awt.event.ItemEvent evt) {
if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED)
imi.setIcon(imagen[comimi.getSelectedIndex()]);
}
private void lcolValueChanged(javax.swing.event.ListSelectionEvent evt) {
fondo.setBackground(colores[lcol.getSelectedIndex()]);
}
private void comedoItemStateChanged(java.awt.event.ItemEvent evt) {
if (evt.getStateChange() == java.awt.event.ItemEvent.SELECTED)
edo.setText(ed[comedo.getSelectedIndex()]);
}
// Variables declaration - do not modify
private javax.swing.JComboBox comedo;
private javax.swing.JComboBox comimi;
private javax.swing.JLabel edo;
private javax.swing.JPanel fondo;
private javax.swing.JLabel imi;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JList lcol;
private javax.swing.JMenuBar menuBar;
private javax.swing.JProgressBar progressBar;
private javax.swing.JLabel statusAnimationLabel;
private javax.swing.JLabel statusMessageLabel;
private javax.swing.JPanel statusPanel;
// End of variables declaration
private final Timer messageTimer;
private final Timer busyIconTimer;
private final Icon idleIcon;
private final Icon[] busyIcons = new Icon[15];
private int busyIconIndex = 0;
private JDialog aboutBox;
}
No hay comentarios:
Publicar un comentario