1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 package com.sun.star.wizards.ui; 24 25 import com.sun.star.awt.Size; 26 import com.sun.star.awt.XActionListener; 27 import com.sun.star.awt.XButton; 28 import com.sun.star.awt.XControl; 29 import com.sun.star.awt.XControlModel; 30 import com.sun.star.awt.XFixedText; 31 import com.sun.star.awt.XItemEventBroadcaster; 32 import com.sun.star.awt.XItemListener; 33 import com.sun.star.awt.XWindow; 34 import com.sun.star.lang.EventObject; 35 import com.sun.star.uno.UnoRuntime; 36 import com.sun.star.wizards.common.Helper; 37 import com.sun.star.wizards.common.IRenderer; 38 import com.sun.star.wizards.common.PropertySetHelper; 39 import com.sun.star.wizards.common.PropertyNames; 40 import javax.swing.ListModel; 41 import javax.swing.event.ListDataEvent; 42 import com.sun.star.wizards.common.HelpIds; 43 import com.sun.star.wizards.common.PropertyNames; 44 45 /** 46 * 47 * @author rpiterman,ll93751 48 */ 49 public class ButtonList implements XItemEventBroadcaster, XActionListener 50 { 51 52 private XFixedText lblImageText; 53 private XButton btnBack; 54 private XButton btnNext; 55 private XFixedText lblCounter; 56 private XControl m_aButtons[]; 57 private boolean benabled = true; 58 private UnoDialog2 oUnoDialog; 59 private Size gap = new Size(4, 4); 60 private int cols = 4; 61 private int rows = 3; 62 private Size m_aButtonSize = new Size(20, 20); 63 private Size pos; 64 private Size selectionGap = new Size(2, 2); 65 private boolean showButtons = true; 66 private Short step; 67 private boolean refreshOverNull = true; 68 private int imageTextLines = 1; 69 private boolean rowSelect = false; 70 public int tabIndex; 71 public Boolean scaleImages = Boolean.TRUE; 72 private String m_aControlName = "il"; 73 private int m_nCurrentSelection = -1; 74 private int pageStart = 0; 75 public int helpURL = 0; 76 private IImageRenderer renderer; 77 private ListModel listModel; 78 public IRenderer counterRenderer = new SimpleCounterRenderer(); 79 private final static int LINE_HEIGHT = 8; //private MethodInvocation METHOD_MOUSE_ENTER_IMAGE; 80 81 /** Getter for property m_aButtonSize. 82 * @return Value of property m_aButtonSize. 83 * 84 */ getButtonSize()85 public Size getButtonSize() 86 { 87 return this.m_aButtonSize; 88 } setName(String _sName)89 public void setName(String _sName) 90 { 91 m_aControlName = _sName; 92 } 93 94 /** Setter for property m_aButtonSize. 95 * @param imageSize New value of property m_aButtonSize. 96 */ setButtonSize(Size imageSize)97 public void setButtonSize(Size imageSize) 98 { 99 this.m_aButtonSize = imageSize; 100 } 101 102 // @Override disposing(EventObject arg0)103 public void disposing(EventObject arg0) 104 { 105 // throw new UnsupportedOperationException("Not supported yet."); 106 } 107 create(UnoDialog2 dialog)108 public void create(UnoDialog2 dialog) 109 { 110 oUnoDialog = dialog; 111 112 int imageTextHeight = imageTextLines * LINE_HEIGHT; 113 114 int nXPos = pos.Width + 1; 115 int nYPos = pos.Height + (m_aButtonSize.Height + gap.Height) * rows + gap.Height; 116 int nWidth = cols * (m_aButtonSize.Width + gap.Width) + gap.Width - 2; 117 118 lblImageText = dialog.insertLabel(m_aControlName + "_imageText", 119 new String[] 120 { 121 PropertyNames.PROPERTY_HEIGHT, 122 PropertyNames.PROPERTY_HELPURL, 123 PropertyNames.PROPERTY_LABEL, 124 PropertyNames.PROPERTY_POSITION_X, 125 PropertyNames.PROPERTY_POSITION_Y, 126 PropertyNames.PROPERTY_STEP, 127 PropertyNames.PROPERTY_TABINDEX, 128 "Tabstop", 129 PropertyNames.PROPERTY_WIDTH 130 }, 131 new Object[] 132 { 133 Integer.valueOf(imageTextHeight), 134 PropertyNames.EMPTY_STRING, 135 "(1)", 136 Integer.valueOf(nXPos), 137 Integer.valueOf(nYPos), 138 step, 139 Short.valueOf((short) 0), 140 Boolean.FALSE, 141 Integer.valueOf(nWidth) 142 }); 143 144 145 if (showButtons) 146 { 147 final String[] pNames1 = new String[] 148 { 149 PropertyNames.PROPERTY_HEIGHT, 150 PropertyNames.PROPERTY_HELPURL, 151 PropertyNames.PROPERTY_POSITION_X, 152 PropertyNames.PROPERTY_POSITION_Y, 153 PropertyNames.PROPERTY_STEP, 154 PropertyNames.PROPERTY_TABINDEX, 155 "Tabstop", 156 PropertyNames.PROPERTY_WIDTH 157 }; 158 159 final Integer btnSize = Integer.valueOf(14); 160 161 // TODO: if list of strings not the same length of list object, office will die. 162 btnBack = dialog.insertButton(m_aControlName + "_btnBack", "prevPage", this, pNames1, new Object[] 163 { 164 btnSize, 165 HelpIds.getHelpIdString(helpURL++), 166 Integer.valueOf(pos.Width), 167 Integer.valueOf(pos.Height + (m_aButtonSize.Height + gap.Height) * rows + gap.Height + imageTextHeight + 1), 168 step, 169 Short.valueOf((short) (tabIndex + 1)), 170 Boolean.TRUE, 171 btnSize 172 }); 173 174 btnNext = dialog.insertButton(m_aControlName + "_btnNext", "nextPage", this, pNames1, new Object[] 175 { 176 btnSize, 177 HelpIds.getHelpIdString(helpURL++), 178 Integer.valueOf(pos.Width + (m_aButtonSize.Width + gap.Width) * cols + gap.Width - btnSize.intValue() + 1), 179 Integer.valueOf(pos.Height + (m_aButtonSize.Height + gap.Height) * rows + gap.Height + imageTextHeight + 1), 180 step, 181 new Short((short) (tabIndex + 2)), 182 Boolean.TRUE, 183 btnSize 184 }); 185 186 lblCounter = dialog.insertLabel(m_aControlName + "_lblCounter", pNames1, new Object[] 187 { 188 Integer.valueOf(LINE_HEIGHT), 189 PropertyNames.EMPTY_STRING, 190 Integer.valueOf(pos.Width + btnSize.intValue() + 1), 191 Integer.valueOf(pos.Height + (m_aButtonSize.Height + gap.Height) * rows + gap.Height + imageTextHeight + ((btnSize.intValue() - LINE_HEIGHT) / 2)), 192 step, 193 Short.valueOf((short) 0), 194 Boolean.FALSE, 195 Integer.valueOf(cols * (m_aButtonSize.Width + gap.Width) + gap.Width - 2 * btnSize.intValue() - 1) 196 }); 197 198 Helper.setUnoPropertyValue(getModel(lblCounter), PropertyNames.PROPERTY_ALIGN, new Short((short) 1)); 199 Helper.setUnoPropertyValue(getModel(btnBack), PropertyNames.PROPERTY_LABEL, "<"); 200 Helper.setUnoPropertyValue(getModel(btnNext), PropertyNames.PROPERTY_LABEL, ">"); 201 202 203 } 204 205 m_tabIndex = new Short((short) tabIndex); 206 207 m_aButtons = new XControl[rows * cols]; 208 209 210 m_aButtonHeight = Integer.valueOf(m_aButtonSize.Height); 211 m_aButtonWidth = Integer.valueOf(m_aButtonSize.Width); 212 213 for (int r = 0; r < rows; r++) 214 { 215 for (int c = 0; c < cols; c++) 216 { 217 XButton aButton = createButton(dialog, r, c); 218 XControl aControl = UnoRuntime.queryInterface(XControl.class, aButton); 219 m_aButtons[r * cols + c] = aControl; 220 } 221 } 222 refreshImages(); 223 } 224 225 private Integer m_aButtonHeight; 226 private Integer m_aButtonWidth; 227 private Short m_tabIndex; 228 createButton(UnoDialog2 dialog, int _row, int _col)229 private XButton createButton(UnoDialog2 dialog, int _row, int _col) 230 { 231 String sButtonName = m_aControlName + "_button" + (_row * cols + _col); 232 int nButtonX = getButtonPosX(_col); 233 int nButtonY = getButtonPosY(_row); 234 XButton aButton = dialog.insertImageButton(sButtonName, this, 235 new String[] 236 { 237 /* PropertyNames.PROPERTY_BORDER, */ 238 /* "BackgroundColor", */ 239 PropertyNames.PROPERTY_HEIGHT, 240 PropertyNames.PROPERTY_HELPURL, 241 /* PropertyNames.PROPERTY_LABEL, */ 242 PropertyNames.PROPERTY_POSITION_X, 243 PropertyNames.PROPERTY_POSITION_Y, 244 /* "ScaleImage", */ 245 PropertyNames.PROPERTY_STEP, 246 PropertyNames.PROPERTY_TABINDEX, 247 "Tabstop", 248 "Toggle", 249 PropertyNames.PROPERTY_WIDTH 250 }, 251 new Object[] 252 { 253 /* Short.valueOf((short) 1), */ /* NO_BORDER, */ 254 /* BACKGROUND_COLOR, */ 255 m_aButtonHeight, 256 HelpIds.getHelpIdString(helpURL++), 257 /* "Test", */ 258 Integer.valueOf(nButtonX), 259 Integer.valueOf(nButtonY), 260 /* scaleImages, */ 261 step, 262 m_tabIndex, 263 Boolean.TRUE, 264 Boolean.TRUE, /* Toggle */ 265 m_aButtonWidth 266 }); 267 268 XWindow win = UnoRuntime.queryInterface(XWindow.class, aButton); 269 win.setEnable(true); 270 win.setVisible(true); 271 return aButton; 272 } 273 getButtonPosX(int _col)274 private int getButtonPosX(int _col) 275 { 276 return pos.Width + _col * (m_aButtonSize.Width + gap.Width) + gap.Width; 277 } 278 getButtonPosY(int _row)279 private int getButtonPosY(int _row) 280 { 281 return pos.Height + _row * (m_aButtonSize.Height + gap.Height) + gap.Height; 282 } 283 refreshImages()284 private void refreshImages() 285 { 286 if (showButtons) 287 { 288 refreshCounterText(); 289 } 290 if (refreshOverNull) 291 { 292 for (int i = 0; i < m_aButtons.length; i++) 293 { 294 setVisible(m_aButtons[i], false); 295 } 296 } 297 boolean focusable = true; 298 for (int i = 0; i < m_aButtons.length; i++) 299 { 300 Object[] oResources = renderer.getImageUrls(getObjectFor(i)); 301 if (oResources != null) 302 { 303 if (oResources.length == 1) 304 { 305 Helper.setUnoPropertyValue(m_aButtons[i].getModel(), PropertyNames.PROPERTY_IMAGEURL, oResources[0]); 306 } 307 else if (oResources.length == 2) 308 { 309 oUnoDialog.getPeerConfiguration().setImageUrl(m_aButtons[i].getModel(), oResources[0], oResources[1]); 310 // Helper.setUnoPropertyValue(m_aButtons[i].getModel(), PropertyNames.PROPERTY_IMAGEURL, oResources[0]); 311 } 312 boolean bTabStop = Boolean.TRUE; // focusable ? Boolean.TRUE : Boolean.FALSE; 313 Helper.setUnoPropertyValue(m_aButtons[i].getModel(), "Tabstop", bTabStop); 314 // Object aEnabled = Helper.getUnoPropertyValue(m_aButtons[i].getModel(), PropertyNames.PROPERTY_ENABLED); 315 if (refreshOverNull) 316 { 317 setVisible(m_aButtons[i], true); 318 } 319 focusable = false; 320 } 321 } 322 // refreshSelection(); 323 } 324 refreshCounterText()325 private void refreshCounterText() 326 { 327 Helper.setUnoPropertyValue(getModel(lblCounter), PropertyNames.PROPERTY_LABEL, counterRenderer.render(new Counter(pageStart + 1, pageEnd(), listModel.getSize()))); 328 } 329 pageEnd()330 private int pageEnd() 331 { 332 int i = pageStart + cols * rows; 333 if (i > listModel.getSize() - 1) 334 { 335 return listModel.getSize(); 336 } 337 else 338 { 339 return i; 340 } 341 } 342 343 /** Utility field holding list of ItemListeners. */ 344 private transient java.util.ArrayList<XItemListener> m_aItemListenerList; setVisible(Object control, boolean visible)345 private void setVisible(Object control, boolean visible) 346 { 347 final XWindow xWindow = UnoRuntime.queryInterface(XWindow.class, control); 348 xWindow.setVisible(visible); 349 } 350 351 /** 352 * 353 * @param i 354 * @return the Object in the list model corresponding to the given image index. 355 */ getObjectFor(int i)356 private Object getObjectFor(int i) 357 { 358 int ii = getIndexFor(i); 359 if (listModel.getSize() <= ii) 360 { 361 return null; 362 } 363 else 364 { 365 return listModel.getElementAt(ii); 366 } 367 } 368 369 /** 370 * 371 * @param i 372 * @return the index in the listModel for the given image index. 373 */ getIndexFor(int i)374 private int getIndexFor(int i) 375 { 376 return pageStart + i; 377 } 378 getImageIndexFor(int i)379 private int getImageIndexFor(int i) 380 { 381 return i - pageStart; 382 } 383 contentsChanged(ListDataEvent event)384 public void contentsChanged(ListDataEvent event) 385 { 386 /*//if the content that was changed is in the displayed range, refresh... 387 if ( (event.getIndex1() < getIndexFor(0)) // range is before... 388 || event.getIndex0() > getIndexFor( cols*rows - 1)) ; //do nothing 389 else 390 refreshImages(); 391 */ //m_nCurrentSelection = 0; 392 //pageStart = 0; 393 //if (event.refreshImages(); 394 } 395 intervalAdded(ListDataEvent event)396 public void intervalAdded(ListDataEvent event) 397 { 398 if (event.getIndex0() <= m_nCurrentSelection) 399 { 400 if (event.getIndex1() <= m_nCurrentSelection) 401 { 402 m_nCurrentSelection += event.getIndex1() - event.getIndex0() + 1; 403 } 404 } 405 if (event.getIndex0() < pageStart || event.getIndex1() < (pageStart + getRows() + getCols())) 406 { 407 refreshImages(); 408 } 409 } 410 intervalRemoved(ListDataEvent event)411 public void intervalRemoved(ListDataEvent event) 412 { 413 //contentsChanged(event); 414 } 415 416 /** Registers ItemListener to receive events. 417 * @param listener The listener to register. 418 * 419 */ 420 // @Override addItemListener(XItemListener listener)421 public synchronized void addItemListener(XItemListener listener) 422 { 423 if (m_aItemListenerList == null) 424 { 425 m_aItemListenerList = new java.util.ArrayList<XItemListener>(); 426 } 427 m_aItemListenerList.add(listener); 428 } 429 430 /** Removes ItemListener from the list of listeners. 431 * @param listener The listener to remove. 432 * 433 */ removeItemListener(XItemListener listener)434 public synchronized void removeItemListener(XItemListener listener) 435 { 436 if (m_aItemListenerList != null) 437 { 438 m_aItemListenerList.remove(listener); 439 } 440 } 441 442 /** Notifies all registered listeners about the event. 443 * 444 * @param event The event to be fired 445 * 446 */ fireItemSelected()447 private void fireItemSelected() 448 { 449 // java.awt.event.ItemEvent event = new java.awt.event.ItemEvent(this, 0, 450 // getSelectedObject(), java.awt.event.ItemEvent.SELECTED); 451 java.util.ArrayList list; 452 synchronized(this) 453 { 454 if (m_aItemListenerList == null) 455 { 456 return; 457 } 458 list = (java.util.ArrayList) m_aItemListenerList.clone(); 459 } 460 for (int i = 0; i < list.size(); i++) 461 { 462 ((com.sun.star.awt.XItemListener) list.get(i)).itemStateChanged(null); 463 } 464 } 465 466 /** 467 * @return 468 */ getCols()469 public int getCols() 470 { 471 return cols; 472 } 473 474 /** 475 * @return 476 */ getGap()477 public Size getGap() 478 { 479 return gap; 480 } 481 482 /** 483 * @return 484 */ getListModel()485 public ListModel getListModel() 486 { 487 return listModel; 488 } 489 490 /** 491 * @return 492 */ getStep()493 public Short getStep() 494 { 495 return step; 496 } 497 498 /** 499 * @return 500 */ getPageStart()501 public int getPageStart() 502 { 503 return pageStart; 504 } 505 506 /** 507 * @return 508 */ getPos()509 public Size getPos() 510 { 511 return pos; 512 } 513 514 /** 515 * @return 516 */ getRenderer()517 public IImageRenderer getRenderer() 518 { 519 return renderer; 520 } 521 522 /** 523 * @return 524 */ getRows()525 public int getRows() 526 { 527 return rows; 528 } 529 530 /** 531 * @return 532 */ getSelected()533 public int getSelected() 534 { 535 return m_nCurrentSelection; 536 } 537 538 /** 539 * @return 540 */ getSelectionGap()541 public Size getSelectionGap() 542 { 543 return selectionGap; 544 } 545 546 /** 547 * @return 548 */ isShowButtons()549 public boolean isShowButtons() 550 { 551 return showButtons; 552 } 553 554 /** 555 * @param i 556 */ setCols(int i)557 public void setCols(int i) 558 { 559 cols = i; 560 } 561 562 /** 563 * @param size 564 */ setGap(Size size)565 public void setGap(Size size) 566 { 567 gap = size; 568 } 569 570 /** 571 * @param model 572 */ setListModel(ListModel model)573 public void setListModel(ListModel model) 574 { 575 listModel = model; 576 } 577 578 /** 579 * @param short1 580 */ setStep(Short short1)581 public void setStep(Short short1) 582 { 583 step = short1; 584 } 585 586 /** 587 * @param i 588 */ setPageStart(int i)589 public void setPageStart(int i) 590 { 591 if (i == pageStart) 592 { 593 return; 594 } 595 pageStart = i; 596 enableButtons(); 597 refreshImages(); 598 } 599 600 /** 601 * @param _size 602 */ setPos(Size _size)603 public void setPos(Size _size) 604 { 605 pos = _size; 606 } 607 608 /** 609 * @param _renderer 610 */ setRenderer(IImageRenderer _renderer)611 public void setRenderer(IImageRenderer _renderer) 612 { 613 this.renderer = _renderer; 614 } 615 616 /** 617 * @param i 618 */ setRows(int i)619 public void setRows(int i) 620 { 621 rows = i; 622 } 623 624 /** 625 * @param i 626 */ setSelected(int i)627 public void setSelected(int i) 628 { 629 if (rowSelect && (i >= 0)) 630 { 631 i = (i / cols) * cols; 632 } 633 if (m_nCurrentSelection == i) 634 { 635 return; 636 } 637 m_nCurrentSelection = i; 638 refreshImageText(); 639 refreshSelection(); 640 fireItemSelected(); 641 } 642 643 /* 644 public void setSelected(Object object) 645 { 646 if (object == null) 647 { 648 setSelected(-1); 649 } 650 else 651 { 652 for (int i = 0; i < getListModel().getSize(); i++) 653 { 654 if (getListModel().getElementAt(i).equals(object)) 655 { 656 setSelected(i); 657 return; 658 } 659 } 660 } 661 setSelected(-1); 662 663 } 664 */ 665 666 /** 667 * set the text under the button list 668 */ refreshImageText()669 private void refreshImageText() 670 { 671 Object item = m_nCurrentSelection >= 0 ? getListModel().getElementAt(m_nCurrentSelection) : null; 672 final String sText = PropertyNames.SPACE + renderer.render(item); 673 Helper.setUnoPropertyValue(getModel(lblImageText), PropertyNames.PROPERTY_LABEL, sText); 674 } 675 676 /** 677 * @param size 678 */ setSelectionGap(Size size)679 public void setSelectionGap(Size size) 680 { 681 selectionGap = size; 682 } 683 684 /** 685 * @param b 686 */ setShowButtons(boolean b)687 public void setShowButtons(boolean b) 688 { 689 showButtons = b; 690 } 691 nextPage()692 public void nextPage() 693 { 694 if (pageStart < getListModel().getSize() - rows * cols) 695 { 696 setPageStart(pageStart + rows * cols); 697 } 698 } 699 prevPage()700 public void prevPage() 701 { 702 if (pageStart == 0) 703 { 704 return; 705 } 706 int i = pageStart - rows * cols; 707 if (i < 0) 708 { 709 i = 0; 710 } 711 setPageStart(i); 712 } 713 enableButtons()714 private void enableButtons() 715 { 716 enable(btnNext, Boolean.valueOf(pageStart + rows * cols < listModel.getSize())); 717 enable(btnBack, Boolean.valueOf(pageStart > 0)); 718 } 719 enable(Object control, Boolean enable)720 private void enable(Object control, Boolean enable) 721 { 722 Helper.setUnoPropertyValue(getModel(control), PropertyNames.PROPERTY_ENABLED, enable); 723 } 724 getModel(Object control)725 private Object getModel(Object control) 726 { 727 return UnoRuntime.queryInterface(XControl.class, control).getModel(); 728 } 729 setBorder(Object control, Short border)730 private void setBorder(Object control, Short border) 731 { 732 Helper.setUnoPropertyValue(getModel(control), PropertyNames.PROPERTY_BORDER, border); 733 //XWindowPeer peer = ((XControl)UnoRuntime.queryInterface(XControl.class,control)).getPeer(); 734 //peer.invalidate(InvalidateStyle.CHILDREN); 735 } 736 737 getSelectedObjects()738 public Object[] getSelectedObjects() 739 { 740 return new Object[] 741 { 742 getListModel().getElementAt(m_nCurrentSelection) 743 }; 744 } 745 746 747 /** 748 */ 749 public static interface IImageRenderer extends IRenderer 750 { 751 752 /** 753 * 754 * @param listItem 755 * @return two resource ids for an image referenced in the imaglist resourcefile of the 756 * wizards project; The second one of them is designed to be used for High Contrast Mode. 757 */ getImageUrls(Object listItem)758 public Object[] getImageUrls(Object listItem); 759 } 760 761 private static class SimpleCounterRenderer implements IRenderer 762 { 763 764 // @Override render(Object counter)765 public String render(Object counter) 766 { 767 return PropertyNames.EMPTY_STRING + ((Counter) counter).start + ".." + ((Counter) counter).end + "/" + ((Counter) counter).max; 768 } 769 } 770 771 public static class Counter 772 { 773 774 public int start, end, max; 775 Counter(int start_, int end_, int max_)776 public Counter(int start_, int end_, int max_) 777 { 778 start = start_; 779 end = end_; 780 max = max_; 781 } 782 } 783 getSelectedObject()784 public Object getSelectedObject() 785 { 786 return m_nCurrentSelection >= 0 ? getListModel().getElementAt(m_nCurrentSelection) : null; 787 } 788 789 setRowSelect(boolean b)790 public void setRowSelect(boolean b) 791 { 792 rowSelect = b; 793 } 794 isRowSelect()795 public boolean isRowSelect() 796 { 797 return rowSelect; 798 } 799 800 801 /** 802 * jump to the given item (display the screen 803 * that contains the given item). 804 * @param i 805 */ display(int i)806 public void display(int i) 807 { 808 int is = (getCols() * getRows()); 809 int ps = (listModel.getSize() / is) * is; 810 setPageStart(ps); 811 } 812 813 /** 814 * @return 815 */ isenabled()816 public boolean isenabled() 817 { 818 return benabled; 819 } 820 821 /** 822 * @param b 823 */ setenabled(boolean b)824 public void setenabled(boolean b) 825 { 826 827 for (int i = 0; i < m_aButtons.length; i++) 828 { 829 UnoDialog2.setEnabled(m_aButtons[i], b); 830 } 831 // UnoDialog2.setEnabled(grbxSelectedImage, b); 832 UnoDialog2.setEnabled(lblImageText, b); 833 if (showButtons) 834 { 835 UnoDialog2.setEnabled(btnBack, b); 836 UnoDialog2.setEnabled(btnNext, b); 837 UnoDialog2.setEnabled(lblCounter, b); 838 } 839 benabled = b; 840 } 841 842 /** 843 * refresh on all buttons, the selected button will get state pressed 844 */ refreshSelection()845 private void refreshSelection() 846 { 847 // reset all buttons to not set 848 for (int i = 0; i < m_aButtons.length; i++) 849 { 850 if (m_aButtons[i] != null) 851 { 852 XControlModel xModel = (XControlModel)UnoDialog2.getModel(m_aButtons[i]); 853 PropertySetHelper aHelper = new PropertySetHelper(xModel); 854 if (i == m_nCurrentSelection) 855 { 856 final short one = 1; 857 aHelper.setPropertyValueDontThrow(PropertyNames.PROPERTY_STATE, Short.valueOf(one)); 858 } 859 else 860 { 861 final short zero = 0; 862 aHelper.setPropertyValueDontThrow(PropertyNames.PROPERTY_STATE, Short.valueOf(zero)); 863 } 864 } 865 } 866 } 867 868 /** 869 * implementation of XActionListener 870 * will call if a button from the m_aButtonList is pressed. 871 * @param actionEvent 872 */ 873 // @Override actionPerformed(com.sun.star.awt.ActionEvent actionEvent)874 public void actionPerformed(com.sun.star.awt.ActionEvent actionEvent) 875 { 876 // bStopProcess = true; 877 XControlModel xModel = (XControlModel)UnoDialog2.getModel(actionEvent.Source); 878 PropertySetHelper aHelper = new PropertySetHelper(xModel); 879 880 int nState = aHelper.getPropertyValueAsInteger(PropertyNames.PROPERTY_STATE, -1); 881 if (nState == 0) 882 { 883 // this will avoid a wrong state, if already pressed. 884 aHelper.setPropertyValueDontThrow(PropertyNames.PROPERTY_STATE, Short.valueOf((short)1)); 885 } 886 887 // check which Button is pressed. 888 String sControlName = aHelper.getPropertyValueAsString(PropertyNames.PROPERTY_NAME, PropertyNames.EMPTY_STRING); 889 final String sButton = sControlName.substring(7 + m_aControlName.length()); 890 int nButton = Integer.parseInt(sButton); 891 892 // int image = getImageFromEvent(event); 893 int index = getIndexFor(nButton); 894 if (index < listModel.getSize()) 895 { 896 // focus(image); 897 setSelected(index); 898 } 899 900 } 901 902 903 } 904