1 package rero.gui.windows; 2 3 import javax.swing.*; 4 import javax.swing.event.*; 5 import javax.swing.table.*; 6 7 import java.awt.*; 8 import java.awt.event.*; 9 10 import java.util.*; 11 import rero.util.*; 12 13 import contrib.javapro.*; 15 import rero.ircfw.interfaces.*; 16 17 import rero.config.*; 18 import rero.client.*; 19 20 import rero.gui.*; 21 import rero.gui.windows.*; 22 23 import text.*; 24 25 import rero.gui.toolkit.*; 26 27 public class GeneralListDialog extends EmptyWindow 28 { 29 protected GeneralListModel model; 30 protected JSortTable table; 31 protected String popupHook; 32 protected String name; 33 34 public GeneralListDialog(String _name, String _hook, GeneralListModel _model) 35 { 36 name = _name; 37 popupHook = _hook; 38 39 this.model = _model; 40 41 setLayout(new BorderLayout()); 42 43 table = new JSortTable(model); 44 table.setOpaque(false); 45 table.setRowSelectionAllowed(true); 46 table.setColumnSelectionAllowed(false); 47 table.setDefaultRenderer((new Object ()).getClass(), new MyRenderer()); 48 table.setShowGrid(false); 49 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 50 table.setRowHeight(TextSource.fontMetrics.getHeight() + 2); 51 52 JScrollPane scroller = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 53 scroller.setOpaque(false); 54 scroller.getViewport().setOpaque(false); 55 scroller.setCorner(JScrollPane.UPPER_RIGHT_CORNER, new JPanel()); 56 57 TableColumn tempcol; 58 int x = 0; 59 60 tempcol = table.getColumnModel().getColumn(x); 61 tempcol.setMinWidth(1); 62 tempcol.setMaxWidth(model.getColumnWidth(x) * 3); 63 tempcol.setPreferredWidth(model.getColumnWidth(x)); 64 65 for (x = 1; x < model.getColumnCount() - 1; x++) 66 { 67 tempcol = table.getColumnModel().getColumn(x); 68 tempcol.setMinWidth(1); 69 tempcol.setMaxWidth(model.getColumnWidth(x) * 3); 70 tempcol.sizeWidthToFit(); 71 } 72 73 table.setRowSelectionAllowed(true); 74 75 scroller.setViewportBorder(BorderFactory.createEmptyBorder(1, 0, 0, 0)); 77 ToolTipManager.sharedInstance().unregisterComponent(table); ToolTipManager.sharedInstance().unregisterComponent(table.getTableHeader()); 79 80 add(scroller); 81 82 table.addMouseListener(new MouseAdapter() 83 { 84 public void mousePressed(MouseEvent e) 85 { 86 Point p = e.getPoint(); 87 int row = table.rowAtPoint(p); 88 int column = table.columnAtPoint(p); 90 maybeShowPopup(e, model.getEventHashMap(row)); 91 } 92 93 public void mouseClicked(MouseEvent e) 94 { 95 Point p = e.getPoint(); 96 int row = table.rowAtPoint(p); 97 int column = table.columnAtPoint(p); 99 maybeShowPopup(e, model.getEventHashMap(row)); 100 101 if (e.getClickCount() == 2 && !e.isPopupTrigger() && e.getButton() == MouseEvent.BUTTON1 && !e.isConsumed()) 102 { 103 processMouseEvent(e, row); 104 e.consume(); 105 } 106 107 } 108 109 public void mouseReleased(MouseEvent e) 110 { 111 Point p = e.getPoint(); 112 int row = table.rowAtPoint(p); 113 int column = table.columnAtPoint(p); 115 maybeShowPopup(e, model.getEventHashMap(row)); 116 } 117 }); 118 } 119 120 public void init() { } 121 122 protected void maybeShowPopup(MouseEvent ev, HashMap data) 123 { 124 JPopupMenu menu = getPopupMenu(popupHook, data); 125 126 if (ev.isPopupTrigger() && menu != null) 127 { 128 menu.show((JComponent)ev.getComponent(), ev.getX(), ev.getY()); 129 ev.consume(); 130 } 131 } 132 133 public String getName() 134 { 135 return name; 136 } 137 138 public ImageIcon getImageIcon() 139 { 140 if (icon == null) 141 { 142 icon = new ImageIcon(ClientState.getClientState().getResource("status.gif")); 143 } 144 145 return icon; 146 } 147 148 public void processMouseEvent(MouseEvent ev, int row) 149 { 150 fireClickEvent(row+"", ev); 151 } 152 153 private static class MyRenderer implements TableCellRenderer 154 { 155 private JLabel select = new JLabel(); 156 private AttributedLabel labeln = new AttributedLabel(); 157 private AttributedLabel labels = new AttributedLabel(); 158 159 public MyRenderer() 160 { 161 select.setOpaque(true); 162 163 select.setLayout(new BorderLayout()); 164 select.setBorder(BorderFactory.createEmptyBorder(0, TextSource.UNIVERSAL_TWEAK, 0, 0)); 165 select.add(labels); 166 } 167 168 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) 169 { 170 if (value == null) 171 return new JLabel(); 172 173 AttributedString attrs = (AttributedString)value; 174 175 if (isSelected) 176 { 177 select.setFont(TextSource.clientFont); 178 select.setBackground(table.getSelectionBackground()); 179 select.setForeground(table.getSelectionForeground()); 180 select.setText(attrs.getText()); 181 return select; 182 } 183 184 labeln.setText(attrs); 185 return labeln; 186 } 187 } 188 } 189 | Popular Tags |