Exemplo n.º 1
0
 // -------->
 // original code:
 // ftp://ftp.oreilly.de/pub/examples/english_examples/jswing2/code/goodies/Mapper.java
 // modified by terai
 //     private Hashtable<Object, ArrayList<KeyStroke>> buildReverseMap(InputMap im) {
 //         Hashtable<Object, ArrayList<KeyStroke>> h = new Hashtable<>();
 //         if (Objects.isNull(im.allKeys())) {
 //             return h;
 //         }
 //         for (KeyStroke ks: im.allKeys()) {
 //             Object name = im.get(ks);
 //             if (h.containsKey(name)) {
 //                 h.get(name).add(ks);
 //             } else {
 //                 ArrayList<KeyStroke> keylist = new ArrayList<>();
 //                 keylist.add(ks);
 //                 h.put(name, keylist);
 //             }
 //         }
 //         return h;
 //     }
 private void loadBindingMap(Integer focusType, InputMap im, ActionMap am) {
   if (Objects.isNull(im.allKeys())) {
     return;
   }
   ActionMap tmpAm = new ActionMap();
   for (Object actionMapKey : am.allKeys()) {
     tmpAm.put(actionMapKey, am.get(actionMapKey));
   }
   for (KeyStroke ks : im.allKeys()) {
     Object actionMapKey = im.get(ks);
     Action action = am.get(actionMapKey);
     if (Objects.isNull(action)) {
       model.addBinding(new Binding(focusType, "____" + actionMapKey.toString(), ks.toString()));
     } else {
       model.addBinding(new Binding(focusType, actionMapKey.toString(), ks.toString()));
     }
     tmpAm.remove(actionMapKey);
   }
   if (Objects.isNull(tmpAm.allKeys())) {
     return;
   }
   for (Object actionMapKey : tmpAm.allKeys()) {
     model.addBinding(new Binding(focusType, actionMapKey.toString(), ""));
   }
 }
Exemplo n.º 2
0
 // Overridden for performance reasons. ---->
 @Override
 public boolean isOpaque() {
   Color back = getBackground();
   Component p = getParent();
   if (Objects.nonNull(p)) {
     p = p.getParent();
   } // p should now be the JTable.
   boolean colorMatch =
       Objects.nonNull(back)
           && Objects.nonNull(p)
           && back.equals(p.getBackground())
           && p.isOpaque();
   return !colorMatch && super.isOpaque();
 }
Exemplo n.º 3
0
 @Override
 protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
   // String literal pool
   // if (propertyName == "document" || ((propertyName == "font" || propertyName == "foreground")
   // && oldValue != newValue)) {
   if ("document".equals(propertyName)
       || !Objects.equals(oldValue, newValue)
           && ("font".equals(propertyName) || "foreground".equals(propertyName))) {
     super.firePropertyChange(propertyName, oldValue, newValue);
   }
 }
Exemplo n.º 4
0
 @Override
 public Component getTableCellRendererComponent(
     JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
   if (isSelected) {
     setForeground(table.getSelectionForeground());
     setBackground(table.getSelectionBackground());
   } else {
     setForeground(table.getForeground());
     setBackground(table.getBackground());
   }
   setFont(table.getFont());
   setText(Objects.toString(value, ""));
   return this;
 }
Exemplo n.º 5
0
 protected void fireEditingCanceled() {
   // Guaranteed to return a non-null array
   Object[] listeners = listenerList.getListenerList();
   // Process the listeners last to first, notifying
   // those that are interested in this event
   for (int i = listeners.length - 2; i >= 0; i -= 2) {
     if (listeners[i] == CellEditorListener.class) {
       // Lazily create the event:
       if (Objects.isNull(changeEvent)) {
         changeEvent = new ChangeEvent(this);
       }
       ((CellEditorListener) listeners[i + 1]).editingCanceled(changeEvent);
     }
   }
 }
Exemplo n.º 6
0
 @Override
 public Component getTableCellEditorComponent(
     JTable table, Object value, boolean isSelected, int row, int column) {
   System.out.println("getTableCellEditorComponent");
   setFont(table.getFont());
   setText(Objects.toString(value, ""));
   EventQueue.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           setCaretPosition(getText().length());
           requestFocusInWindow();
           System.out.println("invokeLater: getTableCellEditorComponent");
         }
       });
   return scroll;
 }