Browse Source

Minor tidying in TextFrame.

Fixes issue CLIENT-22

Change-Id: I65691a9409158974bbc7d83b0c8d0aafdc42fd2c
Reviewed-on: http://gerrit.dmdirc.com/1548
Automatic-Compile: Greg Holmes <greg@dmdirc.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.5
Greg Holmes 13 years ago
parent
commit
75c58ac94e
1 changed files with 78 additions and 75 deletions
  1. 78
    75
      src/com/dmdirc/addons/ui_swing/components/frames/TextFrame.java

+ 78
- 75
src/com/dmdirc/addons/ui_swing/components/frames/TextFrame.java View File

@@ -77,6 +77,7 @@ import java.nio.charset.Charset;
77 77
 import java.nio.charset.IllegalCharsetNameException;
78 78
 import java.nio.charset.UnsupportedCharsetException;
79 79
 import java.util.concurrent.atomic.AtomicBoolean;
80
+import java.util.logging.Level;
80 81
 
81 82
 import javax.swing.BorderFactory;
82 83
 import javax.swing.JComponent;
@@ -179,14 +180,10 @@ public abstract class TextFrame extends JInternalFrame implements Window,
179 180
         addInternalFrameListener(this);
180 181
         getTextPane().addTextPaneListener(this);
181 182
 
182
-        getTextPane().setBackground(config.getOptionColour("ui",
183
-                "backgroundcolour"));
184
-        getTextPane().setForeground(config.getOptionColour("ui",
185
-                "foregroundcolour"));
186
-
187 183
         config.addChangeListener("ui", "foregroundcolour", this);
188 184
         config.addChangeListener("ui", "backgroundcolour", this);
189 185
         config.addChangeListener("ui", "frameBufferSize", this);
186
+        updateColours();
190 187
 
191 188
         addPropertyChangeListener("maximum", this);
192 189
 
@@ -273,8 +270,8 @@ public abstract class TextFrame extends JInternalFrame implements Window,
273 270
     /** {@inheritDoc} */
274 271
     @Override
275 272
     public void open() {
276
-        final boolean pref = frameParent.getConfigManager().getOptionBool("ui",
277
-                "maximisewindows");
273
+        final boolean pref = frameParent.getConfigManager()
274
+                .getOptionBool("ui", "maximisewindows");
278 275
         UIUtilities.invokeLater(new Runnable() {
279 276
 
280 277
             @Override
@@ -283,7 +280,8 @@ public abstract class TextFrame extends JInternalFrame implements Window,
283 280
                     TextFrame.super.setVisible(true);
284 281
                 }
285 282
                 try {
286
-                    if ((pref || controller.getMainFrame().getMaximised()) && !isMaximum()) {
283
+                    if ((pref || controller.getMainFrame().getMaximised())
284
+                            && !isMaximum()) {
287 285
                         setMaximum(true);
288 286
                     }
289 287
                 } catch (PropertyVetoException ex) {
@@ -562,9 +560,9 @@ public abstract class TextFrame extends JInternalFrame implements Window,
562 560
      */
563 561
     @Override
564 562
     public final void propertyChange(final PropertyChangeEvent event) {
565
-        LOGGER.finer("Property change: name: " + event.getPropertyName()
566
-                + " value: " + event.getOldValue() + "->"
567
-                + event.getNewValue());
563
+        LOGGER.log(Level.FINER, "Property change: name: {0}  value: {1} -> {3}"
564
+                , new Object[]{event.getPropertyName(), event.getOldValue(),
565
+                event.getNewValue()});
568 566
         if ("UI".equals(event.getPropertyName())) {
569 567
             if (isMaximum()) {
570 568
                 hideTitlebar();
@@ -613,32 +611,25 @@ public abstract class TextFrame extends JInternalFrame implements Window,
613 611
                 } else {
614 612
                     try {
615 613
                         c = getClass().getClassLoader().loadClass(componentUI);
616
-                        constructor =
617
-                                c.getConstructor(new Class[]{
614
+                        constructor = c.getConstructor(new Class[]{
618 615
                                     javax.swing.JInternalFrame.class});
619
-                        temp =
620
-                                constructor.newInstance(new Object[]{
616
+                        temp = constructor.newInstance(new Object[]{
621 617
                                     TextFrame.this});
622 618
                     } catch (ClassNotFoundException ex) {
623 619
                         Logger.appError(ErrorLevel.MEDIUM,
624
-                                "Unable to readd titlebar",
625
-                                ex);
620
+                                "Unable to readd titlebar", ex);
626 621
                     } catch (NoSuchMethodException ex) {
627 622
                         Logger.appError(ErrorLevel.MEDIUM,
628
-                                "Unable to readd titlebar",
629
-                                ex);
623
+                                "Unable to readd titlebar", ex);
630 624
                     } catch (InstantiationException ex) {
631 625
                         Logger.appError(ErrorLevel.MEDIUM,
632
-                                "Unable to readd titlebar",
633
-                                ex);
626
+                                "Unable to readd titlebar", ex);
634 627
                     } catch (IllegalAccessException ex) {
635 628
                         Logger.appError(ErrorLevel.MEDIUM,
636
-                                "Unable to readd titlebar",
637
-                                ex);
629
+                                "Unable to readd titlebar", ex);
638 630
                     } catch (InvocationTargetException ex) {
639 631
                         Logger.appError(ErrorLevel.MEDIUM,
640
-                                "Unable to readd titlebar",
641
-                                ex);
632
+                                "Unable to readd titlebar", ex);
642 633
                     }
643 634
 
644 635
                 }
@@ -728,7 +719,8 @@ public abstract class TextFrame extends JInternalFrame implements Window,
728 719
      */
729 720
     @Override
730 721
     public void internalFrameActivated(final InternalFrameEvent event) {
731
-        LOGGER.finer(getName() + ": internalFrameActivated()");
722
+        LOGGER.log(Level.FINER, "{0} : internalFrameActivated()",
723
+                new Object[] {getName()});
732 724
 
733 725
         if (maximiseRestoreInProgress.get()) {
734 726
             return;
@@ -738,8 +730,9 @@ public abstract class TextFrame extends JInternalFrame implements Window,
738 730
             /** {@inheritDoc} */
739 731
             @Override
740 732
             protected Object doInBackground() {
741
-                LOGGER.finer(getName()
742
-                        + ": internalFrameActivated(): doInBackground");
733
+                LOGGER.log(Level.FINER,
734
+                        "{0} : internalFrameActivated(): doInBackground",
735
+                        new Object[]{getName()});
743 736
                 frameParent.windowActivated();
744 737
                 return null;
745 738
             }
@@ -816,67 +809,75 @@ public abstract class TextFrame extends JInternalFrame implements Window,
816 809
 
817 810
     /** {@inheritDoc} */
818 811
     @Override
819
-    public void mouseClicked(final ClickTypeValue clicktype,
812
+    public void mouseClicked(final ClickTypeValue clickType,
820 813
             final MouseEventType eventType, final MouseEvent event) {
821 814
         if (event.isPopupTrigger()) {
822
-            showPopupMenuInternal(clicktype, event.getPoint());
815
+            showPopupMenuInternal(clickType, event.getPoint());
823 816
         }
824 817
         if (eventType == MouseEventType.CLICK
825 818
                 && event.getButton() == MouseEvent.BUTTON1) {
826
-            switch (clicktype.getType()) {
827
-                case CHANNEL:
828
-                    if (frameParent.getServer() != null && ActionManager.
829
-                            processEvent(CoreActionType.LINK_CHANNEL_CLICKED,
830
-                            null, this, clicktype.getValue())) {
831
-                        frameParent.getServer().join(
832
-                                new ChannelJoinRequest(clicktype.getValue()));
833
-                    }
834
-                    break;
835
-                case HYPERLINK:
836
-                    if (ActionManager.processEvent(
837
-                            CoreActionType.LINK_URL_CLICKED, null, this,
838
-                            clicktype.getValue())) {
839
-                        controller.getURLHandler().launchApp(clicktype.getValue());
840
-                    }
841
-                    break;
842
-                case NICKNAME:
843
-                    if (frameParent.getServer() != null && ActionManager.
844
-                            processEvent(CoreActionType.LINK_NICKNAME_CLICKED,
845
-                            null, this, clicktype.getValue())) {
846
-                        getContainer().getServer().getQuery(clicktype
847
-                                .getValue()).activateFrame();
848
-                    }
849
-                    break;
850
-                default:
851
-                    break;
852
-            }
819
+            handleLinkClick(clickType);
820
+        }
821
+    }
853 822
 
823
+    /**
824
+     * Handles clicking of a link in a textpane.
825
+     *
826
+     * @param clickType Details of link clicked
827
+     */
828
+    private void handleLinkClick(final ClickTypeValue clickType) {
829
+        switch (clickType.getType()) {
830
+            case CHANNEL:
831
+                if (frameParent.getServer() != null && ActionManager.
832
+                        processEvent(CoreActionType.LINK_CHANNEL_CLICKED,
833
+                        null, this, clickType.getValue())) {
834
+                    frameParent.getServer().join(
835
+                            new ChannelJoinRequest(clickType.getValue()));
836
+                }
837
+                break;
838
+            case HYPERLINK:
839
+                if (ActionManager.processEvent(
840
+                        CoreActionType.LINK_URL_CLICKED, null, this,
841
+                        clickType.getValue())) {
842
+                    controller.getURLHandler().launchApp(clickType.getValue());
843
+                }
844
+                break;
845
+            case NICKNAME:
846
+                if (frameParent.getServer() != null && ActionManager
847
+                        .processEvent(CoreActionType.LINK_NICKNAME_CLICKED,
848
+                        null, this, clickType.getValue())) {
849
+                    getContainer().getServer().getQuery(clickType.getValue())
850
+                            .activateFrame();
851
+                }
852
+                break;
853
+            default:
854
+                break;
854 855
         }
855 856
     }
856 857
 
857 858
     /**
858
-     * What popup type should be used for popup menus for nicknames
859
+     * What popup type should be used for popup menus for nicknames.
859 860
      *
860 861
      * @return Appropriate popuptype for this frame
861 862
      */
862 863
     public abstract PopupType getNicknamePopupType();
863 864
 
864 865
     /**
865
-     * What popup type should be used for popup menus for channels
866
+     * What popup type should be used for popup menus for channels.
866 867
      *
867 868
      * @return Appropriate popuptype for this frame
868 869
      */
869 870
     public abstract PopupType getChannelPopupType();
870 871
 
871 872
     /**
872
-     * What popup type should be used for popup menus for hyperlinks
873
+     * What popup type should be used for popup menus for hyperlinks.
873 874
      *
874 875
      * @return Appropriate popuptype for this frame
875 876
      */
876 877
     public abstract PopupType getHyperlinkPopupType();
877 878
 
878 879
     /**
879
-     * What popup type should be used for popup menus for normal clicks
880
+     * What popup type should be used for popup menus for normal clicks.
880 881
      *
881 882
      * @return Appropriate popuptype for this frame
882 883
      */
@@ -894,7 +895,6 @@ public abstract class TextFrame extends JInternalFrame implements Window,
894 895
      *
895 896
      * @param type ClickType Click type
896 897
      * @param point Point Point of the click
897
-     * @param argument Word under the click
898 898
      */
899 899
     private void showPopupMenuInternal(final ClickTypeValue type,
900 900
             final Point point) {
@@ -954,7 +954,7 @@ public abstract class TextFrame extends JInternalFrame implements Window,
954 954
     }
955 955
 
956 956
     /**
957
-     * Builds a popup menu of a specified type
957
+     * Builds a popup menu of a specified type.
958 958
      *
959 959
      * @param type type of menu to build
960 960
      * @param arguments Arguments for the command
@@ -1013,21 +1013,14 @@ public abstract class TextFrame extends JInternalFrame implements Window,
1013 1013
 
1014 1014
     /** {@inheritDoc} */
1015 1015
     @Override
1016
-    public void configChanged(final String domain,
1017
-            final String key) {
1018
-        if (getConfigManager() == null) {
1016
+    public void configChanged(final String domain, final String key) {
1017
+        if (getConfigManager() == null || getTextPane() == null) {
1019 1018
             return;
1020 1019
         }
1021 1020
 
1022
-        if ("ui".equals(domain)) {
1023
-            if ("foregroundcolour".equals(key) && getTextPane() != null) {
1024
-                getTextPane().setForeground(getConfigManager().
1025
-                        getOptionColour("ui", "foregroundcolour"));
1026
-            } else if ("backgroundcolour".equals(key) && getTextPane()
1027
-                    != null) {
1028
-                getTextPane().setBackground(getConfigManager().
1029
-                        getOptionColour("ui", "backgroundcolour"));
1030
-            }
1021
+        if ("ui".equals(domain) && ("foregroundcolour".equals(key)
1022
+                || "backgroundcolour".equals(key))) {
1023
+            updateColours();
1031 1024
         }
1032 1025
     }
1033 1026
 
@@ -1072,4 +1065,14 @@ public abstract class TextFrame extends JInternalFrame implements Window,
1072 1065
     public SwingController getController() {
1073 1066
         return controller;
1074 1067
     }
1068
+
1069
+    /**
1070
+     * Updates colour settings from their config values.
1071
+     */
1072
+    private void updateColours() {
1073
+        getTextPane().setForeground(getConfigManager().
1074
+                        getOptionColour("ui", "foregroundcolour"));
1075
+        getTextPane().setBackground(getConfigManager().
1076
+                        getOptionColour("ui", "backgroundcolour"));
1077
+    }
1075 1078
 }

Loading…
Cancel
Save